Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
stevstrong committed May 18, 2024
2 parents 32b7f4d + d05a128 commit c691b2c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
6 changes: 6 additions & 0 deletions STM32F1/libraries/SPI/src/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ class SPIClass {
*/
void write(const void * buffer, uint32_t length);

// Some libraries (like recent Adafruit graphics libraries) require
// the write function be availabe under the name transfer, so here it is:
inline void transfer(const void * buffer, uint32_t length) {
write(buffer, length);
}

/**
* @brief Transmit a byte, then return the next unread byte.
*
Expand Down
40 changes: 30 additions & 10 deletions STM32F4/libraries/Wire/WireBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,35 +95,55 @@ uint8 WireBase::requestFrom(int address, int numBytes) {
return WireBase::requestFrom((uint8)address, numBytes);
}

void WireBase::write(uint8 value) {
uint8 WireBase::requestFrom(int address, int numBytes, uint8 stop) {
UNUSED(stop);
return WireBase::requestFrom((uint8)address, numBytes);
}

uint WireBase::write(uint8 value) {
if (tx_buf_idx == BUFFER_LENGTH) {
tx_buf_overflow = true;
return;
return 0;
}
tx_buf[tx_buf_idx++] = value;
itc_msg.length++;
return 1;
}

void WireBase::write(uint8_t* buf, int len) {
uint WireBase::write(uint8* buf, int len) {
uint result = 0;
for (uint8 i = 0; i < len; i++) {
write(buf[i]);
result += write(buf[i]);
}
return result;
}

void WireBase::write(int value) {
write((uint8)value);
uint WireBase::write(const uint8* buf, int len) {
uint result = 0;
for (uint8 i = 0; i < len; i++) {
uint8_t v = buf[i];
result += write(v);
}
return result;
}


uint WireBase::write(int value) {
return write((uint8)value);
}

void WireBase::write(int* buf, int len) {
write((uint8_t*)buf, (uint8)len);
uint WireBase::write(int* buf, int len) {
return write((uint8*)buf, (uint8)len);
}

void WireBase::write(char* buf) {
uint WireBase::write(char* buf) {
uint8 *ptr = (uint8*)buf;
uint result = 0;
while (*ptr) {
write(*ptr);
result += write(*ptr);
ptr++;
}
return result;
}

uint8 WireBase::available() {
Expand Down
16 changes: 8 additions & 8 deletions STM32F4/libraries/Wire/WireBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#ifndef _WIREBASE_H_
#define _WIREBASE_H_

#define UNUSED(x) (void)x;
#include "wirish.h"
#include <libmaple/i2c.h>

Expand Down Expand Up @@ -103,36 +103,36 @@ class WireBase { // Abstraction is awesome!
* storing into the receiving buffer.
*/
uint8 requestFrom(uint8, int);

/*
* Allow only 8 bit addresses to be used when requesting bytes
*/
uint8 requestFrom(int, int);

uint8 requestFrom(int, int, uint8);
/*
* Stack up bytes to be sent when transmitting
*/
void write(uint8);
uint write(uint8);

/*
* Stack up bytes from the array to be sent when transmitting
*/
void write(uint8_t*, int);
uint write(uint8*, int);

/*
* Ensure that a sending data will only be 8-bit bytes
*/
void write(int);
uint write(int);

/*
* Ensure that an array sending data will only be 8-bit bytes
*/
void write(int*, int);
uint write(int*, int);

/*
* Stack up bytes from a string to be sent when transmitting
*/
void write(char*);
uint write(char*);

/*
* Return the amount of bytes that is currently in the receiving buffer
Expand Down

0 comments on commit c691b2c

Please sign in to comment.