Fix RP2040 I2C instance check

This commit is contained in:
Scott Shawcroft 2021-08-18 08:55:52 -07:00
parent 5b0009cbc4
commit 0390f812be
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA

View File

@ -59,9 +59,10 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
self->peripheral = NULL; self->peripheral = NULL;
// I2C pins have a regular pattern. SCL is always odd and SDA is even. They match up in pairs // I2C pins have a regular pattern. SCL is always odd and SDA is even. They match up in pairs
// so we can divide by two to get the instance. This pattern repeats. // so we can divide by two to get the instance. This pattern repeats.
if (scl->number % 2 == 1 && sda->number % 2 == 0 && scl->number / 2 == sda->number / 2) { size_t scl_instance = (scl->number / 2) % 2;
size_t instance = (scl->number / 2) % 2; size_t sda_instance = (sda->number / 2) % 2;
self->peripheral = i2c[instance]; if (scl->number % 2 == 1 && sda->number % 2 == 0 && scl_instance == sda_instance) {
self->peripheral = i2c[sda_instance];
} }
if (self->peripheral == NULL) { if (self->peripheral == NULL) {
mp_raise_ValueError(translate("Invalid pins")); mp_raise_ValueError(translate("Invalid pins"));