Skip to content

Commit ace3b58

Browse files
committed
Remove short-write bitbang from rp2040 I2C
The I2C.c for rp2040 included a special case for writes <=2 bytes, claiming that the hardware does not support these. I'm guessing this was a workaround for an early SDK bug, since I can't find any evidence this is true. Deleting this code did not adversely affect register reads from an is31l3731 which involve a single byte of data written to set up the address pointer, followed by a read. Signed-off-by: Philip Howard <[email protected]>
1 parent be9e045 commit ace3b58

File tree

1 file changed

+0
-29
lines changed
  • ports/raspberrypi/common-hal/busio

1 file changed

+0
-29
lines changed

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ 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.
102-
// Must be done before setting up the I2C pins, since they will be
103-
// set up as GPIO by the bitbangio.I2C object.
104-
//
105-
// Sets pins to open drain, high, and input.
106-
shared_module_bitbangio_i2c_construct(&self->bitbangio_i2c, scl, sda,
107-
frequency, timeout);
108-
109101
self->baudrate = i2c_init(self->peripheral, frequency);
110102

111103
self->scl_pin = scl->number;
@@ -158,27 +150,6 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
158150

159151
uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
160152
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.
163-
// So use bitbangio.I2C to do the write.
164-
165-
gpio_set_function(self->scl_pin, GPIO_FUNC_SIO);
166-
gpio_set_function(self->sda_pin, GPIO_FUNC_SIO);
167-
gpio_set_dir(self->scl_pin, GPIO_IN);
168-
gpio_set_dir(self->sda_pin, GPIO_IN);
169-
gpio_put(self->scl_pin, false);
170-
gpio_put(self->sda_pin, false);
171-
172-
uint8_t status = shared_module_bitbangio_i2c_write(&self->bitbangio_i2c,
173-
addr, data, len, transmit_stop_bit);
174-
175-
// The pins must be set back to GPIO_FUNC_I2C in the order given here,
176-
// SCL first, otherwise reads will hang.
177-
gpio_set_function(self->scl_pin, GPIO_FUNC_I2C);
178-
gpio_set_function(self->sda_pin, GPIO_FUNC_I2C);
179-
180-
return status;
181-
}
182153

183154
int result = i2c_write_timeout_us(self->peripheral, addr, data, len, !transmit_stop_bit, BUS_TIMEOUT_US);
184155
if (result == len) {

0 commit comments

Comments
 (0)