Skip to content

RP2040: Remove short-write bitbang from I2C #4378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions ports/raspberrypi/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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);
Expand Down