File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 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)
380380 if (rxBufferIndex < rxBufferLength){
381381 return ;
382382 }
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+ }
383391 // copy twi rx buffer into local read buffer
384392 // this enables new reads to happen in parallel
385393 memcpy (rxBuffer, inBytes, numBytes);
@@ -423,7 +431,7 @@ void TwoWire::onRequest( void (*function)(void) )
423431 * @note Minimum allocated size is BUFFER_LENGTH)
424432 * @param length: number of bytes to allocate
425433 */
426- inline void TwoWire::allocateRxBuffer (size_t length)
434+ void TwoWire::allocateRxBuffer (size_t length)
427435{
428436 if (rxBufferAllocated < length) {
429437 // 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
5858 static void onRequestService (void );
5959 static void onReceiveService (uint8_t *, int );
6060
61- void allocateRxBuffer (size_t length);
61+ static void allocateRxBuffer (size_t length);
6262 void allocateTxBuffer (size_t length);
6363
6464 void resetRxBuffer (void );
You can’t perform that action at this time.
0 commit comments