mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-26 12:50:30 +00:00
Merge branch 'feature/adc_driver_ng' into 'master'
ADC Driver NG Closes IDF-4560, IDF-3908, IDF-4225, IDF-2482, IDF-4111, IDF-3610, IDF-4058, IDF-3801, IDF-3636, IDF-2537, IDF-4310, IDF-5150, IDF-5151, and IDF-4979 See merge request espressif/esp-idf!17960
This commit is contained in:
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// The HAL layer for ADC (ESP32-C3 specific part)
|
||||
|
||||
#include <string.h>
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/adc_hal.h"
|
||||
#include "hal/adc_types.h"
|
||||
#include "soc/soc.h"
|
||||
|
||||
//Currently we don't have context for the ADC HAL. So HAL variables are temporarily put here. But
|
||||
//please don't follow this code. Create a context for your own HAL!
|
||||
|
||||
static bool s_filter_enabled[SOC_ADC_DIGI_FILTER_NUM] = {};
|
||||
static adc_digi_filter_t s_filter[SOC_ADC_DIGI_FILTER_NUM] = {};
|
||||
|
||||
static bool s_monitor_enabled[SOC_ADC_DIGI_MONITOR_NUM] = {};
|
||||
static adc_digi_monitor_t s_monitor_config[SOC_ADC_DIGI_MONITOR_NUM] = {};
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
Digital controller setting
|
||||
---------------------------------------------------------------*/
|
||||
static void filter_update(adc_digi_filter_idx_t idx)
|
||||
{
|
||||
//ESP32-C3 has no enable bit, the filter will be enabled when the filter channel is configured
|
||||
if (s_filter_enabled[idx]) {
|
||||
adc_ll_digi_filter_set_factor(idx, &s_filter[idx]);
|
||||
} else {
|
||||
adc_ll_digi_filter_disable(idx);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set adc digital controller filter factor.
|
||||
*
|
||||
* @param idx ADC filter unit.
|
||||
* @param filter Filter config. Expression: filter_data = (k-1)/k * last_data + new_data / k. Set values: (2, 4, 8, 16, 64).
|
||||
*/
|
||||
void adc_hal_digi_filter_set_factor(adc_digi_filter_idx_t idx, adc_digi_filter_t *filter)
|
||||
{
|
||||
s_filter[idx] = *filter;
|
||||
filter_update(idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get adc digital controller filter factor.
|
||||
*
|
||||
* @param adc_n ADC unit.
|
||||
* @param factor Expression: filter_data = (k-1)/k * last_data + new_data / k. Set values: (2, 4, 8, 16, 64).
|
||||
*/
|
||||
void adc_hal_digi_filter_get_factor(adc_digi_filter_idx_t idx, adc_digi_filter_t *filter)
|
||||
{
|
||||
*filter = s_filter[idx];
|
||||
}
|
||||
|
||||
void adc_hal_digi_filter_enable(adc_digi_filter_idx_t filter_idx, bool enable)
|
||||
{
|
||||
s_filter_enabled[filter_idx] = enable;
|
||||
filter_update(filter_idx);
|
||||
}
|
||||
|
||||
static void update_monitor(adc_digi_monitor_idx_t idx)
|
||||
{
|
||||
//ESP32-C3 has no enable bit, the monitor will be enabled when the monitor channel is configured
|
||||
if (s_monitor_enabled[idx]) {
|
||||
adc_ll_digi_monitor_set_mode(idx, &s_monitor_config[idx]);
|
||||
} else {
|
||||
adc_ll_digi_monitor_disable(idx);
|
||||
}
|
||||
}
|
||||
|
||||
void adc_hal_digi_monitor_config(adc_digi_monitor_idx_t idx, adc_digi_monitor_t *config)
|
||||
{
|
||||
s_monitor_config[idx] = *config;
|
||||
update_monitor(idx);
|
||||
}
|
||||
|
||||
void adc_hal_digi_monitor_enable(adc_digi_monitor_idx_t mon_idx, bool enable)
|
||||
{
|
||||
s_monitor_enabled[mon_idx] = enable;
|
||||
update_monitor(mon_idx);
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
* The hal is not public api, don't use in application code.
|
||||
* See readme.md in soc/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
// The HAL layer for ADC (esp32s2 specific part)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/adc_ll.h"
|
||||
#include "hal/adc_types.h"
|
||||
|
||||
#include_next "hal/adc_hal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
Digital controller setting
|
||||
---------------------------------------------------------------*/
|
||||
/**
|
||||
* Reset adc digital controller filter.
|
||||
*
|
||||
* @param filter_idx ADC filter unit.
|
||||
*/
|
||||
#define adc_hal_digi_filter_reset(filter_idx) adc_ll_digi_filter_reset(filter_idx)
|
||||
|
||||
/**
|
||||
* Set adc digital controller filter factor.
|
||||
*
|
||||
* @param filter_idx ADC filter unit.
|
||||
* @param filter Filter config. Expression: filter_data = (k-1)/k * last_data + new_data / k. Set values: (2, 4, 8, 16, 64).
|
||||
*/
|
||||
void adc_hal_digi_filter_set_factor(adc_digi_filter_idx_t filter_idx, adc_digi_filter_t *filter);
|
||||
|
||||
/**
|
||||
* Get adc digital controller filter factor.
|
||||
*
|
||||
* @param filter_idx ADC filter unit.
|
||||
* @param factor Expression: filter_data = (k-1)/k * last_data + new_data / k. Set values: (2, 4, 8, 16, 64).
|
||||
*/
|
||||
void adc_hal_digi_filter_get_factor(adc_digi_filter_idx_t filter_idx, adc_digi_filter_t *filter);
|
||||
|
||||
/**
|
||||
* Enable/disable adc digital controller filter.
|
||||
* Filtering the ADC data to obtain smooth data at higher sampling rates.
|
||||
*
|
||||
* @note The filter will filter all the enabled channel data of the each ADC unit at the same time.
|
||||
* @param filter_idx ADC filter unit.
|
||||
* @param enable True to enable the filter, otherwise disable.
|
||||
*/
|
||||
void adc_hal_digi_filter_enable(adc_digi_filter_idx_t filter_idx, bool enable);
|
||||
|
||||
/**
|
||||
* Config monitor of adc digital controller.
|
||||
*
|
||||
* @note If the channel info is not supported, the monitor function will not be enabled.
|
||||
* @param mon_idx ADC monitor index.
|
||||
* @param config Refer to `adc_digi_monitor_t`.
|
||||
*/
|
||||
void adc_hal_digi_monitor_config(adc_digi_monitor_idx_t mon_idx, adc_digi_monitor_t *config);
|
||||
|
||||
/**
|
||||
* Enable/disable monitor of adc digital controller.
|
||||
*
|
||||
* @note The monitor will monitor all the enabled channel data of the each ADC unit at the same time.
|
||||
* @param mon_idx ADC monitor index.
|
||||
* @param enable True to enable the monitor, otherwise disable.
|
||||
*/
|
||||
void adc_hal_digi_monitor_enable(adc_digi_monitor_idx_t mon_idx, bool enable);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -26,9 +26,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ADC_LL_CLKM_DIV_NUM_DEFAULT 15
|
||||
#define ADC_LL_CLKM_DIV_B_DEFAULT 1
|
||||
#define ADC_LL_CLKM_DIV_A_DEFAULT 0
|
||||
#define ADC_LL_CLKM_DIV_NUM_DEFAULT 15
|
||||
#define ADC_LL_CLKM_DIV_B_DEFAULT 1
|
||||
#define ADC_LL_CLKM_DIV_A_DEFAULT 0
|
||||
#define ADC_LL_DEFAULT_CONV_LIMIT_EN 0
|
||||
#define ADC_LL_DEFAULT_CONV_LIMIT_NUM 10
|
||||
|
||||
#define ADC_LL_EVENT_ADC1_ONESHOT_DONE BIT(31)
|
||||
#define ADC_LL_EVENT_ADC2_ONESHOT_DONE BIT(30)
|
||||
@@ -140,19 +142,12 @@ static inline void adc_ll_digi_set_convert_limit_num(uint32_t meas_num)
|
||||
/**
|
||||
* Enable max conversion number detection for digital controller.
|
||||
* If the number of ADC conversion is equal to the maximum, the conversion is stopped.
|
||||
*
|
||||
* @param enable true: enable; false: disable
|
||||
*/
|
||||
static inline void adc_ll_digi_convert_limit_enable(void)
|
||||
static inline void adc_ll_digi_convert_limit_enable(bool enable)
|
||||
{
|
||||
APB_SARADC.ctrl2.meas_num_limit = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable max conversion number detection for digital controller.
|
||||
* If the number of ADC conversion is equal to the maximum, the conversion is stopped.
|
||||
*/
|
||||
static inline void adc_ll_digi_convert_limit_disable(void)
|
||||
{
|
||||
APB_SARADC.ctrl2.meas_num_limit = 0;
|
||||
APB_SARADC.ctrl2.meas_num_limit = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -710,7 +705,7 @@ static inline void adc_ll_vref_output(adc_unit_t adc, adc_channel_t channel, boo
|
||||
static inline void adc_oneshot_ll_set_output_bits(adc_unit_t adc_n, adc_bitwidth_t bits)
|
||||
{
|
||||
//ESP32C3 only supports 12bit, leave here for compatibility
|
||||
HAL_ASSERT(bits == ADC_BITWIDTH_12);
|
||||
HAL_ASSERT(bits == ADC_BITWIDTH_12 || bits == ADC_BITWIDTH_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -873,6 +868,20 @@ static inline void adc_oneshot_ll_set_atten(adc_unit_t adc_n, adc_channel_t chan
|
||||
APB_SARADC.onetime_sample.onetime_atten = atten;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attenuation of a particular channel on ADCn.
|
||||
*
|
||||
* @param adc_n ADC unit.
|
||||
* @param channel ADCn channel number.
|
||||
* @return atten The attenuation option.
|
||||
*/
|
||||
static inline adc_atten_t adc_ll_get_atten(adc_unit_t adc_n, adc_channel_t channel)
|
||||
{
|
||||
(void)adc_n;
|
||||
(void)channel;
|
||||
return APB_SARADC.onetime_sample.onetime_atten;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user