Skip to content

Commit 7f268a1

Browse files
committed
Merge remote-tracking branch 'origin/main' into main
2 parents 41f34d1 + af2f8df commit 7f268a1

File tree

1 file changed

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

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
5959
self->peripheral = NULL;
6060
// I2C pins have a regular pattern. SCL is always odd and SDA is even. They match up in pairs
6161
// so we can divide by two to get the instance. This pattern repeats.
62-
if (scl->number % 2 == 1 && sda->number % 2 == 0 && scl->number / 2 == sda->number / 2) {
63-
size_t instance = (scl->number / 2) % 2;
64-
self->peripheral = i2c[instance];
62+
size_t scl_instance = (scl->number / 2) % 2;
63+
size_t sda_instance = (sda->number / 2) % 2;
64+
if (scl->number % 2 == 1 && sda->number % 2 == 0 && scl_instance == sda_instance) {
65+
self->peripheral = i2c[sda_instance];
6566
}
6667
if (self->peripheral == NULL) {
6768
mp_raise_ValueError(translate("Invalid pins"));

0 commit comments

Comments
 (0)