Skip to content

Commit 1ff4b7f

Browse files
committed
Add return values to write() methods to be compatible with STM32F1 core
1 parent 338020b commit 1ff4b7f

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

STM32F4/libraries/Wire/WireBase.cpp

+30-10
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,55 @@ uint8 WireBase::requestFrom(int address, int numBytes) {
9595
return WireBase::requestFrom((uint8)address, numBytes);
9696
}
9797

98-
void WireBase::write(uint8 value) {
98+
uint8 WireBase::requestFrom(int address, int numBytes, uint8 stop) {
99+
UNUSED(stop);
100+
return WireBase::requestFrom((uint8)address, numBytes);
101+
}
102+
103+
uint WireBase::write(uint8 value) {
99104
if (tx_buf_idx == BUFFER_LENGTH) {
100105
tx_buf_overflow = true;
101-
return;
106+
return 0;
102107
}
103108
tx_buf[tx_buf_idx++] = value;
104109
itc_msg.length++;
110+
return 1;
105111
}
106112

107-
void WireBase::write(uint8* buf, int len) {
113+
uint WireBase::write(uint8* buf, int len) {
114+
uint result = 0;
108115
for (uint8 i = 0; i < len; i++) {
109-
write(buf[i]);
116+
result += write(buf[i]);
110117
}
118+
return result;
111119
}
112120

113-
void WireBase::write(int value) {
114-
write((uint8)value);
121+
uint WireBase::write(const uint8* buf, int len) {
122+
uint result = 0;
123+
for (uint8 i = 0; i < len; i++) {
124+
uint8_t v = buf[i];
125+
result += write(v);
126+
}
127+
return result;
128+
}
129+
130+
131+
uint WireBase::write(int value) {
132+
return write((uint8)value);
115133
}
116134

117-
void WireBase::write(int* buf, int len) {
118-
write((uint8*)buf, (uint8)len);
135+
uint WireBase::write(int* buf, int len) {
136+
return write((uint8*)buf, (uint8)len);
119137
}
120138

121-
void WireBase::write(char* buf) {
139+
uint WireBase::write(char* buf) {
122140
uint8 *ptr = (uint8*)buf;
141+
uint result = 0;
123142
while (*ptr) {
124-
write(*ptr);
143+
result += write(*ptr);
125144
ptr++;
126145
}
146+
return result;
127147
}
128148

129149
uint8 WireBase::available() {

STM32F4/libraries/Wire/WireBase.h

+13-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
#ifndef _WIREBASE_H_
4242
#define _WIREBASE_H_
43-
43+
#define UNUSED(x) (void)x;
4444
#include "wirish.h"
4545
#include <libmaple/i2c.h>
4646

@@ -99,36 +99,41 @@ class WireBase { // Abstraction is awesome!
9999
* storing into the receiving buffer.
100100
*/
101101
uint8 requestFrom(uint8, int);
102-
102+
103103
/*
104104
* Allow only 8 bit addresses to be used when requesting bytes
105105
*/
106106
uint8 requestFrom(int, int);
107-
107+
uint8 requestFrom(int, int, uint8);
108108
/*
109109
* Stack up bytes to be sent when transmitting
110110
*/
111-
void write(uint8);
111+
uint write(uint8);
112+
113+
/*
114+
* Stack up bytes from the array to be sent when transmitting
115+
*/
116+
uint write(uint8*, int);
112117

113118
/*
114119
* Stack up bytes from the array to be sent when transmitting
115120
*/
116-
void write(uint8*, int);
121+
uint write(const uint8*, int);
117122

118123
/*
119124
* Ensure that a sending data will only be 8-bit bytes
120125
*/
121-
void write(int);
126+
uint write(int);
122127

123128
/*
124129
* Ensure that an array sending data will only be 8-bit bytes
125130
*/
126-
void write(int*, int);
131+
uint write(int*, int);
127132

128133
/*
129134
* Stack up bytes from a string to be sent when transmitting
130135
*/
131-
void write(char*);
136+
uint write(char*);
132137

133138
/*
134139
* Return the amount of bytes that is currently in the receiving buffer

0 commit comments

Comments
 (0)