Skip to content

Commit

Permalink
Merge pull request #3803 from skieast/fix_i2c_hang_with_wifi
Browse files Browse the repository at this point in the history
Working, tested with two i2c busses
  • Loading branch information
tannewt authored Dec 9, 2020
2 parents 1330130 + 571c063 commit e14b148
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions ports/esp32s2/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ void never_reset_i2c(i2c_port_t num) {
void i2c_reset(void) {
for (i2c_port_t num = 0; num < I2C_NUM_MAX; num++) {
if (i2c_status[num] == STATUS_IN_USE) {
i2c_driver_delete(num);
i2c_status[num] = STATUS_FREE;
}
}
}
static bool i2c_inited[I2C_NUM_MAX];

void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) {
Expand Down Expand Up @@ -121,13 +121,19 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
if (result != ESP_OK) {
mp_raise_ValueError(translate("Invalid pins"));
}
result = i2c_driver_install(self->i2c_num,
I2C_MODE_MASTER,
0,
0,
0);
if (result != ESP_OK) {
mp_raise_OSError(MP_EIO);


if (!i2c_inited[self->i2c_num]) {
result = i2c_driver_install(self->i2c_num,
I2C_MODE_MASTER,
0,
0,
0);
if (result != ESP_OK) {
mp_raise_OSError(MP_EIO);
}
i2c_inited[self->i2c_num] = true;

}

claim_pin(sda);
Expand All @@ -143,7 +149,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
return;
}

i2c_driver_delete(self->i2c_num);
i2c_status[self->i2c_num] = STATUS_FREE;

common_hal_reset_pin(self->sda_pin);
Expand Down

0 comments on commit e14b148

Please sign in to comment.