File tree 3 files changed +10
-3
lines changed
3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -539,7 +539,7 @@ void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c)
539
539
540
540
if ((obj -> i2c_onSlaveReceive != NULL ) &&
541
541
(obj -> slaveMode == SLAVE_MODE_RECEIVE )) {
542
- nbData = I2C_TXRX_BUFFER_SIZE - obj -> handle .XferCount ;
542
+ nbData = I2C_TXRX_BUFFER_SIZE - obj -> handle .XferSize ;
543
543
if (nbData != 0 ) {
544
544
obj -> i2c_onSlaveReceive (obj -> i2cTxRxBuffer , nbData );
545
545
}
Original file line number Diff line number Diff line change @@ -380,6 +380,13 @@ void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
380
380
if (rxBufferIndex < rxBufferLength){
381
381
return ;
382
382
}
383
+
384
+ allocateRxBuffer (numBytes);
385
+ // error if no memory block available to allocate the buffer
386
+ if (rxBuffer == nullptr ){
387
+ Error_Handler ();
388
+ }
389
+
383
390
// copy twi rx buffer into local read buffer
384
391
// this enables new reads to happen in parallel
385
392
memcpy (rxBuffer, inBytes, numBytes);
@@ -423,7 +430,7 @@ void TwoWire::onRequest( void (*function)(void) )
423
430
* @note Minimum allocated size is BUFFER_LENGTH)
424
431
* @param length: number of bytes to allocate
425
432
*/
426
- inline void TwoWire::allocateRxBuffer (size_t length)
433
+ void TwoWire::allocateRxBuffer (size_t length)
427
434
{
428
435
if (rxBufferAllocated < length) {
429
436
// By default we allocate BUFFER_LENGTH bytes. It is the min size of the buffer.
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ class TwoWire : public Stream
58
58
static void onRequestService (void );
59
59
static void onReceiveService (uint8_t *, int );
60
60
61
- void allocateRxBuffer (size_t length);
61
+ static void allocateRxBuffer (size_t length);
62
62
void allocateTxBuffer (size_t length);
63
63
64
64
void resetRxBuffer (void );
You can’t perform that action at this time.
0 commit comments