From a84cec9c1589f4eefb7963d4336b4502fad17965 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 17 Jun 2026 13:25:59 -0400 Subject: [PATCH 1/4] Turn on PDMIn on ESP32. Update limitations doc for PDMIn and TouchAlarm. Improve option handling in espressif/mpconfigport.mk. --- ports/espressif/mpconfigport.mk | 41 ++++++++++++++++++------ shared-bindings/alarm/touch/TouchAlarm.c | 1 + shared-bindings/audiobusio/PDMIn.c | 2 +- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index 2f16a90d8a2d5..33a989ae970dc 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -64,10 +64,10 @@ CIRCUITPY_LIBC_STRING0 = 0 # These modules are implemented in ports//common-hal: CIRCUITPY__EVE ?= 1 CIRCUITPY_ALARM ?= 1 -CIRCUITPY_ALARM_TOUCH ?= 0 +CIRCUITPY_ALARM_TOUCH ?= 1 CIRCUITPY_ANALOGBUFIO ?= 1 CIRCUITPY_AUDIOBUSIO ?= 1 -CIRCUITPY_AUDIOBUSIO_PDMIN ?= 0 +CIRCUITPY_AUDIOBUSIO_PDMIN ?= 1 CIRCUITPY_AUDIOI2SIN ?= 1 CIRCUITPY_AUDIOIO ?= 1 CIRCUITPY_BLEIO_HCI = 0 @@ -80,7 +80,7 @@ CIRCUITPY_ESPULP ?= 1 CIRCUITPY_FRAMEBUFFERIO ?= 1 CIRCUITPY_FREQUENCYIO ?= 1 CIRCUITPY_HASHLIB ?= 1 -CIRCUITPY_I2CTARGET ?= 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_MAX3421E ?= 1 CIRCUITPY_MEMORYMAP ?= 1 CIRCUITPY_RCLCPY ?= 0 @@ -101,7 +101,6 @@ CIRCUITPY_SOCKETPOOL_IPV6 ?= 1 #### esp32 ############################################################ ifeq ($(IDF_TARGET),esp32) # Modules -CIRCUITPY_ALARM_TOUCH = 1 CIRCUITPY_RGBMATRIX = 0 # Has no USB @@ -117,6 +116,9 @@ CIRCUITPY_ESPCAMERA = 0 CIRCUITPY_ESPULP = 0 CIRCUITPY_MEMORYMAP = 0 +# No capacitive touch peripheral +CIRCUITPY_ALARM_TOUCH = 0 + # No I80 support from the IDF CIRCUITPY_PARALLELDISPLAYBUS = 0 @@ -162,9 +164,15 @@ CIRCUITPY_MEMORYMAP = 0 # No I80 support from the IDF CIRCUITPY_PARALLELDISPLAYBUS = 0 +# No capacitive touch peripheral +CIRCUITPY_ALARM_TOUCH = 0 + # No DAC CIRCUITPY_AUDIOIO = 0 +# No I2S peripheral PDM-to-PCM hardware support +CIRCUITPY_AUDIOBUSIO_PDMIN = 0 + # No PCNT peripheral CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_COUNTIO = 0 @@ -187,9 +195,15 @@ CIRCUITPY_ESPULP = 0 CIRCUITPY_MEMORYMAP = 0 CIRCUITPY_RGBMATRIX = 0 +# No capacitive touch peripheral +CIRCUITPY_ALARM_TOUCH = 0 + # No DAC CIRCUITPY_AUDIOIO = 0 +# No I2S peripheral PDM-to-PCM hardware support +CIRCUITPY_AUDIOBUSIO_PDMIN = 0 + # No space for this CIRCUITPY_AUDIOBUSIO = 0 @@ -213,6 +227,9 @@ CIRCUITPY_ESPULP = 0 CIRCUITPY_MEMORYMAP = 0 CIRCUITPY_RGBMATRIX = 0 +# No capacitive touch peripheral +CIRCUITPY_ALARM_TOUCH = 0 + # No DAC CIRCUITPY_AUDIOIO = 0 @@ -252,9 +269,15 @@ CIRCUITPY_ESPULP = 0 CIRCUITPY_MEMORYMAP = 0 CIRCUITPY_RGBMATRIX = 0 +# No capacitive touch peripheral +CIRCUITPY_ALARM_TOUCH = 0 + # No DAC CIRCUITPY_AUDIOIO = 0 +# No I2S peripheral PDM-to-PCM hardware support +CIRCUITPY_AUDIOBUSIO_PDMIN = 0 + # No I80 support from the IDF CIRCUITPY_PARALLELDISPLAYBUS = 0 @@ -283,7 +306,7 @@ CIRCUITPY_BLEIO_NATIVE = 0 CIRCUITPY_WIFI = 0 CIRCUITPY_SSL = 0 -CIRCUITPY_TOUCHIO = 1 +CIRCUITPY_TOUCHIO ?= 1 CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # Second stage bootloader doesn't work when the factory partition is empty due to @@ -316,9 +339,11 @@ CIRCUITPY_MIPIDSI = 1 #### esp32s2 ########################################################## else ifeq ($(IDF_TARGET),esp32s2) # Modules -CIRCUITPY_ALARM_TOUCH = $(CIRCUITPY_ALARM) CIRCUITPY_AUDIOIO ?= 1 +# No I2S peripheral PDM-to-PCM hardware support +CIRCUITPY_AUDIOBUSIO_PDMIN = 0 + # No BLE in hw CIRCUITPY_BLEIO_NATIVE = 0 @@ -331,8 +356,6 @@ CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 0 else ifeq ($(IDF_TARGET),esp32s3) # Modules -CIRCUITPY_ALARM_TOUCH = $(CIRCUITPY_ALARM) -CIRCUITPY_AUDIOBUSIO_PDMIN = 1 CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 0 # No DAC @@ -342,7 +365,7 @@ endif #### end chip-specific choices ######################################## # By default, enable dualbank, and it'll be disabled for small flash sizes -CIRCUITPY_DUALBANK = 1 +CIRCUITPY_DUALBANK ?= 1 # No room for large modules on 2MB boards # 2MB boards have a single firmware partition, and can't do dualbank. diff --git a/shared-bindings/alarm/touch/TouchAlarm.c b/shared-bindings/alarm/touch/TouchAlarm.c index 42b149c9eeea7..eac3f37b8f410 100644 --- a/shared-bindings/alarm/touch/TouchAlarm.c +++ b/shared-bindings/alarm/touch/TouchAlarm.c @@ -21,6 +21,7 @@ //| may be limited due to hardware restrictions, particularly for deep-sleep alarms. //| //| **Limitations:** Not available on SAMD, Nordic, or RP2040. +//| On Espressif, only available on ESP32, ESP32-S2, ESP32-S3, and ESP32-P4. //| """ //| ... //| diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c index 092897a15cff3..aba8a019f3539 100644 --- a/shared-bindings/audiobusio/PDMIn.c +++ b/shared-bindings/audiobusio/PDMIn.c @@ -48,7 +48,7 @@ //| //| **Limitations:** On SAMD and RP2040, supports only 8 or 16 bit mono input, with 64x oversampling. //| On nRF52840, supports only 16 bit mono input at 16 kHz; oversampling is fixed at 64x. Not provided -//| on nRF52833 for space reasons. Not available on Espressif. +//| on nRF52833 for space reasons. On Espressif, only available on ESP32, ESP32-S3, and ESP32-P4. //| //| For example, to record 8-bit unsigned samples to a buffer:: //| From 48bad18db9d22a2968975130d23f6de7cf2e3a88 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 17 Jun 2026 15:13:27 -0400 Subject: [PATCH 2/4] espressif: handle SOC_TOUCH_SENSOR_VERSION == 3 (ESP32-P4 and other newer chips) --- ports/espressif/common-hal/alarm/touch/TouchAlarm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ports/espressif/common-hal/alarm/touch/TouchAlarm.c b/ports/espressif/common-hal/alarm/touch/TouchAlarm.c index 617f7632e63db..93756b3c2ca34 100644 --- a/ports/espressif/common-hal/alarm/touch/TouchAlarm.c +++ b/ports/espressif/common-hal/alarm/touch/TouchAlarm.c @@ -125,12 +125,19 @@ void alarm_touch_touchalarm_set_alarm(const bool deep_sleep, const size_t n_alar .init_charge_volt = TOUCH_INIT_CHARGE_VOLT_DEFAULT, .group = TOUCH_CHAN_TRIG_GROUP_BOTH, }; - #else + #elif SOC_TOUCH_SENSOR_VERSION == 2 touch_channel_config_t chan_cfg = { .active_thresh = {(uint32_t)(benchmark / 10)}, .charge_speed = TOUCH_CHARGE_SPEED_7, .init_charge_volt = TOUCH_INIT_CHARGE_VOLT_DEFAULT, }; + #elif SOC_TOUCH_SENSOR_VERSION == 3 + // Values are similar to an ESP-IDF example: 1000, 2500, 5000. + touch_channel_config_t chan_cfg = { + .active_thresh = {(uint32_t)(benchmark / 10), (uint32_t)(benchmark / 4), (uint32_t)(benchmark / 2)}, + }; + #else + #error bad SOC_TOUCH_SENSOR_VERSION #endif touch_sensor_reconfig_channel(chan, &chan_cfg); } From b9602c70a74404b16daf86027feb06ef5e49f9ac Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 17 Jun 2026 16:24:42 -0400 Subject: [PATCH 3/4] fix up touchio compile flags --- ports/espressif/mpconfigport.mk | 20 ++++++-------------- ports/espressif/peripherals/touch.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index 33a989ae970dc..310743063f400 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -92,6 +92,7 @@ CIRCUITPY_ROTARYIO ?= 1 CIRCUITPY_SDIOIO ?= 1 CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY ?= 1 CIRCUITPY_SYNTHIO_MAX_CHANNELS ?= 12 +CIRCUITPY_TOUCHIO ?= 1 CIRCUITPY_TOUCHIO_USE_NATIVE ?= 1 CIRCUITPY_WATCHDOG ?= 1 CIRCUITPY_WIFI ?= 1 @@ -118,6 +119,7 @@ CIRCUITPY_MEMORYMAP = 0 # No capacitive touch peripheral CIRCUITPY_ALARM_TOUCH = 0 +CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # No I80 support from the IDF CIRCUITPY_PARALLELDISPLAYBUS = 0 @@ -148,8 +150,6 @@ CIRCUITPY_RGBMATRIX = 0 # No SDMMC CIRCUITPY_SDIOIO = 0 -CIRCUITPY_TOUCHIO ?= 1 -CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # Features CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG = 0 @@ -166,6 +166,7 @@ CIRCUITPY_PARALLELDISPLAYBUS = 0 # No capacitive touch peripheral CIRCUITPY_ALARM_TOUCH = 0 +CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # No DAC CIRCUITPY_AUDIOIO = 0 @@ -181,8 +182,6 @@ CIRCUITPY_ROTARYIO = 0 # No SDMMC CIRCUITPY_SDIOIO = 0 -CIRCUITPY_TOUCHIO ?= 1 -CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # Features CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 @@ -197,6 +196,7 @@ CIRCUITPY_RGBMATRIX = 0 # No capacitive touch peripheral CIRCUITPY_ALARM_TOUCH = 0 +CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # No DAC CIRCUITPY_AUDIOIO = 0 @@ -213,8 +213,6 @@ CIRCUITPY_PARALLELDISPLAYBUS = 0 # No SDMMC CIRCUITPY_SDIOIO = 0 -CIRCUITPY_TOUCHIO ?= 1 -CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # Features CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 @@ -229,6 +227,7 @@ CIRCUITPY_RGBMATRIX = 0 # No capacitive touch peripheral CIRCUITPY_ALARM_TOUCH = 0 +CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # No DAC CIRCUITPY_AUDIOIO = 0 @@ -242,8 +241,6 @@ CIRCUITPY_PARALLELDISPLAYBUS = 0 # No SDMMC CIRCUITPY_SDIOIO = 0 -CIRCUITPY_TOUCHIO ?= 1 -CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # Features CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 @@ -271,6 +268,7 @@ CIRCUITPY_RGBMATRIX = 0 # No capacitive touch peripheral CIRCUITPY_ALARM_TOUCH = 0 +CIRCUITPY_TOUCHIO_USE_NATIVE = 0 # No DAC CIRCUITPY_AUDIOIO = 0 @@ -284,9 +282,6 @@ CIRCUITPY_PARALLELDISPLAYBUS = 0 # No SDMMC CIRCUITPY_SDIOIO = 0 -CIRCUITPY_TOUCHIO ?= 1 -CIRCUITPY_TOUCHIO_USE_NATIVE = 0 - # Features CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 @@ -306,9 +301,6 @@ CIRCUITPY_BLEIO_NATIVE = 0 CIRCUITPY_WIFI = 0 CIRCUITPY_SSL = 0 -CIRCUITPY_TOUCHIO ?= 1 -CIRCUITPY_TOUCHIO_USE_NATIVE = 0 - # Second stage bootloader doesn't work when the factory partition is empty due to # UF2 missing. UF2_BOOTLOADER = 0 diff --git a/ports/espressif/peripherals/touch.c b/ports/espressif/peripherals/touch.c index 1084a030ec87c..e53a38c313b23 100644 --- a/ports/espressif/peripherals/touch.c +++ b/ports/espressif/peripherals/touch.c @@ -74,6 +74,8 @@ void peripherals_touch_init(const int channel_id) { touch_sensor_sample_config_t sample_cfg = TOUCH_SENSOR_V2_DEFAULT_SAMPLE_CONFIG(500, TOUCH_VOLT_LIM_L_0V5, TOUCH_VOLT_LIM_H_2V2); #elif SOC_TOUCH_SENSOR_VERSION == 3 touch_sensor_sample_config_t sample_cfg = TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG2(3, 29, 8, 3); + #else + #error bad SOC_TOUCH_SENSOR_VERSION #endif touch_sensor_config_t sens_cfg = TOUCH_SENSOR_DEFAULT_BASIC_CONFIG(1, &sample_cfg); touch_sensor_new_controller(&sens_cfg, &touch_controller); @@ -86,12 +88,19 @@ void peripherals_touch_init(const int channel_id) { .init_charge_volt = TOUCH_INIT_CHARGE_VOLT_DEFAULT, .group = TOUCH_CHAN_TRIG_GROUP_BOTH, }; - #else + #elif SOC_TOUCH_SENSOR_VERSION == 2 touch_channel_config_t chan_cfg = { .active_thresh = {2000}, .charge_speed = TOUCH_CHARGE_SPEED_7, .init_charge_volt = TOUCH_INIT_CHARGE_VOLT_DEFAULT, }; + #elif SOC_TOUCH_SENSOR_VERSION == 3 + // Values are similar to an ESP-IDF example: 1000, 2500, 5000. + touch_channel_config_t chan_cfg = { + .active_thresh = {1000, 2000, 5000}, + }; + #else + #error bad SOC_TOUCH_SENSOR_VERSION #endif touch_sensor_new_channel(touch_controller, channel_id, &chan_cfg, &touch_channels[idx]); From 704fe543e466c805c4e658ca7febe6b20ff18f52 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 17 Jun 2026 19:43:04 -0400 Subject: [PATCH 4/4] peripherals/touch.c: update for ESP32-P4 --- ports/espressif/peripherals/touch.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ports/espressif/peripherals/touch.c b/ports/espressif/peripherals/touch.c index e53a38c313b23..f55c16d396969 100644 --- a/ports/espressif/peripherals/touch.c +++ b/ports/espressif/peripherals/touch.c @@ -119,19 +119,29 @@ uint16_t peripherals_touch_read(int channel_id) { } uint32_t touch_value = 0; - touch_channel_read_data(touch_channels[idx], TOUCH_CHAN_DATA_TYPE_RAW, &touch_value); #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32 touch reads a lower value when touched. // Flip the values to be consistent with TouchIn assumptions. + touch_channel_read_data(touch_channels[idx], TOUCH_CHAN_DATA_TYPE_RAW, &touch_value); if (touch_value > UINT16_MAX) { return 0; } return UINT16_MAX - (uint16_t)touch_value; - #else + touch_channel_read_data(touch_channels[idx], TOUCH_CHAN_DATA_TYPE_RAW, &touch_value); + return UINT16_MAX - (uint16_t)touch_value; + #elif SOC_TOUCH_SENSOR_VERSION == 2 if (touch_value > UINT16_MAX) { return UINT16_MAX; } return (uint16_t)touch_value; + #elif SOC_TOUCH_SENSOR_VERSION == 3 + touch_channel_read_data(touch_channels[idx], TOUCH_CHAN_DATA_TYPE_SMOOTH, &touch_value); + if (touch_value > UINT16_MAX) { + return UINT16_MAX; + } + return (uint16_t)touch_value; + #else + #error bad SOC_TOUCH_SENSOR_VERSION #endif }