From 26eb429cc69ec8697d733d27e7125190d068d20f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 7 Mar 2021 18:23:14 -0500 Subject: [PATCH 1/5] restore install/delete for i2c driver --- ports/esp32s2/common-hal/busio/I2C.c | 39 +++++++++++------------- ports/esp32s2/common-hal/wifi/__init__.c | 1 + 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/ports/esp32s2/common-hal/busio/I2C.c b/ports/esp32s2/common-hal/busio/I2C.c index 8372eb8c3053..c1a0f75ac46b 100644 --- a/ports/esp32s2/common-hal/busio/I2C.c +++ b/ports/esp32s2/common-hal/busio/I2C.c @@ -53,7 +53,6 @@ void i2c_reset(void) { } } } -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) { @@ -90,10 +89,9 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, #endif - if (xSemaphoreCreateBinaryStatic(&self->semaphore) != &self->semaphore) { + if (xSemaphoreCreateMutexStatic(&self->semaphore) != &self->semaphore) { mp_raise_RuntimeError(translate("Unable to create lock")); } - xSemaphoreGive(&self->semaphore); self->sda_pin = sda; self->scl_pin = scl; self->i2c_num = I2C_NUM_MAX; @@ -106,34 +104,29 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, mp_raise_ValueError(translate("All I2C peripherals are in use")); } i2c_status[self->i2c_num] = STATUS_IN_USE; + + // Delete any previous driver. + i2c_driver_delete(self->i2c_num); + i2c_config_t i2c_conf = { .mode = I2C_MODE_MASTER, .sda_io_num = self->sda_pin->number, .scl_io_num = self->scl_pin->number, - .sda_pullup_en = GPIO_PULLUP_DISABLE, /*!< Internal GPIO pull mode for I2C sda signal*/ - .scl_pullup_en = GPIO_PULLUP_DISABLE, /*!< Internal GPIO pull mode for I2C scl signal*/ .master = { .clk_speed = frequency, } }; - esp_err_t result = i2c_param_config(self->i2c_num, &i2c_conf); - if (result != ESP_OK) { - mp_raise_ValueError(translate("Invalid pins")); + if (i2c_param_config(self->i2c_num, &i2c_conf) != ESP_OK) { + mp_raise_ValueError(translate("Invalid frequency")); } - - 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; - + if (i2c_driver_install(self->i2c_num, + I2C_MODE_MASTER, + 0, + 0, + 0) != ESP_OK) { + mp_raise_OSError(MP_EIO); } claim_pin(sda); @@ -149,12 +142,14 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { return; } - i2c_status[self->i2c_num] = STATUS_FREE; + i2c_driver_delete(self->i2c_num); - common_hal_reset_pin(self->sda_pin); common_hal_reset_pin(self->scl_pin); + common_hal_reset_pin(self->sda_pin); self->sda_pin = NULL; self->scl_pin = NULL; + + i2c_status[self->i2c_num] = STATUS_FREE; } bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { diff --git a/ports/esp32s2/common-hal/wifi/__init__.c b/ports/esp32s2/common-hal/wifi/__init__.c index b8e8f731bd81..a3927b7c3e11 100644 --- a/ports/esp32s2/common-hal/wifi/__init__.c +++ b/ports/esp32s2/common-hal/wifi/__init__.c @@ -109,6 +109,7 @@ void common_hal_wifi_init(void) { wifi_radio_obj_t* self = &common_hal_wifi_radio_obj; self->netif = esp_netif_create_default_wifi_sta(); + self->started = false; // Even though we just called esp_netif_create_default_wifi_sta, // station mode isn't actually ready for use until esp_wifi_set_mode() From 061d5910cb6e6eecda70a7a7a5320a414e8b3b9e Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Mar 2021 12:09:01 -0500 Subject: [PATCH 2/5] use fixed esp-idf --- lib/tinyusb | 2 +- ports/esp32s2/esp-idf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 280297bdb7ae..2adb7e719316 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 280297bdb7aec67adf347ec046943a48a71647df +Subproject commit 2adb7e719316b12c53a907153cfa0056db1abd70 diff --git a/ports/esp32s2/esp-idf b/ports/esp32s2/esp-idf index ebe7784258d8..8dd3ea82f16a 160000 --- a/ports/esp32s2/esp-idf +++ b/ports/esp32s2/esp-idf @@ -1 +1 @@ -Subproject commit ebe7784258d8c10e9cc334ccc00c3fd270746c8b +Subproject commit 8dd3ea82f16a23bc31b194670627cea898e49935 From f75a009ed432221c2afd7546f77bce38bc7855fb Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Mar 2021 15:16:32 -0500 Subject: [PATCH 3/5] fix unnecessary statement order change --- ports/esp32s2/common-hal/busio/I2C.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32s2/common-hal/busio/I2C.c b/ports/esp32s2/common-hal/busio/I2C.c index c1a0f75ac46b..e3586ab1867f 100644 --- a/ports/esp32s2/common-hal/busio/I2C.c +++ b/ports/esp32s2/common-hal/busio/I2C.c @@ -144,8 +144,8 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { i2c_driver_delete(self->i2c_num); - common_hal_reset_pin(self->scl_pin); common_hal_reset_pin(self->sda_pin); + common_hal_reset_pin(self->scl_pin); self->sda_pin = NULL; self->scl_pin = NULL; From c71b6cb699299fb12394ad07afeb54b81be9f581 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Mar 2021 20:05:31 -0500 Subject: [PATCH 4/5] move to esp-idf PR merge --- ports/esp32s2/esp-idf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32s2/esp-idf b/ports/esp32s2/esp-idf index 8dd3ea82f16a..f30a865fd1a4 160000 --- a/ports/esp32s2/esp-idf +++ b/ports/esp32s2/esp-idf @@ -1 +1 @@ -Subproject commit 8dd3ea82f16a23bc31b194670627cea898e49935 +Subproject commit f30a865fd1a44d880b909b84112f74741412c2ce From 0ce5b2f5941f0dc11c3c0e9ca0ad054432ce652c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 12 Mar 2021 08:20:09 -0500 Subject: [PATCH 5/5] put back pullup setting --- ports/esp32s2/common-hal/busio/I2C.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/esp32s2/common-hal/busio/I2C.c b/ports/esp32s2/common-hal/busio/I2C.c index e3586ab1867f..a1d0b8f9c4f9 100644 --- a/ports/esp32s2/common-hal/busio/I2C.c +++ b/ports/esp32s2/common-hal/busio/I2C.c @@ -112,6 +112,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, .mode = I2C_MODE_MASTER, .sda_io_num = self->sda_pin->number, .scl_io_num = self->scl_pin->number, + .sda_pullup_en = GPIO_PULLUP_DISABLE, /*!< Internal GPIO pull mode for I2C sda signal*/ + .scl_pullup_en = GPIO_PULLUP_DISABLE, /*!< Internal GPIO pull mode for I2C scl signal*/ .master = { .clk_speed = frequency,