File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
ports/raspberrypi/common-hal/busio Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -59,9 +59,10 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
59
59
self -> peripheral = NULL ;
60
60
// I2C pins have a regular pattern. SCL is always odd and SDA is even. They match up in pairs
61
61
// 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 ];
65
66
}
66
67
if (self -> peripheral == NULL ) {
67
68
mp_raise_ValueError (translate ("Invalid pins" ));
You can’t perform that action at this time.
0 commit comments