Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add return values to STM32F4 Wire.write() methods to be compatible with recent Adafruit libraries #925

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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