Skip to content

Commit b1cf1cd

Browse files
Fix return value for a failed TwoWire::requestFrom()
1 parent 1446bb4 commit b1cf1cd

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

libraries/Wire/src/Wire.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ TwoWire::TwoWire(struct _stm32l0_i2c_t *i2c, const struct _stm32l0_i2c_params_t
4242
_xf_address = 0;
4343

4444
_rx_read = 0;
45-
_rx_write = 0;
45+
_rx_count = 0;
4646

4747
_tx_write = 0;
4848
_tx_active = false;
@@ -214,7 +214,7 @@ size_t TwoWire::requestFrom(uint8_t address, size_t size, bool stopBit)
214214
_xf_address = 0;
215215

216216
_rx_read = 0;
217-
_rx_write = 0;
217+
_rx_count = 0;
218218

219219
while (transaction.status == STM32L0_I2C_STATUS_BUSY) {
220220
__WFE();
@@ -226,10 +226,10 @@ size_t TwoWire::requestFrom(uint8_t address, size_t size, bool stopBit)
226226
_xf_address = address;
227227
}
228228

229-
_rx_write = size;
229+
_rx_count = size;
230230
}
231231

232-
return size;
232+
return _rx_count;
233233
}
234234

235235
size_t TwoWire::write(uint8_t data)
@@ -266,12 +266,12 @@ size_t TwoWire::write(const uint8_t *data, size_t size)
266266

267267
int TwoWire::available(void)
268268
{
269-
return (_rx_write - _rx_read);
269+
return (_rx_count - _rx_read);
270270
}
271271

272272
int TwoWire::read(void)
273273
{
274-
if (_rx_read >= _rx_write) {
274+
if (_rx_read >= _rx_count) {
275275
return -1;
276276
}
277277

@@ -280,9 +280,9 @@ int TwoWire::read(void)
280280

281281
int TwoWire::read(uint8_t *buffer, size_t size)
282282
{
283-
if (size > (unsigned int)(_rx_write - _rx_read))
283+
if (size > (unsigned int)(_rx_count - _rx_read))
284284
{
285-
size = (_rx_write - _rx_read);
285+
size = (_rx_count - _rx_read);
286286
}
287287

288288
memcpy(buffer, &_rx_data[_rx_read], size);
@@ -294,7 +294,7 @@ int TwoWire::read(uint8_t *buffer, size_t size)
294294

295295
int TwoWire::peek(void)
296296
{
297-
if (_rx_read >= _rx_write) {
297+
if (_rx_read >= _rx_count) {
298298
return -1;
299299
}
300300

@@ -507,10 +507,10 @@ void TwoWire::_eventCallback(class TwoWire *self, uint32_t events)
507507

508508
if (events & STM32L0_I2C_EVENT_RECEIVE_DONE) {
509509
self->_rx_read = 0;
510-
self->_rx_write = (events & STM32L0_I2C_EVENT_COUNT_MASK) >> STM32L0_I2C_EVENT_COUNT_SHIFT;
510+
self->_rx_count = (events & STM32L0_I2C_EVENT_COUNT_MASK) >> STM32L0_I2C_EVENT_COUNT_SHIFT;
511511

512512
if (self->_receiveCallback) {
513-
(*self->_receiveCallback)(self->_rx_write);
513+
(*self->_receiveCallback)(self->_rx_count);
514514
}
515515
}
516516

libraries/Wire/src/Wire.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class TwoWire : public Stream
9393

9494
uint8_t _rx_data[BUFFER_LENGTH];
9595
uint8_t _rx_read;
96-
uint8_t _rx_write;
96+
uint8_t _rx_count;
9797
uint8_t _rx_address;
9898

9999
uint8_t _tx_data[BUFFER_LENGTH];

0 commit comments

Comments
 (0)