From b38f4646deb0d14aecacd55d16d5137d166d89c0 Mon Sep 17 00:00:00 2001 From: Armando Date: Tue, 8 Dec 2020 14:50:32 +0800 Subject: [PATCH 01/22] adc_digi: add dma drivers --- components/driver/esp32c3/adc.c | 90 +++- .../driver/esp32c3/include/driver/adc.h | 33 ++ components/driver/include/driver/adc_common.h | 37 +- components/hal/CMakeLists.txt | 6 +- components/hal/adc_hal.c | 20 +- components/hal/esp32c3/include/hal/adc_ll.h | 388 +++++++++++++++--- .../hal/esp32c3/include/hal/clk_gate_ll.h | 2 + components/hal/include/hal/adc_hal.h | 5 +- components/hal/include/hal/adc_types.h | 19 +- .../peripherals/adc_dma_demo/CMakeLists.txt | 6 + examples/peripherals/adc_dma_demo/README.md | 55 +++ .../adc_dma_demo/main/CMakeLists.txt | 2 + .../adc_dma_demo/main/adc_dma_example_main.c | 117 ++++++ 13 files changed, 656 insertions(+), 124 deletions(-) create mode 100644 examples/peripherals/adc_dma_demo/CMakeLists.txt create mode 100644 examples/peripherals/adc_dma_demo/README.md create mode 100644 examples/peripherals/adc_dma_demo/main/CMakeLists.txt create mode 100644 examples/peripherals/adc_dma_demo/main/adc_dma_example_main.c diff --git a/components/driver/esp32c3/adc.c b/components/driver/esp32c3/adc.c index 5e9748cd82..f1de2eb0a4 100644 --- a/components/driver/esp32c3/adc.c +++ b/components/driver/esp32c3/adc.c @@ -238,6 +238,7 @@ static IRAM_ATTR void adc_dma_intr(void *arg) s_adc_digi_ctx->hal_dma_config.desc_cnt = 0; //start next turns of dma operation + adc_hal_digi_dma_multi_descriptor(&s_adc_digi_ctx->hal_dma_config, s_adc_digi_ctx->rx_dma_buf, s_adc_digi_ctx->bytes_between_intr, s_adc_digi_ctx->hal_dma_config.desc_max_num); adc_hal_digi_rxdma_start(&s_adc_digi_ctx->hal_dma, &s_adc_digi_ctx->hal_dma_config); } @@ -326,7 +327,7 @@ esp_err_t adc_digi_read_bytes(uint8_t *buf, uint32_t length_max, uint32_t *out_l data = xRingbufferReceiveUpTo(s_adc_digi_ctx->ringbuf_hdl, &size, ticks_to_wait, length_max); if (!data) { - ESP_LOGW(ADC_DMA_TAG, "No data, increase timeout or reduce conv_num_each_intr"); + ESP_LOGV(ADC_DMA_TAG, "No data, increase timeout or reduce conv_num_each_intr"); ret = ESP_ERR_TIMEOUT; *out_length = 0; return ret; @@ -340,6 +341,7 @@ esp_err_t adc_digi_read_bytes(uint8_t *buf, uint32_t length_max, uint32_t *out_l if (s_adc_digi_ctx->ringbuf_overflow_flag) { ret = ESP_ERR_INVALID_STATE; } + return ret; } @@ -382,8 +384,8 @@ static adc_atten_t s_atten2_single[ADC2_CHANNEL_MAX]; //Array saving attenuat esp_err_t adc1_config_width(adc_bits_width_t width_bit) { - //On ESP32C3, the data width is always 13-bits. - if (width_bit != ADC_WIDTH_BIT_13) { + //On ESP32C3, the data width is always 12-bits. + if (width_bit != ADC_WIDTH_BIT_12) { return ESP_ERR_INVALID_ARG; } @@ -404,40 +406,41 @@ esp_err_t adc1_config_channel_atten(adc1_channel_t channel, adc_atten_t atten) int adc1_get_raw(adc1_channel_t channel) { - int result = 0; + int raw_out = 0; adc_digi_config_t dig_cfg = { .conv_limit_en = 0, .conv_limit_num = 250, .interval = 40, .dig_clk.use_apll = 0, - .dig_clk.div_num = 1, + .dig_clk.div_num = 15, .dig_clk.div_a = 0, .dig_clk.div_b = 1, }; ADC_DIGI_LOCK_ACQUIRE(); + periph_module_enable(PERIPH_SARADC_MODULE); adc_hal_digi_controller_config(&dig_cfg); adc_hal_intr_clear(ADC_EVENT_ADC1_DONE); - adc_hal_onetime_channel(ADC_NUM_1, channel); adc_hal_set_onetime_atten(s_atten1_single[channel]); - adc_hal_adc1_onetime_sample_enable(true); //Trigger single read. + adc_hal_adc1_onetime_sample_enable(true); adc_hal_onetime_start(&dig_cfg); while (!adc_hal_intr_get_raw(ADC_EVENT_ADC1_DONE)); adc_hal_intr_clear(ADC_EVENT_ADC1_DONE); adc_hal_adc1_onetime_sample_enable(false); - result = adc_hal_adc1_read(); + adc_hal_single_read(ADC_NUM_1, &raw_out); adc_hal_digi_deinit(); + periph_module_disable(PERIPH_SARADC_MODULE); ADC_DIGI_LOCK_RELEASE(); - return result; + return raw_out; } esp_err_t adc2_config_channel_atten(adc2_channel_t channel, adc_atten_t atten) @@ -454,17 +457,18 @@ esp_err_t adc2_config_channel_atten(adc2_channel_t channel, adc_atten_t atten) esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int *raw_out) { - //On ESP32C3, the data width is always 13-bits. - if (width_bit != ADC_WIDTH_BIT_13) { + //On ESP32C3, the data width is always 12-bits. + if (width_bit != ADC_WIDTH_BIT_12) { return ESP_ERR_INVALID_ARG; } + esp_err_t ret = ESP_OK; adc_digi_config_t dig_cfg = { .conv_limit_en = 0, .conv_limit_num = 250, .interval = 40, .dig_clk.use_apll = 0, - .dig_clk.div_num = 1, + .dig_clk.div_num = 15, .dig_clk.div_a = 0, .dig_clk.div_b = 1, }; @@ -472,23 +476,27 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int * SAC_ADC2_LOCK_ACQUIRE(); ADC_DIGI_LOCK_ACQUIRE(); + periph_module_enable(PERIPH_SARADC_MODULE); adc_hal_digi_controller_config(&dig_cfg); adc_hal_intr_clear(ADC_EVENT_ADC2_DONE); - adc_hal_onetime_channel(ADC_NUM_2, channel); adc_hal_set_onetime_atten(s_atten2_single[channel]); - adc_hal_adc2_onetime_sample_enable(true); //Trigger single read. + adc_hal_adc2_onetime_sample_enable(true); adc_hal_onetime_start(&dig_cfg); while (!adc_hal_intr_get_raw(ADC_EVENT_ADC2_DONE)); adc_hal_intr_clear(ADC_EVENT_ADC2_DONE); adc_hal_adc2_onetime_sample_enable(false); - *raw_out = adc_hal_adc2_read(); + ret = adc_hal_single_read(ADC_NUM_2, raw_out); + if (ret != ESP_OK) { + return ret; + } adc_hal_digi_deinit(); + periph_module_disable(PERIPH_SARADC_MODULE); ADC_DIGI_LOCK_RELEASE(); SAC_ADC2_LOCK_RELEASE(); @@ -547,12 +555,12 @@ esp_err_t adc_arbiter_config(adc_unit_t adc_unit, adc_arbiter_t *config) * @note For ADC1, Controller access is mutually exclusive. * * @param adc_unit ADC unit. - * @param ctrl ADC controller, Refer to `adc_ll_controller_t`. + * @param ctrl ADC controller, Refer to `adc_controller_t`. * * @return * - ESP_OK Success */ -esp_err_t adc_set_controller(adc_unit_t adc_unit, adc_ll_controller_t ctrl) +esp_err_t adc_set_controller(adc_unit_t adc_unit, adc_controller_t ctrl) { adc_arbiter_t config = {0}; adc_arbiter_t cfg = ADC_ARBITER_CONFIG_DEFAULT(); @@ -611,22 +619,54 @@ esp_err_t adc_digi_reset(void) esp_err_t adc_digi_filter_reset(adc_digi_filter_idx_t idx) { - abort(); // TODO ESP32-C3 IDF-2528 + ADC_ENTER_CRITICAL(); + if (idx == ADC_DIGI_FILTER_IDX0) { + adc_hal_digi_filter_reset(ADC_NUM_1); + } else if (idx == ADC_DIGI_FILTER_IDX1) { + adc_hal_digi_filter_reset(ADC_NUM_2); + } + ADC_EXIT_CRITICAL(); + return ESP_OK; } esp_err_t adc_digi_filter_set_config(adc_digi_filter_idx_t idx, adc_digi_filter_t *config) { - abort(); // TODO ESP32-C3 IDF-2528 + ADC_ENTER_CRITICAL(); + if (idx == ADC_DIGI_FILTER_IDX0) { + adc_hal_digi_filter_set_factor(ADC_NUM_1, config->mode); + } else if (idx == ADC_DIGI_FILTER_IDX1) { + adc_hal_digi_filter_set_factor(ADC_NUM_2, config->mode); + } + ADC_EXIT_CRITICAL(); + return ESP_OK; } esp_err_t adc_digi_filter_get_config(adc_digi_filter_idx_t idx, adc_digi_filter_t *config) { - abort(); // TODO ESP32-C3 IDF-2528 + ADC_ENTER_CRITICAL(); + if (idx == ADC_DIGI_FILTER_IDX0) { + config->adc_unit = ADC_UNIT_1; + config->channel = ADC_CHANNEL_MAX; + adc_hal_digi_filter_get_factor(ADC_NUM_1, &config->mode); + } else if (idx == ADC_DIGI_FILTER_IDX1) { + config->adc_unit = ADC_UNIT_2; + config->channel = ADC_CHANNEL_MAX; + adc_hal_digi_filter_get_factor(ADC_NUM_2, &config->mode); + } + ADC_EXIT_CRITICAL(); + return ESP_OK; } esp_err_t adc_digi_filter_enable(adc_digi_filter_idx_t idx, bool enable) { - abort(); // TODO ESP32-C3 IDF-2528 + ADC_ENTER_CRITICAL(); + if (idx == ADC_DIGI_FILTER_IDX0) { + adc_hal_digi_filter_enable(ADC_NUM_1, enable); + } else if (idx == ADC_DIGI_FILTER_IDX1) { + adc_hal_digi_filter_enable(ADC_NUM_2, enable); + } + ADC_EXIT_CRITICAL(); + return ESP_OK; } /** @@ -638,7 +678,13 @@ esp_err_t adc_digi_filter_enable(adc_digi_filter_idx_t idx, bool enable) */ int adc_digi_filter_read_data(adc_digi_filter_idx_t idx) { - abort(); // TODO ESP32-C3 IDF-2528 + if (idx == ADC_DIGI_FILTER_IDX0) { + return adc_hal_digi_filter_read_data(ADC_NUM_1); + } else if (idx == ADC_DIGI_FILTER_IDX1) { + return adc_hal_digi_filter_read_data(ADC_NUM_2); + } else { + return -1; + } } /**************************************/ diff --git a/components/driver/esp32c3/include/driver/adc.h b/components/driver/esp32c3/include/driver/adc.h index 463778a3a9..fc8b59412d 100644 --- a/components/driver/esp32c3/include/driver/adc.h +++ b/components/driver/esp32c3/include/driver/adc.h @@ -186,6 +186,39 @@ esp_err_t adc_digi_isr_register(void (*fn)(void *), void *arg, int intr_alloc_fl */ esp_err_t adc_digi_isr_deregister(void); +/*--------------------------------------------------------------- + RTC controller setting +---------------------------------------------------------------*/ + +/*--------------------------------------------------------------- + Deprecated API +---------------------------------------------------------------*/ +/** + * @brief Set I2S data source + * + * @param src I2S DMA data source, I2S DMA can get data from digital signals or from ADC. + * + * @deprecated The ESP32C3 doesn't use I2S DMA. Call ``adc_digi_controller_config`` instead. + * + * @return + * - ESP_OK success + */ +esp_err_t adc_set_i2s_data_source(adc_i2s_source_t src) __attribute__((deprecated)); + +/** + * @brief Initialize I2S ADC mode + * + * @param adc_unit ADC unit index + * @param channel ADC channel index + * + * @deprecated The ESP32C3 doesn't use I2S DMA. Call ``adc_digi_controller_config`` instead. + * + * @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) __attribute__((deprecated)); + #ifdef __cplusplus } #endif diff --git a/components/driver/include/driver/adc_common.h b/components/driver/include/driver/adc_common.h index cbdd377b66..5eafc8d508 100644 --- a/components/driver/include/driver/adc_common.h +++ b/components/driver/include/driver/adc_common.h @@ -37,7 +37,8 @@ typedef enum { ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO35 */ ADC1_CHANNEL_MAX, } adc1_channel_t; -#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // TODO ESP32-S3 channels are wrong IDF-1776 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +//S3 is not sure. Need to be checked when bringing up S3 /**** `adc1_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ typedef enum { ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO1 */ @@ -62,9 +63,10 @@ typedef enum { ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO34 */ ADC1_CHANNEL_MAX, } adc1_channel_t; -#endif // CONFIG_IDF_TARGET_* +#endif -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // TODO ESP32-S3 channels are wrong IDF-1776 +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +//S3 is not sure. Need to be checked when bringing up S3 /**** `adc2_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ typedef enum { ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO4 (ESP32), GPIO11 (ESP32-S2) */ @@ -141,32 +143,14 @@ typedef struct adc_digi_init_config_s { /** * @brief Enable ADC power - * @deprecated Use adc_power_acquire and adc_power_release instead. */ -void adc_power_on(void) __attribute__((deprecated)); +void adc_power_on(void); /** * @brief Power off SAR ADC - * @deprecated Use adc_power_acquire and adc_power_release instead. - * This function will force power down for ADC. - * This function is deprecated because forcing power ADC power off may - * disrupt operation of other components which may be using the ADC. + * This function will force power down for ADC */ -void adc_power_off(void) __attribute__((deprecated)); - -/** - * @brief Increment the usage counter for ADC module. - * ADC will stay powered on while the counter is greater than 0. - * Call adc_power_release when done using the ADC. - */ -void adc_power_acquire(void); - -/** - * @brief Decrement the usage counter for ADC module. - * ADC will stay powered on while the counter is greater than 0. - * Call this function when done using the ADC. - */ -void adc_power_release(void); +void adc_power_off(void); /** * @brief Initialize ADC pad @@ -258,8 +242,6 @@ esp_err_t adc1_config_width(adc_bits_width_t width_bit); * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. - * As a workaround, call adc_power_acquire() in the app. This will result in higher power consumption (by ~1mA), - * but will remove the glitches on GPIO36 and GPIO39. * * @note Call ``adc1_config_width()`` before the first time this * function is called. @@ -385,9 +367,6 @@ esp_err_t adc2_config_channel_atten(adc2_channel_t channel, adc_atten_t atten); * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. - * As a workaround, call adc_power_acquire() in the app. This will result in higher power consumption (by ~1mA), - * but will remove the glitches on GPIO36 and GPIO39. - * * * @note ESP32: * For a given channel, ``adc2_config_channel_atten()`` diff --git a/components/hal/CMakeLists.txt b/components/hal/CMakeLists.txt index 68e3cbfac6..b3b5b2305a 100644 --- a/components/hal/CMakeLists.txt +++ b/components/hal/CMakeLists.txt @@ -30,11 +30,11 @@ if(NOT BOOTLOADER_BUILD) "sha_hal.c" "aes_hal.c" "twai_hal.c" - "twai_hal_iram.c") + "twai_hal_iram.c" + "adc_hal.c") if(${target} STREQUAL "esp32") list(APPEND srcs - "adc_hal.c" "dac_hal.c" "mcpwm_hal.c" "pcnt_hal.c" @@ -52,7 +52,6 @@ if(NOT BOOTLOADER_BUILD) if(${target} STREQUAL "esp32s2") list(APPEND srcs - "adc_hal.c" "dac_hal.c" "pcnt_hal.c" "spi_flash_hal_gpspi.c" @@ -70,7 +69,6 @@ if(NOT BOOTLOADER_BUILD) if(${target} STREQUAL "esp32s3") list(APPEND srcs - "adc_hal.c" "dac_hal.c" "gdma_hal.c" "pcnt_hal.c" diff --git a/components/hal/adc_hal.c b/components/hal/adc_hal.c index 787bc71039..00647c2fb9 100644 --- a/components/hal/adc_hal.c +++ b/components/hal/adc_hal.c @@ -15,6 +15,7 @@ #include "hal/adc_hal.h" #include "hal/adc_hal_conf.h" + #if CONFIG_IDF_TARGET_ESP32C3 #include "soc/soc.h" #include "esp_rom_sys.h" @@ -123,7 +124,7 @@ void adc_hal_digi_init(adc_dma_hal_context_t *adc_dma_ctx, adc_dma_hal_config_t adc_dma_ctx->dev = &GDMA; gdma_ll_enable_clock(adc_dma_ctx->dev, true); gdma_ll_clear_interrupt_status(adc_dma_ctx->dev, dma_config->dma_chan, UINT32_MAX); - gdma_ll_rx_connect_to_periph(adc_dma_ctx->dev, dma_config->dma_chan, SOC_GDMA_TRIG_PERIPH_ADC0); + gdma_ll_rx_connect_to_periph(adc_dma_ctx->dev, dma_config->dma_chan, GDMA_LL_TRIG_SRC_ADC_DAC); } /*--------------------------------------------------------------- @@ -183,14 +184,17 @@ void adc_hal_set_onetime_atten(adc_atten_t atten) adc_ll_onetime_set_atten(atten); } -uint32_t adc_hal_adc1_read(void) +esp_err_t adc_hal_single_read(adc_ll_num_t unit, int *out_raw) { - return adc_ll_adc1_read(); -} - -uint32_t adc_hal_adc2_read(void) -{ - return adc_ll_adc2_read(); + if (unit == ADC_NUM_1) { + *out_raw = adc_ll_adc1_read(); + } else if (unit == ADC_NUM_2) { + *out_raw = adc_ll_adc2_read(); + if (adc_ll_rtc_analysis_raw_data(unit, *out_raw)) { + return ESP_ERR_INVALID_STATE; + } + } + return ESP_OK; } //--------------------INTR------------------------------- diff --git a/components/hal/esp32c3/include/hal/adc_ll.h b/components/hal/esp32c3/include/hal/adc_ll.h index 4e923babb5..9ccbc355c5 100644 --- a/components/hal/esp32c3/include/hal/adc_ll.h +++ b/components/hal/esp32c3/include/hal/adc_ll.h @@ -20,8 +20,6 @@ #include "soc/apb_saradc_struct.h" #include "soc/apb_saradc_reg.h" #include "soc/rtc_cntl_struct.h" -#include "soc/rtc_cntl_reg.h" -#include "regi2c_ctrl.h" #include "esp_attr.h" @@ -29,6 +27,8 @@ extern "C" { #endif +#define ADC_LL_ADC2_CHANNEL_MAX 1 + typedef enum { ADC_NUM_1 = 0, /*!< SAR ADC 1 */ ADC_NUM_2 = 1, /*!< SAR ADC 2 */ @@ -75,7 +75,7 @@ typedef struct { }; uint16_t val; }; -} adc_ll_rtc_output_data_t; +} adc_rtc_output_data_t; #ifdef _MSC_VER #pragma pack(pop) @@ -95,7 +95,7 @@ typedef enum { ADC2_CTRL_FORCE_PWDET = 3, /*!> 13) >= ADC_LL_ADC2_CHANNEL_MAX) { + return ADC_RTC_DATA_FAIL; + } + + return ADC_RTC_DATA_OK; } /*--------------------------------------------------------------- @@ -720,7 +863,18 @@ static inline void adc_ll_set_power_manage(adc_ll_power_t manage) */ static inline adc_ll_power_t adc_ll_get_power_manage(void) { - abort(); // TODO ESP32-C3 IDF-2094 + /* Bit1 0:Fsm 1: SW mode + Bit0 0:SW mode power down 1: SW mode power on */ + // adc_ll_power_t manage; + // if (SENS.sar_power_xpd_sar.force_xpd_sar == SENS_FORCE_XPD_SAR_PU) { + // manage = ADC_POWER_SW_ON; + // } else if (SENS.sar_power_xpd_sar.force_xpd_sar == SENS_FORCE_XPD_SAR_PD) { + // manage = ADC_POWER_SW_OFF; + // } else { + // manage = ADC_POWER_BY_FSM; + // } + // return manage; + return 0; } /** @@ -730,7 +884,11 @@ static inline adc_ll_power_t adc_ll_get_power_manage(void) */ static inline void adc_ll_set_sar_clk_div(adc_ll_num_t adc_n, uint32_t div) { - abort(); // TODO ESP32-C3 IDF-2094 + // if (adc_n == ADC_NUM_1) { + // SENS.sar_reader1_ctrl.sar1_clk_div = div; + // } else { // adc_n == ADC_NUM_2 + // SENS.sar_reader2_ctrl.sar2_clk_div = div; + // } } /** @@ -768,7 +926,11 @@ static inline void adc_ll_set_sar_clk_div(adc_ll_num_t adc_n, uint32_t div) */ static inline void adc_ll_set_atten(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten) { - abort(); // TODO ESP32-C3 IDF-2094 + // if (adc_n == ADC_NUM_1) { + // SENS.sar_atten1 = ( SENS.sar_atten1 & ~(0x3 << (channel * 2)) ) | ((atten & 0x3) << (channel * 2)); + // } else { // adc_n == ADC_NUM_2 + // SENS.sar_atten2 = ( SENS.sar_atten2 & ~(0x3 << (channel * 2)) ) | ((atten & 0x3) << (channel * 2)); + // } } /** @@ -780,7 +942,12 @@ static inline void adc_ll_set_atten(adc_ll_num_t adc_n, adc_channel_t channel, a */ static inline adc_atten_t adc_ll_get_atten(adc_ll_num_t adc_n, adc_channel_t channel) { - abort(); // TODO ESP32-C3 IDF-2094 + abort(); // FIXME + // if (adc_n == ADC_NUM_1) { + // return (adc_atten_t)((SENS.sar_atten1 >> (channel * 2)) & 0x3); + // } else { + // return (adc_atten_t)((SENS.sar_atten2 >> (channel * 2)) & 0x3); + // } } /** @@ -793,9 +960,43 @@ static inline adc_atten_t adc_ll_get_atten(adc_ll_num_t adc_n, adc_channel_t cha * @param adc_n ADC unit. * @param ctrl ADC controller. */ -static inline void adc_ll_set_controller(adc_ll_num_t adc_n, adc_ll_controller_t ctrl) +static inline void adc_ll_set_controller(adc_ll_num_t adc_n, adc_controller_t ctrl) { - abort(); // TODO ESP32-C3 IDF-2094 + //NOTE: ULP is removed on C3, please remove ULP related (if there still are any) code and this comment + + // if (adc_n == ADC_NUM_1) { + // switch ( ctrl ) { + // case ADC_CTRL_RTC: + // SENS.sar_meas1_mux.sar1_dig_force = 0; // 1: Select digital control; 0: Select RTC control. + // SENS.sar_meas1_ctrl2.meas1_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. + // SENS.sar_meas1_ctrl2.sar1_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; + // break; + // case ADC_CTRL_DIG: + // SENS.sar_meas1_mux.sar1_dig_force = 1; // 1: Select digital control; 0: Select RTC control. + // SENS.sar_meas1_ctrl2.meas1_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. + // SENS.sar_meas1_ctrl2.sar1_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; + // break; + // default: + // break; + // } + // } else { // adc_n == ADC_NUM_2 + // switch ( ctrl ) { + // case ADC_CTRL_RTC: + // SENS.sar_meas2_ctrl2.meas2_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. + // SENS.sar_meas2_ctrl2.sar2_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; + // break; + // case ADC_CTRL_DIG: + // SENS.sar_meas2_ctrl2.meas2_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. + // SENS.sar_meas2_ctrl2.sar2_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; + // break; + // case ADC2_CTRL_PWDET: // currently only used by Wi-Fi + // SENS.sar_meas2_ctrl2.meas2_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. + // SENS.sar_meas2_ctrl2.sar2_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; + // break; + // default: + // break; + // } + // } } /** @@ -877,7 +1078,7 @@ static inline void adc_ll_set_arbiter_priority(uint8_t pri_rtc, uint8_t pri_dig, */ static inline void adc_ll_enable_sleep_controller(void) { - abort(); // TODO ESP32-C3 IDF-2094 + // SENS.sar_meas2_mux.sar2_rtc_force = 1; } /** @@ -891,10 +1092,51 @@ static inline void adc_ll_enable_sleep_controller(void) */ static inline void adc_ll_disable_sleep_controller(void) { - abort(); // TODO ESP32-C3 IDF-2094 + // SENS.sar_meas2_mux.sar2_rtc_force = 0; } /* ADC calibration code. */ +#include "soc/rtc_cntl_reg.h" +#include "regi2c_ctrl.h" + +#define I2C_ADC 0X69 +#define I2C_ADC_HOSTID 0 + +#define ANA_CONFIG2_REG 0x6000E048 +#define ANA_CONFIG2_M (BIT(18)) + +#define SAR1_ENCAL_GND_ADDR 0x7 +#define SAR1_ENCAL_GND_ADDR_MSB 5 +#define SAR1_ENCAL_GND_ADDR_LSB 5 + +#define SAR2_ENCAL_GND_ADDR 0x7 +#define SAR2_ENCAL_GND_ADDR_MSB 7 +#define SAR2_ENCAL_GND_ADDR_LSB 7 + +#define SAR1_INITIAL_CODE_HIGH_ADDR 0x1 +#define SAR1_INITIAL_CODE_HIGH_ADDR_MSB 0x3 +#define SAR1_INITIAL_CODE_HIGH_ADDR_LSB 0x0 + +#define SAR1_INITIAL_CODE_LOW_ADDR 0x0 +#define SAR1_INITIAL_CODE_LOW_ADDR_MSB 0x7 +#define SAR1_INITIAL_CODE_LOW_ADDR_LSB 0x0 + +#define SAR2_INITIAL_CODE_HIGH_ADDR 0x4 +#define SAR2_INITIAL_CODE_HIGH_ADDR_MSB 0x3 +#define SAR2_INITIAL_CODE_HIGH_ADDR_LSB 0x0 + +#define SAR2_INITIAL_CODE_LOW_ADDR 0x3 +#define SAR2_INITIAL_CODE_LOW_ADDR_MSB 0x7 +#define SAR2_INITIAL_CODE_LOW_ADDR_LSB 0x0 + +#define SAR1_DREF_ADDR 0x2 +#define SAR1_DREF_ADDR_MSB 0x6 +#define SAR1_DREF_ADDR_LSB 0x4 + +#define SAR2_DREF_ADDR 0x5 +#define SAR2_DREF_ADDR_MSB 0x6 +#define SAR2_DREF_ADDR_LSB 0x4 + #define ADC_HAL_CAL_OFFSET_RANGE (4096) #define ADC_HAL_CAL_TIMES (10) @@ -910,7 +1152,30 @@ static inline void adc_ll_disable_sleep_controller(void) */ static inline void adc_ll_calibration_prepare(adc_ll_num_t adc_n, adc_channel_t channel, bool internal_gnd) { - abort(); // TODO ESP32-C3 IDF-2526 + // /* Enable i2s_write_reg function. */ + // void phy_get_romfunc_addr(void); + // phy_get_romfunc_addr(); + // //CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PD_M); + // //SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M); + // CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18)); + // SET_PERI_REG_MASK(ANA_CONFIG2_REG, BIT(16)); + + // /* Enable/disable internal connect GND (for calibration). */ + // if (adc_n == ADC_NUM_1) { + // REGI2C_WRITE_MASK(I2C_ADC, SAR1_DREF_ADDR, 4); + // if (internal_gnd) { + // REGI2C_WRITE_MASK(I2C_ADC, SAR1_ENCAL_GND_ADDR, 1); + // } else { + // REGI2C_WRITE_MASK(I2C_ADC, SAR1_ENCAL_GND_ADDR, 0); + // } + // } else { + // REGI2C_WRITE_MASK(I2C_ADC, SAR2_DREF_ADDR, 4); + // if (internal_gnd) { + // REGI2C_WRITE_MASK(I2C_ADC, SAR2_ENCAL_GND_ADDR, 1); + // } else { + // REGI2C_WRITE_MASK(I2C_ADC, SAR2_ENCAL_GND_ADDR, 0); + // } + // } } /** @@ -920,7 +1185,11 @@ static inline void adc_ll_calibration_prepare(adc_ll_num_t adc_n, adc_channel_t */ static inline void adc_ll_calibration_finish(adc_ll_num_t adc_n) { - abort(); // TODO ESP32-C3 IDF-2526 + // if (adc_n == ADC_NUM_1) { + // REGI2C_WRITE_MASK(I2C_ADC, SAR1_ENCAL_GND_ADDR, 0); + // } else { + // REGI2C_WRITE_MASK(I2C_ADC, SAR2_ENCAL_GND_ADDR, 0); + // } } /** @@ -932,8 +1201,24 @@ static inline void adc_ll_calibration_finish(adc_ll_num_t adc_n) */ static inline void adc_ll_set_calibration_param(adc_ll_num_t adc_n, uint32_t param) { - abort(); // TODO ESP32-C3 IDF-2526 + // uint8_t msb = param >> 8; + // uint8_t lsb = param & 0xFF; + // /* Enable i2s_write_reg function. */ + // void phy_get_romfunc_addr(void); + // phy_get_romfunc_addr(); + // //SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M); + // CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18)); + // SET_PERI_REG_MASK(ANA_CONFIG2_REG, BIT(16)); + + // if (adc_n == ADC_NUM_1) { + // REGI2C_WRITE_MASK(I2C_ADC, SAR1_INITIAL_CODE_HIGH_ADDR, msb); + // REGI2C_WRITE_MASK(I2C_ADC, SAR1_INITIAL_CODE_LOW_ADDR, lsb); + // } else { + // REGI2C_WRITE_MASK(I2C_ADC, SAR2_INITIAL_CODE_HIGH_ADDR, msb); + // REGI2C_WRITE_MASK(I2C_ADC, SAR2_INITIAL_CODE_LOW_ADDR, lsb); + // } } +/* Temp code end. */ /*--------------------------------------------------------------- Single Read @@ -998,7 +1283,8 @@ static inline void adc_ll_adc1_onetime_sample_dis(void) static inline uint32_t adc_ll_adc1_read(void) { - return APB_SARADC.apb_saradc1_data_status.adc1_data; + //On ESP32C3, valid data width is 12-bit + return (APB_SARADC.apb_saradc1_data_status.adc1_data & 0xfff); } //--------------------------------adc2------------------------------// @@ -1014,8 +1300,10 @@ static inline void adc_ll_adc2_onetime_sample_dis(void) static inline uint32_t adc_ll_adc2_read(void) { - return APB_SARADC.apb_saradc2_data_status.adc2_data; + //On ESP32C3, valid data width is 12-bit + return (APB_SARADC.apb_saradc2_data_status.adc2_data & 0xfff); } + #ifdef __cplusplus } #endif diff --git a/components/hal/esp32c3/include/hal/clk_gate_ll.h b/components/hal/esp32c3/include/hal/clk_gate_ll.h index f7382650d5..7af8ed61ba 100644 --- a/components/hal/esp32c3/include/hal/clk_gate_ll.h +++ b/components/hal/esp32c3/include/hal/clk_gate_ll.h @@ -172,6 +172,7 @@ static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph) case PERIPH_SHA_MODULE: case PERIPH_GDMA_MODULE: return SYSTEM_PERIP_CLK_EN1_REG; + case PERIPH_SARADC_MODULE: default: return SYSTEM_PERIP_CLK_EN0_REG; } @@ -195,6 +196,7 @@ static uint32_t periph_ll_get_rst_en_reg(periph_module_t periph) case PERIPH_SHA_MODULE: case PERIPH_GDMA_MODULE: return SYSTEM_PERIP_RST_EN1_REG; + case PERIPH_SARADC_MODULE: default: return SYSTEM_PERIP_RST_EN0_REG; } diff --git a/components/hal/include/hal/adc_hal.h b/components/hal/include/hal/adc_hal.h index ea952b6472..3ac94b26b9 100644 --- a/components/hal/include/hal/adc_hal.h +++ b/components/hal/include/hal/adc_hal.h @@ -213,6 +213,7 @@ void adc_hal_digi_controller_config(const adc_digi_config_t *cfg); #include "hal/dma_types.h" #include "hal/adc_ll.h" #include "hal/dma_types.h" +#include "esp_err.h" typedef struct adc_dma_hal_context_t { gdma_dev_t *dev; //address of the general DMA @@ -259,9 +260,7 @@ void adc_hal_onetime_channel(adc_ll_num_t unit, adc_channel_t channel); void adc_hal_set_onetime_atten(adc_atten_t atten); -uint32_t adc_hal_adc1_read(void); - -uint32_t adc_hal_adc2_read(void); +esp_err_t adc_hal_single_read(adc_ll_num_t unit, int *out_raw); void adc_hal_intr_enable(adc_event_t event); diff --git a/components/hal/include/hal/adc_types.h b/components/hal/include/hal/adc_types.h index dea8ab0ec1..eddf6a96c5 100644 --- a/components/hal/include/hal/adc_types.h +++ b/components/hal/include/hal/adc_types.h @@ -88,8 +88,10 @@ typedef enum { 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. */ -#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 ADC_WIDTH_BIT_13 = 4, /*!< ADC capture width is 13Bit. */ +#elif CONFIG_IDF_TARGET_ESP32C3 + ADC_WIDTH_BIT_12 = 3, /*!< ADC capture width is 12Bit. */ #endif ADC_WIDTH_MAX, } adc_bits_width_t; @@ -139,7 +141,7 @@ typedef struct { uint8_t reserved: 2; /*!< reserved0 */ #endif }; - uint8_t val; /*! ADC_CHANNEL_MAX), The data is invalid. */ - uint32_t unit: 1; /*! ADC_CHANNEL_MAX), The data is invalid. */ + uint32_t unit: 1; /*!) +``` +[0_1_54e](4e 25 00 00) +[0_1_548](48 25 00 00) +[0_1_556](56 25 00 00) +``` + +## Troubleshooting + +* program upload failure + + * Hardware connection is not correct: run `idf.py -p PORT monitor`, and reboot your board to see if there are any output logs. + * The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again. + +For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. diff --git a/examples/peripherals/adc_dma_demo/main/CMakeLists.txt b/examples/peripherals/adc_dma_demo/main/CMakeLists.txt new file mode 100644 index 0000000000..72b0d08bf0 --- /dev/null +++ b/examples/peripherals/adc_dma_demo/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "adc_dma_example_main.c" + INCLUDE_DIRS ".") diff --git a/examples/peripherals/adc_dma_demo/main/adc_dma_example_main.c b/examples/peripherals/adc_dma_demo/main/adc_dma_example_main.c new file mode 100644 index 0000000000..6bbf9655ef --- /dev/null +++ b/examples/peripherals/adc_dma_demo/main/adc_dma_example_main.c @@ -0,0 +1,117 @@ +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "driver/adc.h" + +#define TIMES 256 +#define DMA_CHANNEL 0 + +static void continuous_adc_init(uint16_t adc1_chan_mask, uint16_t adc2_chan_mask, adc_channel_t *channel, uint8_t channel_num) +{ + esp_err_t ret = ESP_OK; + assert(ret == ESP_OK); + + adc_digi_init_config_t adc_dma_config = { + .max_store_buf_size = 1024, + .conv_num_each_intr = 256, + .dma_chan = SOC_GDMA_ADC_DMA_CHANNEL, + .adc1_chan_mask = adc1_chan_mask, + .adc2_chan_mask = adc2_chan_mask, + }; + ret = adc_digi_initialize(&adc_dma_config); + assert(ret == ESP_OK); + + adc_digi_pattern_table_t adc_pattern[10]; + adc_digi_config_t dig_cfg = { + .conv_limit_en = 0, + .conv_limit_num = 250, + .interval = 40, + .dig_clk.use_apll = 0, + .dig_clk.div_num = 15, + .dig_clk.div_a = 0, + .dig_clk.div_b = 1, + }; + + dig_cfg.adc_pattern_len = channel_num; + for (int i = 0; i < channel_num; i++) { + uint8_t unit = ((channel[i] >> 3) & 0x1); + uint8_t ch = channel[i] & 0x7; + adc_pattern[i].atten = ADC_ATTEN_DB_0; + adc_pattern[i].channel = ch; + adc_pattern[i].unit = unit; + } + dig_cfg.adc_pattern = adc_pattern; + ret = adc_digi_controller_config(&dig_cfg); + assert(ret == ESP_OK); +} + +static void continuous_read_demo(void *arg) +{ + esp_err_t ret; + uint32_t ret_num = 0; + uint8_t result[TIMES] = {0}; + memset(result, 0xcc, TIMES); + + uint16_t adc1_chan_mask = BIT(ADC1_CHANNEL_0) | BIT(ADC1_CHANNEL_1); + uint16_t adc2_chan_mask = BIT(ADC2_CHANNEL_0); + adc_channel_t channel[3] = {ADC1_CHANNEL_0, ADC1_CHANNEL_1, (ADC2_CHANNEL_0 | 1 << 3)}; + + continuous_adc_init(adc1_chan_mask, adc2_chan_mask, channel, sizeof(channel) / sizeof(adc_channel_t)); + adc_digi_start(); + + int n = 20; + while(n--) { + ret = adc_digi_read_bytes(result, TIMES, &ret_num, ADC_MAX_DELAY); + for (int i = 0; i < ret_num; i+=4) { + uint32_t temp = (result[i+3] << 24) | (result[i+2] << 16) | (result[i+1] << 8) | (result[i+0]); + adc_digi_output_data_t *p = (void*)&temp; + printf("[%d_%d_%x](%02x %02x %02x %02x) \n", p->type2.unit, p->type2.channel, p->type2.data, + result[i], + result[i + 1], + result[i + 2], + result[i + 3]); + } + // If you see task WDT in this task, it means the conversion is too fast for the task to handle + } + + adc_digi_stop(); + ret = adc_digi_deinitialize(); + assert(ret == ESP_OK); +} + +static void single_read_demo(void *arg) +{ + esp_err_t ret; + int adc1_reading[3] = {0xcc}; + int adc2_reading[1] = {0xcc}; + + adc1_config_width(ADC_WIDTH_BIT_12); + adc1_config_channel_atten(ADC1_CHANNEL_2, ADC_ATTEN_DB_0); + adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_6); + adc1_config_channel_atten(ADC1_CHANNEL_4, ADC_ATTEN_DB_0); + adc2_config_channel_atten(ADC2_CHANNEL_0, ADC_ATTEN_DB_0); + + int n = 20; + while (n--) { + + adc1_reading[0] = adc1_get_raw(ADC1_CHANNEL_2); + adc1_reading[1] = adc1_get_raw(ADC1_CHANNEL_3); + adc1_reading[2] = adc1_get_raw(ADC1_CHANNEL_4); + + for (int i = 0; i < 3; i++) { + printf("[%x]\n", adc1_reading[i]); + } + + ret = adc2_get_raw(ADC2_CHANNEL_0, ADC_WIDTH_BIT_12, &adc2_reading[0]); + assert(ret == ESP_OK); + printf("[%x]\n", adc2_reading[0]); + } +} + +void app_main() +{ + single_read_demo(NULL); + continuous_read_demo(NULL); +} From d35173c14730287275b03ec4d36aa2fe5959c6b0 Mon Sep 17 00:00:00 2001 From: Armando Date: Thu, 14 Jan 2021 14:46:04 +0800 Subject: [PATCH 02/22] small fix for cherrypick --- components/esp_wifi/src/wifi_init.c | 2 ++ components/hal/esp32c3/include/hal/gdma_ll.h | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 85d74a777c..7aa8cae0f3 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -280,9 +280,11 @@ void set_xpd_sar(bool en) } s_wifi_adc_xpd_flag = en; +#if !CONFIG_IDF_TARGET_ESP32C3 if (en) { adc_power_acquire(); } else { adc_power_release(); } +#endif } diff --git a/components/hal/esp32c3/include/hal/gdma_ll.h b/components/hal/esp32c3/include/hal/gdma_ll.h index 22410d3bdd..c3ad226bce 100644 --- a/components/hal/esp32c3/include/hal/gdma_ll.h +++ b/components/hal/esp32c3/include/hal/gdma_ll.h @@ -39,6 +39,13 @@ extern "C" { #define GDMA_LL_EVENT_RX_SUC_EOF (1<<1) #define GDMA_LL_EVENT_RX_DONE (1<<0) +#define GDMA_LL_TRIG_SRC_SPI2 (0) +#define GDMA_LL_TRIG_SRC_UART (2) +#define GDMA_LL_TRIG_SRC_I2S0 (3) +#define GDMA_LL_TRIG_SRC_AES (6) +#define GDMA_LL_TRIG_SRC_SHA (7) +#define GDMA_LL_TRIG_SRC_ADC_DAC (8) + ///////////////////////////////////// Common ///////////////////////////////////////// /** * @brief Enable DMA channel M2M mode (TX channel n forward data to RX channel n), disabled by default From d7d1dee208ded06c29f5dd00d61e6bdba3c379d8 Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Wed, 23 Dec 2020 12:29:57 +0800 Subject: [PATCH 03/22] system: reset dma when soft reset --- components/driver/CMakeLists.txt | 5 +- components/driver/adc_common.c | 94 +- components/driver/esp32c3/adc.c | 86 +- components/driver/esp32c3/adc2_init_cal.c | 39 + components/driver/esp32c3/rtc_tempsensor.c | 157 ++ components/driver/esp32s2/adc2_init_cal.c | 2 +- components/driver/esp_private/adc_cali.h | 41 + components/driver/include/driver/adc_common.h | 8 + components/driver/rtc_module.c | 1 - components/driver/test/test_adc_dma.c | 284 +++ components/efuse/CMakeLists.txt | 3 + components/efuse/esp32c3/esp_efuse_table.c | 100 +- components/efuse/esp32c3/esp_efuse_table.csv | 15 +- .../efuse/esp32c3/include/esp_efuse_table.h | 14 +- .../include/esp32c3/esp_efuse_rtc_calib.h | 53 + .../efuse/src/esp32c3/esp_efuse_rtc_calib.c | 84 + components/esp32c3/ld/esp32c3.peripherals.ld | 1 - components/esp32c3/system_api_esp32c3.c | 9 +- components/esp32s3/system_api_esp32s3.c | 6 +- components/esp_adc_cal/CMakeLists.txt | 4 + components/esp_adc_cal/component.mk | 2 +- components/esp_adc_cal/esp_adc_cal_esp32c3.c | 164 ++ components/esp_adc_cal/include/esp_adc_cal.h | 3 +- .../esp32c3/private_include/regi2c_lp_bias.h | 28 +- .../esp_hw_support/port/esp32c3/rtc_clk.c | 1 - .../port/esp32c3/rtc_clk_init.c | 1 - .../esp_hw_support/port/esp32c3/rtc_init.c | 120 +- .../port/esp32s2/private_include/regi2c_ulp.h | 13 +- .../esp_hw_support/port/esp32s2/rtc_init.c | 135 +- components/esp_hw_support/test/test_rtc_clk.c | 3 + components/esp_system/port/soc/esp32c3/clk.c | 5 + components/hal/esp32c3/adc_hal.c | 104 - components/hal/esp32c3/include/hal/adc_hal.h | 15 - components/hal/esp32c3/include/hal/adc_ll.h | 191 +- components/hal/esp32s2/adc_hal.c | 14 +- components/soc/esp32/include/soc/soc_caps.h | 2 + components/soc/esp32c3/include/soc/sens_reg.h | 1733 ----------------- .../soc/esp32c3/include/soc/sens_struct.h | 504 ----- components/soc/esp32c3/include/soc/soc_caps.h | 2 +- components/soc/esp32s2/include/soc/soc_caps.h | 3 +- components/soc/esp32s3/include/soc/adc_caps.h | 4 +- components/soc/include/soc/adc_periph.h | 4 + components/soc/include/soc/rtc_io_periph.h | 5 +- .../adc_dma_demo/main/adc_dma_example_main.c | 35 +- 44 files changed, 1325 insertions(+), 2772 deletions(-) create mode 100644 components/driver/esp32c3/adc2_init_cal.c create mode 100644 components/driver/esp32c3/rtc_tempsensor.c create mode 100644 components/driver/esp_private/adc_cali.h create mode 100644 components/driver/test/test_adc_dma.c create mode 100644 components/efuse/include/esp32c3/esp_efuse_rtc_calib.h create mode 100644 components/efuse/src/esp32c3/esp_efuse_rtc_calib.c create mode 100644 components/esp_adc_cal/esp_adc_cal_esp32c3.c delete mode 100644 components/soc/esp32c3/include/soc/sens_reg.h delete mode 100644 components/soc/esp32c3/include/soc/sens_struct.h diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index b833b50a6e..777d0afae0 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -22,7 +22,7 @@ set(srcs "twai.c" "uart.c") -set(includes "include" "${target}/include") +set(includes "include" "${target}/include" "esp_private") if(${target} STREQUAL "esp32") # SDMMC and MCPWM are in ESP32 only. @@ -66,7 +66,8 @@ endif() if(IDF_TARGET STREQUAL "esp32c3") list(APPEND srcs "gdma.c" "spi_slave_hd.c" - "esp32c3/adc.c") + "esp32c3/adc.c" + "esp32c3/adc2_init_cal.c") endif() idf_component_register(SRCS "${srcs}" diff --git a/components/driver/adc_common.c b/components/driver/adc_common.c index 0f5809961d..dbbadf9052 100644 --- a/components/driver/adc_common.c +++ b/components/driver/adc_common.c @@ -31,7 +31,6 @@ #include "hal/adc_types.h" #include "hal/adc_hal.h" -#if !CONFIG_IDF_TARGET_ESP32C3 #include "hal/dac_hal.h" #include "hal/adc_hal_conf.h" @@ -75,14 +74,6 @@ In ADC2, there're two locks used for different cases: adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock. */ -// This gets incremented when adc_power_acquire() is called, and decremented when -// adc_power_release() is called. ADC is powered down when the value reaches zero. -// Should be modified within critical section (ADC_ENTER/EXIT_CRITICAL). -static int s_adc_power_on_cnt; - -static void adc_power_on_internal(void); -static void adc_power_off_internal(void); - #ifdef CONFIG_IDF_TARGET_ESP32 //prevent ADC2 being used by wifi and other tasks at the same time. static _lock_t adc2_wifi_lock; @@ -121,7 +112,7 @@ static esp_pm_lock_handle_t s_adc2_arbiter_lock; ADC Common ---------------------------------------------------------------*/ -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 static uint32_t get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t chan) { adc_atten_t atten = adc_hal_get_atten(adc_n, chan); @@ -131,60 +122,36 @@ static uint32_t get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t chan) } #endif -void adc_power_acquire(void) -{ - bool powered_on = false; - ADC_ENTER_CRITICAL(); - s_adc_power_on_cnt++; - if (s_adc_power_on_cnt == 1) { - adc_power_on_internal(); - powered_on = true; - } - ADC_EXIT_CRITICAL(); - if (powered_on) { - ESP_LOGV(ADC_TAG, "%s: ADC powered on", __func__); - } -} - -void adc_power_release(void) -{ - bool powered_off = false; - ADC_ENTER_CRITICAL(); - s_adc_power_on_cnt--; - /* Sanity check */ - if (s_adc_power_on_cnt < 0) { - ADC_EXIT_CRITICAL(); - ESP_LOGE(ADC_TAG, "%s called, but s_adc_power_on_cnt == 0", __func__); - abort(); - } else if (s_adc_power_on_cnt == 0) { - adc_power_off_internal(); - powered_off = true; - } - ADC_EXIT_CRITICAL(); - if (powered_off) { - ESP_LOGV(ADC_TAG, "%s: ADC powered off", __func__); - } -} - -static void adc_power_on_internal(void) +void adc_power_always_on(void) { ADC_ENTER_CRITICAL(); - /* Set the power always on to increase precision. */ adc_hal_set_power_manage(ADC_POWER_SW_ON); ADC_EXIT_CRITICAL(); } -void adc_power_on(void) __attribute__((alias("adc_power_on_internal"))); +void adc_power_on(void) +{ + ADC_ENTER_CRITICAL(); + /* The power FSM controlled mode saves more power, while the ADC noise may get increased. */ +#ifndef CONFIG_ADC_FORCE_XPD_FSM + /* Set the power always on to increase precision. */ + adc_hal_set_power_manage(ADC_POWER_SW_ON); +#else + /* Use the FSM to turn off the power while not used to save power. */ + if (adc_hal_get_power_manage() != ADC_POWER_BY_FSM) { + adc_hal_set_power_manage(ADC_POWER_SW_ON); + } +#endif + ADC_EXIT_CRITICAL(); +} -static void adc_power_off_internal(void) +void adc_power_off(void) { ADC_ENTER_CRITICAL(); adc_hal_set_power_manage(ADC_POWER_SW_OFF); ADC_EXIT_CRITICAL(); } -void adc_power_off(void) __attribute__((alias("adc_power_off_internal"))); - esp_err_t adc_set_clk_div(uint8_t clk_div) { ADC_ENTER_CRITICAL(); @@ -370,9 +337,9 @@ int adc1_get_raw(adc1_channel_t channel) int adc_value; ADC_CHANNEL_CHECK(ADC_NUM_1, channel); adc1_rtc_mode_acquire(); - adc_power_acquire(); + adc_power_on(); -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // Get calibration value before going into critical section uint32_t cal_val = get_calibration_offset(ADC_NUM_1, channel); #endif @@ -382,7 +349,7 @@ int adc1_get_raw(adc1_channel_t channel) adc_hal_hall_disable(); //Disable other peripherals. adc_hal_amp_disable(); //Currently the LNA is not open, close it by default. #endif -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 adc_hal_set_calibration_param(ADC_NUM_1, cal_val); #endif adc_hal_set_controller(ADC_NUM_1, ADC_CTRL_RTC); //Set controller @@ -392,7 +359,6 @@ int adc1_get_raw(adc1_channel_t channel) #endif ADC_EXIT_CRITICAL(); - adc_power_release(); adc1_lock_release(); return adc_value; } @@ -405,7 +371,7 @@ int adc1_get_voltage(adc1_channel_t channel) //Deprecated. Use adc1_get_raw() #if SOC_ULP_SUPPORTED void adc1_ulp_enable(void) { - adc_power_acquire(); + adc_power_on(); ADC_ENTER_CRITICAL(); adc_hal_set_controller(ADC_NUM_1, ADC_CTRL_ULP); @@ -526,9 +492,9 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int * ADC_CHECK(width_bit == ADC_WIDTH_BIT_13, "WIDTH ERR: ESP32S2 support 13 bit width", ESP_ERR_INVALID_ARG); #endif - adc_power_acquire(); //in critical section with whole rtc module + adc_power_on(); //in critical section with whole rtc module -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // Get calibration value before going into critical section uint32_t cal_val = get_calibration_offset(ADC_NUM_2, channel); #endif @@ -537,14 +503,13 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int * if ( ADC2_WIFI_LOCK_TRY_ACQUIRE() == -1 ) { //try the lock, return if failed (wifi using). ADC2_EXIT_CRITICAL(); - adc_power_release(); return ESP_ERR_TIMEOUT; } #ifdef CONFIG_ADC_DISABLE_DAC adc2_dac_disable(channel); //disable other peripherals #endif adc2_config_width(width_bit); // in critical section with whole rtc module. because the PWDET use the same registers, place it here. -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 adc_hal_set_calibration_param(ADC_NUM_2, cal_val); #endif adc_hal_set_controller(ADC_NUM_2, ADC_CTRL_RTC);// set controller @@ -579,12 +544,8 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int * if (adc_value < 0) { ESP_LOGD( ADC_TAG, "ADC2 ARB: Return data is invalid." ); - adc_power_release(); return ESP_ERR_INVALID_STATE; } - - //in critical section with whole rtc module - adc_power_release(); *raw_out = adc_value; return ESP_OK; } @@ -597,9 +558,7 @@ esp_err_t adc2_vref_to_gpio(gpio_num_t gpio) esp_err_t adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio) { #ifdef CONFIG_IDF_TARGET_ESP32 - adc_power_acquire(); if (adc_unit & ADC_UNIT_1) { - adc_power_release(); return ESP_ERR_INVALID_ARG; } #endif @@ -612,7 +571,6 @@ esp_err_t adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio) } } if (ch == ADC2_CHANNEL_MAX) { - adc_power_release(); return ESP_ERR_INVALID_ARG; } @@ -629,5 +587,3 @@ esp_err_t adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio) adc_gpio_init(ADC_UNIT_2, ch); return ESP_OK; } - -#endif // !CONFIG_IDF_TARGET_ESP32C3 diff --git a/components/driver/esp32c3/adc.c b/components/driver/esp32c3/adc.c index f1de2eb0a4..e2e036f89e 100644 --- a/components/driver/esp32c3/adc.c +++ b/components/driver/esp32c3/adc.c @@ -31,6 +31,7 @@ #include "hal/adc_types.h" #include "hal/adc_hal.h" #include "hal/dma_types.h" +#include "esp32c3/esp_efuse_rtc_calib.h" #define ADC_CHECK_RET(fun_ret) ({ \ if (fun_ret != ESP_OK) { \ @@ -89,13 +90,17 @@ typedef struct adc_digi_context_t { RingbufHandle_t ringbuf_hdl; //RX ringbuffer handler bool ringbuf_overflow_flag; //1: ringbuffer overflow bool driver_start_flag; //1: driver is started; 0: driver is stoped + bool use_adc1; //1: ADC unit1 will be used; 0: ADC unit1 won't be used. bool use_adc2; //1: ADC unit2 will be used; 0: ADC unit2 won't be used. This determines whether to acquire sar_adc2_mutex lock or not. + adc_atten_t adc1_atten; //Attenuation for ADC1. On this chip each ADC can only support one attenuation. + adc_atten_t adc2_atten; //Attenuation for ADC2. On this chip each ADC can only support one attenuation. adc_digi_config_t digi_controller_config; //Digital Controller Configuration } adc_digi_context_t; static const char* ADC_DMA_TAG = "ADC_DMA:"; static adc_digi_context_t *s_adc_digi_ctx = NULL; +static uint32_t adc_get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t chan, adc_atten_t atten); /*--------------------------------------------------------------- ADC Continuous Read Mode (via DMA) @@ -265,6 +270,16 @@ esp_err_t adc_digi_start(void) adc_arbiter_t config = ADC_ARBITER_CONFIG_DEFAULT(); adc_hal_init(); + + if (s_adc_digi_ctx->use_adc1) { + uint32_t cal_val = adc_get_calibration_offset(ADC_NUM_1, ADC_CHANNEL_MAX, s_adc_digi_ctx->adc1_atten); + adc_hal_set_calibration_param(ADC_NUM_1, cal_val); + } + if (s_adc_digi_ctx->use_adc2) { + uint32_t cal_val = adc_get_calibration_offset(ADC_NUM_2, ADC_CHANNEL_MAX, s_adc_digi_ctx->adc2_atten); + adc_hal_set_calibration_param(ADC_NUM_2, cal_val); + } + adc_hal_arbiter_config(&config); adc_hal_digi_init(&s_adc_digi_ctx->hal_dma, &s_adc_digi_ctx->hal_dma_config); adc_hal_digi_controller_config(&s_adc_digi_ctx->digi_controller_config); @@ -365,6 +380,7 @@ esp_err_t adc_digi_deinitialize(void) s_adc_digi_ctx->ringbuf_hdl = NULL; } + free(s_adc_digi_ctx->rx_dma_buf); free(s_adc_digi_ctx->hal_dma_config.rx_desc); free(s_adc_digi_ctx->digi_controller_config.adc_pattern); free(s_adc_digi_ctx); @@ -420,11 +436,16 @@ int adc1_get_raw(adc1_channel_t channel) ADC_DIGI_LOCK_ACQUIRE(); periph_module_enable(PERIPH_SARADC_MODULE); + + adc_atten_t atten = s_atten1_single[channel]; + uint32_t cal_val = adc_get_calibration_offset(ADC_NUM_1, channel, atten); + adc_hal_set_calibration_param(ADC_NUM_1, cal_val); + adc_hal_digi_controller_config(&dig_cfg); adc_hal_intr_clear(ADC_EVENT_ADC1_DONE); adc_hal_onetime_channel(ADC_NUM_1, channel); - adc_hal_set_onetime_atten(s_atten1_single[channel]); + adc_hal_set_onetime_atten(atten); //Trigger single read. adc_hal_adc1_onetime_sample_enable(true); @@ -475,13 +496,17 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int * SAC_ADC2_LOCK_ACQUIRE(); ADC_DIGI_LOCK_ACQUIRE(); - periph_module_enable(PERIPH_SARADC_MODULE); + + adc_atten_t atten = s_atten2_single[channel]; + uint32_t cal_val = adc_get_calibration_offset(ADC_NUM_2, channel, atten); + adc_hal_set_calibration_param(ADC_NUM_2, cal_val); + adc_hal_digi_controller_config(&dig_cfg); adc_hal_intr_clear(ADC_EVENT_ADC2_DONE); adc_hal_onetime_channel(ADC_NUM_2, channel); - adc_hal_set_onetime_atten(s_atten2_single[channel]); + adc_hal_set_onetime_atten(atten); //Trigger single read. adc_hal_adc2_onetime_sample_enable(true); @@ -523,10 +548,26 @@ esp_err_t adc_digi_controller_config(const adc_digi_config_t *config) memcpy(s_adc_digi_ctx->digi_controller_config.adc_pattern, config->adc_pattern, config->adc_pattern_len * sizeof(adc_digi_pattern_table_t)); //See whether ADC2 will be used or not. If yes, the ``sar_adc2_mutex`` should be acquired in the continuous read driver + s_adc_digi_ctx->adc1_atten = ADC_ATTEN_MAX; + s_adc_digi_ctx->adc2_atten = ADC_ATTEN_MAX; + s_adc_digi_ctx->use_adc1 = 0; s_adc_digi_ctx->use_adc2 = 0; for (int i = 0; i < config->adc_pattern_len; i++) { - if (config->adc_pattern->unit == ADC_NUM_2) { + const adc_digi_pattern_table_t* pat = &config->adc_pattern[i]; + if (pat->unit == ADC_NUM_1) { + s_adc_digi_ctx->use_adc1 = 1; + if (s_adc_digi_ctx->adc1_atten == ADC_ATTEN_MAX) { + s_adc_digi_ctx->adc1_atten = pat->atten; + } else if (s_adc_digi_ctx->adc1_atten != pat->atten) { + return ESP_ERR_INVALID_ARG; + } + } else if (pat->unit == ADC_NUM_2) { s_adc_digi_ctx->use_adc2 = 1; + if (s_adc_digi_ctx->adc2_atten == ADC_ATTEN_MAX) { + s_adc_digi_ctx->adc2_atten = pat->atten; + } else if (s_adc_digi_ctx->adc2_atten != pat->atten) { + return ESP_ERR_INVALID_ARG; + } } } @@ -802,3 +843,40 @@ esp_err_t adc_digi_isr_deregister(void) /*--------------------------------------------------------------- RTC controller setting ---------------------------------------------------------------*/ + +static uint16_t s_adc_cali_param[ADC_ATTEN_MAX] = {}; + +//NOTE: according to calibration version, different types of lock may be taken during the process: +// 1. Semaphore when reading efuse +// 2. Lock (Spinlock, or Mutex) if we actually do ADC calibration in the future +//This function shoudn't be called inside critical section or ISR +static uint32_t adc_get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten) +{ + const bool no_cal = false; + if (s_adc_cali_param[atten]) { + return (uint32_t)s_adc_cali_param[atten]; + } + + if (no_cal) { + return 0; //indicating failure + } + + // check if we can fetch the values from eFuse. + int version = esp_efuse_rtc_calib_get_ver(); + assert(version == 1); + uint32_t init_code = esp_efuse_rtc_calib_get_init_code(version, atten); + + ESP_LOGD(ADC_TAG, "Calib(V%d) ADC%d atten=%d: %04X", version, adc_n, atten, init_code); + s_adc_cali_param[atten] = init_code; + return init_code; +} + +// Internal function to calibrate PWDET for WiFi +esp_err_t adc_cal_offset(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten) +{ + uint32_t cal_val = adc_get_calibration_offset(adc_n, channel, atten); + ADC_ENTER_CRITICAL(); + adc_hal_set_calibration_param(adc_n, cal_val); + ADC_EXIT_CRITICAL(); + return ESP_OK; +} diff --git a/components/driver/esp32c3/adc2_init_cal.c b/components/driver/esp32c3/adc2_init_cal.c new file mode 100644 index 0000000000..19e7d98c19 --- /dev/null +++ b/components/driver/esp32c3/adc2_init_cal.c @@ -0,0 +1,39 @@ +// Copyright 2016-2018 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. + +/* This file is used to get `adc2_init_code_calibration` executed before the APP when the ADC2 is used by Wi-Fi or other drivers. +The linker will link constructor (adc2_init_code_calibration) only when any sections inside the same file (adc2_cal_include) is used. +Don't put any other code into this file. */ + +#include "adc2_wifi_private.h" +#include "hal/adc_hal.h" +#include "adc_cali.h" + +/** + * @brief Set initial code to ADC2 after calibration. ADC2 RTC and ADC2 PWDET controller share the initial code. + * This API be called in before `app_main()`. + */ +static __attribute__((constructor)) void adc2_init_code_calibration(void) +{ + const adc_ll_num_t adc_n = ADC_NUM_2; + const adc_atten_t atten = ADC_ATTEN_DB_11; + const adc_channel_t channel = 0; + adc_cal_offset(adc_n, channel, atten); +} + +/** Don't call `adc2_cal_include` in user code. */ +void adc2_cal_include(void) +{ + /* When this empty function is called, the `adc2_init_code_calibration` constructor will be linked and executed before the app.*/ +} diff --git a/components/driver/esp32c3/rtc_tempsensor.c b/components/driver/esp32c3/rtc_tempsensor.c new file mode 100644 index 0000000000..79767a8a75 --- /dev/null +++ b/components/driver/esp32c3/rtc_tempsensor.c @@ -0,0 +1,157 @@ +// Copyright 2016-2018 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. + +#include +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/semphr.h" +#include "esp_log.h" +#include "soc/rtc_cntl_reg.h" +#include "driver/temp_sensor.h" +#include "esp32c3/rom/ets_sys.h" + +static const char *TAG = "tsens"; + +#define TSENS_CHECK(res, ret_val) ({ \ + if (!(res)) { \ + ESP_LOGE(TAG, "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__); \ + return (ret_val); \ + } \ +}) +#define TSENS_XPD_WAIT_DEFAULT 0xFF /* Set wait cycle time(8MHz) from power up to reset enable. */ +#define TSENS_ADC_FACTOR (0.4386) +#define TSENS_DAC_FACTOR (27.88) +#define TSENS_SYS_OFFSET (20.52) + +#include "regi2c_ctrl.h" + +#define ANA_CONFIG2_REG 0x6000E048 +#define ANA_CONFIG2_M (BIT(18)) + +#define I2C_ADC 0X69 +#define I2C_ADC_HOSTID 1 + +typedef struct { + int index; + int offset; + int set_val; + int range_min; + int range_max; + int error_max; +} tsens_dac_offset_t; + +static const tsens_dac_offset_t dac_offset[TSENS_DAC_MAX] = { + /* DAC Offset reg_val min max error */ + {TSENS_DAC_L0, -2, 5, 50, 125, 3}, + {TSENS_DAC_L1, -1, 7, 20, 100, 2}, + {TSENS_DAC_L2, 0, 15, -10, 80, 1}, + {TSENS_DAC_L3, 1, 11, -30, 50, 2}, + {TSENS_DAC_L4, 2, 10, -40, 20, 3}, +}; + +static SemaphoreHandle_t rtc_tsens_mux = NULL; + +esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens) +{ + //CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PD_M); + //SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M); + CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18)); + SET_PERI_REG_MASK(ANA_CONFIG2_REG, BIT(16)); + REGI2C_WRITE_MASK(I2C_ADC, I2C_SARADC_TSENS_DAC, dac_offset[tsens.dac_offset].set_val); + SENS.sar_tctrl.tsens_clk_div = tsens.clk_div; + SENS.sar_tctrl.tsens_power_up_force = 1; + SENS.sar_tctrl2.tsens_xpd_wait = TSENS_XPD_WAIT_DEFAULT; + SENS.sar_tctrl2.tsens_xpd_force = 1; + // SENS.sar_tctrl2.tsens_reset = 1;// Reset the temp sensor. + // SENS.sar_tctrl2.tsens_reset = 0;// Clear the reset status. + ESP_LOGI(TAG, "Config temperature range [%d°C ~ %d°C], error < %d°C", + dac_offset[tsens.dac_offset].range_min, + dac_offset[tsens.dac_offset].range_max, + dac_offset[tsens.dac_offset].error_max); + return ESP_OK; +} + +esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens) +{ + TSENS_CHECK(tsens != NULL, ESP_ERR_INVALID_ARG); + //CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PD_M); + //SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M); + CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18)); + SET_PERI_REG_MASK(ANA_CONFIG2_REG, BIT(16)); + tsens->dac_offset = REGI2C_READ_MASK(I2C_ADC, I2C_SARADC_TSENS_DAC); + for (int i = TSENS_DAC_L0; i < TSENS_DAC_MAX; i++) { + if (tsens->dac_offset == dac_offset[i].set_val) { + tsens->dac_offset = dac_offset[i].index; + break; + } + } + tsens->clk_div = SENS.sar_tctrl.tsens_clk_div; + return ESP_OK; +} + +esp_err_t temp_sensor_start(void) +{ + if (rtc_tsens_mux == NULL) { + rtc_tsens_mux = xSemaphoreCreateMutex(); + } + TSENS_CHECK(rtc_tsens_mux != NULL, ESP_ERR_NO_MEM); + // SENS.sar_tctrl.tsens_dump_out = 0; + // SENS.sar_tctrl2.tsens_clkgate_en = 1; + // SENS.sar_tctrl.tsens_power_up = 1; + return ESP_OK; +} + +esp_err_t temp_sensor_stop(void) +{ + SENS.sar_tctrl.tsens_power_up = 0; + // SENS.sar_tctrl2.tsens_clkgate_en = 0; + if (rtc_tsens_mux != NULL) { + vSemaphoreDelete(rtc_tsens_mux); + rtc_tsens_mux = NULL; + } + return ESP_OK; +} + +esp_err_t temp_sensor_read_raw(uint32_t *tsens_out) +{ + TSENS_CHECK(tsens_out != NULL, ESP_ERR_INVALID_ARG); + TSENS_CHECK(rtc_tsens_mux != NULL, ESP_ERR_INVALID_STATE); + xSemaphoreTake(rtc_tsens_mux, portMAX_DELAY); + SENS.sar_tctrl.tsens_dump_out = 1; + while (!SENS.sar_tctrl.tsens_ready); + *tsens_out = SENS.sar_tctrl.tsens_out; + SENS.sar_tctrl.tsens_dump_out = 0; + xSemaphoreGive(rtc_tsens_mux); + return ESP_OK; +} + +esp_err_t temp_sensor_read_celsius(float *celsius) +{ + TSENS_CHECK(celsius != NULL, ESP_ERR_INVALID_ARG); + temp_sensor_config_t tsens; + uint32_t tsens_out = 0; + esp_err_t ret = temp_sensor_get_config(&tsens); + if (ret == ESP_OK) { + ret = temp_sensor_read_raw(&tsens_out); + TSENS_CHECK(ret == ESP_OK, ret); + const tsens_dac_offset_t *dac = &dac_offset[tsens.dac_offset]; + *celsius = (TSENS_ADC_FACTOR * (float)tsens_out - TSENS_DAC_FACTOR * dac->offset - TSENS_SYS_OFFSET); + if (*celsius < dac->range_min || *celsius > dac->range_max) { + ESP_LOGW(TAG, "Exceeding the temperature range!"); + ret = ESP_ERR_INVALID_STATE; + } + } + return ret; +} diff --git a/components/driver/esp32s2/adc2_init_cal.c b/components/driver/esp32s2/adc2_init_cal.c index 1968cfd49e..19e7d98c19 100644 --- a/components/driver/esp32s2/adc2_init_cal.c +++ b/components/driver/esp32s2/adc2_init_cal.c @@ -18,6 +18,7 @@ Don't put any other code into this file. */ #include "adc2_wifi_private.h" #include "hal/adc_hal.h" +#include "adc_cali.h" /** * @brief Set initial code to ADC2 after calibration. ADC2 RTC and ADC2 PWDET controller share the initial code. @@ -28,7 +29,6 @@ static __attribute__((constructor)) void adc2_init_code_calibration(void) const adc_ll_num_t adc_n = ADC_NUM_2; const adc_atten_t atten = ADC_ATTEN_DB_11; const adc_channel_t channel = 0; - extern esp_err_t adc_cal_offset(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten); adc_cal_offset(adc_n, channel, atten); } diff --git a/components/driver/esp_private/adc_cali.h b/components/driver/esp_private/adc_cali.h new file mode 100644 index 0000000000..ab577a3121 --- /dev/null +++ b/components/driver/esp_private/adc_cali.h @@ -0,0 +1,41 @@ +// Copyright 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. + +// Internal header for calibration, don't use in app + +#include "sdkconfig.h" +#include "esp_err.h" +#include "hal/adc_hal.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !CONFIG_IDF_TARGET_ESP32 + +/** + * @brief Calibrate the offset of ADC. (Based on the pre-stored efuse or actual calibration) + * + * @param adc_n ADC unit to calibrate + * @param channel Target channel if really do calibration + * @param atten Attenuation to use + * @return Always ESP_OK + */ +extern esp_err_t adc_cal_offset(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten); + +#endif + +#ifdef __cplusplus +} +#endif diff --git a/components/driver/include/driver/adc_common.h b/components/driver/include/driver/adc_common.h index 5eafc8d508..4596505822 100644 --- a/components/driver/include/driver/adc_common.h +++ b/components/driver/include/driver/adc_common.h @@ -17,6 +17,7 @@ #include #include #include "esp_err.h" +#include "sdkconfig.h" #include "driver/gpio.h" #include "hal/adc_types.h" @@ -99,6 +100,13 @@ typedef enum { #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 + +/** + * The default (max) bit width of the ADC of current version. You can also get the maximum bitwidth + * by `SOC_ADC_MAX_BITWIDTH` defined in soc_caps.h. + */ +#define ADC_WIDTH_BIT_DEFAULT (ADC_WIDTH_MAX-1) + //this definitions are only for being back-compatible #define ADC_WIDTH_9Bit ADC_WIDTH_BIT_9 #define ADC_WIDTH_10Bit ADC_WIDTH_BIT_10 diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index f19d2b6899..56d5b40751 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -18,7 +18,6 @@ #include "esp_types.h" #include "esp_log.h" #include "soc/rtc_periph.h" -#include "soc/sens_periph.h" #include "soc/syscon_periph.h" #include "soc/rtc.h" #include "soc/periph_defs.h" diff --git a/components/driver/test/test_adc_dma.c b/components/driver/test/test_adc_dma.c new file mode 100644 index 0000000000..db32120d8e --- /dev/null +++ b/components/driver/test/test_adc_dma.c @@ -0,0 +1,284 @@ +// Copyright 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. + +#include +#include +#include "test_utils.h" + +#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32, ESP32S2, ESP32S3) +//API only supported for C3 now. + +#include "driver/adc.h" +#include "esp_adc_cal.h" +#include "esp_log.h" + +#define TEST_COUNT 4096 +#define MAX_ARRAY_SIZE 4096 +#define TEST_ATTEN ADC_ATTEN_MAX //Set to ADC_ATTEN_*db to test a single attenuation only + +static int s_adc_count[MAX_ARRAY_SIZE]={}; +static int s_adc_offset = -1; + +static int insert_point(uint32_t value) +{ + const bool fixed_size = true; + + if (s_adc_offset < 0) { + if (fixed_size) { + assert(MAX_ARRAY_SIZE >= 4096); + s_adc_offset = 0; //Fixed to 0 because the array can hold all the data in 12 bits + } else { + s_adc_offset = MAX((int)value - MAX_ARRAY_SIZE/2, 0); + } + } + + if (!fixed_size && (value < s_adc_offset || value >= s_adc_offset + MAX_ARRAY_SIZE)) { + assert(value >= s_adc_offset); + assert(value < s_adc_offset + MAX_ARRAY_SIZE); + } + + s_adc_count[value - s_adc_offset] ++; + return value - s_adc_offset; +} + +static void reset_array(void) +{ + memset(s_adc_count, 0, sizeof(s_adc_count)); + s_adc_offset = -1; +} + +static uint32_t get_average(void) +{ + uint32_t sum = 0; + int count = 0; + for (int i = 0; i < MAX_ARRAY_SIZE; i++) { + sum += s_adc_count[i] * (s_adc_offset+i); + count += s_adc_count[i]; + } + return sum/count; +} + +static void print_summary(bool figure) +{ + const int MAX_WIDTH=20; + int max_count = 0; + int start = -1; + int end = -1; + uint32_t sum = 0; + int count = 0; + for (int i = 0; i < MAX_ARRAY_SIZE; i++) { + if (s_adc_count[i] > max_count) { + max_count = s_adc_count[i]; + } + if (s_adc_count[i] > 0 && start < 0) { + start = i; + } + if (s_adc_count[i] > 0) { + end = i; + } + count += s_adc_count[i]; + sum += s_adc_count[i] * (s_adc_offset+i); + } + + if (figure) { + for (int i = start; i <= end; i++) { + printf("%4d ", i+s_adc_offset); + int count = s_adc_count[i] * MAX_WIDTH / max_count; + for (int j = 0; j < count; j++) { + putchar('|'); + } + printf(" %d\n", s_adc_count[i]); + } + } + float average = (float)sum/count; + + float variation_square = 0; + for (int i = start; i <= end; i ++) { + if (s_adc_count[i] == 0) { + continue; + } + float delta = i + s_adc_offset - average; + variation_square += (delta * delta) * s_adc_count[i]; + } + + printf("%d points.\n", count); + printf("average: %.1f\n", (float)sum/count); + printf("std: %.2f\n", sqrt(variation_square/count)); +} + +static void continuous_adc_init(uint16_t adc1_chan_mask, uint16_t adc2_chan_mask, adc_channel_t *channel, uint8_t channel_num, adc_atten_t atten) +{ + esp_err_t ret = ESP_OK; + assert(ret == ESP_OK); + + adc_digi_init_config_t adc_dma_config = { + .max_store_buf_size = TEST_COUNT*2, + .conv_num_each_intr = 128, + .dma_chan = SOC_GDMA_ADC_DMA_CHANNEL, + .adc1_chan_mask = adc1_chan_mask, + .adc2_chan_mask = adc2_chan_mask, + }; + ret = adc_digi_initialize(&adc_dma_config); + assert(ret == ESP_OK); + + adc_digi_pattern_table_t adc_pattern[10]; + adc_digi_config_t dig_cfg = { + .conv_limit_en = 0, + .conv_limit_num = 250, + .interval = 40, + .dig_clk.use_apll = 0, + .dig_clk.div_num = 15, + .dig_clk.div_a = 0, + .dig_clk.div_b = 1, + }; + + dig_cfg.adc_pattern_len = channel_num; + for (int i = 0; i < channel_num; i++) { + uint8_t unit = ((channel[i] >> 3) & 0x1); + uint8_t ch = channel[i] & 0x7; + adc_pattern[i].atten = atten; + adc_pattern[i].channel = ch; + adc_pattern[i].unit = unit; + } + dig_cfg.adc_pattern = adc_pattern; + ret = adc_digi_controller_config(&dig_cfg); + assert(ret == ESP_OK); +} + +TEST_CASE("test_adc_dma", "[adc][ignore][manual]") +{ + esp_err_t ret; + uint16_t adc1_chan_mask = BIT(2); + uint16_t adc2_chan_mask = 0; + adc_channel_t channel[1] = {ADC1_CHANNEL_2}; + adc_atten_t target_atten = TEST_ATTEN; + + const int output_data_size = sizeof(adc_digi_output_data_t); + + int buffer_size = TEST_COUNT*output_data_size; + uint8_t* read_buf = malloc(buffer_size); + assert(read_buf); + + adc_atten_t atten; + bool print_figure; + if (target_atten == ADC_ATTEN_MAX) { + atten = ADC_ATTEN_DB_0; + target_atten = ADC_ATTEN_DB_11; + print_figure = false; + } else { + atten = target_atten; + print_figure = true; + } + + while (1) { + ESP_LOGI("TEST_ADC", "Test with atten: %d", atten); + memset(read_buf, 0xce, buffer_size); + + esp_adc_cal_characteristics_t chan1_char = {}; + esp_adc_cal_value_t cal_ret = esp_adc_cal_characterize(ADC_UNIT_1, atten, ADC_WIDTH_12Bit, 0, &chan1_char); + assert(cal_ret == ESP_ADC_CAL_VAL_EFUSE_TP); + + continuous_adc_init(adc1_chan_mask, adc2_chan_mask, channel, sizeof(channel) / sizeof(adc_channel_t), atten); + adc_digi_start(); + + int remain_count = TEST_COUNT; + while (remain_count) { + int already_got = TEST_COUNT - remain_count; + uint32_t ret_num; + ret = adc_digi_read_bytes(read_buf + already_got*output_data_size, + remain_count*output_data_size, &ret_num, ADC_MAX_DELAY); + + ESP_ERROR_CHECK(ret); + assert((ret_num % output_data_size) == 0); + remain_count -= ret_num / output_data_size; + } + + adc_digi_output_data_t *p = (void*)read_buf; + reset_array(); + for (int i = 0; i < TEST_COUNT; i++) { + insert_point(p[i].type2.data); + } + + print_summary(print_figure); + + uint32_t raw = get_average(); + uint32_t voltage_mv = esp_adc_cal_raw_to_voltage(raw, &chan1_char); + printf("Voltage = %d mV\n", voltage_mv); + + adc_digi_stop(); + ret = adc_digi_deinitialize(); + assert(ret == ESP_OK); + + if (atten == target_atten) { + break; + } + + atten++; + } + + free(read_buf); +} + +TEST_CASE("test_adc_single", "[adc][ignore][manual]") +{ + adc_atten_t target_atten = TEST_ATTEN; + adc_atten_t atten; + bool print_figure; + if (target_atten == ADC_ATTEN_MAX) { + atten = ADC_ATTEN_DB_0; + target_atten = ADC_ATTEN_DB_11; + print_figure = false; + } else { + atten = target_atten; + print_figure = true; + } + + adc1_config_width(ADC_WIDTH_BIT_12); + + + while (1) { + ESP_LOGI("TEST_ADC", "Test with atten: %d", atten); + + adc1_config_channel_atten(ADC1_CHANNEL_2, atten); + + esp_adc_cal_characteristics_t chan1_char = {}; + esp_adc_cal_value_t cal_ret = esp_adc_cal_characterize(ADC_UNIT_1, atten, ADC_WIDTH_12Bit, 0, &chan1_char); + assert(cal_ret == ESP_ADC_CAL_VAL_EFUSE_TP); + + + const int test_count = TEST_COUNT; + adc1_channel_t channel = ADC1_CHANNEL_2; + while (1) { + + reset_array(); + + for (int i = 0; i < test_count; i++) { + uint32_t raw = adc1_get_raw(channel); + insert_point(raw); + } + print_summary(print_figure); + break; + } + uint32_t raw = get_average(); + uint32_t voltage_mv = esp_adc_cal_raw_to_voltage(raw, &chan1_char); + printf("Voltage = %d mV\n", voltage_mv); + + if (atten == target_atten) { + break; + } + atten++; + } +} + +#endif diff --git a/components/efuse/CMakeLists.txt b/components/efuse/CMakeLists.txt index 48005d8e2d..04d75ed76c 100644 --- a/components/efuse/CMakeLists.txt +++ b/components/efuse/CMakeLists.txt @@ -11,6 +11,9 @@ if(EXISTS "${COMPONENT_DIR}/${target}") if("esp32s2" STREQUAL "${target}") list(APPEND srcs "src/${target}/esp_efuse_rtc_table.c") endif() + if("esp32c3" STREQUAL "${target}") + list(APPEND srcs "src/${target}/esp_efuse_rtc_calib.c") + endif() endif() list(APPEND srcs "src/esp_efuse_api.c" diff --git a/components/efuse/esp32c3/esp_efuse_table.c b/components/efuse/esp32c3/esp_efuse_table.c index 5bdacd2ac2..06fef0781f 100644 --- a/components/efuse/esp32c3/esp_efuse_table.c +++ b/components/efuse/esp32c3/esp_efuse_table.c @@ -17,7 +17,7 @@ #include #include "esp_efuse_table.h" -// md5_digest_table 2c7ba2aa68a2748d3de9a5d1fed59b9f +// md5_digest_table 96cd6235ddc0947b4a296add3f942acb // This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY. // If you want to change some fields, you need to change esp_efuse_table.csv file // then run `efuse_common_table` or `efuse_custom_table` command it will generate this file. @@ -392,8 +392,48 @@ static const esp_efuse_desc_t SPI_PAD_CONFIG_D7[] = { {EFUSE_BLK1, 108, 6}, // SPI_PAD_configure D7, }; -static const esp_efuse_desc_t SYS_DATA_PART1[] = { - {EFUSE_BLK2, 0, 256}, // System configuration, +static const esp_efuse_desc_t BLOCK2_VERSION[] = { + {EFUSE_BLK2, 128, 3}, // Version of Block2, +}; + +static const esp_efuse_desc_t TEMP_CALIB[] = { + {EFUSE_BLK2, 131, 9}, // Temperature calibration data, +}; + +static const esp_efuse_desc_t OCODE[] = { + {EFUSE_BLK2, 140, 8}, // ADC OCode, +}; + +static const esp_efuse_desc_t ADC1_INIT_CODE_ATTEN0[] = { + {EFUSE_BLK2, 148, 10}, // ADC1 init code at atten0, +}; + +static const esp_efuse_desc_t ADC1_INIT_CODE_ATTEN1[] = { + {EFUSE_BLK2, 158, 10}, // ADC1 init code at atten1, +}; + +static const esp_efuse_desc_t ADC1_INIT_CODE_ATTEN2[] = { + {EFUSE_BLK2, 168, 10}, // ADC1 init code at atten2, +}; + +static const esp_efuse_desc_t ADC1_INIT_CODE_ATTEN3[] = { + {EFUSE_BLK2, 178, 10}, // ADC1 init code at atten3, +}; + +static const esp_efuse_desc_t ADC1_CAL_VOL_ATTEN0[] = { + {EFUSE_BLK2, 188, 10}, // ADC1 calibration voltage at atten0, +}; + +static const esp_efuse_desc_t ADC1_CAL_VOL_ATTEN1[] = { + {EFUSE_BLK2, 198, 10}, // ADC1 calibration voltage at atten1, +}; + +static const esp_efuse_desc_t ADC1_CAL_VOL_ATTEN2[] = { + {EFUSE_BLK2, 208, 10}, // ADC1 calibration voltage at atten2, +}; + +static const esp_efuse_desc_t ADC1_CAL_VOL_ATTEN3[] = { + {EFUSE_BLK2, 218, 10}, // ADC1 calibration voltage at atten3, }; static const esp_efuse_desc_t USER_DATA[] = { @@ -892,8 +932,58 @@ const esp_efuse_desc_t* ESP_EFUSE_SPI_PAD_CONFIG_D7[] = { NULL }; -const esp_efuse_desc_t* ESP_EFUSE_SYS_DATA_PART1[] = { - &SYS_DATA_PART1[0], // System configuration +const esp_efuse_desc_t* ESP_EFUSE_BLOCK2_VERSION[] = { + &BLOCK2_VERSION[0], // Version of Block2 + NULL +}; + +const esp_efuse_desc_t* ESP_EFUSE_TEMP_CALIB[] = { + &TEMP_CALIB[0], // Temperature calibration data + NULL +}; + +const esp_efuse_desc_t* ESP_EFUSE_OCODE[] = { + &OCODE[0], // ADC OCode + NULL +}; + +const esp_efuse_desc_t* ESP_EFUSE_ADC1_INIT_CODE_ATTEN0[] = { + &ADC1_INIT_CODE_ATTEN0[0], // ADC1 init code at atten0 + NULL +}; + +const esp_efuse_desc_t* ESP_EFUSE_ADC1_INIT_CODE_ATTEN1[] = { + &ADC1_INIT_CODE_ATTEN1[0], // ADC1 init code at atten1 + NULL +}; + +const esp_efuse_desc_t* ESP_EFUSE_ADC1_INIT_CODE_ATTEN2[] = { + &ADC1_INIT_CODE_ATTEN2[0], // ADC1 init code at atten2 + NULL +}; + +const esp_efuse_desc_t* ESP_EFUSE_ADC1_INIT_CODE_ATTEN3[] = { + &ADC1_INIT_CODE_ATTEN3[0], // ADC1 init code at atten3 + NULL +}; + +const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN0[] = { + &ADC1_CAL_VOL_ATTEN0[0], // ADC1 calibration voltage at atten0 + NULL +}; + +const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN1[] = { + &ADC1_CAL_VOL_ATTEN1[0], // ADC1 calibration voltage at atten1 + NULL +}; + +const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN2[] = { + &ADC1_CAL_VOL_ATTEN2[0], // ADC1 calibration voltage at atten2 + NULL +}; + +const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN3[] = { + &ADC1_CAL_VOL_ATTEN3[0], // ADC1 calibration voltage at atten3 NULL }; diff --git a/components/efuse/esp32c3/esp_efuse_table.csv b/components/efuse/esp32c3/esp_efuse_table.csv index c69d56137c..0d9076c6b9 100644 --- a/components/efuse/esp32c3/esp_efuse_table.csv +++ b/components/efuse/esp32c3/esp_efuse_table.csv @@ -126,8 +126,21 @@ SPI_PAD_CONFIG_D6, EFUSE_BLK1, 102, 6, SPI_PAD_configure D6 SPI_PAD_CONFIG_D7, EFUSE_BLK1, 108, 6, SPI_PAD_configure D7 +# SYS_DATA_PART1 # +####################### + BLOCK2_VERSION, EFUSE_BLK2, 128, 3, Version of Block2 + TEMP_CALIB, EFUSE_BLK2, 131, 9, Temperature calibration data + OCODE, EFUSE_BLK2, 140, 8, ADC OCode + ADC1_INIT_CODE_ATTEN0, EFUSE_BLK2, 148, 10, ADC1 init code at atten0 + ADC1_INIT_CODE_ATTEN1, EFUSE_BLK2, 158, 10, ADC1 init code at atten1 + ADC1_INIT_CODE_ATTEN2, EFUSE_BLK2, 168, 10, ADC1 init code at atten2 + ADC1_INIT_CODE_ATTEN3, EFUSE_BLK2, 178, 10, ADC1 init code at atten3 + ADC1_CAL_VOL_ATTEN0, EFUSE_BLK2, 188, 10, ADC1 calibration voltage at atten0 + ADC1_CAL_VOL_ATTEN1, EFUSE_BLK2, 198, 10, ADC1 calibration voltage at atten1 + ADC1_CAL_VOL_ATTEN2, EFUSE_BLK2, 208, 10, ADC1 calibration voltage at atten2 + ADC1_CAL_VOL_ATTEN3, EFUSE_BLK2, 218, 10, ADC1 calibration voltage at atten3 + ################ -SYS_DATA_PART1, EFUSE_BLK2, 0, 256, System configuration USER_DATA, EFUSE_BLK3, 0, 256, User data KEY0, EFUSE_BLK4, 0, 256, Key0 or user data KEY1, EFUSE_BLK5, 0, 256, Key1 or user data diff --git a/components/efuse/esp32c3/include/esp_efuse_table.h b/components/efuse/esp32c3/include/esp_efuse_table.h index df8ba61e73..7d74200a59 100644 --- a/components/efuse/esp32c3/include/esp_efuse_table.h +++ b/components/efuse/esp32c3/include/esp_efuse_table.h @@ -17,7 +17,7 @@ extern "C" { #endif -// md5_digest_table 2c7ba2aa68a2748d3de9a5d1fed59b9f +// md5_digest_table 96cd6235ddc0947b4a296add3f942acb // This file was generated from the file esp_efuse_table.csv. DO NOT CHANGE THIS FILE MANUALLY. // If you want to change some fields, you need to change esp_efuse_table.csv file // then run `efuse_common_table` or `efuse_custom_table` command it will generate this file. @@ -115,7 +115,17 @@ extern const esp_efuse_desc_t* ESP_EFUSE_SPI_PAD_CONFIG_D4[]; extern const esp_efuse_desc_t* ESP_EFUSE_SPI_PAD_CONFIG_D5[]; extern const esp_efuse_desc_t* ESP_EFUSE_SPI_PAD_CONFIG_D6[]; extern const esp_efuse_desc_t* ESP_EFUSE_SPI_PAD_CONFIG_D7[]; -extern const esp_efuse_desc_t* ESP_EFUSE_SYS_DATA_PART1[]; +extern const esp_efuse_desc_t* ESP_EFUSE_BLOCK2_VERSION[]; +extern const esp_efuse_desc_t* ESP_EFUSE_TEMP_CALIB[]; +extern const esp_efuse_desc_t* ESP_EFUSE_OCODE[]; +extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_INIT_CODE_ATTEN0[]; +extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_INIT_CODE_ATTEN1[]; +extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_INIT_CODE_ATTEN2[]; +extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_INIT_CODE_ATTEN3[]; +extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN0[]; +extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN1[]; +extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN2[]; +extern const esp_efuse_desc_t* ESP_EFUSE_ADC1_CAL_VOL_ATTEN3[]; extern const esp_efuse_desc_t* ESP_EFUSE_USER_DATA[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY0[]; extern const esp_efuse_desc_t* ESP_EFUSE_KEY1[]; diff --git a/components/efuse/include/esp32c3/esp_efuse_rtc_calib.h b/components/efuse/include/esp32c3/esp_efuse_rtc_calib.h new file mode 100644 index 0000000000..75a0bb397e --- /dev/null +++ b/components/efuse/include/esp32c3/esp_efuse_rtc_calib.h @@ -0,0 +1,53 @@ +// Copyright 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 + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Get the RTC calibration efuse version + * + * @return Version of the stored efuse + */ +int esp_efuse_rtc_calib_get_ver(void); + +/** + * @brief Get the init code in the efuse, for the corresponding attenuation. + * + * @param version Version of the stored efuse + * @param atten Attenuation of the init code + * @return The init code stored in efuse + */ +uint16_t esp_efuse_rtc_calib_get_init_code(int version, int atten); + +/** + * @brief Get the calibration digits stored in the efuse, and the corresponding voltage. + * + * @param version Version of the stored efuse + * @param atten Attenuation to use + * @param out_digi Output buffer of the digits + * @param out_vol_mv Output of the voltage, in mV + * @return + * - ESP_ERR_INVALID_ARG: If efuse version or attenuation is invalid + * - ESP_OK: if success + */ +esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, int atten, uint32_t* out_digi, uint32_t* out_vol_mv); + +#ifdef __cplusplus +} +#endif diff --git a/components/efuse/src/esp32c3/esp_efuse_rtc_calib.c b/components/efuse/src/esp32c3/esp_efuse_rtc_calib.c new file mode 100644 index 0000000000..7f0460b41e --- /dev/null +++ b/components/efuse/src/esp32c3/esp_efuse_rtc_calib.c @@ -0,0 +1,84 @@ +// Copyright 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. + +#include +#include "esp_efuse.h" +#include "esp_efuse_table.h" + +int esp_efuse_rtc_calib_get_ver(void) +{ + uint32_t result = 0; + esp_efuse_read_field_blob(ESP_EFUSE_BLOCK2_VERSION, &result, 3); + return result; +} + +uint16_t esp_efuse_rtc_calib_get_init_code(int version, int atten) +{ + assert(version == 1); + const esp_efuse_desc_t** init_code_efuse; + assert(atten < 4); + if (atten == 0) { + init_code_efuse = ESP_EFUSE_ADC1_INIT_CODE_ATTEN0; + } else if (atten == 1) { + init_code_efuse = ESP_EFUSE_ADC1_INIT_CODE_ATTEN1; + } else if (atten == 2) { + init_code_efuse = ESP_EFUSE_ADC1_INIT_CODE_ATTEN2; + } else { + init_code_efuse = ESP_EFUSE_ADC1_INIT_CODE_ATTEN3; + } + + int init_code_size = esp_efuse_get_field_size(init_code_efuse); + assert(init_code_size == 10); + + uint32_t init_code = 0; + esp_err_t err = esp_efuse_read_field_blob(init_code_efuse, &init_code, init_code_size); + assert(err == ESP_OK); + return init_code + 1000; // version 1 logic +} + +esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, int atten, uint32_t* out_digi, uint32_t* out_vol_mv) +{ + const esp_efuse_desc_t** cal_vol_efuse; + uint32_t calib_vol_expected_mv; + if (version != 1) { + return ESP_ERR_INVALID_ARG; + } + if (atten >= 4) { + return ESP_ERR_INVALID_ARG; + } + if (atten == 0) { + cal_vol_efuse = ESP_EFUSE_ADC1_CAL_VOL_ATTEN0; + calib_vol_expected_mv = 400; + } else if (atten == 1) { + cal_vol_efuse = ESP_EFUSE_ADC1_CAL_VOL_ATTEN1; + calib_vol_expected_mv = 550; + } else if (atten == 2) { + cal_vol_efuse = ESP_EFUSE_ADC1_CAL_VOL_ATTEN2; + calib_vol_expected_mv = 750; + } else { + cal_vol_efuse = ESP_EFUSE_ADC1_CAL_VOL_ATTEN3; + calib_vol_expected_mv = 1370; + } + + int cal_vol_size = esp_efuse_get_field_size(cal_vol_efuse); + assert(cal_vol_size == 10); + + uint32_t cal_vol = 0; + esp_err_t err = esp_efuse_read_field_blob(cal_vol_efuse, &cal_vol, cal_vol_size) & 0x3FF; + assert(err == ESP_OK); + + *out_digi = 2000 + ((cal_vol & BIT(9))? -(cal_vol & ~BIT9): cal_vol); + *out_vol_mv = calib_vol_expected_mv; + return ESP_OK; +} diff --git a/components/esp32c3/ld/esp32c3.peripherals.ld b/components/esp32c3/ld/esp32c3.peripherals.ld index 4b6eaa39cc..61164a12cd 100644 --- a/components/esp32c3/ld/esp32c3.peripherals.ld +++ b/components/esp32c3/ld/esp32c3.peripherals.ld @@ -7,7 +7,6 @@ PROVIDE ( GPIO = 0x60004000 ); PROVIDE ( SIGMADELTA = 0x60004f00 ); PROVIDE ( RTCCNTL = 0x60008000 ); PROVIDE ( RTCIO = 0x60008400 ); -PROVIDE ( SENS = 0x60008800 ); PROVIDE ( HINF = 0x6000B000 ); PROVIDE ( I2S1 = 0x6002d000 ); PROVIDE ( I2C0 = 0x60013000 ); diff --git a/components/esp32c3/system_api_esp32c3.c b/components/esp32c3/system_api_esp32c3.c index c0b51b8552..e054f72240 100644 --- a/components/esp32c3/system_api_esp32c3.c +++ b/components/esp32c3/system_api_esp32c3.c @@ -100,9 +100,16 @@ void IRAM_ATTR esp_restart_noos(void) // Reset timer/spi/uart SET_PERI_REG_MASK(SYSTEM_PERIP_RST_EN0_REG, - SYSTEM_TIMERS_RST | SYSTEM_SPI01_RST | SYSTEM_UART_RST); + SYSTEM_TIMERS_RST | SYSTEM_SPI01_RST | SYSTEM_UART_RST | SYSTEM_SPI3_DMA_RST | SYSTEM_SPI2_DMA_RST); REG_WRITE(SYSTEM_PERIP_RST_EN0_REG, 0); + + // Reset dma + SET_PERI_REG_MASK(SYSTEM_PERIP_RST_EN1_REG, SYSTEM_DMA_RST); REG_WRITE(SYSTEM_PERIP_RST_EN1_REG, 0); + + SET_PERI_REG_MASK(SYSTEM_EDMA_CTRL_REG, SYSTEM_EDMA_RESET); + CLEAR_PERI_REG_MASK(SYSTEM_EDMA_CTRL_REG, SYSTEM_EDMA_RESET); + // Set CPU back to XTAL source, no PLL, same as hard reset #if !CONFIG_IDF_ENV_FPGA rtc_clk_cpu_freq_set_xtal(); diff --git a/components/esp32s3/system_api_esp32s3.c b/components/esp32s3/system_api_esp32s3.c index 5e787fdd90..a562f37dfe 100644 --- a/components/esp32s3/system_api_esp32s3.c +++ b/components/esp32s3/system_api_esp32s3.c @@ -98,9 +98,13 @@ void IRAM_ATTR esp_restart_noos(void) // Reset timer/spi/uart SET_PERI_REG_MASK(SYSTEM_PERIP_RST_EN0_REG, - SYSTEM_TIMERS_RST | SYSTEM_SPI01_RST | SYSTEM_UART_RST); + SYSTEM_TIMERS_RST | SYSTEM_SPI01_RST | SYSTEM_UART_RST | SYSTEM_SPI3_DMA_RST | SYSTEM_SPI2_DMA_RST); REG_WRITE(SYSTEM_PERIP_RST_EN0_REG, 0); + // Reset dma + SET_PERI_REG_MASK(SYSTEM_PERIP_RST_EN1_REG, SYSTEM_DMA_RST); + REG_WRITE(SYSTEM_PERIP_RST_EN1_REG, 0); + // Set CPU back to XTAL source, no PLL, same as hard reset #if !CONFIG_IDF_ENV_FPGA rtc_clk_cpu_freq_set_xtal(); diff --git a/components/esp_adc_cal/CMakeLists.txt b/components/esp_adc_cal/CMakeLists.txt index 771340a460..61d15d185f 100644 --- a/components/esp_adc_cal/CMakeLists.txt +++ b/components/esp_adc_cal/CMakeLists.txt @@ -10,4 +10,8 @@ elseif(${target} STREQUAL "esp32s2") INCLUDE_DIRS "include" REQUIRES driver efuse) +elseif(${target} STREQUAL "esp32c3") + idf_component_register(SRCS "esp_adc_cal_esp32c3.c" + INCLUDE_DIRS "include" + REQUIRES driver efuse) endif() diff --git a/components/esp_adc_cal/component.mk b/components/esp_adc_cal/component.mk index 5c826b74be..b12080ce87 100644 --- a/components/esp_adc_cal/component.mk +++ b/components/esp_adc_cal/component.mk @@ -3,4 +3,4 @@ # COMPONENT_ADD_INCLUDEDIRS := include -COMPONENT_OBJEXCLUDE += esp_adc_cal_esp32s2.o +COMPONENT_OBJEXCLUDE += esp_adc_cal_esp32s2.o esp_adc_cal_esp32c3.o diff --git a/components/esp_adc_cal/esp_adc_cal_esp32c3.c b/components/esp_adc_cal/esp_adc_cal_esp32c3.c new file mode 100644 index 0000000000..28f23bdee7 --- /dev/null +++ b/components/esp_adc_cal/esp_adc_cal_esp32c3.c @@ -0,0 +1,164 @@ +// Copyright 2019-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. + +#include +#include +#include +#include "esp_types.h" +#include "esp_err.h" +#include "esp_log.h" +#include "driver/adc.h" +#include "hal/adc_ll.h" +#include "esp32c3/esp_efuse_rtc_calib.h" +#include "esp_adc_cal.h" + + +#define ADC_CALIB_CHECK(cond, err_msg, ret) do {\ + if (!(cond)) { \ + ESP_LOGE(LOG_TAG, err_msg); \ + return (ret); \ + } \ + } while(0) + +const static char LOG_TAG[] = "adc_calib"; + + +/* ------------------------ Characterization Constants ---------------------- */ + +// coeff_a and coeff_b are actually floats +// they are scaled to put them into uint32_t so that the headers do not have to be changed +static const int coeff_a_scaling = 65536; +static const int coeff_b_scaling = 1024; +/* -------------------- Characterization Helper Data Types ------------------ */ +typedef struct { + uint32_t voltage; + uint32_t digi; +} adc_calib_data_ver1; + +typedef struct { + char version_num; + adc_unit_t adc_num; + adc_atten_t atten_level; + union { + adc_calib_data_ver1 ver1; + } efuse_data; +} adc_calib_parsed_info; + +static bool prepare_calib_data_for(int version_num, adc_unit_t adc_num, adc_atten_t atten, adc_calib_parsed_info *parsed_data_storage) +{ + assert(version_num == 1); + parsed_data_storage->version_num = version_num; + parsed_data_storage->adc_num = adc_num; + parsed_data_storage->atten_level = atten; + // V1 we don't have calibration data for ADC2, using the efuse data of ADC1 + uint32_t voltage, digi; + esp_err_t ret = esp_efuse_rtc_calib_get_cal_voltage(version_num, atten, &digi, &voltage); + assert(ret == ESP_OK); + parsed_data_storage->efuse_data.ver1.voltage = voltage; + parsed_data_storage->efuse_data.ver1.digi = digi; + return true; +} + +/* ----------------------- Characterization Functions ----------------------- */ +/* + * Estimate the (assumed) linear relationship btwn the measured raw value and the voltage + * with the previously done measurement when the chip was manufactured. + * */ +static bool calculate_characterization_coefficients(const adc_calib_parsed_info *parsed_data, esp_adc_cal_characteristics_t *chars) +{ + ESP_LOGD(LOG_TAG, "Calib V1, Cal Voltage = %d, Digi out = %d\n", parsed_data->efuse_data.ver1.voltage, parsed_data->efuse_data.ver1.digi); + + chars->coeff_a = coeff_a_scaling * parsed_data->efuse_data.ver1.voltage / parsed_data->efuse_data.ver1.digi; + chars->coeff_b = 0; + return true; +} + +/* ------------------------- Public API ------------------------------------- */ +esp_err_t esp_adc_cal_check_efuse(esp_adc_cal_value_t source) +{ + if (source != ESP_ADC_CAL_VAL_EFUSE_TP) { + return ESP_ERR_NOT_SUPPORTED; + } + uint8_t adc_encoding_version = esp_efuse_rtc_calib_get_ver(); + if (adc_encoding_version != 1) { + // current version only accepts encoding ver 1. + return ESP_ERR_INVALID_VERSION; + } + return ESP_OK; +} + +esp_adc_cal_value_t esp_adc_cal_characterize(adc_unit_t adc_num, + adc_atten_t atten, + adc_bits_width_t bit_width, + uint32_t default_vref, + esp_adc_cal_characteristics_t *chars) +{ + bool res; + adc_calib_parsed_info efuse_parsed_data = {0}; + // Check parameters + ADC_CALIB_CHECK(adc_num == ADC_UNIT_1 || adc_num == ADC_UNIT_2, "Invalid unit num", ESP_ADC_CAL_VAL_NOT_SUPPORTED); + ADC_CALIB_CHECK(chars != NULL, "Invalid characteristic", ESP_ADC_CAL_VAL_NOT_SUPPORTED); + ADC_CALIB_CHECK(bit_width == ADC_WIDTH_BIT_12, "Invalid bit_width", ESP_ADC_CAL_VAL_NOT_SUPPORTED); + + int version_num = esp_efuse_rtc_calib_get_ver(); + ADC_CALIB_CHECK(version_num == 1, "No calibration efuse burnt", ESP_ADC_CAL_VAL_NOT_SUPPORTED); + + memset(chars, 0, sizeof(esp_adc_cal_characteristics_t)); + + // make sure adc is calibrated. + res = prepare_calib_data_for(version_num, adc_num, atten, &efuse_parsed_data); + assert(res); + res = calculate_characterization_coefficients(&efuse_parsed_data, chars); + assert(res); + ESP_LOGD(LOG_TAG, "adc%d (atten leven %d) calibration done: A:%d B:%d\n", adc_num, atten, chars->coeff_a, chars->coeff_b); + + // Initialize remaining fields + chars->adc_num = adc_num; + chars->atten = atten; + chars->bit_width = bit_width; + + // in esp32c3 we only use the two point method to calibrate the adc. + return ESP_ADC_CAL_VAL_EFUSE_TP; +} + +uint32_t esp_adc_cal_raw_to_voltage(uint32_t adc_reading, const esp_adc_cal_characteristics_t *chars) +{ + ADC_CALIB_CHECK(chars != NULL, "No characteristic input.", ESP_ERR_INVALID_ARG); + + return adc_reading * chars->coeff_a / coeff_a_scaling + chars->coeff_b / coeff_b_scaling; +} + +esp_err_t esp_adc_cal_get_voltage(adc_channel_t channel, + const esp_adc_cal_characteristics_t *chars, + uint32_t *voltage) +{ + // Check parameters + ADC_CALIB_CHECK(chars != NULL, "No characteristic input.", ESP_ERR_INVALID_ARG); + ADC_CALIB_CHECK(voltage != NULL, "No output buffer.", ESP_ERR_INVALID_ARG); + + int adc_reading; + if (chars->adc_num == ADC_UNIT_1) { + //Check if channel is valid on ADC1 + ADC_CALIB_CHECK((adc1_channel_t)channel < ADC1_CHANNEL_MAX, "Invalid channel", ESP_ERR_INVALID_ARG); + adc_reading = adc1_get_raw(channel); + } else { + //Check if channel is valid on ADC2 + ADC_CALIB_CHECK((adc2_channel_t)channel < ADC2_CHANNEL_MAX, "Invalid channel", ESP_ERR_INVALID_ARG); + if (adc2_get_raw(channel, chars->bit_width, &adc_reading) != ESP_OK) { + return ESP_ERR_TIMEOUT; //Timed out waiting for ADC2 + } + } + *voltage = esp_adc_cal_raw_to_voltage((uint32_t)adc_reading, chars); + return ESP_OK; +} diff --git a/components/esp_adc_cal/include/esp_adc_cal.h b/components/esp_adc_cal/include/esp_adc_cal.h index 5a65b0f37d..b7afb383f6 100644 --- a/components/esp_adc_cal/include/esp_adc_cal.h +++ b/components/esp_adc_cal/include/esp_adc_cal.h @@ -30,7 +30,8 @@ typedef enum { ESP_ADC_CAL_VAL_EFUSE_VREF = 0, /**< Characterization based on reference voltage stored in eFuse*/ ESP_ADC_CAL_VAL_EFUSE_TP = 1, /**< Characterization based on Two Point values stored in eFuse*/ ESP_ADC_CAL_VAL_DEFAULT_VREF = 2, /**< Characterization based on default reference voltage*/ - ESP_ADC_CAL_VAL_MAX + ESP_ADC_CAL_VAL_MAX, + ESP_ADC_CAL_VAL_NOT_SUPPORTED = ESP_ADC_CAL_VAL_MAX, } esp_adc_cal_value_t; /** diff --git a/components/esp_hw_support/port/esp32c3/private_include/regi2c_lp_bias.h b/components/esp_hw_support/port/esp32c3/private_include/regi2c_lp_bias.h index 7cf3b457ce..f89a53f0b4 100644 --- a/components/esp_hw_support/port/esp32c3/private_include/regi2c_lp_bias.h +++ b/components/esp_hw_support/port/esp32c3/private_include/regi2c_lp_bias.h @@ -30,6 +30,18 @@ #define I2C_ULP_IR_RESETB_MSB 0 #define I2C_ULP_IR_RESETB_LSB 0 +#define I2C_ULP_IR_FORCE_XPD_CK 0 +#define I2C_ULP_IR_FORCE_XPD_CK_MSB 2 +#define I2C_ULP_IR_FORCE_XPD_CK_LSB 2 + +#define I2C_ULP_IR_FORCE_XPD_IPH 0 +#define I2C_ULP_IR_FORCE_XPD_IPH_MSB 4 +#define I2C_ULP_IR_FORCE_XPD_IPH_LSB 4 + +#define I2C_ULP_IR_DISABLE_WATCHDOG_CK 0 +#define I2C_ULP_IR_DISABLE_WATCHDOG_CK_MSB 6 +#define I2C_ULP_IR_DISABLE_WATCHDOG_CK_LSB 6 + #define I2C_ULP_O_DONE_FLAG 3 #define I2C_ULP_O_DONE_FLAG_MSB 0 #define I2C_ULP_O_DONE_FLAG_LSB 0 @@ -38,14 +50,10 @@ #define I2C_ULP_BG_O_DONE_FLAG_MSB 3 #define I2C_ULP_BG_O_DONE_FLAG_LSB 3 -#define I2C_ULP_IR_FORCE_XPD_IPH 0 -#define I2C_ULP_IR_FORCE_XPD_IPH_MSB 4 -#define I2C_ULP_IR_FORCE_XPD_IPH_LSB 4 +#define I2C_ULP_IR_FORCE_CODE 5 +#define I2C_ULP_IR_FORCE_CODE_MSB 6 +#define I2C_ULP_IR_FORCE_CODE_LSB 6 -#define I2C_ULP_IR_FORCE_XPD_CK 0 -#define I2C_ULP_IR_FORCE_XPD_CK_MSB 2 -#define I2C_ULP_IR_FORCE_XPD_CK_LSB 2 - -#define I2C_ULP_IR_DISABLE_WATCHDOG_CK 0 -#define I2C_ULP_IR_DISABLE_WATCHDOG_CK_MSB 6 -#define I2C_ULP_IR_DISABLE_WATCHDOG_CK_LSB 6 +#define I2C_ULP_EXT_CODE 6 +#define I2C_ULP_EXT_CODE_MSB 7 +#define I2C_ULP_EXT_CODE_LSB 0 diff --git a/components/esp_hw_support/port/esp32c3/rtc_clk.c b/components/esp_hw_support/port/esp32c3/rtc_clk.c index 5cd7259bb7..d9b193fb9c 100644 --- a/components/esp_hw_support/port/esp32c3/rtc_clk.c +++ b/components/esp_hw_support/port/esp32c3/rtc_clk.c @@ -24,7 +24,6 @@ #include "esp32c3/rom/gpio.h" #include "soc/rtc.h" #include "soc/rtc_cntl_reg.h" -#include "soc/sens_reg.h" #include "soc/efuse_reg.h" #include "soc/syscon_reg.h" #include "soc/system_reg.h" diff --git a/components/esp_hw_support/port/esp32c3/rtc_clk_init.c b/components/esp_hw_support/port/esp32c3/rtc_clk_init.c index 0960f6e67b..40fbdd81ae 100644 --- a/components/esp_hw_support/port/esp32c3/rtc_clk_init.c +++ b/components/esp_hw_support/port/esp32c3/rtc_clk_init.c @@ -21,7 +21,6 @@ #include "esp32c3/rom/uart.h" #include "soc/rtc.h" #include "soc/rtc_periph.h" -#include "soc/sens_periph.h" #include "soc/efuse_periph.h" #include "soc/apb_ctrl_reg.h" #include "hal/cpu_hal.h" diff --git a/components/esp_hw_support/port/esp32c3/rtc_init.c b/components/esp_hw_support/port/esp32c3/rtc_init.c index 2f09d06c02..f6f952c04b 100644 --- a/components/esp_hw_support/port/esp32c3/rtc_init.c +++ b/components/esp_hw_support/port/esp32c3/rtc_init.c @@ -24,9 +24,14 @@ #include "soc/system_reg.h" #include "regi2c_ctrl.h" #include "soc_log.h" +#include "esp_efuse.h" +#include "esp_efuse_table.h" static const char *TAG = "rtc_init"; +static void set_ocode_by_efuse(int calib_version); +static void calibrate_ocode(void); + void rtc_init(rtc_config_t cfg) { REGI2C_WRITE_MASK(I2C_DIG_REG, I2C_DIG_REG_XPD_DIG_REG, 0); @@ -135,54 +140,13 @@ void rtc_init(rtc_config_t cfg) CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_NOISO); } if (cfg.cali_ocode) { - /* - Bandgap output voltage is not precise when calibrate o-code by hardware sometimes, so need software o-code calibration(must close PLL). - Method: - 1. read current cpu config, save in old_config; - 2. switch cpu to xtal because PLL will be closed when o-code calibration; - 3. begin o-code calibration; - 4. wait o-code calibration done flag(odone_flag & bg_odone_flag) or timeout; - 5. set cpu to old-config. - */ - rtc_slow_freq_t slow_clk_freq = rtc_clk_slow_freq_get(); - rtc_slow_freq_t rtc_slow_freq_x32k = RTC_SLOW_FREQ_32K_XTAL; - rtc_slow_freq_t rtc_slow_freq_8MD256 = RTC_SLOW_FREQ_8MD256; - rtc_cal_sel_t cal_clk = RTC_CAL_RTC_MUX; - if (slow_clk_freq == (rtc_slow_freq_x32k)) { - cal_clk = RTC_CAL_32K_XTAL; - } else if (slow_clk_freq == rtc_slow_freq_8MD256) { - cal_clk = RTC_CAL_8MD256; + uint32_t rtc_calib_version = 0; + esp_efuse_read_field_blob(ESP_EFUSE_BLOCK2_VERSION, &rtc_calib_version, 3); + if (rtc_calib_version == 1) { + set_ocode_by_efuse(rtc_calib_version); + } else { + calibrate_ocode(); } - - uint64_t max_delay_time_us = 10000; - uint32_t slow_clk_period = rtc_clk_cal(cal_clk, 100); - uint64_t max_delay_cycle = rtc_time_us_to_slowclk(max_delay_time_us, slow_clk_period); - uint64_t cycle0 = rtc_time_get(); - uint64_t timeout_cycle = cycle0 + max_delay_cycle; - uint64_t cycle1 = 0; - - rtc_cpu_freq_config_t old_config; - rtc_clk_cpu_freq_get_config(&old_config); - rtc_clk_cpu_freq_set_xtal(); - - - REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_RESETB, 0); - REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_RESETB, 1); - bool odone_flag = 0; - bool bg_odone_flag = 0; - while (1) { - odone_flag = REGI2C_READ_MASK(I2C_ULP, I2C_ULP_O_DONE_FLAG); - bg_odone_flag = REGI2C_READ_MASK(I2C_ULP, I2C_ULP_BG_O_DONE_FLAG); - cycle1 = rtc_time_get(); - if (odone_flag && bg_odone_flag) { - break; - } - if (cycle1 >= timeout_cycle) { - SOC_LOGW(TAG, "o_code calibration fail\n"); - break; - } - } - rtc_clk_cpu_freq_set_config(&old_config); } } @@ -223,3 +187,65 @@ void rtc_vddsdio_set_config(rtc_vddsdio_config_t config) val |= RTC_CNTL_SDIO_PD_EN; REG_WRITE(RTC_CNTL_SDIO_CONF_REG, val); } + +static void set_ocode_by_efuse(int calib_version) +{ + assert(calib_version == 1); + // use efuse ocode. + uint32_t ocode; + esp_err_t err = esp_efuse_read_field_blob(ESP_EFUSE_OCODE, &ocode, 8); + assert(err == ESP_OK); + REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_EXT_CODE, ocode); + REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_FORCE_CODE, 1); +} + +static void calibrate_ocode(void) +{ + /* + Bandgap output voltage is not precise when calibrate o-code by hardware sometimes, so need software o-code calibration (must turn off PLL). + Method: + 1. read current cpu config, save in old_config; + 2. switch cpu to xtal because PLL will be closed when o-code calibration; + 3. begin o-code calibration; + 4. wait o-code calibration done flag(odone_flag & bg_odone_flag) or timeout; + 5. set cpu to old-config. + */ + rtc_slow_freq_t slow_clk_freq = rtc_clk_slow_freq_get(); + rtc_slow_freq_t rtc_slow_freq_x32k = RTC_SLOW_FREQ_32K_XTAL; + rtc_slow_freq_t rtc_slow_freq_8MD256 = RTC_SLOW_FREQ_8MD256; + rtc_cal_sel_t cal_clk = RTC_CAL_RTC_MUX; + if (slow_clk_freq == (rtc_slow_freq_x32k)) { + cal_clk = RTC_CAL_32K_XTAL; + } else if (slow_clk_freq == rtc_slow_freq_8MD256) { + cal_clk = RTC_CAL_8MD256; + } + + uint64_t max_delay_time_us = 10000; + uint32_t slow_clk_period = rtc_clk_cal(cal_clk, 100); + uint64_t max_delay_cycle = rtc_time_us_to_slowclk(max_delay_time_us, slow_clk_period); + uint64_t cycle0 = rtc_time_get(); + uint64_t timeout_cycle = cycle0 + max_delay_cycle; + uint64_t cycle1 = 0; + + rtc_cpu_freq_config_t old_config; + rtc_clk_cpu_freq_get_config(&old_config); + rtc_clk_cpu_freq_set_xtal(); + + REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_RESETB, 0); + REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_RESETB, 1); + bool odone_flag = 0; + bool bg_odone_flag = 0; + while (1) { + odone_flag = REGI2C_READ_MASK(I2C_ULP, I2C_ULP_O_DONE_FLAG); + bg_odone_flag = REGI2C_READ_MASK(I2C_ULP, I2C_ULP_BG_O_DONE_FLAG); + cycle1 = rtc_time_get(); + if (odone_flag && bg_odone_flag) { + break; + } + if (cycle1 >= timeout_cycle) { + SOC_LOGW(TAG, "o_code calibration fail\n"); + break; + } + } + rtc_clk_cpu_freq_set_config(&old_config); +} diff --git a/components/esp_hw_support/port/esp32s2/private_include/regi2c_ulp.h b/components/esp_hw_support/port/esp32s2/private_include/regi2c_ulp.h index de38328a2c..4be3a499d2 100644 --- a/components/esp_hw_support/port/esp32s2/private_include/regi2c_ulp.h +++ b/components/esp_hw_support/port/esp32s2/private_include/regi2c_ulp.h @@ -38,9 +38,10 @@ #define I2C_ULP_BG_O_DONE_FLAG_MSB 3 #define I2C_ULP_BG_O_DONE_FLAG_LSB 3 -#define I2C_ULP_OCODE_ADDR 6 -#define I2C_ULP_OCODE_ADDR_MSB 7 -#define I2C_ULP_OCODE_ADDR_LSB 0 -#define I2C_ULP_IR_FORCE_CODE_ADDR 5 -#define I2C_ULP_IR_FORCE_CODE_ADDR_MSB 6 -#define I2C_ULP_IR_FORCE_CODE_ADDR_LSB 6 +#define I2C_ULP_IR_FORCE_CODE 5 +#define I2C_ULP_IR_FORCE_CODE_MSB 6 +#define I2C_ULP_IR_FORCE_CODE_LSB 6 + +#define I2C_ULP_EXT_CODE 6 +#define I2C_ULP_EXT_CODE_MSB 7 +#define I2C_ULP_EXT_CODE_LSB 0 diff --git a/components/esp_hw_support/port/esp32s2/rtc_init.c b/components/esp_hw_support/port/esp32s2/rtc_init.c index dfbff46150..a71251eb61 100644 --- a/components/esp_hw_support/port/esp32s2/rtc_init.c +++ b/components/esp_hw_support/port/esp32s2/rtc_init.c @@ -28,6 +28,9 @@ #include "esp_efuse_table.h" static const char *TAG = "rtc_init"; +static void set_ocode_by_efuse(int calib_version); +static void calibrate_ocode(void); + void rtc_init(rtc_config_t cfg) { CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_PVTMON_PU); @@ -152,68 +155,9 @@ void rtc_init(rtc_config_t cfg) uint32_t rtc_calib_version = 0; esp_efuse_read_field_blob(ESP_EFUSE_BLOCK2_VERSION, &rtc_calib_version, 32); if (rtc_calib_version == 2) { - // use efuse ocode. - uint32_t ocode1 = 0; - uint32_t ocode2 = 0; - uint32_t ocode; - esp_efuse_read_block(2, &ocode1, 16*8, 4); - esp_efuse_read_block(2, &ocode2, 18*8, 3); - ocode = (ocode2 << 4) + ocode1; - if (ocode >> 6) { - ocode = 93 - (ocode ^ (1 << 6)); - } else { - ocode = 93 + ocode; - } - REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_OCODE_ADDR, ocode); - REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_FORCE_CODE_ADDR, 1); + set_ocode_by_efuse(rtc_calib_version); } else { - /* - Bangap output voltage is not precise when calibrate o-code by hardware sometimes, so need software o-code calibration(must close PLL). - Method: - 1. read current cpu config, save in old_config; - 2. switch cpu to xtal because PLL will be closed when o-code calibration; - 3. begin o-code calibration; - 4. wait o-code calibration done flag(odone_flag & bg_odone_flag) or timeout; - 5. set cpu to old-config. - */ - rtc_slow_freq_t slow_clk_freq = rtc_clk_slow_freq_get(); - rtc_slow_freq_t rtc_slow_freq_x32k = RTC_SLOW_FREQ_32K_XTAL; - rtc_slow_freq_t rtc_slow_freq_8MD256 = RTC_SLOW_FREQ_8MD256; - rtc_cal_sel_t cal_clk = RTC_CAL_RTC_MUX; - if (slow_clk_freq == (rtc_slow_freq_x32k)) { - cal_clk = RTC_CAL_32K_XTAL; - } else if (slow_clk_freq == rtc_slow_freq_8MD256) { - cal_clk = RTC_CAL_8MD256; - } - - uint64_t max_delay_time_us = 10000; - uint32_t slow_clk_period = rtc_clk_cal(cal_clk, 100); - uint64_t max_delay_cycle = rtc_time_us_to_slowclk(max_delay_time_us, slow_clk_period); - uint64_t cycle0 = rtc_time_get(); - uint64_t timeout_cycle = cycle0 + max_delay_cycle; - uint64_t cycle1 = 0; - - rtc_cpu_freq_config_t old_config; - rtc_clk_cpu_freq_get_config(&old_config); - rtc_clk_cpu_freq_set_xtal(); - - - REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_RESETB, 0); - REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_RESETB, 1); - bool odone_flag = 0; - bool bg_odone_flag = 0; - while(1) { - odone_flag = REGI2C_READ_MASK(I2C_ULP, I2C_ULP_O_DONE_FLAG); - bg_odone_flag = REGI2C_READ_MASK(I2C_ULP, I2C_ULP_BG_O_DONE_FLAG); - cycle1 = rtc_time_get(); - if (odone_flag && bg_odone_flag) - break; - if (cycle1 >= timeout_cycle) { - SOC_LOGW(TAG, "o_code calibration fail"); - break; - } - } - rtc_clk_cpu_freq_set_config(&old_config); + calibrate_ocode(); } } } @@ -269,3 +213,72 @@ void rtc_vddsdio_set_config(rtc_vddsdio_config_t config) val |= RTC_CNTL_SDIO_PD_EN; REG_WRITE(RTC_CNTL_SDIO_CONF_REG, val); } + +static void set_ocode_by_efuse(int calib_version) +{ + assert(calib_version == 2); + // use efuse ocode. + uint32_t ocode1 = 0; + uint32_t ocode2 = 0; + uint32_t ocode; + esp_efuse_read_block(2, &ocode1, 16*8, 4); + esp_efuse_read_block(2, &ocode2, 18*8, 3); + ocode = (ocode2 << 4) + ocode1; + if (ocode >> 6) { + ocode = 93 - (ocode ^ (1 << 6)); + } else { + ocode = 93 + ocode; + } + REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_EXT_CODE, ocode); + REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_FORCE_CODE, 1); +} + +static void calibrate_ocode(void) +{ + /* + Bandgap output voltage is not precise when calibrate o-code by hardware sometimes, so need software o-code calibration (must turn off PLL). + Method: + 1. read current cpu config, save in old_config; + 2. switch cpu to xtal because PLL will be closed when o-code calibration; + 3. begin o-code calibration; + 4. wait o-code calibration done flag(odone_flag & bg_odone_flag) or timeout; + 5. set cpu to old-config. + */ + rtc_slow_freq_t slow_clk_freq = rtc_clk_slow_freq_get(); + rtc_slow_freq_t rtc_slow_freq_x32k = RTC_SLOW_FREQ_32K_XTAL; + rtc_slow_freq_t rtc_slow_freq_8MD256 = RTC_SLOW_FREQ_8MD256; + rtc_cal_sel_t cal_clk = RTC_CAL_RTC_MUX; + if (slow_clk_freq == (rtc_slow_freq_x32k)) { + cal_clk = RTC_CAL_32K_XTAL; + } else if (slow_clk_freq == rtc_slow_freq_8MD256) { + cal_clk = RTC_CAL_8MD256; + } + + uint64_t max_delay_time_us = 10000; + uint32_t slow_clk_period = rtc_clk_cal(cal_clk, 100); + uint64_t max_delay_cycle = rtc_time_us_to_slowclk(max_delay_time_us, slow_clk_period); + uint64_t cycle0 = rtc_time_get(); + uint64_t timeout_cycle = cycle0 + max_delay_cycle; + uint64_t cycle1 = 0; + + rtc_cpu_freq_config_t old_config; + rtc_clk_cpu_freq_get_config(&old_config); + rtc_clk_cpu_freq_set_xtal(); + + REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_RESETB, 0); + REGI2C_WRITE_MASK(I2C_ULP, I2C_ULP_IR_RESETB, 1); + bool odone_flag = 0; + bool bg_odone_flag = 0; + while(1) { + odone_flag = REGI2C_READ_MASK(I2C_ULP, I2C_ULP_O_DONE_FLAG); + bg_odone_flag = REGI2C_READ_MASK(I2C_ULP, I2C_ULP_BG_O_DONE_FLAG); + cycle1 = rtc_time_get(); + if (odone_flag && bg_odone_flag) + break; + if (cycle1 >= timeout_cycle) { + SOC_LOGW(TAG, "o_code calibration fail"); + break; + } + } + rtc_clk_cpu_freq_set_config(&old_config); +} diff --git a/components/esp_hw_support/test/test_rtc_clk.c b/components/esp_hw_support/test/test_rtc_clk.c index 8d8acc04b8..9d3d3d4895 100644 --- a/components/esp_hw_support/test/test_rtc_clk.c +++ b/components/esp_hw_support/test/test_rtc_clk.c @@ -1,9 +1,12 @@ #include #include "unity.h" +#include "soc/soc_caps.h" #include "soc/rtc.h" #include "soc/rtc_periph.h" +#if SOC_ADC_SUPPORT_RTC_CTRL #include "soc/sens_periph.h" +#endif #include "soc/gpio_periph.h" #include "hal/gpio_ll.h" #include "driver/rtc_io.h" diff --git a/components/esp_system/port/soc/esp32c3/clk.c b/components/esp_system/port/soc/esp32c3/clk.c index d2467a4cf9..2f9d42c589 100644 --- a/components/esp_system/port/soc/esp32c3/clk.c +++ b/components/esp_system/port/soc/esp32c3/clk.c @@ -75,6 +75,11 @@ static const char *TAG = "clk"; { #if !CONFIG_IDF_ENV_FPGA rtc_config_t cfg = RTC_CONFIG_DEFAULT(); + RESET_REASON rst_reas; + rst_reas = rtc_get_reset_reason(0); + if (rst_reas == POWERON_RESET) { + cfg.cali_ocode = 1; + } rtc_init(cfg); assert(rtc_clk_xtal_freq_get() == RTC_XTAL_FREQ_40M); diff --git a/components/hal/esp32c3/adc_hal.c b/components/hal/esp32c3/adc_hal.c index b000a6c9d8..7f1e49d4f6 100644 --- a/components/hal/esp32c3/adc_hal.c +++ b/components/hal/esp32c3/adc_hal.c @@ -33,14 +33,6 @@ void adc_hal_digi_deinit(void) adc_hal_deinit(); } -uint32_t adc_hal_calibration(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten, bool internal_gnd, bool force_cal); - -static inline void adc_set_init_code(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten) -{ - uint32_t cal_val = adc_hal_calibration(adc_n, channel, atten, true, false); - adc_hal_set_calibration_param(adc_n, cal_val); -} - void adc_hal_digi_controller_config(const adc_digi_config_t *cfg) { //only one pattern table is supported on C3, but LL still needs one argument. @@ -53,7 +45,6 @@ void adc_hal_digi_controller_config(const adc_digi_config_t *cfg) adc_ll_digi_set_pattern_table_len(pattern_both, cfg->adc_pattern_len); for (int i = 0; i < cfg->adc_pattern_len; i++) { adc_ll_digi_set_pattern_table(pattern_both, i, cfg->adc_pattern[i]); - adc_set_init_code(pattern_both, cfg->adc_pattern[i].channel, cfg->adc_pattern[i].atten); } } @@ -136,98 +127,3 @@ void adc_hal_arbiter_config(adc_arbiter_t *config) adc_ll_set_arbiter_work_mode(config->mode); adc_ll_set_arbiter_priority(config->rtc_pri, config->dig_pri, config->pwdet_pri); } - -/*--------------------------------------------------------------- - ADC calibration setting ----------------------------------------------------------------*/ - -#define ADC_HAL_CAL_OFFSET_RANGE (4096) -#define ADC_HAL_CAL_TIMES (10) - -static uint16_t s_adc_cali_param[ADC_NUM_MAX][ADC_ATTEN_MAX] = { {0}, {0} }; - -static uint32_t adc_hal_read_self_cal(adc_ll_num_t adc_n, int channel) -{ - adc_ll_rtc_start_convert(adc_n, channel); - while (adc_ll_rtc_convert_is_done(adc_n) != true); - return (uint32_t)adc_ll_rtc_get_convert_value(adc_n); -} - -uint32_t adc_hal_calibration(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten, bool internal_gnd, bool force_cal) -{ - if (!force_cal) { - if (s_adc_cali_param[adc_n][atten]) { - return (uint32_t)s_adc_cali_param[adc_n][atten]; - } - } - - uint32_t code_list[ADC_HAL_CAL_TIMES] = {0}; - uint32_t code_sum = 0; - uint32_t code_h = 0; - uint32_t code_l = 0; - uint32_t chk_code = 0; - uint32_t dout = 0; - - adc_hal_set_power_manage(ADC_POWER_SW_ON); - if (adc_n == ADC_NUM_2) { - adc_arbiter_t config = ADC_ARBITER_CONFIG_DEFAULT(); - adc_hal_arbiter_config(&config); - } - adc_hal_set_controller(adc_n, ADC_CTRL_RTC); //Set controller - - // adc_hal_arbiter_config(adc_arbiter_t *config) - adc_ll_calibration_prepare(adc_n, channel, internal_gnd); - - /* Enable/disable internal connect GND (for calibration). */ - if (internal_gnd) { - adc_ll_rtc_disable_channel(adc_n, channel); - adc_ll_set_atten(adc_n, 0, atten); // Note: when disable all channel, HW auto select channel0 atten param. - } else { - adc_ll_rtc_enable_channel(adc_n, channel); - adc_ll_set_atten(adc_n, channel, atten); - } - - for (uint8_t rpt = 0 ; rpt < ADC_HAL_CAL_TIMES ; rpt ++) { - code_h = ADC_HAL_CAL_OFFSET_RANGE; - code_l = 0; - chk_code = (code_h + code_l) / 2; - adc_ll_set_calibration_param(adc_n, chk_code); - dout = adc_hal_read_self_cal(adc_n, channel); - while (code_h - code_l > 1) { - if (dout == 0) { - code_h = chk_code; - } else { - code_l = chk_code; - } - chk_code = (code_h + code_l) / 2; - adc_ll_set_calibration_param(adc_n, chk_code); - dout = adc_hal_read_self_cal(adc_n, channel); - if ((code_h - code_l == 1)) { - chk_code += 1; - adc_ll_set_calibration_param(adc_n, chk_code); - dout = adc_hal_read_self_cal(adc_n, channel); - } - } - code_list[rpt] = chk_code; - code_sum += chk_code; - } - code_l = code_list[0]; - code_h = code_list[0]; - for (uint8_t i = 0 ; i < ADC_HAL_CAL_TIMES ; i++) { - if (code_l > code_list[i]) { - code_l = code_list[i]; - } - if (code_h < code_list[i]) { - code_h = code_list[i]; - } - } - chk_code = code_h + code_l; - dout = ((code_sum - chk_code) % (ADC_HAL_CAL_TIMES - 2) < 4) - ? (code_sum - chk_code) / (ADC_HAL_CAL_TIMES - 2) - : (code_sum - chk_code) / (ADC_HAL_CAL_TIMES - 2) + 1; - - adc_ll_set_calibration_param(adc_n, dout); - adc_ll_calibration_finish(adc_n); - s_adc_cali_param[adc_n][atten] = (uint16_t)dout; - return dout; -} diff --git a/components/hal/esp32c3/include/hal/adc_hal.h b/components/hal/esp32c3/include/hal/adc_hal.h index 9055be8868..1e9e972c2f 100644 --- a/components/hal/esp32c3/include/hal/adc_hal.h +++ b/components/hal/esp32c3/include/hal/adc_hal.h @@ -226,21 +226,6 @@ void adc_hal_arbiter_config(adc_arbiter_t *config); ADC calibration setting ---------------------------------------------------------------*/ -/** - * Calibrate the ADC using internal connections. - * - * @note Different ADC units and different attenuation options use different calibration data (initial data). - * - * @param adc_n ADC index number. - * @param channel adc channel number. - * @param atten The attenuation for the channel - * @param internal_gnd true: Disconnect from the IO port and use the internal GND as the calibration voltage. - * false: Use IO external voltage as calibration voltage. - * - * @return - * - The calibration result (initial data) to ADC, use `adc_hal_set_calibration_param` to set. - */ -uint32_t adc_hal_self_calibration(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten, bool internal_gnd); /** * Set the calibration result (initial data) to ADC. diff --git a/components/hal/esp32c3/include/hal/adc_ll.h b/components/hal/esp32c3/include/hal/adc_ll.h index 9ccbc355c5..6212c5f631 100644 --- a/components/hal/esp32c3/include/hal/adc_ll.h +++ b/components/hal/esp32c3/include/hal/adc_ll.h @@ -15,12 +15,13 @@ #include #include +#include "regi2c_ctrl.h" +#include "esp_attr.h" + #include "soc/adc_periph.h" #include "hal/adc_types.h" #include "soc/apb_saradc_struct.h" #include "soc/apb_saradc_reg.h" -#include "soc/rtc_cntl_struct.h" -#include "esp_attr.h" #ifdef __cplusplus @@ -845,13 +846,13 @@ static inline void adc_ll_set_power_manage(adc_ll_power_t manage) // 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 = SENS_FORCE_XPD_SAR_PU; + APB_SARADC.ctrl.xpd_sar_force = 3; } else if (manage == ADC_POWER_BY_FSM) { APB_SARADC.ctrl.sar_clk_gated = 1; - APB_SARADC.ctrl.xpd_sar_force = SENS_FORCE_XPD_SAR_FSM; + APB_SARADC.ctrl.xpd_sar_force = 0; } else if (manage == ADC_POWER_SW_OFF) { - APB_SARADC.ctrl.xpd_sar_force = SENS_FORCE_XPD_SAR_PD; APB_SARADC.ctrl.sar_clk_gated = 1; + APB_SARADC.ctrl.xpd_sar_force = 2; } } @@ -891,64 +892,6 @@ static inline void adc_ll_set_sar_clk_div(adc_ll_num_t adc_n, uint32_t div) // } } -/** - * Set the attenuation of a particular channel on ADCn. - * - * @note For any given channel, this function must be called before the first time conversion. - * - * The default ADC full-scale voltage is 1.1V. To read higher voltages (up to the pin maximum voltage, - * usually 3.3V) requires setting >0dB signal attenuation for that ADC channel. - * - * When VDD_A is 3.3V: - * - * - 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.) - * - * @note At 11dB attenuation the maximum voltage is limited by VDD_A, not the full scale voltage. - * - * Due to ADC characteristics, most accurate results are obtained within the following approximate voltage ranges: - * - * - 0dB attenuaton (ADC_ATTEN_DB_0) between 100 and 950mV - * - 2.5dB attenuation (ADC_ATTEN_DB_2_5) between 100 and 1250mV - * - 6dB attenuation (ADC_ATTEN_DB_6) between 150 to 1750mV - * - 11dB attenuation (ADC_ATTEN_DB_11) between 150 to 2450mV - * - * For maximum accuracy, use the ADC calibration APIs and measure voltages within these recommended ranges. - * - * @param adc_n ADC unit. - * @param channel ADCn channel number. - * @param atten The attenuation option. - */ -static inline void adc_ll_set_atten(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten) -{ - // if (adc_n == ADC_NUM_1) { - // SENS.sar_atten1 = ( SENS.sar_atten1 & ~(0x3 << (channel * 2)) ) | ((atten & 0x3) << (channel * 2)); - // } else { // adc_n == ADC_NUM_2 - // SENS.sar_atten2 = ( SENS.sar_atten2 & ~(0x3 << (channel * 2)) ) | ((atten & 0x3) << (channel * 2)); - // } -} - -/** - * 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_ll_num_t adc_n, adc_channel_t channel) -{ - abort(); // FIXME - // if (adc_n == ADC_NUM_1) { - // return (adc_atten_t)((SENS.sar_atten1 >> (channel * 2)) & 0x3); - // } else { - // return (adc_atten_t)((SENS.sar_atten2 >> (channel * 2)) & 0x3); - // } -} /** * Set ADC module controller. @@ -1011,7 +954,6 @@ static inline void adc_ll_set_controller(adc_ll_num_t adc_n, adc_controller_t ct */ static inline void adc_ll_set_arbiter_work_mode(adc_arbiter_mode_t mode) { - SENS.sar_meas2_mux.sar2_rtc_force = 0; // Enable arbiter in wakeup mode if (mode == ADC_ARB_MODE_FIX) { APB_SARADC.apb_adc_arb_ctrl.adc_arb_grant_force = 0; APB_SARADC.apb_adc_arb_ctrl.adc_arb_fix_priority = 1; @@ -1096,102 +1038,6 @@ static inline void adc_ll_disable_sleep_controller(void) } /* ADC calibration code. */ -#include "soc/rtc_cntl_reg.h" -#include "regi2c_ctrl.h" - -#define I2C_ADC 0X69 -#define I2C_ADC_HOSTID 0 - -#define ANA_CONFIG2_REG 0x6000E048 -#define ANA_CONFIG2_M (BIT(18)) - -#define SAR1_ENCAL_GND_ADDR 0x7 -#define SAR1_ENCAL_GND_ADDR_MSB 5 -#define SAR1_ENCAL_GND_ADDR_LSB 5 - -#define SAR2_ENCAL_GND_ADDR 0x7 -#define SAR2_ENCAL_GND_ADDR_MSB 7 -#define SAR2_ENCAL_GND_ADDR_LSB 7 - -#define SAR1_INITIAL_CODE_HIGH_ADDR 0x1 -#define SAR1_INITIAL_CODE_HIGH_ADDR_MSB 0x3 -#define SAR1_INITIAL_CODE_HIGH_ADDR_LSB 0x0 - -#define SAR1_INITIAL_CODE_LOW_ADDR 0x0 -#define SAR1_INITIAL_CODE_LOW_ADDR_MSB 0x7 -#define SAR1_INITIAL_CODE_LOW_ADDR_LSB 0x0 - -#define SAR2_INITIAL_CODE_HIGH_ADDR 0x4 -#define SAR2_INITIAL_CODE_HIGH_ADDR_MSB 0x3 -#define SAR2_INITIAL_CODE_HIGH_ADDR_LSB 0x0 - -#define SAR2_INITIAL_CODE_LOW_ADDR 0x3 -#define SAR2_INITIAL_CODE_LOW_ADDR_MSB 0x7 -#define SAR2_INITIAL_CODE_LOW_ADDR_LSB 0x0 - -#define SAR1_DREF_ADDR 0x2 -#define SAR1_DREF_ADDR_MSB 0x6 -#define SAR1_DREF_ADDR_LSB 0x4 - -#define SAR2_DREF_ADDR 0x5 -#define SAR2_DREF_ADDR_MSB 0x6 -#define SAR2_DREF_ADDR_LSB 0x4 - -#define ADC_HAL_CAL_OFFSET_RANGE (4096) -#define ADC_HAL_CAL_TIMES (10) - -/** - * Configure the registers for ADC calibration. You need to call the ``adc_ll_calibration_finish`` interface to resume after calibration. - * - * @note Different ADC units and different attenuation options use different calibration data (initial data). - * - * @param adc_n ADC index number. - * @param channel adc channel number. - * @param internal_gnd true: Disconnect from the IO port and use the internal GND as the calibration voltage. - * false: Use IO external voltage as calibration voltage. - */ -static inline void adc_ll_calibration_prepare(adc_ll_num_t adc_n, adc_channel_t channel, bool internal_gnd) -{ - // /* Enable i2s_write_reg function. */ - // void phy_get_romfunc_addr(void); - // phy_get_romfunc_addr(); - // //CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PD_M); - // //SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M); - // CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18)); - // SET_PERI_REG_MASK(ANA_CONFIG2_REG, BIT(16)); - - // /* Enable/disable internal connect GND (for calibration). */ - // if (adc_n == ADC_NUM_1) { - // REGI2C_WRITE_MASK(I2C_ADC, SAR1_DREF_ADDR, 4); - // if (internal_gnd) { - // REGI2C_WRITE_MASK(I2C_ADC, SAR1_ENCAL_GND_ADDR, 1); - // } else { - // REGI2C_WRITE_MASK(I2C_ADC, SAR1_ENCAL_GND_ADDR, 0); - // } - // } else { - // REGI2C_WRITE_MASK(I2C_ADC, SAR2_DREF_ADDR, 4); - // if (internal_gnd) { - // REGI2C_WRITE_MASK(I2C_ADC, SAR2_ENCAL_GND_ADDR, 1); - // } else { - // REGI2C_WRITE_MASK(I2C_ADC, SAR2_ENCAL_GND_ADDR, 0); - // } - // } -} - -/** - * Resume register status after calibration. - * - * @param adc_n ADC index number. - */ -static inline void adc_ll_calibration_finish(adc_ll_num_t adc_n) -{ - // if (adc_n == ADC_NUM_1) { - // REGI2C_WRITE_MASK(I2C_ADC, SAR1_ENCAL_GND_ADDR, 0); - // } else { - // REGI2C_WRITE_MASK(I2C_ADC, SAR2_ENCAL_GND_ADDR, 0); - // } -} - /** * Set the calibration result to ADC. * @@ -1201,22 +1047,15 @@ static inline void adc_ll_calibration_finish(adc_ll_num_t adc_n) */ static inline void adc_ll_set_calibration_param(adc_ll_num_t adc_n, uint32_t param) { - // uint8_t msb = param >> 8; - // uint8_t lsb = param & 0xFF; - // /* Enable i2s_write_reg function. */ - // void phy_get_romfunc_addr(void); - // phy_get_romfunc_addr(); - // //SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M); - // CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18)); - // SET_PERI_REG_MASK(ANA_CONFIG2_REG, BIT(16)); - - // if (adc_n == ADC_NUM_1) { - // REGI2C_WRITE_MASK(I2C_ADC, SAR1_INITIAL_CODE_HIGH_ADDR, msb); - // REGI2C_WRITE_MASK(I2C_ADC, SAR1_INITIAL_CODE_LOW_ADDR, lsb); - // } else { - // REGI2C_WRITE_MASK(I2C_ADC, SAR2_INITIAL_CODE_HIGH_ADDR, msb); - // REGI2C_WRITE_MASK(I2C_ADC, SAR2_INITIAL_CODE_LOW_ADDR, lsb); - // } + uint8_t msb = param >> 8; + uint8_t lsb = param & 0xFF; + if (adc_n == ADC_NUM_1) { + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR1_INITIAL_CODE_HIGH_ADDR, msb); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR1_INITIAL_CODE_LOW_ADDR, lsb); + } else { + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR2_INITIAL_CODE_HIGH_ADDR, msb); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR2_INITIAL_CODE_LOW_ADDR, lsb); + } } /* Temp code end. */ diff --git a/components/hal/esp32s2/adc_hal.c b/components/hal/esp32s2/adc_hal.c index 68e8b98071..c244432d76 100644 --- a/components/hal/esp32s2/adc_hal.c +++ b/components/hal/esp32s2/adc_hal.c @@ -46,7 +46,7 @@ void adc_hal_digi_controller_config(const adc_digi_config_t *cfg) if (cfg->adc1_pattern_len) { adc_ll_digi_clear_pattern_table(ADC_NUM_1); adc_ll_digi_set_pattern_table_len(ADC_NUM_1, cfg->adc1_pattern_len); - for (uint32_t i = 0; i < cfg->adc1_pattern_len; i++) { + for (int i = 0; i < cfg->adc1_pattern_len; i++) { adc_ll_digi_set_pattern_table(ADC_NUM_1, i, cfg->adc1_pattern[i]); } } @@ -55,7 +55,7 @@ void adc_hal_digi_controller_config(const adc_digi_config_t *cfg) if (cfg->adc2_pattern_len) { adc_ll_digi_clear_pattern_table(ADC_NUM_2); adc_ll_digi_set_pattern_table_len(ADC_NUM_2, cfg->adc2_pattern_len); - for (uint32_t i = 0; i < cfg->adc2_pattern_len; i++) { + for (int i = 0; i < cfg->adc2_pattern_len; i++) { adc_ll_digi_set_pattern_table(ADC_NUM_2, i, cfg->adc2_pattern[i]); } } @@ -181,11 +181,11 @@ uint32_t adc_hal_self_calibration(adc_ll_num_t adc_n, adc_channel_t channel, adc adc_ll_set_atten(adc_n, channel, atten); } - uint32_t code_list[ADC_HAL_CAL_TIMES] = {0}; - uint32_t code_sum = 0; - uint32_t code_h = 0; - uint32_t code_l = 0; - uint32_t chk_code = 0; + uint32_t code_list[ADC_HAL_CAL_TIMES] = {0}; + uint32_t code_sum = 0; + uint32_t code_h = 0; + uint32_t code_l = 0; + uint32_t chk_code = 0; for (uint8_t rpt = 0 ; rpt < ADC_HAL_CAL_TIMES ; rpt ++) { code_h = ADC_HAL_CAL_OFFSET_RANGE; diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index 1b307ebb0a..9ec7679842 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -79,6 +79,7 @@ #define SOC_ADC_PATT_LEN_MAX (16) #define SOC_ADC_CHANNEL_NUM(PERIPH_NUM) ((PERIPH_NUM==0)? 8: 10) #define SOC_ADC_MAX_CHANNEL_NUM (10) +#define SOC_ADC_MAX_BITWIDTH (12) /** * Check if adc support digital controller (DMA) mode. @@ -87,6 +88,7 @@ * - 0 : not support; */ #define SOC_ADC_SUPPORT_DMA_MODE(PERIPH_NUM) ((PERIPH_NUM==0)? 1: 0) +#define SOC_ADC_SUPPORT_RTC_CTRL 1 /*-------------------------- BROWNOUT CAPS -----------------------------------*/ #if SOC_CAPS_ECO_VER >= 1 diff --git a/components/soc/esp32c3/include/soc/sens_reg.h b/components/soc/esp32c3/include/soc/sens_reg.h deleted file mode 100644 index 95420e84a2..0000000000 --- a/components/soc/esp32c3/include/soc/sens_reg.h +++ /dev/null @@ -1,1733 +0,0 @@ -// Copyright 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. -#ifndef _SOC_SENS_REG_H_ -#define _SOC_SENS_REG_H_ - - -#ifdef __cplusplus -extern "C" { -#endif -#include "soc.h" -#define SENS_SAR_READER1_CTRL_REG (DR_REG_SENS_BASE + 0x0000) -/* SENS_SAR1_INT_EN : R/W ;bitpos:[29] ;default: 1'b1 ; */ -/*description: enable saradc1 to send out interrupt*/ -#define SENS_SAR1_INT_EN (BIT(29)) -#define SENS_SAR1_INT_EN_M (BIT(29)) -#define SENS_SAR1_INT_EN_V 0x1 -#define SENS_SAR1_INT_EN_S 29 -/* SENS_SAR1_DATA_INV : R/W ;bitpos:[28] ;default: 1'd0 ; */ -/*description: Invert SAR ADC1 data*/ -#define SENS_SAR1_DATA_INV (BIT(28)) -#define SENS_SAR1_DATA_INV_M (BIT(28)) -#define SENS_SAR1_DATA_INV_V 0x1 -#define SENS_SAR1_DATA_INV_S 28 -/* SENS_SAR1_SAMPLE_NUM : R/W ;bitpos:[26:19] ;default: 8'd0 ; */ -/*description: */ -#define SENS_SAR1_SAMPLE_NUM 0x000000FF -#define SENS_SAR1_SAMPLE_NUM_M ((SENS_SAR1_SAMPLE_NUM_V)<<(SENS_SAR1_SAMPLE_NUM_S)) -#define SENS_SAR1_SAMPLE_NUM_V 0xFF -#define SENS_SAR1_SAMPLE_NUM_S 19 -/* SENS_SAR1_CLK_GATED : R/W ;bitpos:[18] ;default: 1'b1 ; */ -/*description: */ -#define SENS_SAR1_CLK_GATED (BIT(18)) -#define SENS_SAR1_CLK_GATED_M (BIT(18)) -#define SENS_SAR1_CLK_GATED_V 0x1 -#define SENS_SAR1_CLK_GATED_S 18 -/* SENS_SAR1_CLK_DIV : R/W ;bitpos:[7:0] ;default: 8'd2 ; */ -/*description: clock divider*/ -#define SENS_SAR1_CLK_DIV 0x000000FF -#define SENS_SAR1_CLK_DIV_M ((SENS_SAR1_CLK_DIV_V)<<(SENS_SAR1_CLK_DIV_S)) -#define SENS_SAR1_CLK_DIV_V 0xFF -#define SENS_SAR1_CLK_DIV_S 0 - -#define SENS_SAR_READER1_STATUS_REG (DR_REG_SENS_BASE + 0x0004) -/* SENS_SAR1_READER_STATUS : RO ;bitpos:[31:0] ;default: 32'h0 ; */ -/*description: */ -#define SENS_SAR1_READER_STATUS 0xFFFFFFFF -#define SENS_SAR1_READER_STATUS_M ((SENS_SAR1_READER_STATUS_V)<<(SENS_SAR1_READER_STATUS_S)) -#define SENS_SAR1_READER_STATUS_V 0xFFFFFFFF -#define SENS_SAR1_READER_STATUS_S 0 - -#define SENS_SAR_MEAS1_CTRL1_REG (DR_REG_SENS_BASE + 0x0008) -/* SENS_AMP_SHORT_REF_GND_FORCE : R/W ;bitpos:[31:30] ;default: 2'b0 ; */ -/*description: */ -#define SENS_AMP_SHORT_REF_GND_FORCE 0x00000003 -#define SENS_AMP_SHORT_REF_GND_FORCE_M ((SENS_AMP_SHORT_REF_GND_FORCE_V)<<(SENS_AMP_SHORT_REF_GND_FORCE_S)) -#define SENS_AMP_SHORT_REF_GND_FORCE_V 0x3 -#define SENS_AMP_SHORT_REF_GND_FORCE_S 30 -/* SENS_AMP_SHORT_REF_FORCE : R/W ;bitpos:[29:28] ;default: 2'b0 ; */ -/*description: */ -#define SENS_AMP_SHORT_REF_FORCE 0x00000003 -#define SENS_AMP_SHORT_REF_FORCE_M ((SENS_AMP_SHORT_REF_FORCE_V)<<(SENS_AMP_SHORT_REF_FORCE_S)) -#define SENS_AMP_SHORT_REF_FORCE_V 0x3 -#define SENS_AMP_SHORT_REF_FORCE_S 28 -/* SENS_AMP_RST_FB_FORCE : R/W ;bitpos:[27:26] ;default: 2'b0 ; */ -/*description: */ -#define SENS_AMP_RST_FB_FORCE 0x00000003 -#define SENS_AMP_RST_FB_FORCE_M ((SENS_AMP_RST_FB_FORCE_V)<<(SENS_AMP_RST_FB_FORCE_S)) -#define SENS_AMP_RST_FB_FORCE_V 0x3 -#define SENS_AMP_RST_FB_FORCE_S 26 -/* SENS_FORCE_XPD_AMP : R/W ;bitpos:[25:24] ;default: 2'd0 ; */ -/*description: */ -#define SENS_FORCE_XPD_AMP 0x00000003 -#define SENS_FORCE_XPD_AMP_M ((SENS_FORCE_XPD_AMP_V)<<(SENS_FORCE_XPD_AMP_S)) -#define SENS_FORCE_XPD_AMP_V 0x3 -#define SENS_FORCE_XPD_AMP_S 24 -#define SENS_FORCE_XPD_AMP_FSM 0 // Use FSM to control power down -#define SENS_FORCE_XPD_AMP_PD 2 // Force power down -#define SENS_FORCE_XPD_AMP_PU 3 // Force power up - -#define SENS_SAR_MEAS1_CTRL2_REG (DR_REG_SENS_BASE + 0x000c) -/* SENS_SAR1_EN_PAD_FORCE : R/W ;bitpos:[31] ;default: 1'b0 ; */ -/*description: 1: SAR ADC1 pad enable bitmap is controlled by SW*/ -#define SENS_SAR1_EN_PAD_FORCE (BIT(31)) -#define SENS_SAR1_EN_PAD_FORCE_M (BIT(31)) -#define SENS_SAR1_EN_PAD_FORCE_V 0x1 -#define SENS_SAR1_EN_PAD_FORCE_S 31 -/* SENS_SAR1_EN_PAD : R/W ;bitpos:[30:19] ;default: 12'b0 ; */ -/*description: SAR ADC1 pad enable bitmap*/ -#define SENS_SAR1_EN_PAD 0x00000FFF -#define SENS_SAR1_EN_PAD_M ((SENS_SAR1_EN_PAD_V)<<(SENS_SAR1_EN_PAD_S)) -#define SENS_SAR1_EN_PAD_V 0xFFF -#define SENS_SAR1_EN_PAD_S 19 -/* SENS_MEAS1_START_FORCE : R/W ;bitpos:[18] ;default: 1'b0 ; */ -/*description: 1: SAR ADC1 controller (in RTC) is started by SW*/ -#define SENS_MEAS1_START_FORCE (BIT(18)) -#define SENS_MEAS1_START_FORCE_M (BIT(18)) -#define SENS_MEAS1_START_FORCE_V 0x1 -#define SENS_MEAS1_START_FORCE_S 18 -/* SENS_MEAS1_START_SAR : R/W ;bitpos:[17] ;default: 1'b0 ; */ -/*description: SAR ADC1 controller (in RTC) starts conversion*/ -#define SENS_MEAS1_START_SAR (BIT(17)) -#define SENS_MEAS1_START_SAR_M (BIT(17)) -#define SENS_MEAS1_START_SAR_V 0x1 -#define SENS_MEAS1_START_SAR_S 17 -/* SENS_MEAS1_DONE_SAR : RO ;bitpos:[16] ;default: 1'b0 ; */ -/*description: SAR ADC1 conversion done indication*/ -#define SENS_MEAS1_DONE_SAR (BIT(16)) -#define SENS_MEAS1_DONE_SAR_M (BIT(16)) -#define SENS_MEAS1_DONE_SAR_V 0x1 -#define SENS_MEAS1_DONE_SAR_S 16 -/* SENS_MEAS1_DATA_SAR : RO ;bitpos:[15:0] ;default: 16'b0 ; */ -/*description: SAR ADC1 data*/ -#define SENS_MEAS1_DATA_SAR 0x0000FFFF -#define SENS_MEAS1_DATA_SAR_M ((SENS_MEAS1_DATA_SAR_V)<<(SENS_MEAS1_DATA_SAR_S)) -#define SENS_MEAS1_DATA_SAR_V 0xFFFF -#define SENS_MEAS1_DATA_SAR_S 0 - -#define SENS_SAR_MEAS1_MUX_REG (DR_REG_SENS_BASE + 0x0010) -/* SENS_SAR1_DIG_FORCE : R/W ;bitpos:[31] ;default: 1'd0 ; */ -/*description: 1: SAR ADC1 controlled by DIG ADC1 CTRL*/ -#define SENS_SAR1_DIG_FORCE (BIT(31)) -#define SENS_SAR1_DIG_FORCE_M (BIT(31)) -#define SENS_SAR1_DIG_FORCE_V 0x1 -#define SENS_SAR1_DIG_FORCE_S 31 - -#define SENS_SAR_ATTEN1_REG (DR_REG_SENS_BASE + 0x0014) -/* SENS_SAR1_ATTEN : R/W ;bitpos:[31:0] ;default: 32'hffffffff ; */ -/*description: 2-bit attenuation for each pad*/ -#define SENS_SAR1_ATTEN 0xFFFFFFFF -#define SENS_SAR1_ATTEN_M ((SENS_SAR1_ATTEN_V)<<(SENS_SAR1_ATTEN_S)) -#define SENS_SAR1_ATTEN_V 0xFFFFFFFF -#define SENS_SAR1_ATTEN_S 0 - -#define SENS_SAR_AMP_CTRL1_REG (DR_REG_SENS_BASE + 0x0018) -/* SENS_SAR_AMP_WAIT2 : R/W ;bitpos:[31:16] ;default: 16'd10 ; */ -/*description: */ -#define SENS_SAR_AMP_WAIT2 0x0000FFFF -#define SENS_SAR_AMP_WAIT2_M ((SENS_SAR_AMP_WAIT2_V)<<(SENS_SAR_AMP_WAIT2_S)) -#define SENS_SAR_AMP_WAIT2_V 0xFFFF -#define SENS_SAR_AMP_WAIT2_S 16 -/* SENS_SAR_AMP_WAIT1 : R/W ;bitpos:[15:0] ;default: 16'd10 ; */ -/*description: */ -#define SENS_SAR_AMP_WAIT1 0x0000FFFF -#define SENS_SAR_AMP_WAIT1_M ((SENS_SAR_AMP_WAIT1_V)<<(SENS_SAR_AMP_WAIT1_S)) -#define SENS_SAR_AMP_WAIT1_V 0xFFFF -#define SENS_SAR_AMP_WAIT1_S 0 - -#define SENS_SAR_AMP_CTRL2_REG (DR_REG_SENS_BASE + 0x001c) -/* SENS_SAR_AMP_WAIT3 : R/W ;bitpos:[31:16] ;default: 16'd10 ; */ -/*description: */ -#define SENS_SAR_AMP_WAIT3 0x0000FFFF -#define SENS_SAR_AMP_WAIT3_M ((SENS_SAR_AMP_WAIT3_V)<<(SENS_SAR_AMP_WAIT3_S)) -#define SENS_SAR_AMP_WAIT3_V 0xFFFF -#define SENS_SAR_AMP_WAIT3_S 16 -/* SENS_SAR_RSTB_FSM_IDLE : R/W ;bitpos:[6] ;default: 1'b0 ; */ -/*description: */ -#define SENS_SAR_RSTB_FSM_IDLE (BIT(6)) -#define SENS_SAR_RSTB_FSM_IDLE_M (BIT(6)) -#define SENS_SAR_RSTB_FSM_IDLE_V 0x1 -#define SENS_SAR_RSTB_FSM_IDLE_S 6 -/* SENS_XPD_SAR_FSM_IDLE : R/W ;bitpos:[5] ;default: 1'b0 ; */ -/*description: */ -#define SENS_XPD_SAR_FSM_IDLE (BIT(5)) -#define SENS_XPD_SAR_FSM_IDLE_M (BIT(5)) -#define SENS_XPD_SAR_FSM_IDLE_V 0x1 -#define SENS_XPD_SAR_FSM_IDLE_S 5 -/* SENS_AMP_SHORT_REF_GND_FSM_IDLE : R/W ;bitpos:[4] ;default: 1'b0 ; */ -/*description: */ -#define SENS_AMP_SHORT_REF_GND_FSM_IDLE (BIT(4)) -#define SENS_AMP_SHORT_REF_GND_FSM_IDLE_M (BIT(4)) -#define SENS_AMP_SHORT_REF_GND_FSM_IDLE_V 0x1 -#define SENS_AMP_SHORT_REF_GND_FSM_IDLE_S 4 -/* SENS_AMP_SHORT_REF_FSM_IDLE : R/W ;bitpos:[3] ;default: 1'b0 ; */ -/*description: */ -#define SENS_AMP_SHORT_REF_FSM_IDLE (BIT(3)) -#define SENS_AMP_SHORT_REF_FSM_IDLE_M (BIT(3)) -#define SENS_AMP_SHORT_REF_FSM_IDLE_V 0x1 -#define SENS_AMP_SHORT_REF_FSM_IDLE_S 3 -/* SENS_AMP_RST_FB_FSM_IDLE : R/W ;bitpos:[2] ;default: 1'b0 ; */ -/*description: */ -#define SENS_AMP_RST_FB_FSM_IDLE (BIT(2)) -#define SENS_AMP_RST_FB_FSM_IDLE_M (BIT(2)) -#define SENS_AMP_RST_FB_FSM_IDLE_V 0x1 -#define SENS_AMP_RST_FB_FSM_IDLE_S 2 -/* SENS_XPD_SAR_AMP_FSM_IDLE : R/W ;bitpos:[1] ;default: 1'b0 ; */ -/*description: */ -#define SENS_XPD_SAR_AMP_FSM_IDLE (BIT(1)) -#define SENS_XPD_SAR_AMP_FSM_IDLE_M (BIT(1)) -#define SENS_XPD_SAR_AMP_FSM_IDLE_V 0x1 -#define SENS_XPD_SAR_AMP_FSM_IDLE_S 1 -/* SENS_SAR1_DAC_XPD_FSM_IDLE : R/W ;bitpos:[0] ;default: 1'b0 ; */ -/*description: */ -#define SENS_SAR1_DAC_XPD_FSM_IDLE (BIT(0)) -#define SENS_SAR1_DAC_XPD_FSM_IDLE_M (BIT(0)) -#define SENS_SAR1_DAC_XPD_FSM_IDLE_V 0x1 -#define SENS_SAR1_DAC_XPD_FSM_IDLE_S 0 - -#define SENS_SAR_AMP_CTRL3_REG (DR_REG_SENS_BASE + 0x0020) -/* SENS_SAR_RSTB_FSM : R/W ;bitpos:[27:24] ;default: 4'b0000 ; */ -/*description: */ -#define SENS_SAR_RSTB_FSM 0x0000000F -#define SENS_SAR_RSTB_FSM_M ((SENS_SAR_RSTB_FSM_V)<<(SENS_SAR_RSTB_FSM_S)) -#define SENS_SAR_RSTB_FSM_V 0xF -#define SENS_SAR_RSTB_FSM_S 24 -/* SENS_XPD_SAR_FSM : R/W ;bitpos:[23:20] ;default: 4'b0111 ; */ -/*description: */ -#define SENS_XPD_SAR_FSM 0x0000000F -#define SENS_XPD_SAR_FSM_M ((SENS_XPD_SAR_FSM_V)<<(SENS_XPD_SAR_FSM_S)) -#define SENS_XPD_SAR_FSM_V 0xF -#define SENS_XPD_SAR_FSM_S 20 -/* SENS_AMP_SHORT_REF_GND_FSM : R/W ;bitpos:[19:16] ;default: 4'b0011 ; */ -/*description: */ -#define SENS_AMP_SHORT_REF_GND_FSM 0x0000000F -#define SENS_AMP_SHORT_REF_GND_FSM_M ((SENS_AMP_SHORT_REF_GND_FSM_V)<<(SENS_AMP_SHORT_REF_GND_FSM_S)) -#define SENS_AMP_SHORT_REF_GND_FSM_V 0xF -#define SENS_AMP_SHORT_REF_GND_FSM_S 16 -/* SENS_AMP_SHORT_REF_FSM : R/W ;bitpos:[15:12] ;default: 4'b0011 ; */ -/*description: */ -#define SENS_AMP_SHORT_REF_FSM 0x0000000F -#define SENS_AMP_SHORT_REF_FSM_M ((SENS_AMP_SHORT_REF_FSM_V)<<(SENS_AMP_SHORT_REF_FSM_S)) -#define SENS_AMP_SHORT_REF_FSM_V 0xF -#define SENS_AMP_SHORT_REF_FSM_S 12 -/* SENS_AMP_RST_FB_FSM : R/W ;bitpos:[11:8] ;default: 4'b1000 ; */ -/*description: */ -#define SENS_AMP_RST_FB_FSM 0x0000000F -#define SENS_AMP_RST_FB_FSM_M ((SENS_AMP_RST_FB_FSM_V)<<(SENS_AMP_RST_FB_FSM_S)) -#define SENS_AMP_RST_FB_FSM_V 0xF -#define SENS_AMP_RST_FB_FSM_S 8 -/* SENS_XPD_SAR_AMP_FSM : R/W ;bitpos:[7:4] ;default: 4'b1111 ; */ -/*description: */ -#define SENS_XPD_SAR_AMP_FSM 0x0000000F -#define SENS_XPD_SAR_AMP_FSM_M ((SENS_XPD_SAR_AMP_FSM_V)<<(SENS_XPD_SAR_AMP_FSM_S)) -#define SENS_XPD_SAR_AMP_FSM_V 0xF -#define SENS_XPD_SAR_AMP_FSM_S 4 -/* SENS_SAR1_DAC_XPD_FSM : R/W ;bitpos:[3:0] ;default: 4'b0011 ; */ -/*description: */ -#define SENS_SAR1_DAC_XPD_FSM 0x0000000F -#define SENS_SAR1_DAC_XPD_FSM_M ((SENS_SAR1_DAC_XPD_FSM_V)<<(SENS_SAR1_DAC_XPD_FSM_S)) -#define SENS_SAR1_DAC_XPD_FSM_V 0xF -#define SENS_SAR1_DAC_XPD_FSM_S 0 - -#define SENS_SAR_READER2_CTRL_REG (DR_REG_SENS_BASE + 0x0024) -/* SENS_SAR2_INT_EN : R/W ;bitpos:[30] ;default: 1'b1 ; */ -/*description: enable saradc2 to send out interrupt*/ -#define SENS_SAR2_INT_EN (BIT(30)) -#define SENS_SAR2_INT_EN_M (BIT(30)) -#define SENS_SAR2_INT_EN_V 0x1 -#define SENS_SAR2_INT_EN_S 30 -/* SENS_SAR2_DATA_INV : R/W ;bitpos:[29] ;default: 1'b0 ; */ -/*description: Invert SAR ADC2 data*/ -#define SENS_SAR2_DATA_INV (BIT(29)) -#define SENS_SAR2_DATA_INV_M (BIT(29)) -#define SENS_SAR2_DATA_INV_V 0x1 -#define SENS_SAR2_DATA_INV_S 29 -/* SENS_SAR2_SAMPLE_NUM : R/W ;bitpos:[26:19] ;default: 8'd0 ; */ -/*description: */ -#define SENS_SAR2_SAMPLE_NUM 0x000000FF -#define SENS_SAR2_SAMPLE_NUM_M ((SENS_SAR2_SAMPLE_NUM_V)<<(SENS_SAR2_SAMPLE_NUM_S)) -#define SENS_SAR2_SAMPLE_NUM_V 0xFF -#define SENS_SAR2_SAMPLE_NUM_S 19 -/* SENS_SAR2_CLK_GATED : R/W ;bitpos:[18] ;default: 1'b1 ; */ -/*description: */ -#define SENS_SAR2_CLK_GATED (BIT(18)) -#define SENS_SAR2_CLK_GATED_M (BIT(18)) -#define SENS_SAR2_CLK_GATED_V 0x1 -#define SENS_SAR2_CLK_GATED_S 18 -/* SENS_SAR2_WAIT_ARB_CYCLE : R/W ;bitpos:[17:16] ;default: 2'b1 ; */ -/*description: wait arbit stable after sar_done*/ -#define SENS_SAR2_WAIT_ARB_CYCLE 0x00000003 -#define SENS_SAR2_WAIT_ARB_CYCLE_M ((SENS_SAR2_WAIT_ARB_CYCLE_V)<<(SENS_SAR2_WAIT_ARB_CYCLE_S)) -#define SENS_SAR2_WAIT_ARB_CYCLE_V 0x3 -#define SENS_SAR2_WAIT_ARB_CYCLE_S 16 -/* SENS_SAR2_CLK_DIV : R/W ;bitpos:[7:0] ;default: 8'd2 ; */ -/*description: clock divider*/ -#define SENS_SAR2_CLK_DIV 0x000000FF -#define SENS_SAR2_CLK_DIV_M ((SENS_SAR2_CLK_DIV_V)<<(SENS_SAR2_CLK_DIV_S)) -#define SENS_SAR2_CLK_DIV_V 0xFF -#define SENS_SAR2_CLK_DIV_S 0 - -#define SENS_SAR_READER2_STATUS_REG (DR_REG_SENS_BASE + 0x0028) -/* SENS_SAR2_READER_STATUS : RO ;bitpos:[31:0] ;default: 32'h0 ; */ -/*description: */ -#define SENS_SAR2_READER_STATUS 0xFFFFFFFF -#define SENS_SAR2_READER_STATUS_M ((SENS_SAR2_READER_STATUS_V)<<(SENS_SAR2_READER_STATUS_S)) -#define SENS_SAR2_READER_STATUS_V 0xFFFFFFFF -#define SENS_SAR2_READER_STATUS_S 0 - -#define SENS_SAR_MEAS2_CTRL1_REG (DR_REG_SENS_BASE + 0x002c) -/* SENS_SAR2_XPD_WAIT : R/W ;bitpos:[31:24] ;default: 8'h7 ; */ -/*description: */ -#define SENS_SAR2_XPD_WAIT 0x000000FF -#define SENS_SAR2_XPD_WAIT_M ((SENS_SAR2_XPD_WAIT_V)<<(SENS_SAR2_XPD_WAIT_S)) -#define SENS_SAR2_XPD_WAIT_V 0xFF -#define SENS_SAR2_XPD_WAIT_S 24 -/* SENS_SAR2_RSTB_WAIT : R/W ;bitpos:[23:16] ;default: 8'd2 ; */ -/*description: */ -#define SENS_SAR2_RSTB_WAIT 0x000000FF -#define SENS_SAR2_RSTB_WAIT_M ((SENS_SAR2_RSTB_WAIT_V)<<(SENS_SAR2_RSTB_WAIT_S)) -#define SENS_SAR2_RSTB_WAIT_V 0xFF -#define SENS_SAR2_RSTB_WAIT_S 16 -/* SENS_SAR2_STANDBY_WAIT : R/W ;bitpos:[15:8] ;default: 8'd2 ; */ -/*description: */ -#define SENS_SAR2_STANDBY_WAIT 0x000000FF -#define SENS_SAR2_STANDBY_WAIT_M ((SENS_SAR2_STANDBY_WAIT_V)<<(SENS_SAR2_STANDBY_WAIT_S)) -#define SENS_SAR2_STANDBY_WAIT_V 0xFF -#define SENS_SAR2_STANDBY_WAIT_S 8 -/* SENS_SAR2_RSTB_FORCE : R/W ;bitpos:[7:6] ;default: 2'b0 ; */ -/*description: */ -#define SENS_SAR2_RSTB_FORCE 0x00000003 -#define SENS_SAR2_RSTB_FORCE_M ((SENS_SAR2_RSTB_FORCE_V)<<(SENS_SAR2_RSTB_FORCE_S)) -#define SENS_SAR2_RSTB_FORCE_V 0x3 -#define SENS_SAR2_RSTB_FORCE_S 6 -/* SENS_SAR2_EN_TEST : R/W ;bitpos:[5] ;default: 1'b0 ; */ -/*description: SAR2_EN_TEST*/ -#define SENS_SAR2_EN_TEST (BIT(5)) -#define SENS_SAR2_EN_TEST_M (BIT(5)) -#define SENS_SAR2_EN_TEST_V 0x1 -#define SENS_SAR2_EN_TEST_S 5 -/* SENS_SAR2_PKDET_CAL_EN : R/W ;bitpos:[4] ;default: 1'b0 ; */ -/*description: rtc control pkdet enable*/ -#define SENS_SAR2_PKDET_CAL_EN (BIT(4)) -#define SENS_SAR2_PKDET_CAL_EN_M (BIT(4)) -#define SENS_SAR2_PKDET_CAL_EN_V 0x1 -#define SENS_SAR2_PKDET_CAL_EN_S 4 -/* SENS_SAR2_PWDET_CAL_EN : R/W ;bitpos:[3] ;default: 1'b0 ; */ -/*description: rtc control pwdet enable*/ -#define SENS_SAR2_PWDET_CAL_EN (BIT(3)) -#define SENS_SAR2_PWDET_CAL_EN_M (BIT(3)) -#define SENS_SAR2_PWDET_CAL_EN_V 0x1 -#define SENS_SAR2_PWDET_CAL_EN_S 3 -/* SENS_SAR2_CNTL_STATE : RO ;bitpos:[2:0] ;default: 3'b0 ; */ -/*description: saradc2_cntl_fsm*/ -#define SENS_SAR2_CNTL_STATE 0x00000007 -#define SENS_SAR2_CNTL_STATE_M ((SENS_SAR2_CNTL_STATE_V)<<(SENS_SAR2_CNTL_STATE_S)) -#define SENS_SAR2_CNTL_STATE_V 0x7 -#define SENS_SAR2_CNTL_STATE_S 0 - -#define SENS_SAR_MEAS2_CTRL2_REG (DR_REG_SENS_BASE + 0x0030) -/* SENS_SAR2_EN_PAD_FORCE : R/W ;bitpos:[31] ;default: 1'b0 ; */ -/*description: 1: SAR ADC2 pad enable bitmap is controlled by SW*/ -#define SENS_SAR2_EN_PAD_FORCE (BIT(31)) -#define SENS_SAR2_EN_PAD_FORCE_M (BIT(31)) -#define SENS_SAR2_EN_PAD_FORCE_V 0x1 -#define SENS_SAR2_EN_PAD_FORCE_S 31 -/* SENS_SAR2_EN_PAD : R/W ;bitpos:[30:19] ;default: 12'b0 ; */ -/*description: SAR ADC2 pad enable bitmap*/ -#define SENS_SAR2_EN_PAD 0x00000FFF -#define SENS_SAR2_EN_PAD_M ((SENS_SAR2_EN_PAD_V)<<(SENS_SAR2_EN_PAD_S)) -#define SENS_SAR2_EN_PAD_V 0xFFF -#define SENS_SAR2_EN_PAD_S 19 -/* SENS_MEAS2_START_FORCE : R/W ;bitpos:[18] ;default: 1'b0 ; */ -/*description: 1: SAR ADC2 controller (in RTC) is started by SW*/ -#define SENS_MEAS2_START_FORCE (BIT(18)) -#define SENS_MEAS2_START_FORCE_M (BIT(18)) -#define SENS_MEAS2_START_FORCE_V 0x1 -#define SENS_MEAS2_START_FORCE_S 18 -/* SENS_MEAS2_START_SAR : R/W ;bitpos:[17] ;default: 1'b0 ; */ -/*description: SAR ADC2 controller (in RTC) starts conversion*/ -#define SENS_MEAS2_START_SAR (BIT(17)) -#define SENS_MEAS2_START_SAR_M (BIT(17)) -#define SENS_MEAS2_START_SAR_V 0x1 -#define SENS_MEAS2_START_SAR_S 17 -/* SENS_MEAS2_DONE_SAR : RO ;bitpos:[16] ;default: 1'b0 ; */ -/*description: SAR ADC2 conversion done indication*/ -#define SENS_MEAS2_DONE_SAR (BIT(16)) -#define SENS_MEAS2_DONE_SAR_M (BIT(16)) -#define SENS_MEAS2_DONE_SAR_V 0x1 -#define SENS_MEAS2_DONE_SAR_S 16 -/* SENS_MEAS2_DATA_SAR : RO ;bitpos:[15:0] ;default: 16'b0 ; */ -/*description: SAR ADC2 data*/ -#define SENS_MEAS2_DATA_SAR 0x0000FFFF -#define SENS_MEAS2_DATA_SAR_M ((SENS_MEAS2_DATA_SAR_V)<<(SENS_MEAS2_DATA_SAR_S)) -#define SENS_MEAS2_DATA_SAR_V 0xFFFF -#define SENS_MEAS2_DATA_SAR_S 0 - -#define SENS_SAR_MEAS2_MUX_REG (DR_REG_SENS_BASE + 0x0034) -/* SENS_SAR2_RTC_FORCE : R/W ;bitpos:[31] ;default: 1'b0 ; */ -/*description: in sleep force to use rtc to control ADC*/ -#define SENS_SAR2_RTC_FORCE (BIT(31)) -#define SENS_SAR2_RTC_FORCE_M (BIT(31)) -#define SENS_SAR2_RTC_FORCE_V 0x1 -#define SENS_SAR2_RTC_FORCE_S 31 -/* SENS_SAR2_PWDET_CCT : R/W ;bitpos:[30:28] ;default: 3'b0 ; */ -/*description: SAR2_PWDET_CCT*/ -#define SENS_SAR2_PWDET_CCT 0x00000007 -#define SENS_SAR2_PWDET_CCT_M ((SENS_SAR2_PWDET_CCT_V)<<(SENS_SAR2_PWDET_CCT_S)) -#define SENS_SAR2_PWDET_CCT_V 0x7 -#define SENS_SAR2_PWDET_CCT_S 28 - -#define SENS_SAR_ATTEN2_REG (DR_REG_SENS_BASE + 0x0038) -/* SENS_SAR2_ATTEN : R/W ;bitpos:[31:0] ;default: 32'hffffffff ; */ -/*description: 2-bit attenuation for each pad*/ -#define SENS_SAR2_ATTEN 0xFFFFFFFF -#define SENS_SAR2_ATTEN_M ((SENS_SAR2_ATTEN_V)<<(SENS_SAR2_ATTEN_S)) -#define SENS_SAR2_ATTEN_V 0xFFFFFFFF -#define SENS_SAR2_ATTEN_S 0 - -#define SENS_SAR_POWER_XPD_SAR_REG (DR_REG_SENS_BASE + 0x003c) -/* SENS_SARCLK_EN : R/W ;bitpos:[31] ;default: 1'b0 ; */ -/*description: */ -#define SENS_SARCLK_EN (BIT(31)) -#define SENS_SARCLK_EN_M (BIT(31)) -#define SENS_SARCLK_EN_V 0x1 -#define SENS_SARCLK_EN_S 31 -/* SENS_FORCE_XPD_SAR : R/W ;bitpos:[30:29] ;default: 2'd0 ; */ -/*description: */ -#define SENS_FORCE_XPD_SAR 0x00000003 -#define SENS_FORCE_XPD_SAR_M ((SENS_FORCE_XPD_SAR_V)<<(SENS_FORCE_XPD_SAR_S)) -#define SENS_FORCE_XPD_SAR_V 0x3 -#define SENS_FORCE_XPD_SAR_S 29 - -#define SENS_SAR_SLAVE_ADDR1_REG (DR_REG_SENS_BASE + 0x0040) -/* SENS_MEAS_STATUS : RO ;bitpos:[29:22] ;default: 8'h0 ; */ -/*description: */ -#define SENS_MEAS_STATUS 0x000000FF -#define SENS_MEAS_STATUS_M ((SENS_MEAS_STATUS_V)<<(SENS_MEAS_STATUS_S)) -#define SENS_MEAS_STATUS_V 0xFF -#define SENS_MEAS_STATUS_S 22 -/* SENS_I2C_SLAVE_ADDR0 : R/W ;bitpos:[21:11] ;default: 11'h0 ; */ -/*description: */ -#define SENS_I2C_SLAVE_ADDR0 0x000007FF -#define SENS_I2C_SLAVE_ADDR0_M ((SENS_I2C_SLAVE_ADDR0_V)<<(SENS_I2C_SLAVE_ADDR0_S)) -#define SENS_I2C_SLAVE_ADDR0_V 0x7FF -#define SENS_I2C_SLAVE_ADDR0_S 11 -/* SENS_I2C_SLAVE_ADDR1 : R/W ;bitpos:[10:0] ;default: 11'h0 ; */ -/*description: */ -#define SENS_I2C_SLAVE_ADDR1 0x000007FF -#define SENS_I2C_SLAVE_ADDR1_M ((SENS_I2C_SLAVE_ADDR1_V)<<(SENS_I2C_SLAVE_ADDR1_S)) -#define SENS_I2C_SLAVE_ADDR1_V 0x7FF -#define SENS_I2C_SLAVE_ADDR1_S 0 - -#define SENS_SAR_SLAVE_ADDR2_REG (DR_REG_SENS_BASE + 0x0044) -/* SENS_I2C_SLAVE_ADDR2 : R/W ;bitpos:[21:11] ;default: 11'h0 ; */ -/*description: */ -#define SENS_I2C_SLAVE_ADDR2 0x000007FF -#define SENS_I2C_SLAVE_ADDR2_M ((SENS_I2C_SLAVE_ADDR2_V)<<(SENS_I2C_SLAVE_ADDR2_S)) -#define SENS_I2C_SLAVE_ADDR2_V 0x7FF -#define SENS_I2C_SLAVE_ADDR2_S 11 -/* SENS_I2C_SLAVE_ADDR3 : R/W ;bitpos:[10:0] ;default: 11'h0 ; */ -/*description: */ -#define SENS_I2C_SLAVE_ADDR3 0x000007FF -#define SENS_I2C_SLAVE_ADDR3_M ((SENS_I2C_SLAVE_ADDR3_V)<<(SENS_I2C_SLAVE_ADDR3_S)) -#define SENS_I2C_SLAVE_ADDR3_V 0x7FF -#define SENS_I2C_SLAVE_ADDR3_S 0 - -#define SENS_SAR_SLAVE_ADDR3_REG (DR_REG_SENS_BASE + 0x0048) -/* SENS_I2C_SLAVE_ADDR4 : R/W ;bitpos:[21:11] ;default: 11'h0 ; */ -/*description: */ -#define SENS_I2C_SLAVE_ADDR4 0x000007FF -#define SENS_I2C_SLAVE_ADDR4_M ((SENS_I2C_SLAVE_ADDR4_V)<<(SENS_I2C_SLAVE_ADDR4_S)) -#define SENS_I2C_SLAVE_ADDR4_V 0x7FF -#define SENS_I2C_SLAVE_ADDR4_S 11 -/* SENS_I2C_SLAVE_ADDR5 : R/W ;bitpos:[10:0] ;default: 11'h0 ; */ -/*description: */ -#define SENS_I2C_SLAVE_ADDR5 0x000007FF -#define SENS_I2C_SLAVE_ADDR5_M ((SENS_I2C_SLAVE_ADDR5_V)<<(SENS_I2C_SLAVE_ADDR5_S)) -#define SENS_I2C_SLAVE_ADDR5_V 0x7FF -#define SENS_I2C_SLAVE_ADDR5_S 0 - -#define SENS_SAR_SLAVE_ADDR4_REG (DR_REG_SENS_BASE + 0x004c) -/* SENS_I2C_SLAVE_ADDR6 : R/W ;bitpos:[21:11] ;default: 11'h0 ; */ -/*description: */ -#define SENS_I2C_SLAVE_ADDR6 0x000007FF -#define SENS_I2C_SLAVE_ADDR6_M ((SENS_I2C_SLAVE_ADDR6_V)<<(SENS_I2C_SLAVE_ADDR6_S)) -#define SENS_I2C_SLAVE_ADDR6_V 0x7FF -#define SENS_I2C_SLAVE_ADDR6_S 11 -/* SENS_I2C_SLAVE_ADDR7 : R/W ;bitpos:[10:0] ;default: 11'h0 ; */ -/*description: */ -#define SENS_I2C_SLAVE_ADDR7 0x000007FF -#define SENS_I2C_SLAVE_ADDR7_M ((SENS_I2C_SLAVE_ADDR7_V)<<(SENS_I2C_SLAVE_ADDR7_S)) -#define SENS_I2C_SLAVE_ADDR7_V 0x7FF -#define SENS_I2C_SLAVE_ADDR7_S 0 - -#define SENS_SAR_TSENS_CTRL_REG (DR_REG_SENS_BASE + 0x0050) -/* SENS_TSENS_DUMP_OUT : R/W ;bitpos:[24] ;default: 1'b0 ; */ -/*description: temperature sensor dump out*/ -#define SENS_TSENS_DUMP_OUT (BIT(24)) -#define SENS_TSENS_DUMP_OUT_M (BIT(24)) -#define SENS_TSENS_DUMP_OUT_V 0x1 -#define SENS_TSENS_DUMP_OUT_S 24 -/* SENS_TSENS_POWER_UP_FORCE : R/W ;bitpos:[23] ;default: 1'b0 ; */ -/*description: 1: dump out & power up controlled by SW*/ -#define SENS_TSENS_POWER_UP_FORCE (BIT(23)) -#define SENS_TSENS_POWER_UP_FORCE_M (BIT(23)) -#define SENS_TSENS_POWER_UP_FORCE_V 0x1 -#define SENS_TSENS_POWER_UP_FORCE_S 23 -/* SENS_TSENS_POWER_UP : R/W ;bitpos:[22] ;default: 1'b0 ; */ -/*description: temperature sensor power up*/ -#define SENS_TSENS_POWER_UP (BIT(22)) -#define SENS_TSENS_POWER_UP_M (BIT(22)) -#define SENS_TSENS_POWER_UP_V 0x1 -#define SENS_TSENS_POWER_UP_S 22 -/* SENS_TSENS_CLK_DIV : R/W ;bitpos:[21:14] ;default: 8'd6 ; */ -/*description: temperature sensor clock divider*/ -#define SENS_TSENS_CLK_DIV 0x000000FF -#define SENS_TSENS_CLK_DIV_M ((SENS_TSENS_CLK_DIV_V)<<(SENS_TSENS_CLK_DIV_S)) -#define SENS_TSENS_CLK_DIV_V 0xFF -#define SENS_TSENS_CLK_DIV_S 14 -/* SENS_TSENS_IN_INV : R/W ;bitpos:[13] ;default: 1'b0 ; */ -/*description: invert temperature sensor data*/ -#define SENS_TSENS_IN_INV (BIT(13)) -#define SENS_TSENS_IN_INV_M (BIT(13)) -#define SENS_TSENS_IN_INV_V 0x1 -#define SENS_TSENS_IN_INV_S 13 -/* SENS_TSENS_INT_EN : R/W ;bitpos:[12] ;default: 1'b1 ; */ -/*description: enable temperature sensor to send out interrupt*/ -#define SENS_TSENS_INT_EN (BIT(12)) -#define SENS_TSENS_INT_EN_M (BIT(12)) -#define SENS_TSENS_INT_EN_V 0x1 -#define SENS_TSENS_INT_EN_S 12 -/* SENS_TSENS_READY : RO ;bitpos:[8] ;default: 1'h0 ; */ -/*description: indicate temperature sensor out ready*/ -#define SENS_TSENS_READY (BIT(8)) -#define SENS_TSENS_READY_M (BIT(8)) -#define SENS_TSENS_READY_V 0x1 -#define SENS_TSENS_READY_S 8 -/* SENS_TSENS_OUT : RO ;bitpos:[7:0] ;default: 8'h0 ; */ -/*description: temperature sensor data out*/ -#define SENS_TSENS_OUT 0x000000FF -#define SENS_TSENS_OUT_M ((SENS_TSENS_OUT_V)<<(SENS_TSENS_OUT_S)) -#define SENS_TSENS_OUT_V 0xFF -#define SENS_TSENS_OUT_S 0 - -#define SENS_SAR_TSENS_CTRL2_REG (DR_REG_SENS_BASE + 0x0054) -/* SENS_TSENS_CLK_INV : R/W ;bitpos:[14] ;default: 1'b1 ; */ -/*description: */ -#define SENS_TSENS_CLK_INV (BIT(14)) -#define SENS_TSENS_CLK_INV_M (BIT(14)) -#define SENS_TSENS_CLK_INV_V 0x1 -#define SENS_TSENS_CLK_INV_S 14 -/* SENS_TSENS_XPD_FORCE : R/W ;bitpos:[13:12] ;default: 2'b0 ; */ -/*description: */ -#define SENS_TSENS_XPD_FORCE 0x00000003 -#define SENS_TSENS_XPD_FORCE_M ((SENS_TSENS_XPD_FORCE_V)<<(SENS_TSENS_XPD_FORCE_S)) -#define SENS_TSENS_XPD_FORCE_V 0x3 -#define SENS_TSENS_XPD_FORCE_S 12 -/* SENS_TSENS_XPD_WAIT : R/W ;bitpos:[11:0] ;default: 12'h2 ; */ -/*description: */ -#define SENS_TSENS_XPD_WAIT 0x00000FFF -#define SENS_TSENS_XPD_WAIT_M ((SENS_TSENS_XPD_WAIT_V)<<(SENS_TSENS_XPD_WAIT_S)) -#define SENS_TSENS_XPD_WAIT_V 0xFFF -#define SENS_TSENS_XPD_WAIT_S 0 - -#define SENS_SAR_I2C_CTRL_REG (DR_REG_SENS_BASE + 0x0058) -/* SENS_SAR_I2C_START_FORCE : R/W ;bitpos:[29] ;default: 1'b0 ; */ -/*description: 1: I2C started by SW*/ -#define SENS_SAR_I2C_START_FORCE (BIT(29)) -#define SENS_SAR_I2C_START_FORCE_M (BIT(29)) -#define SENS_SAR_I2C_START_FORCE_V 0x1 -#define SENS_SAR_I2C_START_FORCE_S 29 -/* SENS_SAR_I2C_START : R/W ;bitpos:[28] ;default: 1'b0 ; */ -/*description: start I2C*/ -#define SENS_SAR_I2C_START (BIT(28)) -#define SENS_SAR_I2C_START_M (BIT(28)) -#define SENS_SAR_I2C_START_V 0x1 -#define SENS_SAR_I2C_START_S 28 -/* SENS_SAR_I2C_CTRL : R/W ;bitpos:[27:0] ;default: 28'b0 ; */ -/*description: I2C control data*/ -#define SENS_SAR_I2C_CTRL 0x0FFFFFFF -#define SENS_SAR_I2C_CTRL_M ((SENS_SAR_I2C_CTRL_V)<<(SENS_SAR_I2C_CTRL_S)) -#define SENS_SAR_I2C_CTRL_V 0xFFFFFFF -#define SENS_SAR_I2C_CTRL_S 0 - -#define SENS_SAR_TOUCH_CONF_REG (DR_REG_SENS_BASE + 0x005c) -/* SENS_TOUCH_APPROACH_PAD0 : R/W ;bitpos:[31:28] ;default: 4'hF ; */ -/*description: indicate which pad is approach pad0*/ -#define SENS_TOUCH_APPROACH_PAD0 0x0000000F -#define SENS_TOUCH_APPROACH_PAD0_M ((SENS_TOUCH_APPROACH_PAD0_V)<<(SENS_TOUCH_APPROACH_PAD0_S)) -#define SENS_TOUCH_APPROACH_PAD0_V 0xF -#define SENS_TOUCH_APPROACH_PAD0_S 28 -/* SENS_TOUCH_APPROACH_PAD1 : R/W ;bitpos:[27:24] ;default: 4'hF ; */ -/*description: indicate which pad is approach pad1*/ -#define SENS_TOUCH_APPROACH_PAD1 0x0000000F -#define SENS_TOUCH_APPROACH_PAD1_M ((SENS_TOUCH_APPROACH_PAD1_V)<<(SENS_TOUCH_APPROACH_PAD1_S)) -#define SENS_TOUCH_APPROACH_PAD1_V 0xF -#define SENS_TOUCH_APPROACH_PAD1_S 24 -/* SENS_TOUCH_APPROACH_PAD2 : R/W ;bitpos:[23:20] ;default: 4'hF ; */ -/*description: indicate which pad is approach pad2*/ -#define SENS_TOUCH_APPROACH_PAD2 0x0000000F -#define SENS_TOUCH_APPROACH_PAD2_M ((SENS_TOUCH_APPROACH_PAD2_V)<<(SENS_TOUCH_APPROACH_PAD2_S)) -#define SENS_TOUCH_APPROACH_PAD2_V 0xF -#define SENS_TOUCH_APPROACH_PAD2_S 20 -/* SENS_TOUCH_UNIT_END : RO ;bitpos:[19] ;default: 1'd0 ; */ -/*description: touch_unit_done*/ -#define SENS_TOUCH_UNIT_END (BIT(19)) -#define SENS_TOUCH_UNIT_END_M (BIT(19)) -#define SENS_TOUCH_UNIT_END_V 0x1 -#define SENS_TOUCH_UNIT_END_S 19 -/* SENS_TOUCH_DENOISE_END : RO ;bitpos:[18] ;default: 1'd0 ; */ -/*description: touch_denoise_done*/ -#define SENS_TOUCH_DENOISE_END (BIT(18)) -#define SENS_TOUCH_DENOISE_END_M (BIT(18)) -#define SENS_TOUCH_DENOISE_END_V 0x1 -#define SENS_TOUCH_DENOISE_END_S 18 -/* SENS_TOUCH_DATA_SEL : R/W ;bitpos:[17:16] ;default: 2'd0 ; */ -/*description: 3: smooth data 2: baseline 1 0: raw_data*/ -#define SENS_TOUCH_DATA_SEL 0x00000003 -#define SENS_TOUCH_DATA_SEL_M ((SENS_TOUCH_DATA_SEL_V)<<(SENS_TOUCH_DATA_SEL_S)) -#define SENS_TOUCH_DATA_SEL_V 0x3 -#define SENS_TOUCH_DATA_SEL_S 16 -/* SENS_TOUCH_STATUS_CLR : WO ;bitpos:[15] ;default: 1'd0 ; */ -/*description: clear all touch active status*/ -#define SENS_TOUCH_STATUS_CLR (BIT(15)) -#define SENS_TOUCH_STATUS_CLR_M (BIT(15)) -#define SENS_TOUCH_STATUS_CLR_V 0x1 -#define SENS_TOUCH_STATUS_CLR_S 15 -/* SENS_TOUCH_OUTEN : R/W ;bitpos:[14:0] ;default: 15'h7FFF ; */ -/*description: touch controller output enable*/ -#define SENS_TOUCH_OUTEN 0x00007FFF -#define SENS_TOUCH_OUTEN_M ((SENS_TOUCH_OUTEN_V)<<(SENS_TOUCH_OUTEN_S)) -#define SENS_TOUCH_OUTEN_V 0x7FFF -#define SENS_TOUCH_OUTEN_S 0 - -#define SENS_SAR_TOUCH_THRES1_REG (DR_REG_SENS_BASE + 0x0060) -/* SENS_TOUCH_OUT_TH1 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 1*/ -#define SENS_TOUCH_OUT_TH1 0x003FFFFF -#define SENS_TOUCH_OUT_TH1_M ((SENS_TOUCH_OUT_TH1_V)<<(SENS_TOUCH_OUT_TH1_S)) -#define SENS_TOUCH_OUT_TH1_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH1_S 0 - -#define SENS_SAR_TOUCH_THRES2_REG (DR_REG_SENS_BASE + 0x0064) -/* SENS_TOUCH_OUT_TH2 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 2*/ -#define SENS_TOUCH_OUT_TH2 0x003FFFFF -#define SENS_TOUCH_OUT_TH2_M ((SENS_TOUCH_OUT_TH2_V)<<(SENS_TOUCH_OUT_TH2_S)) -#define SENS_TOUCH_OUT_TH2_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH2_S 0 - -#define SENS_SAR_TOUCH_THRES3_REG (DR_REG_SENS_BASE + 0x0068) -/* SENS_TOUCH_OUT_TH3 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 3*/ -#define SENS_TOUCH_OUT_TH3 0x003FFFFF -#define SENS_TOUCH_OUT_TH3_M ((SENS_TOUCH_OUT_TH3_V)<<(SENS_TOUCH_OUT_TH3_S)) -#define SENS_TOUCH_OUT_TH3_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH3_S 0 - -#define SENS_SAR_TOUCH_THRES4_REG (DR_REG_SENS_BASE + 0x006c) -/* SENS_TOUCH_OUT_TH4 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 4*/ -#define SENS_TOUCH_OUT_TH4 0x003FFFFF -#define SENS_TOUCH_OUT_TH4_M ((SENS_TOUCH_OUT_TH4_V)<<(SENS_TOUCH_OUT_TH4_S)) -#define SENS_TOUCH_OUT_TH4_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH4_S 0 - -#define SENS_SAR_TOUCH_THRES5_REG (DR_REG_SENS_BASE + 0x0070) -/* SENS_TOUCH_OUT_TH5 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 5*/ -#define SENS_TOUCH_OUT_TH5 0x003FFFFF -#define SENS_TOUCH_OUT_TH5_M ((SENS_TOUCH_OUT_TH5_V)<<(SENS_TOUCH_OUT_TH5_S)) -#define SENS_TOUCH_OUT_TH5_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH5_S 0 - -#define SENS_SAR_TOUCH_THRES6_REG (DR_REG_SENS_BASE + 0x0074) -/* SENS_TOUCH_OUT_TH6 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 6*/ -#define SENS_TOUCH_OUT_TH6 0x003FFFFF -#define SENS_TOUCH_OUT_TH6_M ((SENS_TOUCH_OUT_TH6_V)<<(SENS_TOUCH_OUT_TH6_S)) -#define SENS_TOUCH_OUT_TH6_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH6_S 0 - -#define SENS_SAR_TOUCH_THRES7_REG (DR_REG_SENS_BASE + 0x0078) -/* SENS_TOUCH_OUT_TH7 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 7*/ -#define SENS_TOUCH_OUT_TH7 0x003FFFFF -#define SENS_TOUCH_OUT_TH7_M ((SENS_TOUCH_OUT_TH7_V)<<(SENS_TOUCH_OUT_TH7_S)) -#define SENS_TOUCH_OUT_TH7_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH7_S 0 - -#define SENS_SAR_TOUCH_THRES8_REG (DR_REG_SENS_BASE + 0x007c) -/* SENS_TOUCH_OUT_TH8 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 8*/ -#define SENS_TOUCH_OUT_TH8 0x003FFFFF -#define SENS_TOUCH_OUT_TH8_M ((SENS_TOUCH_OUT_TH8_V)<<(SENS_TOUCH_OUT_TH8_S)) -#define SENS_TOUCH_OUT_TH8_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH8_S 0 - -#define SENS_SAR_TOUCH_THRES9_REG (DR_REG_SENS_BASE + 0x0080) -/* SENS_TOUCH_OUT_TH9 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 9*/ -#define SENS_TOUCH_OUT_TH9 0x003FFFFF -#define SENS_TOUCH_OUT_TH9_M ((SENS_TOUCH_OUT_TH9_V)<<(SENS_TOUCH_OUT_TH9_S)) -#define SENS_TOUCH_OUT_TH9_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH9_S 0 - -#define SENS_SAR_TOUCH_THRES10_REG (DR_REG_SENS_BASE + 0x0084) -/* SENS_TOUCH_OUT_TH10 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 10*/ -#define SENS_TOUCH_OUT_TH10 0x003FFFFF -#define SENS_TOUCH_OUT_TH10_M ((SENS_TOUCH_OUT_TH10_V)<<(SENS_TOUCH_OUT_TH10_S)) -#define SENS_TOUCH_OUT_TH10_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH10_S 0 - -#define SENS_SAR_TOUCH_THRES11_REG (DR_REG_SENS_BASE + 0x0088) -/* SENS_TOUCH_OUT_TH11 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 11*/ -#define SENS_TOUCH_OUT_TH11 0x003FFFFF -#define SENS_TOUCH_OUT_TH11_M ((SENS_TOUCH_OUT_TH11_V)<<(SENS_TOUCH_OUT_TH11_S)) -#define SENS_TOUCH_OUT_TH11_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH11_S 0 - -#define SENS_SAR_TOUCH_THRES12_REG (DR_REG_SENS_BASE + 0x008c) -/* SENS_TOUCH_OUT_TH12 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 12*/ -#define SENS_TOUCH_OUT_TH12 0x003FFFFF -#define SENS_TOUCH_OUT_TH12_M ((SENS_TOUCH_OUT_TH12_V)<<(SENS_TOUCH_OUT_TH12_S)) -#define SENS_TOUCH_OUT_TH12_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH12_S 0 - -#define SENS_SAR_TOUCH_THRES13_REG (DR_REG_SENS_BASE + 0x0090) -/* SENS_TOUCH_OUT_TH13 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 13*/ -#define SENS_TOUCH_OUT_TH13 0x003FFFFF -#define SENS_TOUCH_OUT_TH13_M ((SENS_TOUCH_OUT_TH13_V)<<(SENS_TOUCH_OUT_TH13_S)) -#define SENS_TOUCH_OUT_TH13_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH13_S 0 - -#define SENS_SAR_TOUCH_THRES14_REG (DR_REG_SENS_BASE + 0x0094) -/* SENS_TOUCH_OUT_TH14 : R/W ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: Finger threshold for touch pad 14*/ -#define SENS_TOUCH_OUT_TH14 0x003FFFFF -#define SENS_TOUCH_OUT_TH14_M ((SENS_TOUCH_OUT_TH14_V)<<(SENS_TOUCH_OUT_TH14_S)) -#define SENS_TOUCH_OUT_TH14_V 0x3FFFFF -#define SENS_TOUCH_OUT_TH14_S 0 - -#define SENS_SAR_TOUCH_CHN_ST_REG (DR_REG_SENS_BASE + 0x00d4) -/* SENS_TOUCH_MEAS_DONE : RO ;bitpos:[31] ;default: 1'b0 ; */ -/*description: */ -#define SENS_TOUCH_MEAS_DONE (BIT(31)) -#define SENS_TOUCH_MEAS_DONE_M (BIT(31)) -#define SENS_TOUCH_MEAS_DONE_V 0x1 -#define SENS_TOUCH_MEAS_DONE_S 31 -/* SENS_TOUCH_CHANNEL_CLR : WO ;bitpos:[29:15] ;default: 15'd0 ; */ -/*description: Clear touch channel*/ -#define SENS_TOUCH_CHANNEL_CLR 0x00007FFF -#define SENS_TOUCH_CHANNEL_CLR_M ((SENS_TOUCH_CHANNEL_CLR_V)<<(SENS_TOUCH_CHANNEL_CLR_S)) -#define SENS_TOUCH_CHANNEL_CLR_V 0x7FFF -#define SENS_TOUCH_CHANNEL_CLR_S 15 -/* SENS_TOUCH_PAD_ACTIVE : RO ;bitpos:[14:0] ;default: 15'd0 ; */ -/*description: touch active status*/ -#define SENS_TOUCH_PAD_ACTIVE 0x00007FFF -#define SENS_TOUCH_PAD_ACTIVE_M ((SENS_TOUCH_PAD_ACTIVE_V)<<(SENS_TOUCH_PAD_ACTIVE_S)) -#define SENS_TOUCH_PAD_ACTIVE_V 0x7FFF -#define SENS_TOUCH_PAD_ACTIVE_S 0 - -#define SENS_SAR_TOUCH_STATUS0_REG (DR_REG_SENS_BASE + 0x00d8) -/* SENS_TOUCH_SCAN_CURR : RO ;bitpos:[25:22] ;default: 4'd0 ; */ -/*description: */ -#define SENS_TOUCH_SCAN_CURR 0x0000000F -#define SENS_TOUCH_SCAN_CURR_M ((SENS_TOUCH_SCAN_CURR_V)<<(SENS_TOUCH_SCAN_CURR_S)) -#define SENS_TOUCH_SCAN_CURR_V 0xF -#define SENS_TOUCH_SCAN_CURR_S 22 -/* SENS_TOUCH_DENOISE_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: the counter for touch pad 0*/ -#define SENS_TOUCH_DENOISE_DATA 0x003FFFFF -#define SENS_TOUCH_DENOISE_DATA_M ((SENS_TOUCH_DENOISE_DATA_V)<<(SENS_TOUCH_DENOISE_DATA_S)) -#define SENS_TOUCH_DENOISE_DATA_V 0x3FFFFF -#define SENS_TOUCH_DENOISE_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS1_REG (DR_REG_SENS_BASE + 0x00dc) -/* SENS_TOUCH_PAD1_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD1_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD1_DEBOUNCE_M ((SENS_TOUCH_PAD1_DEBOUNCE_V)<<(SENS_TOUCH_PAD1_DEBOUNCE_S)) -#define SENS_TOUCH_PAD1_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD1_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD1_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD1_DATA 0x003FFFFF -#define SENS_TOUCH_PAD1_DATA_M ((SENS_TOUCH_PAD1_DATA_V)<<(SENS_TOUCH_PAD1_DATA_S)) -#define SENS_TOUCH_PAD1_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD1_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS2_REG (DR_REG_SENS_BASE + 0x00e0) -/* SENS_TOUCH_PAD2_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD2_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD2_DEBOUNCE_M ((SENS_TOUCH_PAD2_DEBOUNCE_V)<<(SENS_TOUCH_PAD2_DEBOUNCE_S)) -#define SENS_TOUCH_PAD2_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD2_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD2_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD2_DATA 0x003FFFFF -#define SENS_TOUCH_PAD2_DATA_M ((SENS_TOUCH_PAD2_DATA_V)<<(SENS_TOUCH_PAD2_DATA_S)) -#define SENS_TOUCH_PAD2_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD2_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS3_REG (DR_REG_SENS_BASE + 0x00e4) -/* SENS_TOUCH_PAD3_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD3_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD3_DEBOUNCE_M ((SENS_TOUCH_PAD3_DEBOUNCE_V)<<(SENS_TOUCH_PAD3_DEBOUNCE_S)) -#define SENS_TOUCH_PAD3_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD3_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD3_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD3_DATA 0x003FFFFF -#define SENS_TOUCH_PAD3_DATA_M ((SENS_TOUCH_PAD3_DATA_V)<<(SENS_TOUCH_PAD3_DATA_S)) -#define SENS_TOUCH_PAD3_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD3_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS4_REG (DR_REG_SENS_BASE + 0x00e8) -/* SENS_TOUCH_PAD4_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD4_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD4_DEBOUNCE_M ((SENS_TOUCH_PAD4_DEBOUNCE_V)<<(SENS_TOUCH_PAD4_DEBOUNCE_S)) -#define SENS_TOUCH_PAD4_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD4_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD4_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD4_DATA 0x003FFFFF -#define SENS_TOUCH_PAD4_DATA_M ((SENS_TOUCH_PAD4_DATA_V)<<(SENS_TOUCH_PAD4_DATA_S)) -#define SENS_TOUCH_PAD4_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD4_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS5_REG (DR_REG_SENS_BASE + 0x00ec) -/* SENS_TOUCH_PAD5_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD5_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD5_DEBOUNCE_M ((SENS_TOUCH_PAD5_DEBOUNCE_V)<<(SENS_TOUCH_PAD5_DEBOUNCE_S)) -#define SENS_TOUCH_PAD5_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD5_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD5_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD5_DATA 0x003FFFFF -#define SENS_TOUCH_PAD5_DATA_M ((SENS_TOUCH_PAD5_DATA_V)<<(SENS_TOUCH_PAD5_DATA_S)) -#define SENS_TOUCH_PAD5_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD5_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS6_REG (DR_REG_SENS_BASE + 0x00f0) -/* SENS_TOUCH_PAD6_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD6_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD6_DEBOUNCE_M ((SENS_TOUCH_PAD6_DEBOUNCE_V)<<(SENS_TOUCH_PAD6_DEBOUNCE_S)) -#define SENS_TOUCH_PAD6_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD6_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD6_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD6_DATA 0x003FFFFF -#define SENS_TOUCH_PAD6_DATA_M ((SENS_TOUCH_PAD6_DATA_V)<<(SENS_TOUCH_PAD6_DATA_S)) -#define SENS_TOUCH_PAD6_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD6_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS7_REG (DR_REG_SENS_BASE + 0x00f4) -/* SENS_TOUCH_PAD7_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD7_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD7_DEBOUNCE_M ((SENS_TOUCH_PAD7_DEBOUNCE_V)<<(SENS_TOUCH_PAD7_DEBOUNCE_S)) -#define SENS_TOUCH_PAD7_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD7_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD7_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD7_DATA 0x003FFFFF -#define SENS_TOUCH_PAD7_DATA_M ((SENS_TOUCH_PAD7_DATA_V)<<(SENS_TOUCH_PAD7_DATA_S)) -#define SENS_TOUCH_PAD7_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD7_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS8_REG (DR_REG_SENS_BASE + 0x00f8) -/* SENS_TOUCH_PAD8_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD8_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD8_DEBOUNCE_M ((SENS_TOUCH_PAD8_DEBOUNCE_V)<<(SENS_TOUCH_PAD8_DEBOUNCE_S)) -#define SENS_TOUCH_PAD8_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD8_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD8_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD8_DATA 0x003FFFFF -#define SENS_TOUCH_PAD8_DATA_M ((SENS_TOUCH_PAD8_DATA_V)<<(SENS_TOUCH_PAD8_DATA_S)) -#define SENS_TOUCH_PAD8_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD8_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS9_REG (DR_REG_SENS_BASE + 0x00fc) -/* SENS_TOUCH_PAD9_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD9_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD9_DEBOUNCE_M ((SENS_TOUCH_PAD9_DEBOUNCE_V)<<(SENS_TOUCH_PAD9_DEBOUNCE_S)) -#define SENS_TOUCH_PAD9_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD9_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD9_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD9_DATA 0x003FFFFF -#define SENS_TOUCH_PAD9_DATA_M ((SENS_TOUCH_PAD9_DATA_V)<<(SENS_TOUCH_PAD9_DATA_S)) -#define SENS_TOUCH_PAD9_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD9_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS10_REG (DR_REG_SENS_BASE + 0x0100) -/* SENS_TOUCH_PAD10_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD10_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD10_DEBOUNCE_M ((SENS_TOUCH_PAD10_DEBOUNCE_V)<<(SENS_TOUCH_PAD10_DEBOUNCE_S)) -#define SENS_TOUCH_PAD10_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD10_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD10_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD10_DATA 0x003FFFFF -#define SENS_TOUCH_PAD10_DATA_M ((SENS_TOUCH_PAD10_DATA_V)<<(SENS_TOUCH_PAD10_DATA_S)) -#define SENS_TOUCH_PAD10_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD10_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS11_REG (DR_REG_SENS_BASE + 0x0104) -/* SENS_TOUCH_PAD11_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD11_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD11_DEBOUNCE_M ((SENS_TOUCH_PAD11_DEBOUNCE_V)<<(SENS_TOUCH_PAD11_DEBOUNCE_S)) -#define SENS_TOUCH_PAD11_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD11_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD11_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD11_DATA 0x003FFFFF -#define SENS_TOUCH_PAD11_DATA_M ((SENS_TOUCH_PAD11_DATA_V)<<(SENS_TOUCH_PAD11_DATA_S)) -#define SENS_TOUCH_PAD11_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD11_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS12_REG (DR_REG_SENS_BASE + 0x0108) -/* SENS_TOUCH_PAD12_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD12_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD12_DEBOUNCE_M ((SENS_TOUCH_PAD12_DEBOUNCE_V)<<(SENS_TOUCH_PAD12_DEBOUNCE_S)) -#define SENS_TOUCH_PAD12_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD12_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD12_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD12_DATA 0x003FFFFF -#define SENS_TOUCH_PAD12_DATA_M ((SENS_TOUCH_PAD12_DATA_V)<<(SENS_TOUCH_PAD12_DATA_S)) -#define SENS_TOUCH_PAD12_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD12_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS13_REG (DR_REG_SENS_BASE + 0x010c) -/* SENS_TOUCH_PAD13_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD13_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD13_DEBOUNCE_M ((SENS_TOUCH_PAD13_DEBOUNCE_V)<<(SENS_TOUCH_PAD13_DEBOUNCE_S)) -#define SENS_TOUCH_PAD13_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD13_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD13_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD13_DATA 0x003FFFFF -#define SENS_TOUCH_PAD13_DATA_M ((SENS_TOUCH_PAD13_DATA_V)<<(SENS_TOUCH_PAD13_DATA_S)) -#define SENS_TOUCH_PAD13_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD13_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS14_REG (DR_REG_SENS_BASE + 0x0110) -/* SENS_TOUCH_PAD14_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_PAD14_DEBOUNCE 0x00000007 -#define SENS_TOUCH_PAD14_DEBOUNCE_M ((SENS_TOUCH_PAD14_DEBOUNCE_V)<<(SENS_TOUCH_PAD14_DEBOUNCE_S)) -#define SENS_TOUCH_PAD14_DEBOUNCE_V 0x7 -#define SENS_TOUCH_PAD14_DEBOUNCE_S 29 -/* SENS_TOUCH_PAD14_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_PAD14_DATA 0x003FFFFF -#define SENS_TOUCH_PAD14_DATA_M ((SENS_TOUCH_PAD14_DATA_V)<<(SENS_TOUCH_PAD14_DATA_S)) -#define SENS_TOUCH_PAD14_DATA_V 0x3FFFFF -#define SENS_TOUCH_PAD14_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS15_REG (DR_REG_SENS_BASE + 0x0114) -/* SENS_TOUCH_SLP_DEBOUNCE : RO ;bitpos:[31:29] ;default: 3'd0 ; */ -/*description: */ -#define SENS_TOUCH_SLP_DEBOUNCE 0x00000007 -#define SENS_TOUCH_SLP_DEBOUNCE_M ((SENS_TOUCH_SLP_DEBOUNCE_V)<<(SENS_TOUCH_SLP_DEBOUNCE_S)) -#define SENS_TOUCH_SLP_DEBOUNCE_V 0x7 -#define SENS_TOUCH_SLP_DEBOUNCE_S 29 -/* SENS_TOUCH_SLP_DATA : RO ;bitpos:[21:0] ;default: 22'h0 ; */ -/*description: */ -#define SENS_TOUCH_SLP_DATA 0x003FFFFF -#define SENS_TOUCH_SLP_DATA_M ((SENS_TOUCH_SLP_DATA_V)<<(SENS_TOUCH_SLP_DATA_S)) -#define SENS_TOUCH_SLP_DATA_V 0x3FFFFF -#define SENS_TOUCH_SLP_DATA_S 0 - -#define SENS_SAR_TOUCH_STATUS16_REG (DR_REG_SENS_BASE + 0x0118) -/* SENS_TOUCH_SLP_APPROACH_CNT : RO ;bitpos:[31:24] ;default: 8'd0 ; */ -/*description: */ -#define SENS_TOUCH_SLP_APPROACH_CNT 0x000000FF -#define SENS_TOUCH_SLP_APPROACH_CNT_M ((SENS_TOUCH_SLP_APPROACH_CNT_V)<<(SENS_TOUCH_SLP_APPROACH_CNT_S)) -#define SENS_TOUCH_SLP_APPROACH_CNT_V 0xFF -#define SENS_TOUCH_SLP_APPROACH_CNT_S 24 -/* SENS_TOUCH_APPROACH_PAD0_CNT : RO ;bitpos:[23:16] ;default: 8'd0 ; */ -/*description: */ -#define SENS_TOUCH_APPROACH_PAD0_CNT 0x000000FF -#define SENS_TOUCH_APPROACH_PAD0_CNT_M ((SENS_TOUCH_APPROACH_PAD0_CNT_V)<<(SENS_TOUCH_APPROACH_PAD0_CNT_S)) -#define SENS_TOUCH_APPROACH_PAD0_CNT_V 0xFF -#define SENS_TOUCH_APPROACH_PAD0_CNT_S 16 -/* SENS_TOUCH_APPROACH_PAD1_CNT : RO ;bitpos:[15:8] ;default: 8'd0 ; */ -/*description: */ -#define SENS_TOUCH_APPROACH_PAD1_CNT 0x000000FF -#define SENS_TOUCH_APPROACH_PAD1_CNT_M ((SENS_TOUCH_APPROACH_PAD1_CNT_V)<<(SENS_TOUCH_APPROACH_PAD1_CNT_S)) -#define SENS_TOUCH_APPROACH_PAD1_CNT_V 0xFF -#define SENS_TOUCH_APPROACH_PAD1_CNT_S 8 -/* SENS_TOUCH_APPROACH_PAD2_CNT : RO ;bitpos:[7:0] ;default: 8'd0 ; */ -/*description: */ -#define SENS_TOUCH_APPROACH_PAD2_CNT 0x000000FF -#define SENS_TOUCH_APPROACH_PAD2_CNT_M ((SENS_TOUCH_APPROACH_PAD2_CNT_V)<<(SENS_TOUCH_APPROACH_PAD2_CNT_S)) -#define SENS_TOUCH_APPROACH_PAD2_CNT_V 0xFF -#define SENS_TOUCH_APPROACH_PAD2_CNT_S 0 - -#define SENS_SAR_DAC_CTRL1_REG (DR_REG_SENS_BASE + 0x011c) -/* SENS_DAC_CLK_INV : R/W ;bitpos:[25] ;default: 1'b0 ; */ -/*description: 1: invert PDAC_CLK*/ -#define SENS_DAC_CLK_INV (BIT(25)) -#define SENS_DAC_CLK_INV_M (BIT(25)) -#define SENS_DAC_CLK_INV_V 0x1 -#define SENS_DAC_CLK_INV_S 25 -/* SENS_DAC_CLK_FORCE_HIGH : R/W ;bitpos:[24] ;default: 1'b0 ; */ -/*description: 1: force PDAC_CLK to high*/ -#define SENS_DAC_CLK_FORCE_HIGH (BIT(24)) -#define SENS_DAC_CLK_FORCE_HIGH_M (BIT(24)) -#define SENS_DAC_CLK_FORCE_HIGH_V 0x1 -#define SENS_DAC_CLK_FORCE_HIGH_S 24 -/* SENS_DAC_CLK_FORCE_LOW : R/W ;bitpos:[23] ;default: 1'b0 ; */ -/*description: 1: force PDAC_CLK to low*/ -#define SENS_DAC_CLK_FORCE_LOW (BIT(23)) -#define SENS_DAC_CLK_FORCE_LOW_M (BIT(23)) -#define SENS_DAC_CLK_FORCE_LOW_V 0x1 -#define SENS_DAC_CLK_FORCE_LOW_S 23 -/* SENS_DAC_DIG_FORCE : R/W ;bitpos:[22] ;default: 1'b0 ; */ -/*description: 1: DAC1 & DAC2 use DMA*/ -#define SENS_DAC_DIG_FORCE (BIT(22)) -#define SENS_DAC_DIG_FORCE_M (BIT(22)) -#define SENS_DAC_DIG_FORCE_V 0x1 -#define SENS_DAC_DIG_FORCE_S 22 -/* SENS_DEBUG_BIT_SEL : R/W ;bitpos:[21:17] ;default: 5'b0 ; */ -/*description: */ -#define SENS_DEBUG_BIT_SEL 0x0000001F -#define SENS_DEBUG_BIT_SEL_M ((SENS_DEBUG_BIT_SEL_V)<<(SENS_DEBUG_BIT_SEL_S)) -#define SENS_DEBUG_BIT_SEL_V 0x1F -#define SENS_DEBUG_BIT_SEL_S 17 -/* SENS_SW_TONE_EN : R/W ;bitpos:[16] ;default: 1'b0 ; */ -/*description: 1: enable CW generator*/ -#define SENS_SW_TONE_EN (BIT(16)) -#define SENS_SW_TONE_EN_M (BIT(16)) -#define SENS_SW_TONE_EN_V 0x1 -#define SENS_SW_TONE_EN_S 16 -/* SENS_SW_FSTEP : R/W ;bitpos:[15:0] ;default: 16'b0 ; */ -/*description: frequency step for CW generator*/ -#define SENS_SW_FSTEP 0x0000FFFF -#define SENS_SW_FSTEP_M ((SENS_SW_FSTEP_V)<<(SENS_SW_FSTEP_S)) -#define SENS_SW_FSTEP_V 0xFFFF -#define SENS_SW_FSTEP_S 0 - -#define SENS_SAR_DAC_CTRL2_REG (DR_REG_SENS_BASE + 0x0120) -/* SENS_DAC_CW_EN2 : R/W ;bitpos:[25] ;default: 1'b1 ; */ -/*description: 1: to select CW generator as source to PDAC2_DAC[7:0]*/ -#define SENS_DAC_CW_EN2 (BIT(25)) -#define SENS_DAC_CW_EN2_M (BIT(25)) -#define SENS_DAC_CW_EN2_V 0x1 -#define SENS_DAC_CW_EN2_S 25 -/* SENS_DAC_CW_EN1 : R/W ;bitpos:[24] ;default: 1'b1 ; */ -/*description: 1: to select CW generator as source to PDAC1_DAC[7:0]*/ -#define SENS_DAC_CW_EN1 (BIT(24)) -#define SENS_DAC_CW_EN1_M (BIT(24)) -#define SENS_DAC_CW_EN1_V 0x1 -#define SENS_DAC_CW_EN1_S 24 -/* SENS_DAC_INV2 : R/W ;bitpos:[23:22] ;default: 2'b0 ; */ -/*description: 00: do not invert any bits*/ -#define SENS_DAC_INV2 0x00000003 -#define SENS_DAC_INV2_M ((SENS_DAC_INV2_V)<<(SENS_DAC_INV2_S)) -#define SENS_DAC_INV2_V 0x3 -#define SENS_DAC_INV2_S 22 -/* SENS_DAC_INV1 : R/W ;bitpos:[21:20] ;default: 2'b0 ; */ -/*description: 00: do not invert any bits*/ -#define SENS_DAC_INV1 0x00000003 -#define SENS_DAC_INV1_M ((SENS_DAC_INV1_V)<<(SENS_DAC_INV1_S)) -#define SENS_DAC_INV1_V 0x3 -#define SENS_DAC_INV1_S 20 -/* SENS_DAC_SCALE2 : R/W ;bitpos:[19:18] ;default: 2'b0 ; */ -/*description: 00: no scale*/ -#define SENS_DAC_SCALE2 0x00000003 -#define SENS_DAC_SCALE2_M ((SENS_DAC_SCALE2_V)<<(SENS_DAC_SCALE2_S)) -#define SENS_DAC_SCALE2_V 0x3 -#define SENS_DAC_SCALE2_S 18 -/* SENS_DAC_SCALE1 : R/W ;bitpos:[17:16] ;default: 2'b0 ; */ -/*description: 00: no scale*/ -#define SENS_DAC_SCALE1 0x00000003 -#define SENS_DAC_SCALE1_M ((SENS_DAC_SCALE1_V)<<(SENS_DAC_SCALE1_S)) -#define SENS_DAC_SCALE1_V 0x3 -#define SENS_DAC_SCALE1_S 16 -/* SENS_DAC_DC2 : R/W ;bitpos:[15:8] ;default: 8'b0 ; */ -/*description: DC offset for DAC2 CW generator*/ -#define SENS_DAC_DC2 0x000000FF -#define SENS_DAC_DC2_M ((SENS_DAC_DC2_V)<<(SENS_DAC_DC2_S)) -#define SENS_DAC_DC2_V 0xFF -#define SENS_DAC_DC2_S 8 -/* SENS_DAC_DC1 : R/W ;bitpos:[7:0] ;default: 8'b0 ; */ -/*description: DC offset for DAC1 CW generator*/ -#define SENS_DAC_DC1 0x000000FF -#define SENS_DAC_DC1_M ((SENS_DAC_DC1_V)<<(SENS_DAC_DC1_S)) -#define SENS_DAC_DC1_V 0xFF -#define SENS_DAC_DC1_S 0 - -#define SENS_SAR_COCPU_STATE_REG (DR_REG_SENS_BASE + 0x0124) -/* SENS_COCPU_EBREAK : RO ;bitpos:[30] ;default: 1'b0 ; */ -/*description: check cocpu whether in ebreak*/ -#define SENS_COCPU_EBREAK (BIT(30)) -#define SENS_COCPU_EBREAK_M (BIT(30)) -#define SENS_COCPU_EBREAK_V 0x1 -#define SENS_COCPU_EBREAK_S 30 -/* SENS_COCPU_TRAP : RO ;bitpos:[29] ;default: 1'b0 ; */ -/*description: check cocpu whether in trap state*/ -#define SENS_COCPU_TRAP (BIT(29)) -#define SENS_COCPU_TRAP_M (BIT(29)) -#define SENS_COCPU_TRAP_V 0x1 -#define SENS_COCPU_TRAP_S 29 -/* SENS_COCPU_EOI : RO ;bitpos:[28] ;default: 1'b0 ; */ -/*description: check cocpu whether in interrupt state*/ -#define SENS_COCPU_EOI (BIT(28)) -#define SENS_COCPU_EOI_M (BIT(28)) -#define SENS_COCPU_EOI_V 0x1 -#define SENS_COCPU_EOI_S 28 -/* SENS_COCPU_RESET_N : RO ;bitpos:[27] ;default: 1'b0 ; */ -/*description: check cocpu whether in reset state*/ -#define SENS_COCPU_RESET_N (BIT(27)) -#define SENS_COCPU_RESET_N_M (BIT(27)) -#define SENS_COCPU_RESET_N_V 0x1 -#define SENS_COCPU_RESET_N_S 27 -/* SENS_COCPU_CLK_EN_ST : RO ;bitpos:[26] ;default: 1'b0 ; */ -/*description: check cocpu whether clk on*/ -#define SENS_COCPU_CLK_EN_ST (BIT(26)) -#define SENS_COCPU_CLK_EN_ST_M (BIT(26)) -#define SENS_COCPU_CLK_EN_ST_V 0x1 -#define SENS_COCPU_CLK_EN_ST_S 26 -/* SENS_COCPU_DBG_TRIGGER : WO ;bitpos:[25] ;default: 1'b0 ; */ -/*description: trigger cocpu debug registers*/ -#define SENS_COCPU_DBG_TRIGGER (BIT(25)) -#define SENS_COCPU_DBG_TRIGGER_M (BIT(25)) -#define SENS_COCPU_DBG_TRIGGER_V 0x1 -#define SENS_COCPU_DBG_TRIGGER_S 25 - -#define SENS_SAR_COCPU_INT_RAW_REG (DR_REG_SENS_BASE + 0x0128) -/* SENS_COCPU_TOUCH_SCAN_DONE_INT_RAW : RO ;bitpos:[11] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_RAW (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_RAW_M (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_RAW_V 0x1 -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_RAW_S 11 -/* SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_RAW : RO ;bitpos:[10] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_RAW (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_RAW_M (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_RAW_V 0x1 -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_RAW_S 10 -/* SENS_COCPU_TOUCH_TIMEOUT_INT_RAW : RO ;bitpos:[9] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_TIMEOUT_INT_RAW (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_RAW_M (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_RAW_V 0x1 -#define SENS_COCPU_TOUCH_TIMEOUT_INT_RAW_S 9 -/* SENS_COCPU_SWD_INT_RAW : RO ;bitpos:[8] ;default: 1'b0 ; */ -/*description: int from super watch dog*/ -#define SENS_COCPU_SWD_INT_RAW (BIT(8)) -#define SENS_COCPU_SWD_INT_RAW_M (BIT(8)) -#define SENS_COCPU_SWD_INT_RAW_V 0x1 -#define SENS_COCPU_SWD_INT_RAW_S 8 -/* SENS_COCPU_SW_INT_RAW : RO ;bitpos:[7] ;default: 1'b0 ; */ -/*description: int from software*/ -#define SENS_COCPU_SW_INT_RAW (BIT(7)) -#define SENS_COCPU_SW_INT_RAW_M (BIT(7)) -#define SENS_COCPU_SW_INT_RAW_V 0x1 -#define SENS_COCPU_SW_INT_RAW_S 7 -/* SENS_COCPU_START_INT_RAW : RO ;bitpos:[6] ;default: 1'b0 ; */ -/*description: int from start*/ -#define SENS_COCPU_START_INT_RAW (BIT(6)) -#define SENS_COCPU_START_INT_RAW_M (BIT(6)) -#define SENS_COCPU_START_INT_RAW_V 0x1 -#define SENS_COCPU_START_INT_RAW_S 6 -/* SENS_COCPU_TSENS_INT_RAW : RO ;bitpos:[5] ;default: 1'b0 ; */ -/*description: int from tsens*/ -#define SENS_COCPU_TSENS_INT_RAW (BIT(5)) -#define SENS_COCPU_TSENS_INT_RAW_M (BIT(5)) -#define SENS_COCPU_TSENS_INT_RAW_V 0x1 -#define SENS_COCPU_TSENS_INT_RAW_S 5 -/* SENS_COCPU_SENS2_INT_RAW : RO ;bitpos:[4] ;default: 1'b0 ; */ -/*description: int from saradc2*/ -#define SENS_COCPU_SENS2_INT_RAW (BIT(4)) -#define SENS_COCPU_SENS2_INT_RAW_M (BIT(4)) -#define SENS_COCPU_SENS2_INT_RAW_V 0x1 -#define SENS_COCPU_SENS2_INT_RAW_S 4 -/* SENS_COCPU_SENS1_INT_RAW : RO ;bitpos:[3] ;default: 1'b0 ; */ -/*description: int from saradc1*/ -#define SENS_COCPU_SENS1_INT_RAW (BIT(3)) -#define SENS_COCPU_SENS1_INT_RAW_M (BIT(3)) -#define SENS_COCPU_SENS1_INT_RAW_V 0x1 -#define SENS_COCPU_SENS1_INT_RAW_S 3 -/* SENS_COCPU_TOUCH_ACTIVE_INT_RAW : RO ;bitpos:[2] ;default: 1'b0 ; */ -/*description: int from touch active*/ -#define SENS_COCPU_TOUCH_ACTIVE_INT_RAW (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_RAW_M (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_RAW_V 0x1 -#define SENS_COCPU_TOUCH_ACTIVE_INT_RAW_S 2 -/* SENS_COCPU_TOUCH_INACTIVE_INT_RAW : RO ;bitpos:[1] ;default: 1'b0 ; */ -/*description: int from touch inactive*/ -#define SENS_COCPU_TOUCH_INACTIVE_INT_RAW (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_RAW_M (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_RAW_V 0x1 -#define SENS_COCPU_TOUCH_INACTIVE_INT_RAW_S 1 -/* SENS_COCPU_TOUCH_DONE_INT_RAW : RO ;bitpos:[0] ;default: 1'b0 ; */ -/*description: int from touch done*/ -#define SENS_COCPU_TOUCH_DONE_INT_RAW (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_RAW_M (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_RAW_V 0x1 -#define SENS_COCPU_TOUCH_DONE_INT_RAW_S 0 - -#define SENS_SAR_COCPU_INT_ENA_REG (DR_REG_SENS_BASE + 0x012c) -/* SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA : R/W ;bitpos:[11] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_M (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_V 0x1 -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_S 11 -/* SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA : R/W ;bitpos:[10] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_M (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_V 0x1 -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_S 10 -/* SENS_COCPU_TOUCH_TIMEOUT_INT_ENA : R/W ;bitpos:[9] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_M (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_V 0x1 -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_S 9 -/* SENS_COCPU_SWD_INT_ENA : R/W ;bitpos:[8] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SWD_INT_ENA (BIT(8)) -#define SENS_COCPU_SWD_INT_ENA_M (BIT(8)) -#define SENS_COCPU_SWD_INT_ENA_V 0x1 -#define SENS_COCPU_SWD_INT_ENA_S 8 -/* SENS_COCPU_SW_INT_ENA : R/W ;bitpos:[7] ;default: 1'b0 ; */ -/*description: cocpu int enable*/ -#define SENS_COCPU_SW_INT_ENA (BIT(7)) -#define SENS_COCPU_SW_INT_ENA_M (BIT(7)) -#define SENS_COCPU_SW_INT_ENA_V 0x1 -#define SENS_COCPU_SW_INT_ENA_S 7 -/* SENS_COCPU_START_INT_ENA : R/W ;bitpos:[6] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_START_INT_ENA (BIT(6)) -#define SENS_COCPU_START_INT_ENA_M (BIT(6)) -#define SENS_COCPU_START_INT_ENA_V 0x1 -#define SENS_COCPU_START_INT_ENA_S 6 -/* SENS_COCPU_TSENS_INT_ENA : R/W ;bitpos:[5] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TSENS_INT_ENA (BIT(5)) -#define SENS_COCPU_TSENS_INT_ENA_M (BIT(5)) -#define SENS_COCPU_TSENS_INT_ENA_V 0x1 -#define SENS_COCPU_TSENS_INT_ENA_S 5 -/* SENS_COCPU_SENS2_INT_ENA : R/W ;bitpos:[4] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SENS2_INT_ENA (BIT(4)) -#define SENS_COCPU_SENS2_INT_ENA_M (BIT(4)) -#define SENS_COCPU_SENS2_INT_ENA_V 0x1 -#define SENS_COCPU_SENS2_INT_ENA_S 4 -/* SENS_COCPU_SENS1_INT_ENA : R/W ;bitpos:[3] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SENS1_INT_ENA (BIT(3)) -#define SENS_COCPU_SENS1_INT_ENA_M (BIT(3)) -#define SENS_COCPU_SENS1_INT_ENA_V 0x1 -#define SENS_COCPU_SENS1_INT_ENA_S 3 -/* SENS_COCPU_TOUCH_ACTIVE_INT_ENA : R/W ;bitpos:[2] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA_M (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA_V 0x1 -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA_S 2 -/* SENS_COCPU_TOUCH_INACTIVE_INT_ENA : R/W ;bitpos:[1] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA_M (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA_V 0x1 -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA_S 1 -/* SENS_COCPU_TOUCH_DONE_INT_ENA : R/W ;bitpos:[0] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_DONE_INT_ENA (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_ENA_M (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_ENA_V 0x1 -#define SENS_COCPU_TOUCH_DONE_INT_ENA_S 0 - -#define SENS_SAR_COCPU_INT_ST_REG (DR_REG_SENS_BASE + 0x0130) -/* SENS_COCPU_TOUCH_SCAN_DONE_INT_ST : RO ;bitpos:[11] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ST (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ST_M (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ST_V 0x1 -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ST_S 11 -/* SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ST : RO ;bitpos:[10] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ST (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ST_M (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ST_V 0x1 -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ST_S 10 -/* SENS_COCPU_TOUCH_TIMEOUT_INT_ST : RO ;bitpos:[9] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ST (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ST_M (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ST_V 0x1 -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ST_S 9 -/* SENS_COCPU_SWD_INT_ST : RO ;bitpos:[8] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SWD_INT_ST (BIT(8)) -#define SENS_COCPU_SWD_INT_ST_M (BIT(8)) -#define SENS_COCPU_SWD_INT_ST_V 0x1 -#define SENS_COCPU_SWD_INT_ST_S 8 -/* SENS_COCPU_SW_INT_ST : RO ;bitpos:[7] ;default: 1'b0 ; */ -/*description: cocpu int status*/ -#define SENS_COCPU_SW_INT_ST (BIT(7)) -#define SENS_COCPU_SW_INT_ST_M (BIT(7)) -#define SENS_COCPU_SW_INT_ST_V 0x1 -#define SENS_COCPU_SW_INT_ST_S 7 -/* SENS_COCPU_START_INT_ST : RO ;bitpos:[6] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_START_INT_ST (BIT(6)) -#define SENS_COCPU_START_INT_ST_M (BIT(6)) -#define SENS_COCPU_START_INT_ST_V 0x1 -#define SENS_COCPU_START_INT_ST_S 6 -/* SENS_COCPU_TSENS_INT_ST : RO ;bitpos:[5] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TSENS_INT_ST (BIT(5)) -#define SENS_COCPU_TSENS_INT_ST_M (BIT(5)) -#define SENS_COCPU_TSENS_INT_ST_V 0x1 -#define SENS_COCPU_TSENS_INT_ST_S 5 -/* SENS_COCPU_SENS2_INT_ST : RO ;bitpos:[4] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SENS2_INT_ST (BIT(4)) -#define SENS_COCPU_SENS2_INT_ST_M (BIT(4)) -#define SENS_COCPU_SENS2_INT_ST_V 0x1 -#define SENS_COCPU_SENS2_INT_ST_S 4 -/* SENS_COCPU_SENS1_INT_ST : RO ;bitpos:[3] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SENS1_INT_ST (BIT(3)) -#define SENS_COCPU_SENS1_INT_ST_M (BIT(3)) -#define SENS_COCPU_SENS1_INT_ST_V 0x1 -#define SENS_COCPU_SENS1_INT_ST_S 3 -/* SENS_COCPU_TOUCH_ACTIVE_INT_ST : RO ;bitpos:[2] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_ACTIVE_INT_ST (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_ST_M (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_ST_V 0x1 -#define SENS_COCPU_TOUCH_ACTIVE_INT_ST_S 2 -/* SENS_COCPU_TOUCH_INACTIVE_INT_ST : RO ;bitpos:[1] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_INACTIVE_INT_ST (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_ST_M (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_ST_V 0x1 -#define SENS_COCPU_TOUCH_INACTIVE_INT_ST_S 1 -/* SENS_COCPU_TOUCH_DONE_INT_ST : RO ;bitpos:[0] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_DONE_INT_ST (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_ST_M (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_ST_V 0x1 -#define SENS_COCPU_TOUCH_DONE_INT_ST_S 0 - -#define SENS_SAR_COCPU_INT_CLR_REG (DR_REG_SENS_BASE + 0x0134) -/* SENS_COCPU_TOUCH_SCAN_DONE_INT_CLR : WO ;bitpos:[11] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_CLR (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_CLR_M (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_CLR_V 0x1 -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_CLR_S 11 -/* SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_CLR : WO ;bitpos:[10] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_CLR (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_CLR_M (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_CLR_V 0x1 -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_CLR_S 10 -/* SENS_COCPU_TOUCH_TIMEOUT_INT_CLR : WO ;bitpos:[9] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_TIMEOUT_INT_CLR (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_CLR_M (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_CLR_V 0x1 -#define SENS_COCPU_TOUCH_TIMEOUT_INT_CLR_S 9 -/* SENS_COCPU_SWD_INT_CLR : WO ;bitpos:[8] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SWD_INT_CLR (BIT(8)) -#define SENS_COCPU_SWD_INT_CLR_M (BIT(8)) -#define SENS_COCPU_SWD_INT_CLR_V 0x1 -#define SENS_COCPU_SWD_INT_CLR_S 8 -/* SENS_COCPU_SW_INT_CLR : WO ;bitpos:[7] ;default: 1'b0 ; */ -/*description: cocpu int clear*/ -#define SENS_COCPU_SW_INT_CLR (BIT(7)) -#define SENS_COCPU_SW_INT_CLR_M (BIT(7)) -#define SENS_COCPU_SW_INT_CLR_V 0x1 -#define SENS_COCPU_SW_INT_CLR_S 7 -/* SENS_COCPU_START_INT_CLR : WO ;bitpos:[6] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_START_INT_CLR (BIT(6)) -#define SENS_COCPU_START_INT_CLR_M (BIT(6)) -#define SENS_COCPU_START_INT_CLR_V 0x1 -#define SENS_COCPU_START_INT_CLR_S 6 -/* SENS_COCPU_TSENS_INT_CLR : WO ;bitpos:[5] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TSENS_INT_CLR (BIT(5)) -#define SENS_COCPU_TSENS_INT_CLR_M (BIT(5)) -#define SENS_COCPU_TSENS_INT_CLR_V 0x1 -#define SENS_COCPU_TSENS_INT_CLR_S 5 -/* SENS_COCPU_SENS2_INT_CLR : WO ;bitpos:[4] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SENS2_INT_CLR (BIT(4)) -#define SENS_COCPU_SENS2_INT_CLR_M (BIT(4)) -#define SENS_COCPU_SENS2_INT_CLR_V 0x1 -#define SENS_COCPU_SENS2_INT_CLR_S 4 -/* SENS_COCPU_SENS1_INT_CLR : WO ;bitpos:[3] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SENS1_INT_CLR (BIT(3)) -#define SENS_COCPU_SENS1_INT_CLR_M (BIT(3)) -#define SENS_COCPU_SENS1_INT_CLR_V 0x1 -#define SENS_COCPU_SENS1_INT_CLR_S 3 -/* SENS_COCPU_TOUCH_ACTIVE_INT_CLR : WO ;bitpos:[2] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_ACTIVE_INT_CLR (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_CLR_M (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_CLR_V 0x1 -#define SENS_COCPU_TOUCH_ACTIVE_INT_CLR_S 2 -/* SENS_COCPU_TOUCH_INACTIVE_INT_CLR : WO ;bitpos:[1] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_INACTIVE_INT_CLR (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_CLR_M (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_CLR_V 0x1 -#define SENS_COCPU_TOUCH_INACTIVE_INT_CLR_S 1 -/* SENS_COCPU_TOUCH_DONE_INT_CLR : WO ;bitpos:[0] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_DONE_INT_CLR (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_CLR_M (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_CLR_V 0x1 -#define SENS_COCPU_TOUCH_DONE_INT_CLR_S 0 - -#define SENS_SAR_COCPU_DEBUG_REG (DR_REG_SENS_BASE + 0x0138) -/* SENS_COCPU_MEM_ADDR : RO ;bitpos:[31:19] ;default: 13'd0 ; */ -/*description: cocpu mem address output*/ -#define SENS_COCPU_MEM_ADDR 0x00001FFF -#define SENS_COCPU_MEM_ADDR_M ((SENS_COCPU_MEM_ADDR_V)<<(SENS_COCPU_MEM_ADDR_S)) -#define SENS_COCPU_MEM_ADDR_V 0x1FFF -#define SENS_COCPU_MEM_ADDR_S 19 -/* SENS_COCPU_MEM_WEN : RO ;bitpos:[18:15] ;default: 4'd0 ; */ -/*description: cocpu mem write enable output*/ -#define SENS_COCPU_MEM_WEN 0x0000000F -#define SENS_COCPU_MEM_WEN_M ((SENS_COCPU_MEM_WEN_V)<<(SENS_COCPU_MEM_WEN_S)) -#define SENS_COCPU_MEM_WEN_V 0xF -#define SENS_COCPU_MEM_WEN_S 15 -/* SENS_COCPU_MEM_RDY : RO ;bitpos:[14] ;default: 1'b0 ; */ -/*description: cocpu mem ready input*/ -#define SENS_COCPU_MEM_RDY (BIT(14)) -#define SENS_COCPU_MEM_RDY_M (BIT(14)) -#define SENS_COCPU_MEM_RDY_V 0x1 -#define SENS_COCPU_MEM_RDY_S 14 -/* SENS_COCPU_MEM_VLD : RO ;bitpos:[13] ;default: 1'b0 ; */ -/*description: cocpu mem valid output*/ -#define SENS_COCPU_MEM_VLD (BIT(13)) -#define SENS_COCPU_MEM_VLD_M (BIT(13)) -#define SENS_COCPU_MEM_VLD_V 0x1 -#define SENS_COCPU_MEM_VLD_S 13 -/* SENS_COCPU_PC : RO ;bitpos:[12:0] ;default: 13'd0 ; */ -/*description: cocpu Program counter*/ -#define SENS_COCPU_PC 0x00001FFF -#define SENS_COCPU_PC_M ((SENS_COCPU_PC_V)<<(SENS_COCPU_PC_S)) -#define SENS_COCPU_PC_V 0x1FFF -#define SENS_COCPU_PC_S 0 - -#define SENS_SAR_HALL_CTRL_REG (DR_REG_SENS_BASE + 0x013c) -/* SENS_HALL_PHASE_FORCE : R/W ;bitpos:[31] ;default: 1'b1 ; */ -/*description: 1: HALL PHASE is controlled by SW 0: HALL PHASE is controlled - by FSM in ULP-coprocessor*/ -#define SENS_HALL_PHASE_FORCE (BIT(31)) -#define SENS_HALL_PHASE_FORCE_M (BIT(31)) -#define SENS_HALL_PHASE_FORCE_V 0x1 -#define SENS_HALL_PHASE_FORCE_S 31 -/* SENS_HALL_PHASE : R/W ;bitpos:[30] ;default: 1'b0 ; */ -/*description: Reverse phase of hall sensor*/ -#define SENS_HALL_PHASE (BIT(30)) -#define SENS_HALL_PHASE_M (BIT(30)) -#define SENS_HALL_PHASE_V 0x1 -#define SENS_HALL_PHASE_S 30 -/* SENS_XPD_HALL_FORCE : R/W ;bitpos:[29] ;default: 1'b1 ; */ -/*description: 1: XPD HALL is controlled by SW. 0: XPD HALL is controlled by - FSM in ULP-coprocessor*/ -#define SENS_XPD_HALL_FORCE (BIT(29)) -#define SENS_XPD_HALL_FORCE_M (BIT(29)) -#define SENS_XPD_HALL_FORCE_V 0x1 -#define SENS_XPD_HALL_FORCE_S 29 -/* SENS_XPD_HALL : R/W ;bitpos:[28] ;default: 1'b0 ; */ -/*description: Power on hall sensor and connect to VP and VN*/ -#define SENS_XPD_HALL (BIT(28)) -#define SENS_XPD_HALL_M (BIT(28)) -#define SENS_XPD_HALL_V 0x1 -#define SENS_XPD_HALL_S 28 - -#define SENS_SAR_NOUSE_REG (DR_REG_SENS_BASE + 0x0140) -/* SENS_SAR_NOUSE : R/W ;bitpos:[31:0] ;default: 32'h0 ; */ -/*description: */ -#define SENS_SAR_NOUSE 0xFFFFFFFF -#define SENS_SAR_NOUSE_M ((SENS_SAR_NOUSE_V)<<(SENS_SAR_NOUSE_S)) -#define SENS_SAR_NOUSE_V 0xFFFFFFFF -#define SENS_SAR_NOUSE_S 0 - -#define SENS_SAR_PERI_CLK_GATE_CONF_REG (DR_REG_SENS_BASE + 0x0144) -/* SENS_IOMUX_CLK_EN : R/W ;bitpos:[31] ;default: 1'd0 ; */ -/*description: */ -#define SENS_IOMUX_CLK_EN (BIT(31)) -#define SENS_IOMUX_CLK_EN_M (BIT(31)) -#define SENS_IOMUX_CLK_EN_V 0x1 -#define SENS_IOMUX_CLK_EN_S 31 -/* SENS_CLK_EN : R/W ;bitpos:[30] ;default: 1'b0 ; */ -/*description: */ -#define SENS_CLK_EN (BIT(30)) -#define SENS_CLK_EN_M (BIT(30)) -#define SENS_CLK_EN_V 0x1 -#define SENS_CLK_EN_S 30 -/* SENS_TSENS_CLK_EN : R/W ;bitpos:[29] ;default: 1'b0 ; */ -/*description: */ -#define SENS_TSENS_CLK_EN (BIT(29)) -#define SENS_TSENS_CLK_EN_M (BIT(29)) -#define SENS_TSENS_CLK_EN_V 0x1 -#define SENS_TSENS_CLK_EN_S 29 -/* SENS_RTC_I2C_CLK_EN : R/W ;bitpos:[27] ;default: 1'b0 ; */ -/*description: */ -#define SENS_RTC_I2C_CLK_EN (BIT(27)) -#define SENS_RTC_I2C_CLK_EN_M (BIT(27)) -#define SENS_RTC_I2C_CLK_EN_V 0x1 -#define SENS_RTC_I2C_CLK_EN_S 27 -/* SENS_DAC_CLK_EN : R/W ;bitpos:[26] ;default: 1'b0 ; */ -/*description: */ -#define SENS_DAC_CLK_EN (BIT(26)) -#define SENS_DAC_CLK_EN_M (BIT(26)) -#define SENS_DAC_CLK_EN_V 0x1 -#define SENS_DAC_CLK_EN_S 26 - -#define SENS_SAR_PERI_RESET_CONF_REG (DR_REG_SENS_BASE + 0x0148) -/* SENS_RESET : R/W ;bitpos:[30] ;default: 1'b0 ; */ -/*description: */ -#define SENS_RESET (BIT(30)) -#define SENS_RESET_M (BIT(30)) -#define SENS_RESET_V 0x1 -#define SENS_RESET_S 30 -/* SENS_TSENS_RESET : R/W ;bitpos:[29] ;default: 1'b0 ; */ -/*description: */ -#define SENS_TSENS_RESET (BIT(29)) -#define SENS_TSENS_RESET_M (BIT(29)) -#define SENS_TSENS_RESET_V 0x1 -#define SENS_TSENS_RESET_S 29 -#define SENS_FORCE_XPD_SAR_SW_M (BIT1) -#define SENS_FORCE_XPD_SAR_FSM 0 // Use FSM to control power down -#define SENS_FORCE_XPD_SAR_PD 2 // Force power down -#define SENS_FORCE_XPD_SAR_PU 3 // Force power up -/* SENS_RTC_I2C_RESET : R/W ;bitpos:[27] ;default: 1'b0 ; */ -/*description: */ -#define SENS_RTC_I2C_RESET (BIT(27)) -#define SENS_RTC_I2C_RESET_M (BIT(27)) -#define SENS_RTC_I2C_RESET_V 0x1 -#define SENS_RTC_I2C_RESET_S 27 -/* SENS_DAC_RESET : R/W ;bitpos:[26] ;default: 1'b0 ; */ -/*description: */ -#define SENS_DAC_RESET (BIT(26)) -#define SENS_DAC_RESET_M (BIT(26)) -#define SENS_DAC_RESET_V 0x1 -#define SENS_DAC_RESET_S 26 -/* SENS_COCPU_RESET : R/W ;bitpos:[25] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_RESET (BIT(25)) -#define SENS_COCPU_RESET_M (BIT(25)) -#define SENS_COCPU_RESET_V 0x1 -#define SENS_COCPU_RESET_S 25 - -#define SENS_SAR_COCPU_INT_ENA_W1TS_REG (DR_REG_SENS_BASE + 0x014c) -/* SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_W1TS : WO ;bitpos:[11] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_W1TS (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_W1TS_M (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_W1TS_S 11 -/* SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_W1TS : WO ;bitpos:[10] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_W1TS (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_W1TS_M (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_W1TS_S 10 -/* SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_W1TS : WO ;bitpos:[9] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_W1TS (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_W1TS_M (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_W1TS_S 9 -/* SENS_COCPU_SWD_INT_ENA_W1TS : WO ;bitpos:[8] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SWD_INT_ENA_W1TS (BIT(8)) -#define SENS_COCPU_SWD_INT_ENA_W1TS_M (BIT(8)) -#define SENS_COCPU_SWD_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_SWD_INT_ENA_W1TS_S 8 -/* SENS_COCPU_SW_INT_ENA_W1TS : WO ;bitpos:[7] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SW_INT_ENA_W1TS (BIT(7)) -#define SENS_COCPU_SW_INT_ENA_W1TS_M (BIT(7)) -#define SENS_COCPU_SW_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_SW_INT_ENA_W1TS_S 7 -/* SENS_COCPU_START_INT_ENA_W1TS : WO ;bitpos:[6] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_START_INT_ENA_W1TS (BIT(6)) -#define SENS_COCPU_START_INT_ENA_W1TS_M (BIT(6)) -#define SENS_COCPU_START_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_START_INT_ENA_W1TS_S 6 -/* SENS_COCPU_TSENS_INT_ENA_W1TS : WO ;bitpos:[5] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TSENS_INT_ENA_W1TS (BIT(5)) -#define SENS_COCPU_TSENS_INT_ENA_W1TS_M (BIT(5)) -#define SENS_COCPU_TSENS_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_TSENS_INT_ENA_W1TS_S 5 -/* SENS_COCPU_SENS2_INT_ENA_W1TS : WO ;bitpos:[4] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SENS2_INT_ENA_W1TS (BIT(4)) -#define SENS_COCPU_SENS2_INT_ENA_W1TS_M (BIT(4)) -#define SENS_COCPU_SENS2_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_SENS2_INT_ENA_W1TS_S 4 -/* SENS_COCPU_SENS1_INT_ENA_W1TS : WO ;bitpos:[3] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SENS1_INT_ENA_W1TS (BIT(3)) -#define SENS_COCPU_SENS1_INT_ENA_W1TS_M (BIT(3)) -#define SENS_COCPU_SENS1_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_SENS1_INT_ENA_W1TS_S 3 -/* SENS_COCPU_TOUCH_ACTIVE_INT_ENA_W1TS : WO ;bitpos:[2] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA_W1TS (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA_W1TS_M (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA_W1TS_S 2 -/* SENS_COCPU_TOUCH_INACTIVE_INT_ENA_W1TS : WO ;bitpos:[1] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA_W1TS (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA_W1TS_M (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA_W1TS_S 1 -/* SENS_COCPU_TOUCH_DONE_INT_ENA_W1TS : WO ;bitpos:[0] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_DONE_INT_ENA_W1TS (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_ENA_W1TS_M (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_ENA_W1TS_V 0x1 -#define SENS_COCPU_TOUCH_DONE_INT_ENA_W1TS_S 0 - -#define SENS_SAR_COCPU_INT_ENA_W1TC_REG (DR_REG_SENS_BASE + 0x0150) -/* SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_W1TC : WO ;bitpos:[11] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_W1TC (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_W1TC_M (BIT(11)) -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_TOUCH_SCAN_DONE_INT_ENA_W1TC_S 11 -/* SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_W1TC : WO ;bitpos:[10] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_W1TC (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_W1TC_M (BIT(10)) -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_TOUCH_APPROACH_LOOP_DONE_INT_ENA_W1TC_S 10 -/* SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_W1TC : WO ;bitpos:[9] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_W1TC (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_W1TC_M (BIT(9)) -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_TOUCH_TIMEOUT_INT_ENA_W1TC_S 9 -/* SENS_COCPU_SWD_INT_ENA_W1TC : WO ;bitpos:[8] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SWD_INT_ENA_W1TC (BIT(8)) -#define SENS_COCPU_SWD_INT_ENA_W1TC_M (BIT(8)) -#define SENS_COCPU_SWD_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_SWD_INT_ENA_W1TC_S 8 -/* SENS_COCPU_SW_INT_ENA_W1TC : WO ;bitpos:[7] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SW_INT_ENA_W1TC (BIT(7)) -#define SENS_COCPU_SW_INT_ENA_W1TC_M (BIT(7)) -#define SENS_COCPU_SW_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_SW_INT_ENA_W1TC_S 7 -/* SENS_COCPU_START_INT_ENA_W1TC : WO ;bitpos:[6] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_START_INT_ENA_W1TC (BIT(6)) -#define SENS_COCPU_START_INT_ENA_W1TC_M (BIT(6)) -#define SENS_COCPU_START_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_START_INT_ENA_W1TC_S 6 -/* SENS_COCPU_TSENS_INT_ENA_W1TC : WO ;bitpos:[5] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TSENS_INT_ENA_W1TC (BIT(5)) -#define SENS_COCPU_TSENS_INT_ENA_W1TC_M (BIT(5)) -#define SENS_COCPU_TSENS_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_TSENS_INT_ENA_W1TC_S 5 -/* SENS_COCPU_SENS2_INT_ENA_W1TC : WO ;bitpos:[4] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SENS2_INT_ENA_W1TC (BIT(4)) -#define SENS_COCPU_SENS2_INT_ENA_W1TC_M (BIT(4)) -#define SENS_COCPU_SENS2_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_SENS2_INT_ENA_W1TC_S 4 -/* SENS_COCPU_SENS1_INT_ENA_W1TC : WO ;bitpos:[3] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SENS1_INT_ENA_W1TC (BIT(3)) -#define SENS_COCPU_SENS1_INT_ENA_W1TC_M (BIT(3)) -#define SENS_COCPU_SENS1_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_SENS1_INT_ENA_W1TC_S 3 -/* SENS_COCPU_TOUCH_ACTIVE_INT_ENA_W1TC : WO ;bitpos:[2] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA_W1TC (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA_W1TC_M (BIT(2)) -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_TOUCH_ACTIVE_INT_ENA_W1TC_S 2 -/* SENS_COCPU_TOUCH_INACTIVE_INT_ENA_W1TC : WO ;bitpos:[1] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA_W1TC (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA_W1TC_M (BIT(1)) -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_TOUCH_INACTIVE_INT_ENA_W1TC_S 1 -/* SENS_COCPU_TOUCH_DONE_INT_ENA_W1TC : WO ;bitpos:[0] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TOUCH_DONE_INT_ENA_W1TC (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_ENA_W1TC_M (BIT(0)) -#define SENS_COCPU_TOUCH_DONE_INT_ENA_W1TC_V 0x1 -#define SENS_COCPU_TOUCH_DONE_INT_ENA_W1TC_S 0 - -#define SENS_SARDATE_REG (DR_REG_SENS_BASE + 0x0154) -/* SENS_SAR_DATE : R/W ;bitpos:[27:0] ;default: 28'h1909160 ; */ -/*description: */ -#define SENS_SAR_DATE 0x0FFFFFFF -#define SENS_SAR_DATE_M ((SENS_SAR_DATE_V)<<(SENS_SAR_DATE_S)) -#define SENS_SAR_DATE_V 0xFFFFFFF -#define SENS_SAR_DATE_S 0 - -#ifdef __cplusplus -} -#endif - - - -#endif /*_SOC_SENS_REG_H_ */ diff --git a/components/soc/esp32c3/include/soc/sens_struct.h b/components/soc/esp32c3/include/soc/sens_struct.h deleted file mode 100644 index 4a084b9111..0000000000 --- a/components/soc/esp32c3/include/soc/sens_struct.h +++ /dev/null @@ -1,504 +0,0 @@ -// Copyright 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. -#ifndef _SOC_SENS_STRUCT_H_ -#define _SOC_SENS_STRUCT_H_ -#ifdef __cplusplus -extern "C" { -#endif - -typedef volatile struct { - union { - struct { - uint32_t sar1_clk_div: 8; /*clock divider*/ - uint32_t reserved8: 10; - uint32_t sar1_clk_gated: 1; - uint32_t sar1_sample_num: 8; - uint32_t reserved27: 1; - uint32_t sar1_data_inv: 1; /*Invert SAR ADC1 data*/ - uint32_t sar1_int_en: 1; /*enable saradc1 to send out interrupt*/ - uint32_t reserved30: 2; - }; - uint32_t val; - } sar_reader1_ctrl; - uint32_t sar_reader1_status; /**/ - union { - struct { - uint32_t reserved0: 24; - uint32_t force_xpd_amp: 2; - uint32_t amp_rst_fb_force: 2; - uint32_t amp_short_ref_force: 2; - uint32_t amp_short_ref_gnd_force: 2; - }; - uint32_t val; - } sar_meas1_ctrl1; - union { - struct { - uint32_t meas1_data_sar: 16; /*SAR ADC1 data*/ - uint32_t meas1_done_sar: 1; /*SAR ADC1 conversion done indication*/ - uint32_t meas1_start_sar: 1; /*SAR ADC1 controller (in RTC) starts conversion*/ - uint32_t meas1_start_force: 1; /*1: SAR ADC1 controller (in RTC) is started by SW*/ - uint32_t sar1_en_pad: 12; /*SAR ADC1 pad enable bitmap*/ - uint32_t sar1_en_pad_force: 1; /*1: SAR ADC1 pad enable bitmap is controlled by SW*/ - }; - uint32_t val; - } sar_meas1_ctrl2; - union { - struct { - uint32_t reserved0: 31; - uint32_t sar1_dig_force: 1; /*1: SAR ADC1 controlled by DIG ADC1 CTRL*/ - }; - uint32_t val; - } sar_meas1_mux; - uint32_t sar_atten1; /*2-bit attenuation for each pad*/ - union { - struct { - uint32_t sar_amp_wait1:16; - uint32_t sar_amp_wait2:16; - }; - uint32_t val; - } sar_amp_ctrl1; - union { - struct { - uint32_t sar1_dac_xpd_fsm_idle: 1; - uint32_t xpd_sar_amp_fsm_idle: 1; - uint32_t amp_rst_fb_fsm_idle: 1; - uint32_t amp_short_ref_fsm_idle: 1; - uint32_t amp_short_ref_gnd_fsm_idle: 1; - uint32_t xpd_sar_fsm_idle: 1; - uint32_t sar_rstb_fsm_idle: 1; - uint32_t reserved7: 9; - uint32_t sar_amp_wait3: 16; - }; - uint32_t val; - } sar_amp_ctrl2; - union { - struct { - uint32_t sar1_dac_xpd_fsm: 4; - uint32_t xpd_sar_amp_fsm: 4; - uint32_t amp_rst_fb_fsm: 4; - uint32_t amp_short_ref_fsm: 4; - uint32_t amp_short_ref_gnd_fsm: 4; - uint32_t xpd_sar_fsm: 4; - uint32_t sar_rstb_fsm: 4; - uint32_t reserved28: 4; - }; - uint32_t val; - } sar_amp_ctrl3; - union { - struct { - uint32_t sar2_clk_div: 8; /*clock divider*/ - uint32_t reserved8: 8; - uint32_t sar2_wait_arb_cycle: 2; /*wait arbit stable after sar_done*/ - uint32_t sar2_clk_gated: 1; - uint32_t sar2_sample_num: 8; - uint32_t reserved27: 2; - uint32_t sar2_data_inv: 1; /*Invert SAR ADC2 data*/ - uint32_t sar2_int_en: 1; /*enable saradc2 to send out interrupt*/ - uint32_t reserved31: 1; - }; - uint32_t val; - } sar_reader2_ctrl; - uint32_t sar_reader2_status; /**/ - union { - struct { - uint32_t sar2_cntl_state: 3; /*saradc2_cntl_fsm*/ - uint32_t sar2_pwdet_cal_en: 1; /*rtc control pwdet enable*/ - uint32_t sar2_pkdet_cal_en: 1; /*rtc control pkdet enable*/ - uint32_t sar2_en_test: 1; /*SAR2_EN_TEST*/ - uint32_t sar2_rstb_force: 2; - uint32_t sar2_standby_wait: 8; - uint32_t sar2_rstb_wait: 8; - uint32_t sar2_xpd_wait: 8; - }; - uint32_t val; - } sar_meas2_ctrl1; - union { - struct { - uint32_t meas2_data_sar: 16; /*SAR ADC2 data*/ - uint32_t meas2_done_sar: 1; /*SAR ADC2 conversion done indication*/ - uint32_t meas2_start_sar: 1; /*SAR ADC2 controller (in RTC) starts conversion*/ - uint32_t meas2_start_force: 1; /*1: SAR ADC2 controller (in RTC) is started by SW*/ - uint32_t sar2_en_pad: 12; /*SAR ADC2 pad enable bitmap*/ - uint32_t sar2_en_pad_force: 1; /*1: SAR ADC2 pad enable bitmap is controlled by SW*/ - }; - uint32_t val; - } sar_meas2_ctrl2; - union { - struct { - uint32_t reserved0: 28; - uint32_t sar2_pwdet_cct: 3; /*SAR2_PWDET_CCT*/ - uint32_t sar2_rtc_force: 1; /*in sleep force to use rtc to control ADC*/ - }; - uint32_t val; - } sar_meas2_mux; - uint32_t sar_atten2; /*2-bit attenuation for each pad*/ - union { - struct { - uint32_t reserved0: 29; - uint32_t force_xpd_sar: 2; - uint32_t sarclk_en: 1; - }; - uint32_t val; - } sar_power_xpd_sar; - union { - struct { - uint32_t i2c_slave_addr1: 11; - uint32_t i2c_slave_addr0: 11; - uint32_t meas_status: 8; - uint32_t reserved30: 2; - }; - uint32_t val; - } sar_slave_addr1; - union { - struct { - uint32_t i2c_slave_addr3:11; - uint32_t i2c_slave_addr2:11; - uint32_t reserved22: 10; - }; - uint32_t val; - } sar_slave_addr2; - union { - struct { - uint32_t i2c_slave_addr5:11; - uint32_t i2c_slave_addr4:11; - uint32_t reserved22: 10; - }; - uint32_t val; - } sar_slave_addr3; - union { - struct { - uint32_t i2c_slave_addr7:11; - uint32_t i2c_slave_addr6:11; - uint32_t reserved22: 10; - }; - uint32_t val; - } sar_slave_addr4; - union { - struct { - uint32_t tsens_out: 8; /*temperature sensor data out*/ - uint32_t tsens_ready: 1; /*indicate temperature sensor out ready*/ - uint32_t reserved9: 3; - uint32_t tsens_int_en: 1; /*enable temperature sensor to send out interrupt*/ - uint32_t tsens_in_inv: 1; /*invert temperature sensor data*/ - uint32_t tsens_clk_div: 8; /*temperature sensor clock divider*/ - uint32_t tsens_power_up: 1; /*temperature sensor power up*/ - uint32_t tsens_power_up_force: 1; /*1: dump out & power up controlled by SW*/ - uint32_t tsens_dump_out: 1; /*temperature sensor dump out*/ - uint32_t reserved25: 7; - }; - uint32_t val; - } sar_tctrl; - union { - struct { - uint32_t tsens_xpd_wait: 12; - uint32_t tsens_xpd_force: 2; - uint32_t tsens_clk_inv: 1; - uint32_t reserved15: 17; - }; - uint32_t val; - } sar_tctrl2; - union { - struct { - uint32_t sar_i2c_ctrl: 28; /*I2C control data*/ - uint32_t sar_i2c_start: 1; /*start I2C*/ - uint32_t sar_i2c_start_force: 1; /*1: I2C started by SW*/ - uint32_t reserved30: 2; - }; - uint32_t val; - } sar_i2c_ctrl; - union { - struct { - uint32_t touch_outen: 15; /*touch controller output enable*/ - uint32_t touch_status_clr: 1; /*clear all touch active status*/ - uint32_t touch_data_sel: 2; /*3: smooth data 2: baseline 1 0: raw_data*/ - uint32_t touch_denoise_end: 1; /*touch_denoise_done*/ - uint32_t touch_unit_end: 1; /*touch_unit_done*/ - uint32_t touch_approach_pad2: 4; /*indicate which pad is approach pad2*/ - uint32_t touch_approach_pad1: 4; /*indicate which pad is approach pad1*/ - uint32_t touch_approach_pad0: 4; /*indicate which pad is approach pad0*/ - }; - uint32_t val; - } sar_touch_conf; - union { - struct { - uint32_t thresh: 22; /*Finger threshold for touch pad 1*/ - uint32_t reserved22: 10; - }; - uint32_t val; - } touch_thresh[14]; - uint32_t reserved_98; - uint32_t reserved_9c; - uint32_t reserved_a0; - uint32_t reserved_a4; - uint32_t reserved_a8; - uint32_t reserved_ac; - uint32_t reserved_b0; - uint32_t reserved_b4; - uint32_t reserved_b8; - uint32_t reserved_bc; - uint32_t reserved_c0; - uint32_t reserved_c4; - uint32_t reserved_c8; - uint32_t reserved_cc; - uint32_t reserved_d0; - union { - struct { - uint32_t touch_pad_active: 15; /*touch active status*/ - uint32_t touch_channel_clr:15; /*Clear touch channel*/ - uint32_t reserved30: 1; - uint32_t touch_meas_done: 1; - }; - uint32_t val; - } sar_touch_chn_st; - union { - struct { - uint32_t touch_denoise_data:22; /*the counter for touch pad 0*/ - uint32_t touch_scan_curr: 4; - uint32_t reserved26: 6; - }; - uint32_t val; - } sar_touch_status0; - union { - struct { - uint32_t touch_pad1_data: 22; - uint32_t reserved22: 7; - uint32_t touch_pad_debounce: 3; - }; - uint32_t val; - } sar_touch_status[14]; - union { - struct { - uint32_t touch_slp_data: 22; - uint32_t reserved22: 7; - uint32_t touch_slp_debounce: 3; - }; - uint32_t val; - } sar_touch_status15; - union { - struct { - uint32_t touch_approach_pad2_cnt: 8; - uint32_t touch_approach_pad1_cnt: 8; - uint32_t touch_approach_pad0_cnt: 8; - uint32_t touch_slp_approach_cnt: 8; - }; - uint32_t val; - } sar_touch_status16; - union { - struct { - uint32_t sw_fstep: 16; /*frequency step for CW generator*/ - uint32_t sw_tone_en: 1; /*1: enable CW generator*/ - uint32_t debug_bit_sel: 5; - uint32_t dac_dig_force: 1; /*1: DAC1 & DAC2 use DMA*/ - uint32_t dac_clk_force_low: 1; /*1: force PDAC_CLK to low*/ - uint32_t dac_clk_force_high: 1; /*1: force PDAC_CLK to high*/ - uint32_t dac_clk_inv: 1; /*1: invert PDAC_CLK*/ - uint32_t reserved26: 6; - }; - uint32_t val; - } sar_dac_ctrl1; - union { - struct { - uint32_t dac_dc1: 8; /*DC offset for DAC1 CW generator*/ - uint32_t dac_dc2: 8; /*DC offset for DAC2 CW generator*/ - uint32_t dac_scale1: 2; /*00: no scale*/ - uint32_t dac_scale2: 2; /*00: no scale*/ - uint32_t dac_inv1: 2; /*00: do not invert any bits*/ - uint32_t dac_inv2: 2; /*00: do not invert any bits*/ - uint32_t dac_cw_en1: 1; /*1: to select CW generator as source to PDAC1_DAC[7:0]*/ - uint32_t dac_cw_en2: 1; /*1: to select CW generator as source to PDAC2_DAC[7:0]*/ - uint32_t reserved26: 6; - }; - uint32_t val; - } sar_dac_ctrl2; - union { - struct { - uint32_t reserved0: 25; - uint32_t dbg_trigger: 1; /*trigger cocpu debug registers*/ - uint32_t clk_en_st: 1; /*check cocpu whether clk on*/ - uint32_t reset_n: 1; /*check cocpu whether in reset state*/ - uint32_t eoi: 1; /*check cocpu whether in interrupt state*/ - uint32_t trap: 1; /*check cocpu whether in trap state*/ - uint32_t ebreak: 1; /*check cocpu whether in ebreak*/ - uint32_t reserved31: 1; - }; - uint32_t val; - } sar_cocpu_state; - union { - struct { - uint32_t touch_done: 1; /*int from touch done*/ - uint32_t touch_inactive: 1; /*int from touch inactive*/ - uint32_t touch_active: 1; /*int from touch active*/ - uint32_t saradc1: 1; /*int from saradc1*/ - uint32_t saradc2: 1; /*int from saradc2*/ - uint32_t tsens: 1; /*int from tsens*/ - uint32_t start: 1; /*int from start*/ - uint32_t sw: 1; /*int from software*/ - uint32_t swd: 1; /*int from super watch dog*/ - uint32_t touch_timeout: 1; - uint32_t touch_approach_loop_done: 1; - uint32_t touch_scan_done: 1; - uint32_t reserved12: 20; - }; - uint32_t val; - } sar_cocpu_int_raw; - union { - struct { - uint32_t touch_done: 1; - uint32_t touch_inactive: 1; - uint32_t touch_active: 1; - uint32_t saradc1: 1; - uint32_t saradc2: 1; - uint32_t tsens: 1; - uint32_t start: 1; - uint32_t sw: 1; /*cocpu int enable*/ - uint32_t swd: 1; - uint32_t touch_timeout: 1; - uint32_t touch_approach_loop_done: 1; - uint32_t touch_scan_done: 1; - uint32_t reserved12: 20; - }; - uint32_t val; - } sar_cocpu_int_ena; - union { - struct { - uint32_t touch_done: 1; - uint32_t touch_inactive: 1; - uint32_t touch_active: 1; - uint32_t saradc1: 1; - uint32_t saradc2: 1; - uint32_t tsens: 1; - uint32_t start: 1; - uint32_t sw: 1; /*cocpu int status*/ - uint32_t swd: 1; - uint32_t touch_timeout: 1; - uint32_t touch_approach_loop_done: 1; - uint32_t touch_scan_done: 1; - uint32_t reserved12: 20; - }; - uint32_t val; - } sar_cocpu_int_st; - union { - struct { - uint32_t touch_done: 1; - uint32_t touch_inactive: 1; - uint32_t touch_active: 1; - uint32_t saradc1: 1; - uint32_t saradc2: 1; - uint32_t tsens: 1; - uint32_t start: 1; - uint32_t sw: 1; /*cocpu int clear*/ - uint32_t swd: 1; - uint32_t touch_timeout: 1; - uint32_t touch_approach_loop_done: 1; - uint32_t touch_scan_done: 1; - uint32_t reserved12: 20; - }; - uint32_t val; - } sar_cocpu_int_clr; - union { - struct { - uint32_t pc: 13; /*cocpu Program counter*/ - uint32_t mem_vld: 1; /*cocpu mem valid output*/ - uint32_t mem_rdy: 1; /*cocpu mem ready input*/ - uint32_t mem_wen: 4; /*cocpu mem write enable output*/ - uint32_t mem_addr: 13; /*cocpu mem address output*/ - }; - uint32_t val; - } sar_cocpu_debug; - union { - struct { - uint32_t reserved0: 28; - uint32_t xpd_hall: 1; /*Power on hall sensor and connect to VP and VN*/ - uint32_t xpd_hall_force: 1; /*1: XPD HALL is controlled by SW. 0: XPD HALL is controlled by FSM in ULP-coprocessor*/ - uint32_t hall_phase: 1; /*Reverse phase of hall sensor*/ - uint32_t hall_phase_force: 1; /*1: HALL PHASE is controlled by SW 0: HALL PHASE is controlled by FSM in ULP-coprocessor*/ - }; - uint32_t val; - } sar_hall_ctrl; - uint32_t sar_nouse; /**/ - union { - struct { - uint32_t reserved0: 26; - uint32_t dac_clk_en: 1; - uint32_t rtc_i2c_clk_en: 1; - uint32_t reserved28: 1; - uint32_t tsens_clk_en: 1; - uint32_t saradc_clk_en: 1; - uint32_t iomux_clk_en: 1; - }; - uint32_t val; - } sar_peri_clk_gate_conf; - union { - struct { - uint32_t reserved0: 25; - uint32_t reset: 1; - uint32_t dac_reset: 1; - uint32_t rtc_i2c_reset: 1; - uint32_t reserved28: 1; - uint32_t tsens_reset: 1; - uint32_t saradc_reset: 1; - uint32_t reserved31: 1; - }; - uint32_t val; - } sar_peri_reset_conf; - union { - struct { - uint32_t touch_done_w1ts: 1; - uint32_t touch_inactive_w1ts: 1; - uint32_t touch_active_w1ts: 1; - uint32_t saradc1_w1ts: 1; - uint32_t saradc2_w1ts: 1; - uint32_t tsens_w1ts: 1; - uint32_t start_w1ts: 1; - uint32_t sw_w1ts: 1; - uint32_t swd_w1ts: 1; - uint32_t touch_timeout_w1ts: 1; - uint32_t touch_approach_loop_done_w1ts: 1; - uint32_t touch_scan_done_w1ts: 1; - uint32_t reserved12: 20; - }; - uint32_t val; - } sar_cocpu_int_ena_w1ts; - union { - struct { - uint32_t touch_done_w1tc: 1; - uint32_t touch_inactive_w1tc: 1; - uint32_t touch_active_w1tc: 1; - uint32_t saradc1_w1tc: 1; - uint32_t saradc2_w1tc: 1; - uint32_t tsens_w1tc: 1; - uint32_t start_w1tc: 1; - uint32_t sw_w1tc: 1; - uint32_t swd_w1tc: 1; - uint32_t touch_timeout_w1tc: 1; - uint32_t touch_approach_loop_done_w1tc: 1; - uint32_t touch_scan_done_w1tc: 1; - uint32_t reserved12: 20; - }; - uint32_t val; - } sar_cocpu_int_ena_w1tc; - union { - struct { - uint32_t sar_date: 28; - uint32_t reserved28: 4; - }; - uint32_t val; - } sardate; -} sens_dev_t; -extern sens_dev_t SENS; -#ifdef __cplusplus -} -#endif - -#endif /* _SOC_SENS_STRUCT_H_ */ diff --git a/components/soc/esp32c3/include/soc/soc_caps.h b/components/soc/esp32c3/include/soc/soc_caps.h index a236e2e6fc..fae89b8a41 100644 --- a/components/soc/esp32c3/include/soc/soc_caps.h +++ b/components/soc/esp32c3/include/soc/soc_caps.h @@ -104,9 +104,9 @@ /*-------------------------- ADC CAPS -------------------------------*/ #define SOC_ADC_PERIPH_NUM (2) #define SOC_ADC_PATT_LEN_MAX (16) - #define SOC_ADC_CHANNEL_NUM(PERIPH_NUM) ((PERIPH_NUM==0)? 5 : 1) #define SOC_ADC_MAX_CHANNEL_NUM (10) +#define SOC_ADC_MAX_BITWIDTH (12) /** * Check if adc support digital controller (DMA) mode. diff --git a/components/soc/esp32s2/include/soc/soc_caps.h b/components/soc/esp32s2/include/soc/soc_caps.h index 11454d5b2a..6368926b85 100644 --- a/components/soc/esp32s2/include/soc/soc_caps.h +++ b/components/soc/esp32s2/include/soc/soc_caps.h @@ -55,9 +55,9 @@ /*-------------------------- ADC CAPS ----------------------------------------*/ #define SOC_ADC_PERIPH_NUM (2) #define SOC_ADC_PATT_LEN_MAX (16) - #define SOC_ADC_CHANNEL_NUM(PERIPH_NUM) (10) #define SOC_ADC_MAX_CHANNEL_NUM (10) +#define SOC_ADC_MAX_BITWIDTH (13) /** * Check if adc support digital controller (DMA) mode. @@ -66,6 +66,7 @@ * - 0 : not support; */ #define SOC_ADC_SUPPORT_DMA_MODE(PERIPH_NUM) ((PERIPH_NUM==0)? 1: 1) +#define SOC_ADC_SUPPORT_RTC_CTRL 1 /*-------------------------- BROWNOUT CAPS -----------------------------------*/ #define SOC_BROWNOUT_RESET_SUPPORTED 1 diff --git a/components/soc/esp32s3/include/soc/adc_caps.h b/components/soc/esp32s3/include/soc/adc_caps.h index c6ea4cfaf9..1460198b12 100644 --- a/components/soc/esp32s3/include/soc/adc_caps.h +++ b/components/soc/esp32s3/include/soc/adc_caps.h @@ -15,9 +15,10 @@ #define SOC_ADC_PERIPH_NUM (2) #define SOC_ADC_PATT_LEN_MAX (16) - #define SOC_ADC_CHANNEL_NUM(PERIPH_NUM) (10) #define SOC_ADC_MAX_CHANNEL_NUM (10) +#define SOC_ADC_MAX_BITWIDTH (13) + /** * Check if adc support digital controller (DMA) mode. @@ -26,3 +27,4 @@ * - 0 : not support; */ #define SOC_ADC_SUPPORT_DMA_MODE(PERIPH_NUM) ((PERIPH_NUM==0)? 1: 1) +#define SOC_ADC_SUPPORT_RTC_CTRL 1 diff --git a/components/soc/include/soc/adc_periph.h b/components/soc/include/soc/adc_periph.h index 9cb75283eb..796ea18e90 100644 --- a/components/soc/include/soc/adc_periph.h +++ b/components/soc/include/soc/adc_periph.h @@ -17,8 +17,12 @@ #include "soc/soc.h" #include "soc/soc_caps.h" #include "soc/syscon_struct.h" + +#if SOC_ADC_SUPPORT_RTC_CTRL #include "soc/sens_reg.h" #include "soc/sens_struct.h" +#endif + #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED #include "soc/rtc_io_struct.h" #endif diff --git a/components/soc/include/soc/rtc_io_periph.h b/components/soc/include/soc/rtc_io_periph.h index 3bf77472ce..e9309771c6 100644 --- a/components/soc/include/soc/rtc_io_periph.h +++ b/components/soc/include/soc/rtc_io_periph.h @@ -19,16 +19,17 @@ #include "soc/soc_caps.h" #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED - #include "soc/rtc_io_channel.h" #include "soc/rtc_io_reg.h" #include "soc/rtc_io_struct.h" - #endif #include "soc/rtc_cntl_reg.h" #include "soc/rtc_cntl_struct.h" + +#if SOC_ADC_SUPPORT_RTC_CTRL #include "soc/sens_struct.h" +#endif #ifdef __cplusplus extern "C" diff --git a/examples/peripherals/adc_dma_demo/main/adc_dma_example_main.c b/examples/peripherals/adc_dma_demo/main/adc_dma_example_main.c index 6bbf9655ef..005c168375 100644 --- a/examples/peripherals/adc_dma_demo/main/adc_dma_example_main.c +++ b/examples/peripherals/adc_dma_demo/main/adc_dma_example_main.c @@ -3,6 +3,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" +#include "esp_log.h" #include "driver/adc.h" #define TIMES 256 @@ -47,6 +48,15 @@ static void continuous_adc_init(uint16_t adc1_chan_mask, uint16_t adc2_chan_mask assert(ret == ESP_OK); } +static bool check_valid_data(const adc_digi_output_data_t *data) +{ + const unsigned int unit = data->type2.unit; + if (unit > 2) return false; + if (data->type2.channel >= SOC_ADC_CHANNEL_NUM(unit)) return false; + + return true; +} + static void continuous_read_demo(void *arg) { esp_err_t ret; @@ -54,8 +64,8 @@ static void continuous_read_demo(void *arg) uint8_t result[TIMES] = {0}; memset(result, 0xcc, TIMES); - uint16_t adc1_chan_mask = BIT(ADC1_CHANNEL_0) | BIT(ADC1_CHANNEL_1); - uint16_t adc2_chan_mask = BIT(ADC2_CHANNEL_0); + uint16_t adc1_chan_mask = BIT(0) | BIT(1); + uint16_t adc2_chan_mask = BIT(0); adc_channel_t channel[3] = {ADC1_CHANNEL_0, ADC1_CHANNEL_1, (ADC2_CHANNEL_0 | 1 << 3)}; continuous_adc_init(adc1_chan_mask, adc2_chan_mask, channel, sizeof(channel) / sizeof(adc_channel_t)); @@ -65,13 +75,12 @@ static void continuous_read_demo(void *arg) while(n--) { ret = adc_digi_read_bytes(result, TIMES, &ret_num, ADC_MAX_DELAY); for (int i = 0; i < ret_num; i+=4) { - uint32_t temp = (result[i+3] << 24) | (result[i+2] << 16) | (result[i+1] << 8) | (result[i+0]); - adc_digi_output_data_t *p = (void*)&temp; - printf("[%d_%d_%x](%02x %02x %02x %02x) \n", p->type2.unit, p->type2.channel, p->type2.data, - result[i], - result[i + 1], - result[i + 2], - result[i + 3]); + adc_digi_output_data_t *p = (void*)&result[i]; + if (check_valid_data(p)) { + printf("ADC%d_CH%d: %x\n", p->type2.unit+1, p->type2.channel, p->type2.data); + } else { + printf("Invalid data [%d_%d_%x]\n", p->type2.unit+1, p->type2.channel, p->type2.data); + } } // If you see task WDT in this task, it means the conversion is too fast for the task to handle } @@ -87,7 +96,9 @@ static void single_read_demo(void *arg) int adc1_reading[3] = {0xcc}; int adc2_reading[1] = {0xcc}; - adc1_config_width(ADC_WIDTH_BIT_12); + const char TAG_CH[][10] = {"ADC1_CH2", "ADC1_CH3","ADC1_CH4", "ADC2_CH0"}; + + adc1_config_width(ADC_WIDTH_BIT_DEFAULT); adc1_config_channel_atten(ADC1_CHANNEL_2, ADC_ATTEN_DB_0); adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_6); adc1_config_channel_atten(ADC1_CHANNEL_4, ADC_ATTEN_DB_0); @@ -101,12 +112,12 @@ static void single_read_demo(void *arg) adc1_reading[2] = adc1_get_raw(ADC1_CHANNEL_4); for (int i = 0; i < 3; i++) { - printf("[%x]\n", adc1_reading[i]); + ESP_LOGI(TAG_CH[i], "%x", adc1_reading[i]); } ret = adc2_get_raw(ADC2_CHANNEL_0, ADC_WIDTH_BIT_12, &adc2_reading[0]); assert(ret == ESP_OK); - printf("[%x]\n", adc2_reading[0]); + ESP_LOGI(TAG_CH[3], "%x", adc2_reading[0]); } } From abe94e3b53f1a85041114b31102a02ec5d1c0a29 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 7 Jan 2020 09:35:43 +0100 Subject: [PATCH 04/22] adc: add adc_power_acquire/release, deprecate adc_power_on/off --- components/driver/i2s.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/components/driver/i2s.c b/components/driver/i2s.c index e705467491..c6a4c56b49 100644 --- a/components/driver/i2s.c +++ b/components/driver/i2s.c @@ -867,13 +867,6 @@ static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_co periph_module_enable(i2s_periph_signal[i2s_num].module); #if SOC_I2S_SUPPORTS_ADC_DAC - 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_acquire(); - } #endif // configure I2S data port interface. i2s_hal_config_param(&(p_i2s_obj[i2s_num]->hal), i2s_config); From 34408026bbfbb3c2ee158b1e5c569e7348ad7233 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 2 Jan 2020 10:44:45 +0100 Subject: [PATCH 05/22] wifi: add set_xpd_sar override Wi-Fi enables and disables ADC when exiting and entering sleep mode. Coordinate ADC power state with other modules, using adc_power_acquire and adc_power_release. --- components/esp_wifi/src/wifi_init.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 7aa8cae0f3..85d74a777c 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -280,11 +280,9 @@ void set_xpd_sar(bool en) } s_wifi_adc_xpd_flag = en; -#if !CONFIG_IDF_TARGET_ESP32C3 if (en) { adc_power_acquire(); } else { adc_power_release(); } -#endif } From 4e6e34e3ad20b99a829346dd4d2b4f6c5d661c01 Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Thu, 3 Dec 2020 13:58:24 +0800 Subject: [PATCH 06/22] adc_i2s: solve the i2s_adc issue when using wifi --- components/driver/adc_common.c | 71 +++++++++++++++---- components/driver/i2s.c | 7 ++ components/driver/include/driver/adc_common.h | 29 +++++++- 3 files changed, 89 insertions(+), 18 deletions(-) diff --git a/components/driver/adc_common.c b/components/driver/adc_common.c index dbbadf9052..3c2400185d 100644 --- a/components/driver/adc_common.c +++ b/components/driver/adc_common.c @@ -74,6 +74,14 @@ In ADC2, there're two locks used for different cases: adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock. */ +// This gets incremented when adc_power_acquire() is called, and decremented when +// adc_power_release() is called. ADC is powered down when the value reaches zero. +// Should be modified within critical section (ADC_ENTER/EXIT_CRITICAL). +static int s_adc_power_on_cnt; + +static void adc_power_on_internal(void); +static void adc_power_off_internal(void); + #ifdef CONFIG_IDF_TARGET_ESP32 //prevent ADC2 being used by wifi and other tasks at the same time. static _lock_t adc2_wifi_lock; @@ -122,36 +130,60 @@ static uint32_t get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t chan) } #endif -void adc_power_always_on(void) +void adc_power_acquire(void) { + bool powered_on = false; ADC_ENTER_CRITICAL(); - adc_hal_set_power_manage(ADC_POWER_SW_ON); + s_adc_power_on_cnt++; + if (s_adc_power_on_cnt == 1) { + adc_power_on_internal(); + powered_on = true; + } ADC_EXIT_CRITICAL(); + if (powered_on) { + ESP_LOGV(ADC_TAG, "%s: ADC powered on", __func__); + } } -void adc_power_on(void) +void adc_power_release(void) +{ + bool powered_off = false; + ADC_ENTER_CRITICAL(); + s_adc_power_on_cnt--; + /* Sanity check */ + if (s_adc_power_on_cnt < 0) { + ADC_EXIT_CRITICAL(); + ESP_LOGE(ADC_TAG, "%s called, but s_adc_power_on_cnt == 0", __func__); + abort(); + } else if (s_adc_power_on_cnt == 0) { + adc_power_off_internal(); + powered_off = true; + } + ADC_EXIT_CRITICAL(); + if (powered_off) { + ESP_LOGV(ADC_TAG, "%s: ADC powered off", __func__); + } +} + +static void adc_power_on_internal(void) { ADC_ENTER_CRITICAL(); - /* The power FSM controlled mode saves more power, while the ADC noise may get increased. */ -#ifndef CONFIG_ADC_FORCE_XPD_FSM /* Set the power always on to increase precision. */ adc_hal_set_power_manage(ADC_POWER_SW_ON); -#else - /* Use the FSM to turn off the power while not used to save power. */ - if (adc_hal_get_power_manage() != ADC_POWER_BY_FSM) { - adc_hal_set_power_manage(ADC_POWER_SW_ON); - } -#endif ADC_EXIT_CRITICAL(); } -void adc_power_off(void) +void adc_power_on(void) __attribute__((alias("adc_power_on_internal"))); + +static void adc_power_off_internal(void) { ADC_ENTER_CRITICAL(); adc_hal_set_power_manage(ADC_POWER_SW_OFF); ADC_EXIT_CRITICAL(); } +void adc_power_off(void) __attribute__((alias("adc_power_off_internal"))); + esp_err_t adc_set_clk_div(uint8_t clk_div) { ADC_ENTER_CRITICAL(); @@ -337,7 +369,7 @@ int adc1_get_raw(adc1_channel_t channel) int adc_value; ADC_CHANNEL_CHECK(ADC_NUM_1, channel); adc1_rtc_mode_acquire(); - adc_power_on(); + adc_power_acquire(); #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // Get calibration value before going into critical section @@ -359,6 +391,7 @@ int adc1_get_raw(adc1_channel_t channel) #endif ADC_EXIT_CRITICAL(); + adc_power_release(); adc1_lock_release(); return adc_value; } @@ -371,7 +404,7 @@ int adc1_get_voltage(adc1_channel_t channel) //Deprecated. Use adc1_get_raw() #if SOC_ULP_SUPPORTED void adc1_ulp_enable(void) { - adc_power_on(); + adc_power_acquire(); ADC_ENTER_CRITICAL(); adc_hal_set_controller(ADC_NUM_1, ADC_CTRL_ULP); @@ -492,7 +525,7 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int * ADC_CHECK(width_bit == ADC_WIDTH_BIT_13, "WIDTH ERR: ESP32S2 support 13 bit width", ESP_ERR_INVALID_ARG); #endif - adc_power_on(); //in critical section with whole rtc module + adc_power_acquire(); //in critical section with whole rtc module #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // Get calibration value before going into critical section @@ -503,6 +536,7 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int * if ( ADC2_WIFI_LOCK_TRY_ACQUIRE() == -1 ) { //try the lock, return if failed (wifi using). ADC2_EXIT_CRITICAL(); + adc_power_release(); return ESP_ERR_TIMEOUT; } #ifdef CONFIG_ADC_DISABLE_DAC @@ -544,8 +578,12 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int * if (adc_value < 0) { ESP_LOGD( ADC_TAG, "ADC2 ARB: Return data is invalid." ); + adc_power_release(); return ESP_ERR_INVALID_STATE; } + + //in critical section with whole rtc module + adc_power_release(); *raw_out = adc_value; return ESP_OK; } @@ -558,7 +596,9 @@ esp_err_t adc2_vref_to_gpio(gpio_num_t gpio) esp_err_t adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio) { #ifdef CONFIG_IDF_TARGET_ESP32 + adc_power_acquire(); if (adc_unit & ADC_UNIT_1) { + adc_power_release(); return ESP_ERR_INVALID_ARG; } #endif @@ -571,6 +611,7 @@ esp_err_t adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio) } } if (ch == ADC2_CHANNEL_MAX) { + adc_power_release(); return ESP_ERR_INVALID_ARG; } diff --git a/components/driver/i2s.c b/components/driver/i2s.c index c6a4c56b49..e705467491 100644 --- a/components/driver/i2s.c +++ b/components/driver/i2s.c @@ -867,6 +867,13 @@ static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_co periph_module_enable(i2s_periph_signal[i2s_num].module); #if SOC_I2S_SUPPORTS_ADC_DAC + 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_acquire(); + } #endif // configure I2S data port interface. i2s_hal_config_param(&(p_i2s_obj[i2s_num]->hal), i2s_config); diff --git a/components/driver/include/driver/adc_common.h b/components/driver/include/driver/adc_common.h index 4596505822..abb1b17e57 100644 --- a/components/driver/include/driver/adc_common.h +++ b/components/driver/include/driver/adc_common.h @@ -151,14 +151,32 @@ typedef struct adc_digi_init_config_s { /** * @brief Enable ADC power + * @deprecated Use adc_power_acquire and adc_power_release instead. */ -void adc_power_on(void); +void adc_power_on(void) __attribute__((deprecated)); /** * @brief Power off SAR ADC - * This function will force power down for ADC + * @deprecated Use adc_power_acquire and adc_power_release instead. + * This function will force power down for ADC. + * This function is deprecated because forcing power ADC power off may + * disrupt operation of other components which may be using the ADC. */ -void adc_power_off(void); +void adc_power_off(void) __attribute__((deprecated)); + +/** + * @brief Increment the usage counter for ADC module. + * ADC will stay powered on while the counter is greater than 0. + * Call adc_power_release when done using the ADC. + */ +void adc_power_acquire(void); + +/** + * @brief Decrement the usage counter for ADC module. + * ADC will stay powered on while the counter is greater than 0. + * Call this function when done using the ADC. + */ +void adc_power_release(void); /** * @brief Initialize ADC pad @@ -250,6 +268,8 @@ esp_err_t adc1_config_width(adc_bits_width_t width_bit); * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. + * As a workaround, call adc_power_acquire() in the app. This will result in higher power consumption (by ~1mA), + * but will remove the glitches on GPIO36 and GPIO39. * * @note Call ``adc1_config_width()`` before the first time this * function is called. @@ -375,6 +395,9 @@ esp_err_t adc2_config_channel_atten(adc2_channel_t channel, adc_atten_t atten); * the input of GPIO36 and GPIO39 will be pulled down for about 80ns. * When enabling power for any of these peripherals, ignore input from GPIO36 and GPIO39. * Please refer to section 3.11 of 'ECO_and_Workarounds_for_Bugs_in_ESP32' for the description of this issue. + * As a workaround, call adc_power_acquire() in the app. This will result in higher power consumption (by ~1mA), + * but will remove the glitches on GPIO36 and GPIO39. + * * * @note ESP32: * For a given channel, ``adc2_config_channel_atten()`` From 3fd37d0b5902b4b94f32592040edd967a792b868 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Mon, 28 Dec 2020 11:25:18 +0800 Subject: [PATCH 07/22] adc: change the way data is formattted in adc_dma_demo The way the adc_dma_demo data was formatted caused it go get parsed as markdown syntax. Changed it be more "human" readable as well as put all ADC examples in a common folder --- docs/en/api-reference/peripherals/adc.rst | 4 +- .../peripherals/adc/{ => adc}/CMakeLists.txt | 0 examples/peripherals/adc/{ => adc}/Makefile | 0 examples/peripherals/adc/{ => adc}/README.md | 0 .../adc/{ => adc}/main/CMakeLists.txt | 0 .../adc/{ => adc}/main/adc1_example_main.c | 0 .../adc/{ => adc}/main/component.mk | 0 .../peripherals/{ => adc}/adc2/CMakeLists.txt | 0 examples/peripherals/{ => adc}/adc2/Makefile | 0 examples/peripherals/{ => adc}/adc2/README.md | 0 .../{ => adc}/adc2/main/CMakeLists.txt | 0 .../{ => adc}/adc2/main/Kconfig.projbuild | 0 .../{ => adc}/adc2/main/adc2_example_main.c | 0 .../{ => adc}/adc2/main/component.mk | 0 .../{ => adc}/adc_dma_demo/CMakeLists.txt | 0 .../adc_dma_demo/main/CMakeLists.txt | 0 .../adc_dma_demo/main/adc_dma_example_main.c | 0 examples/peripherals/adc_dma_demo/README.md | 55 ------------------- 18 files changed, 2 insertions(+), 57 deletions(-) rename examples/peripherals/adc/{ => adc}/CMakeLists.txt (100%) rename examples/peripherals/adc/{ => adc}/Makefile (100%) rename examples/peripherals/adc/{ => adc}/README.md (100%) rename examples/peripherals/adc/{ => adc}/main/CMakeLists.txt (100%) rename examples/peripherals/adc/{ => adc}/main/adc1_example_main.c (100%) rename examples/peripherals/adc/{ => adc}/main/component.mk (100%) rename examples/peripherals/{ => adc}/adc2/CMakeLists.txt (100%) rename examples/peripherals/{ => adc}/adc2/Makefile (100%) rename examples/peripherals/{ => adc}/adc2/README.md (100%) rename examples/peripherals/{ => adc}/adc2/main/CMakeLists.txt (100%) rename examples/peripherals/{ => adc}/adc2/main/Kconfig.projbuild (100%) rename examples/peripherals/{ => adc}/adc2/main/adc2_example_main.c (100%) rename examples/peripherals/{ => adc}/adc2/main/component.mk (100%) rename examples/peripherals/{ => adc}/adc_dma_demo/CMakeLists.txt (100%) rename examples/peripherals/{ => adc}/adc_dma_demo/main/CMakeLists.txt (100%) rename examples/peripherals/{ => adc}/adc_dma_demo/main/adc_dma_example_main.c (100%) delete mode 100644 examples/peripherals/adc_dma_demo/README.md diff --git a/docs/en/api-reference/peripherals/adc.rst b/docs/en/api-reference/peripherals/adc.rst index b5876ffe1b..abba6594dc 100644 --- a/docs/en/api-reference/peripherals/adc.rst +++ b/docs/en/api-reference/peripherals/adc.rst @@ -76,7 +76,7 @@ Reading voltage on ADC1 channel 0 ({IDF_TARGET_ADC1_CH0}):: int val = adc1_get_raw(ADC1_CHANNEL_0); The input voltage in the above example is from 0 to 1.1 V (0 dB attenuation). The input range can be extended by setting a higher attenuation, see :cpp:type:`adc_atten_t`. -An example of using the ADC driver including calibration (discussed below) is available at esp-idf: :example:`peripherals/adc` +An example of using the ADC driver including calibration (discussed below) is available at esp-idf: :example:`peripherals/adc/adc` Reading voltage on ADC2 channel 7 ({IDF_TARGET_ADC2_CH7}):: @@ -95,7 +95,7 @@ Reading voltage on ADC2 channel 7 ({IDF_TARGET_ADC2_CH7}):: } The reading may fail due to collision with Wi-Fi, should check it. -An example using the ADC2 driver to read the output of DAC is available in esp-idf: :example:`peripherals/adc2` +An example using the ADC2 driver to read the output of DAC is available in esp-idf: :example:`peripherals/adc/adc2` .. only:: esp32 diff --git a/examples/peripherals/adc/CMakeLists.txt b/examples/peripherals/adc/adc/CMakeLists.txt similarity index 100% rename from examples/peripherals/adc/CMakeLists.txt rename to examples/peripherals/adc/adc/CMakeLists.txt diff --git a/examples/peripherals/adc/Makefile b/examples/peripherals/adc/adc/Makefile similarity index 100% rename from examples/peripherals/adc/Makefile rename to examples/peripherals/adc/adc/Makefile diff --git a/examples/peripherals/adc/README.md b/examples/peripherals/adc/adc/README.md similarity index 100% rename from examples/peripherals/adc/README.md rename to examples/peripherals/adc/adc/README.md diff --git a/examples/peripherals/adc/main/CMakeLists.txt b/examples/peripherals/adc/adc/main/CMakeLists.txt similarity index 100% rename from examples/peripherals/adc/main/CMakeLists.txt rename to examples/peripherals/adc/adc/main/CMakeLists.txt diff --git a/examples/peripherals/adc/main/adc1_example_main.c b/examples/peripherals/adc/adc/main/adc1_example_main.c similarity index 100% rename from examples/peripherals/adc/main/adc1_example_main.c rename to examples/peripherals/adc/adc/main/adc1_example_main.c diff --git a/examples/peripherals/adc/main/component.mk b/examples/peripherals/adc/adc/main/component.mk similarity index 100% rename from examples/peripherals/adc/main/component.mk rename to examples/peripherals/adc/adc/main/component.mk diff --git a/examples/peripherals/adc2/CMakeLists.txt b/examples/peripherals/adc/adc2/CMakeLists.txt similarity index 100% rename from examples/peripherals/adc2/CMakeLists.txt rename to examples/peripherals/adc/adc2/CMakeLists.txt diff --git a/examples/peripherals/adc2/Makefile b/examples/peripherals/adc/adc2/Makefile similarity index 100% rename from examples/peripherals/adc2/Makefile rename to examples/peripherals/adc/adc2/Makefile diff --git a/examples/peripherals/adc2/README.md b/examples/peripherals/adc/adc2/README.md similarity index 100% rename from examples/peripherals/adc2/README.md rename to examples/peripherals/adc/adc2/README.md diff --git a/examples/peripherals/adc2/main/CMakeLists.txt b/examples/peripherals/adc/adc2/main/CMakeLists.txt similarity index 100% rename from examples/peripherals/adc2/main/CMakeLists.txt rename to examples/peripherals/adc/adc2/main/CMakeLists.txt diff --git a/examples/peripherals/adc2/main/Kconfig.projbuild b/examples/peripherals/adc/adc2/main/Kconfig.projbuild similarity index 100% rename from examples/peripherals/adc2/main/Kconfig.projbuild rename to examples/peripherals/adc/adc2/main/Kconfig.projbuild diff --git a/examples/peripherals/adc2/main/adc2_example_main.c b/examples/peripherals/adc/adc2/main/adc2_example_main.c similarity index 100% rename from examples/peripherals/adc2/main/adc2_example_main.c rename to examples/peripherals/adc/adc2/main/adc2_example_main.c diff --git a/examples/peripherals/adc2/main/component.mk b/examples/peripherals/adc/adc2/main/component.mk similarity index 100% rename from examples/peripherals/adc2/main/component.mk rename to examples/peripherals/adc/adc2/main/component.mk diff --git a/examples/peripherals/adc_dma_demo/CMakeLists.txt b/examples/peripherals/adc/adc_dma_demo/CMakeLists.txt similarity index 100% rename from examples/peripherals/adc_dma_demo/CMakeLists.txt rename to examples/peripherals/adc/adc_dma_demo/CMakeLists.txt diff --git a/examples/peripherals/adc_dma_demo/main/CMakeLists.txt b/examples/peripherals/adc/adc_dma_demo/main/CMakeLists.txt similarity index 100% rename from examples/peripherals/adc_dma_demo/main/CMakeLists.txt rename to examples/peripherals/adc/adc_dma_demo/main/CMakeLists.txt diff --git a/examples/peripherals/adc_dma_demo/main/adc_dma_example_main.c b/examples/peripherals/adc/adc_dma_demo/main/adc_dma_example_main.c similarity index 100% rename from examples/peripherals/adc_dma_demo/main/adc_dma_example_main.c rename to examples/peripherals/adc/adc_dma_demo/main/adc_dma_example_main.c diff --git a/examples/peripherals/adc_dma_demo/README.md b/examples/peripherals/adc_dma_demo/README.md deleted file mode 100644 index 0b969030e5..0000000000 --- a/examples/peripherals/adc_dma_demo/README.md +++ /dev/null @@ -1,55 +0,0 @@ -| Supported Targets | ESP32-C3 | -| ----------------- | -------- | - -# ADC DMA Example - -(See the README.md file in the upper level 'examples' directory for more information about examples.) - -This example shows how to use DMA to read voltage from a GPIO pin via ADC controller. - -## How to use example - -### Hardware Required - -* A development board with ESP32C3 SoC -* A USB cable for power supply and programming - -In this example, we use `ADC_UNIT_1` by default, we need to connect a voltage source (0 ~ 3.3v) to GPIO1. If another ADC unit is selected in your application, you need to change the GPIO pin (please refer to the `ESP32C3 Technical Reference Manual`). - -### Configure the project - -``` -idf.py menuconfig -``` - -### Build and Flash - -Build the project and flash it to the board, then run monitor tool to view serial output: - -``` -idf.py -p PORT flash monitor -``` - -(To exit the serial monitor, type ``Ctrl-]``.) - -See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. - -## Example Output - -Running this example, you will see the following log output on the serial monitor: - -[unit_channel_data]() -``` -[0_1_54e](4e 25 00 00) -[0_1_548](48 25 00 00) -[0_1_556](56 25 00 00) -``` - -## Troubleshooting - -* program upload failure - - * Hardware connection is not correct: run `idf.py -p PORT monitor`, and reboot your board to see if there are any output logs. - * The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again. - -For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. From 4793bb3267141bd110bf0f59642393631f92c936 Mon Sep 17 00:00:00 2001 From: Armando Date: Thu, 14 Jan 2021 16:57:10 +0800 Subject: [PATCH 08/22] adc: update adc_dma example README.md --- .../{adc_dma_demo => adc_dma}/CMakeLists.txt | 0 examples/peripherals/adc/adc_dma/README.md | 63 +++++++++++++++++++ .../main/CMakeLists.txt | 0 .../main/adc_dma_example_main.c | 8 +-- 4 files changed, 67 insertions(+), 4 deletions(-) rename examples/peripherals/adc/{adc_dma_demo => adc_dma}/CMakeLists.txt (100%) create mode 100644 examples/peripherals/adc/adc_dma/README.md rename examples/peripherals/adc/{adc_dma_demo => adc_dma}/main/CMakeLists.txt (100%) rename examples/peripherals/adc/{adc_dma_demo => adc_dma}/main/adc_dma_example_main.c (96%) diff --git a/examples/peripherals/adc/adc_dma_demo/CMakeLists.txt b/examples/peripherals/adc/adc_dma/CMakeLists.txt similarity index 100% rename from examples/peripherals/adc/adc_dma_demo/CMakeLists.txt rename to examples/peripherals/adc/adc_dma/CMakeLists.txt diff --git a/examples/peripherals/adc/adc_dma/README.md b/examples/peripherals/adc/adc_dma/README.md new file mode 100644 index 0000000000..8d349d76f3 --- /dev/null +++ b/examples/peripherals/adc/adc_dma/README.md @@ -0,0 +1,63 @@ +| Supported Targets | ESP32-C3 | +| ----------------- | -------- | + +# ADC DMA Example + +(See the README.md file in the upper level 'examples' directory for more information about examples.) + +This example shows how to use DMA-Read-APIs and Single-Read-APIs to read voltage from GPIO pins via ADC controller. + +## How to use example + +### Hardware Required + +* A development board with ESP32C3 SoC +* A USB cable for power supply and programming + +For `single_read` (Single-Read-APIs example), we use `ADC1_CHANNEL_2`, `ADC1_CHANNEL_3`, `ADC1_CHANNEL_4`, `ADC2_CHANNEL_0`. Hence we need to connect voltage sources (0 ~ 3.3V) to GPIO2, GPIO3, GPIO4, GPIO5 respectively. + +For `continuous_read` (DMA-Read-APIs example), we use `ADC1_CHANNEL_0`, `ADC1_CHANNEL_1` and `ADC2_CHANNEL_0`. Therefore, GPIO0, GPIO1 and GPIO5 should be connected to voltage sources (0 ~ 3.3V). + +If other ADC units/channels are selected in your application, you need to change the GPIO pin (please refer to the `ESP32C3 Technical Reference Manual`). + +### Configure the project + +``` +idf.py menuconfig +``` + +### Build and Flash + +Build the project and flash it to the board, then run monitor tool to view serial output: + +``` +idf.py -p PORT flash monitor +``` + +(To exit the serial monitor, type ``Ctrl-]``.) + +See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. + +## Example Output + +Running this example, you will see the following log output on the serial monitor: +``` +I (322) ADC1_CH2: 7c8 +I (322) ADC1_CH3: 278 +I (322) ADC1_CH4: d4b +I (322) ADC2_CH0: 48 +``` +``` +ADC1_CH0: 61b +ADC1_CH1: 39b +ADC2_CH0: 4b +``` + +## Troubleshooting + +* program upload failure + + * Hardware connection is not correct: run `idf.py -p PORT monitor`, and reboot your board to see if there are any output logs. + * The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again. + +For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. diff --git a/examples/peripherals/adc/adc_dma_demo/main/CMakeLists.txt b/examples/peripherals/adc/adc_dma/main/CMakeLists.txt similarity index 100% rename from examples/peripherals/adc/adc_dma_demo/main/CMakeLists.txt rename to examples/peripherals/adc/adc_dma/main/CMakeLists.txt diff --git a/examples/peripherals/adc/adc_dma_demo/main/adc_dma_example_main.c b/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c similarity index 96% rename from examples/peripherals/adc/adc_dma_demo/main/adc_dma_example_main.c rename to examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c index 005c168375..1adc19b328 100644 --- a/examples/peripherals/adc/adc_dma_demo/main/adc_dma_example_main.c +++ b/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c @@ -57,7 +57,7 @@ static bool check_valid_data(const adc_digi_output_data_t *data) return true; } -static void continuous_read_demo(void *arg) +static void continuous_read(void *arg) { esp_err_t ret; uint32_t ret_num = 0; @@ -90,7 +90,7 @@ static void continuous_read_demo(void *arg) assert(ret == ESP_OK); } -static void single_read_demo(void *arg) +static void single_read(void *arg) { esp_err_t ret; int adc1_reading[3] = {0xcc}; @@ -123,6 +123,6 @@ static void single_read_demo(void *arg) void app_main() { - single_read_demo(NULL); - continuous_read_demo(NULL); + single_read(NULL); + continuous_read(NULL); } From 2b737c1927c1da43b720564e121aa879707d293c Mon Sep 17 00:00:00 2001 From: Armando Date: Fri, 15 Jan 2021 12:33:35 +0800 Subject: [PATCH 09/22] adc: fix adc invalid data issue by update adc_reset --- components/driver/esp32c3/adc.c | 6 ++++-- components/hal/adc_hal.c | 2 ++ .../peripherals/adc/adc_dma/main/adc_dma_example_main.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/components/driver/esp32c3/adc.c b/components/driver/esp32c3/adc.c index e2e036f89e..3dfb86efc0 100644 --- a/components/driver/esp32c3/adc.c +++ b/components/driver/esp32c3/adc.c @@ -293,11 +293,13 @@ esp_err_t adc_digi_start(void) //enable in suc eof intr adc_hal_digi_ena_intr(&s_adc_digi_ctx->hal_dma, &s_adc_digi_ctx->hal_dma_config, IN_SUC_EOF_BIT); - //start DMA - adc_hal_digi_rxdma_start(&s_adc_digi_ctx->hal_dma, &s_adc_digi_ctx->hal_dma_config); + //start ADC adc_hal_digi_start(&s_adc_digi_ctx->hal_dma, &s_adc_digi_ctx->hal_dma_config); + //start DMA + adc_hal_digi_rxdma_start(&s_adc_digi_ctx->hal_dma, &s_adc_digi_ctx->hal_dma_config); + return ESP_OK; } diff --git a/components/hal/adc_hal.c b/components/hal/adc_hal.c index 00647c2fb9..4389a1df2e 100644 --- a/components/hal/adc_hal.c +++ b/components/hal/adc_hal.c @@ -109,6 +109,8 @@ void adc_hal_digi_start(adc_dma_hal_context_t *adc_dma_ctx, adc_dma_hal_config_t adc_ll_digi_dma_enable(); //enable sar adc timer adc_ll_digi_trigger_enable(); + //reset the adc state + adc_ll_digi_reset(); } void adc_hal_digi_stop(adc_dma_hal_context_t *adc_dma_ctx, adc_dma_hal_config_t *dma_config) diff --git a/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c b/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c index 1adc19b328..6604e1d6e4 100644 --- a/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c +++ b/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c @@ -121,7 +121,7 @@ static void single_read(void *arg) } } -void app_main() +void app_main(void) { single_read(NULL); continuous_read(NULL); From 02600309c8e12cf1786ce3326d81709639462264 Mon Sep 17 00:00:00 2001 From: Armando Date: Mon, 18 Jan 2021 21:59:18 +0800 Subject: [PATCH 10/22] adc: fix some regression issues --- components/driver/CMakeLists.txt | 2 +- components/driver/esp32c3/adc2_init_cal.c | 2 +- .../driver/esp32c3/include/driver/adc.h | 33 ------------------ components/driver/esp32s2/adc2_init_cal.c | 2 +- components/driver/include/driver/adc_common.h | 8 ++--- .../{ => include}/esp_private/adc_cali.h | 0 components/driver/test/test_adc_dma.c | 34 +++++++------------ components/hal/adc_hal.c | 3 +- components/hal/esp32c3/adc_hal.c | 2 +- .../hal/esp32c3/include/hal/clk_gate_ll.h | 2 -- components/hal/esp32c3/include/hal/gdma_ll.h | 7 ---- components/hal/esp32s2/adc_hal.c | 14 ++++---- components/hal/include/hal/adc_types.h | 6 ++-- .../adc/adc_dma/main/adc_dma_example_main.c | 2 +- 14 files changed, 33 insertions(+), 84 deletions(-) rename components/driver/{ => include}/esp_private/adc_cali.h (100%) diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 777d0afae0..4e71325b50 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -22,7 +22,7 @@ set(srcs "twai.c" "uart.c") -set(includes "include" "${target}/include" "esp_private") +set(includes "include" "${target}/include") if(${target} STREQUAL "esp32") # SDMMC and MCPWM are in ESP32 only. diff --git a/components/driver/esp32c3/adc2_init_cal.c b/components/driver/esp32c3/adc2_init_cal.c index 19e7d98c19..944d8fa46f 100644 --- a/components/driver/esp32c3/adc2_init_cal.c +++ b/components/driver/esp32c3/adc2_init_cal.c @@ -18,7 +18,7 @@ Don't put any other code into this file. */ #include "adc2_wifi_private.h" #include "hal/adc_hal.h" -#include "adc_cali.h" +#include "esp_private/adc_cali.h" /** * @brief Set initial code to ADC2 after calibration. ADC2 RTC and ADC2 PWDET controller share the initial code. diff --git a/components/driver/esp32c3/include/driver/adc.h b/components/driver/esp32c3/include/driver/adc.h index fc8b59412d..463778a3a9 100644 --- a/components/driver/esp32c3/include/driver/adc.h +++ b/components/driver/esp32c3/include/driver/adc.h @@ -186,39 +186,6 @@ esp_err_t adc_digi_isr_register(void (*fn)(void *), void *arg, int intr_alloc_fl */ esp_err_t adc_digi_isr_deregister(void); -/*--------------------------------------------------------------- - RTC controller setting ----------------------------------------------------------------*/ - -/*--------------------------------------------------------------- - Deprecated API ----------------------------------------------------------------*/ -/** - * @brief Set I2S data source - * - * @param src I2S DMA data source, I2S DMA can get data from digital signals or from ADC. - * - * @deprecated The ESP32C3 doesn't use I2S DMA. Call ``adc_digi_controller_config`` instead. - * - * @return - * - ESP_OK success - */ -esp_err_t adc_set_i2s_data_source(adc_i2s_source_t src) __attribute__((deprecated)); - -/** - * @brief Initialize I2S ADC mode - * - * @param adc_unit ADC unit index - * @param channel ADC channel index - * - * @deprecated The ESP32C3 doesn't use I2S DMA. Call ``adc_digi_controller_config`` instead. - * - * @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) __attribute__((deprecated)); - #ifdef __cplusplus } #endif diff --git a/components/driver/esp32s2/adc2_init_cal.c b/components/driver/esp32s2/adc2_init_cal.c index 19e7d98c19..944d8fa46f 100644 --- a/components/driver/esp32s2/adc2_init_cal.c +++ b/components/driver/esp32s2/adc2_init_cal.c @@ -18,7 +18,7 @@ Don't put any other code into this file. */ #include "adc2_wifi_private.h" #include "hal/adc_hal.h" -#include "adc_cali.h" +#include "esp_private/adc_cali.h" /** * @brief Set initial code to ADC2 after calibration. ADC2 RTC and ADC2 PWDET controller share the initial code. diff --git a/components/driver/include/driver/adc_common.h b/components/driver/include/driver/adc_common.h index abb1b17e57..2ac5110c43 100644 --- a/components/driver/include/driver/adc_common.h +++ b/components/driver/include/driver/adc_common.h @@ -38,8 +38,7 @@ typedef enum { ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO35 */ ADC1_CHANNEL_MAX, } adc1_channel_t; -#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 -//S3 is not sure. Need to be checked when bringing up S3 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // TODO ESP32-S3 channels are wrong IDF-1776 /**** `adc1_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ typedef enum { ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO1 */ @@ -64,10 +63,9 @@ typedef enum { ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO34 */ ADC1_CHANNEL_MAX, } adc1_channel_t; -#endif +#endif // CONFIG_IDF_TARGET_* -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 -//S3 is not sure. Need to be checked when bringing up S3 +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 // TODO ESP32-S3 channels are wrong IDF-1776 /**** `adc2_channel_t` will be deprecated functions, combine into `adc_channel_t` ********/ typedef enum { ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO4 (ESP32), GPIO11 (ESP32-S2) */ diff --git a/components/driver/esp_private/adc_cali.h b/components/driver/include/esp_private/adc_cali.h similarity index 100% rename from components/driver/esp_private/adc_cali.h rename to components/driver/include/esp_private/adc_cali.h diff --git a/components/driver/test/test_adc_dma.c b/components/driver/test/test_adc_dma.c index db32120d8e..04d2c4c57a 100644 --- a/components/driver/test/test_adc_dma.c +++ b/components/driver/test/test_adc_dma.c @@ -36,7 +36,7 @@ static int insert_point(uint32_t value) if (s_adc_offset < 0) { if (fixed_size) { - assert(MAX_ARRAY_SIZE >= 4096); + TEST_ASSERT_GREATER_OR_EQUAL(4096, MAX_ARRAY_SIZE); s_adc_offset = 0; //Fixed to 0 because the array can hold all the data in 12 bits } else { s_adc_offset = MAX((int)value - MAX_ARRAY_SIZE/2, 0); @@ -44,8 +44,8 @@ static int insert_point(uint32_t value) } if (!fixed_size && (value < s_adc_offset || value >= s_adc_offset + MAX_ARRAY_SIZE)) { - assert(value >= s_adc_offset); - assert(value < s_adc_offset + MAX_ARRAY_SIZE); + TEST_ASSERT_GREATER_OR_EQUAL(s_adc_offset, value); + TEST_ASSERT_LESS_THAN(s_adc_offset + MAX_ARRAY_SIZE, value); } s_adc_count[value - s_adc_offset] ++; @@ -119,9 +119,6 @@ static void print_summary(bool figure) static void continuous_adc_init(uint16_t adc1_chan_mask, uint16_t adc2_chan_mask, adc_channel_t *channel, uint8_t channel_num, adc_atten_t atten) { - esp_err_t ret = ESP_OK; - assert(ret == ESP_OK); - adc_digi_init_config_t adc_dma_config = { .max_store_buf_size = TEST_COUNT*2, .conv_num_each_intr = 128, @@ -129,10 +126,9 @@ static void continuous_adc_init(uint16_t adc1_chan_mask, uint16_t adc2_chan_mask .adc1_chan_mask = adc1_chan_mask, .adc2_chan_mask = adc2_chan_mask, }; - ret = adc_digi_initialize(&adc_dma_config); - assert(ret == ESP_OK); + TEST_ESP_OK(adc_digi_initialize(&adc_dma_config)); - adc_digi_pattern_table_t adc_pattern[10]; + adc_digi_pattern_table_t adc_pattern[10] = {0}; adc_digi_config_t dig_cfg = { .conv_limit_en = 0, .conv_limit_num = 250, @@ -152,13 +148,11 @@ static void continuous_adc_init(uint16_t adc1_chan_mask, uint16_t adc2_chan_mask adc_pattern[i].unit = unit; } dig_cfg.adc_pattern = adc_pattern; - ret = adc_digi_controller_config(&dig_cfg); - assert(ret == ESP_OK); + TEST_ESP_OK(adc_digi_controller_config(&dig_cfg)); } TEST_CASE("test_adc_dma", "[adc][ignore][manual]") { - esp_err_t ret; uint16_t adc1_chan_mask = BIT(2); uint16_t adc2_chan_mask = 0; adc_channel_t channel[1] = {ADC1_CHANNEL_2}; @@ -168,7 +162,7 @@ TEST_CASE("test_adc_dma", "[adc][ignore][manual]") int buffer_size = TEST_COUNT*output_data_size; uint8_t* read_buf = malloc(buffer_size); - assert(read_buf); + TEST_ASSERT_NOT_NULL(read_buf); adc_atten_t atten; bool print_figure; @@ -187,7 +181,7 @@ TEST_CASE("test_adc_dma", "[adc][ignore][manual]") esp_adc_cal_characteristics_t chan1_char = {}; esp_adc_cal_value_t cal_ret = esp_adc_cal_characterize(ADC_UNIT_1, atten, ADC_WIDTH_12Bit, 0, &chan1_char); - assert(cal_ret == ESP_ADC_CAL_VAL_EFUSE_TP); + TEST_ASSERT(cal_ret == ESP_ADC_CAL_VAL_EFUSE_TP); continuous_adc_init(adc1_chan_mask, adc2_chan_mask, channel, sizeof(channel) / sizeof(adc_channel_t), atten); adc_digi_start(); @@ -196,11 +190,10 @@ TEST_CASE("test_adc_dma", "[adc][ignore][manual]") while (remain_count) { int already_got = TEST_COUNT - remain_count; uint32_t ret_num; - ret = adc_digi_read_bytes(read_buf + already_got*output_data_size, - remain_count*output_data_size, &ret_num, ADC_MAX_DELAY); + TEST_ESP_OK(adc_digi_read_bytes(read_buf + already_got*output_data_size, + remain_count*output_data_size, &ret_num, ADC_MAX_DELAY)); - ESP_ERROR_CHECK(ret); - assert((ret_num % output_data_size) == 0); + TEST_ASSERT((ret_num % output_data_size) == 0); remain_count -= ret_num / output_data_size; } @@ -217,8 +210,7 @@ TEST_CASE("test_adc_dma", "[adc][ignore][manual]") printf("Voltage = %d mV\n", voltage_mv); adc_digi_stop(); - ret = adc_digi_deinitialize(); - assert(ret == ESP_OK); + TEST_ESP_OK(adc_digi_deinitialize()); if (atten == target_atten) { break; @@ -254,7 +246,7 @@ TEST_CASE("test_adc_single", "[adc][ignore][manual]") esp_adc_cal_characteristics_t chan1_char = {}; esp_adc_cal_value_t cal_ret = esp_adc_cal_characterize(ADC_UNIT_1, atten, ADC_WIDTH_12Bit, 0, &chan1_char); - assert(cal_ret == ESP_ADC_CAL_VAL_EFUSE_TP); + TEST_ASSERT(cal_ret == ESP_ADC_CAL_VAL_EFUSE_TP); const int test_count = TEST_COUNT; diff --git a/components/hal/adc_hal.c b/components/hal/adc_hal.c index 4389a1df2e..73d6a7887d 100644 --- a/components/hal/adc_hal.c +++ b/components/hal/adc_hal.c @@ -17,6 +17,7 @@ #if CONFIG_IDF_TARGET_ESP32C3 +#include "soc/gdma_channel.h" #include "soc/soc.h" #include "esp_rom_sys.h" #endif @@ -126,7 +127,7 @@ void adc_hal_digi_init(adc_dma_hal_context_t *adc_dma_ctx, adc_dma_hal_config_t adc_dma_ctx->dev = &GDMA; gdma_ll_enable_clock(adc_dma_ctx->dev, true); gdma_ll_clear_interrupt_status(adc_dma_ctx->dev, dma_config->dma_chan, UINT32_MAX); - gdma_ll_rx_connect_to_periph(adc_dma_ctx->dev, dma_config->dma_chan, GDMA_LL_TRIG_SRC_ADC_DAC); + gdma_ll_rx_connect_to_periph(adc_dma_ctx->dev, dma_config->dma_chan, SOC_GDMA_TRIG_PERIPH_ADC0); } /*--------------------------------------------------------------- diff --git a/components/hal/esp32c3/adc_hal.c b/components/hal/esp32c3/adc_hal.c index 7f1e49d4f6..a2ab50c02b 100644 --- a/components/hal/esp32c3/adc_hal.c +++ b/components/hal/esp32c3/adc_hal.c @@ -43,7 +43,7 @@ void adc_hal_digi_controller_config(const adc_digi_config_t *cfg) if (cfg->adc_pattern_len) { adc_ll_digi_clear_pattern_table(pattern_both); adc_ll_digi_set_pattern_table_len(pattern_both, cfg->adc_pattern_len); - for (int i = 0; i < cfg->adc_pattern_len; i++) { + for (uint32_t i = 0; i < cfg->adc_pattern_len; i++) { adc_ll_digi_set_pattern_table(pattern_both, i, cfg->adc_pattern[i]); } } diff --git a/components/hal/esp32c3/include/hal/clk_gate_ll.h b/components/hal/esp32c3/include/hal/clk_gate_ll.h index 7af8ed61ba..f7382650d5 100644 --- a/components/hal/esp32c3/include/hal/clk_gate_ll.h +++ b/components/hal/esp32c3/include/hal/clk_gate_ll.h @@ -172,7 +172,6 @@ static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph) case PERIPH_SHA_MODULE: case PERIPH_GDMA_MODULE: return SYSTEM_PERIP_CLK_EN1_REG; - case PERIPH_SARADC_MODULE: default: return SYSTEM_PERIP_CLK_EN0_REG; } @@ -196,7 +195,6 @@ static uint32_t periph_ll_get_rst_en_reg(periph_module_t periph) case PERIPH_SHA_MODULE: case PERIPH_GDMA_MODULE: return SYSTEM_PERIP_RST_EN1_REG; - case PERIPH_SARADC_MODULE: default: return SYSTEM_PERIP_RST_EN0_REG; } diff --git a/components/hal/esp32c3/include/hal/gdma_ll.h b/components/hal/esp32c3/include/hal/gdma_ll.h index c3ad226bce..22410d3bdd 100644 --- a/components/hal/esp32c3/include/hal/gdma_ll.h +++ b/components/hal/esp32c3/include/hal/gdma_ll.h @@ -39,13 +39,6 @@ extern "C" { #define GDMA_LL_EVENT_RX_SUC_EOF (1<<1) #define GDMA_LL_EVENT_RX_DONE (1<<0) -#define GDMA_LL_TRIG_SRC_SPI2 (0) -#define GDMA_LL_TRIG_SRC_UART (2) -#define GDMA_LL_TRIG_SRC_I2S0 (3) -#define GDMA_LL_TRIG_SRC_AES (6) -#define GDMA_LL_TRIG_SRC_SHA (7) -#define GDMA_LL_TRIG_SRC_ADC_DAC (8) - ///////////////////////////////////// Common ///////////////////////////////////////// /** * @brief Enable DMA channel M2M mode (TX channel n forward data to RX channel n), disabled by default diff --git a/components/hal/esp32s2/adc_hal.c b/components/hal/esp32s2/adc_hal.c index c244432d76..68e8b98071 100644 --- a/components/hal/esp32s2/adc_hal.c +++ b/components/hal/esp32s2/adc_hal.c @@ -46,7 +46,7 @@ void adc_hal_digi_controller_config(const adc_digi_config_t *cfg) if (cfg->adc1_pattern_len) { adc_ll_digi_clear_pattern_table(ADC_NUM_1); adc_ll_digi_set_pattern_table_len(ADC_NUM_1, cfg->adc1_pattern_len); - for (int i = 0; i < cfg->adc1_pattern_len; i++) { + for (uint32_t i = 0; i < cfg->adc1_pattern_len; i++) { adc_ll_digi_set_pattern_table(ADC_NUM_1, i, cfg->adc1_pattern[i]); } } @@ -55,7 +55,7 @@ void adc_hal_digi_controller_config(const adc_digi_config_t *cfg) if (cfg->adc2_pattern_len) { adc_ll_digi_clear_pattern_table(ADC_NUM_2); adc_ll_digi_set_pattern_table_len(ADC_NUM_2, cfg->adc2_pattern_len); - for (int i = 0; i < cfg->adc2_pattern_len; i++) { + for (uint32_t i = 0; i < cfg->adc2_pattern_len; i++) { adc_ll_digi_set_pattern_table(ADC_NUM_2, i, cfg->adc2_pattern[i]); } } @@ -181,11 +181,11 @@ uint32_t adc_hal_self_calibration(adc_ll_num_t adc_n, adc_channel_t channel, adc adc_ll_set_atten(adc_n, channel, atten); } - uint32_t code_list[ADC_HAL_CAL_TIMES] = {0}; - uint32_t code_sum = 0; - uint32_t code_h = 0; - uint32_t code_l = 0; - uint32_t chk_code = 0; + uint32_t code_list[ADC_HAL_CAL_TIMES] = {0}; + uint32_t code_sum = 0; + uint32_t code_h = 0; + uint32_t code_l = 0; + uint32_t chk_code = 0; for (uint8_t rpt = 0 ; rpt < ADC_HAL_CAL_TIMES ; rpt ++) { code_h = ADC_HAL_CAL_OFFSET_RANGE; diff --git a/components/hal/include/hal/adc_types.h b/components/hal/include/hal/adc_types.h index eddf6a96c5..3718899407 100644 --- a/components/hal/include/hal/adc_types.h +++ b/components/hal/include/hal/adc_types.h @@ -88,10 +88,10 @@ typedef enum { 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. */ -#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 - ADC_WIDTH_BIT_13 = 4, /*!< ADC capture width is 13Bit. */ -#elif CONFIG_IDF_TARGET_ESP32C3 +#elif SOC_ADC_MAX_BITWIDTH == 12 ADC_WIDTH_BIT_12 = 3, /*!< ADC capture width is 12Bit. */ +#elif SOC_ADC_MAX_BITWIDTH == 13 + ADC_WIDTH_BIT_13 = 4, /*!< ADC capture width is 13Bit. */ #endif ADC_WIDTH_MAX, } adc_bits_width_t; diff --git a/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c b/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c index 6604e1d6e4..99ef45de50 100644 --- a/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c +++ b/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c @@ -24,7 +24,7 @@ static void continuous_adc_init(uint16_t adc1_chan_mask, uint16_t adc2_chan_mask ret = adc_digi_initialize(&adc_dma_config); assert(ret == ESP_OK); - adc_digi_pattern_table_t adc_pattern[10]; + adc_digi_pattern_table_t adc_pattern[10] = {0}; adc_digi_config_t dig_cfg = { .conv_limit_en = 0, .conv_limit_num = 250, From a5fb7deda5d77c0a6f767713576f9b0c8e78e0f6 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Mon, 21 Dec 2020 16:33:49 +1100 Subject: [PATCH 11/22] driver: Update/cleanup esp32c3 rtc_tempsensor.c --- components/driver/esp32c3/rtc_tempsensor.c | 47 +++++++------------ .../esp_hw_support/port/esp32c3/regi2c_ctrl.h | 14 ++++-- .../port/esp32c3/rtc_clk_init.c | 2 +- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/components/driver/esp32c3/rtc_tempsensor.c b/components/driver/esp32c3/rtc_tempsensor.c index 79767a8a75..55620f2472 100644 --- a/components/driver/esp32c3/rtc_tempsensor.c +++ b/components/driver/esp32c3/rtc_tempsensor.c @@ -21,6 +21,7 @@ #include "soc/rtc_cntl_reg.h" #include "driver/temp_sensor.h" #include "esp32c3/rom/ets_sys.h" +#include "regi2c_ctrl.h" static const char *TAG = "tsens"; @@ -35,13 +36,6 @@ static const char *TAG = "tsens"; #define TSENS_DAC_FACTOR (27.88) #define TSENS_SYS_OFFSET (20.52) -#include "regi2c_ctrl.h" - -#define ANA_CONFIG2_REG 0x6000E048 -#define ANA_CONFIG2_M (BIT(18)) - -#define I2C_ADC 0X69 -#define I2C_ADC_HOSTID 1 typedef struct { int index; @@ -61,22 +55,18 @@ static const tsens_dac_offset_t dac_offset[TSENS_DAC_MAX] = { {TSENS_DAC_L4, 2, 10, -40, 20, 3}, }; -static SemaphoreHandle_t rtc_tsens_mux = NULL; +static SemaphoreHandle_t s_rtc_tsens_mux = NULL; esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens) { - //CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PD_M); - //SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M); - CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18)); - SET_PERI_REG_MASK(ANA_CONFIG2_REG, BIT(16)); + CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD); + SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU); REGI2C_WRITE_MASK(I2C_ADC, I2C_SARADC_TSENS_DAC, dac_offset[tsens.dac_offset].set_val); SENS.sar_tctrl.tsens_clk_div = tsens.clk_div; SENS.sar_tctrl.tsens_power_up_force = 1; SENS.sar_tctrl2.tsens_xpd_wait = TSENS_XPD_WAIT_DEFAULT; SENS.sar_tctrl2.tsens_xpd_force = 1; - // SENS.sar_tctrl2.tsens_reset = 1;// Reset the temp sensor. - // SENS.sar_tctrl2.tsens_reset = 0;// Clear the reset status. - ESP_LOGI(TAG, "Config temperature range [%d°C ~ %d°C], error < %d°C", + ESP_LOGD(TAG, "Config temperature range [%d°C ~ %d°C], error < %d°C", dac_offset[tsens.dac_offset].range_min, dac_offset[tsens.dac_offset].range_max, dac_offset[tsens.dac_offset].error_max); @@ -86,10 +76,8 @@ esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens) esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens) { TSENS_CHECK(tsens != NULL, ESP_ERR_INVALID_ARG); - //CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PD_M); - //SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M); - CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18)); - SET_PERI_REG_MASK(ANA_CONFIG2_REG, BIT(16)); + CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD); + SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU); tsens->dac_offset = REGI2C_READ_MASK(I2C_ADC, I2C_SARADC_TSENS_DAC); for (int i = TSENS_DAC_L0; i < TSENS_DAC_MAX; i++) { if (tsens->dac_offset == dac_offset[i].set_val) { @@ -103,13 +91,10 @@ esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens) esp_err_t temp_sensor_start(void) { - if (rtc_tsens_mux == NULL) { - rtc_tsens_mux = xSemaphoreCreateMutex(); + if (s_rtc_tsens_mux == NULL) { + s_rtc_tsens_mux = xSemaphoreCreateMutex(); } - TSENS_CHECK(rtc_tsens_mux != NULL, ESP_ERR_NO_MEM); - // SENS.sar_tctrl.tsens_dump_out = 0; - // SENS.sar_tctrl2.tsens_clkgate_en = 1; - // SENS.sar_tctrl.tsens_power_up = 1; + TSENS_CHECK(s_rtc_tsens_mux != NULL, ESP_ERR_NO_MEM); return ESP_OK; } @@ -117,9 +102,9 @@ esp_err_t temp_sensor_stop(void) { SENS.sar_tctrl.tsens_power_up = 0; // SENS.sar_tctrl2.tsens_clkgate_en = 0; - if (rtc_tsens_mux != NULL) { - vSemaphoreDelete(rtc_tsens_mux); - rtc_tsens_mux = NULL; + if (s_rtc_tsens_mux != NULL) { + vSemaphoreDelete(s_rtc_tsens_mux); + s_rtc_tsens_mux = NULL; } return ESP_OK; } @@ -127,13 +112,13 @@ esp_err_t temp_sensor_stop(void) esp_err_t temp_sensor_read_raw(uint32_t *tsens_out) { TSENS_CHECK(tsens_out != NULL, ESP_ERR_INVALID_ARG); - TSENS_CHECK(rtc_tsens_mux != NULL, ESP_ERR_INVALID_STATE); - xSemaphoreTake(rtc_tsens_mux, portMAX_DELAY); + TSENS_CHECK(s_rtc_tsens_mux != NULL, ESP_ERR_INVALID_STATE); + xSemaphoreTake(s_rtc_tsens_mux, portMAX_DELAY); SENS.sar_tctrl.tsens_dump_out = 1; while (!SENS.sar_tctrl.tsens_ready); *tsens_out = SENS.sar_tctrl.tsens_out; SENS.sar_tctrl.tsens_dump_out = 0; - xSemaphoreGive(rtc_tsens_mux); + xSemaphoreGive(s_rtc_tsens_mux); return ESP_OK; } diff --git a/components/esp_hw_support/port/esp32c3/regi2c_ctrl.h b/components/esp_hw_support/port/esp32c3/regi2c_ctrl.h index a8a07a8c1b..bee967ac7d 100644 --- a/components/esp_hw_support/port/esp32c3/regi2c_ctrl.h +++ b/components/esp_hw_support/port/esp32c3/regi2c_ctrl.h @@ -43,10 +43,16 @@ extern "C" { #define ANA_CONFIG_REG 0x6000E044 #define ANA_CONFIG_S (8) #define ANA_CONFIG_M (0x3FF) -/* Clear to enable APLL */ -#define I2C_APLL_M (BIT(14)) -/* Clear to enable BBPLL */ -#define I2C_BBPLL_M (BIT(17)) + +#define ANA_I2C_SAR_FORCE_PD BIT(18) +#define ANA_I2C_BBPLL_M (BIT(17)) /* Clear to enable BBPLL */ +#define ANA_I2C_APLL_M (BIT(14)) /* Clear to enable APLL */ + + +#define ANA_CONFIG2_REG 0x6000E048 +#define ANA_CONFIG2_M (BIT(18)) + +#define ANA_I2C_SAR_FORCE_PU BIT(16) /* ROM functions which read/write internal control bus */ uint8_t rom_i2c_readReg(uint8_t block, uint8_t host_id, uint8_t reg_add); diff --git a/components/esp_hw_support/port/esp32c3/rtc_clk_init.c b/components/esp_hw_support/port/esp32c3/rtc_clk_init.c index 40fbdd81ae..3c4314a85e 100644 --- a/components/esp_hw_support/port/esp32c3/rtc_clk_init.c +++ b/components/esp_hw_support/port/esp32c3/rtc_clk_init.c @@ -55,7 +55,7 @@ void rtc_clk_init(rtc_clk_config_t cfg) /* Enable the internal bus used to configure PLLs */ SET_PERI_REG_BITS(ANA_CONFIG_REG, ANA_CONFIG_M, ANA_CONFIG_M, ANA_CONFIG_S); - CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, I2C_APLL_M | I2C_BBPLL_M); + CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_APLL_M | ANA_I2C_BBPLL_M); rtc_xtal_freq_t xtal_freq = cfg.xtal_freq; esp_rom_uart_tx_wait_idle(0); From 33647c7cd4bde2460f510f7a62ce443987af5cbf Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Mon, 11 Jan 2021 16:26:50 +0800 Subject: [PATCH 12/22] update temperature Sensor driver for esp32c3 --- components/driver/esp32c3/rtc_tempsensor.c | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/components/driver/esp32c3/rtc_tempsensor.c b/components/driver/esp32c3/rtc_tempsensor.c index 55620f2472..a62b95db1d 100644 --- a/components/driver/esp32c3/rtc_tempsensor.c +++ b/components/driver/esp32c3/rtc_tempsensor.c @@ -21,7 +21,9 @@ #include "soc/rtc_cntl_reg.h" #include "driver/temp_sensor.h" #include "esp32c3/rom/ets_sys.h" -#include "regi2c_ctrl.h" +#include "soc/apb_saradc_struct.h" +#include "soc/apb_saradc_reg.h" +#include "soc/system_reg.h" static const char *TAG = "tsens"; @@ -36,7 +38,6 @@ static const char *TAG = "tsens"; #define TSENS_DAC_FACTOR (27.88) #define TSENS_SYS_OFFSET (20.52) - typedef struct { int index; int offset; @@ -59,13 +60,13 @@ static SemaphoreHandle_t s_rtc_tsens_mux = NULL; esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens) { + REG_SET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_TSENS_CLK_EN); CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD); SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU); REGI2C_WRITE_MASK(I2C_ADC, I2C_SARADC_TSENS_DAC, dac_offset[tsens.dac_offset].set_val); - SENS.sar_tctrl.tsens_clk_div = tsens.clk_div; - SENS.sar_tctrl.tsens_power_up_force = 1; - SENS.sar_tctrl2.tsens_xpd_wait = TSENS_XPD_WAIT_DEFAULT; - SENS.sar_tctrl2.tsens_xpd_force = 1; + APB_SARADC.apb_tsens_ctrl.tsens_clk_div = tsens.clk_div; + APB_SARADC.apb_tsens_ctrl2.tsens_xpd_wait = TSENS_XPD_WAIT_DEFAULT; + APB_SARADC.apb_tsens_ctrl2.tsens_xpd_force = 1; ESP_LOGD(TAG, "Config temperature range [%d°C ~ %d°C], error < %d°C", dac_offset[tsens.dac_offset].range_min, dac_offset[tsens.dac_offset].range_max, @@ -85,7 +86,7 @@ esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens) break; } } - tsens->clk_div = SENS.sar_tctrl.tsens_clk_div; + tsens->clk_div = APB_SARADC.apb_tsens_ctrl.tsens_clk_div; return ESP_OK; } @@ -95,13 +96,16 @@ esp_err_t temp_sensor_start(void) s_rtc_tsens_mux = xSemaphoreCreateMutex(); } TSENS_CHECK(s_rtc_tsens_mux != NULL, ESP_ERR_NO_MEM); + REG_SET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_TSENS_CLK_EN); + APB_SARADC.apb_tsens_ctrl2.tsens_clk_sel = 1; + APB_SARADC.apb_tsens_ctrl.tsens_pu = 1; return ESP_OK; } esp_err_t temp_sensor_stop(void) { - SENS.sar_tctrl.tsens_power_up = 0; - // SENS.sar_tctrl2.tsens_clkgate_en = 0; + APB_SARADC.apb_tsens_ctrl.tsens_pu = 0; + APB_SARADC.apb_tsens_ctrl2.tsens_clk_sel = 0; if (s_rtc_tsens_mux != NULL) { vSemaphoreDelete(s_rtc_tsens_mux); s_rtc_tsens_mux = NULL; @@ -114,10 +118,7 @@ esp_err_t temp_sensor_read_raw(uint32_t *tsens_out) TSENS_CHECK(tsens_out != NULL, ESP_ERR_INVALID_ARG); TSENS_CHECK(s_rtc_tsens_mux != NULL, ESP_ERR_INVALID_STATE); xSemaphoreTake(s_rtc_tsens_mux, portMAX_DELAY); - SENS.sar_tctrl.tsens_dump_out = 1; - while (!SENS.sar_tctrl.tsens_ready); - *tsens_out = SENS.sar_tctrl.tsens_out; - SENS.sar_tctrl.tsens_dump_out = 0; + *tsens_out = APB_SARADC.apb_tsens_ctrl.tsens_out; xSemaphoreGive(s_rtc_tsens_mux); return ESP_OK; } @@ -130,6 +131,7 @@ esp_err_t temp_sensor_read_celsius(float *celsius) esp_err_t ret = temp_sensor_get_config(&tsens); if (ret == ESP_OK) { ret = temp_sensor_read_raw(&tsens_out); + printf("tsens_out %d\r\n", tsens_out); TSENS_CHECK(ret == ESP_OK, ret); const tsens_dac_offset_t *dac = &dac_offset[tsens.dac_offset]; *celsius = (TSENS_ADC_FACTOR * (float)tsens_out - TSENS_DAC_FACTOR * dac->offset - TSENS_SYS_OFFSET); From feb293797f3f11ab95636e542c5a3ad52f845608 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 13 Jan 2021 10:45:57 +1100 Subject: [PATCH 13/22] driver: esp32c3 rtc_tempsensor compile fixes --- components/driver/CMakeLists.txt | 3 ++- components/driver/esp32c3/rtc_tempsensor.c | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 4e71325b50..858634b4b9 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -67,7 +67,8 @@ if(IDF_TARGET STREQUAL "esp32c3") list(APPEND srcs "gdma.c" "spi_slave_hd.c" "esp32c3/adc.c" - "esp32c3/adc2_init_cal.c") + "esp32c3/adc2_init_cal.c" + "esp32c3/rtc_tempsensor.c") endif() idf_component_register(SRCS "${srcs}" diff --git a/components/driver/esp32c3/rtc_tempsensor.c b/components/driver/esp32c3/rtc_tempsensor.c index a62b95db1d..2a6775dccb 100644 --- a/components/driver/esp32c3/rtc_tempsensor.c +++ b/components/driver/esp32c3/rtc_tempsensor.c @@ -18,12 +18,14 @@ #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "esp_log.h" +#include "hal/adc_ll.h" #include "soc/rtc_cntl_reg.h" -#include "driver/temp_sensor.h" -#include "esp32c3/rom/ets_sys.h" #include "soc/apb_saradc_struct.h" #include "soc/apb_saradc_reg.h" #include "soc/system_reg.h" +#include "driver/temp_sensor.h" +#include "regi2c_ctrl.h" +#include "esp32c3/rom/ets_sys.h" static const char *TAG = "tsens"; @@ -63,7 +65,7 @@ esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens) REG_SET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_TSENS_CLK_EN); CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD); SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU); - REGI2C_WRITE_MASK(I2C_ADC, I2C_SARADC_TSENS_DAC, dac_offset[tsens.dac_offset].set_val); + REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, dac_offset[tsens.dac_offset].set_val); APB_SARADC.apb_tsens_ctrl.tsens_clk_div = tsens.clk_div; APB_SARADC.apb_tsens_ctrl2.tsens_xpd_wait = TSENS_XPD_WAIT_DEFAULT; APB_SARADC.apb_tsens_ctrl2.tsens_xpd_force = 1; @@ -79,7 +81,7 @@ esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens) TSENS_CHECK(tsens != NULL, ESP_ERR_INVALID_ARG); CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD); SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU); - tsens->dac_offset = REGI2C_READ_MASK(I2C_ADC, I2C_SARADC_TSENS_DAC); + tsens->dac_offset = REGI2C_READ_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC); for (int i = TSENS_DAC_L0; i < TSENS_DAC_MAX; i++) { if (tsens->dac_offset == dac_offset[i].set_val) { tsens->dac_offset = dac_offset[i].index; From 271c97149da37cd224c66459dd27ab4e104c9178 Mon Sep 17 00:00:00 2001 From: Armando Date: Fri, 22 Jan 2021 16:42:25 +0800 Subject: [PATCH 14/22] rtc_tmpsensor: remove redundant semaphore on c3 --- components/driver/esp32c3/rtc_tempsensor.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/components/driver/esp32c3/rtc_tempsensor.c b/components/driver/esp32c3/rtc_tempsensor.c index 2a6775dccb..dc3e118f82 100644 --- a/components/driver/esp32c3/rtc_tempsensor.c +++ b/components/driver/esp32c3/rtc_tempsensor.c @@ -58,8 +58,6 @@ static const tsens_dac_offset_t dac_offset[TSENS_DAC_MAX] = { {TSENS_DAC_L4, 2, 10, -40, 20, 3}, }; -static SemaphoreHandle_t s_rtc_tsens_mux = NULL; - esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens) { REG_SET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_TSENS_CLK_EN); @@ -94,10 +92,6 @@ esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens) esp_err_t temp_sensor_start(void) { - if (s_rtc_tsens_mux == NULL) { - s_rtc_tsens_mux = xSemaphoreCreateMutex(); - } - TSENS_CHECK(s_rtc_tsens_mux != NULL, ESP_ERR_NO_MEM); REG_SET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_TSENS_CLK_EN); APB_SARADC.apb_tsens_ctrl2.tsens_clk_sel = 1; APB_SARADC.apb_tsens_ctrl.tsens_pu = 1; @@ -108,20 +102,13 @@ esp_err_t temp_sensor_stop(void) { APB_SARADC.apb_tsens_ctrl.tsens_pu = 0; APB_SARADC.apb_tsens_ctrl2.tsens_clk_sel = 0; - if (s_rtc_tsens_mux != NULL) { - vSemaphoreDelete(s_rtc_tsens_mux); - s_rtc_tsens_mux = NULL; - } return ESP_OK; } esp_err_t temp_sensor_read_raw(uint32_t *tsens_out) { TSENS_CHECK(tsens_out != NULL, ESP_ERR_INVALID_ARG); - TSENS_CHECK(s_rtc_tsens_mux != NULL, ESP_ERR_INVALID_STATE); - xSemaphoreTake(s_rtc_tsens_mux, portMAX_DELAY); *tsens_out = APB_SARADC.apb_tsens_ctrl.tsens_out; - xSemaphoreGive(s_rtc_tsens_mux); return ESP_OK; } From 5798c22a5c4049fcc60578a62972167643ed748e Mon Sep 17 00:00:00 2001 From: Armando Date: Fri, 22 Jan 2021 17:19:02 +0800 Subject: [PATCH 15/22] adc: replace assert with esp check --- components/esp_adc_cal/esp_adc_cal_esp32c3.c | 30 ++++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/components/esp_adc_cal/esp_adc_cal_esp32c3.c b/components/esp_adc_cal/esp_adc_cal_esp32c3.c index 28f23bdee7..f7e4495e03 100644 --- a/components/esp_adc_cal/esp_adc_cal_esp32c3.c +++ b/components/esp_adc_cal/esp_adc_cal_esp32c3.c @@ -55,33 +55,36 @@ typedef struct { } efuse_data; } adc_calib_parsed_info; -static bool prepare_calib_data_for(int version_num, adc_unit_t adc_num, adc_atten_t atten, adc_calib_parsed_info *parsed_data_storage) +static esp_err_t prepare_calib_data_for(int version_num, adc_unit_t adc_num, adc_atten_t atten, adc_calib_parsed_info *parsed_data_storage) { assert(version_num == 1); + esp_err_t ret; + parsed_data_storage->version_num = version_num; parsed_data_storage->adc_num = adc_num; parsed_data_storage->atten_level = atten; // V1 we don't have calibration data for ADC2, using the efuse data of ADC1 uint32_t voltage, digi; - esp_err_t ret = esp_efuse_rtc_calib_get_cal_voltage(version_num, atten, &digi, &voltage); - assert(ret == ESP_OK); + ret = esp_efuse_rtc_calib_get_cal_voltage(version_num, atten, &digi, &voltage); + if (ret != ESP_OK) { + return ret; + } parsed_data_storage->efuse_data.ver1.voltage = voltage; parsed_data_storage->efuse_data.ver1.digi = digi; - return true; + return ret; } /* ----------------------- Characterization Functions ----------------------- */ /* * Estimate the (assumed) linear relationship btwn the measured raw value and the voltage * with the previously done measurement when the chip was manufactured. - * */ -static bool calculate_characterization_coefficients(const adc_calib_parsed_info *parsed_data, esp_adc_cal_characteristics_t *chars) + */ +static void calculate_characterization_coefficients(const adc_calib_parsed_info *parsed_data, esp_adc_cal_characteristics_t *chars) { ESP_LOGD(LOG_TAG, "Calib V1, Cal Voltage = %d, Digi out = %d\n", parsed_data->efuse_data.ver1.voltage, parsed_data->efuse_data.ver1.digi); chars->coeff_a = coeff_a_scaling * parsed_data->efuse_data.ver1.voltage / parsed_data->efuse_data.ver1.digi; chars->coeff_b = 0; - return true; } /* ------------------------- Public API ------------------------------------- */ @@ -104,12 +107,13 @@ esp_adc_cal_value_t esp_adc_cal_characterize(adc_unit_t adc_num, uint32_t default_vref, esp_adc_cal_characteristics_t *chars) { - bool res; + esp_err_t ret; adc_calib_parsed_info efuse_parsed_data = {0}; // Check parameters ADC_CALIB_CHECK(adc_num == ADC_UNIT_1 || adc_num == ADC_UNIT_2, "Invalid unit num", ESP_ADC_CAL_VAL_NOT_SUPPORTED); ADC_CALIB_CHECK(chars != NULL, "Invalid characteristic", ESP_ADC_CAL_VAL_NOT_SUPPORTED); ADC_CALIB_CHECK(bit_width == ADC_WIDTH_BIT_12, "Invalid bit_width", ESP_ADC_CAL_VAL_NOT_SUPPORTED); + ADC_CALIB_CHECK(atten < 4, "Invalid attenuation", ESP_ADC_CAL_VAL_NOT_SUPPORTED); int version_num = esp_efuse_rtc_calib_get_ver(); ADC_CALIB_CHECK(version_num == 1, "No calibration efuse burnt", ESP_ADC_CAL_VAL_NOT_SUPPORTED); @@ -117,10 +121,12 @@ esp_adc_cal_value_t esp_adc_cal_characterize(adc_unit_t adc_num, memset(chars, 0, sizeof(esp_adc_cal_characteristics_t)); // make sure adc is calibrated. - res = prepare_calib_data_for(version_num, adc_num, atten, &efuse_parsed_data); - assert(res); - res = calculate_characterization_coefficients(&efuse_parsed_data, chars); - assert(res); + ret = prepare_calib_data_for(version_num, adc_num, atten, &efuse_parsed_data); + if (ret != ESP_OK) { + abort(); + } + + calculate_characterization_coefficients(&efuse_parsed_data, chars); ESP_LOGD(LOG_TAG, "adc%d (atten leven %d) calibration done: A:%d B:%d\n", adc_num, atten, chars->coeff_a, chars->coeff_b); // Initialize remaining fields From 19fb11549bc9056c04d26e84162f905b4216e55c Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Thu, 31 Dec 2020 22:44:36 +0800 Subject: [PATCH 16/22] driver(adc): update adc ll and hal driver for esp32c3 --- components/driver/esp32c3/adc.c | 44 +- components/hal/adc_hal.c | 4 +- components/hal/esp32c3/adc_hal.c | 42 +- components/hal/esp32c3/include/hal/adc_hal.h | 49 +- components/hal/esp32c3/include/hal/adc_ll.h | 727 +++++++------------ components/hal/include/hal/adc_hal.h | 2 + components/hal/include/hal/adc_types.h | 24 + 7 files changed, 344 insertions(+), 548 deletions(-) diff --git a/components/driver/esp32c3/adc.c b/components/driver/esp32c3/adc.c index 3dfb86efc0..3123ed4a72 100644 --- a/components/driver/esp32c3/adc.c +++ b/components/driver/esp32c3/adc.c @@ -675,11 +675,7 @@ esp_err_t adc_digi_filter_reset(adc_digi_filter_idx_t idx) esp_err_t adc_digi_filter_set_config(adc_digi_filter_idx_t idx, adc_digi_filter_t *config) { ADC_ENTER_CRITICAL(); - if (idx == ADC_DIGI_FILTER_IDX0) { - adc_hal_digi_filter_set_factor(ADC_NUM_1, config->mode); - } else if (idx == ADC_DIGI_FILTER_IDX1) { - adc_hal_digi_filter_set_factor(ADC_NUM_2, config->mode); - } + adc_hal_digi_filter_set_factor(idx, config); ADC_EXIT_CRITICAL(); return ESP_OK; } @@ -687,28 +683,13 @@ esp_err_t adc_digi_filter_set_config(adc_digi_filter_idx_t idx, adc_digi_filter_ esp_err_t adc_digi_filter_get_config(adc_digi_filter_idx_t idx, adc_digi_filter_t *config) { ADC_ENTER_CRITICAL(); - if (idx == ADC_DIGI_FILTER_IDX0) { - config->adc_unit = ADC_UNIT_1; - config->channel = ADC_CHANNEL_MAX; - adc_hal_digi_filter_get_factor(ADC_NUM_1, &config->mode); - } else if (idx == ADC_DIGI_FILTER_IDX1) { - config->adc_unit = ADC_UNIT_2; - config->channel = ADC_CHANNEL_MAX; - adc_hal_digi_filter_get_factor(ADC_NUM_2, &config->mode); - } + adc_hal_digi_filter_get_factor(idx, config); ADC_EXIT_CRITICAL(); return ESP_OK; } esp_err_t adc_digi_filter_enable(adc_digi_filter_idx_t idx, bool enable) { - ADC_ENTER_CRITICAL(); - if (idx == ADC_DIGI_FILTER_IDX0) { - adc_hal_digi_filter_enable(ADC_NUM_1, enable); - } else if (idx == ADC_DIGI_FILTER_IDX1) { - adc_hal_digi_filter_enable(ADC_NUM_2, enable); - } - ADC_EXIT_CRITICAL(); return ESP_OK; } @@ -721,13 +702,7 @@ esp_err_t adc_digi_filter_enable(adc_digi_filter_idx_t idx, bool enable) */ int adc_digi_filter_read_data(adc_digi_filter_idx_t idx) { - if (idx == ADC_DIGI_FILTER_IDX0) { - return adc_hal_digi_filter_read_data(ADC_NUM_1); - } else if (idx == ADC_DIGI_FILTER_IDX1) { - return adc_hal_digi_filter_read_data(ADC_NUM_2); - } else { - return -1; - } + return -1; } /**************************************/ @@ -737,24 +712,13 @@ int adc_digi_filter_read_data(adc_digi_filter_idx_t idx) esp_err_t adc_digi_monitor_set_config(adc_digi_monitor_idx_t idx, adc_digi_monitor_t *config) { ADC_ENTER_CRITICAL(); - if (idx == ADC_DIGI_MONITOR_IDX0) { - adc_hal_digi_monitor_config(ADC_NUM_1, config); - } else if (idx == ADC_DIGI_MONITOR_IDX1) { - adc_hal_digi_monitor_config(ADC_NUM_2, config); - } + adc_hal_digi_monitor_config(idx, config); ADC_EXIT_CRITICAL(); return ESP_OK; } esp_err_t adc_digi_monitor_enable(adc_digi_monitor_idx_t idx, bool enable) { - ADC_ENTER_CRITICAL(); - if (idx == ADC_DIGI_MONITOR_IDX0) { - adc_hal_digi_monitor_enable(ADC_NUM_1, enable); - } else if (idx == ADC_DIGI_MONITOR_IDX1) { - adc_hal_digi_monitor_enable(ADC_NUM_2, enable); - } - ADC_EXIT_CRITICAL(); return ESP_OK; } diff --git a/components/hal/adc_hal.c b/components/hal/adc_hal.c index 73d6a7887d..a04f31d694 100644 --- a/components/hal/adc_hal.c +++ b/components/hal/adc_hal.c @@ -39,6 +39,7 @@ void adc_hal_deinit(void) adc_ll_set_power_manage(ADC_POWER_SW_OFF); } +#ifndef CONFIG_IDF_TARGET_ESP32C3 int adc_hal_convert(adc_ll_num_t adc_n, int channel, int *value) { adc_ll_rtc_enable_channel(adc_n, channel); @@ -47,6 +48,7 @@ int adc_hal_convert(adc_ll_num_t adc_n, int channel, int *value) *value = adc_ll_rtc_get_convert_value(adc_n); return (int)adc_ll_rtc_analysis_raw_data(adc_n, (uint16_t)(*value)); } +#endif #if CONFIG_IDF_TARGET_ESP32C3 //This feature is currently supported on ESP32C3, will be supported on other chips soon @@ -193,7 +195,7 @@ esp_err_t adc_hal_single_read(adc_ll_num_t unit, int *out_raw) *out_raw = adc_ll_adc1_read(); } else if (unit == ADC_NUM_2) { *out_raw = adc_ll_adc2_read(); - if (adc_ll_rtc_analysis_raw_data(unit, *out_raw)) { + if (adc_ll_analysis_raw_data(unit, *out_raw)) { return ESP_ERR_INVALID_STATE; } } diff --git a/components/hal/esp32c3/adc_hal.c b/components/hal/esp32c3/adc_hal.c index a2ab50c02b..cb41e2b39e 100644 --- a/components/hal/esp32c3/adc_hal.c +++ b/components/hal/esp32c3/adc_hal.c @@ -94,17 +94,49 @@ void adc_hal_digi_disable(void) adc_ll_digi_dma_disable(); } +/** + * 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) +{ + if (filter->mode == ADC_DIGI_FILTER_DIS) { + adc_ll_digi_filter_disable(idx); + } else { + adc_ll_digi_filter_set_factor(idx, filter); + } +} + +/** + * 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) +{ + adc_ll_digi_filter_get_factor(idx, filter); + if (((filter->adc_unit << 3) | filter->channel) > 9) { + filter->mode = ADC_DIGI_FILTER_DIS; + } +} + /** * Config 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 adc_n ADC unit. + * @note If the channel info is not supported, the monitor function will not be enabled. + * @param idx ADC monitor index. * @param config Refer to `adc_digi_monitor_t`. */ -void adc_hal_digi_monitor_config(adc_ll_num_t adc_n, adc_digi_monitor_t *config) +void adc_hal_digi_monitor_config(adc_digi_monitor_idx_t idx, adc_digi_monitor_t *config) { - adc_ll_digi_monitor_set_mode(adc_n, config->mode); - adc_ll_digi_monitor_set_thres(adc_n, config->threshold); + if (config->mode == ADC_DIGI_MONITOR_DIS) { + adc_ll_digi_monitor_disable(idx); + } else { + adc_ll_digi_monitor_set_mode(idx, config); + } } /*--------------------------------------------------------------- diff --git a/components/hal/esp32c3/include/hal/adc_hal.h b/components/hal/esp32c3/include/hal/adc_hal.h index 1e9e972c2f..fc6a618796 100644 --- a/components/hal/esp32c3/include/hal/adc_hal.h +++ b/components/hal/esp32c3/include/hal/adc_hal.h @@ -91,10 +91,10 @@ void adc_hal_digi_clk_config(const adc_digi_clk_t *clk); /** * Set 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). + * @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). */ -#define adc_hal_digi_filter_set_factor(adc_n, factor) adc_ll_digi_filter_set_factor(adc_n, factor) +void adc_hal_digi_filter_set_factor(adc_digi_filter_idx_t idx, adc_digi_filter_t *filter); /** * Get adc digital controller filter factor. @@ -102,43 +102,16 @@ void adc_hal_digi_clk_config(const adc_digi_clk_t *clk); * @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). */ -#define adc_hal_digi_filter_get_factor(adc_n, factor) adc_ll_digi_filter_get_factor(adc_n, factor) - -/** - * 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 adc_n ADC unit. - */ -#define adc_hal_digi_filter_enable(adc_n, enable) adc_ll_digi_filter_enable(adc_n, enable) - -/** - * Get the filtered data of adc digital controller filter. - * The data after each measurement and filtering is updated to the DMA by the digital controller. But it can also be obtained manually through this API. - * - * @note The filter will filter all the enabled channel data of the each ADC unit at the same time. - * @param adc_n ADC unit. - * @return Filtered data. - */ -#define adc_hal_digi_filter_read_data(adc_n) adc_ll_digi_filter_read_data(adc_n) +void adc_hal_digi_filter_get_factor(adc_digi_filter_idx_t idx, adc_digi_filter_t *filter); /** * Config 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 adc_n ADC unit. + * @note If the channel info is not supported, the monitor function will not be enabled. + * @param idx ADC monitor index. * @param config Refer to `adc_digi_monitor_t`. */ -void adc_hal_digi_monitor_config(adc_ll_num_t adc_n, 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 adc_n ADC unit. - */ -#define adc_hal_digi_monitor_enable(adc_n, enable) adc_ll_digi_monitor_enable(adc_n, enable) +void adc_hal_digi_monitor_config(adc_digi_monitor_idx_t idx, adc_digi_monitor_t *config); /** * Enable interrupt of adc digital controller by bitmask. @@ -197,14 +170,6 @@ void adc_hal_digi_monitor_config(adc_ll_num_t adc_n, adc_digi_monitor_t *config) */ #define adc_hal_digi_reset() adc_ll_digi_reset() -/*--------------------------------------------------------------- - RTC controller setting ----------------------------------------------------------------*/ -/** - * Reset RTC controller FSM. - */ -#define adc_hal_rtc_reset() adc_ll_rtc_reset() - /*--------------------------------------------------------------- Common setting ---------------------------------------------------------------*/ diff --git a/components/hal/esp32c3/include/hal/adc_ll.h b/components/hal/esp32c3/include/hal/adc_ll.h index 6212c5f631..59bab42995 100644 --- a/components/hal/esp32c3/include/hal/adc_ll.h +++ b/components/hal/esp32c3/include/hal/adc_ll.h @@ -22,7 +22,8 @@ #include "hal/adc_types.h" #include "soc/apb_saradc_struct.h" #include "soc/apb_saradc_reg.h" - +#include "soc/rtc_cntl_struct.h" +#include "soc/rtc_cntl_reg.h" #ifdef __cplusplus extern "C" { @@ -56,32 +57,6 @@ typedef enum { } adc_ll_intr_t; FLAG_ATTR(adc_ll_intr_t) -#ifdef _MSC_VER -#pragma pack(push, 1) -#endif /* _MSC_VER */ - -/** - * @brief Analyze whether the obtained raw data is correct. - * ADC2 use arbiter by default. The arbitration result can be judged by the flag bit in the original data. - * - */ -typedef struct { - union { - struct { - uint16_t data: 13; /*! 0), The data is invalid. */ - }; - uint16_t val; - }; -} adc_rtc_output_data_t; - -#ifdef _MSC_VER -#pragma pack(pop) -#endif /* _MSC_VER */ - /** * @brief ADC controller type selection. * @@ -128,7 +103,9 @@ static inline void adc_ll_digi_set_fsm_time(uint32_t rst_wait, uint32_t start_wa */ static inline void adc_ll_set_sample_cycle(uint32_t sample_cycle) { - // APB_SARADC.fsm.sample_cycle = sample_cycle; + /* Should be called before writing I2C registers. */ + SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_PU); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR1_SAMPLE_CYCLE_ADDR, sample_cycle); } /** @@ -143,16 +120,6 @@ static inline void adc_ll_digi_set_clk_div(uint32_t div) APB_SARADC.ctrl.sar_clk_div = div; } -/** - * Set adc output data format for digital controller. - * - * @param format Output data format. - */ -static inline void adc_ll_digi_set_output_format(adc_digi_output_format_t format) -{ - /*take off*/ -} - /** * Set adc max conversion number for digital controller. * If the number of ADC conversion is equal to the maximum, the conversion is stopped. @@ -182,50 +149,32 @@ 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 ESP32 only support ADC1 single mode. - * - * @param mode Conversion mode select. - */ -static inline void adc_ll_digi_set_convert_mode(adc_digi_convert_mode_t mode) -{ - /*take off*/ -} - /** * Set pattern table length for digital controller. - * The pattern table that defines the conversion rules for each SAR ADC. Each table has 16 items, in which channel selection, - * resolution and attenuation are stored. When the conversion is started, the controller reads conversion rules from the - * pattern table one by one. For each controller the scan sequence has at most 16 different rules before repeating itself. + * The pattern table that defines the conversion rules for each SAR ADC. Each table has 8 items, in which channel selection, + * and attenuation are stored. When the conversion is started, the controller reads conversion rules from the + * pattern table one by one. For each controller the scan sequence has at most 8 different rules before repeating itself. * * @param adc_n ADC unit. * @param patt_len Items range: 1 ~ 8. */ static inline void adc_ll_digi_set_pattern_table_len(adc_ll_num_t adc_n, uint32_t patt_len) { - /* - * channel 可以配置为0~6, 其中 0~4 代表 ADC1 , 5 代表 ADC2 , 6 代表有 EN_TEST 的测试选项,可以采样内部的一些电压信号 - */ APB_SARADC.ctrl.sar_patt_len = patt_len - 1; } /** * Set pattern table for digital controller. - * The pattern table that defines the conversion rules for each SAR ADC. Each table has 16 items, in which channel selection, + * The pattern table that defines the conversion rules for each SAR ADC. Each table has 8 items, in which channel selection, * resolution and attenuation are stored. When the conversion is started, the controller reads conversion rules from the - * pattern table one by one. For each controller the scan sequence has at most 16 different rules before repeating itself. + * pattern table one by one. For each controller the scan sequence has at most 8 different rules before repeating itself. * * @param adc_n ADC unit. - * @param pattern_index Items index. Range: 0 ~ 15. + * @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) { - /* - * channel 可以配置为0~6, 其中 0~4 代表 ADC1 , 5 代表 ADC2 , 6 代表有 EN_TEST 的测试选项,可以采样内部的一些电压信号 - */ uint32_t tab; uint8_t index = pattern_index / 4; uint8_t offset = (pattern_index % 4) * 6; @@ -234,7 +183,6 @@ static inline void adc_ll_digi_set_pattern_table(adc_ll_num_t adc_n, uint32_t pa tab &= (~(0xFC0000 >> offset)); // clear old data tab |= ((uint32_t)pattern.val << 18) >> offset; // Fill in the new data APB_SARADC.sar_patt_tab[index].sar_patt_tab1 = tab; // Write back - } /** @@ -244,9 +192,6 @@ static inline void adc_ll_digi_set_pattern_table(adc_ll_num_t adc_n, uint32_t pa */ static inline void adc_ll_digi_clear_pattern_table(adc_ll_num_t adc_n) { - /* - * channel 可以配置为0~6, 其中 0~4 代表 ADC1 , 5 代表 ADC2 , 6 代表有 EN_TEST 的测试选项,可以采样内部的一些电压信号 - */ APB_SARADC.ctrl.sar_patt_p_clear = 1; APB_SARADC.ctrl.sar_patt_p_clear = 0; } @@ -310,7 +255,7 @@ static inline void adc_ll_digi_trigger_disable(void) * * @param div_num Division factor. Range: 1 ~ 255. * @param div_b Division factor. Range: 1 ~ 63. - * @param div_a Division factor. Range: 1 ~ 63. + * @param div_a Division factor. Range: 0 ~ 63. */ static inline void adc_ll_digi_controller_clk_div(uint32_t div_num, uint32_t div_b, uint32_t div_a) { @@ -356,18 +301,18 @@ static inline void adc_ll_digi_filter_reset(adc_ll_num_t adc_n) /** * Set 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). + * @note If the channel info is not supported, the filter function will not be enabled. + * @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). */ -static inline void adc_ll_digi_filter_set_factor(adc_ll_num_t adc_n, adc_digi_filter_mode_t factor) +static inline void adc_ll_digi_filter_set_factor(adc_digi_filter_idx_t idx, adc_digi_filter_t *filter) { - adc_channel_t channel = 0; - if (!APB_SARADC.filter_ctrl0.filter_channel0) { - APB_SARADC.filter_ctrl0.filter_channel0 = (adc_n<<4) | channel; - APB_SARADC.filter_ctrl1.filter_factor0 = factor; - } else if (!APB_SARADC.filter_ctrl0.filter_channel1) { - APB_SARADC.filter_ctrl0.filter_channel1 = (adc_n<<4) | channel; - APB_SARADC.filter_ctrl1.filter_factor1 = factor; + if (idx == ADC_DIGI_FILTER_IDX0) { + APB_SARADC.filter_ctrl0.filter_channel0 = (filter->adc_unit << 3) | (filter->channel & 0x7); + APB_SARADC.filter_ctrl1.filter_factor0 = filter->mode; + } else if (idx == ADC_DIGI_FILTER_IDX1) { + APB_SARADC.filter_ctrl0.filter_channel1 = (filter->adc_unit << 3) | (filter->channel & 0x7); + APB_SARADC.filter_ctrl1.filter_factor1 = filter->mode; } } @@ -377,91 +322,71 @@ static inline void adc_ll_digi_filter_set_factor(adc_ll_num_t adc_n, adc_digi_fi * @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). */ -static inline void adc_ll_digi_filter_get_factor(adc_ll_num_t adc_n, adc_digi_filter_mode_t *factor) +static inline void adc_ll_digi_filter_get_factor(adc_digi_filter_idx_t idx, adc_digi_filter_t *filter) { - + if (idx == ADC_DIGI_FILTER_IDX0) { + filter->adc_unit = (APB_SARADC.filter_ctrl0.filter_channel0 >> 3) & 0x1; + filter->channel = APB_SARADC.filter_ctrl0.filter_channel0 & 0x7; + filter->mode = APB_SARADC.filter_ctrl1.filter_factor0; + } else if (idx == ADC_DIGI_FILTER_IDX1) { + filter->adc_unit = (APB_SARADC.filter_ctrl0.filter_channel1 >> 3) & 0x1; + filter->channel = APB_SARADC.filter_ctrl0.filter_channel1 & 0x7; + filter->mode = APB_SARADC.filter_ctrl1.filter_factor1; + } } /** - * Enable/disable adc digital controller filter. + * 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. + * + * @note If the channel info is not supported, the filter function will not be enabled. * @param adc_n ADC unit. */ -static inline void adc_ll_digi_filter_enable(adc_ll_num_t adc_n, bool enable) +static inline void adc_ll_digi_filter_disable(adc_digi_filter_idx_t idx) { - // if (adc_n == ADC_NUM_1) { - // APB_SARADC.filter_ctrl.adc1_filter_en = enable; - // } else { // adc_n == ADC_NUM_2 - // APB_SARADC.filter_ctrl.adc2_filter_en = enable; - // } -} - -/** - * Get the filtered data of adc digital controller filter. - * The data after each measurement and filtering is updated to the DMA by the digital controller. But it can also be obtained manually through this API. - * - * @note The filter will filter all the enabled channel data of the each ADC unit at the same time. - * @param adc_n ADC unit. - * @return Filtered data. - */ -static inline uint32_t adc_ll_digi_filter_read_data(adc_ll_num_t adc_n) -{ - abort(); // FIXME - // if (adc_n == ADC_NUM_1) { - // return APB_SARADC.filter_status.adc1_filter_data; - // } else { // adc_n == ADC_NUM_2 - // return APB_SARADC.filter_status.adc2_filter_data; - // } + if (idx == ADC_DIGI_FILTER_IDX0) { + APB_SARADC.filter_ctrl0.filter_channel0 = 0xF; + APB_SARADC.filter_ctrl1.filter_factor0 = 0; + } else if (idx == ADC_DIGI_FILTER_IDX1) { + APB_SARADC.filter_ctrl0.filter_channel1 = 0xF; + APB_SARADC.filter_ctrl1.filter_factor1 = 0; + } } /** * Set monitor mode of adc digital controller. * - * @note The monitor will monitor all the enabled channel data of the each ADC unit at the same time. + * @note If the channel info is not supported, the monitor function will not be enabled. * @param adc_n ADC unit. * @param is_larger true: If ADC_OUT > threshold, Generates monitor interrupt. * false: If ADC_OUT < threshold, Generates monitor interrupt. */ -static inline void adc_ll_digi_monitor_set_mode(adc_ll_num_t adc_n, bool is_larger) +static inline void adc_ll_digi_monitor_set_mode(adc_digi_monitor_idx_t idx, adc_digi_monitor_t *cfg) { - // if (adc_n == ADC_NUM_1) { - // APB_SARADC.thres_ctrl.adc1_thres_mode = is_larger; - // } else { // adc_n == ADC_NUM_2 - // APB_SARADC.thres_ctrl.adc2_thres_mode = is_larger; - // } -} - -/** - * Set monitor threshold of adc digital controller. - * - * @note The monitor will monitor all the enabled channel data of the each ADC unit at the same time. - * @param adc_n ADC unit. - * @param threshold Monitor threshold. - */ -static inline void adc_ll_digi_monitor_set_thres(adc_ll_num_t adc_n, uint32_t threshold) -{ - // if (adc_n == ADC_NUM_1) { - // APB_SARADC.thres_ctrl.adc1_thres = threshold; - // } else { // adc_n == ADC_NUM_2 - // APB_SARADC.thres_ctrl.adc2_thres = threshold; - // } + if (idx == ADC_DIGI_MONITOR_IDX0) { + APB_SARADC.thres0_ctrl.thres0_channel = (cfg->adc_unit << 3) | (cfg->channel & 0x7); + APB_SARADC.thres0_ctrl.thres0_high = cfg->h_threshold; + APB_SARADC.thres0_ctrl.thres0_low = cfg->l_threshold; + } else { // ADC_DIGI_MONITOR_IDX1 + APB_SARADC.thres1_ctrl.thres1_channel = (cfg->adc_unit << 3) | (cfg->channel & 0x7); + APB_SARADC.thres1_ctrl.thres1_high = cfg->h_threshold; + APB_SARADC.thres1_ctrl.thres1_low = cfg->l_threshold; + } } /** * 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. + * @note If the channel info is not supported, the monitor function will not be enabled. * @param adc_n ADC unit. */ -static inline void adc_ll_digi_monitor_enable(adc_ll_num_t adc_n, bool enable) +static inline void adc_ll_digi_monitor_disable(adc_digi_monitor_idx_t idx) { - // if (adc_n == ADC_NUM_1) { - // APB_SARADC.thres_ctrl.adc1_thres_en = enable; - // } else { // adc_n == ADC_NUM_2 - // APB_SARADC.thres_ctrl.adc2_thres_en = enable; - // } + if (idx == ADC_DIGI_MONITOR_IDX0) { + APB_SARADC.thres0_ctrl.thres0_channel = 0xF; + } else { // ADC_DIGI_MONITOR_IDX1 + APB_SARADC.thres1_ctrl.thres1_channel = 0xF; + } } /** @@ -472,21 +397,27 @@ static inline void adc_ll_digi_monitor_enable(adc_ll_num_t adc_n, bool enable) */ static inline void adc_ll_digi_intr_enable(adc_ll_num_t adc_n, adc_digi_intr_t intr) { - // if (adc_n == ADC_NUM_1) { - // if (intr & ADC_DIGI_INTR_MASK_MONITOR) { - // APB_SARADC.int_ena.adc1_thres = 1; - // } - // if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { - // APB_SARADC.int_ena.adc1_done = 1; - // } - // } else { // adc_n == ADC_NUM_2 - // if (intr & ADC_DIGI_INTR_MASK_MONITOR) { - // APB_SARADC.int_ena.adc2_thres = 1; - // } - // if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { - // APB_SARADC.int_ena.adc2_done = 1; - // } - // } + if (adc_n == ADC_NUM_1) { + if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { + APB_SARADC.int_ena.adc1_done = 1; + } + } else { // adc_n == ADC_NUM_2 + if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { + APB_SARADC.int_ena.adc2_done = 1; + } + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR0_HIGH) { + APB_SARADC.int_ena.thres0_high = 1; + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR0_LOW) { + APB_SARADC.int_ena.thres0_low = 1; + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR1_HIGH) { + APB_SARADC.int_ena.thres1_high = 1; + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR1_LOW) { + APB_SARADC.int_ena.thres1_low = 1; + } } /** @@ -497,21 +428,27 @@ static inline void adc_ll_digi_intr_enable(adc_ll_num_t adc_n, adc_digi_intr_t i */ static inline void adc_ll_digi_intr_disable(adc_ll_num_t adc_n, adc_digi_intr_t intr) { - // if (adc_n == ADC_NUM_1) { - // if (intr & ADC_DIGI_INTR_MASK_MONITOR) { - // APB_SARADC.int_ena.adc1_thres = 0; - // } - // if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { - // APB_SARADC.int_ena.adc1_done = 0; - // } - // } else { // adc_n == ADC_NUM_2 - // if (intr & ADC_DIGI_INTR_MASK_MONITOR) { - // APB_SARADC.int_ena.adc2_thres = 0; - // } - // if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { - // APB_SARADC.int_ena.adc2_done = 0; - // } - // } + if (adc_n == ADC_NUM_1) { + if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { + APB_SARADC.int_ena.adc1_done = 0; + } + } else { // adc_n == ADC_NUM_2 + if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { + APB_SARADC.int_ena.adc2_done = 0; + } + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR0_HIGH) { + APB_SARADC.int_ena.thres0_high = 0; + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR0_LOW) { + APB_SARADC.int_ena.thres0_low = 0; + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR1_HIGH) { + APB_SARADC.int_ena.thres1_high = 0; + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR1_LOW) { + APB_SARADC.int_ena.thres1_low = 0; + } } /** @@ -522,21 +459,27 @@ static inline void adc_ll_digi_intr_disable(adc_ll_num_t adc_n, adc_digi_intr_t */ static inline void adc_ll_digi_intr_clear(adc_ll_num_t adc_n, adc_digi_intr_t intr) { - // if (adc_n == ADC_NUM_1) { - // if (intr & ADC_DIGI_INTR_MASK_MONITOR) { - // APB_SARADC.int_clr.adc1_thres = 1; - // } - // if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { - // APB_SARADC.int_clr.adc1_done = 1; - // } - // } else { // adc_n == ADC_NUM_2 - // if (intr & ADC_DIGI_INTR_MASK_MONITOR) { - // APB_SARADC.int_clr.adc2_thres = 1; - // } - // if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { - // APB_SARADC.int_clr.adc2_done = 1; - // } - // } + if (adc_n == ADC_NUM_1) { + if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { + APB_SARADC.int_clr.adc1_done = 1; + } + } else { // adc_n == ADC_NUM_2 + if (intr & ADC_DIGI_INTR_MASK_MEAS_DONE) { + APB_SARADC.int_clr.adc2_done = 1; + } + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR0_HIGH) { + APB_SARADC.int_clr.thres0_high = 1; + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR0_LOW) { + APB_SARADC.int_clr.thres0_low = 1; + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR1_HIGH) { + APB_SARADC.int_clr.thres1_high = 1; + } + if (intr & ADC_DIGI_INTR_MASK_MONITOR1_LOW) { + APB_SARADC.int_clr.thres1_low = 1; + } } /** @@ -548,28 +491,32 @@ static inline void adc_ll_digi_intr_clear(adc_ll_num_t adc_n, adc_digi_intr_t in */ static inline uint32_t adc_ll_digi_get_intr_status(adc_ll_num_t adc_n) { - abort(); // FIXME + uint32_t int_st = APB_SARADC.int_st.val; + uint32_t ret_msk = 0; - // uint32_t int_st = APB_SARADC.int_st.val; - // uint32_t ret_msk = 0; + if (adc_n == ADC_NUM_1) { + if (int_st & APB_SARADC_ADC1_DONE_INT_ST_M) { + ret_msk |= ADC_DIGI_INTR_MASK_MEAS_DONE; + } + } else { // adc_n == ADC_NUM_2 + if (int_st & APB_SARADC_ADC2_DONE_INT_ST_M) { + ret_msk |= ADC_DIGI_INTR_MASK_MEAS_DONE; + } + } + if (int_st & APB_SARADC_THRES0_HIGH_INT_ST) { + ret_msk |= ADC_DIGI_INTR_MASK_MONITOR0_HIGH; + } + if (int_st & APB_SARADC_THRES0_LOW_INT_ST_M) { + ret_msk |= ADC_DIGI_INTR_MASK_MONITOR0_LOW; + } + if (int_st & APB_SARADC_THRES1_HIGH_INT_ST_M) { + ret_msk |= ADC_DIGI_INTR_MASK_MONITOR1_HIGH; + } + if (int_st & APB_SARADC_THRES1_LOW_INT_ST_M) { + ret_msk |= ADC_DIGI_INTR_MASK_MONITOR1_LOW; + } - // if (adc_n == ADC_NUM_1) { - // if (int_st & APB_SARADC_ADC1_DONE_INT_ST_M) { - // ret_msk |= ADC_DIGI_INTR_MASK_MEAS_DONE; - // } - // // if (int_st & APB_SARADC_ADC1_THRES_INT_ST) { - // // ret_msk |= ADC_DIGI_INTR_MASK_MONITOR; - // // } - // } else { // adc_n == ADC_NUM_2 - // if (int_st & APB_SARADC_ADC2_DONE_INT_ST_M) { - // ret_msk |= ADC_DIGI_INTR_MASK_MEAS_DONE; - // } - // // if (int_st & APB_SARADC_ADC2_THRES_INT_ST_M) { - // // ret_msk |= ADC_DIGI_INTR_MASK_MONITOR; - // // } - // } - - // return ret_msk; + return ret_msk; } /** @@ -619,8 +566,8 @@ 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. */ - // SENS.sar_meas2_mux.sar2_pwdet_cct = cct; + /* Capacitor tuning of the PA power monitor. cct set to the same value with PHY. */ + RTCCNTL.sensor_ctrl.sar2_pwdet_cct = cct; } /** @@ -632,186 +579,12 @@ 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 SENS.sar_meas2_mux.sar2_pwdet_cct; - return 0; -} - -/*--------------------------------------------------------------- - RTC controller setting ----------------------------------------------------------------*/ -/** - * Set adc output data format for RTC controller. - * - * @note ESP32S2 RTC controller only support 13bit. - * @prarm adc_n ADC unit. - * @prarm bits Output data bits width option. - */ -static inline void adc_ll_rtc_set_output_format(adc_ll_num_t adc_n, adc_bits_width_t bits) -{ - return; -} - -/** - * Enable adc channel to start convert. - * - * @note Only one channel can be selected for once measurement. - * - * @param adc_n ADC unit. - * @param channel ADC channel number for each ADCn. - */ -static inline void adc_ll_rtc_enable_channel(adc_ll_num_t adc_n, int channel) -{ - // if (adc_n == ADC_NUM_1) { - // SENS.sar_meas1_ctrl2.sar1_en_pad = (1 << channel); //only one channel is selected. - // } else { // adc_n == ADC_NUM_2 - // SENS.sar_meas2_ctrl2.sar2_en_pad = (1 << channel); //only one channel is selected. - // } -} - -/** - * Disable adc channel to start convert. - * - * @note Only one channel can be selected in once measurement. - * - * @param adc_n ADC unit. - * @param channel ADC channel number for each ADCn. - */ -static inline void adc_ll_rtc_disable_channel(adc_ll_num_t adc_n, int channel) -{ - // if (adc_n == ADC_NUM_1) { - // SENS.sar_meas1_ctrl2.sar1_en_pad = 0; //only one channel is selected. - // } else { // adc_n == ADC_NUM_2 - // SENS.sar_meas2_ctrl2.sar2_en_pad = 0; //only one channel is selected. - // } -} - -/** - * Start conversion once by software for RTC controller. - * - * @note It may be block to wait conversion idle for ADC1. - * - * @param adc_n ADC unit. - * @param channel ADC channel number for each ADCn. - */ -static inline void adc_ll_rtc_start_convert(adc_ll_num_t adc_n, int channel) -{ - // if (adc_n == ADC_NUM_1) { - // while (SENS.sar_slave_addr1.meas_status != 0); - // SENS.sar_meas1_ctrl2.meas1_start_sar = 0; - // SENS.sar_meas1_ctrl2.meas1_start_sar = 1; - // } else { // adc_n == ADC_NUM_2 - // SENS.sar_meas2_ctrl2.meas2_start_sar = 0; //start force 0 - // SENS.sar_meas2_ctrl2.meas2_start_sar = 1; //start force 1 - // } -} - -/** - * Check the conversion done flag for each ADCn for RTC controller. - * - * @param adc_n ADC unit. - * @return - * -true : The conversion process is finish. - * -false : The conversion process is not finish. - */ -static inline bool adc_ll_rtc_convert_is_done(adc_ll_num_t adc_n) -{ - bool ret = true; - // if (adc_n == ADC_NUM_1) { - // ret = (bool)SENS.sar_meas1_ctrl2.meas1_done_sar; - // } else { // adc_n == ADC_NUM_2 - // ret = (bool)SENS.sar_meas2_ctrl2.meas2_done_sar; - // } - return ret; -} - -/** - * Get the converted value for each ADCn for RTC controller. - * - * @param adc_n ADC unit. - * @return - * - Converted value. - */ -static inline int adc_ll_rtc_get_convert_value(adc_ll_num_t adc_n) -{ - int ret_val = 0; - // if (adc_n == ADC_NUM_1) { - // ret_val = SENS.sar_meas1_ctrl2.meas1_data_sar; - // } else { // adc_n == ADC_NUM_2 - // ret_val = SENS.sar_meas2_ctrl2.meas2_data_sar; - // } - return ret_val; -} - -/** - * ADC module RTC output data invert or not. - * - * @param adc_n ADC unit. - * @param inv_en data invert or not. - */ -static inline void adc_ll_rtc_output_invert(adc_ll_num_t adc_n, bool inv_en) -{ - // if (adc_n == ADC_NUM_1) { - // SENS.sar_reader1_ctrl.sar1_data_inv = inv_en; // Enable / Disable ADC data invert - // } else { // adc_n == ADC_NUM_2 - // SENS.sar_reader2_ctrl.sar2_data_inv = inv_en; // Enable / Disable ADC data invert - // } -} - -/** - * Enable ADCn conversion complete interrupt for RTC controller. - * - * @param adc_n ADC unit. - */ -static inline void adc_ll_rtc_intr_enable(adc_ll_num_t adc_n) -{ - // if (adc_n == ADC_NUM_1) { - // SENS.sar_reader1_ctrl.sar1_int_en = 1; - // RTCCNTL.int_ena.rtc_saradc1 = 1; - // } else { // adc_n == ADC_NUM_2 - // SENS.sar_reader2_ctrl.sar2_int_en = 1; - // RTCCNTL.int_ena.rtc_saradc2 = 1; - // } -} - -/** - * Disable ADCn conversion complete interrupt for RTC controller. - * - * @param adc_n ADC unit. - */ -static inline void adc_ll_rtc_intr_disable(adc_ll_num_t adc_n) -{ - // if (adc_n == ADC_NUM_1) { - // SENS.sar_reader1_ctrl.sar1_int_en = 0; - // RTCCNTL.int_ena.rtc_saradc1 = 0; - // } else { // adc_n == ADC_NUM_2 - // SENS.sar_reader2_ctrl.sar2_int_en = 0; - // RTCCNTL.int_ena.rtc_saradc2 = 0; - // } -} - -/** - * Reset RTC controller FSM. - */ -static inline void adc_ll_rtc_reset(void) -{ - // SENS.sar_meas1_ctrl1.rtc_saradc_reset = 1; - // SENS.sar_meas1_ctrl1.rtc_saradc_reset = 0; -} - -/** - * Sets the number of cycles required for the conversion to complete and wait for the arbiter to stabilize. - * - * @note Only ADC2 have arbiter function. - * @param cycle range: [0,4]. - */ -static inline void adc_ll_rtc_set_arbiter_stable_cycle(uint32_t cycle) -{ - // SENS.sar_reader2_ctrl.sar2_wait_arb_cycle = cycle; + return RTCCNTL.sensor_ctrl.sar2_pwdet_cct; } /** * Analyze whether the obtained raw data is correct. - * ADC2 can use arbiter. + * 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). @@ -819,13 +592,14 @@ static inline void adc_ll_rtc_set_arbiter_stable_cycle(uint32_t cycle) * - 0: The data is correct to use. * - -1: The data is invalid. */ -static inline adc_ll_rtc_raw_data_t adc_ll_rtc_analysis_raw_data(adc_ll_num_t adc_n, int raw_data) +static inline adc_ll_rtc_raw_data_t adc_ll_analysis_raw_data(adc_ll_num_t adc_n, int raw_data) { if (adc_n == ADC_NUM_1) { return ADC_RTC_DATA_OK; } - if (((APB_SARADC.apb_saradc2_data_status.adc2_data & 0xffff) >> 13) >= ADC_LL_ADC2_CHANNEL_MAX) { + //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 ADC_RTC_DATA_FAIL; } @@ -851,8 +625,8 @@ 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.sar_clk_gated = 1; APB_SARADC.ctrl.xpd_sar_force = 2; + APB_SARADC.ctrl.sar_clk_gated = 0; } } @@ -866,16 +640,15 @@ static inline adc_ll_power_t adc_ll_get_power_manage(void) { /* Bit1 0:Fsm 1: SW mode Bit0 0:SW mode power down 1: SW mode power on */ - // adc_ll_power_t manage; - // if (SENS.sar_power_xpd_sar.force_xpd_sar == SENS_FORCE_XPD_SAR_PU) { - // manage = ADC_POWER_SW_ON; - // } else if (SENS.sar_power_xpd_sar.force_xpd_sar == SENS_FORCE_XPD_SAR_PD) { - // manage = ADC_POWER_SW_OFF; - // } else { - // manage = ADC_POWER_BY_FSM; - // } - // return manage; - return 0; + 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; } /** @@ -885,14 +658,8 @@ static inline adc_ll_power_t adc_ll_get_power_manage(void) */ static inline void adc_ll_set_sar_clk_div(adc_ll_num_t adc_n, uint32_t div) { - // if (adc_n == ADC_NUM_1) { - // SENS.sar_reader1_ctrl.sar1_clk_div = div; - // } else { // adc_n == ADC_NUM_2 - // SENS.sar_reader2_ctrl.sar2_clk_div = div; - // } } - /** * Set ADC module controller. * There are five SAR ADC controllers: @@ -906,40 +673,6 @@ static inline void adc_ll_set_sar_clk_div(adc_ll_num_t adc_n, uint32_t div) static inline void adc_ll_set_controller(adc_ll_num_t adc_n, adc_controller_t ctrl) { //NOTE: ULP is removed on C3, please remove ULP related (if there still are any) code and this comment - - // if (adc_n == ADC_NUM_1) { - // switch ( ctrl ) { - // case ADC_CTRL_RTC: - // SENS.sar_meas1_mux.sar1_dig_force = 0; // 1: Select digital control; 0: Select RTC control. - // SENS.sar_meas1_ctrl2.meas1_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. - // SENS.sar_meas1_ctrl2.sar1_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; - // break; - // case ADC_CTRL_DIG: - // SENS.sar_meas1_mux.sar1_dig_force = 1; // 1: Select digital control; 0: Select RTC control. - // SENS.sar_meas1_ctrl2.meas1_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. - // SENS.sar_meas1_ctrl2.sar1_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; - // break; - // default: - // break; - // } - // } else { // adc_n == ADC_NUM_2 - // switch ( ctrl ) { - // case ADC_CTRL_RTC: - // SENS.sar_meas2_ctrl2.meas2_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. - // SENS.sar_meas2_ctrl2.sar2_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; - // break; - // case ADC_CTRL_DIG: - // SENS.sar_meas2_ctrl2.meas2_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. - // SENS.sar_meas2_ctrl2.sar2_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; - // break; - // case ADC2_CTRL_PWDET: // currently only used by Wi-Fi - // SENS.sar_meas2_ctrl2.meas2_start_force = 1; // 1: SW control RTC ADC start; 0: ULP control RTC ADC start. - // SENS.sar_meas2_ctrl2.sar2_en_pad_force = 1; // 1: SW control RTC ADC bit map; 0: ULP control RTC ADC bit map; - // break; - // default: - // break; - // } - // } } /** @@ -1009,35 +742,55 @@ static inline void adc_ll_set_arbiter_priority(uint8_t pri_rtc, uint8_t pri_dig, } } -/** - * Force switch ADC2 to RTC controller in sleep mode. Shield arbiter. - * In sleep mode, the arbiter is in power-down mode. - * Need to switch the controller to RTC to shield the control of the arbiter. - * After waking up, it needs to switch to arbiter control. - * - * @note The hardware will do this automatically. In normal use, there is no need to call this interface to manually switch the controller. - * @note Only support ADC2. - */ -static inline void adc_ll_enable_sleep_controller(void) -{ - // SENS.sar_meas2_mux.sar2_rtc_force = 1; -} - -/** - * Force switch ADC2 to arbiter in wakeup mode. - * In sleep mode, the arbiter is in power-down mode. - * Need to switch the controller to RTC to shield the control of the arbiter. - * After waking up, it needs to switch to arbiter control. - * - * @note The hardware will do this automatically. In normal use, there is no need to call this interface to manually switch the controller. - * @note Only support ADC2. - */ -static inline void adc_ll_disable_sleep_controller(void) -{ - // SENS.sar_meas2_mux.sar2_rtc_force = 0; -} - /* ADC calibration code. */ + +/** + * Configure the registers for ADC calibration. You need to call the ``adc_ll_calibration_finish`` interface to resume after calibration. + * + * @note Different ADC units and different attenuation options use different calibration data (initial data). + * + * @param adc_n ADC index number. + * @param channel adc channel number. + * @param internal_gnd true: Disconnect from the IO port and use the internal GND as the calibration voltage. + * false: Use IO external voltage as calibration voltage. + */ +static inline void adc_ll_calibration_prepare(adc_ll_num_t adc_n, adc_channel_t channel, bool internal_gnd) +{ + /* Should be called before writing I2C registers. */ + SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_PU); + + /* Enable/disable internal connect GND (for calibration). */ + if (adc_n == ADC_NUM_1) { + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR1_DREF_ADDR, 4); + if (internal_gnd) { + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR1_ENCAL_GND_ADDR, 1); + } else { + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR1_ENCAL_GND_ADDR, 0); + } + } else { + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR2_DREF_ADDR, 4); + if (internal_gnd) { + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR2_ENCAL_GND_ADDR, 1); + } else { + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR2_ENCAL_GND_ADDR, 0); + } + } +} + +/** + * Resume register status after calibration. + * + * @param adc_n ADC index number. + */ +static inline void adc_ll_calibration_finish(adc_ll_num_t adc_n) +{ + if (adc_n == ADC_NUM_1) { + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR1_ENCAL_GND_ADDR, 0); + } else { + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SAR2_ENCAL_GND_ADDR, 0); + } +} + /** * Set the calibration result to ADC. * @@ -1059,6 +812,60 @@ static inline void adc_ll_set_calibration_param(adc_ll_num_t adc_n, uint32_t par } /* Temp code end. */ +/** + * Output ADCn inter reference voltage to ADC2 channels. + * + * This function routes the internal reference voltage of ADCn to one of + * ADC1's channels. This reference voltage can then be manually measured + * for calibration purposes. + * + * @param[in] adc ADC unit select + * @param[in] channel ADC1 channel number + * @param[in] en Enable/disable the reference voltage output + */ +static inline void adc_ll_vref_output(adc_ll_num_t adc, adc_channel_t channel, bool en) +{ + if (en) { + REG_SET_FIELD(RTC_CNTL_SENSOR_CTRL_REG, RTC_CNTL_FORCE_XPD_SAR, 3); + SET_PERI_REG_MASK(RTC_CNTL_REG, RTC_CNTL_REGULATOR_FORCE_PU); + + REG_SET_FIELD(APB_SARADC_APB_ADC_CLKM_CONF_REG, APB_SARADC_CLK_SEL, 2); + SET_PERI_REG_MASK(APB_SARADC_APB_ADC_CLKM_CONF_REG, APB_SARADC_CLK_EN); + SET_PERI_REG_MASK(APB_SARADC_APB_ADC_ARB_CTRL_REG, APB_SARADC_ADC_ARB_GRANT_FORCE); + SET_PERI_REG_MASK(APB_SARADC_APB_ADC_ARB_CTRL_REG, APB_SARADC_ADC_ARB_APB_FORCE); + APB_SARADC.sar_patt_tab[0].sar_patt_tab1 = 0xFFFFFF; + APB_SARADC.sar_patt_tab[1].sar_patt_tab1 = 0xFFFFFF; + APB_SARADC.onetime_sample.adc1_onetime_sample = 1; + APB_SARADC.onetime_sample.onetime_channel = channel; + SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_PU); + if (adc == ADC_NUM_1) { + /* Config test mux to route v_ref to ADC1 Channels */ + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC1_ENCAL_REF_ADDR, 1); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR, 1); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_TSENS_ADDR, 0); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_RTC_ADDR, 1); + } else { + /* Config test mux to route v_ref to ADC2 Channels */ + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC2_ENCAL_REF_ADDR, 1); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR, 0); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_TSENS_ADDR, 0); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_RTC_ADDR, 0); + } + } else { + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC2_ENCAL_REF_ADDR, 0); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC1_ENCAL_REF_ADDR, 0); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR, 0); + REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_RTC_ADDR, 0); + APB_SARADC.onetime_sample.adc1_onetime_sample = 0; + APB_SARADC.onetime_sample.onetime_channel = 0xf; + REG_SET_FIELD(RTC_CNTL_SENSOR_CTRL_REG, RTC_CNTL_FORCE_XPD_SAR, 0); + REG_SET_FIELD(APB_SARADC_APB_ADC_CLKM_CONF_REG, APB_SARADC_CLK_SEL, 0); + CLEAR_PERI_REG_MASK(APB_SARADC_APB_ADC_CLKM_CONF_REG, APB_SARADC_CLK_EN); + CLEAR_PERI_REG_MASK(APB_SARADC_APB_ADC_ARB_CTRL_REG, APB_SARADC_ADC_ARB_GRANT_FORCE); + CLEAR_PERI_REG_MASK(APB_SARADC_APB_ADC_ARB_CTRL_REG, APB_SARADC_ADC_ARB_APB_FORCE); + } +} + /*--------------------------------------------------------------- Single Read ---------------------------------------------------------------*/ diff --git a/components/hal/include/hal/adc_hal.h b/components/hal/include/hal/adc_hal.h index 3ac94b26b9..dc048d4ad2 100644 --- a/components/hal/include/hal/adc_hal.h +++ b/components/hal/include/hal/adc_hal.h @@ -134,6 +134,7 @@ void adc_hal_deinit(void); */ #define adc_hal_pwdet_get_cct() adc_ll_pwdet_get_cct() +#ifndef CONFIG_IDF_TARGET_ESP32C3 /*--------------------------------------------------------------- RTC controller setting ---------------------------------------------------------------*/ @@ -167,6 +168,7 @@ int adc_hal_convert(adc_ll_num_t adc_n, int channel, int *value); * @prarm adc_n ADC unit. */ #define adc_hal_rtc_output_invert(adc_n, inv_en) adc_ll_rtc_output_invert(adc_n, inv_en) +#endif /** * Enable/disable the output of ADCn's internal reference voltage to one of ADC2's channels. diff --git a/components/hal/include/hal/adc_types.h b/components/hal/include/hal/adc_types.h index 3718899407..a35ff1959a 100644 --- a/components/hal/include/hal/adc_types.h +++ b/components/hal/include/hal/adc_types.h @@ -17,6 +17,7 @@ #include #include "sdkconfig.h" #include "soc/soc_caps.h" +#include "esp_attr.h" /** * @brief ADC unit enumeration. @@ -329,10 +330,19 @@ typedef struct { * @brief ADC digital controller (DMA mode) interrupt type options. */ typedef enum { +#if CONFIG_IDF_TARGET_ESP32C3 + ADC_DIGI_INTR_MASK_MONITOR0_HIGH = BIT(0), + ADC_DIGI_INTR_MASK_MONITOR0_LOW = BIT(1), + ADC_DIGI_INTR_MASK_MONITOR1_HIGH = BIT(2), + ADC_DIGI_INTR_MASK_MONITOR1_LOW = BIT(3), + ADC_DIGI_INTR_MASK_MEAS_DONE = BIT(4), +#else ADC_DIGI_INTR_MASK_MONITOR = 0x1, ADC_DIGI_INTR_MASK_MEAS_DONE = 0x2, ADC_DIGI_INTR_MASK_ALL = 0x3, +#endif } adc_digi_intr_t; +FLAG_ATTR(adc_digi_intr_t) /** * @brief ADC digital controller (DMA mode) filter index options. @@ -352,6 +362,9 @@ typedef enum { * Expression: filter_data = (k-1)/k * last_data + new_data / k. */ typedef enum { +#if CONFIG_IDF_TARGET_ESP32C3 + ADC_DIGI_FILTER_DIS = -1, /*!< Disable filter */ +#endif ADC_DIGI_FILTER_IIR_2 = 0, /*! threshold, Generates monitor interrupt. */ +#else ADC_DIGI_MONITOR_HIGH = 0, /*! threshold, Generates monitor interrupt. */ ADC_DIGI_MONITOR_LOW, /*! Date: Thu, 7 Jan 2021 23:43:35 +0800 Subject: [PATCH 17/22] adc: update the monitor and filter in the HAL on C3 On C3 ADC has no enable bit for monitor and filter. However we can use context variables to implement one --- components/driver/esp32c3/adc.c | 25 +++---- components/hal/esp32c3/adc_hal.c | 67 +++++++++++++------ components/hal/esp32c3/include/hal/adc_hal.h | 35 +++++++--- components/hal/esp32c3/include/hal/adc_ll.h | 2 +- components/soc/esp32c3/include/soc/soc_caps.h | 2 + 5 files changed, 85 insertions(+), 46 deletions(-) diff --git a/components/driver/esp32c3/adc.c b/components/driver/esp32c3/adc.c index 3123ed4a72..9fbcc3d720 100644 --- a/components/driver/esp32c3/adc.c +++ b/components/driver/esp32c3/adc.c @@ -663,11 +663,7 @@ esp_err_t adc_digi_reset(void) esp_err_t adc_digi_filter_reset(adc_digi_filter_idx_t idx) { ADC_ENTER_CRITICAL(); - if (idx == ADC_DIGI_FILTER_IDX0) { - adc_hal_digi_filter_reset(ADC_NUM_1); - } else if (idx == ADC_DIGI_FILTER_IDX1) { - adc_hal_digi_filter_reset(ADC_NUM_2); - } + adc_hal_digi_filter_reset(idx); ADC_EXIT_CRITICAL(); return ESP_OK; } @@ -690,21 +686,12 @@ esp_err_t adc_digi_filter_get_config(adc_digi_filter_idx_t idx, adc_digi_filter_ esp_err_t adc_digi_filter_enable(adc_digi_filter_idx_t idx, bool enable) { + ADC_ENTER_CRITICAL(); + adc_hal_digi_filter_enable(idx, enable); + ADC_EXIT_CRITICAL(); return ESP_OK; } -/** - * @brief Get the filtered data of adc digital controller filter. For debug. - * The data after each measurement and filtering is updated to the DMA by the digital controller. But it can also be obtained manually through this API. - * - * @param idx Filter index. - * @return Filtered data. if <0, the read data invalid. - */ -int adc_digi_filter_read_data(adc_digi_filter_idx_t idx) -{ - return -1; -} - /**************************************/ /* Digital controller monitor setting */ /**************************************/ @@ -719,6 +706,10 @@ esp_err_t adc_digi_monitor_set_config(adc_digi_monitor_idx_t idx, adc_digi_monit esp_err_t adc_digi_monitor_enable(adc_digi_monitor_idx_t idx, bool enable) { + + ADC_ENTER_CRITICAL(); + adc_hal_digi_monitor_enable(idx, enable); + ADC_EXIT_CRITICAL(); return ESP_OK; } diff --git a/components/hal/esp32c3/adc_hal.c b/components/hal/esp32c3/adc_hal.c index cb41e2b39e..8f7b2678fd 100644 --- a/components/hal/esp32c3/adc_hal.c +++ b/components/hal/esp32c3/adc_hal.c @@ -14,9 +14,20 @@ // The HAL layer for ADC (ESP32-C3 specific part) +#include +#include "soc/soc_caps.h" #include "hal/adc_hal.h" #include "hal/adc_types.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 ---------------------------------------------------------------*/ @@ -94,6 +105,16 @@ void adc_hal_digi_disable(void) adc_ll_digi_dma_disable(); } +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. * @@ -102,11 +123,8 @@ void adc_hal_digi_disable(void) */ void adc_hal_digi_filter_set_factor(adc_digi_filter_idx_t idx, adc_digi_filter_t *filter) { - if (filter->mode == ADC_DIGI_FILTER_DIS) { - adc_ll_digi_filter_disable(idx); - } else { - adc_ll_digi_filter_set_factor(idx, filter); - } + s_filter[idx] = *filter; + filter_update(idx); } /** @@ -117,26 +135,35 @@ void adc_hal_digi_filter_set_factor(adc_digi_filter_idx_t idx, adc_digi_filter_t */ void adc_hal_digi_filter_get_factor(adc_digi_filter_idx_t idx, adc_digi_filter_t *filter) { - adc_ll_digi_filter_get_factor(idx, filter); - if (((filter->adc_unit << 3) | filter->channel) > 9) { - filter->mode = ADC_DIGI_FILTER_DIS; + *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); } } -/** - * Config monitor of adc digital controller. - * - * @note If the channel info is not supported, the monitor function will not be enabled. - * @param idx ADC monitor index. - * @param config Refer to `adc_digi_monitor_t`. - */ void adc_hal_digi_monitor_config(adc_digi_monitor_idx_t idx, adc_digi_monitor_t *config) { - if (config->mode == ADC_DIGI_MONITOR_DIS) { - adc_ll_digi_monitor_disable(idx); - } else { - adc_ll_digi_monitor_set_mode(idx, 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); } /*--------------------------------------------------------------- diff --git a/components/hal/esp32c3/include/hal/adc_hal.h b/components/hal/esp32c3/include/hal/adc_hal.h index fc6a618796..0b53e44f54 100644 --- a/components/hal/esp32c3/include/hal/adc_hal.h +++ b/components/hal/esp32c3/include/hal/adc_hal.h @@ -84,34 +84,53 @@ void adc_hal_digi_clk_config(const adc_digi_clk_t *clk); /** * Reset adc digital controller filter. * - * @param adc_n ADC unit. + * @param filter_idx ADC filter unit. */ -#define adc_hal_digi_filter_reset(adc_n) adc_ll_digi_filter_reset(adc_n) +#define adc_hal_digi_filter_reset(filter_idx) adc_ll_digi_filter_reset(filter_idx) /** * Set adc digital controller filter factor. * - * @param idx ADC filter unit. + * @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 idx, adc_digi_filter_t *filter); +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 adc_n ADC unit. + * @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 idx, adc_digi_filter_t *filter); +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 idx ADC monitor index. + * @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 idx, adc_digi_monitor_t *config); +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); /** * Enable interrupt of adc digital controller by bitmask. diff --git a/components/hal/esp32c3/include/hal/adc_ll.h b/components/hal/esp32c3/include/hal/adc_ll.h index 59bab42995..7149f88171 100644 --- a/components/hal/esp32c3/include/hal/adc_ll.h +++ b/components/hal/esp32c3/include/hal/adc_ll.h @@ -338,7 +338,7 @@ static inline void adc_ll_digi_filter_get_factor(adc_digi_filter_idx_t idx, adc_ /** * Disable adc digital controller filter. * Filtering the ADC data to obtain smooth data at higher sampling rates. - * + * * @note If the channel info is not supported, the filter function will not be enabled. * @param adc_n ADC unit. */ diff --git a/components/soc/esp32c3/include/soc/soc_caps.h b/components/soc/esp32c3/include/soc/soc_caps.h index fae89b8a41..fc323730e0 100644 --- a/components/soc/esp32c3/include/soc/soc_caps.h +++ b/components/soc/esp32c3/include/soc/soc_caps.h @@ -107,6 +107,8 @@ #define SOC_ADC_CHANNEL_NUM(PERIPH_NUM) ((PERIPH_NUM==0)? 5 : 1) #define SOC_ADC_MAX_CHANNEL_NUM (10) #define SOC_ADC_MAX_BITWIDTH (12) +#define SOC_ADC_DIGI_FILTER_NUM (2) +#define SOC_ADC_DIGI_MONITOR_NUM (2) /** * Check if adc support digital controller (DMA) mode. From 56919682be6c1ca866dcb5ce964e72654257dbe2 Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Fri, 8 Jan 2021 00:50:47 +0800 Subject: [PATCH 18/22] adc: remove useless adc_ll_set_sar_clk_div in LL --- components/hal/esp32c3/include/hal/adc_ll.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/components/hal/esp32c3/include/hal/adc_ll.h b/components/hal/esp32c3/include/hal/adc_ll.h index 7149f88171..ee9da0a907 100644 --- a/components/hal/esp32c3/include/hal/adc_ll.h +++ b/components/hal/esp32c3/include/hal/adc_ll.h @@ -651,15 +651,6 @@ static inline adc_ll_power_t adc_ll_get_power_manage(void) return manage; } -/** - * ADC SAR clock division factor setting. ADC SAR clock devided from `RTC_FAST_CLK`. - * - * @param div Division factor. - */ -static inline void adc_ll_set_sar_clk_div(adc_ll_num_t adc_n, uint32_t div) -{ -} - /** * Set ADC module controller. * There are five SAR ADC controllers: From d8a4b247b9e166d8b4f804d4dc1665024200ad47 Mon Sep 17 00:00:00 2001 From: Armando Date: Fri, 25 Dec 2020 14:24:19 +0800 Subject: [PATCH 19/22] adc_digi: update_adc_api_for_5M_freq_limit The ``adc_digi_config_t`` struct is modified on esp32c3: configuration of clock divider factors are not provided anymore. The SARADC sampling frequency is provided instead. In this way, we can handle the frequency limit better. --- components/driver/esp32c3/adc.c | 33 ++++++++----------- components/driver/include/driver/adc_common.h | 1 + components/driver/test/test_adc_dma.c | 6 +--- components/hal/adc_hal.c | 2 +- components/hal/esp32c3/adc_hal.c | 24 +++++--------- components/hal/esp32c3/include/hal/adc_hal.h | 4 +-- components/hal/esp32c3/include/hal/adc_ll.h | 16 +++++---- components/hal/esp32s2/include/hal/adc_ll.h | 8 ++--- components/hal/include/hal/adc_types.h | 9 ++++- .../adc/adc_dma/main/adc_dma_example_main.c | 6 +--- 10 files changed, 50 insertions(+), 59 deletions(-) diff --git a/components/driver/esp32c3/adc.c b/components/driver/esp32c3/adc.c index 9fbcc3d720..05fc107f9a 100644 --- a/components/driver/esp32c3/adc.c +++ b/components/driver/esp32c3/adc.c @@ -97,7 +97,6 @@ typedef struct adc_digi_context_t { adc_digi_config_t digi_controller_config; //Digital Controller Configuration } adc_digi_context_t; -static const char* ADC_DMA_TAG = "ADC_DMA:"; static adc_digi_context_t *s_adc_digi_ctx = NULL; static uint32_t adc_get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t chan, adc_atten_t atten); @@ -344,7 +343,7 @@ esp_err_t adc_digi_read_bytes(uint8_t *buf, uint32_t length_max, uint32_t *out_l data = xRingbufferReceiveUpTo(s_adc_digi_ctx->ringbuf_hdl, &size, ticks_to_wait, length_max); if (!data) { - ESP_LOGV(ADC_DMA_TAG, "No data, increase timeout or reduce conv_num_each_intr"); + ESP_LOGV(ADC_TAG, "No data, increase timeout or reduce conv_num_each_intr"); ret = ESP_ERR_TIMEOUT; *out_length = 0; return ret; @@ -428,11 +427,7 @@ int adc1_get_raw(adc1_channel_t channel) adc_digi_config_t dig_cfg = { .conv_limit_en = 0, .conv_limit_num = 250, - .interval = 40, - .dig_clk.use_apll = 0, - .dig_clk.div_num = 15, - .dig_clk.div_a = 0, - .dig_clk.div_b = 1, + .sample_freq_hz = SOC_ADC_SAMPLE_FREQ_THRES_HIGH, }; ADC_DIGI_LOCK_ACQUIRE(); @@ -489,11 +484,7 @@ esp_err_t adc2_get_raw(adc2_channel_t channel, adc_bits_width_t width_bit, int * adc_digi_config_t dig_cfg = { .conv_limit_en = 0, .conv_limit_num = 250, - .interval = 40, - .dig_clk.use_apll = 0, - .dig_clk.div_num = 15, - .dig_clk.div_a = 0, - .dig_clk.div_b = 1, + .sample_freq_hz = SOC_ADC_SAMPLE_FREQ_THRES_HIGH, }; SAC_ADC2_LOCK_ACQUIRE(); @@ -540,32 +531,34 @@ esp_err_t adc_digi_controller_config(const adc_digi_config_t *config) if (!s_adc_digi_ctx) { return ESP_ERR_INVALID_STATE; } + ADC_CHECK(config->sample_freq_hz <= 83333 && config->sample_freq_hz >= 610, "ADC sampling frequency out of range", ESP_ERR_INVALID_ARG); s_adc_digi_ctx->digi_controller_config.conv_limit_en = config->conv_limit_en; s_adc_digi_ctx->digi_controller_config.conv_limit_num = config->conv_limit_num; s_adc_digi_ctx->digi_controller_config.adc_pattern_len = config->adc_pattern_len; - s_adc_digi_ctx->digi_controller_config.interval = config->interval; - s_adc_digi_ctx->digi_controller_config.dig_clk = config-> dig_clk; - s_adc_digi_ctx->digi_controller_config.dma_eof_num = config->dma_eof_num; + s_adc_digi_ctx->digi_controller_config.sample_freq_hz = config->sample_freq_hz; memcpy(s_adc_digi_ctx->digi_controller_config.adc_pattern, config->adc_pattern, config->adc_pattern_len * sizeof(adc_digi_pattern_table_t)); - //See whether ADC2 will be used or not. If yes, the ``sar_adc2_mutex`` should be acquired in the continuous read driver - s_adc_digi_ctx->adc1_atten = ADC_ATTEN_MAX; - s_adc_digi_ctx->adc2_atten = ADC_ATTEN_MAX; + const int atten_uninitialised = 999; + s_adc_digi_ctx->adc1_atten = atten_uninitialised; + s_adc_digi_ctx->adc2_atten = atten_uninitialised; s_adc_digi_ctx->use_adc1 = 0; s_adc_digi_ctx->use_adc2 = 0; for (int i = 0; i < config->adc_pattern_len; i++) { const adc_digi_pattern_table_t* pat = &config->adc_pattern[i]; if (pat->unit == ADC_NUM_1) { s_adc_digi_ctx->use_adc1 = 1; - if (s_adc_digi_ctx->adc1_atten == ADC_ATTEN_MAX) { + + if (s_adc_digi_ctx->adc1_atten == atten_uninitialised) { s_adc_digi_ctx->adc1_atten = pat->atten; } else if (s_adc_digi_ctx->adc1_atten != pat->atten) { return ESP_ERR_INVALID_ARG; } } else if (pat->unit == ADC_NUM_2) { + //See whether ADC2 will be used or not. If yes, the ``sar_adc2_mutex`` should be acquired in the continuous read driver s_adc_digi_ctx->use_adc2 = 1; - if (s_adc_digi_ctx->adc2_atten == ADC_ATTEN_MAX) { + + if (s_adc_digi_ctx->adc2_atten == atten_uninitialised) { s_adc_digi_ctx->adc2_atten = pat->atten; } else if (s_adc_digi_ctx->adc2_atten != pat->atten) { return ESP_ERR_INVALID_ARG; diff --git a/components/driver/include/driver/adc_common.h b/components/driver/include/driver/adc_common.h index 2ac5110c43..52b7d60c38 100644 --- a/components/driver/include/driver/adc_common.h +++ b/components/driver/include/driver/adc_common.h @@ -477,6 +477,7 @@ esp_err_t adc_digi_deinit(void); * * @return * - ESP_ERR_INVALID_STATE Driver state is invalid. + * - ESP_ERR_INVALID_ARG If the combination of arguments is invalid. * - ESP_OK On success */ esp_err_t adc_digi_controller_config(const adc_digi_config_t *config); diff --git a/components/driver/test/test_adc_dma.c b/components/driver/test/test_adc_dma.c index 04d2c4c57a..d9504cd6d4 100644 --- a/components/driver/test/test_adc_dma.c +++ b/components/driver/test/test_adc_dma.c @@ -132,11 +132,7 @@ static void continuous_adc_init(uint16_t adc1_chan_mask, uint16_t adc2_chan_mask adc_digi_config_t dig_cfg = { .conv_limit_en = 0, .conv_limit_num = 250, - .interval = 40, - .dig_clk.use_apll = 0, - .dig_clk.div_num = 15, - .dig_clk.div_a = 0, - .dig_clk.div_b = 1, + .sample_freq_hz = 83333, }; dig_cfg.adc_pattern_len = channel_num; diff --git a/components/hal/adc_hal.c b/components/hal/adc_hal.c index a04f31d694..4cb8922a86 100644 --- a/components/hal/adc_hal.c +++ b/components/hal/adc_hal.c @@ -145,7 +145,7 @@ void adc_hal_onetime_start(adc_digi_config_t *adc_digi_config) * This limitation will be removed in hardware future versions. * */ - uint32_t digi_clk = APB_CLK_FREQ / (adc_digi_config->dig_clk.div_num + adc_digi_config->dig_clk.div_a / adc_digi_config->dig_clk.div_b + 1); + uint32_t digi_clk = APB_CLK_FREQ / (ADC_LL_CLKM_DIV_NUM_DEFAULT + ADC_LL_CLKM_DIV_A_DEFAULT / ADC_LL_CLKM_DIV_B_DEFAULT + 1); //Convert frequency to time (us). Since decimals are removed by this division operation. Add 1 here in case of the fact that delay is not enough. uint32_t delay = (1000 * 1000) / digi_clk + 1; //3 ADC digital controller clock cycle diff --git a/components/hal/esp32c3/adc_hal.c b/components/hal/esp32c3/adc_hal.c index 8f7b2678fd..105dff6490 100644 --- a/components/hal/esp32c3/adc_hal.c +++ b/components/hal/esp32c3/adc_hal.c @@ -18,6 +18,7 @@ #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! @@ -67,24 +68,17 @@ void adc_hal_digi_controller_config(const adc_digi_config_t *cfg) adc_ll_digi_convert_limit_disable(); } - adc_ll_digi_set_trigger_interval(cfg->interval); - adc_hal_digi_clk_config(&cfg->dig_clk); + //clock + uint32_t interval = APB_CLK_FREQ / (ADC_LL_CLKM_DIV_NUM_DEFAULT + ADC_LL_CLKM_DIV_A_DEFAULT / ADC_LL_CLKM_DIV_B_DEFAULT + 1) / 2 / cfg->sample_freq_hz; + adc_ll_digi_set_trigger_interval(interval); + adc_hal_digi_clk_config(); } -/** - * Set ADC digital controller clock division factor. The clock divided from `APLL` or `APB` clock. - * Enable clock and select clock source for ADC digital controller. - * Expression: controller_clk = APLL/APB * (div_num + div_b / div_a). - * - * @note ADC and DAC digital controller share the same frequency divider. - * Please set a reasonable frequency division factor to meet the sampling frequency of the ADC and the output frequency of the DAC. - * - * @param clk Refer to ``adc_digi_clk_t``. - */ -void adc_hal_digi_clk_config(const adc_digi_clk_t *clk) +void adc_hal_digi_clk_config(void) { - adc_ll_digi_controller_clk_div(clk->div_num, clk->div_b, clk->div_a); - adc_ll_digi_controller_clk_enable(clk->use_apll); + //Here we set the clock divider factor to make the digital clock to 5M Hz + adc_ll_digi_controller_clk_div(ADC_LL_CLKM_DIV_NUM_DEFAULT, ADC_LL_CLKM_DIV_B_DEFAULT, ADC_LL_CLKM_DIV_A_DEFAULT); + adc_ll_digi_controller_clk_enable(0); } /** diff --git a/components/hal/esp32c3/include/hal/adc_hal.h b/components/hal/esp32c3/include/hal/adc_hal.h index 0b53e44f54..122d438d3e 100644 --- a/components/hal/esp32c3/include/hal/adc_hal.h +++ b/components/hal/esp32c3/include/hal/adc_hal.h @@ -75,11 +75,11 @@ void adc_hal_digi_disable(void); /** * Set ADC digital controller clock division factor. The clock divided from `APLL` or `APB` clock. * Enable clock and select clock source for ADC digital controller. - * Expression: controller_clk = APLL/APB * (div_num + div_b / div_a). + * Expression: controller_clk = APLL/APB * (div_num + div_a / div_b + 1). * * @param clk Refer to `adc_digi_clk_t`. */ -void adc_hal_digi_clk_config(const adc_digi_clk_t *clk); +void adc_hal_digi_clk_config(void); /** * Reset adc digital controller filter. diff --git a/components/hal/esp32c3/include/hal/adc_ll.h b/components/hal/esp32c3/include/hal/adc_ll.h index ee9da0a907..913b59ed35 100644 --- a/components/hal/esp32c3/include/hal/adc_ll.h +++ b/components/hal/esp32c3/include/hal/adc_ll.h @@ -29,7 +29,10 @@ extern "C" { #endif -#define ADC_LL_ADC2_CHANNEL_MAX 1 +#define ADC_LL_ADC2_CHANNEL_MAX 1 +#define ADC_LL_CLKM_DIV_NUM_DEFAULT 15 +#define ADC_LL_CLKM_DIV_B_DEFAULT 1 +#define ADC_LL_CLKM_DIV_A_DEFAULT 0 typedef enum { ADC_NUM_1 = 0, /*!< SAR ADC 1 */ @@ -180,8 +183,8 @@ static inline void adc_ll_digi_set_pattern_table(adc_ll_num_t adc_n, uint32_t pa uint8_t offset = (pattern_index % 4) * 6; 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 << 18) >> offset; // Fill in the new data + 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 } @@ -223,10 +226,11 @@ static inline void adc_ll_digi_output_invert(adc_ll_num_t adc_n, bool inv_en) } /** - * Sets the number of interval clock cycles for the digital controller to trigger the measurement. + * Set the interval clock cycle for the digital controller to trigger the measurement. + * Expression: `trigger_meas_freq` = `controller_clk` / 2 / interval. * - * @note The trigger interval should not be less than the sampling time of the SAR ADC. - * @param cycle The number of clock cycles for the trigger interval. The unit is the divided clock. Range: 40 ~ 4095. + * @note The trigger interval should not be smaller than the sampling time of the SAR ADC. + * @param cycle The clock cycle (trigger interval) of the measurement. Range: 30 ~ 4095. */ static inline void adc_ll_digi_set_trigger_interval(uint32_t cycle) { diff --git a/components/hal/esp32s2/include/hal/adc_ll.h b/components/hal/esp32s2/include/hal/adc_ll.h index 7eedf5b936..1d306db61a 100644 --- a/components/hal/esp32s2/include/hal/adc_ll.h +++ b/components/hal/esp32s2/include/hal/adc_ll.h @@ -268,11 +268,11 @@ static inline void adc_ll_digi_output_invert(adc_ll_num_t adc_n, bool inv_en) } /** - * Sets the number of interval clock cycles for the digital controller to trigger the measurement. - * Expression: `trigger_meas_freq` = `controller_clk` / 2 / interval. Refer to ``adc_digi_clk_t``. + * Set the interval clock cycle for the digital controller to trigger the measurement. + * Expression: `trigger_meas_freq` = `controller_clk` / 2 / interval. * - * @note The trigger interval should not be less than the sampling time of the SAR ADC. - * @param cycle The number of clock cycles for the trigger interval. The unit is the divided clock. Range: 40 ~ 4095. + * @note The trigger interval should be larger than the sampling time of the SAR ADC. + * @param cycle The clock cycle (trigger interval) of the measurement. Range: 40 ~ 4095. */ static inline void adc_ll_digi_set_trigger_interval(uint32_t cycle) { diff --git a/components/hal/include/hal/adc_types.h b/components/hal/include/hal/adc_types.h index a35ff1959a..9d73c0de4b 100644 --- a/components/hal/include/hal/adc_types.h +++ b/components/hal/include/hal/adc_types.h @@ -275,7 +275,7 @@ typedef struct { pattern table one by one. For each controller the scan sequence has at most 16 different rules before repeating itself. */ adc_digi_pattern_table_t *adc_pattern; /*! Date: Tue, 5 Jan 2021 11:00:05 +0800 Subject: [PATCH 20/22] adc: add comment for ADC sampling frequency --- components/driver/esp32c3/adc.c | 2 +- components/hal/include/hal/adc_types.h | 9 +++---- components/soc/esp32c3/include/soc/soc_caps.h | 26 ++++++++----------- .../adc/adc_dma/main/adc_dma_example_main.c | 4 ++- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/components/driver/esp32c3/adc.c b/components/driver/esp32c3/adc.c index 05fc107f9a..628bb2f642 100644 --- a/components/driver/esp32c3/adc.c +++ b/components/driver/esp32c3/adc.c @@ -531,7 +531,7 @@ esp_err_t adc_digi_controller_config(const adc_digi_config_t *config) if (!s_adc_digi_ctx) { return ESP_ERR_INVALID_STATE; } - ADC_CHECK(config->sample_freq_hz <= 83333 && config->sample_freq_hz >= 610, "ADC sampling frequency out of range", ESP_ERR_INVALID_ARG); + ADC_CHECK(config->sample_freq_hz <= SOC_ADC_SAMPLE_FREQ_THRES_HIGH && config->sample_freq_hz >= SOC_ADC_SAMPLE_FREQ_THRES_LOW, "ADC sampling frequency out of range", ESP_ERR_INVALID_ARG); s_adc_digi_ctx->digi_controller_config.conv_limit_en = config->conv_limit_en; s_adc_digi_ctx->digi_controller_config.conv_limit_num = config->conv_limit_num; diff --git a/components/hal/include/hal/adc_types.h b/components/hal/include/hal/adc_types.h index 9d73c0de4b..247a84a5e4 100644 --- a/components/hal/include/hal/adc_types.h +++ b/components/hal/include/hal/adc_types.h @@ -286,12 +286,11 @@ typedef struct { If the number of measurements reaches `dma_eof_num`, then `dma_in_suc_eof` signal is generated in DMA. Note: The converted data in the DMA in link buffer will be multiple of two bytes. */ #elif CONFIG_IDF_TARGET_ESP32C3 - uint32_t sample_freq_hz; /*!< The expected ADC sampling frequency in Hz. Range: 610Hz ~ 83333Hz - Fs: sampling frequency; - Fd: digital controller frequency - interval: interval between 2 measurement trigger signal + uint32_t sample_freq_hz; /*!< The expected ADC sampling frequency in Hz. Range: 611Hz ~ 83333Hz Fs = Fd / interval / 2 - Range: the smallest interval should not be smaller than the ADC measurement period. The largest interval should not be larger than 4095. */ + Fs: sampling frequency; + Fd: digital controller frequency, no larger than 5M for better performance + interval: interval between 2 measurement trigger signal, the smallest interval should not be smaller than the ADC measurement period, the largest interval should not be larger than 4095 */ #endif } adc_digi_config_t; diff --git a/components/soc/esp32c3/include/soc/soc_caps.h b/components/soc/esp32c3/include/soc/soc_caps.h index fc323730e0..0f256f5843 100644 --- a/components/soc/esp32c3/include/soc/soc_caps.h +++ b/components/soc/esp32c3/include/soc/soc_caps.h @@ -102,21 +102,17 @@ #define SOC_AES_SUPPORT_AES_256 (1) /*-------------------------- ADC CAPS -------------------------------*/ -#define SOC_ADC_PERIPH_NUM (2) -#define SOC_ADC_PATT_LEN_MAX (16) -#define SOC_ADC_CHANNEL_NUM(PERIPH_NUM) ((PERIPH_NUM==0)? 5 : 1) -#define SOC_ADC_MAX_CHANNEL_NUM (10) -#define SOC_ADC_MAX_BITWIDTH (12) -#define SOC_ADC_DIGI_FILTER_NUM (2) -#define SOC_ADC_DIGI_MONITOR_NUM (2) - -/** - * Check if adc support digital controller (DMA) mode. - * @value - * - 1 : support; - * - 0 : not support; - */ -#define SOC_ADC_SUPPORT_DMA_MODE(PERIPH_NUM) 1 +#define SOC_ADC_PERIPH_NUM (2) +#define SOC_ADC_PATT_LEN_MAX (16) +#define SOC_ADC_CHANNEL_NUM(PERIPH_NUM) ((PERIPH_NUM==0)? 5 : 1) +#define SOC_ADC_MAX_CHANNEL_NUM (10) +#define SOC_ADC_MAX_BITWIDTH (12) +#define SOC_ADC_DIGI_FILTER_NUM (2) +#define SOC_ADC_DIGI_MONITOR_NUM (2) +#define SOC_ADC_SUPPORT_DMA_MODE(PERIPH_NUM) 1 +//F_sample = F_digi_con / 2 / interval. F_digi_con = 5M for now. 30 <= interva <= 4095 +#define SOC_ADC_SAMPLE_FREQ_THRES_HIGH 83333 +#define SOC_ADC_SAMPLE_FREQ_THRES_LOW 611 /*-------------------------- APB BACKUP DMA CAPS -------------------------------*/ #define SOC_APB_BACKUP_DMA (1) diff --git a/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c b/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c index 93cc6efba1..bac3dece22 100644 --- a/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c +++ b/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c @@ -25,10 +25,12 @@ static void continuous_adc_init(uint16_t adc1_chan_mask, uint16_t adc2_chan_mask assert(ret == ESP_OK); adc_digi_pattern_table_t adc_pattern[10] = {0}; + + //Do not set the sampling frequency out of the range between `SOC_ADC_SAMPLE_FREQ_THRES_LOW` and `SOC_ADC_SAMPLE_FREQ_THRES_HIGH` adc_digi_config_t dig_cfg = { .conv_limit_en = 0, .conv_limit_num = 250, - .sample_freq_hz = 83333, + .sample_freq_hz = 620, }; dig_cfg.adc_pattern_len = channel_num; From f5f046126468ff27c8ec2c4e2e06bdf74c5b1e5c Mon Sep 17 00:00:00 2001 From: Armando Date: Fri, 22 Jan 2021 19:50:31 +0800 Subject: [PATCH 21/22] tmpsensor: add temp_sensor.h for c3 --- .../esp32c3/include/driver/temp_sensor.h | 99 +++++++++++++++++++ components/efuse/src/esp_efuse_utility.c | 2 +- .../esp_hw_support/port/esp32c3/regi2c_ctrl.h | 6 +- 3 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 components/driver/esp32c3/include/driver/temp_sensor.h diff --git a/components/driver/esp32c3/include/driver/temp_sensor.h b/components/driver/esp32c3/include/driver/temp_sensor.h new file mode 100644 index 0000000000..2eccefcf0f --- /dev/null +++ b/components/driver/esp32c3/include/driver/temp_sensor.h @@ -0,0 +1,99 @@ +// Copyright 2010-2018 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. + +#pragma once + +#include +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + TSENS_DAC_L0 = 0, /*!< offset = -2, measure range: 50℃ ~ 125℃, error < 3℃. */ + TSENS_DAC_L1, /*!< offset = -1, measure range: 20℃ ~ 100℃, error < 2℃. */ + TSENS_DAC_L2, /*!< offset = 0, measure range:-10℃ ~ 80℃, error < 1℃. */ + TSENS_DAC_L3, /*!< offset = 1, measure range:-30℃ ~ 50℃, error < 2℃. */ + TSENS_DAC_L4, /*!< offset = 2, measure range:-40℃ ~ 20℃, error < 3℃. */ + TSENS_DAC_MAX, + TSENS_DAC_DEFAULT = TSENS_DAC_L2, +} temp_sensor_dac_offset_t; + +/** + * @brief Configuration for temperature sensor reading + */ +typedef struct { + temp_sensor_dac_offset_t dac_offset; /*!< The temperature measurement range is configured with a built-in temperature offset DAC. */ + uint8_t clk_div; /*!< Default: 6 */ +} temp_sensor_config_t; + +#define TSENS_CONFIG_DEFAULT() {.dac_offset = TSENS_DAC_L2, \ + .clk_div = 6} + +/** + * @brief Set parameter of temperature sensor. + * @param tsens + * @return + * - ESP_OK Success + */ +esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens); + +/** + * @brief Get parameter of temperature sensor. + * @param tsens + * @return + * - ESP_OK Success + */ +esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens); + +/** + * @brief Start temperature sensor measure. + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG + */ +esp_err_t temp_sensor_start(void); + +/** + * @brief Stop temperature sensor measure. + * @return + * - ESP_OK Success + */ +esp_err_t temp_sensor_stop(void); + +/** + * @brief Read temperature sensor raw data. + * @param tsens_out Pointer to raw data, Range: 0 ~ 255 + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG `tsens_out` is NULL + * - ESP_ERR_INVALID_STATE temperature sensor dont start + */ +esp_err_t temp_sensor_read_raw(uint32_t *tsens_out); + +/** + * @brief Read temperature sensor data that is converted to degrees Celsius. + * @note Should not be called from interrupt. + * @param celsius The measure output value. + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG ARG is NULL. + * - ESP_ERR_INVALID_STATE The ambient temperature is out of range. + */ +esp_err_t temp_sensor_read_celsius(float *celsius); + +#ifdef __cplusplus +} +#endif diff --git a/components/efuse/src/esp_efuse_utility.c b/components/efuse/src/esp_efuse_utility.c index 00735bbff0..a6a303f72e 100644 --- a/components/efuse/src/esp_efuse_utility.c +++ b/components/efuse/src/esp_efuse_utility.c @@ -68,7 +68,7 @@ esp_err_t esp_efuse_utility_process(const esp_efuse_desc_t* field[], void* ptr, if ((bits_counter + num_bits) > req_size) { // Limits the length of the field. num_bits = req_size - bits_counter; } - ESP_EARLY_LOGD(TAG, "In EFUSE_BLK%d__DATA%d_REG is used %d bits starting with %d bit", + ESP_LOGD(TAG, "In EFUSE_BLK%d__DATA%d_REG is used %d bits starting with %d bit", (int)field[i]->efuse_block, num_reg, num_bits, start_bit); err = func_proc(num_reg, field[i]->efuse_block, start_bit, num_bits, ptr, &bits_counter); ++i_reg; diff --git a/components/esp_hw_support/port/esp32c3/regi2c_ctrl.h b/components/esp_hw_support/port/esp32c3/regi2c_ctrl.h index bee967ac7d..cec9f76d97 100644 --- a/components/esp_hw_support/port/esp32c3/regi2c_ctrl.h +++ b/components/esp_hw_support/port/esp32c3/regi2c_ctrl.h @@ -45,12 +45,12 @@ extern "C" { #define ANA_CONFIG_M (0x3FF) #define ANA_I2C_SAR_FORCE_PD BIT(18) -#define ANA_I2C_BBPLL_M (BIT(17)) /* Clear to enable BBPLL */ -#define ANA_I2C_APLL_M (BIT(14)) /* Clear to enable APLL */ +#define ANA_I2C_BBPLL_M BIT(17) /* Clear to enable BBPLL */ +#define ANA_I2C_APLL_M BIT(14) /* Clear to enable APLL */ #define ANA_CONFIG2_REG 0x6000E048 -#define ANA_CONFIG2_M (BIT(18)) +#define ANA_CONFIG2_M BIT(18) #define ANA_I2C_SAR_FORCE_PU BIT(16) From 402ccacc1011b58ffef8288c3d9521b8e140daa4 Mon Sep 17 00:00:00 2001 From: Armando Date: Fri, 22 Jan 2021 20:23:54 +0800 Subject: [PATCH 22/22] system: update edma reset in system_api_esp32c3/s3.c --- components/esp32c3/system_api_esp32c3.c | 6 +----- components/esp32s3/system_api_esp32s3.c | 5 ++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/components/esp32c3/system_api_esp32c3.c b/components/esp32c3/system_api_esp32c3.c index e054f72240..703a68e5b0 100644 --- a/components/esp32c3/system_api_esp32c3.c +++ b/components/esp32c3/system_api_esp32c3.c @@ -100,16 +100,12 @@ void IRAM_ATTR esp_restart_noos(void) // Reset timer/spi/uart SET_PERI_REG_MASK(SYSTEM_PERIP_RST_EN0_REG, - SYSTEM_TIMERS_RST | SYSTEM_SPI01_RST | SYSTEM_UART_RST | SYSTEM_SPI3_DMA_RST | SYSTEM_SPI2_DMA_RST); + SYSTEM_TIMERS_RST | SYSTEM_SPI01_RST | SYSTEM_UART_RST); REG_WRITE(SYSTEM_PERIP_RST_EN0_REG, 0); - // Reset dma SET_PERI_REG_MASK(SYSTEM_PERIP_RST_EN1_REG, SYSTEM_DMA_RST); REG_WRITE(SYSTEM_PERIP_RST_EN1_REG, 0); - SET_PERI_REG_MASK(SYSTEM_EDMA_CTRL_REG, SYSTEM_EDMA_RESET); - CLEAR_PERI_REG_MASK(SYSTEM_EDMA_CTRL_REG, SYSTEM_EDMA_RESET); - // Set CPU back to XTAL source, no PLL, same as hard reset #if !CONFIG_IDF_ENV_FPGA rtc_clk_cpu_freq_set_xtal(); diff --git a/components/esp32s3/system_api_esp32s3.c b/components/esp32s3/system_api_esp32s3.c index a562f37dfe..924da6fd2b 100644 --- a/components/esp32s3/system_api_esp32s3.c +++ b/components/esp32s3/system_api_esp32s3.c @@ -98,13 +98,16 @@ void IRAM_ATTR esp_restart_noos(void) // Reset timer/spi/uart SET_PERI_REG_MASK(SYSTEM_PERIP_RST_EN0_REG, - SYSTEM_TIMERS_RST | SYSTEM_SPI01_RST | SYSTEM_UART_RST | SYSTEM_SPI3_DMA_RST | SYSTEM_SPI2_DMA_RST); + SYSTEM_TIMERS_RST | SYSTEM_SPI01_RST | SYSTEM_UART_RST); REG_WRITE(SYSTEM_PERIP_RST_EN0_REG, 0); // Reset dma SET_PERI_REG_MASK(SYSTEM_PERIP_RST_EN1_REG, SYSTEM_DMA_RST); REG_WRITE(SYSTEM_PERIP_RST_EN1_REG, 0); + SET_PERI_REG_MASK(SYSTEM_EDMA_CTRL_REG, SYSTEM_EDMA_RESET); + CLEAR_PERI_REG_MASK(SYSTEM_EDMA_CTRL_REG, SYSTEM_EDMA_RESET); + // Set CPU back to XTAL source, no PLL, same as hard reset #if !CONFIG_IDF_ENV_FPGA rtc_clk_cpu_freq_set_xtal();