mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-11 21:10:20 +00:00
feature(I2S-ADC): add ADC mode for I2S.
1. Support built-in ADC for I2S. 2. Modify code of ADC, made no change to the original APIs. 3. Add APIs in I2S: esp_err_t i2s_set_adc_mode(adc_unit_t adc_unit, adc1_channel_t adc_channel); 4. Add I2S ADC/DAC example code. 5. add old-fashion definition to make it more compatible 6. replase spi_flash_ APIs with esp_partition_ APIs 7. add example of generating audio table from wav 8. change example sound
This commit is contained in:
@@ -278,7 +278,7 @@ esp_err_t i2s_set_clk(i2s_port_t i2s_num, uint32_t rate, i2s_bits_per_sample_t b
|
||||
}
|
||||
|
||||
double mclk;
|
||||
if (p_i2s_obj[i2s_num]->mode & I2S_MODE_DAC_BUILT_IN) {
|
||||
if (p_i2s_obj[i2s_num]->mode & (I2S_MODE_DAC_BUILT_IN | I2S_MODE_ADC_BUILT_IN)) {
|
||||
//DAC uses bclk as sample clock, not WS. WS can be something arbitrary.
|
||||
//Rate as given to this function is the intended sample rate;
|
||||
//According to the TRM, WS clk equals to the sample rate, and bclk is double the speed of WS
|
||||
@@ -554,6 +554,13 @@ esp_err_t i2s_set_dac_mode(i2s_dac_mode_t dac_mode)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t i2s_set_adc_mode(adc_unit_t adc_unit, adc1_channel_t adc_channel)
|
||||
{
|
||||
I2S_CHECK((adc_unit < ADC_UNIT_2), "i2s ADC unit error, only support ADC1 for now", ESP_ERR_INVALID_ARG);
|
||||
// For now, we only support SAR ADC1.
|
||||
return adc_i2s_mode_init(adc_unit, adc_channel);
|
||||
}
|
||||
|
||||
esp_err_t i2s_set_pin(i2s_port_t i2s_num, const i2s_pin_config_t *pin)
|
||||
{
|
||||
I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_ERR_INVALID_ARG);
|
||||
@@ -669,10 +676,14 @@ esp_err_t i2s_set_sample_rates(i2s_port_t i2s_num, uint32_t rate)
|
||||
I2S_CHECK((p_i2s_obj[i2s_num]->bytes_per_sample > 0), "bits_per_sample not set", ESP_ERR_INVALID_ARG);
|
||||
return i2s_set_clk(i2s_num, rate, p_i2s_obj[i2s_num]->bits_per_sample, p_i2s_obj[i2s_num]->channel_num);
|
||||
}
|
||||
|
||||
static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_config)
|
||||
{
|
||||
I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_ERR_INVALID_ARG);
|
||||
I2S_CHECK((i2s_config), "param null", ESP_ERR_INVALID_ARG);
|
||||
I2S_CHECK(!((i2s_config->mode & I2S_MODE_ADC_BUILT_IN) && (i2s_num != I2S_NUM_0)), "I2S ADC built-in only support on I2S0", ESP_ERR_INVALID_ARG);
|
||||
I2S_CHECK(!((i2s_config->mode & I2S_MODE_DAC_BUILT_IN) && (i2s_num != I2S_NUM_0)), "I2S DAC built-in only support on I2S0", ESP_ERR_INVALID_ARG);
|
||||
I2S_CHECK(!((i2s_config->mode & I2S_MODE_PDM) && (i2s_num != I2S_NUM_0)), "I2S DAC PDM only support on I2S0", ESP_ERR_INVALID_ARG);
|
||||
|
||||
if (i2s_num == I2S_NUM_1) {
|
||||
periph_module_enable(PERIPH_I2S1_MODULE);
|
||||
@@ -680,23 +691,27 @@ static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_co
|
||||
periph_module_enable(PERIPH_I2S0_MODULE);
|
||||
}
|
||||
|
||||
if(i2s_config->mode & I2S_MODE_ADC_BUILT_IN) {
|
||||
//in ADC built-in mode, we need to call i2s_set_adc_mode to
|
||||
//initialize the specific ADC channel.
|
||||
//in the current stage, we only support ADC1 and single channel mode.
|
||||
//In default data mode, the ADC data is in 12-bit resolution mode.
|
||||
adc_power_on();
|
||||
}
|
||||
// configure I2S data port interface.
|
||||
i2s_reset_fifo(i2s_num);
|
||||
|
||||
//reset i2s
|
||||
I2S[i2s_num]->conf.tx_reset = 1;
|
||||
I2S[i2s_num]->conf.tx_reset = 0;
|
||||
I2S[i2s_num]->conf.rx_reset = 1;
|
||||
I2S[i2s_num]->conf.rx_reset = 0;
|
||||
|
||||
|
||||
//reset dma
|
||||
I2S[i2s_num]->lc_conf.in_rst = 1;
|
||||
I2S[i2s_num]->lc_conf.in_rst = 0;
|
||||
I2S[i2s_num]->lc_conf.out_rst = 1;
|
||||
I2S[i2s_num]->lc_conf.out_rst = 0;
|
||||
|
||||
|
||||
//Enable and configure DMA
|
||||
I2S[i2s_num]->lc_conf.check_owner = 0;
|
||||
I2S[i2s_num]->lc_conf.out_loop_test = 0;
|
||||
@@ -707,7 +722,6 @@ static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_co
|
||||
I2S[i2s_num]->lc_conf.indscr_burst_en = 0;
|
||||
I2S[i2s_num]->lc_conf.out_eof_mode = 1;
|
||||
|
||||
|
||||
I2S[i2s_num]->conf2.lcd_en = 0;
|
||||
I2S[i2s_num]->conf2.camera_en = 0;
|
||||
I2S[i2s_num]->pdm_conf.pcm2pdm_conv_en = 0;
|
||||
@@ -751,9 +765,10 @@ static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_co
|
||||
}
|
||||
}
|
||||
|
||||
if (i2s_config->mode & I2S_MODE_DAC_BUILT_IN) {
|
||||
if (i2s_config->mode & (I2S_MODE_DAC_BUILT_IN | I2S_MODE_ADC_BUILT_IN)) {
|
||||
I2S[i2s_num]->conf2.lcd_en = 1;
|
||||
I2S[i2s_num]->conf.tx_right_first = 1;
|
||||
I2S[i2s_num]->conf2.camera_en = 0;
|
||||
}
|
||||
|
||||
if (i2s_config->mode & I2S_MODE_PDM) {
|
||||
@@ -873,7 +888,12 @@ esp_err_t i2s_driver_install(i2s_port_t i2s_num, const i2s_config_t *i2s_config,
|
||||
return err;
|
||||
}
|
||||
i2s_stop(i2s_num);
|
||||
i2s_param_config(i2s_num, i2s_config);
|
||||
err = i2s_param_config(i2s_num, i2s_config);
|
||||
if (err != ESP_OK) {
|
||||
i2s_driver_uninstall(i2s_num);
|
||||
ESP_LOGE(I2S_TAG, "I2S param configure error");
|
||||
return err;
|
||||
}
|
||||
|
||||
if (i2s_queue) {
|
||||
p_i2s_obj[i2s_num]->i2s_queue = xQueueCreate(queue_size, sizeof(i2s_event_t));
|
||||
|
@@ -20,24 +20,38 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "soc/adc_channel.h"
|
||||
|
||||
typedef enum {
|
||||
ADC_ATTEN_0db = 0, /*!<The input voltage of ADC will be reduced to about 1/1 */
|
||||
ADC_ATTEN_2_5db = 1, /*!<The input voltage of ADC will be reduced to about 1/1.34 */
|
||||
ADC_ATTEN_6db = 2, /*!<The input voltage of ADC will be reduced to about 1/2 */
|
||||
ADC_ATTEN_11db = 3, /*!<The input voltage of ADC will be reduced to about 1/3.6*/
|
||||
ADC_ATTEN_DB_0 = 0, /*!<The input voltage of ADC will be reduced to about 1/1 */
|
||||
ADC_ATTEN_DB_2_5 = 1, /*!<The input voltage of ADC will be reduced to about 1/1.34 */
|
||||
ADC_ATTEN_DB_6 = 2, /*!<The input voltage of ADC will be reduced to about 1/2 */
|
||||
ADC_ATTEN_DB_11 = 3, /*!<The input voltage of ADC will be reduced to about 1/3.6*/
|
||||
ADC_ATTEN_MAX,
|
||||
} adc_atten_t;
|
||||
|
||||
typedef enum {
|
||||
ADC_WIDTH_9Bit = 0, /*!< ADC capture width is 9Bit*/
|
||||
ADC_WIDTH_10Bit = 1, /*!< ADC capture width is 10Bit*/
|
||||
ADC_WIDTH_11Bit = 2, /*!< ADC capture width is 11Bit*/
|
||||
ADC_WIDTH_12Bit = 3, /*!< ADC capture width is 12Bit*/
|
||||
ADC_WIDTH_BIT_9 = 0, /*!< ADC capture width is 9Bit*/
|
||||
ADC_WIDTH_BIT_10 = 1, /*!< ADC capture width is 10Bit*/
|
||||
ADC_WIDTH_BIT_11 = 2, /*!< ADC capture width is 11Bit*/
|
||||
ADC_WIDTH_BIT_12 = 3, /*!< ADC capture width is 12Bit*/
|
||||
ADC_WIDTH_MAX,
|
||||
} adc_bits_width_t;
|
||||
|
||||
//this definitions are only for being back-compatible
|
||||
#define ADC_ATTEN_0db ADC_ATTEN_DB_0
|
||||
#define ADC_ATTEN_2_5db ADC_ATTEN_DB_2_5
|
||||
#define ADC_ATTEN_6db ADC_ATTEN_DB_6
|
||||
#define ADC_ATTEN_11db ADC_ATTEN_DB_11
|
||||
//this definitions are only for being back-compatible
|
||||
#define ADC_WIDTH_9Bit ADC_WIDTH_BIT_9
|
||||
#define ADC_WIDTH_10Bit ADC_WIDTH_BIT_10
|
||||
#define ADC_WIDTH_11Bit ADC_WIDTH_BIT_11
|
||||
#define ADC_WIDTH_12Bit ADC_WIDTH_BIT_12
|
||||
|
||||
typedef enum {
|
||||
ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO36 */
|
||||
ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO37 */
|
||||
@@ -64,11 +78,43 @@ typedef enum {
|
||||
ADC2_CHANNEL_MAX,
|
||||
} adc2_channel_t;
|
||||
|
||||
typedef enum {
|
||||
ADC_CHANNEL_0 = 0, /*!< ADC channel */
|
||||
ADC_CHANNEL_1, /*!< ADC channel */
|
||||
ADC_CHANNEL_2, /*!< ADC channel */
|
||||
ADC_CHANNEL_3, /*!< ADC channel */
|
||||
ADC_CHANNEL_4, /*!< ADC channel */
|
||||
ADC_CHANNEL_5, /*!< ADC channel */
|
||||
ADC_CHANNEL_6, /*!< ADC channel */
|
||||
ADC_CHANNEL_7, /*!< ADC channel */
|
||||
ADC_CHANNEL_8, /*!< ADC channel */
|
||||
ADC_CHANNEL_9, /*!< ADC channel */
|
||||
ADC_CHANNEL_MAX,
|
||||
} adc_channel_t;
|
||||
|
||||
typedef enum {
|
||||
ADC_UNIT_1 = 1, /*!< SAR ADC 1*/
|
||||
ADC_UNIT_2 = 2, /*!< SAR ADC 2, not supported yet*/
|
||||
ADC_UNIT_BOTH = 3, /*!< SAR ADC 1 and 2, not supported yet */
|
||||
ADC_UNIT_ALTER = 7, /*!< SAR ADC 1 and 2 alternative mode, not supported yet */
|
||||
ADC_UNIT_MAX,
|
||||
} adc_unit_t;
|
||||
|
||||
typedef enum {
|
||||
ADC_ENCODE_12BIT, /*!< ADC to I2S data format, [15:12]-channel [11:0]-12 bits ADC data */
|
||||
ADC_ENCODE_11BIT, /*!< ADC to I2S data format, [15]-1 [14:11]-channel [10:0]-11 bits ADC data */
|
||||
ADC_ENCODE_MAX,
|
||||
} adc_i2s_encode_t;
|
||||
|
||||
typedef enum {
|
||||
ADC_I2S_DATA_SRC_IO_SIG = 0, /*!< I2S data from GPIO matrix signal */
|
||||
ADC_I2S_DATA_SRC_ADC = 1, /*!< I2S data from ADC */
|
||||
ADC_I2S_DATA_SRC_MAX,
|
||||
} adc_i2s_source_t;
|
||||
|
||||
/**
|
||||
* @brief Configure ADC1 capture width.
|
||||
*
|
||||
* @brief Configure ADC1 capture width, meanwhile enable output invert for ADC1.
|
||||
* The configuration is for all channels of ADC1
|
||||
*
|
||||
* @param width_bit Bit capture width for ADC1
|
||||
*
|
||||
* @return
|
||||
@@ -77,6 +123,16 @@ typedef enum {
|
||||
*/
|
||||
esp_err_t adc1_config_width(adc_bits_width_t width_bit);
|
||||
|
||||
/**
|
||||
* @brief Configure ADC capture width.
|
||||
* @param adc_unit ADC unit index
|
||||
* @param width_bit Bit capture width for ADC unit.
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t adc_set_data_width(adc_unit_t adc_unit, adc_bits_width_t width_bit);
|
||||
|
||||
/**
|
||||
* @brief Configure the ADC1 channel, including setting attenuation.
|
||||
*
|
||||
@@ -89,10 +145,10 @@ esp_err_t adc1_config_width(adc_bits_width_t width_bit);
|
||||
*
|
||||
* When VDD_A is 3.3V:
|
||||
*
|
||||
* - 0dB attenuaton (ADC_ATTEN_0db) gives full-scale voltage 1.1V
|
||||
* - 2.5dB attenuation (ADC_ATTEN_2_5db) gives full-scale voltage 1.5V
|
||||
* - 6dB attenuation (ADC_ATTEN_6db) gives full-scale voltage 2.2V
|
||||
* - 11dB attenuation (ADC_ATTEN_11db) gives full-scale voltage 3.9V (see note below)
|
||||
* - 0dB attenuaton (ADC_ATTEN_DB_0) gives full-scale voltage 1.1V
|
||||
* - 2.5dB attenuation (ADC_ATTEN_DB_2_5) gives full-scale voltage 1.5V
|
||||
* - 6dB attenuation (ADC_ATTEN_DB_6) gives full-scale voltage 2.2V
|
||||
* - 11dB attenuation (ADC_ATTEN_DB_11) gives full-scale voltage 3.9V (see note below)
|
||||
*
|
||||
* @note The full-scale voltage is the voltage corresponding to a maximum reading (depending on ADC1 configured
|
||||
* bit width, this value is: 4095 for 12-bits, 2047 for 11-bits, 1023 for 10-bits, 511 for 9 bits.)
|
||||
@@ -134,6 +190,62 @@ int adc1_get_raw(adc1_channel_t channel);
|
||||
int adc1_get_voltage(adc1_channel_t channel) __attribute__((deprecated));
|
||||
/** @endcond */
|
||||
|
||||
/**
|
||||
* @brief Power on SAR ADC
|
||||
*/
|
||||
void adc_power_on();
|
||||
|
||||
/**
|
||||
* @brief Power off SAR ADC
|
||||
*/
|
||||
void adc_power_off();
|
||||
|
||||
/**
|
||||
* @brief Initialize ADC pad
|
||||
* @param adc_unit ADC unit index
|
||||
* @param channel ADC channel index
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t adc_gpio_init(adc_unit_t adc_unit, adc_channel_t channel);
|
||||
|
||||
/**
|
||||
* @brief Set ADC data invert
|
||||
* @param adc_unit ADC unit index
|
||||
* @param inv_en whether enable data invert
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t adc_set_data_inv(adc_unit_t adc_unit, bool inv_en);
|
||||
|
||||
/**
|
||||
* @brief Set ADC source clock
|
||||
* @param clk_div ADC clock divider, ADC clock is divided from APB clock
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
*/
|
||||
esp_err_t adc_set_clk_div(uint8_t clk_div);
|
||||
|
||||
/**
|
||||
* @brief Set I2S data source
|
||||
* @param src I2S DMA data source, I2S DMA can get data from digital signals or from ADC.
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
*/
|
||||
esp_err_t adc_set_i2s_data_source(adc_i2s_source_t src);
|
||||
|
||||
/**
|
||||
* @brief Initialize I2S ADC mode
|
||||
* @param adc_unit ADC unit index
|
||||
* @param channel ADC channel index
|
||||
* @return
|
||||
* - ESP_OK success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t adc_i2s_mode_init(adc_unit_t adc_unit, adc_channel_t channel);
|
||||
|
||||
/**
|
||||
* @brief Configure ADC1 to be usable by the ULP
|
||||
*
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include "esp_attr.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "driver/periph_ctrl.h"
|
||||
#include "driver/adc.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -118,7 +119,7 @@ typedef enum {
|
||||
I2S_MODE_TX = 4,
|
||||
I2S_MODE_RX = 8,
|
||||
I2S_MODE_DAC_BUILT_IN = 16, /*!< Output I2S data to built-in DAC, no matter the data format is 16bit or 32 bit, the DAC module will only take the 8bits from MSB*/
|
||||
//I2S_MODE_ADC_BUILT_IN = 32, /*!< Currently not supported yet, will be added for the next version*/
|
||||
I2S_MODE_ADC_BUILT_IN = 32, /*!< Input I2S data from built-in ADC, each data can be 12-bit width at most*/
|
||||
I2S_MODE_PDM = 64,
|
||||
} i2s_mode_t;
|
||||
|
||||
@@ -402,6 +403,17 @@ esp_err_t i2s_zero_dma_buffer(i2s_port_t i2s_num);
|
||||
*/
|
||||
esp_err_t i2s_set_clk(i2s_port_t i2s_num, uint32_t rate, i2s_bits_per_sample_t bits, i2s_channel_t ch);
|
||||
|
||||
/**
|
||||
* @brief Set built-in ADC mode for I2S DMA, this function will initialize ADC pad,
|
||||
* and set ADC parameters.
|
||||
* @param adc_unit SAR ADC unit index
|
||||
* @param adc_channel ADC channel index
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_FAIL Parameter error
|
||||
*/
|
||||
esp_err_t i2s_set_adc_mode(adc_unit_t adc_unit, adc1_channel_t adc_channel);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -20,6 +20,8 @@
|
||||
#include "soc/sens_struct.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/rtc_cntl_struct.h"
|
||||
#include "soc/syscon_reg.h"
|
||||
#include "soc/syscon_struct.h"
|
||||
#include "rtc_io.h"
|
||||
#include "touch_pad.h"
|
||||
#include "adc.h"
|
||||
@@ -40,6 +42,18 @@
|
||||
#include "rom/queue.h"
|
||||
|
||||
|
||||
#define ADC_FSM_RSTB_WAIT_DEFAULT (8)
|
||||
#define ADC_FSM_START_WAIT_DEFAULT (5)
|
||||
#define ADC_FSM_STANDBY_WAIT_DEFAULT (100)
|
||||
#define ADC_FSM_TIME_KEEP (-1)
|
||||
#define ADC_MAX_MEAS_NUM_DEFAULT (255)
|
||||
#define ADC_MEAS_NUM_LIM_DEFAULT (1)
|
||||
#define SAR_ADC_CLK_DIV_DEFUALT (2)
|
||||
#define ADC_PATT_LEN_MAX (16)
|
||||
#define TOUCH_PAD_FILTER_FACTOR_DEFAULT (16)
|
||||
#define TOUCH_PAD_SHIFT_DEFAULT (4)
|
||||
#define DAC_ERR_STR_CHANNEL_ERROR "DAC channel error"
|
||||
|
||||
static const char *RTC_MODULE_TAG = "RTC_MODULE";
|
||||
|
||||
#define RTC_MODULE_CHECK(a, str, ret_val) if (!(a)) { \
|
||||
@@ -52,17 +66,16 @@ static const char *RTC_MODULE_TAG = "RTC_MODULE";
|
||||
return (ret_val); \
|
||||
}
|
||||
|
||||
#define ADC_CHECK_UNIT(unit) RTC_MODULE_CHECK(adc_unit < ADC_UNIT_2, "ADC unit error, only support ADC1 for now", ESP_ERR_INVALID_ARG)
|
||||
|
||||
#define ADC1_CHECK_FUNCTION_RET(fun_ret) if(fun_ret!=ESP_OK){\
|
||||
ESP_LOGE(RTC_MODULE_TAG,"%s:%d\n",__FUNCTION__,__LINE__);\
|
||||
return ESP_FAIL;\
|
||||
}
|
||||
|
||||
#define DAC_ERR_STR_CHANNEL_ERROR "DAC channel error"
|
||||
|
||||
portMUX_TYPE rtc_spinlock = portMUX_INITIALIZER_UNLOCKED;
|
||||
static SemaphoreHandle_t rtc_touch_mux = NULL;
|
||||
|
||||
|
||||
typedef struct {
|
||||
TimerHandle_t timer;
|
||||
uint32_t filtered_val[TOUCH_PAD_MAX];
|
||||
@@ -72,6 +85,12 @@ typedef struct {
|
||||
} touch_pad_filter_t;
|
||||
static touch_pad_filter_t *s_touch_pad_filter = NULL;
|
||||
|
||||
typedef enum {
|
||||
ADC_FORCE_FSM = 0x0,
|
||||
ADC_FORCE_DISABLE = 0x2,
|
||||
ADC_FORCE_ENABLE = 0x3,
|
||||
} adc_force_mode_t;
|
||||
|
||||
//Reg,Mux,Fun,IE,Up,Down,Rtc_number
|
||||
const rtc_gpio_desc_t rtc_gpio_desc[GPIO_PIN_COUNT] = {
|
||||
{RTC_IO_TOUCH_PAD1_REG, RTC_IO_TOUCH_PAD1_MUX_SEL_M, RTC_IO_TOUCH_PAD1_FUN_SEL_S, RTC_IO_TOUCH_PAD1_FUN_IE_M, RTC_IO_TOUCH_PAD1_RUE_M, RTC_IO_TOUCH_PAD1_RDE_M, RTC_IO_TOUCH_PAD1_SLP_SEL_M, RTC_IO_TOUCH_PAD1_SLP_IE_M, RTC_IO_TOUCH_PAD1_HOLD_M, RTC_CNTL_TOUCH_PAD1_HOLD_FORCE_M, RTC_IO_TOUCH_PAD1_DRV_V, RTC_IO_TOUCH_PAD1_DRV_S, RTCIO_GPIO0_CHANNEL}, //0
|
||||
@@ -412,8 +431,6 @@ static esp_err_t touch_pad_get_io_num(touch_pad_t touch_num, gpio_num_t *gpio_nu
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#define TOUCH_PAD_FILTER_FACTOR_DEFAULT (16)
|
||||
#define TOUCH_PAD_SHIFT_DEFAULT (4)
|
||||
static uint32_t _touch_filter_iir(uint32_t in_now, uint32_t out_last, uint32_t k)
|
||||
{
|
||||
if (k == 0) {
|
||||
@@ -909,69 +926,304 @@ static esp_err_t adc1_pad_get_io_num(adc1_channel_t channel, gpio_num_t *gpio_nu
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t adc1_pad_init(adc1_channel_t channel)
|
||||
static esp_err_t adc_set_fsm_time(int rst_wait, int start_wait, int standby_wait, int sample_cycle)
|
||||
{
|
||||
gpio_num_t gpio_num = 0;
|
||||
ADC1_CHECK_FUNCTION_RET(adc1_pad_get_io_num(channel, &gpio_num));
|
||||
ADC1_CHECK_FUNCTION_RET(rtc_gpio_init(gpio_num));
|
||||
ADC1_CHECK_FUNCTION_RET(rtc_gpio_output_disable(gpio_num));
|
||||
ADC1_CHECK_FUNCTION_RET(rtc_gpio_input_disable(gpio_num));
|
||||
ADC1_CHECK_FUNCTION_RET(gpio_set_pull_mode(gpio_num, GPIO_FLOATING));
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
// Internal FSM reset wait time
|
||||
if (rst_wait >= 0) {
|
||||
SYSCON.saradc_fsm.rstb_wait = rst_wait;
|
||||
}
|
||||
// Internal FSM start wait time
|
||||
if (start_wait >= 0) {
|
||||
SYSCON.saradc_fsm.start_wait = start_wait;
|
||||
}
|
||||
// Internal FSM standby wait time
|
||||
if (standby_wait >= 0) {
|
||||
SYSCON.saradc_fsm.standby_wait = standby_wait;
|
||||
}
|
||||
// Internal FSM standby sample cycle
|
||||
if (sample_cycle >= 0) {
|
||||
SYSCON.saradc_fsm.sample_cycle = sample_cycle;
|
||||
}
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t adc_set_data_format(adc_i2s_encode_t mode)
|
||||
{
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
//data format:
|
||||
//0: ADC_ENCODE_12BIT [15:12]-channel [11:0]-12 bits ADC data
|
||||
//1: ADC_ENCODE_11BIT [15]-1 [14:11]-channel [10:0]-11 bits ADC data, the resolution should not be larger than 11 bits in this case.
|
||||
SYSCON.saradc_ctrl.data_sar_sel = mode;
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t adc_set_measure_limit(uint8_t meas_num, bool lim_en)
|
||||
{
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
// Set max measure number
|
||||
SYSCON.saradc_ctrl2.max_meas_num = meas_num;
|
||||
// Enable max measure number limit
|
||||
SYSCON.saradc_ctrl2.meas_num_limit = lim_en;
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t adc_set_work_mode(adc_unit_t adc_unit)
|
||||
{
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
if (adc_unit == ADC_UNIT_1) {
|
||||
// saradc mode sel : 0--single saradc; 1--double saradc; 2--alternative saradc
|
||||
SYSCON.saradc_ctrl.work_mode = 0;
|
||||
//ENABLE ADC 0: ADC1 1: ADC2, only work for single SAR mode
|
||||
SYSCON.saradc_ctrl.sar_sel = 0;
|
||||
} else if (adc_unit == ADC_UNIT_2) {
|
||||
// saradc mode sel : 0--single saradc; 1--double saradc; 2--alternative saradc
|
||||
SYSCON.saradc_ctrl.work_mode = 0;
|
||||
//ENABLE ADC1 0: SAR1 1: SAR2 only work for single SAR mode
|
||||
SYSCON.saradc_ctrl.sar_sel = 1;
|
||||
} else if (adc_unit == ADC_UNIT_BOTH) {
|
||||
// saradc mode sel : 0--single saradc; 1--double saradc; 2--alternative saradc
|
||||
SYSCON.saradc_ctrl.work_mode = 1;
|
||||
} else if (adc_unit == ADC_UNIT_ALTER) {
|
||||
// saradc mode sel : 0--single saradc; 1--double saradc; 2--alternative saradc
|
||||
SYSCON.saradc_ctrl.work_mode = 2;
|
||||
}
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t adc_set_atten(adc_unit_t adc_unit, adc_channel_t channel, adc_atten_t atten)
|
||||
{
|
||||
ADC_CHECK_UNIT(adc_unit);
|
||||
if (adc_unit & ADC_UNIT_1) {
|
||||
RTC_MODULE_CHECK((adc1_channel_t)channel < ADC1_CHANNEL_MAX, "ADC Channel Err", ESP_ERR_INVALID_ARG);
|
||||
}
|
||||
RTC_MODULE_CHECK(atten < ADC_ATTEN_MAX, "ADC Atten Err", ESP_ERR_INVALID_ARG);
|
||||
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
if (adc_unit & ADC_UNIT_1) {
|
||||
//SAR1_atten
|
||||
SET_PERI_REG_BITS(SENS_SAR_ATTEN1_REG, SENS_SAR1_ATTEN_VAL_MASK, atten, (channel * 2));
|
||||
}
|
||||
if (adc_unit & ADC_UNIT_2) {
|
||||
//SAR2_atten
|
||||
SET_PERI_REG_BITS(SENS_SAR_ATTEN2_REG, SENS_SAR2_ATTEN_VAL_MASK, atten, (channel * 2));
|
||||
}
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void adc_power_on()
|
||||
{
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
//Bit1 0:Fsm 1: SW mode
|
||||
//Bit0 0:SW mode power down 1: SW mode power on
|
||||
SENS.sar_meas_wait2.force_xpd_sar = ADC_FORCE_ENABLE;
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
}
|
||||
|
||||
void adc_power_off()
|
||||
{
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
//Bit1 0:Fsm 1: SW mode
|
||||
//Bit0 0:SW mode power down 1: SW mode power on
|
||||
SENS.sar_meas_wait2.force_xpd_sar = ADC_FORCE_DISABLE;
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
}
|
||||
|
||||
esp_err_t adc_set_clk_div(uint8_t clk_div)
|
||||
{
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
// ADC clock devided from APB clk, 80 / 2 = 40Mhz,
|
||||
SYSCON.saradc_ctrl.sar_clk_div = clk_div;
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t adc_set_i2s_data_source(adc_i2s_source_t src)
|
||||
{
|
||||
RTC_MODULE_CHECK(src < ADC_I2S_DATA_SRC_MAX, "ADC i2s data source error", ESP_ERR_INVALID_ARG);
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
// 1: I2S input data is from SAR ADC (for DMA) 0: I2S input data is from GPIO matrix
|
||||
SYSCON.saradc_ctrl.data_to_i2s = src;
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t adc_gpio_init(adc_unit_t adc_unit, adc_channel_t channel)
|
||||
{
|
||||
ADC_CHECK_UNIT(adc_unit);
|
||||
gpio_num_t gpio_num = 0;
|
||||
if (adc_unit & ADC_UNIT_1) {
|
||||
RTC_MODULE_CHECK((adc1_channel_t) channel < ADC1_CHANNEL_MAX, "ADC1 channel error", ESP_ERR_INVALID_ARG);
|
||||
ADC1_CHECK_FUNCTION_RET(adc1_pad_get_io_num((adc1_channel_t) channel, &gpio_num));
|
||||
ADC1_CHECK_FUNCTION_RET(rtc_gpio_init(gpio_num));
|
||||
ADC1_CHECK_FUNCTION_RET(rtc_gpio_output_disable(gpio_num));
|
||||
ADC1_CHECK_FUNCTION_RET(rtc_gpio_input_disable(gpio_num));
|
||||
ADC1_CHECK_FUNCTION_RET(gpio_set_pull_mode(gpio_num, GPIO_FLOATING));
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t adc_set_data_inv(adc_unit_t adc_unit, bool inv_en)
|
||||
{
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
if (adc_unit & ADC_UNIT_1) {
|
||||
// Enable ADC data invert
|
||||
SENS.sar_read_ctrl.sar1_data_inv = inv_en;
|
||||
}
|
||||
if (adc_unit & ADC_UNIT_2) {
|
||||
// Enable ADC data invert
|
||||
SENS.sar_read_ctrl2.sar2_data_inv = inv_en;
|
||||
}
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t adc_set_data_width(adc_unit_t adc_unit, adc_bits_width_t bits)
|
||||
{
|
||||
ADC_CHECK_UNIT(adc_unit);
|
||||
RTC_MODULE_CHECK(bits < ADC_WIDTH_MAX, "ADC bit width error", ESP_ERR_INVALID_ARG);
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
if (adc_unit & ADC_UNIT_1) {
|
||||
SENS.sar_start_force.sar1_bit_width = bits;
|
||||
SENS.sar_read_ctrl.sar1_sample_bit = bits;
|
||||
}
|
||||
if (adc_unit & ADC_UNIT_2) {
|
||||
SENS.sar_start_force.sar2_bit_width = bits;
|
||||
SENS.sar_read_ctrl2.sar2_sample_bit = bits;
|
||||
}
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t adc_set_i2s_data_len(adc_unit_t adc_unit, int patt_len)
|
||||
{
|
||||
ADC_CHECK_UNIT(adc_unit);
|
||||
RTC_MODULE_CHECK((patt_len < ADC_PATT_LEN_MAX) && (patt_len > 0), "ADC pattern length error", ESP_ERR_INVALID_ARG);
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
if(adc_unit & ADC_UNIT_1) {
|
||||
SYSCON.saradc_ctrl.sar1_patt_len = patt_len - 1;
|
||||
}
|
||||
if(adc_unit & ADC_UNIT_2) {
|
||||
SYSCON.saradc_ctrl.sar2_patt_len = patt_len - 1;
|
||||
}
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t adc_set_i2s_data_pattern(adc_unit_t adc_unit, int seq_num, adc_channel_t channel, adc_bits_width_t bits, adc_atten_t atten)
|
||||
{
|
||||
ADC_CHECK_UNIT(adc_unit);
|
||||
if (adc_unit & ADC_UNIT_1) {
|
||||
RTC_MODULE_CHECK((adc1_channel_t) channel < ADC1_CHANNEL_MAX, "ADC1 channel error", ESP_ERR_INVALID_ARG);
|
||||
}
|
||||
RTC_MODULE_CHECK(bits < ADC_WIDTH_MAX, "ADC bit width error", ESP_ERR_INVALID_ARG);
|
||||
RTC_MODULE_CHECK(atten < ADC_ATTEN_MAX, "ADC Atten Err", ESP_ERR_INVALID_ARG);
|
||||
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
//Configure pattern table, each 8 bit defines one channel
|
||||
//[7:4]-channel [3:2]-bit width [1:0]- attenuation
|
||||
//BIT WIDTH: 3: 12BIT 2: 11BIT 1: 10BIT 0: 9BIT
|
||||
//ATTEN: 3: ATTEN = 11dB 2: 6dB 1: 2.5dB 0: 0dB
|
||||
uint8_t val = (channel << 4) | (bits << 2) | (atten << 0);
|
||||
if (adc_unit & ADC_UNIT_1) {
|
||||
SYSCON.saradc_sar1_patt_tab[seq_num / 4] &= (~(0xff << ((3 - (seq_num % 4)) * 8)));
|
||||
SYSCON.saradc_sar1_patt_tab[seq_num / 4] |= (val << ((3 - (seq_num % 4)) * 8));
|
||||
}
|
||||
if (adc_unit & ADC_UNIT_2) {
|
||||
SYSCON.saradc_sar2_patt_tab[seq_num / 4] &= (~(0xff << ((3 - (seq_num % 4)) * 8)));
|
||||
SYSCON.saradc_sar2_patt_tab[seq_num / 4] |= (val << ((3 - (seq_num % 4)) * 8));
|
||||
}
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t adc_i2s_mode_init(adc_unit_t adc_unit, adc_channel_t channel)
|
||||
{
|
||||
ADC_CHECK_UNIT(adc_unit);
|
||||
if (adc_unit & ADC_UNIT_1) {
|
||||
RTC_MODULE_CHECK((adc1_channel_t) channel < ADC1_CHANNEL_MAX, "ADC1 channel error", ESP_ERR_INVALID_ARG);
|
||||
}
|
||||
|
||||
uint8_t table_len = 1;
|
||||
//POWER ON SAR
|
||||
adc_power_on();
|
||||
adc_gpio_init(adc_unit, channel);
|
||||
adc_set_i2s_data_len(adc_unit, table_len);
|
||||
adc_set_i2s_data_pattern(adc_unit, 0, channel, ADC_WIDTH_BIT_12, ADC_ATTEN_DB_11);
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
if (adc_unit & ADC_UNIT_1) {
|
||||
//switch SARADC into DIG channel
|
||||
SENS.sar_read_ctrl.sar1_dig_force = 1;
|
||||
}
|
||||
if (adc_unit & ADC_UNIT_2) {
|
||||
//switch SARADC into DIG channel
|
||||
SENS.sar_read_ctrl2.sar2_dig_force = 1;
|
||||
//1: SAR ADC2 is controlled by DIG ADC2 CTRL 0: SAR ADC2 is controlled by PWDET CTRL
|
||||
SYSCON.saradc_ctrl.sar2_mux = 1;
|
||||
}
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
adc_set_i2s_data_source(ADC_I2S_DATA_SRC_ADC);
|
||||
adc_set_clk_div(SAR_ADC_CLK_DIV_DEFUALT);
|
||||
// Set internal FSM wait time.
|
||||
adc_set_fsm_time(ADC_FSM_RSTB_WAIT_DEFAULT, ADC_FSM_START_WAIT_DEFAULT, ADC_FSM_STANDBY_WAIT_DEFAULT,
|
||||
ADC_FSM_TIME_KEEP);
|
||||
adc_set_work_mode(adc_unit);
|
||||
adc_set_data_format(ADC_ENCODE_12BIT);
|
||||
adc_set_measure_limit(ADC_MAX_MEAS_NUM_DEFAULT, ADC_MEAS_NUM_LIM_DEFAULT);
|
||||
//Invert The Level, Invert SAR ADC1 data
|
||||
adc_set_data_inv(adc_unit, true);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t adc1_config_channel_atten(adc1_channel_t channel, adc_atten_t atten)
|
||||
{
|
||||
RTC_MODULE_CHECK(channel < ADC1_CHANNEL_MAX, "ADC Channel Err", ESP_ERR_INVALID_ARG);
|
||||
RTC_MODULE_CHECK(atten <= ADC_ATTEN_11db, "ADC Atten Err", ESP_ERR_INVALID_ARG);
|
||||
adc1_pad_init(channel);
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
SET_PERI_REG_BITS(SENS_SAR_ATTEN1_REG, 3, atten, (channel * 2)); //SAR1_atten
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
|
||||
RTC_MODULE_CHECK(atten < ADC_ATTEN_MAX, "ADC Atten Err", ESP_ERR_INVALID_ARG);
|
||||
adc_gpio_init(ADC_UNIT_1, channel);
|
||||
adc_set_atten(ADC_UNIT_1, channel, atten);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t adc1_config_width(adc_bits_width_t width_bit)
|
||||
{
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
SET_PERI_REG_BITS(SENS_SAR_START_FORCE_REG, SENS_SAR1_BIT_WIDTH_V, width_bit, SENS_SAR1_BIT_WIDTH_S); //SAR2_BIT_WIDTH[1:0]=0x3, SAR1_BIT_WIDTH[1:0]=0x3
|
||||
//Invert the adc value,the Output value is invert
|
||||
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR1_DATA_INV);
|
||||
//Set The adc sample width,invert adc value,must
|
||||
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL_REG, SENS_SAR1_SAMPLE_BIT_V, width_bit, SENS_SAR1_SAMPLE_BIT_S); //digital sar1_bit_width[1:0]=3
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
|
||||
RTC_MODULE_CHECK(width_bit < ADC_WIDTH_MAX, "ADC bit width error", ESP_ERR_INVALID_ARG);
|
||||
adc_set_data_width(ADC_UNIT_1, width_bit);
|
||||
adc_set_data_inv(ADC_UNIT_1, true);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int adc1_get_raw(adc1_channel_t channel)
|
||||
{
|
||||
uint16_t adc_value;
|
||||
|
||||
RTC_MODULE_CHECK(channel < ADC1_CHANNEL_MAX, "ADC Channel Err", ESP_ERR_INVALID_ARG);
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
//Adc Controler is Rtc module,not ulp coprocessor
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_START1_REG, 1, 1, SENS_MEAS1_START_FORCE_S); //force pad mux and force start
|
||||
SENS.sar_meas_start1.meas1_start_force = 1;
|
||||
//Bit1=0:Fsm Bit1=1(Bit0=0:PownDown Bit10=1:Powerup)
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 0, SENS_FORCE_XPD_SAR_S); //force XPD_SAR=0, use XPD_FSM
|
||||
SENS.sar_meas_wait2.force_xpd_sar = 0;
|
||||
//Disable Amp Bit1=0:Fsm Bit1=1(Bit0=0:PownDown Bit10=1:Powerup)
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_AMP, 0x2, SENS_FORCE_XPD_AMP_S); //force XPD_AMP=0
|
||||
SENS.sar_meas_wait2.force_xpd_amp = 0x2;
|
||||
//Open the ADC1 Data port Not ulp coprocessor
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_START1_REG, 1, 1, SENS_SAR1_EN_PAD_FORCE_S); //open the ADC1 data port
|
||||
SENS.sar_meas_start1.sar1_en_pad_force = 1;
|
||||
//Select channel
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_START1_REG, SENS_SAR1_EN_PAD, (1 << channel), SENS_SAR1_EN_PAD_S); //pad enable
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_CTRL_REG, 0xfff, 0x0, SENS_AMP_RST_FB_FSM_S); //[11:8]:short ref ground, [7:4]:short ref, [3:0]:rst fb
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT1_REG, SENS_SAR_AMP_WAIT1, 0x1, SENS_SAR_AMP_WAIT1_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT1_REG, SENS_SAR_AMP_WAIT2, 0x1, SENS_SAR_AMP_WAIT2_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_SAR_AMP_WAIT3, 0x1, SENS_SAR_AMP_WAIT3_S);
|
||||
while (GET_PERI_REG_BITS2(SENS_SAR_SLAVE_ADDR1_REG, 0x7, SENS_MEAS_STATUS_S) != 0); //wait det_fsm==0
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_START1_REG, 1, 0, SENS_MEAS1_START_SAR_S); //start force 0
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_START1_REG, 1, 1, SENS_MEAS1_START_SAR_S); //start force 1
|
||||
while (GET_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DONE_SAR) == 0) {}; //read done
|
||||
adc_value = GET_PERI_REG_BITS2(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_DATA_SAR, SENS_MEAS1_DATA_SAR_S);
|
||||
SENS.sar_meas_start1.sar1_en_pad = (1 << channel);
|
||||
SENS.sar_meas_ctrl.amp_rst_fb_fsm = 0;
|
||||
SENS.sar_meas_ctrl.amp_short_ref_fsm = 0;
|
||||
SENS.sar_meas_ctrl.amp_short_ref_gnd_fsm = 0;
|
||||
SENS.sar_meas_wait1.sar_amp_wait1 = 1;
|
||||
SENS.sar_meas_wait1.sar_amp_wait2 = 1;
|
||||
SENS.sar_meas_wait2.sar_amp_wait3 = 1;
|
||||
while (SENS.sar_slave_addr1.meas_status != 0);
|
||||
SENS.sar_meas_start1.meas1_start_sar = 0;
|
||||
SENS.sar_meas_start1.meas1_start_sar = 1;
|
||||
while (SENS.sar_meas_start1.meas1_done_sar == 0);
|
||||
adc_value = SENS.sar_meas_start1.meas1_data_sar;
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
|
||||
return adc_value;
|
||||
}
|
||||
|
||||
@@ -983,14 +1235,16 @@ int adc1_get_voltage(adc1_channel_t channel) //Deprecated. Use adc1_get_raw()
|
||||
void adc1_ulp_enable(void)
|
||||
{
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_FORCE);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_SAR1_EN_PAD_FORCE_M);
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_AMP, 0x2, SENS_FORCE_XPD_AMP_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 0, SENS_FORCE_XPD_SAR_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_CTRL_REG, 0xfff, 0x0, SENS_AMP_RST_FB_FSM_S); //[11:8]:short ref ground, [7:4]:short ref, [3:0]:rst fb
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT1_REG, SENS_SAR_AMP_WAIT1, 0x1, SENS_SAR_AMP_WAIT1_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT1_REG, SENS_SAR_AMP_WAIT2, 0x1, SENS_SAR_AMP_WAIT2_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_SAR_AMP_WAIT3, 0x1, SENS_SAR_AMP_WAIT3_S);
|
||||
SENS.sar_meas_start1.meas1_start_force = 0;
|
||||
SENS.sar_meas_start1.sar1_en_pad_force = 0;
|
||||
SENS.sar_meas_wait2.force_xpd_amp = 0x2;
|
||||
SENS.sar_meas_wait2.force_xpd_sar = 0;
|
||||
SENS.sar_meas_ctrl.amp_rst_fb_fsm = 0;
|
||||
SENS.sar_meas_ctrl.amp_short_ref_fsm = 0;
|
||||
SENS.sar_meas_ctrl.amp_short_ref_gnd_fsm = 0;
|
||||
SENS.sar_meas_wait1.sar_amp_wait1 = 0x1;
|
||||
SENS.sar_meas_wait1.sar_amp_wait2 = 1;
|
||||
SENS.sar_meas_wait2.sar_amp_wait3 = 0x1;
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
}
|
||||
|
||||
@@ -1199,10 +1453,10 @@ static int hall_sensor_get_value() //hall sensor without LNA
|
||||
|
||||
int hall_sensor_read()
|
||||
{
|
||||
adc1_pad_init(ADC1_CHANNEL_0);
|
||||
adc1_pad_init(ADC1_CHANNEL_3);
|
||||
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_0db);
|
||||
adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_0db);
|
||||
adc_gpio_init(ADC_UNIT_1, ADC1_CHANNEL_0);
|
||||
adc_gpio_init(ADC_UNIT_1, ADC1_CHANNEL_3);
|
||||
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_0);
|
||||
adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_0);
|
||||
return hall_sensor_get_value();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user