Skip to content

ports/esp32: Add basic espressif IDF v5.3 compatibility. #15733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ports/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ manage the ESP32 microcontroller, as well as a way to manage the required
build environment and toolchains needed to build the firmware.

The ESP-IDF changes quickly and MicroPython only supports certain versions.
Currently MicroPython supports v5.0.4, v5.0.5, v5.1.2, v5.2.0, v5.2.2.
Currently MicroPython supports v5.0.4, v5.0.5, v5.1.2, v5.2.0, v5.2.2, v5.3.

To install the ESP-IDF the full instructions can be found at the
[Espressif Getting Started guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html#installation-step-by-step).
Expand Down
26 changes: 17 additions & 9 deletions ports/esp32/machine_touchpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@

#if SOC_TOUCH_SENSOR_SUPPORTED

#if SOC_TOUCH_VERSION_1 // ESP32 only
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0)
#if SOC_TOUCH_VERSION_1
#define SOC_TOUCH_SENSOR_VERSION (1)
#elif SOC_TOUCH_VERSION_2
#define SOC_TOUCH_SENSOR_VERSION (2)
#endif
#endif

#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32 only
#include "driver/touch_pad.h"
#elif SOC_TOUCH_VERSION_2 // All other SoCs with touch, to date
#elif SOC_TOUCH_SENSOR_VERSION == 2 // All other SoCs with touch, to date
#include "driver/touch_sensor.h"
#else
#error "Unknown touch hardware version"
Expand Down Expand Up @@ -98,13 +106,13 @@ static mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
initialized = 1;
}
#if SOC_TOUCH_VERSION_1
#if SOC_TOUCH_SENSOR_VERSION == 1
esp_err_t err = touch_pad_config(self->touchpad_id, 0);
#elif SOC_TOUCH_VERSION_2
#elif SOC_TOUCH_SENSOR_VERSION == 2
esp_err_t err = touch_pad_config(self->touchpad_id);
#endif
if (err == ESP_OK) {
#if SOC_TOUCH_VERSION_2
#if SOC_TOUCH_SENSOR_VERSION == 2
touch_pad_fsm_start();
#endif

Expand All @@ -115,10 +123,10 @@ static mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_

static mp_obj_t mtp_config(mp_obj_t self_in, mp_obj_t value_in) {
mtp_obj_t *self = self_in;
#if SOC_TOUCH_VERSION_1
#if SOC_TOUCH_SENSOR_VERSION == 1
uint16_t value = mp_obj_get_int(value_in);
esp_err_t err = touch_pad_config(self->touchpad_id, value);
#elif SOC_TOUCH_VERSION_2
#elif SOC_TOUCH_SENSOR_VERSION == 2
esp_err_t err = touch_pad_config(self->touchpad_id);
#endif
if (err == ESP_OK) {
Expand All @@ -130,10 +138,10 @@ MP_DEFINE_CONST_FUN_OBJ_2(mtp_config_obj, mtp_config);

static mp_obj_t mtp_read(mp_obj_t self_in) {
mtp_obj_t *self = self_in;
#if SOC_TOUCH_VERSION_1
#if SOC_TOUCH_SENSOR_VERSION == 1
uint16_t value;
esp_err_t err = touch_pad_read(self->touchpad_id, &value);
#elif SOC_TOUCH_VERSION_2
#elif SOC_TOUCH_SENSOR_VERSION == 2
uint32_t value;
esp_err_t err = touch_pad_read_raw_data(self->touchpad_id, &value);
#endif
Expand Down
7 changes: 6 additions & 1 deletion ports/esp32/network_wlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,14 +768,19 @@ static const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA3_EXT_PSK), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK) },
{ MP_ROM_QSTR(MP_QSTR_SEC_WPA3_EXT_PSK_MIXED_MODE), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE) },
#endif
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
{ MP_ROM_QSTR(MP_QSTR_SEC_DPP), MP_ROM_INT(WIFI_AUTH_DPP) },
#endif

{ MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(WIFI_PS_NONE) },
{ MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(WIFI_PS_MIN_MODEM) },
{ MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(WIFI_PS_MAX_MODEM) },
};
static MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
_Static_assert(WIFI_AUTH_MAX == 14, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types_generic.h");
#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
_Static_assert(WIFI_AUTH_MAX == 13, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2)
_Static_assert(WIFI_AUTH_MAX == 11, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h");
Expand Down
11 changes: 7 additions & 4 deletions ports/esp32/usb_serial_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@
#include "soc/periph_defs.h"
#include "freertos/portmacro.h"

#define USB_SERIAL_JTAG_BUF_SIZE (64)
// Number of bytes in the input buffer, and number of bytes for output chunking.
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
#define USB_SERIAL_JTAG_PACKET_SZ_BYTES (64)
#endif

static DRAM_ATTR portMUX_TYPE rx_mux = portMUX_INITIALIZER_UNLOCKED;
static uint8_t rx_buf[USB_SERIAL_JTAG_BUF_SIZE];
static uint8_t rx_buf[USB_SERIAL_JTAG_PACKET_SZ_BYTES];
static volatile bool terminal_connected = false;

static void usb_serial_jtag_handle_rx(void) {
Expand All @@ -48,8 +51,8 @@ static void usb_serial_jtag_handle_rx(void) {
portENTER_CRITICAL(&rx_mux);
}
size_t req_len = ringbuf_free(&stdin_ringbuf);
if (req_len > USB_SERIAL_JTAG_BUF_SIZE) {
req_len = USB_SERIAL_JTAG_BUF_SIZE;
if (req_len > USB_SERIAL_JTAG_PACKET_SZ_BYTES) {
req_len = USB_SERIAL_JTAG_PACKET_SZ_BYTES;
}
size_t len = usb_serial_jtag_ll_read_rxfifo(rx_buf, req_len);
for (size_t i = 0; i < len; ++i) {
Expand Down
Loading