mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-27 18:32:54 +00:00
adc: create common adc hal layer
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "hal/misc.h"
|
||||
#include "hal/adc_types.h"
|
||||
#include "hal/adc_types_private.h"
|
||||
|
||||
#include "esp_private/regi2c_ctrl.h"
|
||||
#include "regi2c_saradc.h"
|
||||
@@ -28,6 +29,8 @@ extern "C" {
|
||||
#define ADC_LL_CLKM_DIV_B_DEFAULT 1
|
||||
#define ADC_LL_CLKM_DIV_A_DEFAULT 0
|
||||
|
||||
#define ADC_LL_EVENT_ADC1_ONESHOT_DONE BIT(31)
|
||||
#define ADC_LL_EVENT_ADC2_ONESHOT_DONE BIT(30)
|
||||
|
||||
typedef enum {
|
||||
ADC_POWER_BY_FSM, /*!< ADC XPD controled by FSM. Used for polling mode */
|
||||
@@ -767,82 +770,188 @@ static inline void adc_ll_vref_output(adc_unit_t adc, adc_channel_t channel, boo
|
||||
Single Read
|
||||
---------------------------------------------------------------*/
|
||||
/**
|
||||
* Trigger single read
|
||||
* Set adc output data format for oneshot mode
|
||||
*
|
||||
* @note ESP32C3 Oneshot mode only supports 12bit.
|
||||
* @param adc_n ADC unit.
|
||||
* @param bits Output data bits width option.
|
||||
*/
|
||||
static inline void adc_oneshot_ll_set_output_bits(adc_unit_t adc_n, adc_bitwidth_t bits)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// //ESP32C3 only supports 12bit, leave here for compatibility
|
||||
// HAL_ASSERT(bits == ADC_BITWIDTH_12);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable adc channel to start convert.
|
||||
*
|
||||
* @note Only one channel can be selected for measurement.
|
||||
*
|
||||
* @param adc_n ADC unit.
|
||||
* @param channel ADC channel number for each ADCn.
|
||||
*/
|
||||
static inline void adc_oneshot_ll_set_channel(adc_unit_t adc_n, adc_channel_t channel)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// APB_SARADC.onetime_sample.onetime_channel = ((adc_n << 3) | channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable adc channel to start convert.
|
||||
*
|
||||
* @note Only one channel can be selected in once measurement.
|
||||
*
|
||||
* @param adc_n ADC unit.
|
||||
*/
|
||||
static inline void adc_oneshot_ll_disable_channel(adc_unit_t adc_n)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// if (adc_n == ADC_UNIT_1) {
|
||||
// APB_SARADC.onetime_sample.onetime_channel = ((adc_n << 3) | 0xF);
|
||||
// } else { // adc_n == ADC_UNIT_2
|
||||
// APB_SARADC.onetime_sample.onetime_channel = ((adc_n << 3) | 0x1);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Start oneshot conversion by software
|
||||
*
|
||||
* @param val Usage: set to 1 to start the ADC conversion. The step signal should at least keep 3 ADC digital controller clock cycle,
|
||||
* otherwise the step signal may not be captured by the ADC digital controller when its frequency is slow.
|
||||
* This hardware limitation will be removed in future versions.
|
||||
*/
|
||||
static inline void adc_ll_onetime_start(bool val)
|
||||
static inline void adc_oneshot_ll_start(bool val)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// APB_SARADC.onetime_sample.onetime_start = val;
|
||||
}
|
||||
|
||||
static inline void adc_ll_onetime_set_channel(adc_unit_t unit, adc_channel_t channel)
|
||||
/**
|
||||
* Clear the event for each ADCn for Oneshot mode
|
||||
*
|
||||
* @param event ADC event
|
||||
*/
|
||||
static inline void adc_oneshot_ll_clear_event(uint32_t event_mask)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// APB_SARADC.onetime_sample.onetime_channel = ((unit << 3) | channel);
|
||||
// APB_SARADC.int_clr.val |= event_mask;
|
||||
}
|
||||
|
||||
static inline void adc_ll_onetime_set_atten(adc_atten_t atten)
|
||||
/**
|
||||
* Check the event for each ADCn for Oneshot mode
|
||||
*
|
||||
* @param event ADC event
|
||||
*
|
||||
* @return
|
||||
* -true : The conversion process is finish.
|
||||
* -false : The conversion process is not finish.
|
||||
*/
|
||||
static inline bool adc_oneshot_ll_get_event(uint32_t event_mask)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// APB_SARADC.onetime_sample.onetime_atten = atten;
|
||||
// return (APB_SARADC.int_raw.val & event_mask);
|
||||
}
|
||||
|
||||
static inline void adc_ll_intr_enable(adc_ll_intr_t mask)
|
||||
/**
|
||||
* Get the converted value for each ADCn for RTC controller.
|
||||
*
|
||||
* @param adc_n ADC unit.
|
||||
* @return
|
||||
* - Converted value.
|
||||
*/
|
||||
static inline uint32_t adc_oneshot_ll_get_raw_result(adc_unit_t adc_n)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// APB_SARADC.int_ena.val |= mask;
|
||||
// uint32_t ret_val = 0;
|
||||
// if (adc_n == ADC_UNIT_1) {
|
||||
// ret_val = APB_SARADC.apb_saradc1_data_status.adc1_data & 0xfff;
|
||||
// } else { // adc_n == ADC_UNIT_2
|
||||
// ret_val = APB_SARADC.apb_saradc2_data_status.adc2_data & 0xfff;
|
||||
// }
|
||||
// return ret_val;
|
||||
}
|
||||
|
||||
static inline void adc_ll_intr_disable(adc_ll_intr_t mask)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// APB_SARADC.int_ena.val &= ~mask;
|
||||
}
|
||||
|
||||
static inline void adc_ll_intr_clear(adc_ll_intr_t mask)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// APB_SARADC.int_clr.val |= mask;
|
||||
}
|
||||
|
||||
static inline bool adc_ll_intr_get_raw(adc_ll_intr_t mask)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// return (APB_SARADC.int_raw.val & mask);
|
||||
}
|
||||
|
||||
static inline bool adc_ll_intr_get_status(adc_ll_intr_t mask)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// return (APB_SARADC.int_st.val & mask);
|
||||
}
|
||||
|
||||
static inline void adc_ll_onetime_sample_enable(adc_unit_t adc_n, bool enable)
|
||||
/**
|
||||
* Analyze whether the obtained raw data is correct.
|
||||
* ADC2 can use arbiter. The arbitration result is stored in the channel information of the returned data.
|
||||
*
|
||||
* @param adc_n ADC unit.
|
||||
* @param raw_data ADC raw data input (convert value).
|
||||
* @return
|
||||
* - 1: The data is correct to use.
|
||||
* - 0: The data is invalid.
|
||||
*/
|
||||
static inline bool adc_oneshot_ll_raw_check_valid(adc_unit_t adc_n, uint32_t raw_data)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// if (adc_n == ADC_UNIT_1) {
|
||||
// APB_SARADC.onetime_sample.adc1_onetime_sample = enable;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// //The raw data API returns value without channel information. Read value directly from the register
|
||||
// if (((APB_SARADC.apb_saradc2_data_status.adc2_data >> 13) & 0xF) > 9) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* ADC module RTC output data invert or not.
|
||||
*
|
||||
* @param adc_n ADC unit.
|
||||
* @param inv_en data invert or not.
|
||||
*/
|
||||
static inline void adc_oneshot_ll_output_invert(adc_unit_t adc_n, bool inv_en)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// (void)adc_n;
|
||||
// (void)inv_en;
|
||||
// //For compatibility
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable oneshot conversion trigger
|
||||
*
|
||||
* @param adc_n ADC unit
|
||||
*/
|
||||
static inline void adc_oneshot_ll_enable(adc_unit_t adc_n)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// if (adc_n == ADC_UNIT_1) {
|
||||
// APB_SARADC.onetime_sample.adc1_onetime_sample = 1;
|
||||
// } else {
|
||||
// APB_SARADC.onetime_sample.adc2_onetime_sample = enable;
|
||||
// APB_SARADC.onetime_sample.adc2_onetime_sample = 1;
|
||||
// }
|
||||
}
|
||||
|
||||
static inline uint32_t adc_ll_adc1_read(void)
|
||||
/**
|
||||
* Disable oneshot conversion trigger for all the ADC units
|
||||
*/
|
||||
static inline void adc_oneshot_ll_disable_all_unit(void)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// //On ESP32-C2, valid data width is 12-bit
|
||||
// return (APB_SARADC.apb_saradc1_data_status.adc1_data & 0xfff);
|
||||
// APB_SARADC.onetime_sample.adc1_onetime_sample = 0;
|
||||
// APB_SARADC.onetime_sample.adc2_onetime_sample = 0;
|
||||
}
|
||||
|
||||
static inline uint32_t adc_ll_adc2_read(void)
|
||||
/**
|
||||
* Set attenuation
|
||||
*
|
||||
* @note Attenuation is for all channels
|
||||
*
|
||||
* @param adc_n ADC unit
|
||||
* @param channel ADC channel
|
||||
* @param atten ADC attenuation
|
||||
*/
|
||||
static inline void adc_oneshot_ll_set_atten(adc_unit_t adc_n, adc_channel_t channel, adc_atten_t atten)
|
||||
{
|
||||
abort(); //TODO IDF-3908
|
||||
// //On ESP32-C2, valid data width is 12-bit
|
||||
// return (APB_SARADC.apb_saradc2_data_status.adc2_data & 0xfff);
|
||||
// (void)adc_n;
|
||||
// (void)channel;
|
||||
// // Attenuation is for all channels, unit and channel are for compatibility
|
||||
// APB_SARADC.onetime_sample.onetime_atten = atten;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Reference in New Issue
Block a user