anacmpr
Overview
The anacmpr peripheral type describes an on-chip analog comparator unit. BMGR generates an ana_cmpr_config_t from this configuration and calls the ESP-IDF driver/ana_cmpr.h to create the analog comparator unit.
After BMGR initialization, the application retrieves the periph_anacmpr_handle_t via esp_board_manager_get_periph_handle() and then uses the ESP-IDF analog comparator APIs to configure the internal reference, level-crossing callback, debounce, and start/stop actions.
Supported Operating Modes
anacmpr does not use role or format to split modes. The configuration axis is a single analog comparator unit.
Minimal Configuration
Analog Comparator Unit
See complete fields: Analog Comparator Unit — Full Fields.
board_peripherals.yaml:
peripherals:
- name: anacmpr_unit_0
type: anacmpr
config:
unit: 0
ref_src: ANA_CMPR_REF_SRC_INTERNAL
cross_type: ANA_CMPR_CROSS_ANY
clk_src: ANA_CMPR_CLK_SRC_DEFAULT
intr_priority: 0
Mode Description
anacmpr creates one analog comparator unit. ref_src selects the internal or external reference input, cross_type selects the crossing direction that triggers the event, and intr_priority configures the interrupt priority.
The current BMGR parser only accepts unit: 0. The internal reference voltage, debounce, and event callbacks are not configured in the peripheral YAML; they must be set by the application after obtaining the handle via the ESP-IDF analog comparator APIs.
Full Field Reference
Analog Comparator Unit — Full Fields
# Analog Comparator example with internal reference
- name: anacmpr_unit_0
type: anacmpr
config:
# Analog Comparator unit number, must be not less than 0 and less than 'SOC_ANA_CMPR_NUM' (default: 0)
# Please check the 'SOC_ANA_CMPR_NUM' in 'soc/soc_caps.h' for valid values
unit: 0 # [TO_BE_CONFIRMED] Analog Comparator unit
# Reference source type (default: ANA_CMPR_REF_SRC_INTERNAL)
ref_src: ANA_CMPR_REF_SRC_INTERNAL # [TO_BE_CONFIRMED] Reference source type
# Valid values:
# - ANA_CMPR_REF_SRC_INTERNAL: Use internal reference voltage (divided from VDD)
# - ANA_CMPR_REF_SRC_EXTERNAL: Use external reference from GPIO pin
# Cross type for interrupt triggering (default: ANA_CMPR_CROSS_ANY)
cross_type: ANA_CMPR_CROSS_ANY
# Valid values:
# - ANA_CMPR_CROSS_POS: Trigger on positive crossing (source > reference)
# - ANA_CMPR_CROSS_NEG: Trigger on negative crossing (source < reference)
# - ANA_CMPR_CROSS_ANY: Trigger on both positive and negative crossing
# - ANA_CMPR_CROSS_DISABLE: Disable crossing interrupt
# Clock source (default: ANA_CMPR_CLK_SRC_DEFAULT)
clk_src: ANA_CMPR_CLK_SRC_DEFAULT
# Valid values (chip-dependent, see soc_periph_ana_cmpr_clk_src_t):
# - ANA_CMPR_CLK_SRC_DEFAULT
# - ANA_CMPR_CLK_SRC_XTAL
# - ANA_CMPR_CLK_SRC_RC_FAST
# - ANA_CMPR_CLK_SRC_PLL_F48M
# - ANA_CMPR_CLK_SRC_PLL_F80M
# - ANA_CMPR_CLK_SRC_REF_F80M
# Interrupt priority (default: 0)
# If set to 0, the driver will automatically select a relative low priority (1,2,3)
intr_priority: 0
Field sources:
YAML template:
esp_board_manager/peripherals/periph_anacmpr/periph_anacmpr.yml.Header file:
esp_board_manager/peripherals/periph_anacmpr/periph_anacmpr.h.
Applicable Devices
device type |
Usage |
Notes |
|---|---|---|
Direct application use |
Application retrieves the analog comparator peripheral handle via |
No device type in the current repository references the |
Reference Code
esp_board_manager/test_apps/main/periph/test_periph_anacmpr.c
Board-Level Reference
esp_board_manager/test_apps/components/board_customer/boards/esp32_p4_core/board_peripherals.yaml:anacmpr_unit_0configuration, along withgpio_monitorfor observing crossing events during testing.
Notes
The current parser only accepts
unit: 0.ref_srconly acceptsANA_CMPR_REF_SRC_INTERNALorANA_CMPR_REF_SRC_EXTERNAL.cross_typeacceptsANA_CMPR_CROSS_POS,ANA_CMPR_CROSS_NEG,ANA_CMPR_CROSS_ANY, orANA_CMPR_CROSS_DISABLE.clk_srcvalues are chip-dependent; see the YAML comments above. Unknown names with theANA_CMPR_CLK_SRC_prefix are passed through.The internal reference voltage, debounce, and event callbacks must be configured in application code and must not be written into the
anacmprperipheralconfig.After modifying the analog comparator peripheral configuration, re-run
idf.py bmgr -b <board>.
Debugging Tips
API Reference
Use esp_board_manager_get_periph_handle() to retrieve the analog comparator peripheral handle. The handle type is periph_anacmpr_handle_t:
typedef struct {
ana_cmpr_handle_t cmpr_handle; /*!< Analog comparator handle */
ana_cmpr_unit_t unit; /*!< Analog comparator unit */
} periph_anacmpr_handle_t;
cmpr_handle can be passed to the ESP-IDF ana_cmpr_* APIs. unit identifies the current comparator controller number.
Related declarations are in esp_board_manager/peripherals/periph_anacmpr/periph_anacmpr.h.
Underlying ESP-IDF driver documentation: Analog Comparator.