mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-03 10:30:58 +02:00
Merge branch 'feat/allow-adc-unit-2-ulp' into 'master'
feat(ulp): Allow usage of ADC unit 2 on RISCV co processor Closes IDFGH-16376 See merge request espressif/esp-idf!41863
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -15,38 +15,37 @@
|
||||
#include "esp_private/adc_share_hw_ctrl.h"
|
||||
|
||||
static const char *TAG = "ulp_adc";
|
||||
static adc_oneshot_unit_handle_t s_adc1_handle = NULL;
|
||||
static adc_oneshot_unit_handle_t s_adc_handle = NULL;
|
||||
|
||||
esp_err_t ulp_adc_init(const ulp_adc_cfg_t *cfg)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ESP_RETURN_ON_FALSE(cfg, ESP_ERR_INVALID_ARG, TAG, "cfg == NULL");
|
||||
ESP_RETURN_ON_FALSE(cfg->adc_n == ADC_UNIT_1, ESP_ERR_INVALID_ARG, TAG, "Only ADC_UNIT_1 is supported for now");
|
||||
|
||||
//-------------ADC1 Init---------------//
|
||||
adc_oneshot_unit_init_cfg_t init_config1 = {
|
||||
adc_oneshot_unit_init_cfg_t init_config = {
|
||||
.unit_id = cfg->adc_n,
|
||||
.ulp_mode = cfg->ulp_mode,
|
||||
};
|
||||
|
||||
if (init_config1.ulp_mode == ADC_ULP_MODE_DISABLE) {
|
||||
if (init_config.ulp_mode == ADC_ULP_MODE_DISABLE) {
|
||||
/* Default to RISCV for backward compatibility */
|
||||
ESP_LOGI(TAG, "No ulp mode specified in cfg struct, default to riscv");
|
||||
init_config1.ulp_mode = ADC_ULP_MODE_RISCV;
|
||||
init_config.ulp_mode = ADC_ULP_MODE_RISCV;
|
||||
}
|
||||
|
||||
ret = adc_oneshot_new_unit(&init_config1, &s_adc1_handle);
|
||||
ret = adc_oneshot_new_unit(&init_config, &s_adc_handle);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
//-------------ADC1 Config---------------//
|
||||
//-------------ADC Config---------------//
|
||||
adc_oneshot_chan_cfg_t config = {
|
||||
.bitwidth = cfg->width,
|
||||
.atten = cfg->atten,
|
||||
};
|
||||
ret = adc_oneshot_config_channel(s_adc1_handle, cfg->channel, &config);
|
||||
ret = adc_oneshot_config_channel(s_adc_handle, cfg->channel, &config);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
@@ -62,5 +61,5 @@ esp_err_t ulp_adc_init(const ulp_adc_cfg_t *cfg)
|
||||
esp_err_t ulp_adc_deinit(void)
|
||||
{
|
||||
// No need to check for null-pointer and stuff, oneshot driver already does that
|
||||
return adc_oneshot_del_unit(s_adc1_handle);
|
||||
return adc_oneshot_del_unit(s_adc_handle);
|
||||
}
|
||||
|
@@ -18,8 +18,10 @@ extern "C" {
|
||||
*
|
||||
* @note Will block until the conversion is completed
|
||||
*
|
||||
* @note ADC should be initilized for ULP by main CPU by calling ulp_riscv_adc_init()
|
||||
* @note ADC should be initialized for ULP by main CPU by calling ulp_riscv_adc_init()
|
||||
* before calling this.
|
||||
* @note When using ADC_UNIT_2, the caller must ensure that no other module (e.g., Wi-Fi or BT)
|
||||
* is accessing the ADC, as conflicts may lead to undefined behavior.
|
||||
*
|
||||
* @param adc_n ADC unit.
|
||||
* @param channel ADC channel number.
|
||||
|
Reference in New Issue
Block a user