From b70699b924e8abcec186c0bf7214a9fe12478f71 Mon Sep 17 00:00:00 2001 From: Morgan Sandercock Date: Tue, 21 Oct 2025 17:23:46 -0700 Subject: [PATCH 1/6] Allow more than 255 byte reads Change the type for reading length to size_t so that more than 255 bytes can be read in one operation. (Writing more than 255 is a little more complex due to the small (usually 32 byte) buffer used inside the Wire.h library.) --- Adafruit_BusIO_Register.cpp | 6 +++--- Adafruit_BusIO_Register.h | 4 ++-- Adafruit_I2CDevice.cpp | 4 ++-- library.properties | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Adafruit_BusIO_Register.cpp b/Adafruit_BusIO_Register.cpp index f3e8187..98b0351 100644 --- a/Adafruit_BusIO_Register.cpp +++ b/Adafruit_BusIO_Register.cpp @@ -111,11 +111,11 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register( /*! * @brief Write a buffer of data to the register location * @param buffer Pointer to data to write - * @param len Number of bytes to write + * @param len Number of bytes to write (don't exceed maxbuffersize() which may be as small as 32 bytes) * @return True on successful write (only really useful for I2C as SPI is * uncheckable) */ -bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) { +bool Adafruit_BusIO_Register::write(uint8_t *buffer, size_t len) { uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF), (uint8_t)(_address >> 8)}; if (_i2cdevice) { @@ -216,7 +216,7 @@ uint32_t Adafruit_BusIO_Register::readCached(void) { return _cached; } @param len Number of bytes to read into the buffer @return true on successful read, otherwise false */ -bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) { +bool Adafruit_BusIO_Register::read(uint8_t *buffer, size_t len) { uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF), (uint8_t)(_address >> 8)}; if (_i2cdevice) { diff --git a/Adafruit_BusIO_Register.h b/Adafruit_BusIO_Register.h index 046e04c..d733f82 100644 --- a/Adafruit_BusIO_Register.h +++ b/Adafruit_BusIO_Register.h @@ -63,12 +63,12 @@ class Adafruit_BusIO_Register { uint8_t byteorder = LSBFIRST, uint8_t address_width = 1); - bool read(uint8_t *buffer, uint8_t len); + bool read(uint8_t *buffer, size_t len); bool read(uint8_t *value); bool read(uint16_t *value); uint32_t read(void); uint32_t readCached(void); - bool write(uint8_t *buffer, uint8_t len); + bool write(uint8_t *buffer, size_t len); bool write(uint32_t value, uint8_t numbytes = 0); uint8_t width(void); diff --git a/Adafruit_I2CDevice.cpp b/Adafruit_I2CDevice.cpp index 2633cf1..8805d3a 100644 --- a/Adafruit_I2CDevice.cpp +++ b/Adafruit_I2CDevice.cpp @@ -174,7 +174,7 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop, /*! * @brief Read from I2C into a buffer from the I2C device. - * Cannot be more than maxBufferSize() bytes. + * Unlimited length, in chunks of maxBufferSize() bytes. * @param buffer Pointer to buffer of data to read into * @param len Number of bytes from buffer to read. * @param stop Whether to send an I2C STOP signal on read @@ -235,7 +235,7 @@ bool Adafruit_I2CDevice::_read(uint8_t *buffer, size_t len, bool stop) { /*! * @brief Write some data, then read some data from I2C into another buffer. - * Cannot be more than maxBufferSize() bytes. The buffers can point to + * Written buffer cannot be more than maxBufferSize() bytes. The buffers can point to * same/overlapping locations. * @param write_buffer Pointer to buffer of data to write from * @param write_len Number of bytes from buffer to write. diff --git a/library.properties b/library.properties index 1615468..85f8c14 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit BusIO -version=1.17.4 +version=1.17.5 author=Adafruit maintainer=Adafruit sentence=This is a library for abstracting away UART, I2C and SPI interfacing From c78767d5f11b9942c4fb786cdac80aa2f60894d0 Mon Sep 17 00:00:00 2001 From: Morgan Sandercock Date: Tue, 21 Oct 2025 19:13:32 -0700 Subject: [PATCH 2/6] fix line length for clang-format to pass --- Adafruit_BusIO_Register.cpp | 3 ++- Adafruit_I2CDevice.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Adafruit_BusIO_Register.cpp b/Adafruit_BusIO_Register.cpp index 98b0351..1e497b4 100644 --- a/Adafruit_BusIO_Register.cpp +++ b/Adafruit_BusIO_Register.cpp @@ -111,7 +111,8 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register( /*! * @brief Write a buffer of data to the register location * @param buffer Pointer to data to write - * @param len Number of bytes to write (don't exceed maxbuffersize() which may be as small as 32 bytes) + * @param len Number of bytes to write (don't exceed maxbuffersize() + * which may be as small as 32 bytes) * @return True on successful write (only really useful for I2C as SPI is * uncheckable) */ diff --git a/Adafruit_I2CDevice.cpp b/Adafruit_I2CDevice.cpp index 8805d3a..48b6043 100644 --- a/Adafruit_I2CDevice.cpp +++ b/Adafruit_I2CDevice.cpp @@ -235,8 +235,8 @@ bool Adafruit_I2CDevice::_read(uint8_t *buffer, size_t len, bool stop) { /*! * @brief Write some data, then read some data from I2C into another buffer. - * Written buffer cannot be more than maxBufferSize() bytes. The buffers can point to - * same/overlapping locations. + * Written buffer cannot be more than maxBufferSize() bytes. The buffers + * can point to same/overlapping locations. * @param write_buffer Pointer to buffer of data to write from * @param write_len Number of bytes from buffer to write. * @param read_buffer Pointer to buffer of data to read into. From fa9d5cbf822532bbae206c7c879590ef56e836a5 Mon Sep 17 00:00:00 2001 From: Morgan Sandercock Date: Tue, 21 Oct 2025 19:16:36 -0700 Subject: [PATCH 3/6] further attempt to placate clang-format --- Adafruit_BusIO_Register.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_BusIO_Register.cpp b/Adafruit_BusIO_Register.cpp index 1e497b4..7fc555f 100644 --- a/Adafruit_BusIO_Register.cpp +++ b/Adafruit_BusIO_Register.cpp @@ -111,8 +111,8 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register( /*! * @brief Write a buffer of data to the register location * @param buffer Pointer to data to write - * @param len Number of bytes to write (don't exceed maxbuffersize() - * which may be as small as 32 bytes) + * @param len Number of bytes to write - don't exceed maxbuffersize() + * which may be as small as 32 bytes * @return True on successful write (only really useful for I2C as SPI is * uncheckable) */ From c9c125b0baff7106771c7a389928b8359a0433c1 Mon Sep 17 00:00:00 2001 From: Morgan Sandercock Date: Tue, 21 Oct 2025 19:19:52 -0700 Subject: [PATCH 4/6] changing whitespace in comments for clang-format --- Adafruit_I2CDevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_I2CDevice.cpp b/Adafruit_I2CDevice.cpp index 48b6043..6653374 100644 --- a/Adafruit_I2CDevice.cpp +++ b/Adafruit_I2CDevice.cpp @@ -235,7 +235,7 @@ bool Adafruit_I2CDevice::_read(uint8_t *buffer, size_t len, bool stop) { /*! * @brief Write some data, then read some data from I2C into another buffer. - * Written buffer cannot be more than maxBufferSize() bytes. The buffers + * Written buffer cannot be more than maxBufferSize() bytes. The buffers * can point to same/overlapping locations. * @param write_buffer Pointer to buffer of data to write from * @param write_len Number of bytes from buffer to write. From 5f6232c6c7a3a0fc1497201fa49e474c1886469e Mon Sep 17 00:00:00 2001 From: Morgan Sandercock Date: Mon, 27 Oct 2025 21:02:57 -0700 Subject: [PATCH 5/6] Support larger buffer available in Teensy The Teensy LC, 3.x and 4.x have their own implementation of the TwoWire object. This has an internal buffer much bigger than the default 32 bytes expected by this library. This change will allow whatever is declared by the Teensy library to be used as the real buffer size. --- Adafruit_I2CDevice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Adafruit_I2CDevice.cpp b/Adafruit_I2CDevice.cpp index 6653374..44c1e6e 100644 --- a/Adafruit_I2CDevice.cpp +++ b/Adafruit_I2CDevice.cpp @@ -15,6 +15,8 @@ Adafruit_I2CDevice::Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire) { _maxBufferSize = 250; // as defined in Wire.h's RingBuffer #elif defined(ESP32) _maxBufferSize = I2C_BUFFER_LENGTH; +#elif defined(TwoWireKinetis_h) || defined(TwoWireIMXRT_h) //Teensy 3.x || 4.x + _maxBufferSize = BUFFER_LENGTH; #else _maxBufferSize = 32; #endif From fdf0de16fd0a6ce7b3f1e96fb040ce35603b4609 Mon Sep 17 00:00:00 2001 From: Morgan Sandercock Date: Mon, 27 Oct 2025 21:11:31 -0700 Subject: [PATCH 6/6] Fix clang violation --- Adafruit_I2CDevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_I2CDevice.cpp b/Adafruit_I2CDevice.cpp index 44c1e6e..1f7e545 100644 --- a/Adafruit_I2CDevice.cpp +++ b/Adafruit_I2CDevice.cpp @@ -15,7 +15,7 @@ Adafruit_I2CDevice::Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire) { _maxBufferSize = 250; // as defined in Wire.h's RingBuffer #elif defined(ESP32) _maxBufferSize = I2C_BUFFER_LENGTH; -#elif defined(TwoWireKinetis_h) || defined(TwoWireIMXRT_h) //Teensy 3.x || 4.x +#elif defined(TwoWireKinetis_h) || defined(TwoWireIMXRT_h) // Teensy 3.x || 4.x _maxBufferSize = BUFFER_LENGTH; #else _maxBufferSize = 32;