Files
esp-idf/components/esp_driver_ana_cmpr/ana_cmpr_etm.c
T
morris 45d2c0c486 feat(ana_cmpr): refactor driver implemnetation for new ip
esp32h4 and esp32s31 has a new IP design WRT the ana cmpr module
2026-04-19 21:47:30 +08:00

39 lines
1.4 KiB
C

/*
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "driver/ana_cmpr_etm.h"
#include "esp_private/etm_interface.h"
#include "ana_cmpr_private.h"
#define ETM_MEM_ALLOC_CAPS MALLOC_CAP_DEFAULT
typedef struct {
esp_etm_event_t base;
} ana_cmpr_etm_event_t;
static esp_err_t ana_cmpr_del_etm_event(esp_etm_event_handle_t base_event)
{
ana_cmpr_etm_event_t *event = __containerof(base_event, ana_cmpr_etm_event_t, base);
free(event);
return ESP_OK;
}
esp_err_t ana_cmpr_new_etm_event(ana_cmpr_handle_t cmpr, const ana_cmpr_etm_event_config_t *config, esp_etm_event_handle_t *ret_event)
{
ESP_RETURN_ON_FALSE(cmpr && config && ret_event, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
ana_cmpr_unit_t unit_id = cmpr->unit_id;
ana_cmpr_etm_event_t *event = heap_caps_calloc(1, sizeof(ana_cmpr_etm_event_t), ETM_MEM_ALLOC_CAPS);
ESP_RETURN_ON_FALSE(event, ESP_ERR_NO_MEM, TAG, "no mem for analog comparator event");
uint32_t event_id = ANALOG_CMPR_LL_ETM_SOURCE(unit_id, 0, config->event_type);
event->base.del = ana_cmpr_del_etm_event;
event->base.event_id = event_id;
event->base.trig_periph = ETM_TRIG_PERIPH_ANA_CMPR;
ESP_LOGD(TAG, "new event @%p, event_id=%"PRIu32", unit_id=%d", event, event_id, unit_id);
*ret_event = &event->base;
return ESP_OK;
}