Skip to content

Commit

Permalink
Merge pull request #925 from board707/wire_compat_issue
Browse files Browse the repository at this point in the history
Add return values to STM32F4 Wire.write() methods to be compatible with recent Adafruit libraries
  • Loading branch information
stevstrong committed Apr 28, 2024
2 parents 338020b + 1ff4b7f commit 1cbad56
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
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* 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*)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
21 changes: 13 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 @@ -99,36 +99,41 @@ 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
*/
uint write(uint8*, int);

/*
* Stack up bytes from the array to be sent when transmitting
*/
void write(uint8*, int);
uint write(const 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 1cbad56

Please sign in to comment.