File tree 2 files changed +10
-2
lines changed
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -380,6 +380,14 @@ void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
380
380
if (rxBufferIndex < rxBufferLength){
381
381
return ;
382
382
}
383
+
384
+ if (rxBuffer == nullptr ){
385
+ allocateRxBuffer (numBytes);
386
+ // error if no memory block available to allocate the buffer
387
+ if (rxBuffer == nullptr ){
388
+ Error_Handler ();
389
+ }
390
+ }
383
391
// copy twi rx buffer into local read buffer
384
392
// this enables new reads to happen in parallel
385
393
memcpy (rxBuffer, inBytes, numBytes);
@@ -423,7 +431,7 @@ void TwoWire::onRequest( void (*function)(void) )
423
431
* @note Minimum allocated size is BUFFER_LENGTH)
424
432
* @param length: number of bytes to allocate
425
433
*/
426
- inline void TwoWire::allocateRxBuffer (size_t length)
434
+ void TwoWire::allocateRxBuffer (size_t length)
427
435
{
428
436
if (rxBufferAllocated < length) {
429
437
// 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