-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/support_analog_comparator_on_p4' into 'master'
feat(ana_cmpr): supported analog comparator on esp32p4 Closes IDF-7479 See merge request espressif/esp-idf!24873
- Loading branch information
Showing
50 changed files
with
1,240 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "sdkconfig.h" | ||
#if CONFIG_ETM_ENABLE_DEBUG_LOG | ||
// The local log level must be defined before including esp_log.h | ||
// Set the maximum log level for this source file | ||
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG | ||
#endif | ||
#include "freertos/FreeRTOS.h" | ||
#include "esp_heap_caps.h" | ||
#include "esp_log.h" | ||
#include "esp_check.h" | ||
#include "soc/soc_caps.h" | ||
#include "hal/ana_cmpr_ll.h" | ||
#include "driver/ana_cmpr_types.h" | ||
#include "driver/ana_cmpr_etm.h" | ||
#include "esp_private/etm_interface.h" | ||
#include "ana_cmpr_private.h" | ||
|
||
static const char *TAG = "ana-cmpr-etm"; | ||
|
||
#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); | ||
event = NULL; | ||
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) | ||
{ | ||
#if CONFIG_ETM_ENABLE_DEBUG_LOG | ||
esp_log_level_set(TAG, ESP_LOG_DEBUG); | ||
#endif | ||
esp_err_t ret = ESP_OK; | ||
ana_cmpr_etm_event_t *event = NULL; | ||
ana_cmpr_unit_t unit = ana_cmpr_priv_get_unit_by_handle(cmpr); | ||
ESP_RETURN_ON_FALSE(((int)unit) >= 0, ESP_ERR_INVALID_ARG, TAG, "invalid analog comparator handle"); | ||
ESP_RETURN_ON_FALSE(config && ret_event, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); | ||
event = heap_caps_calloc(1, sizeof(ana_cmpr_etm_event_t), ETM_MEM_ALLOC_CAPS); | ||
ESP_GOTO_ON_FALSE(event, ESP_ERR_NO_MEM, err, TAG, "no mem for analog comparator event"); | ||
|
||
uint32_t event_id = ANALOG_CMPR_LL_ETM_SOURCE(unit, 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); | ||
*ret_event = &event->base; | ||
return ESP_OK; | ||
|
||
err: | ||
if (event) { | ||
free(event); | ||
event = NULL; | ||
} | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdbool.h> | ||
#include "driver/ana_cmpr_types.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
ana_cmpr_unit_t ana_cmpr_priv_get_unit_by_handle(ana_cmpr_handle_t cmpr); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
components/driver/analog_comparator/include/driver/ana_cmpr_etm.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdbool.h> | ||
#include "esp_err.h" | ||
#include "esp_etm.h" | ||
#include "driver/ana_cmpr_types.h" | ||
|
||
#if SOC_ANA_CMPR_SUPPORT_ETM | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief Analog Comparator ETM Events for each unit | ||
* | ||
*/ | ||
typedef enum { | ||
ANA_CMPR_EVENT_POS_CROSS, /*!< Positive cross event when the source signal becomes higher than the reference signal */ | ||
ANA_CMPR_EVENT_NEG_CROSS, /*!< Negative cross event when the source signal becomes lower than the reference signal */ | ||
} ana_cmpr_event_type_t; | ||
|
||
/** | ||
* @brief Analog Comparator ETM event configuration | ||
* | ||
*/ | ||
typedef struct { | ||
ana_cmpr_event_type_t event_type; /*!< Which kind of cross type can trigger the ETM event module */ | ||
} ana_cmpr_etm_event_config_t; | ||
|
||
/** | ||
* @brief Allocate a new Analog Comparator ETM event | ||
* | ||
* @param[in] cmpr Analog Comparator handle that allocated by `ana_cmpr_new_unit` | ||
* @param[in] config Analog Comparator ETM event configuration | ||
* @param[out] ret_event The returned generic handle of ETM event, which is used to connect to a task in the ETM driver | ||
* @return | ||
* - ESP_OK Success to create the new ETM event handle | ||
* - ESP_ERR_NO_MEM No memory for the ETM event | ||
* - ESP_ERR_INVALID_ARG NULL pointer of the input parameters | ||
* - ESP_ERR_INVALID_STATE The event on the unit has been registered | ||
*/ | ||
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); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // SOC_ANA_CMPR_SUPPORT_ETM |
Oops, something went wrong.