mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-19 08:49:43 +01:00
adc: support adc dma driver on all chips
This commit is contained in:
committed by
Armando (Dou Yiwen)
parent
5ddce053ea
commit
4dc0d6b2fe
@@ -1,16 +1,8 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
@@ -54,6 +46,22 @@ typedef enum {
|
||||
ADC_RTC_DATA_FAIL = -1,
|
||||
} adc_ll_rtc_raw_data_t;
|
||||
|
||||
typedef enum {
|
||||
ADC_LL_CTRL_DIG = 0, ///< For ADC1. Select DIG controller.
|
||||
ADC_LL_CTRL_ARB = 1, ///< For ADC2. The controller is selected by the arbiter.
|
||||
} adc_ll_controller_t;
|
||||
|
||||
/**
|
||||
* @brief ADC digital controller (DMA mode) work mode.
|
||||
*
|
||||
* @note The conversion mode affects the sampling frequency:
|
||||
* ESP32H2 only support ALTER_UNIT mode
|
||||
* ALTER_UNIT : When the measurement is triggered, ADC1 or ADC2 samples alternately.
|
||||
*/
|
||||
typedef enum {
|
||||
ADC_LL_DIGI_CONV_ALTER_UNIT = 0, // Use both ADC1 and ADC2 for conversion by turn. e.g. ADC1 -> ADC2 -> ADC1 -> ADC2 .....
|
||||
} adc_ll_digi_convert_mode_t;
|
||||
|
||||
//These values should be set according to the HW
|
||||
typedef enum {
|
||||
ADC_LL_INTR_THRES1_LOW = BIT(26),
|
||||
@@ -65,21 +73,17 @@ typedef enum {
|
||||
} adc_ll_intr_t;
|
||||
FLAG_ATTR(adc_ll_intr_t)
|
||||
|
||||
/**
|
||||
* @brief ADC controller type selection.
|
||||
*
|
||||
* @note For ADC2, use the force option with care. The system power consumption detection will use ADC2.
|
||||
* If it is forced to switch to another controller, it may cause the system to obtain incorrect values.
|
||||
* @note Normally, there is no need to switch the controller manually.
|
||||
*/
|
||||
typedef enum {
|
||||
ADC_CTRL_RTC = 0, /*!<For ADC1. Select RTC controller. For ADC2. The controller is selected by the arbiter. Arbiter in default mode. */
|
||||
ADC_CTRL_DIG = 2, /*!<For ADC1. Select DIG controller. For ADC2. The controller is selected by the arbiter. Arbiter in default mode. */
|
||||
ADC2_CTRL_PWDET = 3,/*!<For ADC2. The controller is selected by the arbiter. Arbiter in default mode. */
|
||||
ADC2_CTRL_FORCE_PWDET = 3, /*!<For ADC2. Arbiter in shield mode. Force select Wi-Fi controller work. */
|
||||
ADC2_CTRL_FORCE_RTC = 4, /*!<For ADC2. Arbiter in shield mode. Force select RTC controller work. */
|
||||
ADC2_CTRL_FORCE_DIG = 6, /*!<For ADC2. Arbiter in shield mode. Force select digital controller work. */
|
||||
} adc_ll_controller_t;
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
uint8_t atten: 2;
|
||||
uint8_t channel: 3;
|
||||
uint8_t unit: 1;
|
||||
uint8_t reserved: 2;
|
||||
};
|
||||
uint8_t val;
|
||||
};
|
||||
} __attribute__((packed)) adc_ll_digi_pattern_table_t;
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
Digital controller setting
|
||||
@@ -157,6 +161,18 @@ static inline void adc_ll_digi_convert_limit_disable(void)
|
||||
APB_SARADC.ctrl2.meas_num_limit = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set adc conversion mode for digital controller.
|
||||
*
|
||||
* @note ESP32H2 only support ADC1 single mode.
|
||||
*
|
||||
* @param mode Conversion mode select.
|
||||
*/
|
||||
static inline void adc_ll_digi_set_convert_mode(adc_ll_digi_convert_mode_t mode)
|
||||
{
|
||||
//ESP32H2 only supports ADC_CONV_ALTER_UNIT mode
|
||||
}
|
||||
|
||||
/**
|
||||
* Set pattern table length for digital controller.
|
||||
* The pattern table that defines the conversion rules for each SAR ADC. Each table has 8 items, in which channel selection,
|
||||
@@ -181,16 +197,18 @@ static inline void adc_ll_digi_set_pattern_table_len(adc_ll_num_t adc_n, uint32_
|
||||
* @param pattern_index Items index. Range: 0 ~ 7.
|
||||
* @param pattern Stored conversion rules.
|
||||
*/
|
||||
static inline void adc_ll_digi_set_pattern_table(adc_ll_num_t adc_n, uint32_t pattern_index, adc_digi_pattern_table_t pattern)
|
||||
static inline void adc_ll_digi_set_pattern_table(adc_ll_num_t adc_n, uint32_t pattern_index, adc_digi_pattern_config_t table)
|
||||
{
|
||||
uint32_t tab;
|
||||
uint8_t index = pattern_index / 4;
|
||||
uint8_t offset = (pattern_index % 4) * 6;
|
||||
adc_ll_digi_pattern_table_t pattern = {0};
|
||||
|
||||
tab = APB_SARADC.sar_patt_tab[index].sar_patt_tab1; // Read old register value
|
||||
tab &= (~(0xFC0000 >> offset)); // Clear old data
|
||||
tab |= ((uint32_t)(pattern.val & 0x3F) << 18) >> offset; // Fill in the new data
|
||||
APB_SARADC.sar_patt_tab[index].sar_patt_tab1 = tab; // Write back
|
||||
pattern.val = (table.atten & 0x3) | ((table.channel & 0x7) << 2) | ((table.unit & 0x1) << 5);
|
||||
tab = APB_SARADC.sar_patt_tab[index].sar_patt_tab1; // Read old register value
|
||||
tab &= (~(0xFC0000 >> offset)); // Clear old data
|
||||
tab |= ((uint32_t)(pattern.val & 0x3F) << 18) >> offset; // Fill in the new data
|
||||
APB_SARADC.sar_patt_tab[index].sar_patt_tab1 = tab; // Write back
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,9 +278,9 @@ static inline void adc_ll_digi_trigger_disable(void)
|
||||
|
||||
/**
|
||||
* Set ADC digital controller clock division factor. The clock divided from `APLL` or `APB` clock.
|
||||
* Expression: controller_clk = APLL/APB * (div_num + div_b / div_a).
|
||||
* Expression: controller_clk = (APLL or APB) / (div_num + div_a / div_b + 1).
|
||||
*
|
||||
* @param div_num Division factor. Range: 1 ~ 255.
|
||||
* @param div_num Division factor. Range: 0 ~ 255.
|
||||
* @param div_b Division factor. Range: 1 ~ 63.
|
||||
* @param div_a Division factor. Range: 0 ~ 63.
|
||||
*/
|
||||
@@ -278,7 +296,7 @@ static inline void adc_ll_digi_controller_clk_div(uint32_t div_num, uint32_t div
|
||||
*
|
||||
* @param use_apll true: use APLL clock; false: use APB clock.
|
||||
*/
|
||||
static inline void adc_ll_digi_controller_clk_enable(bool use_apll)
|
||||
static inline void adc_ll_digi_clk_sel(bool use_apll)
|
||||
{
|
||||
if (use_apll) {
|
||||
APB_SARADC.apb_adc_clkm_conf.clk_sel = 1; // APLL clock
|
||||
@@ -445,8 +463,7 @@ static inline void adc_ll_digi_reset(void)
|
||||
static inline void adc_ll_pwdet_set_cct(uint32_t cct)
|
||||
{
|
||||
/* Capacitor tuning of the PA power monitor. cct set to the same value with PHY. */
|
||||
// RTCCNTL.sensor_ctrl.sar2_pwdet_cct = cct;
|
||||
abort(); // ESP32H2-TODO: IDF-3389
|
||||
abort();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -458,9 +475,7 @@ static inline void adc_ll_pwdet_set_cct(uint32_t cct)
|
||||
static inline uint32_t adc_ll_pwdet_get_cct(void)
|
||||
{
|
||||
/* Capacitor tuning of the PA power monitor. cct set to the same value with PHY. */
|
||||
// return RTCCNTL.sensor_ctrl.sar2_pwdet_cct;
|
||||
abort(); // ESP32H2-TODO: IDF-3389
|
||||
return 0;
|
||||
abort();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -497,8 +512,8 @@ static inline adc_ll_rtc_raw_data_t adc_ll_analysis_raw_data(adc_ll_num_t adc_n,
|
||||
*/
|
||||
static inline void adc_ll_set_power_manage(adc_ll_power_t manage)
|
||||
{
|
||||
// /* Bit1 0:Fsm 1: SW mode
|
||||
// Bit0 0:SW mode power down 1: SW mode power on */
|
||||
/* Bit1 0:Fsm 1: SW mode
|
||||
Bit0 0:SW mode power down 1: SW mode power on */
|
||||
if (manage == ADC_POWER_SW_ON) {
|
||||
APB_SARADC.ctrl.sar_clk_gated = 1;
|
||||
APB_SARADC.ctrl.xpd_sar_force = 3;
|
||||
@@ -506,30 +521,14 @@ static inline void adc_ll_set_power_manage(adc_ll_power_t manage)
|
||||
APB_SARADC.ctrl.sar_clk_gated = 1;
|
||||
APB_SARADC.ctrl.xpd_sar_force = 0;
|
||||
} else if (manage == ADC_POWER_SW_OFF) {
|
||||
APB_SARADC.ctrl.xpd_sar_force = 2;
|
||||
APB_SARADC.ctrl.sar_clk_gated = 0;
|
||||
APB_SARADC.ctrl.xpd_sar_force = 2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ADC module power management.
|
||||
*
|
||||
* @return
|
||||
* - ADC power status.
|
||||
*/
|
||||
static inline adc_ll_power_t adc_ll_get_power_manage(void)
|
||||
static inline void adc_ll_set_controller(adc_ll_num_t adc_n, adc_ll_controller_t ctrl)
|
||||
{
|
||||
/* Bit1 0:Fsm 1: SW mode
|
||||
Bit0 0:SW mode power down 1: SW mode power on */
|
||||
adc_ll_power_t manage;
|
||||
if (APB_SARADC.ctrl.xpd_sar_force == 3) {
|
||||
manage = ADC_POWER_SW_ON;
|
||||
} else if (APB_SARADC.ctrl.xpd_sar_force == 2) {
|
||||
manage = ADC_POWER_SW_OFF;
|
||||
} else {
|
||||
manage = ADC_POWER_BY_FSM;
|
||||
}
|
||||
return manage;
|
||||
//Not used on ESP32H2
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -688,7 +687,7 @@ static inline void adc_ll_set_calibration_param(adc_ll_num_t adc_n, uint32_t par
|
||||
*/
|
||||
static inline void adc_ll_vref_output(adc_ll_num_t adc, adc_channel_t channel, bool en)
|
||||
{
|
||||
// ESP32H2-TODO: IDF-3389
|
||||
abort();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user