Skip to content

Commit 3b9e1b8

Browse files
committed
RP2040: Only bitbang 0-byte writes
The I2C.c for RP2040 included a special case for writes <=2 bytes to match the MicroPython implementation, however RP2040 does support 1 and 2 byte reads, with only 0 bytes being the exception. Signed-off-by: Philip Howard <[email protected]>
1 parent be9e045 commit 3b9e1b8

File tree

1 file changed

+8
-3
lines changed
  • ports/raspberrypi/common-hal/busio

1 file changed

+8
-3
lines changed

ports/raspberrypi/common-hal/busio/I2C.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
9898
}
9999
#endif
100100

101-
// Create a bitbangio.I2C object to do short writes.
101+
// Create a bitbangio.I2C object to do 0 byte writes.
102+
//
103+
// These are used to non-invasively detect I2C devices by sending
104+
// the address and confirming an ACK.
105+
// They are not supported by the RP2040 hardware.
106+
//
102107
// Must be done before setting up the I2C pins, since they will be
103108
// set up as GPIO by the bitbangio.I2C object.
104109
//
@@ -158,8 +163,8 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
158163

159164
uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
160165
const uint8_t *data, size_t len, bool transmit_stop_bit) {
161-
if (len <= 2) {
162-
// The RP2040 I2C peripheral will not do writes 2 bytes or less long.
166+
if (len == 0) {
167+
// The RP2040 I2C peripheral will not perform 0 byte writes.
163168
// So use bitbangio.I2C to do the write.
164169

165170
gpio_set_function(self->scl_pin, GPIO_FUNC_SIO);

0 commit comments

Comments
 (0)