Skip to content

Commit f980144

Browse files
dbdtannewt
authored andcommitted
[ports/espressif] esp-idf v5.5 changes
1 parent c25ce60 commit f980144

File tree

5 files changed

+47
-37
lines changed

5 files changed

+47
-37
lines changed

ports/espressif/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ ifneq ($(IDF_TARGET),esp32p4)
672672
BINARY_BLOBS = esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libphy.a
673673
endif
674674
ifneq ($(CIRCUITPY_WIFI),0)
675-
BINARY_BLOBS += esp-idf/components/esp_coex/lib/$(IDF_TARGET)/libcoexist.a $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS))
675+
BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS))
676676
ifneq ($(IDF_TARGET),esp32c2)
677677
BINARY_BLOBS += $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, libmesh.a libwapi.a)
678678
endif
@@ -683,6 +683,12 @@ BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/librtc.a
683683
endif
684684

685685
ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) $(CHIP_COMPONENTS) app_update bootloader_support driver esp_driver_gpio esp_driver_gptimer esp_driver_i2c esp_driver_ledc esp_driver_spi esp_driver_uart efuse esp_adc esp_app_format esp_common esp_event esp_hw_support esp_mm esp_partition esp_pm esp_ringbuf esp_rom esp_system esp_timer freertos hal heap log newlib nvs_flash pthread soc spi_flash vfs esp_vfs_console
686+
NEEDS_COEX = $(CIRCUITPY_BLEIO_NATIVE) + $(CIRCUITPY_WIFI)
687+
ifneq ($(NEEDS_COEX),0)
688+
# esp_system_include_startup_funcs requires coexist as well BT regardless of wifi
689+
BINARY_BLOBS += esp-idf/components/esp_coex/lib/$(IDF_TARGET)/libcoexist.a
690+
ESP_IDF_COMPONENTS_LINK += esp_coex
691+
endif
686692
ifneq ($(CIRCUITPY_WIFI),0)
687693
ESP_IDF_COMPONENTS_LINK += esp_coex esp_netif esp_security esp-tls esp_wifi lwip mbedtls mdns wpa_supplicant esp_phy
688694
endif

