diff options
| author | Phil Howard <phil@gadgetoid.com> | 2021-03-10 19:58:09 +0000 |
|---|---|---|
| committer | Phil Howard <phil@gadgetoid.com> | 2021-03-17 16:25:54 +0000 |
| commit | b8d4f9655f62f05e650a5baa256c8310aaa3f5dd (patch) | |
| tree | 2d0c0d76710b21510cdc1a226506e74281baec6e | |
| parent | bfc8c89536e12dba0cc9adc0065819d730bb0983 (diff) | |
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 <phil@pimoroni.com>
| -rw-r--r-- | ports/raspberrypi/common-hal/busio/I2C.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/ports/raspberrypi/common-hal/busio/I2C.c b/ports/raspberrypi/common-hal/busio/I2C.c index c9f89fadd..0190959f8 100644 --- a/ports/raspberrypi/common-hal/busio/I2C.c +++ b/ports/raspberrypi/common-hal/busio/I2C.c @@ -98,7 +98,12 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, } #endif - // Create a bitbangio.I2C object to do short writes. + // Create a bitbangio.I2C object to do 0 byte writes. + // + // These are used to non-invasively detect I2C devices by sending + // the address and confirming an ACK. + // They are not supported by the RP2040 hardware. + // // Must be done before setting up the I2C pins, since they will be // set up as GPIO by the bitbangio.I2C object. // @@ -157,9 +162,9 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) { } uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, - const uint8_t *data, size_t len, bool transmit_stop_bit) { - if (len <= 2) { - // The RP2040 I2C peripheral will not do writes 2 bytes or less long. + const uint8_t *data, size_t len, bool transmit_stop_bit) { + if (len == 0) { + // The RP2040 I2C peripheral will not perform 0 byte writes. // So use bitbangio.I2C to do the write. gpio_set_function(self->scl_pin, GPIO_FUNC_SIO); |
