File tree 1 file changed +7
-6
lines changed
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,8 @@ void arduino::MbedI2C::flush() {
124
124
void arduino::MbedI2C::receiveThd () {
125
125
while (1 ) {
126
126
int i = slave->receive ();
127
+ int c = 0 ;
128
+ int buf_idx = 0 ;
127
129
switch (i) {
128
130
case mbed::I2CSlave::ReadAddressed:
129
131
if (onRequestCb != NULL ) {
@@ -139,12 +141,11 @@ void arduino::MbedI2C::receiveThd() {
139
141
case mbed::I2CSlave::WriteAddressed:
140
142
rxBuffer.clear ();
141
143
char buf[72 ];
142
- while (1 ) {
143
- size_t c = slave->read (buf, sizeof (buf));
144
- for (size_t i = 0 ; i < c; i++) {
145
- rxBuffer.store_char (uint8_t (buf[i]));
146
- }
147
- if (c <= sizeof (buf)) {
144
+ c = slave->read (buf, sizeof (buf));
145
+ for (buf_idx = 0 ; buf_idx < c; buf_idx++) {
146
+ if (rxBuffer.availableForStore ()) {
147
+ rxBuffer.store_char (uint8_t (buf[buf_idx]));
148
+ } else {
148
149
break ;
149
150
}
150
151
}
You can’t perform that action at this time.
0 commit comments