ports/espressif/common-hal/alarm/pin/PinAlarm.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -360,38 +360,36 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob
360360
if (gpio_isr_register(gpio_interrupt, NULL, 0, &gpio_interrupt_handle) != ESP_OK) {
361361
mp_raise_ValueError(MP_ERROR_TEXT("Can only alarm on RTC IO from deep sleep."));
362362
}
363-
for (size_t i = 0; i < 64; i++) {
364-
uint64_t mask = 1ull << i;
363+
for (gpio_num_t pin = 0; pin < SOC_GPIO_PIN_COUNT; pin++) {
364+
uint64_t mask = 1ULL << pin;
365365
bool high = (high_alarms & mask) != 0;
366366
bool low = (low_alarms & mask) != 0;
367367
bool pull = (pull_pins & mask) != 0;
368368
if (!(high || low)) {
369369
continue;
370370
}
371-
if (rtc_gpio_is_valid_gpio(i)) {
371+
if (rtc_gpio_is_valid_gpio(pin)) {
372372
#ifdef SOC_PM_SUPPORT_RTC_PERIPH_PD
373-
rtc_gpio_deinit(i);
373+
rtc_gpio_deinit(pin);
374374
#endif
375375
}
376-
gpio_int_type_t interrupt_mode = GPIO_INTR_DISABLE;
377-
gpio_pull_mode_t pull_mode = GPIO_FLOATING;
378-
if (high) {
379-
interrupt_mode = GPIO_INTR_HIGH_LEVEL;
380-
pull_mode = GPIO_PULLDOWN_ONLY;
381-
}
382-
if (low) {
383-
interrupt_mode = GPIO_INTR_LOW_LEVEL;
384-
pull_mode = GPIO_PULLUP_ONLY;
385-
}
386-
gpio_set_direction(i, GPIO_MODE_DEF_INPUT);
387-
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[i], PIN_FUNC_GPIO);
376+
gpio_set_direction(pin, GPIO_MODE_INPUT);
388377
if (pull) {
389-
gpio_set_pull_mode(i, pull_mode);
378+
if (high) {
379+
ESP_ERROR_CHECK(gpio_set_pull_mode(pin, GPIO_PULLDOWN_ONLY));
380+
} else {
381+
ESP_ERROR_CHECK(gpio_set_pull_mode(pin, GPIO_PULLUP_ONLY));
382+
}
383+
} else {
384+
ESP_ERROR_CHECK(gpio_set_pull_mode(pin, GPIO_FLOATING));
390385
}
391-
never_reset_pin_number(i);
392-
// Sets interrupt type and wakeup bits.
393-
gpio_wakeup_enable(i, interrupt_mode);
394-
gpio_intr_enable(i);
386+
gpio_int_type_t intr = GPIO_INTR_DISABLE;
387+
if (high) intr = GPIO_INTR_HIGH_LEVEL;
388+
if (low) intr = GPIO_INTR_LOW_LEVEL;
389+
never_reset_pin_number(pin);
390+
gpio_wakeup_enable(pin, intr);
391+
gpio_set_intr_type(pin, intr);
392+
gpio_intr_enable(pin);
395393
}
396394
// Wait for any pulls to settle.
397395
mp_hal_delay_ms(50);

ports/espressif/common-hal/digitalio/DigitalInOut.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
#include "hal/gpio_hal.h"
1212

1313
static bool _pin_is_input(uint8_t pin_number) {
14-
const uint32_t iomux = READ_PERI_REG(GPIO_PIN_MUX_REG[pin_number]);
15-
return (iomux & FUN_IE) != 0;
14+
gpio_io_config_t config;
15+
if (gpio_get_io_config((gpio_num_t)pin_number, &config) != ESP_OK) {
16+
return false;
17+
}
18+
return config.ie;
1619
}
1720

1821
void digitalio_digitalinout_preserve_for_deep_sleep(size_t n_dios, digitalio_digitalinout_obj_t *preserve_dios[]) {
@@ -113,10 +116,12 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(
113116

114117
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
115118
digitalio_digitalinout_obj_t *self) {
116-
if (GPIO_HAL_GET_HW(GPIO_PORT_0)->pin[self->pin->number].pad_driver == 1) {
119+
gpio_io_config_t config;
120+
if (gpio_get_io_config((gpio_num_t)self->pin->number, &config) != ESP_OK) {
121+
// Should it fail closed or open?
117122
return DRIVE_MODE_OPEN_DRAIN;
118123
}
119-
return DRIVE_MODE_PUSH_PULL;
124+
return config.od ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL;
120125
}
121126

122127
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
@@ -134,11 +139,10 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
134139

135140
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(
136141
digitalio_digitalinout_obj_t *self) {
137-
gpio_num_t gpio_num = self->pin->number;
138-
if (REG_GET_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU)) {
139-
return PULL_UP;
140-
} else if (REG_GET_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PD)) {
141-
return PULL_DOWN;
142+
gpio_io_config_t config;
143+
if (gpio_get_io_config((gpio_num_t)self->pin->number, &config) != ESP_OK) {
144+
// Should it fail closed or open?
145+
return PULL_NONE;
142146
}
143-
return PULL_NONE;
147+
return config.pd ? PULL_DOWN : PULL_UP;
144148
}

ports/espressif/common-hal/microcontroller/Pin.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,8 @@ void reset_all_pins(void) {
370370
gpio_deep_sleep_hold_dis();
371371
#endif
372372

373-
for (uint8_t i = 0; i < GPIO_PIN_COUNT; i++) {
374-
uint32_t iomux_address = GPIO_PIN_MUX_REG[i];
375-
if (iomux_address == 0 ||
373+
for (gpio_num_t i = 0; i < SOC_GPIO_PIN_COUNT; i++) {
374+
if (!GPIO_IS_VALID_GPIO(i) ||
376375
_never_reset(i) ||
377376
_skip_reset_once(i) ||
378377
_preserved_pin(i)) {

ports/espressif/common-hal/wifi/__init__.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ void common_hal_wifi_init(bool user_initiated) {
146146
common_hal_wifi_radio_obj.base.type = &wifi_radio_type;
147147

148148
if (!wifi_ever_inited) {
149-
ESP_ERROR_CHECK(esp_netif_init());
150149
ESP_ERROR_CHECK(esp_event_loop_create_default());
150+
ESP_ERROR_CHECK(esp_netif_init());
151151
wifi_ever_inited = true;
152152
}
153153

@@ -175,6 +175,7 @@ void common_hal_wifi_init(bool user_initiated) {
175175
&self->handler_instance_got_ip));
176176

177177
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
178+
esp_err_t result = esp_wifi_init(&config);
178179
#ifdef CONFIG_ESP32_WIFI_NVS_ENABLED
179180
// Generally we don't use this because we store ssid and passwords ourselves in the filesystem.
180181
esp_err_t err = nvs_flash_init();
@@ -185,8 +186,10 @@ void common_hal_wifi_init(bool user_initiated) {
185186
err = nvs_flash_init();
186187
}
187188
ESP_ERROR_CHECK(err);
189+
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH));
190+
#else
191+
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
188192
#endif
189-
esp_err_t result = esp_wifi_init(&config);
190193
if (result == ESP_ERR_NO_MEM) {
191194
if (gc_alloc_possible()) {
192195
mp_raise_msg(&mp_type_MemoryError, MP_ERROR_TEXT("Failed to allocate Wifi memory"));

0 commit comments

Comments
 (0)