From dd44195481659bb0c526dcc3cca626728a388c19 Mon Sep 17 00:00:00 2001 From: Tiago Medicci Date: Wed, 15 Jul 2026 14:02:27 -0300 Subject: [PATCH] fix(ana_cmpr): Fix swapped POS/NEG cross interrupt masks on ESP32-C5/P4/C61 In components/soc/esp32c5/register/soc/gpio_ext_struct.h (ESP32-C5), components/soc/esp32c61/register/soc/gpio_ext_struct.h (ESP32-C61), and components/soc/esp32p4/register/hw_ver3/soc/gpio_struct.h (ESP32-P4), the analog comparator raw/status/enable/clear register fields are named comp_neg_0_*/comp0_neg_* for bit 0 and comp_pos_0_*/comp0_pos_* for bit 1, but each field's own comment says the opposite: bit 0 is documented as "analog comparator pos edge interrupt raw/status/enable/clear" and bit 1 as the "neg" counterpart. The LL masks were defined from the field names rather than from this documented behavior, so ANALOG_CMPR_LL_POS_CROSS_INTR_MASK() ended up selecting bit 1 and ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK() bit 0. A new test case, added in the following commit, arms only one cross direction at a time and checks that a matching transition fires the callback while the opposite, never-armed direction does not; without this fix it reproducibly fails on ESP32-C5, ESP32-P4, and ESP32-C61. Signed-off-by: Tiago Medicci --- .../esp_hal_ana_cmpr/esp32c5/include/hal/ana_cmpr_ll.h | 6 +++--- .../esp_hal_ana_cmpr/esp32c61/include/hal/ana_cmpr_ll.h | 6 +++--- .../esp_hal_ana_cmpr/esp32p4/include/hal/ana_cmpr_ll.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/components/esp_hal_ana_cmpr/esp32c5/include/hal/ana_cmpr_ll.h b/components/esp_hal_ana_cmpr/esp32c5/include/hal/ana_cmpr_ll.h index e98fe461c0d..7553db94eb3 100644 --- a/components/esp_hal_ana_cmpr/esp32c5/include/hal/ana_cmpr_ll.h +++ b/components/esp_hal_ana_cmpr/esp32c5/include/hal/ana_cmpr_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -37,8 +37,8 @@ extern "C" { #define ANALOG_CMPR_LL_GET_HW(unit) (&ANALOG_CMPR[unit]) -#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) 0x01 -#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) 0x02 +#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) 0x02 +#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) 0x01 #define ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan)) #define ANALOG_CMPR_LL_ALL_INTR_MASK(unit) 0x07 diff --git a/components/esp_hal_ana_cmpr/esp32c61/include/hal/ana_cmpr_ll.h b/components/esp_hal_ana_cmpr/esp32c61/include/hal/ana_cmpr_ll.h index 8db001d82fb..b952bcd0890 100644 --- a/components/esp_hal_ana_cmpr/esp32c61/include/hal/ana_cmpr_ll.h +++ b/components/esp_hal_ana_cmpr/esp32c61/include/hal/ana_cmpr_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -37,8 +37,8 @@ extern "C" { #define ANALOG_CMPR_LL_GET_HW(unit) (&ANALOG_CMPR[unit]) -#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) 0x01 -#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) 0x02 +#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) 0x02 +#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) 0x01 #define ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan)) #define ANALOG_CMPR_LL_ALL_INTR_MASK(unit) 0x07 diff --git a/components/esp_hal_ana_cmpr/esp32p4/include/hal/ana_cmpr_ll.h b/components/esp_hal_ana_cmpr/esp32p4/include/hal/ana_cmpr_ll.h index 5d8d2733c0f..138ba8ac0d8 100644 --- a/components/esp_hal_ana_cmpr/esp32p4/include/hal/ana_cmpr_ll.h +++ b/components/esp_hal_ana_cmpr/esp32p4/include/hal/ana_cmpr_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -38,8 +38,8 @@ extern "C" { #define ANALOG_CMPR_LL_GET_HW(unit) (&ANALOG_CMPR[unit]) #define ANALOG_CMPR_LL_GET_UNIT(hw) ((hw) == (&ANALOG_CMPR[0]) ? 0 : 1) -#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) (1UL << ((unit) * 3 + 0)) -#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) (1UL << ((unit) * 3 + 1)) +#define ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) (1UL << ((unit) * 3 + 1)) +#define ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan) (1UL << ((unit) * 3 + 0)) #define ANALOG_CMPR_LL_ANY_CROSS_INTR_MASK(unit, src_chan) (ANALOG_CMPR_LL_NEG_CROSS_INTR_MASK(unit, src_chan) | ANALOG_CMPR_LL_POS_CROSS_INTR_MASK(unit, src_chan)) #define ANALOG_CMPR_LL_ALL_INTR_MASK(unit) (0x07 << ((unit) * 3))