From 83e00cf64329569c16907423ee6b48c05fc4054b Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Thu, 13 Jun 2019 15:37:58 +0800 Subject: [PATCH 1/5] Driver: gpio and rtcio dirver update --- components/driver/gpio.c | 1 - components/driver/rtc_module.c | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/components/driver/gpio.c b/components/driver/gpio.c index 22095cd3b5..d8d5c26948 100644 --- a/components/driver/gpio.c +++ b/components/driver/gpio.c @@ -628,7 +628,6 @@ esp_err_t gpio_force_unhold_all() SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_CLR_DG_PAD_AUTOHOLD); return ESP_OK; } - #endif void gpio_iomux_in(uint32_t gpio, uint32_t signal_idx) diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index 5994f21eff..929440c63d 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -122,6 +122,48 @@ static touch_pad_filter_t *s_touch_pad_filter = NULL; static uint16_t s_touch_pad_init_bit = 0x0000; static filter_cb_t s_filter_cb = NULL; +#if CONFIG_IDF_TARGET_ESP32S2BETA +typedef volatile struct { + uint32_t reserved0: 13; + uint32_t fun_ie: 1; /*input enable in work mode*/ + uint32_t slp_oe: 1; /*output enable in sleep mode*/ + uint32_t slp_ie: 1; /*input enable in sleep mode*/ + uint32_t slp_sel: 1; /*1: enable sleep mode during sleep 0: no sleep mode*/ + uint32_t fun_sel: 2; /*function sel*/ + uint32_t mux_sel: 1; /*1: use RTC GPIO 0: use digital GPIO*/ + uint32_t reserved20: 7; + uint32_t rue: 1; /*RUE*/ + uint32_t rde: 1; /*RDE*/ + uint32_t drv: 2; /*DRV*/ + uint32_t reserved31: 1; +} rtc_gpio_info_t; + +static rtc_gpio_info_t* rtc_gpio[RTC_GPIO_NUMBER] = { + &RTCIO.touch_pad[0].val, + &RTCIO.touch_pad[1].val, + &RTCIO.touch_pad[2].val, + &RTCIO.touch_pad[3].val, + &RTCIO.touch_pad[4].val, + &RTCIO.touch_pad[5].val, + &RTCIO.touch_pad[6].val, + &RTCIO.touch_pad[7].val, + &RTCIO.touch_pad[8].val, + &RTCIO.touch_pad[9].val, + &RTCIO.touch_pad[10].val, + &RTCIO.touch_pad[11].val, + &RTCIO.touch_pad[12].val, + &RTCIO.touch_pad[13].val, + &RTCIO.touch_pad[14].val, + &RTCIO.xtal_32p_pad.val, + &RTCIO.xtal_32n_pad.val, + &RTCIO.pad_dac[0].val, + &RTCIO.pad_dac[1].val, + &RTCIO.rtc_pad19.val, + &RTCIO.rtc_pad20.val, + &RTCIO.rtc_pad21.val +}; +#endif + typedef enum { ADC_CTRL_RTC = 0, ADC_CTRL_ULP = 1, From b055bff580a1a93256777bf1b58db410f1cf4065 Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Thu, 13 Jun 2019 19:34:01 +0800 Subject: [PATCH 2/5] 1.update touch driver; 2.update adc/dac driver; 3.add temp sensor driver; --- .../src/bootloader_random.c | 37 +- components/driver/CMakeLists.txt | 2 + components/driver/include/driver/adc.h | 30 + components/driver/include/driver/dac.h | 8 + .../driver/include/driver/temp_sensor.h | 36 + components/driver/include/driver/touch_pad.h | 178 ++ components/driver/rtc_module.c | 216 +- components/driver/rtc_tempsensor.c | 99 + components/driver/rtc_touchpad.c | 738 ++++++ components/esp32s2beta/sleep_modes.c | 2 +- .../esp32s2beta/include/soc/rtc_cntl_reg.h | 4 +- .../esp32s2beta/include/soc/rtc_cntl_struct.h | 517 ++-- .../soc/esp32s2beta/include/soc/sens_reg.h | 2291 ++++++++++------- .../soc/esp32s2beta/include/soc/sens_struct.h | 586 +++-- .../esp32s2beta/include/soc/touch_channel.h | 50 +- components/ulp/ulp.c | 4 + .../peripherals/adc/main/adc1_example_main.c | 41 +- .../peripherals/adc2/main/adc2_example_main.c | 1 - .../peripherals/temp_sensor/CMakeLists.txt | 6 + examples/peripherals/temp_sensor/Makefile | 9 + examples/peripherals/temp_sensor/README.md | 0 .../temp_sensor/main/CMakeLists.txt | 4 + .../peripherals/temp_sensor/main/component.mk | 3 + .../temp_sensor/main/temp_sensor_main.c | 46 + .../main/tp_interrupt_main.c | 187 ++ .../touch_pad_read/main/tp_read_main.c | 73 + 26 files changed, 3793 insertions(+), 1375 deletions(-) create mode 100644 components/driver/include/driver/temp_sensor.h create mode 100644 components/driver/rtc_tempsensor.c create mode 100644 components/driver/rtc_touchpad.c create mode 100644 examples/peripherals/temp_sensor/CMakeLists.txt create mode 100644 examples/peripherals/temp_sensor/Makefile create mode 100644 examples/peripherals/temp_sensor/README.md create mode 100644 examples/peripherals/temp_sensor/main/CMakeLists.txt create mode 100644 examples/peripherals/temp_sensor/main/component.mk create mode 100644 examples/peripherals/temp_sensor/main/temp_sensor_main.c diff --git a/components/bootloader_support/src/bootloader_random.c b/components/bootloader_support/src/bootloader_random.c index 04fa10d9c4..99766abd72 100644 --- a/components/bootloader_support/src/bootloader_random.c +++ b/components/bootloader_support/src/bootloader_random.c @@ -20,6 +20,7 @@ #include "soc/dport_reg.h" #include "soc/i2s_periph.h" #include "esp_log.h" +#include "soc/io_mux_reg.h" #ifndef BOOTLOADER_BUILD #include "esp_system.h" @@ -81,11 +82,25 @@ void bootloader_random_enable(void) */ SET_PERI_REG_BITS(RTC_CNTL_TEST_MUX_REG, RTC_CNTL_DTEST_RTC, 2, RTC_CNTL_DTEST_RTC_S); SET_PERI_REG_MASK(RTC_CNTL_TEST_MUX_REG, RTC_CNTL_ENT_RTC); +#if CONFIG_IDF_TARGET_ESP32 SET_PERI_REG_MASK(SENS_SAR_START_FORCE_REG, SENS_SAR2_EN_TEST); DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2S0_CLK_EN); CLEAR_PERI_REG_MASK(SENS_SAR_START_FORCE_REG, SENS_ULP_CP_FORCE_START_TOP); CLEAR_PERI_REG_MASK(SENS_SAR_START_FORCE_REG, SENS_ULP_CP_START_TOP); +#elif CONFIG_IDF_TARGET_ESP32S2BETA + /* Disable IO1 digital function for random function. */ + PIN_INPUT_DISABLE(PERIPHS_IO_MUX_GPIO1_U); + PIN_PULLDWN_DIS(PERIPHS_IO_MUX_GPIO1_U); + PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO1_U); + WRITE_PERI_REG(SYSCON_SARADC_SAR1_PATT_TAB1_REG, 0xFFFFFFFF); + + SET_PERI_REG_MASK(SENS_SAR_MEAS2_CTRL1_REG, SENS_SAR2_EN_TEST); + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2S0_CLK_EN); + CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_CTRL_REG, RTC_CNTL_ULP_CP_FORCE_START_TOP); + CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_CTRL_REG, RTC_CNTL_ULP_CP_START_TOP); +#endif + // Test pattern configuration byte 0xAD: //--[7:4] channel_sel: 10-->en_test //--[3:2] bit_width : 3-->12bit @@ -94,10 +109,15 @@ void bootloader_random_enable(void) WRITE_PERI_REG(SYSCON_SARADC_SAR2_PATT_TAB2_REG, 0xADADADAD); WRITE_PERI_REG(SYSCON_SARADC_SAR2_PATT_TAB3_REG, 0xADADADAD); WRITE_PERI_REG(SYSCON_SARADC_SAR2_PATT_TAB4_REG, 0xADADADAD); - +#if CONFIG_IDF_TARGET_ESP32 SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 3, SENS_FORCE_XPD_SAR_S); SET_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR1_DIG_FORCE); SET_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DIG_FORCE); +#elif CONFIG_IDF_TARGET_ESP32S2BETA + SET_PERI_REG_BITS(SENS_SAR_POWER_XPD_SAR_REG, SENS_FORCE_XPD_SAR, 3, SENS_FORCE_XPD_SAR_S); + SET_PERI_REG_MASK(SENS_SAR_MEAS1_MUX_REG, SENS_SAR1_DIG_FORCE); +#endif + #if CONFIG_IDF_TARGET_ESP32 SET_PERI_REG_MASK(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_SAR2_MUX); #endif @@ -137,18 +157,25 @@ void bootloader_random_disable(void) CLEAR_PERI_REG_MASK(I2S_CONF_REG(0), I2S_RX_START); /* Restore SYSCON mode registers */ +#if CONFIG_IDF_TARGET_ESP32 CLEAR_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR1_DIG_FORCE); CLEAR_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DIG_FORCE); +#elif CONFIG_IDF_TARGET_ESP32S2BETA + CLEAR_PERI_REG_MASK(SENS_SAR_MEAS1_MUX_REG, SENS_SAR1_DIG_FORCE); +#endif +#if CONFIG_IDF_TARGET_ESP32 /* Restore SAR ADC mode */ CLEAR_PERI_REG_MASK(SENS_SAR_START_FORCE_REG, SENS_SAR2_EN_TEST); -#if CONFIG_IDF_TARGET_ESP32 CLEAR_PERI_REG_MASK(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_SAR2_MUX | SYSCON_SARADC_SAR_SEL | SYSCON_SARADC_DATA_TO_I2S); -#elif CONFIG_IDF_TARGET_ESP32S2BETA - CLEAR_PERI_REG_MASK(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_SAR_SEL | SYSCON_SARADC_DATA_TO_I2S); -#endif SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 0, SENS_FORCE_XPD_SAR_S); +#elif CONFIG_IDF_TARGET_ESP32S2BETA + CLEAR_PERI_REG_MASK(SENS_SAR_MEAS2_CTRL1_REG, SENS_SAR2_EN_TEST); + CLEAR_PERI_REG_MASK(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_SAR_SEL | SYSCON_SARADC_DATA_TO_I2S); + SET_PERI_REG_BITS(SENS_SAR_POWER_XPD_SAR_REG, SENS_FORCE_XPD_SAR, 0, SENS_FORCE_XPD_SAR_S); +#endif + #if CONFIG_IDF_TARGET_ESP32 SET_PERI_REG_BITS(SYSCON_SARADC_FSM_REG, SYSCON_SARADC_START_WAIT, 8, SYSCON_SARADC_START_WAIT_S); #endif diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 8e2ab494ba..743d213322 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -6,6 +6,8 @@ set(COMPONENT_SRCS "can.c" "periph_ctrl.c" "rmt.c" "rtc_module.c" + "rtc_tempsensor.c" + "rtc_touchpad.c" "sdspi_crc.c" "sdspi_host.c" "sdspi_transaction.c" diff --git a/components/driver/include/driver/adc.h b/components/driver/include/driver/adc.h index 91eb18fd2f..a890a8ab22 100644 --- a/components/driver/include/driver/adc.h +++ b/components/driver/include/driver/adc.h @@ -52,6 +52,7 @@ typedef enum { #define ADC_WIDTH_11Bit ADC_WIDTH_BIT_11 #define ADC_WIDTH_12Bit ADC_WIDTH_BIT_12 +#if CONFIG_IDF_TARGET_ESP32 typedef enum { ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO36 */ ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO37 */ @@ -77,6 +78,35 @@ typedef enum { ADC2_CHANNEL_9, /*!< ADC2 channel 9 is GPIO26 */ ADC2_CHANNEL_MAX, } adc2_channel_t; +#elif CONFIG_IDF_TARGET_ESP32S2BETA +typedef enum { + ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO1 */ + ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO2 */ + ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO3 */ + ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO4 */ + ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO5 */ + ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO6 */ + ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO7 */ + ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO8 */ + ADC1_CHANNEL_8, /*!< ADC1 channel 6 is GPIO9 */ + ADC1_CHANNEL_9, /*!< ADC1 channel 7 is GPIO10 */ + ADC1_CHANNEL_MAX, +} adc1_channel_t; + +typedef enum { + ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO11 */ + ADC2_CHANNEL_1, /*!< ADC2 channel 1 is GPIO12 */ + ADC2_CHANNEL_2, /*!< ADC2 channel 2 is GPIO13 */ + ADC2_CHANNEL_3, /*!< ADC2 channel 3 is GPIO14 */ + ADC2_CHANNEL_4, /*!< ADC2 channel 4 is GPIO15 */ + ADC2_CHANNEL_5, /*!< ADC2 channel 5 is GPIO16 */ + ADC2_CHANNEL_6, /*!< ADC2 channel 6 is GPIO17 */ + ADC2_CHANNEL_7, /*!< ADC2 channel 7 is GPIO18 */ + ADC2_CHANNEL_8, /*!< ADC2 channel 8 is GPIO19 */ + ADC2_CHANNEL_9, /*!< ADC2 channel 9 is GPIO20 */ + ADC2_CHANNEL_MAX, +} adc2_channel_t; +#endif typedef enum { ADC_CHANNEL_0 = 0, /*!< ADC channel */ diff --git a/components/driver/include/driver/dac.h b/components/driver/include/driver/dac.h index 1e60263c2f..cdde967398 100644 --- a/components/driver/include/driver/dac.h +++ b/components/driver/include/driver/dac.h @@ -23,11 +23,19 @@ extern "C" { #include "esp_err.h" #include "soc/dac_periph.h" +#if CONFIG_IDF_TARGET_ESP32 typedef enum { DAC_CHANNEL_1 = 1, /*!< DAC channel 1 is GPIO25 */ DAC_CHANNEL_2, /*!< DAC channel 2 is GPIO26 */ DAC_CHANNEL_MAX, } dac_channel_t; +#elif CONFIG_IDF_TARGET_ESP32S2BETA +typedef enum { + DAC_CHANNEL_1 = 1, /*!< DAC channel 1 is GPIO17 */ + DAC_CHANNEL_2, /*!< DAC channel 2 is GPIO18 */ + DAC_CHANNEL_MAX, +} dac_channel_t; +#endif /** * @brief Get the gpio number of a specific DAC channel. diff --git a/components/driver/include/driver/temp_sensor.h b/components/driver/include/driver/temp_sensor.h new file mode 100644 index 0000000000..eaf7c2cbcb --- /dev/null +++ b/components/driver/include/driver/temp_sensor.h @@ -0,0 +1,36 @@ +#ifndef _TEMP_SENSOR_H_ +#define _TEMP_SENSOR_H_ + +#include +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if CONFIG_IDF_TARGET_ESP32S2BETA +typedef enum { + TEMP_SENSOR_DAC_L0 = 5, // offset = -2, range: 50℃ ~ 125℃, error < 3℃. + TEMP_SENSOR_DAC_L1 = 7, // offset = -1, range: 20℃ ~ 100℃, error < 2℃. + TEMP_SENSOR_DAC_L2 = 15, // offset = 0, range:-10℃ ~ 80℃, error < 1℃. + TEMP_SENSOR_DAC_L3 = 11, // offset = 1, range:-30℃ ~ 50℃, error < 2℃. + TEMP_SENSOR_DAC_L4 = 10, // offset = 2, range:-40℃ ~ 20℃, error < 3℃. + TEMP_SENSOR_DAC_DEFAULT = TEMP_SENSOR_DAC_L2, +} temp_sensor_dac_offset_t;; + +typedef struct temp_sensor { + temp_sensor_dac_offset_t dac_offset; + uint8_t clk_div; +} temp_sensor_t; + +esp_err_t temp_sensor_set_config(temp_sensor_t temps); +esp_err_t temp_sensor_get_config(temp_sensor_t *temps); +esp_err_t temp_sensor_start(void); +esp_err_t temp_sensor_stop(void); +esp_err_t temp_sensor_read(uint8_t *temp_out); +#endif + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/components/driver/include/driver/touch_pad.h b/components/driver/include/driver/touch_pad.h index 0c3884ded9..bbfab6ab72 100644 --- a/components/driver/include/driver/touch_pad.h +++ b/components/driver/include/driver/touch_pad.h @@ -32,6 +32,13 @@ typedef enum { TOUCH_PAD_NUM7, /*!< Touch pad channel 7 is GPIO27*/ TOUCH_PAD_NUM8, /*!< Touch pad channel 8 is GPIO33*/ TOUCH_PAD_NUM9, /*!< Touch pad channel 9 is GPIO32*/ +#if CONFIG_IDF_TARGET_ESP32S2BETA + TOUCH_PAD_NUM10, /*!< Touch pad channel 6 is */ + TOUCH_PAD_NUM11, /*!< Touch pad channel 7 is */ + TOUCH_PAD_NUM12, /*!< Touch pad channel 8 is */ + TOUCH_PAD_NUM13, /*!< Touch pad channel 9 is */ + TOUCH_PAD_NUM14, /*!< Touch pad channel 9 is */ +#endif TOUCH_PAD_MAX, } touch_pad_t; @@ -98,9 +105,104 @@ typedef enum { TOUCH_FSM_MODE_MAX, } touch_fsm_mode_t; +#if CONFIG_IDF_TARGET_ESP32S2BETA +typedef enum { + TOUCH_PAD_INTR_DONE = 0, //each channel measure done. + TOUCH_PAD_INTR_ACTIVE = 1, + TOUCH_PAD_INTR_INACTIVE = 2, + TOUCH_PAD_INTR_ALL, + TOUCH_PAD_INTR_MAX +} touch_pad_intr_type_t; + +typedef enum { + TOUCH_PAD_INTR_MASK_DONE = BIT(0), //each channel measure done. + TOUCH_PAD_INTR_MASK_ACTIVE = BIT(1), + TOUCH_PAD_INTR_MASK_INACTIVE = BIT(2), + TOUCH_PAD_INTR_MASK_ALL = BIT(2)|BIT(1)|BIT(0), + TOUCH_PAD_INTR_MASK_MAX +}touch_pad_intr_mask_t; + +typedef enum { + TOUCH_PAD_DENOISE_BIT12 = 0, + TOUCH_PAD_DENOISE_BIT10 = 1, + TOUCH_PAD_DENOISE_BIT8 = 2, + TOUCH_PAD_DENOISE_BIT4 = 3, + TOUCH_PAD_DENOISE_MAX +} touch_pad_denoise_grade_t; + +typedef enum { + TOUCH_PAD_DENOISE_CAP_L0 = 0, // 0pf + TOUCH_PAD_DENOISE_CAP_L1 = 4, // 1.4pf + TOUCH_PAD_DENOISE_CAP_L2 = 2, // 2.8pf + TOUCH_PAD_DENOISE_CAP_L3 = 6, // 4.2pf + TOUCH_PAD_DENOISE_CAP_L4 = 1, // 5.6pf + TOUCH_PAD_DENOISE_CAP_L5 = 5, // 7.0pf + TOUCH_PAD_DENOISE_CAP_L6 = 3, // 8.4pf + TOUCH_PAD_DENOISE_CAP_L7 = 7, // 9.8pf + TOUCH_PAD_DENOISE_CAP_MAX +} touch_pad_denoise_cap_t; + +typedef struct touch_pad_denoise { + touch_pad_denoise_grade_t grade; + touch_pad_denoise_cap_t cap_level; +} touch_pad_denoise_t; + +typedef enum { + TOUCH_PAD_SHIELD_DRV_L0 = 0, // 40pf + TOUCH_PAD_SHIELD_DRV_L1, // 80pf + TOUCH_PAD_SHIELD_DRV_L2, // 120pf + TOUCH_PAD_SHIELD_DRV_L3, // 160pf + TOUCH_PAD_SHIELD_DRV_L4, // 200pf + TOUCH_PAD_SHIELD_DRV_L5, // 240pf + TOUCH_PAD_SHIELD_DRV_L6, // 280pf + TOUCH_PAD_SHIELD_DRV_L7, // 320pf + TOUCH_PAD_SHIELD_DRV_MAX +} touch_pad_shield_driver_t; + +typedef struct touch_pad_waterproof { + touch_pad_t guard_ring_pad; + touch_pad_shield_driver_t shield_driver; +} touch_pad_waterproof_t; + +typedef struct touch_pad_approach { + touch_pad_t select_pad0; + touch_pad_t select_pad1; + touch_pad_t select_pad2; + uint8_t means_num; +} touch_pad_approach_t; + +typedef enum { + TOUCH_PAD_CONN_HIGHZ = 0, + TOUCH_PAD_CONN_GND = 1, + TOUCH_PAD_CONN_MAX +} touch_pad_conn_type_t; + +typedef enum { + TOUCH_PAD_FILTER_IIR_2 = 0, + TOUCH_PAD_FILTER_IIR_4, + TOUCH_PAD_FILTER_IIR_8, + TOUCH_PAD_FILTER_JITTER, + TOUCH_PAD_FILTER_MAX +} touch_filter_mode_t; + +typedef struct touch_filter_config { + touch_filter_mode_t mode; + uint8_t debounce_cnt; //0 ~ 7. + uint8_t hysteresis_thr; //0 ~ 3. 0: 1/8; 1: 3/32; 2: 1/16; 3: 1/32; + uint8_t noise_thr; //0 ~ 3. 0: 1/2; 1: 3/8; 2: 1/4; 3: 1/8; + uint8_t noise_neg_thr; //0 ~ 3. 0: 1/2; 1: 3/8; 2: 1/4; 3: 1/8; + uint8_t neg_noise_limit;//0 ~ 15. + uint8_t jitter_step; //0 ~ 15. +} touch_filter_config_t; + +#define TOUCH_PAD_THRESHOLD_MAX 0x1FFFFF//0x3FFFFF + +#endif typedef intr_handle_t touch_isr_handle_t; +#if CONFIG_IDF_TARGET_ESP32 + #define TOUCH_PAD_SLEEP_CYCLE_DEFAULT (0x1000) /*! +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/semphr.h" +#include "esp_log.h" +#include "soc/rtc_io_reg.h" +#include "soc/rtc_io_struct.h" +#include "soc/sens_reg.h" +#include "soc/sens_struct.h" +#include "temp_sensor.h" +#if CONFIG_IDF_TARGET_ESP32 +#include "esp32/rom/ets_sys.h" +#elif CONFIG_IDF_TARGET_ESP32S2BETA +#include "esp32s2beta/rom/ets_sys.h" +#endif + +#if CONFIG_IDF_TARGET_ESP32S2BETA + +#define TEMP_SENSOR_XPD_WAIT_DEFAULT 0xFF /* Set wait cycle time(8MHz) from power up to reset enable. */ + +portMUX_TYPE rtc_temp_spinlock = portMUX_INITIALIZER_UNLOCKED; +static SemaphoreHandle_t rtc_touch_mux = NULL; + +esp_err_t temp_sensor_set_config(temp_sensor_t temps) +{ + portENTER_CRITICAL(&rtc_temp_spinlock); + SENS.sar_tctrl.tsens_dac = temps.dac_offset; + SENS.sar_tctrl.tsens_clk_div = temps.clk_div; + SENS.sar_tctrl.tsens_power_up_force = 1; + SENS.sar_tctrl2.tsens_xpd_wait = TEMP_SENSOR_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. + portEXIT_CRITICAL(&rtc_temp_spinlock); + return ESP_OK; +} + +esp_err_t temp_sensor_get_config(temp_sensor_t *temps) +{ + if(temps) { + portENTER_CRITICAL(&rtc_temp_spinlock); + temps->dac_offset = SENS.sar_tctrl.tsens_dac; + temps->clk_div = SENS.sar_tctrl.tsens_clk_div; + portEXIT_CRITICAL(&rtc_temp_spinlock); + return ESP_OK; + } else { + return ESP_FAIL; + } +} + +esp_err_t temp_sensor_start(void) +{ + portENTER_CRITICAL(&rtc_temp_spinlock); + SENS.sar_tctrl.tsens_dump_out = 0; + SENS.sar_tctrl2.tsens_clkgate_en = 1; + SENS.sar_tctrl.tsens_power_up = 1; + portEXIT_CRITICAL(&rtc_temp_spinlock); + return ESP_OK; +} + +esp_err_t temp_sensor_stop(void) +{ + portENTER_CRITICAL(&rtc_temp_spinlock); + SENS.sar_tctrl.tsens_power_up = 0; + SENS.sar_tctrl2.tsens_clkgate_en = 0; + portEXIT_CRITICAL(&rtc_temp_spinlock); + return ESP_OK; +} + +esp_err_t temp_sensor_read(uint8_t *temp_out) +{ + if(temp_out) { + portENTER_CRITICAL(&rtc_temp_spinlock); + SENS.sar_tctrl.tsens_dump_out = 1; + while(!SENS.sar_tctrl.tsens_ready); + *temp_out = SENS.sar_tctrl.tsens_out; + SENS.sar_tctrl.tsens_dump_out = 0; + portEXIT_CRITICAL(&rtc_temp_spinlock); + return ESP_OK; + } else { + return ESP_FAIL; + } +} +#endif \ No newline at end of file diff --git a/components/driver/rtc_touchpad.c b/components/driver/rtc_touchpad.c new file mode 100644 index 0000000000..5843d5665d --- /dev/null +++ b/components/driver/rtc_touchpad.c @@ -0,0 +1,738 @@ +// 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 "esp_log.h" +#include "soc/rtc_periph.h" +#include "soc/sens_periph.h" +#include "soc/rtc_io_reg.h" +#include "soc/rtc_io_struct.h" +#include "soc/sens_reg.h" +#include "soc/sens_struct.h" +#include "soc/rtc_cntl_reg.h" +#include "soc/rtc_cntl_struct.h" +#include "soc/rtc.h" +#include "soc/periph_defs.h" +#include "rtc_io.h" +#include "touch_pad.h" +#include "freertos/FreeRTOS.h" +#include "freertos/xtensa_api.h" +#include "freertos/semphr.h" +#include "freertos/timers.h" +#include "esp_intr_alloc.h" +#include "sys/lock.h" +#include "driver/rtc_cntl.h" +#include "driver/gpio.h" +#include "sdkconfig.h" +#if CONFIG_IDF_TARGET_ESP32 +#include "esp32/rom/ets_sys.h" +#elif CONFIG_IDF_TARGET_ESP32S2BETA +#include "esp32s2beta/rom/ets_sys.h" +#endif + +#ifndef NDEBUG +// Enable built-in checks in queue.h in debug builds +#define INVARIANTS +#endif +#include "sys/queue.h" + +#if CONFIG_IDF_TARGET_ESP32S2BETA + +#define TOUCH_PAD_FILTER_FACTOR_DEFAULT (4) // IIR filter coefficient. +#define TOUCH_PAD_SHIFT_DEFAULT (4) // Increase computing accuracy. +#define TOUCH_PAD_SHIFT_ROUND_DEFAULT (8) // ROUND = 2^(n-1); rounding off for fractional. +#define DAC_ERR_STR_CHANNEL_ERROR "DAC channel error" + +static portMUX_TYPE rtc_spinlock = portMUX_INITIALIZER_UNLOCKED; +static const char *RTC_MODULE_TAG = "RTC_MODULE"; + +#define RTC_MODULE_CHECK(a, str, ret_val) if (!(a)) { \ + ESP_LOGE(RTC_MODULE_TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \ + return (ret_val); \ +} + +#define RTC_RES_CHECK(res, ret_val) if ( (a) != ESP_OK) { \ + ESP_LOGE(RTC_MODULE_TAG,"%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__); \ + return (ret_val); \ +} +static SemaphoreHandle_t rtc_touch_mux = NULL; + +// check if touch pad be inited. +static uint16_t s_touch_pad_init_bit = 0x0000; + +/*--------------------------------------------------------------- + Touch Pad +---------------------------------------------------------------*/ +esp_err_t touch_pad_isr_register(intr_handler_t fn, void* arg, touch_pad_intr_mask_t intr_mask) +{ + RTC_MODULE_CHECK(intr_mask < TOUCH_PAD_INTR_MASK_MAX, "intr mask err", ESP_ERR_INVALID_ARG); + RTC_MODULE_CHECK(fn, "Touch_Pad ISR null", ESP_ERR_INVALID_ARG); + return rtc_isr_register(fn, arg, intr_mask << RTC_CNTL_TOUCH_DONE_INT_ENA_S); +} + +esp_err_t touch_pad_isr_deregister(intr_handler_t fn, void *arg) +{ + return rtc_isr_deregister(fn, arg); +} + +esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_cycle) +{ + xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); + portENTER_CRITICAL(&rtc_spinlock); + // touch sensor sleep cycle Time = sleep_cycle / RTC_SLOW_CLK( can be 150k or 32k depending on the options) + RTCCNTL.touch_ctrl1.touch_sleep_cycles = sleep_cycle; + //touch sensor measure time= meas_cycle / 8Mhz + RTCCNTL.touch_ctrl1.touch_meas_num = meas_cycle; + //the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD + RTCCNTL.touch_ctrl2.touch_xpd_wait = 255; //wait volt stable + portEXIT_CRITICAL(&rtc_spinlock); + xSemaphoreGive(rtc_touch_mux); + return ESP_OK; +} + +esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_cycle) +{ + RTC_MODULE_CHECK(sleep_cycle != NULL, "parameter is NULL", ESP_ERR_INVALID_ARG); + RTC_MODULE_CHECK(meas_cycle != NULL, "parameter is NULL", ESP_ERR_INVALID_ARG); + portENTER_CRITICAL(&rtc_spinlock); + *sleep_cycle = RTCCNTL.touch_ctrl1.touch_sleep_cycles; + *meas_cycle = RTCCNTL.touch_ctrl1.touch_meas_num; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_set_inactive_connect(touch_pad_conn_type_t type) +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_scan_ctrl.touch_inactive_connection = type; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_get_inactive_connect(touch_pad_conn_type_t *type) +{ + if(type) { + *type = RTCCNTL.touch_scan_ctrl.touch_inactive_connection; + return ESP_FAIL; + } else { + return ESP_OK; + } +} + +esp_err_t touch_pad_set_voltage(touch_high_volt_t refh, touch_low_volt_t refl, touch_volt_atten_t atten) +{ + portENTER_CRITICAL(&rtc_spinlock); + if (refh > TOUCH_HVOLT_KEEP) { + RTCCNTL.touch_ctrl2.touch_drefh = refh; + } + if (refl > TOUCH_LVOLT_KEEP) { + RTCCNTL.touch_ctrl2.touch_drefl = refl; + } + if (atten > TOUCH_HVOLT_ATTEN_KEEP) { + RTCCNTL.touch_ctrl2.touch_drange = atten; + } + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_get_voltage(touch_high_volt_t *refh, touch_low_volt_t *refl, touch_volt_atten_t *atten) +{ + portENTER_CRITICAL(&rtc_spinlock); + if (refh) { + *refh = RTCCNTL.touch_ctrl2.touch_drefh; + } + if (refl) { + *refl = RTCCNTL.touch_ctrl2.touch_drefl; + } + if (atten) { + *atten = RTCCNTL.touch_ctrl2.touch_drange; + } + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_set_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t slope) +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCIO.touch_pad[touch_num].tie_opt = TOUCH_PAD_TIE_OPT_LOW; + RTCIO.touch_pad[touch_num].dac = slope; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_get_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t *slope) +{ + portENTER_CRITICAL(&rtc_spinlock); + if(slope) { + *slope = RTCIO.touch_pad[touch_num].dac; + } + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_io_init(touch_pad_t touch_num) +{ + RTC_MODULE_CHECK((touch_num < TOUCH_PAD_MAX), "touch IO error", ESP_ERR_INVALID_ARG); + RTC_MODULE_CHECK((touch_num > TOUCH_PAD_NUM0), "touch IO error", ESP_ERR_INVALID_ARG); + gpio_num_t gpio_num = GPIO_NUM_1; + gpio_num = touch_num; + rtc_gpio_init(gpio_num); + rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_DISABLED); + rtc_gpio_pulldown_dis(gpio_num); + rtc_gpio_pullup_dis(gpio_num); + return ESP_OK; +} + +esp_err_t touch_pad_wait_init_done() +{ + // TODO + return ESP_FAIL; +} + +/*touch_pad_fsm_start_vf, after set mask*/ +esp_err_t touch_pad_fsm_start(touch_fsm_mode_t mode) +{ + RTC_MODULE_CHECK((mode < TOUCH_FSM_MODE_MAX), "touch fsm mode error", ESP_ERR_INVALID_ARG); + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_ctrl2.touch_start_en = 0; //stop touch fsm + RTCCNTL.touch_ctrl2.touch_start_force = mode; + RTCCNTL.touch_ctrl2.touch_slp_timer_en = (mode == TOUCH_FSM_MODE_TIMER ? 1 : 0); + RTCCNTL.touch_ctrl2.touch_clkgate_en = 1; //enable touch clock for FSM. or force enable. + SENS.sar_touch_chn_st.touch_channel_clr = TOUCH_PAD_BIT_MASK_MAX; // clear baseline + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_fsm_stop() +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_ctrl2.touch_start_en = 0; //stop touch fsm + RTCCNTL.touch_ctrl2.touch_slp_timer_en = 0; + RTCCNTL.touch_ctrl2.touch_clkgate_en = 0; //enable touch clock for FSM. or force enable. + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_get_fsm_mode(touch_fsm_mode_t *mode) +{ + if (mode) { + *mode = RTCCNTL.touch_ctrl2.touch_start_force; + } + return ESP_OK; +} + +/* + * If doing measure, the flag will be self-clear. + * After measure, the flag will be set. + */ +uint8_t touch_pad_means_is_done() +{ + return SENS.sar_touch_chn_st.touch_meas_done; +} + +/* return the current scan channel. */ +esp_err_t touch_pad_sw_start(touch_pad_t *current_scan) +{ + RTC_MODULE_CHECK((RTCCNTL.touch_ctrl2.touch_start_force == TOUCH_FSM_MODE_SW), + "touch IO error", ESP_FAIL); + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_ctrl2.touch_start_en = 0; + RTCCNTL.touch_ctrl2.touch_start_en = 1; + portEXIT_CRITICAL(&rtc_spinlock); + if(current_scan) { + *current_scan = SENS.sar_touch_status0.touch_scan_curr; + } + return ESP_OK; +} + +/* If set "TOUCH_PAD_THRESHOLD_MAX", the filter is not triger. */ +esp_err_t touch_pad_set_thresh(touch_pad_t touch_num, uint32_t threshold) +{ + RTC_MODULE_CHECK((threshold != 0), "threshold error", ESP_ERR_INVALID_ARG); + RTC_MODULE_CHECK((touch_num < TOUCH_PAD_MAX), "touch IO error", ESP_ERR_INVALID_ARG); + RTC_MODULE_CHECK((touch_num > TOUCH_PAD_NUM0), "touch0 no thresh", ESP_ERR_INVALID_ARG); + portENTER_CRITICAL(&rtc_spinlock); + SENS.touch_thresh[touch_num-1].thresh = threshold; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_get_thresh(touch_pad_t touch_num, uint32_t *threshold) +{ + RTC_MODULE_CHECK((touch_num < TOUCH_PAD_MAX), "touch IO error", ESP_ERR_INVALID_ARG); + if (threshold) { + *threshold = SENS.touch_thresh[touch_num-1].thresh; + } + return ESP_OK; +} + +/* If set mask, the FSM timer should be stop firsty. + * Noitce: The touchpad that in scan map ,should be deinit digital function firstly. + * */ +esp_err_t touch_pad_set_group_mask(uint16_t enable_mask) +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_scan_ctrl.touch_scan_pad_map |= (enable_mask&TOUCH_PAD_BIT_MASK_MAX); + SENS.sar_touch_conf.touch_outen |= (enable_mask&TOUCH_PAD_BIT_MASK_MAX); + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_get_group_mask(uint16_t *enable_mask) +{ + portENTER_CRITICAL(&rtc_spinlock); + *enable_mask = SENS.sar_touch_conf.touch_outen \ + & RTCCNTL.touch_scan_ctrl.touch_scan_pad_map \ + & TOUCH_PAD_BIT_MASK_MAX; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +/* If clear all mask, the FSM timer should be stop firsty. */ +esp_err_t touch_pad_clear_group_mask(uint16_t enable_mask) +{ + portENTER_CRITICAL(&rtc_spinlock); + SENS.sar_touch_conf.touch_outen &= ~(enable_mask&TOUCH_PAD_BIT_MASK_MAX); + RTCCNTL.touch_scan_ctrl.touch_scan_pad_map &= ~(enable_mask&TOUCH_PAD_BIT_MASK_MAX); + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +uint32_t IRAM_ATTR touch_pad_get_int_status() +{ + return REG_READ(RTC_CNTL_INT_ST_REG) >> (RTC_CNTL_TOUCH_DONE_INT_ST_S) & (TOUCH_PAD_INTR_MASK_ALL); +} + +/* + * The "touch_pad_active" will be change auto. + * If status bit is 1, this pad is be active, else, this pad is inactive. + */ +uint32_t IRAM_ATTR touch_pad_get_status() +{ + return (SENS.sar_touch_chn_st.touch_pad_active & TOUCH_PAD_BIT_MASK_MAX); +} +// get current scan channel. note: in interrupt and set a litter sleep time. +uint32_t IRAM_ATTR touch_pad_get_scan_curr() +{ + return (SENS.sar_touch_status0.touch_scan_curr); +} + +/* + * Normaly, Should't call this function manual. . + */ +esp_err_t IRAM_ATTR touch_pad_clear_status() +{ + portENTER_CRITICAL(&rtc_spinlock); + SENS.sar_touch_conf.touch_status_clr = 1; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_intr_enable(touch_pad_intr_type_t type) +{ + portENTER_CRITICAL(&rtc_spinlock); + if(type == TOUCH_PAD_INTR_DONE) { + RTCCNTL.int_ena.rtc_touch_done = 1; + } else if(type == TOUCH_PAD_INTR_ACTIVE) { + RTCCNTL.int_ena.rtc_touch_active = 1; + } else if(type == TOUCH_PAD_INTR_INACTIVE) { + RTCCNTL.int_ena.rtc_touch_inactive = 1; + } else if(type == TOUCH_PAD_INTR_ALL){ + RTCCNTL.int_ena.rtc_touch_done = 1; + RTCCNTL.int_ena.rtc_touch_active = 1; + RTCCNTL.int_ena.rtc_touch_inactive = 1; + } else { + ESP_LOGE(RTC_MODULE_TAG, "no this intr type"); + } + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_intr_disable(touch_pad_intr_type_t type) +{ + portENTER_CRITICAL(&rtc_spinlock); + if(type == TOUCH_PAD_INTR_DONE) { + RTCCNTL.int_ena.rtc_touch_done = 0; + } else if(type == TOUCH_PAD_INTR_ACTIVE) { + RTCCNTL.int_ena.rtc_touch_active = 0; + } else if(type == TOUCH_PAD_INTR_INACTIVE) { + RTCCNTL.int_ena.rtc_touch_inactive = 0; + } else if(type == TOUCH_PAD_INTR_ALL){ + RTCCNTL.int_ena.rtc_touch_done = 0; + RTCCNTL.int_ena.rtc_touch_active = 0; + RTCCNTL.int_ena.rtc_touch_inactive = 0; + } else { + ESP_LOGE(RTC_MODULE_TAG, "no this intr type"); + } + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +uint32_t IRAM_ATTR touch_pad_intr_get_mask() +{ + return REG_READ(RTC_CNTL_INT_ENA_REG) >> (RTC_CNTL_TOUCH_DONE_INT_ENA_S) & (TOUCH_PAD_INTR_MASK_ALL); +} + +esp_err_t touch_pad_config(touch_pad_t touch_num) +{ + RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + RTC_MODULE_CHECK(touch_num < TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG); + + touch_pad_io_init(touch_num); + touch_pad_set_cnt_mode(touch_num, TOUCH_PAD_SLOPE_7); + touch_pad_set_thresh(touch_num, TOUCH_PAD_THRESHOLD_MAX); + touch_pad_set_group_mask(BIT(touch_num)); + + return ESP_OK; +} + +esp_err_t touch_pad_init() +{ + if (rtc_touch_mux == NULL) { + rtc_touch_mux = xSemaphoreCreateMutex(); + } + if (rtc_touch_mux == NULL) { + return ESP_FAIL; + } + touch_pad_intr_disable(TOUCH_PAD_INTR_ALL); + touch_pad_clear_group_mask(TOUCH_PAD_BIT_MASK_MAX); + touch_pad_clear_status(); + touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_MEASURE_CYCLE_DEFAULT); + // Set reference voltage for charging/discharging + touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V5); + touch_pad_set_inactive_connect(TOUCH_PAD_CONN_GND); + return ESP_OK; +} + +esp_err_t touch_pad_deinit() +{ + RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); + s_touch_pad_init_bit = 0x0000; + touch_pad_fsm_stop(); + touch_pad_clear_status(); + touch_pad_intr_disable(TOUCH_PAD_INTR_ALL); + xSemaphoreGive(rtc_touch_mux); + vSemaphoreDelete(rtc_touch_mux); + rtc_touch_mux = NULL; + return ESP_OK; +} + +/*raw data 的单位是时间,单位是 1/8MHz */ +IRAM_ATTR esp_err_t touch_pad_read_raw(touch_pad_t touch_num, uint32_t *raw_data) +{ + RTC_MODULE_CHECK(touch_num > TOUCH_PAD_NUM0, "Touch pad0 is forbidden", ESP_FAIL); + if (raw_data) { + *raw_data = SENS.touch_meas[touch_num].meas_out; + } + return ESP_OK; +} + + +IRAM_ATTR esp_err_t touch_pad_filter_baseline_read(touch_pad_t touch_num, uint32_t *basedata) +{ + RTC_MODULE_CHECK(touch_num > TOUCH_PAD_NUM0, "Touch pad0 is forbidden", ESP_FAIL); + if (basedata) { + *basedata = SENS.sar_touch_status[touch_num-1].touch_pad_baseline; + } + return ESP_OK; +} + +IRAM_ATTR esp_err_t touch_pad_read_debounce(touch_pad_t touch_num, uint32_t *debounce) +{ + RTC_MODULE_CHECK(touch_num > TOUCH_PAD_NUM0, "Touch pad0 is forbidden", ESP_FAIL); + if (debounce) { + *debounce = SENS.sar_touch_status[touch_num-1].touch_pad_debounce; + } + return ESP_OK; +} + +IRAM_ATTR esp_err_t touch_pad_read_thresh(touch_pad_t touch_num, uint32_t *thresh_out) +{ + RTC_MODULE_CHECK(touch_num > TOUCH_PAD_NUM0, "Touch pad0 is forbidden", ESP_FAIL); + if (thresh_out) { + *thresh_out = SENS.touch_thresh[touch_num-1].thresh; + } + return ESP_OK; +} + +/* Should be call after clk enable and filter enable. */ +esp_err_t touch_pad_filter_baseline_reset(touch_pad_t touch_num) +{ + RTC_MODULE_CHECK(touch_num <= TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG); + portENTER_CRITICAL(&rtc_spinlock); + if(touch_num == TOUCH_PAD_MAX) { + SENS.sar_touch_chn_st.touch_channel_clr = TOUCH_PAD_BIT_MASK_MAX; + } else { + SENS.sar_touch_chn_st.touch_channel_clr = BIT(touch_num); + } + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_filter_set_config(touch_filter_config_t filter_info) +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_filter_ctrl.touch_filter_mode = filter_info.mode; + RTCCNTL.touch_filter_ctrl.touch_debounce = filter_info.debounce_cnt; + RTCCNTL.touch_filter_ctrl.touch_hysteresis = filter_info.hysteresis_thr; + RTCCNTL.touch_filter_ctrl.touch_noise_thres = filter_info.noise_thr; + RTCCNTL.touch_filter_ctrl.touch_neg_noise_thres = filter_info.noise_neg_thr; + RTCCNTL.touch_filter_ctrl.touch_neg_noise_limit = filter_info.neg_noise_limit; + RTCCNTL.touch_filter_ctrl.touch_jitter_step = filter_info.jitter_step; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info) +{ + portENTER_CRITICAL(&rtc_spinlock); + filter_info->mode = RTCCNTL.touch_filter_ctrl.touch_filter_mode; + filter_info->debounce_cnt = RTCCNTL.touch_filter_ctrl.touch_debounce; + filter_info->hysteresis_thr = RTCCNTL.touch_filter_ctrl.touch_hysteresis; + filter_info->noise_thr = RTCCNTL.touch_filter_ctrl.touch_noise_thres; + filter_info->noise_neg_thr = RTCCNTL.touch_filter_ctrl.touch_neg_noise_thres; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_filter_start() +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_filter_ctrl.touch_filter_en = 1; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_filter_stop() +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_filter_ctrl.touch_filter_en = 0; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_enable() +{ + touch_pad_clear_group_mask(BIT(TOUCH_PAD_NUM0)); + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_scan_ctrl.touch_denoise_en = 1; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_disable() +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_scan_ctrl.touch_denoise_en = 0; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t denoise) +{ + touch_pad_set_cnt_mode(TOUCH_PAD_NUM0, TOUCH_PAD_SLOPE_7); + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_ctrl2.touch_refc = denoise.cap_level; + RTCCNTL.touch_scan_ctrl.touch_denoise_res = denoise.grade; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise) +{ + if(denoise) { + denoise->grade = RTCCNTL.touch_scan_ctrl.touch_denoise_res; + denoise->cap_level = RTCCNTL.touch_ctrl2.touch_refc; + return ESP_OK; + } else { + return ESP_FAIL; + } +} + +esp_err_t touch_pad_denoise_data_get(uint32_t *data) +{ + *data = SENS.sar_touch_status0.touch_denoise_data; + return ESP_OK; +} + +/* + * waterproof function include two setting part: 'shield pad driver' and 'guard ring pad num' + * @note waterproof and touch function are mutually exclusive. if config touch14, dont use shield. + * @note self-calibration is implemented in hardware. + * @note touch_out_ring point to touch0, can disable the guatd ring function ? + * @note "touch_bufdrv" should user config ? + */ +esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t waterproof) +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_scan_ctrl.touch_out_ring = waterproof.guard_ring_pad; + RTCCNTL.touch_scan_ctrl.touch_bufdrv = waterproof.shield_driver; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof) +{ + if(waterproof) { + waterproof->guard_ring_pad = RTCCNTL.touch_scan_ctrl.touch_out_ring; + waterproof->shield_driver = RTCCNTL.touch_scan_ctrl.touch_bufdrv; + return ESP_OK; + } else { + return ESP_FAIL; + } +} + +esp_err_t touch_pad_waterproof_enable() +{ + touch_pad_clear_group_mask(BIT(TOUCH_PAD_NUM14)); + touch_pad_io_init(TOUCH_PAD_NUM14); + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_scan_ctrl.touch_shield_pad_en = 1; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_waterproof_disable() +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_scan_ctrl.touch_shield_pad_en = 0; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +/* + * @note approach pad can set three pin. + * @note if clear the approach pad, point this pad to touch0 and then reset this channel baseline. + * @note the approach thresh is abs value. + * @note TODO: add channel reset reg. + */ +esp_err_t touch_pad_approach_set_config(touch_pad_approach_t approach) +{ + portENTER_CRITICAL(&rtc_spinlock); + if(approach.select_pad0) { + SENS.sar_touch_conf.touch_approach_pad0 = approach.select_pad0; + } + if(approach.select_pad1) { + SENS.sar_touch_conf.touch_approach_pad1 = approach.select_pad1; + } + if(approach.select_pad2) { + SENS.sar_touch_conf.touch_approach_pad2 = approach.select_pad2; + } + RTCCNTL.touch_approach.touch_approach_meas_time = approach.means_num; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +esp_err_t touch_pad_approach_get_config(touch_pad_approach_t *approach) +{ + if(approach) { + approach->select_pad0 = SENS.sar_touch_conf.touch_approach_pad0; + approach->select_pad1 = SENS.sar_touch_conf.touch_approach_pad1; + approach->select_pad2 = SENS.sar_touch_conf.touch_approach_pad2; + approach->means_num = RTCCNTL.touch_approach.touch_approach_meas_time; + return ESP_OK; + } else { + return ESP_FAIL; + } +} + +uint32_t touch_pad_approach_get_cnt(uint8_t pad) +{ + uint32_t cnt = 0; + if(pad == 0){ + cnt = SENS.sar_touch_status16.touch_approach_pad0_cnt; + } else if(pad == 1) { + cnt = SENS.sar_touch_status16.touch_approach_pad1_cnt; + } else if(pad == 2) { + cnt = SENS.sar_touch_status16.touch_approach_pad2_cnt; + } else if(pad == 3) { + cnt = SENS.sar_touch_status16.touch_slp_approach_cnt; + } + return cnt; +} + +/* TODO */ +esp_err_t touch_pad_approach_disable() +{ + portENTER_CRITICAL(&rtc_spinlock); + SENS.sar_touch_conf.touch_approach_pad0 = 0; + SENS.sar_touch_conf.touch_approach_pad1 = 0; + SENS.sar_touch_conf.touch_approach_pad2 = 0; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +/* After touch_clkgate_en = 0, reset the whole of touch module. */ +esp_err_t touch_pad_reset() +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_ctrl2.touch_reset = 0; + RTCCNTL.touch_ctrl2.touch_reset = 1; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +/************** sleep pad setting ***********************/ + +esp_err_t touch_pad_sleep_pad_config(touch_pad_t pad, uint32_t sleep_thr, uint8_t is_approach) +{ + portENTER_CRITICAL(&rtc_spinlock); + RTCCNTL.touch_slp_thres.touch_slp_pad = pad; + RTCCNTL.touch_slp_thres.touch_slp_th = sleep_thr; + RTCCNTL.touch_slp_thres.touch_slp_approach_en = is_approach?1:0; + portEXIT_CRITICAL(&rtc_spinlock); + return ESP_OK; +} + +/** + * Get sleep touch pad baseline data. + * + * @param baseline + */ +void touch_sleep_baseline_get(uint32_t *baseline) +{ + *baseline = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS15_REG, SENS_TOUCH_SLP_BASELINE); +} + +/** + * Get sleep touch pad debounce data. + * + * @param debounce + */ +void touch_sleep_debounce_get(uint32_t *debounce) +{ + *debounce = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS15_REG, SENS_TOUCH_SLP_DEBOUNCE); +} + +/** + * Get sleep touch pad approach cnt data. + * + * @param approach_cnt + */ +void touch_sleep_approach_cnt_get(uint32_t *approach_cnt) +{ + *approach_cnt = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS16_REG, SENS_TOUCH_SLP_APPROACH_CNT); +} + +esp_err_t touch_pad_get_wakeup_status(touch_pad_t *pad_num) +{ + uint32_t touch_mask = SENS.sar_touch_chn_st.touch_pad_active; + *pad_num = __builtin_ffs(touch_mask) - 1; + return ESP_OK; +} + +#endif \ No newline at end of file diff --git a/components/esp32s2beta/sleep_modes.c b/components/esp32s2beta/sleep_modes.c index 7bc6835f60..c5e5181fd4 100644 --- a/components/esp32s2beta/sleep_modes.c +++ b/components/esp32s2beta/sleep_modes.c @@ -406,7 +406,7 @@ touch_pad_t esp_sleep_get_touchpad_wakeup_status() if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_TOUCHPAD) { return TOUCH_PAD_MAX; } - uint32_t touch_mask = REG_GET_FIELD(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_EN); + uint32_t touch_mask = REG_GET_FIELD(RTC_CNTL_TOUCH_CTRL1_REG, RTC_CNTL_TOUCH_MEAS_NUM); assert(touch_mask != 0 && "wakeup reason is RTC_TOUCH_TRIG_EN but SENS_TOUCH_MEAS_EN is zero"); return (touch_pad_t) (__builtin_ffs(touch_mask) - 1); } diff --git a/components/soc/esp32s2beta/include/soc/rtc_cntl_reg.h b/components/soc/esp32s2beta/include/soc/rtc_cntl_reg.h index 54bf7764e3..bdf0d5bbc8 100644 --- a/components/soc/esp32s2beta/include/soc/rtc_cntl_reg.h +++ b/components/soc/esp32s2beta/include/soc/rtc_cntl_reg.h @@ -336,7 +336,7 @@ extern "C" { #define RTC_CNTL_XTL_BUF_WAIT_M ((RTC_CNTL_XTL_BUF_WAIT_V)<<(RTC_CNTL_XTL_BUF_WAIT_S)) #define RTC_CNTL_XTL_BUF_WAIT_V 0x3FF #define RTC_CNTL_XTL_BUF_WAIT_S 14 -#define RTC_CNTL_XTL_BUF_WAIT_DEFAULT 20 +#define RTC_CNTL_XTL_BUF_WAIT_DEFAULT 100 /* RTC_CNTL_CK8M_WAIT : R/W ;bitpos:[13:6] ;default: 8'h10 ; */ /*description: CK8M wait cycles in slow_clk_rtc*/ #define RTC_CNTL_CK8M_WAIT 0x000000FF @@ -1451,7 +1451,7 @@ extern "C" { #define RTC_CNTL_DBG_ATTEN_V 0xF #define RTC_CNTL_DBG_ATTEN_S 22 /* reserved for driver to check */ -#define RTC_CNTL_DBG_ATTEN_DEFAULT 3 +#define RTC_CNTL_DBG_ATTEN_DEFAULT 15 #define RTC_CNTL_REG (DR_REG_RTCCNTL_BASE + 0x0084) /* RTC_CNTL_REGULATOR_FORCE_PU : R/W ;bitpos:[31] ;default: 1'd1 ; */ diff --git a/components/soc/esp32s2beta/include/soc/rtc_cntl_struct.h b/components/soc/esp32s2beta/include/soc/rtc_cntl_struct.h index 44ce111137..03f2ec0f58 100644 --- a/components/soc/esp32s2beta/include/soc/rtc_cntl_struct.h +++ b/components/soc/esp32s2beta/include/soc/rtc_cntl_struct.h @@ -1,9 +1,9 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// Copyright 2017-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 @@ -64,37 +64,34 @@ typedef volatile struct { } slp_timer1; union { struct { - uint32_t reserved0: 30; + uint32_t reserved0: 27; + uint32_t timer_sys_stall: 1; /*Enable to record system stall time*/ + uint32_t timer_xtl_off: 1; /*Enable to record 40M XTAL OFF time*/ + uint32_t timer_sys_rst: 1; /*enable to record system reset time*/ uint32_t valid: 1; /*To indicate the register is updated*/ uint32_t update: 1; /*Set 1: to update register with RTC timer*/ }; uint32_t val; } time_update; - uint32_t time0; /*RTC timer low 32 bits*/ + uint32_t time_low0; /*RTC timer low 32 bits*/ union { struct { - uint32_t time_hi: 16; /*RTC timer high 16 bits*/ - uint32_t reserved16: 16; + uint32_t rtc_timer_value0_high:16; /*RTC timer high 16 bits*/ + uint32_t reserved16: 16; }; uint32_t val; - } time1; + } time_high0; union { struct { - uint32_t reserved0: 18; - uint32_t cocpu_wakeup: 1; /*riscV cocpu wake up register*/ - uint32_t cocpu_wakeup_force_en: 1; /*riscV cocpu force wake up*/ - uint32_t touch_wakeup_force_en: 1; /*touch controller force wake up*/ - uint32_t ulp_cp_wakeup_force_en: 1; /*ULP-coprocessor force wake up*/ - uint32_t apb2rtc_bridge_sel: 1; /*1: APB to RTC using bridge 0: APB to RTC using sync*/ - uint32_t touch_slp_timer_en: 1; /*touch timer enable bit*/ - uint32_t ulp_cp_slp_timer_en: 1; /*ULP-coprocessor timer enable bit*/ - uint32_t ulp_cp_gpio_wakeup_ena: 1; /*ULP-coprocessor wakeup by GPIO enable*/ - uint32_t ulp_cp_gpio_wakeup_clr: 1; /*ULP-coprocessor wakeup by GPIO state clear*/ - uint32_t reserved27: 1; - uint32_t sdio_active_ind: 1; /*SDIO active indication*/ - uint32_t slp_wakeup: 1; /*leep wakeup bit*/ - uint32_t slp_reject: 1; /*leep reject bit*/ - uint32_t sleep_en: 1; /*sleep enable bit*/ + uint32_t rtc_sw_cpu_int: 1; /*rtc software interrupt to main cpu*/ + uint32_t rtc_slp_reject_cause_clr: 1; /*clear rtc sleep reject cause*/ + uint32_t reserved2: 20; + uint32_t apb2rtc_bridge_sel: 1; /*1: APB to RTC using bridge 0: APB to RTC using sync*/ + uint32_t reserved23: 5; + uint32_t sdio_active_ind: 1; /*SDIO active indication*/ + uint32_t slp_wakeup: 1; /*leep wakeup bit*/ + uint32_t slp_reject: 1; /*leep reject bit*/ + uint32_t sleep_en: 1; /*sleep enable bit*/ }; uint32_t val; } state0; @@ -136,10 +133,10 @@ typedef volatile struct { } timer4; union { struct { - uint32_t ulp_cp_subtimer_prediv: 8; - uint32_t min_slp_val: 8; /*minimal sleep cycles in slow_clk_rtc*/ - uint32_t rtcmem_wait_timer: 9; - uint32_t rtcmem_powerup_timer: 7; + uint32_t reserved0: 8; + uint32_t min_slp_val: 8; /*minimal sleep cycles in slow_clk_rtc*/ + uint32_t rtcmem_wait_timer: 9; + uint32_t rtcmem_powerup_timer: 7; }; uint32_t val; } timer5; @@ -153,9 +150,7 @@ typedef volatile struct { } timer6; union { struct { - uint32_t reserved0: 19; - uint32_t pkdet_cal_force_en: 2; /*pkdet force option*/ - uint32_t pwdet_cal_force_en: 2; /*pwdet force option*/ + uint32_t reserved0: 23; uint32_t plla_force_pd: 1; /*PLLA force power down*/ uint32_t plla_force_pu: 1; /*PLLA force power up*/ uint32_t bbpll_cal_slp_start: 1; /*start BBPLL calibration during sleep*/ @@ -180,95 +175,130 @@ typedef volatile struct { } reset_state; union { struct { - uint32_t wakeup_cause: 12; /*wakeup cause*/ - uint32_t rtc_wakeup_ena: 12; /*wakeup enable bitmap*/ + uint32_t wakeup_cause: 15; /*wakeup cause*/ + uint32_t rtc_wakeup_ena: 15; /*wakeup enable bitmap*/ uint32_t gpio_wakeup_filter: 1; /*enable filter for gpio wakeup event*/ - uint32_t reserved25: 7; + uint32_t reserved31: 1; }; uint32_t val; } wakeup_state; union { struct { - uint32_t slp_wakeup: 1; /*enable sleep wakeup interrupt*/ - uint32_t slp_reject: 1; /*enable sleep reject interrupt*/ - uint32_t sdio_idle: 1; /*enable SDIO idle interrupt*/ - uint32_t rtc_wdt: 1; /*enable RTC WDT interrupt*/ - uint32_t rtc_time_valid: 1; /*enable RTC time valid interrupt*/ - uint32_t rtc_ulp_cp: 1; /*enable ULP-coprocessor interrupt*/ - uint32_t rtc_touch: 1; /*enable touch interrupt*/ - uint32_t rtc_brown_out: 1; /*enable brown out interrupt*/ - uint32_t rtc_main_timer: 1; /*enable RTC main timer interrupt*/ - uint32_t rtc_saradc1: 1; /*enable saradc1 interrupt*/ - uint32_t rtc_tsens: 1; /*enable tsens interrupt*/ - uint32_t rtc_cocpu: 1; /*enable riscV cocpu interrupt*/ - uint32_t rtc_saradc2: 1; /*enable saradc2 interrupt*/ - uint32_t reserved13: 19; + uint32_t slp_wakeup: 1; /*enable sleep wakeup interrupt*/ + uint32_t slp_reject: 1; /*enable sleep reject interrupt*/ + uint32_t sdio_idle: 1; /*enable SDIO idle interrupt*/ + uint32_t rtc_wdt: 1; /*enable RTC WDT interrupt*/ + uint32_t rtc_time_valid: 1; /*enable RTC time valid interrupt*/ + uint32_t rtc_ulp_cp: 1; /*enable ULP-coprocessor interrupt*/ + uint32_t rtc_touch_done: 1; /*enable touch done interrupt*/ + uint32_t rtc_touch_active: 1; /*enable touch active interrupt*/ + uint32_t rtc_touch_inactive: 1; /*enable touch inactive interrupt*/ + uint32_t rtc_brown_out: 1; /*enable brown out interrupt*/ + uint32_t rtc_main_timer: 1; /*enable RTC main timer interrupt*/ + uint32_t rtc_saradc1: 1; /*enable saradc1 interrupt*/ + uint32_t rtc_tsens: 1; /*enable tsens interrupt*/ + uint32_t rtc_cocpu: 1; /*enable riscV cocpu interrupt*/ + uint32_t rtc_saradc2: 1; /*enable saradc2 interrupt*/ + uint32_t rtc_swd: 1; /*enable super watch dog interrupt*/ + uint32_t rtc_xtal32k_dead: 1; /*enable cocpu trap interrupt*/ + uint32_t rtc_cocpu_trap: 1; + uint32_t reserved18: 14; }; uint32_t val; } int_ena; union { struct { - uint32_t slp_wakeup: 1; /*sleep wakeup interrupt raw*/ - uint32_t slp_reject: 1; /*sleep reject interrupt raw*/ - uint32_t sdio_idle: 1; /*SDIO idle interrupt raw*/ - uint32_t rtc_wdt: 1; /*RTC WDT interrupt raw*/ - uint32_t rtc_time_valid: 1; /*RTC time valid interrupt raw*/ - uint32_t rtc_ulp_cp: 1; /*ULP-coprocessor interrupt raw*/ - uint32_t rtc_touch: 1; /*touch interrupt raw*/ - uint32_t rtc_brown_out: 1; /*brown out interrupt raw*/ - uint32_t rtc_main_timer: 1; /*RTC main timer interrupt raw*/ - uint32_t rtc_saradc1: 1; /*saradc1 interrupt raw*/ - uint32_t rtc_tsens: 1; /*tsens interrupt raw*/ - uint32_t rtc_cocpu: 1; /*riscV cocpu interrupt raw*/ - uint32_t rtc_saradc2: 1; /*saradc2 interrupt raw*/ - uint32_t reserved13: 19; + uint32_t slp_wakeup: 1; /*sleep wakeup interrupt raw*/ + uint32_t slp_reject: 1; /*sleep reject interrupt raw*/ + uint32_t sdio_idle: 1; /*SDIO idle interrupt raw*/ + uint32_t rtc_wdt: 1; /*RTC WDT interrupt raw*/ + uint32_t rtc_time_valid: 1; /*RTC time valid interrupt raw*/ + uint32_t rtc_ulp_cp: 1; /*ULP-coprocessor interrupt raw*/ + uint32_t rtc_touch_done: 1; /*touch interrupt raw*/ + uint32_t rtc_touch_active: 1; /*touch active interrupt raw*/ + uint32_t rtc_touch_inactive: 1; /*touch inactive interrupt raw*/ + uint32_t rtc_brown_out: 1; /*brown out interrupt raw*/ + uint32_t rtc_main_timer: 1; /*RTC main timer interrupt raw*/ + uint32_t rtc_saradc1: 1; /*saradc1 interrupt raw*/ + uint32_t rtc_tsens: 1; /*tsens interrupt raw*/ + uint32_t rtc_cocpu: 1; /*riscV cocpu interrupt raw*/ + uint32_t rtc_saradc2: 1; /*saradc2 interrupt raw*/ + uint32_t rtc_swd: 1; /*super watch dog interrupt raw*/ + uint32_t rtc_xtal32k_dead: 1; /*xtal32k dead detection interrupt raw*/ + uint32_t rtc_cocpu_trap: 1; /*cocpu trap interrupt raw*/ + uint32_t reserved18: 14; }; uint32_t val; } int_raw; union { struct { - uint32_t slp_wakeup: 1; /*sleep wakeup interrupt state*/ - uint32_t slp_reject: 1; /*sleep reject interrupt state*/ - uint32_t sdio_idle: 1; /*SDIO idle interrupt state*/ - uint32_t rtc_wdt: 1; /*RTC WDT interrupt state*/ - uint32_t rtc_time_valid: 1; /*RTC time valid interrupt state*/ - uint32_t rtc_ulp_cp: 1; /*ULP-coprocessor interrupt state*/ - uint32_t rtc_touch: 1; /*touch interrupt state*/ - uint32_t rtc_brown_out: 1; /*brown out interrupt state*/ - uint32_t rtc_main_timer: 1; /*RTC main timer interrupt state*/ - uint32_t rtc_saradc1: 1; /*saradc1 interrupt state*/ - uint32_t rtc_tsens: 1; /*tsens interrupt state*/ - uint32_t rtc_cocpu: 1; /*riscV cocpu interrupt state*/ - uint32_t rtc_saradc2: 1; /*saradc2 interrupt state*/ - uint32_t reserved13: 19; + uint32_t slp_wakeup: 1; /*sleep wakeup interrupt state*/ + uint32_t slp_reject: 1; /*sleep reject interrupt state*/ + uint32_t sdio_idle: 1; /*SDIO idle interrupt state*/ + uint32_t rtc_wdt: 1; /*RTC WDT interrupt state*/ + uint32_t rtc_time_valid: 1; /*RTC time valid interrupt state*/ + uint32_t rtc_ulp_cp: 1; /*ULP-coprocessor interrupt state*/ + uint32_t rtc_touch_done: 1; /*touch done interrupt state*/ + uint32_t rtc_touch_active: 1; /*touch active interrupt state*/ + uint32_t rtc_touch_inactive: 1; /*touch inactive interrupt state*/ + uint32_t rtc_brown_out: 1; /*brown out interrupt state*/ + uint32_t rtc_main_timer: 1; /*RTC main timer interrupt state*/ + uint32_t rtc_saradc1: 1; /*saradc1 interrupt state*/ + uint32_t rtc_tsens: 1; /*tsens interrupt state*/ + uint32_t rtc_cocpu: 1; /*riscV cocpu interrupt state*/ + uint32_t rtc_saradc2: 1; /*saradc2 interrupt state*/ + uint32_t rtc_swd: 1; /*super watch dog interrupt state*/ + uint32_t rtc_xtal32k_dead: 1; /*xtal32k dead detection interrupt state*/ + uint32_t rtc_cocpu_trap: 1; /*cocpu trap interrupt state*/ + uint32_t reserved18: 14; }; uint32_t val; } int_st; union { struct { - uint32_t slp_wakeup: 1; /*Clear sleep wakeup interrupt state*/ - uint32_t slp_reject: 1; /*Clear sleep reject interrupt state*/ - uint32_t sdio_idle: 1; /*Clear SDIO idle interrupt state*/ - uint32_t rtc_wdt: 1; /*Clear RTC WDT interrupt state*/ - uint32_t rtc_time_valid: 1; /*Clear RTC time valid interrupt state*/ - uint32_t rtc_ulp_cp: 1; /*Clear ULP-coprocessor interrupt state*/ - uint32_t rtc_touch: 1; /*Clear touch interrupt state*/ - uint32_t rtc_brown_out: 1; /*Clear brown out interrupt state*/ - uint32_t rtc_main_timer: 1; /*Clear RTC main timer interrupt state*/ - uint32_t rtc_saradc1: 1; /*Clear saradc1 interrupt state*/ - uint32_t rtc_tsens: 1; /*Clear tsens interrupt state*/ - uint32_t rtc_cocpu: 1; /*Clear riscV cocpu interrupt state*/ - uint32_t rtc_saradc2: 1; /*Clear saradc2 interrupt state*/ - uint32_t reserved13: 19; + uint32_t slp_wakeup: 1; /*Clear sleep wakeup interrupt state*/ + uint32_t slp_reject: 1; /*Clear sleep reject interrupt state*/ + uint32_t sdio_idle: 1; /*Clear SDIO idle interrupt state*/ + uint32_t rtc_wdt: 1; /*Clear RTC WDT interrupt state*/ + uint32_t rtc_time_valid: 1; /*Clear RTC time valid interrupt state*/ + uint32_t rtc_ulp_cp: 1; /*Clear ULP-coprocessor interrupt state*/ + uint32_t rtc_touch_done: 1; /*Clear touch done interrupt state*/ + uint32_t rtc_touch_active: 1; /*Clear touch active interrupt state*/ + uint32_t rtc_touch_inactive: 1; /*Clear touch inactive interrupt state*/ + uint32_t rtc_brown_out: 1; /*Clear brown out interrupt state*/ + uint32_t rtc_main_timer: 1; /*Clear RTC main timer interrupt state*/ + uint32_t rtc_saradc1: 1; /*Clear saradc1 interrupt state*/ + uint32_t rtc_tsens: 1; /*Clear tsens interrupt state*/ + uint32_t rtc_cocpu: 1; /*Clear riscV cocpu interrupt state*/ + uint32_t rtc_saradc2: 1; /*Clear saradc2 interrupt state*/ + uint32_t rtc_swd: 1; /*Clear super watch dog interrupt state*/ + uint32_t rtc_xtal32k_dead: 1; /*Clear RTC WDT interrupt state*/ + uint32_t rtc_cocpu_trap: 1; /*Clear cocpu trap interrupt state*/ + uint32_t reserved18: 14; }; uint32_t val; } int_clr; uint32_t store[4]; /**/ union { struct { - uint32_t reserved0: 30; - uint32_t ctr_lv: 1; /*0: power down XTAL at high level 1: power down XTAL at low level*/ - uint32_t ctr_en: 1; + uint32_t xtal32k_wdt_en: 1; /*xtal 32k watch dog enable*/ + uint32_t xtal32k_wdt_clk_fo: 1; /*xtal 32k watch dog clock force on*/ + uint32_t xtal32k_wdt_reset: 1; /*xtal 32k watch dog sw reset*/ + uint32_t xtal32k_ext_clk_fo: 1; /*xtal 32k external xtal clock force on*/ + uint32_t xtal32k_auto_backup: 1; /*xtal 32k switch to back up clock when xtal is dead*/ + uint32_t xtal32k_auto_restart: 1; /*xtal 32k restart xtal when xtal is dead*/ + uint32_t xtal32k_auto_return: 1; /*xtal 32k switch back xtal when xtal is restarted*/ + uint32_t xtal32k_xpd_force: 1; /*Xtal 32k xpd control by sw or fsm*/ + uint32_t enckinit_xtal_32k: 1; /*apply an internal clock to help xtal 32k to start*/ + uint32_t dbuf_xtal_32k: 1; /*0: single-end buffer 1: differential buffer*/ + uint32_t dgm_xtal_32k: 3; /*xtal_32k gm control*/ + uint32_t dres_xtal_32k: 3; /*DRES_XTAL_32K*/ + uint32_t xpd_xtal_32k: 1; /*XPD_XTAL_32K*/ + uint32_t dac_xtal_32k: 6; /*DAC_XTAL_32K*/ + uint32_t rtc_xtal32k_gpio_sel: 1; /*XTAL_32K sel. 0: external XTAL_32K 1: CLK from RTC pad X32P_C*/ + uint32_t reserved24: 6; + uint32_t ctr_lv: 1; /*0: power down XTAL at high level 1: power down XTAL at low level*/ + uint32_t ctr_en: 1; }; uint32_t val; } ext_xtl_conf; @@ -282,12 +312,10 @@ typedef volatile struct { } ext_wakeup_conf; union { struct { - uint32_t reserved0: 24; - uint32_t gpio_reject_en: 1; /*enable GPIO reject*/ - uint32_t sdio_reject_en: 1; /*enable SDIO reject*/ - uint32_t light_slp_reject_en: 1; /*enable reject for light sleep*/ - uint32_t deep_slp_reject_en: 1; /*enable reject for deep sleep*/ - uint32_t reject_cause: 4; + uint32_t reject_cause: 15; /*sleep reject cause*/ + uint32_t rtc_sleep_reject_ena:15; /*sleep reject enable*/ + uint32_t light_slp_reject_en: 1; /*enable reject for light sleep*/ + uint32_t deep_slp_reject_en: 1; /*enable reject for deep sleep*/ }; uint32_t val; } slp_reject_conf; @@ -331,12 +359,7 @@ typedef volatile struct { } clk_conf; union { struct { - uint32_t reserved0: 14; - uint32_t dbias_xtal_32k: 2; /*DBIAS_XTAL_32K*/ - uint32_t dres_xtal_32k: 2; /*DRES_XTAL_32K*/ - uint32_t xpd_xtal_32k: 1; /*XPD_XTAL_32K*/ - uint32_t dac_xtal_32k: 2; /*DAC_XTAL_32K*/ - uint32_t rtc_xtal32k_gpio_sel: 1; /*XTAL_32K sel. 0: external XTAL_32K 1: CLK from RTC pad X32P_C*/ + uint32_t reserved0: 22; uint32_t rtc_ana_clk_div_vld: 1; /*used to sync div bus. clear vld before set reg_rtc_ana_clk_div then set vld to actually switch the clk*/ uint32_t rtc_ana_clk_div: 8; uint32_t slow_clk_next_edge: 1; @@ -345,22 +368,30 @@ typedef volatile struct { } slow_clk_conf; union { struct { - uint32_t reserved0: 21; - uint32_t sdio_pd_en: 1; /*power down SDIO_REG in sleep. Only active when reg_sdio_force = 0*/ - uint32_t sdio_force: 1; /*1: use SW option to control SDIO_REG 0: use state machine*/ - uint32_t sdio_tieh: 1; /*SW option for SDIO_TIEH. Only active when reg_sdio_force = 1*/ - uint32_t reg1p8_ready: 1; /*read only register for REG1P8_READY*/ - uint32_t drefl_sdio: 2; /*SW option for DREFL_SDIO. Only active when reg_sdio_force = 1*/ - uint32_t drefm_sdio: 2; /*SW option for DREFM_SDIO. Only active when reg_sdio_force = 1*/ - uint32_t drefh_sdio: 2; /*SW option for DREFH_SDIO. Only active when reg_sdio_force = 1*/ - uint32_t xpd_sdio: 1; + uint32_t sdio_timer_target: 8; /*timer count to apply reg_sdio_dcap after sdio power on*/ + uint32_t reserved8: 1; + uint32_t sdio_dthdrv: 2; /*Tieh = 1 mode drive ability. Initially set to 0 to limit charge current set to 3 after several us.*/ + uint32_t sdio_dcap: 2; /*ability to prevent LDO from overshoot*/ + uint32_t sdio_initi: 2; /*add resistor from ldo output to ground. 0: no res 1: 6k 2: 4k 3: 2k*/ + uint32_t sdio_en_initi: 1; /*0 to set init[1:0]=0*/ + uint32_t sdio_dcurlim: 3; /*tune current limit threshold when tieh = 0. About 800mA/(8+d)*/ + uint32_t sdio_modecurlim: 1; /*select current limit mode*/ + uint32_t sdio_encurlim: 1; /*enable current limit*/ + uint32_t sdio_pd_en: 1; /*power down SDIO_REG in sleep. Only active when reg_sdio_force = 0*/ + uint32_t sdio_force: 1; /*1: use SW option to control SDIO_REG 0: use state machine*/ + uint32_t sdio_tieh: 1; /*SW option for SDIO_TIEH. Only active when reg_sdio_force = 1*/ + uint32_t reg1p8_ready: 1; /*read only register for REG1P8_READY*/ + uint32_t drefl_sdio: 2; /*SW option for DREFL_SDIO. Only active when reg_sdio_force = 1*/ + uint32_t drefm_sdio: 2; /*SW option for DREFM_SDIO. Only active when reg_sdio_force = 1*/ + uint32_t drefh_sdio: 2; /*SW option for DREFH_SDIO. Only active when reg_sdio_force = 1*/ + uint32_t xpd_sdio: 1; }; uint32_t val; } sdio_conf; union { struct { - uint32_t reserved0: 24; - uint32_t dbg_atten: 2; /*DBG_ATTEN*/ + uint32_t reserved0: 22; + uint32_t dbg_atten: 4; /*DBG_ATTEN*/ uint32_t enb_sck_xtal: 1; /*ENB_SCK_XTAL*/ uint32_t inc_heartbeat_refresh: 1; /*INC_HEARTBEAT_REFRESH*/ uint32_t dec_heartbeat_period: 1; /*DEC_HEARTBEAT_PERIOD*/ @@ -408,14 +439,8 @@ typedef volatile struct { uint32_t rtc_force_pd: 1; /*rtc_peri force power down*/ uint32_t rtc_force_pu: 1; /*rtc_peri force power up*/ uint32_t rtc_pd_en: 1; /*enable power down rtc_peri in sleep*/ - uint32_t rtc_pad_autohold: 1; /*read only register to indicate rtc pad auto-hold status*/ - uint32_t clr_rtc_pad_autohold: 1; /*wtite only register to clear rtc pad auto-hold*/ - uint32_t rtc_pad_autohold_en: 1; /*rtc pad enable auto-hold*/ - uint32_t rtc_pad_force_noiso: 1; /*rtc pad force no ISO*/ - uint32_t rtc_pad_force_iso: 1; /*rtc pad force ISO*/ - uint32_t rtc_pad_force_unhold: 1; /*rtc pad force un-hold*/ uint32_t rtc_pad_force_hold: 1; /*rtc pad force hold*/ - uint32_t reserved28: 4; + uint32_t reserved22: 10; }; uint32_t val; } rtc_pwc; @@ -487,15 +512,14 @@ typedef volatile struct { } dig_iso; union { struct { - uint32_t reserved0: 7; + uint32_t chip_reset_width: 8; /*chip reset siginal pulse width*/ + uint32_t chip_reset_en: 1; /*wdt reset whole chip enable*/ uint32_t pause_in_slp: 1; /*pause WDT in sleep*/ uint32_t appcpu_reset_en: 1; /*enable WDT reset APP CPU*/ uint32_t procpu_reset_en: 1; /*enable WDT reset PRO CPU*/ uint32_t flashboot_mod_en: 1; /*enable WDT in flash boot*/ uint32_t sys_reset_length: 3; /*system reset counter length*/ uint32_t cpu_reset_length: 3; /*CPU reset counter length*/ - uint32_t level_int_en: 1; /*N/A*/ - uint32_t edge_int_en: 1; /*N/A*/ uint32_t stg3: 3; /*1: interrupt stage en 2: CPU reset stage en 3: system reset stage en 4: RTC reset stage en*/ uint32_t stg2: 3; /*1: interrupt stage en 2: CPU reset stage en 3: system reset stage en 4: RTC reset stage en*/ uint32_t stg1: 3; /*1: interrupt stage en 2: CPU reset stage en 3: system reset stage en 4: RTC reset stage en*/ @@ -518,7 +542,22 @@ typedef volatile struct { uint32_t wdt_wprotect; /**/ union { struct { - uint32_t reserved0: 29; + uint32_t swd_reset_flag: 1; /*swd reset flag*/ + uint32_t swd_feed_int: 1; /*swd interrupt for feeding*/ + uint32_t reserved2: 16; + uint32_t swd_signal_width:10; /*adjust signal width send to swd*/ + uint32_t swd_rst_flag_clr: 1; /*reset swd reset flag*/ + uint32_t swd_feed: 1; /*Sw feed swd*/ + uint32_t swd_disable: 1; /*disabel SWD*/ + uint32_t swd_auto_feed_en: 1; /*automatically feed swd when int comes*/ + }; + uint32_t val; + } swd_conf; + uint32_t swd_wprotect; /*swd write protect*/ + union { + struct { + uint32_t reserved0: 28; + uint32_t ent_tsens: 1; /*ENT_TSENS*/ uint32_t ent_rtc: 1; /*ENT_RTC*/ uint32_t dtest_rtc: 2; }; @@ -547,14 +586,14 @@ typedef volatile struct { uint32_t xpd_wifi: 1; /*wifi wrap power down*/ uint32_t dig_iso: 1; /*digital wrap iso*/ uint32_t xpd_dig: 1; /*digital wrap power down*/ - uint32_t rtc_touch_start: 1; /*touch should start to work*/ + uint32_t rtc_touch_state_start: 1; /*touch should start to work*/ uint32_t rtc_touch_state_switch: 1; /*touch is about to working. Switch rtc main state*/ - uint32_t rtc_touch_slp: 1; /*touch is in sleep state*/ - uint32_t rtc_touch_done: 1; /*touch is done*/ - uint32_t rtc_cocpu_start: 1; /*ulp/cocpu should start to work*/ + uint32_t rtc_touch_state_slp: 1; /*touch is in sleep state*/ + uint32_t rtc_touch_state_done: 1; /*touch is done*/ + uint32_t rtc_cocpu_state_start: 1; /*ulp/cocpu should start to work*/ uint32_t rtc_cocpu_state_switch: 1; /*ulp/cocpu is about to working. Switch rtc main state*/ - uint32_t rtc_cocpu_slp: 1; /*ulp/cocpu is in sleep state*/ - uint32_t rtc_cocpu_done: 1; /*ulp/cocpu is done*/ + uint32_t rtc_cocpu_state_slp: 1; /*ulp/cocpu is in sleep state*/ + uint32_t rtc_cocpu_state_done: 1; /*ulp/cocpu is done*/ uint32_t rtc_main_state_xtal_iso: 1; /*no use any more*/ uint32_t rtc_main_state_pll_on: 1; /*rtc main state machine is in states that pll should be running*/ uint32_t rtc_rdy_for_wakeup: 1; /*rtc is ready to receive wake up trigger from wake up source*/ @@ -573,62 +612,216 @@ typedef volatile struct { uint32_t diag0; /**/ union { struct { - uint32_t adc1_hold_force: 1; - uint32_t adc2_hold_force: 1; - uint32_t pdac1_hold_force: 1; - uint32_t pdac2_hold_force: 1; - uint32_t sense1_hold_force: 1; - uint32_t sense2_hold_force: 1; - uint32_t sense3_hold_force: 1; - uint32_t sense4_hold_force: 1; - uint32_t touch_pad0_hold_force: 1; - uint32_t touch_pad1_hold_force: 1; - uint32_t touch_pad2_hold_force: 1; - uint32_t touch_pad3_hold_force: 1; - uint32_t touch_pad4_hold_force: 1; - uint32_t touch_pad5_hold_force: 1; - uint32_t touch_pad6_hold_force: 1; - uint32_t touch_pad7_hold_force: 1; - uint32_t x32p_hold_force: 1; - uint32_t x32n_hold_force: 1; - uint32_t reserved18: 14; + uint32_t touch_pad0_hold: 1; + uint32_t touch_pad1_hold: 1; + uint32_t touch_pad2_hold: 1; + uint32_t touch_pad3_hold: 1; + uint32_t touch_pad4_hold: 1; + uint32_t touch_pad5_hold: 1; + uint32_t touch_pad6_hold: 1; + uint32_t touch_pad7_hold: 1; + uint32_t touch_pad8_hold: 1; + uint32_t touch_pad9_hold: 1; + uint32_t touch_pad10_hold: 1; + uint32_t touch_pad11_hold: 1; + uint32_t touch_pad12_hold: 1; + uint32_t touch_pad13_hold: 1; + uint32_t touch_pad14_hold: 1; + uint32_t x32p_hold: 1; + uint32_t x32n_hold: 1; + uint32_t pdac1_hold: 1; + uint32_t pdac2_hold: 1; + uint32_t rtc_pad19_hold: 1; + uint32_t rtc_pad20_hold: 1; + uint32_t rtc_pad21_hold: 1; + uint32_t reserved22: 10; }; uint32_t val; - } hold_force; + } pad_hold; uint32_t dig_pad_hold; /**/ union { struct { - uint32_t sel: 18; /*Bitmap to select RTC pads for ext wakeup1*/ + uint32_t sel: 22; /*Bitmap to select RTC pads for ext wakeup1*/ uint32_t status_clr: 1; /*clear ext wakeup1 status*/ - uint32_t reserved19: 13; + uint32_t reserved23: 9; }; uint32_t val; } ext_wakeup1; union { struct { - uint32_t status: 18; /*ext wakeup1 status*/ - uint32_t reserved18: 14; + uint32_t status: 22; /*ext wakeup1 status*/ + uint32_t reserved22: 10; }; uint32_t val; } ext_wakeup1_status; union { struct { - uint32_t reserved0: 14; + uint32_t reserved0: 4; + uint32_t int_wait: 10; /*brown out interrupt wait cycles*/ uint32_t close_flash_ena: 1; /*enable close flash when brown out happens*/ uint32_t pd_rf_ena: 1; /*enable power down RF when brown out happens*/ uint32_t rst_wait: 10; /*brown out reset wait cycles*/ uint32_t rst_ena: 1; /*enable brown out reset*/ - uint32_t thres: 3; /*brown out threshold*/ + uint32_t reserved27: 2; + uint32_t cnt_clr: 1; /*clear brown out counter*/ uint32_t ena: 1; /*enable brown out*/ uint32_t det: 1; }; uint32_t val; } brown_out; - uint32_t reserved_3c; - uint32_t reserved_40; - uint32_t reserved_44; - uint32_t reserved_48; - uint32_t reserved_4c; + uint32_t time_low1; /*RTC timer low 32 bits*/ + union { + struct { + uint32_t rtc_timer_value1_high:16; /*RTC timer high 16 bits*/ + uint32_t reserved16: 16; + }; + uint32_t val; + } time_high1; + uint32_t xtal32k_clk_factor; /*xtal 32k watch dog backup clock factor*/ + union { + struct { + uint32_t xtal32k_return_wait: 4; /*cycles to wait to return noral xtal 32k*/ + uint32_t xtal32k_restart_wait:16; /*cycles to wait to repower on xtal 32k*/ + uint32_t xtal32k_wdt_timeout: 8; /*If no clock detected for this amount of time 32k is regarded as dead*/ + uint32_t xtal32k_stable_thres: 4; /*if restarted xtal32k period is smaller than this it is regarded as stable*/ + }; + uint32_t val; + } xtal32k_conf; + union { + struct { + uint32_t ulp_cp_pc_init: 11; /*ULP-coprocessor PC initial address*/ + uint32_t reserved11: 1; + uint32_t ulp_cp_timer_slp_cycle:16; /*sleep cycles for ULP-coprocessor timer*/ + uint32_t reserved28: 1; + uint32_t ulp_cp_gpio_wakeup_ena: 1; /*ULP-coprocessor wakeup by GPIO enable*/ + uint32_t ulp_cp_gpio_wakeup_clr: 1; /*ULP-coprocessor wakeup by GPIO state clear*/ + uint32_t ulp_cp_slp_timer_en: 1; /*ULP-coprocessor timer enable bit*/ + }; + uint32_t val; + } ulp_cp_timer; + union { + struct { + uint32_t ulp_cp_mem_addr_init: 11; + uint32_t ulp_cp_mem_addr_size: 11; + uint32_t ulp_cp_mem_offst_clr: 1; + uint32_t reserved23: 5; + uint32_t ulp_cp_clk_fo: 1; /*ulp coprocessor clk force on*/ + uint32_t ulp_cp_reset: 1; /*ulp coprocessor clk software reset*/ + uint32_t ulp_cp_force_start_top: 1; /*1: ULP-coprocessor is started by SW*/ + uint32_t ulp_cp_start_top: 1; /*Write 1 to start ULP-coprocessor*/ + }; + uint32_t val; + } ulp_cp_ctrl; + union { + struct { + uint32_t cocpu_clk_fo: 1; /*cocpu clk force on*/ + uint32_t cocpu_start_2_reset_dis: 6; /*time from start cocpu to pull down reset*/ + uint32_t cocpu_start_2_intr_en: 6; /*time from start cocpu to give start interrupt*/ + uint32_t cocpu_shut: 1; /*to shut cocpu*/ + uint32_t cocpu_shut_2_clk_dis: 6; /*time from shut cocpu to disable clk*/ + uint32_t cocpu_shut_reset_en: 1; /*to reset cocpu*/ + uint32_t cocpu_sel: 1; /*1: old ULP 0: new riscV*/ + uint32_t cocpu_done_force: 1; /*1: select riscv done 0: select ulp done*/ + uint32_t cocpu_done: 1; /*done signal used by riscv to control timer.*/ + uint32_t cocpu_sw_int_trigger: 1; /*trigger cocpu register interrupt*/ + uint32_t reserved25: 7; + }; + uint32_t val; + } cocpu_ctrl; + union { + struct { + uint32_t touch_sleep_cycles:16; /*sleep cycles for timer*/ + uint32_t touch_meas_num: 16; /*the meas length (in 8MHz)*/ + }; + uint32_t val; + } touch_ctrl1; + union { + struct { + uint32_t reserved0: 2; + uint32_t touch_drange: 2; /*TOUCH_DRANGE*/ + uint32_t touch_drefl: 2; /*TOUCH_DREFL*/ + uint32_t touch_drefh: 2; /*TOUCH_DREFH*/ + uint32_t touch_xpd_bias: 1; /*TOUCH_XPD_BIAS*/ + uint32_t touch_refc: 3; /*TOUCH pad0 reference cap*/ + uint32_t reserved12: 1; + uint32_t touch_slp_timer_en: 1; /*touch timer enable bit*/ + uint32_t touch_start_fsm_en: 1; /*1: TOUCH_START & TOUCH_XPD is controlled by touch fsm*/ + uint32_t touch_start_en: 1; /*1: start touch fsm*/ + uint32_t touch_start_force: 1; /*1: to start touch fsm by SW*/ + uint32_t touch_xpd_wait: 8; /*the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD*/ + uint32_t touch_slp_cyc_div: 2; /*when a touch pad is active sleep cycle could be divided by this number*/ + uint32_t reserved27: 2; + uint32_t touch_reset: 1; /*reset upgrade touch*/ + uint32_t touch_clk_fo: 1; /*touch clock force on*/ + uint32_t touch_clkgate_en: 1; /*touch clock enable*/ + }; + uint32_t val; + } touch_ctrl2; + union { + struct { + uint32_t touch_denoise_res: 2; /*De-noise resolution: 12/10/8/4 bit*/ + uint32_t touch_denoise_en: 1; /*touch pad0 will be used to de-noise*/ + uint32_t reserved3: 5; + uint32_t touch_inactive_connection: 1; /*inactive touch pads connect to 1: gnd 0: HighZ*/ + uint32_t touch_shield_pad_en: 1; /*touch pad14 will be used as shield*/ + uint32_t touch_scan_pad_map: 15; /*touch scan mode pad enable map*/ + uint32_t touch_bufdrv: 3; /*touch7 buffer driver strength*/ + uint32_t touch_out_ring: 4; /*select out ring pad*/ + }; + uint32_t val; + } touch_scan_ctrl; + union { + struct { + uint32_t touch_slp_th: 22; /*the threshold for sleep touch pad*/ + uint32_t reserved22: 4; + uint32_t touch_slp_approach_en: 1; /*sleep pad approach function enable*/ + uint32_t touch_slp_pad: 5; + }; + uint32_t val; + } touch_slp_thres; + union { + struct { + uint32_t reserved0: 23; + uint32_t touch_slp_channel_clr: 1; /*clear touch slp channel*/ + uint32_t touch_approach_meas_time: 8; /*approach pads total meas times*/ + }; + uint32_t val; + } touch_approach; + union { + struct { + uint32_t reserved0: 12; + uint32_t touch_jitter_step: 4; /*touch jitter step*/ + uint32_t touch_neg_noise_limit: 4; /*negative threshold counter limit*/ + uint32_t touch_neg_noise_thres: 2; + uint32_t touch_noise_thres: 2; + uint32_t touch_hysteresis: 2; + uint32_t touch_debounce: 3; /*debounce counter*/ + uint32_t touch_filter_mode: 2; /*0: IIR ? 1: IIR ? 2: IIR 1/8 3: Jitter*/ + uint32_t touch_filter_en: 1; /*touch filter enable*/ + }; + uint32_t val; + } touch_filter_ctrl; + union { + struct { + uint32_t usb_vrefh: 2; + uint32_t usb_vrefl: 2; + uint32_t usb_vref_override: 1; + uint32_t usb_pad_pull_override: 1; + uint32_t usb_dp_pullup: 1; + uint32_t usb_dp_pulldown: 1; + uint32_t usb_dm_pullup: 1; + uint32_t usb_dm_pulldown: 1; + uint32_t usb_pullup_value: 1; + uint32_t usb_pad_enable_override: 1; + uint32_t usb_pad_enable: 1; + uint32_t usb_txm: 1; + uint32_t usb_txp: 1; + uint32_t usb_tx_en: 1; + uint32_t usb_tx_en_override: 1; + uint32_t reserved17: 15; + }; + uint32_t val; + } usb_conf; union { struct { uint32_t date: 28; diff --git a/components/soc/esp32s2beta/include/soc/sens_reg.h b/components/soc/esp32s2beta/include/soc/sens_reg.h index a00c59c9a7..13c454ae08 100644 --- a/components/soc/esp32s2beta/include/soc/sens_reg.h +++ b/components/soc/esp32s2beta/include/soc/sens_reg.h @@ -1,9 +1,9 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// Copyright 2017-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 @@ -19,19 +19,19 @@ extern "C" { #endif #include "soc.h" -#define SENS_SAR_READ_CTRL_REG (DR_REG_SENS_BASE + 0x0000) +#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_DIG_FORCE : R/W ;bitpos:[27] ;default: 1'd0 ; */ -/*description: 1: SAR ADC1 controlled by DIG ADC1 CTRL 0: SAR ADC1 controlled by RTC ADC1 CTRL*/ -#define SENS_SAR1_DIG_FORCE (BIT(27)) -#define SENS_SAR1_DIG_FORCE_M (BIT(27)) -#define SENS_SAR1_DIG_FORCE_V 0x1 -#define SENS_SAR1_DIG_FORCE_S 27 /* SENS_SAR1_SAMPLE_NUM : R/W ;bitpos:[26:19] ;default: 8'd0 ; */ /*description: */ #define SENS_SAR1_SAMPLE_NUM 0x000000FF @@ -45,8 +45,7 @@ extern "C" { #define SENS_SAR1_CLK_GATED_V 0x1 #define SENS_SAR1_CLK_GATED_S 18 /* SENS_SAR1_SAMPLE_BIT : R/W ;bitpos:[17:16] ;default: 2'd3 ; */ -/*description: 00: for 9-bit width 01: for 10-bit width 10: for 11-bit width - 11: for 12-bit width*/ +/*description: 00: for 9-bit width*/ #define SENS_SAR1_SAMPLE_BIT 0x00000003 #define SENS_SAR1_SAMPLE_BIT_M ((SENS_SAR1_SAMPLE_BIT_V)<<(SENS_SAR1_SAMPLE_BIT_S)) #define SENS_SAR1_SAMPLE_BIT_V 0x3 @@ -64,7 +63,7 @@ extern "C" { #define SENS_SAR1_CLK_DIV_V 0xFF #define SENS_SAR1_CLK_DIV_S 0 -#define SENS_SAR_READ_STATUS1_REG (DR_REG_SENS_BASE + 0x0004) +#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 @@ -72,457 +71,65 @@ extern "C" { #define SENS_SAR1_READER_STATUS_V 0xFFFFFFFF #define SENS_SAR1_READER_STATUS_S 0 -#define SENS_SAR_MEAS_WAIT1_REG (DR_REG_SENS_BASE + 0x0008) -/* SENS_SAR_AMP_WAIT2 : R/W ;bitpos:[31:16] ;default: 16'd10 ; */ +#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_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 ; */ +#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_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_MEAS_WAIT2_REG (DR_REG_SENS_BASE + 0x000c) -/* SENS_SAR2_RSTB_WAIT : R/W ;bitpos:[27:20] ;default: 8'd2 ; */ +#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_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 20 -/* SENS_FORCE_XPD_SAR : R/W ;bitpos:[19:18] ;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 18 -/* reserved for driver to check */ -#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_FORCE_XPD_AMP : R/W ;bitpos:[17:16] ;default: 2'd0 ; */ +#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 16 -#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 -/* SENS_SAR_AMP_WAIT3 : R/W ;bitpos:[15:0] ;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 0 - -#define SENS_SAR_MEAS_CTRL_REG (DR_REG_SENS_BASE + 0x0010) -/* 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_SAR_RSTB_FSM : R/W ;bitpos:[23:20] ;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 20 -/* SENS_XPD_SAR_FSM : R/W ;bitpos:[19:16] ;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 16 -/* SENS_AMP_SHORT_REF_GND_FSM : R/W ;bitpos:[15:12] ;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 12 -/* SENS_AMP_SHORT_REF_FSM : R/W ;bitpos:[11:8] ;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 8 -/* SENS_AMP_RST_FB_FSM : R/W ;bitpos:[7:4] ;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 4 -/* SENS_XPD_SAR_AMP_FSM : R/W ;bitpos:[3:0] ;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 0 - -#define SENS_SAR_READ_STATUS2_REG (DR_REG_SENS_BASE + 0x0014) -/* 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_ULP_CP_SLEEP_CYC0_REG (DR_REG_SENS_BASE + 0x0018) -/* SENS_SLEEP_CYCLES_S0 : R/W ;bitpos:[31:0] ;default: 32'd200 ; */ -/*description: sleep cycles for ULP-coprocessor timer*/ -#define SENS_SLEEP_CYCLES_S0 0xFFFFFFFF -#define SENS_SLEEP_CYCLES_S0_M ((SENS_SLEEP_CYCLES_S0_V)<<(SENS_SLEEP_CYCLES_S0_S)) -#define SENS_SLEEP_CYCLES_S0_V 0xFFFFFFFF -#define SENS_SLEEP_CYCLES_S0_S 0 - -#define SENS_ULP_CP_SLEEP_CYC1_REG (DR_REG_SENS_BASE + 0x001c) -/* SENS_SLEEP_CYCLES_S1 : R/W ;bitpos:[31:0] ;default: 32'd100 ; */ -/*description: */ -#define SENS_SLEEP_CYCLES_S1 0xFFFFFFFF -#define SENS_SLEEP_CYCLES_S1_M ((SENS_SLEEP_CYCLES_S1_V)<<(SENS_SLEEP_CYCLES_S1_S)) -#define SENS_SLEEP_CYCLES_S1_V 0xFFFFFFFF -#define SENS_SLEEP_CYCLES_S1_S 0 - -#define SENS_ULP_CP_SLEEP_CYC2_REG (DR_REG_SENS_BASE + 0x0020) -/* SENS_SLEEP_CYCLES_S2 : R/W ;bitpos:[31:0] ;default: 32'd50 ; */ -/*description: */ -#define SENS_SLEEP_CYCLES_S2 0xFFFFFFFF -#define SENS_SLEEP_CYCLES_S2_M ((SENS_SLEEP_CYCLES_S2_V)<<(SENS_SLEEP_CYCLES_S2_S)) -#define SENS_SLEEP_CYCLES_S2_V 0xFFFFFFFF -#define SENS_SLEEP_CYCLES_S2_S 0 - -#define SENS_ULP_CP_SLEEP_CYC3_REG (DR_REG_SENS_BASE + 0x0024) -/* SENS_SLEEP_CYCLES_S3 : R/W ;bitpos:[31:0] ;default: 32'd40 ; */ -/*description: */ -#define SENS_SLEEP_CYCLES_S3 0xFFFFFFFF -#define SENS_SLEEP_CYCLES_S3_M ((SENS_SLEEP_CYCLES_S3_V)<<(SENS_SLEEP_CYCLES_S3_S)) -#define SENS_SLEEP_CYCLES_S3_V 0xFFFFFFFF -#define SENS_SLEEP_CYCLES_S3_S 0 - -#define SENS_ULP_CP_SLEEP_CYC4_REG (DR_REG_SENS_BASE + 0x0028) -/* SENS_SLEEP_CYCLES_S4 : R/W ;bitpos:[31:0] ;default: 32'd20 ; */ -/*description: */ -#define SENS_SLEEP_CYCLES_S4 0xFFFFFFFF -#define SENS_SLEEP_CYCLES_S4_M ((SENS_SLEEP_CYCLES_S4_V)<<(SENS_SLEEP_CYCLES_S4_S)) -#define SENS_SLEEP_CYCLES_S4_V 0xFFFFFFFF -#define SENS_SLEEP_CYCLES_S4_S 0 - -#define SENS_SAR_START_FORCE_REG (DR_REG_SENS_BASE + 0x002c) -/* SENS_SAR2_PWDET_EN : R/W ;bitpos:[24] ;default: 1'b0 ; */ -/*description: N/A*/ -#define SENS_SAR2_PWDET_EN (BIT(24)) -#define SENS_SAR2_PWDET_EN_M (BIT(24)) -#define SENS_SAR2_PWDET_EN_V 0x1 -#define SENS_SAR2_PWDET_EN_S 24 -/* SENS_SAR1_STOP : R/W ;bitpos:[23] ;default: 1'b0 ; */ +#define SENS_FORCE_XPD_AMP_S 24 +/* SENS_SAR1_STOP : R/W ;bitpos:[2] ;default: 1'b0 ; */ /*description: stop SAR ADC1 conversion*/ -#define SENS_SAR1_STOP (BIT(23)) -#define SENS_SAR1_STOP_M (BIT(23)) +#define SENS_SAR1_STOP (BIT(2)) +#define SENS_SAR1_STOP_M (BIT(2)) #define SENS_SAR1_STOP_V 0x1 -#define SENS_SAR1_STOP_S 23 -/* SENS_SAR2_STOP : R/W ;bitpos:[22] ;default: 1'b0 ; */ -/*description: stop SAR ADC2 conversion*/ -#define SENS_SAR2_STOP (BIT(22)) -#define SENS_SAR2_STOP_M (BIT(22)) -#define SENS_SAR2_STOP_V 0x1 -#define SENS_SAR2_STOP_S 22 -/* SENS_PC_INIT : R/W ;bitpos:[21:11] ;default: 11'b0 ; */ -/*description: initialized PC for ULP-coprocessor*/ -#define SENS_PC_INIT 0x000007FF -#define SENS_PC_INIT_M ((SENS_PC_INIT_V)<<(SENS_PC_INIT_S)) -#define SENS_PC_INIT_V 0x7FF -#define SENS_PC_INIT_S 11 -/* SENS_SARCLK_EN : R/W ;bitpos:[10] ;default: 1'b0 ; */ -/*description: */ -#define SENS_SARCLK_EN (BIT(10)) -#define SENS_SARCLK_EN_M (BIT(10)) -#define SENS_SARCLK_EN_V 0x1 -#define SENS_SARCLK_EN_S 10 -/* SENS_ULP_CP_START_TOP : R/W ;bitpos:[9] ;default: 1'b0 ; */ -/*description: Write 1 to start ULP-coprocessor only active when reg_ulp_cp_force_start_top - = 1*/ -#define SENS_ULP_CP_START_TOP (BIT(9)) -#define SENS_ULP_CP_START_TOP_M (BIT(9)) -#define SENS_ULP_CP_START_TOP_V 0x1 -#define SENS_ULP_CP_START_TOP_S 9 -/* SENS_ULP_CP_FORCE_START_TOP : R/W ;bitpos:[8] ;default: 1'b0 ; */ -/*description: 1: ULP-coprocessor is started by SW 0: ULP-coprocessor is started by timer*/ -#define SENS_ULP_CP_FORCE_START_TOP (BIT(8)) -#define SENS_ULP_CP_FORCE_START_TOP_M (BIT(8)) -#define SENS_ULP_CP_FORCE_START_TOP_V 0x1 -#define SENS_ULP_CP_FORCE_START_TOP_S 8 -/* SENS_SAR2_PWDET_CCT : R/W ;bitpos:[7:5] ;default: 3'b0 ; */ -/*description: SAR2_PWDET_CCT PA power detector capacitance tuning.*/ -#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 5 -/* SENS_SAR2_EN_TEST : R/W ;bitpos:[4] ;default: 1'b0 ; */ -/*description: SAR2_EN_TEST only active when reg_sar2_dig_force = 0*/ -#define SENS_SAR2_EN_TEST (BIT(4)) -#define SENS_SAR2_EN_TEST_M (BIT(4)) -#define SENS_SAR2_EN_TEST_V 0x1 -#define SENS_SAR2_EN_TEST_S 4 -/* SENS_SAR2_BIT_WIDTH : R/W ;bitpos:[3:2] ;default: 2'b11 ; */ -/*description: 00: 9 bit 01: 10 bits 10: 11bits 11: 12bits*/ -#define SENS_SAR2_BIT_WIDTH 0x00000003 -#define SENS_SAR2_BIT_WIDTH_M ((SENS_SAR2_BIT_WIDTH_V)<<(SENS_SAR2_BIT_WIDTH_S)) -#define SENS_SAR2_BIT_WIDTH_V 0x3 -#define SENS_SAR2_BIT_WIDTH_S 2 +#define SENS_SAR1_STOP_S 2 /* SENS_SAR1_BIT_WIDTH : R/W ;bitpos:[1:0] ;default: 2'b11 ; */ -/*description: 00: 9 bit 01: 10 bits 10: 11bits 11: 12bits*/ +/*description: 00: 9 bit*/ #define SENS_SAR1_BIT_WIDTH 0x00000003 #define SENS_SAR1_BIT_WIDTH_M ((SENS_SAR1_BIT_WIDTH_V)<<(SENS_SAR1_BIT_WIDTH_S)) #define SENS_SAR1_BIT_WIDTH_V 0x3 #define SENS_SAR1_BIT_WIDTH_S 0 -#define SENS_SAR_MEM_WR_CTRL_REG (DR_REG_SENS_BASE + 0x0030) -/* SENS_ULP_CP_CLK_FO : R/W ;bitpos:[23] ;default: 1'd0 ; */ -/*description: ulp coprocessor clk force on*/ -#define SENS_ULP_CP_CLK_FO (BIT(23)) -#define SENS_ULP_CP_CLK_FO_M (BIT(23)) -#define SENS_ULP_CP_CLK_FO_V 0x1 -#define SENS_ULP_CP_CLK_FO_S 23 -/* SENS_RTC_MEM_WR_OFFST_CLR : WO ;bitpos:[22] ;default: 1'd0 ; */ -/*description: */ -#define SENS_RTC_MEM_WR_OFFST_CLR (BIT(22)) -#define SENS_RTC_MEM_WR_OFFST_CLR_M (BIT(22)) -#define SENS_RTC_MEM_WR_OFFST_CLR_V 0x1 -#define SENS_RTC_MEM_WR_OFFST_CLR_S 22 -/* SENS_MEM_WR_ADDR_SIZE : R/W ;bitpos:[21:11] ;default: 11'd512 ; */ -/*description: */ -#define SENS_MEM_WR_ADDR_SIZE 0x000007FF -#define SENS_MEM_WR_ADDR_SIZE_M ((SENS_MEM_WR_ADDR_SIZE_V)<<(SENS_MEM_WR_ADDR_SIZE_S)) -#define SENS_MEM_WR_ADDR_SIZE_V 0x7FF -#define SENS_MEM_WR_ADDR_SIZE_S 11 -/* SENS_MEM_WR_ADDR_INIT : R/W ;bitpos:[10:0] ;default: 11'd512 ; */ -/*description: */ -#define SENS_MEM_WR_ADDR_INIT 0x000007FF -#define SENS_MEM_WR_ADDR_INIT_M ((SENS_MEM_WR_ADDR_INIT_V)<<(SENS_MEM_WR_ADDR_INIT_S)) -#define SENS_MEM_WR_ADDR_INIT_V 0x7FF -#define SENS_MEM_WR_ADDR_INIT_S 0 - -#define SENS_SAR_ATTEN1_REG (DR_REG_SENS_BASE + 0x0034) -/* SENS_SAR1_ATTEN : R/W ;bitpos:[31:0] ;default: 32'hffffffff ; */ -/*description: 2-bit attenuation for each pad 11:1dB 10:6dB 01:3dB 00:0dB*/ -#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_SAR1_ATTEN_VAL_MASK 0x3 -#define SENS_SAR2_ATTEN_VAL_MASK 0x3 - -#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 11:1dB 10:6dB 01:3dB 00:0dB*/ -#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_SLAVE_ADDR1_REG (DR_REG_SENS_BASE + 0x003c) -/* SENS_SARADC_MEAS_STATUS : RO ;bitpos:[29:22] ;default: 8'h0 ; */ -/*description: */ -#define SENS_SARADC_MEAS_STATUS 0x000000FF -#define SENS_SARADC_MEAS_STATUS_M ((SENS_SARADC_MEAS_STATUS_V)<<(SENS_SARADC_MEAS_STATUS_S)) -#define SENS_SARADC_MEAS_STATUS_V 0xFF -#define SENS_SARADC_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 + 0x0040) -/* 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 + 0x0044) -/* SENS_TSENS_RDY_OUT : RO ;bitpos:[30] ;default: 1'h0 ; */ -/*description: indicate temperature sensor out ready*/ -#define SENS_TSENS_RDY_OUT (BIT(30)) -#define SENS_TSENS_RDY_OUT_M (BIT(30)) -#define SENS_TSENS_RDY_OUT_V 0x1 -#define SENS_TSENS_RDY_OUT_S 30 -/* SENS_TSENS_OUT : RO ;bitpos:[29:22] ;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 22 -/* 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 + 0x0048) -/* SENS_I2C_DONE : RO ;bitpos:[30] ;default: 1'h0 ; */ -/*description: indicate I2C done*/ -#define SENS_I2C_DONE (BIT(30)) -#define SENS_I2C_DONE_M (BIT(30)) -#define SENS_I2C_DONE_V 0x1 -#define SENS_I2C_DONE_S 30 -/* SENS_I2C_RDATA : RO ;bitpos:[29:22] ;default: 8'h0 ; */ -/*description: I2C read data*/ -#define SENS_I2C_RDATA 0x000000FF -#define SENS_I2C_RDATA_M ((SENS_I2C_RDATA_V)<<(SENS_I2C_RDATA_S)) -#define SENS_I2C_RDATA_V 0xFF -#define SENS_I2C_RDATA_S 22 -/* 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 + 0x004c) -/* SENS_TSENS_FORCE : R/W ;bitpos:[31] ;default: 1'b0 ; */ -/*description: 1: select saradc_reg 0: select efuse*/ -#define SENS_TSENS_FORCE (BIT(31)) -#define SENS_TSENS_FORCE_M (BIT(31)) -#define SENS_TSENS_FORCE_V 0x1 -#define SENS_TSENS_FORCE_S 31 -/* SENS_TSENS_DOS : R/W ;bitpos:[30:27] ;default: 4'd7 ; */ -/*description: Temperature sensor calibration bits*/ -#define SENS_TSENS_DOS 0x0000000F -#define SENS_TSENS_DOS_M ((SENS_TSENS_DOS_V)<<(SENS_TSENS_DOS_S)) -#define SENS_TSENS_DOS_V 0xF -#define SENS_TSENS_DOS_S 27 -/* SENS_TSENS_DUMP_OUT : R/W ;bitpos:[26] ;default: 1'b0 ; */ -/*description: temperature sensor dump out only active when reg_tsens_power_up_force = 1*/ -#define SENS_TSENS_DUMP_OUT (BIT(26)) -#define SENS_TSENS_DUMP_OUT_M (BIT(26)) -#define SENS_TSENS_DUMP_OUT_V 0x1 -#define SENS_TSENS_DUMP_OUT_S 26 -/* SENS_TSENS_POWER_UP_FORCE : R/W ;bitpos:[25] ;default: 1'b0 ; */ -/*description: 1: dump out & power up controlled by SW 0: by FSM*/ -#define SENS_TSENS_POWER_UP_FORCE (BIT(25)) -#define SENS_TSENS_POWER_UP_FORCE_M (BIT(25)) -#define SENS_TSENS_POWER_UP_FORCE_V 0x1 -#define SENS_TSENS_POWER_UP_FORCE_S 25 -/* SENS_TSENS_POWER_UP : R/W ;bitpos:[24] ;default: 1'b0 ; */ -/*description: temperature sensor power up*/ -#define SENS_TSENS_POWER_UP (BIT(24)) -#define SENS_TSENS_POWER_UP_M (BIT(24)) -#define SENS_TSENS_POWER_UP_V 0x1 -#define SENS_TSENS_POWER_UP_S 24 -/* SENS_TSENS_CLK_DIV : R/W ;bitpos:[23:16] ;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 16 -/* SENS_TSENS_IN_INV : R/W ;bitpos:[15] ;default: 1'b0 ; */ -/*description: invert temperature sensor data*/ -#define SENS_TSENS_IN_INV (BIT(15)) -#define SENS_TSENS_IN_INV_M (BIT(15)) -#define SENS_TSENS_IN_INV_V 0x1 -#define SENS_TSENS_IN_INV_S 15 -/* SENS_TSENS_CLK_GATED : R/W ;bitpos:[14] ;default: 1'b1 ; */ -/*description: */ -#define SENS_TSENS_CLK_GATED (BIT(14)) -#define SENS_TSENS_CLK_GATED_M (BIT(14)) -#define SENS_TSENS_CLK_GATED_V 0x1 -#define SENS_TSENS_CLK_GATED_S 14 -/* SENS_TSENS_CLK_INV : R/W ;bitpos:[13] ;default: 1'b1 ; */ -/*description: */ -#define SENS_TSENS_CLK_INV (BIT(13)) -#define SENS_TSENS_CLK_INV_M (BIT(13)) -#define SENS_TSENS_CLK_INV_V 0x1 -#define SENS_TSENS_CLK_INV_S 13 -/* SENS_TSENS_XPD_FORCE : R/W ;bitpos:[12] ;default: 1'b0 ; */ -/*description: */ -#define SENS_TSENS_XPD_FORCE (BIT(12)) -#define SENS_TSENS_XPD_FORCE_M (BIT(12)) -#define SENS_TSENS_XPD_FORCE_V 0x1 -#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 + 0x0050) -/* SENS_SAR_I2C_START_FORCE : R/W ;bitpos:[29] ;default: 1'b0 ; */ -/*description: 1: I2C started by SW 0: I2C started by FSM*/ -#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 only active when reg_sar_i2c_start_force = 1*/ -#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 only active when reg_sar_i2c_start_force = 1*/ -#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_MEAS_START1_REG (DR_REG_SENS_BASE + 0x0054) +#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 0: SAR ADC1 - pad enable bitmap is controlled by ULP-coprocessor*/ +/*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 only active when reg_sar1_en_pad_force = 1*/ +/*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 0: SAR ADC1 - controller is started by ULP-coprocessor*/ +/*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 only active when - reg_meas1_start_force = 1*/ +/*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 @@ -540,283 +147,143 @@ extern "C" { #define SENS_MEAS1_DATA_SAR_V 0xFFFF #define SENS_MEAS1_DATA_SAR_S 0 -#define SENS_SAR_TOUCH_CTRL1_REG (DR_REG_SENS_BASE + 0x0058) -/* SENS_HALL_PHASE_FORCE : R/W ;bitpos:[27] ;default: 1'b0 ; */ -/*description: 1: HALL PHASE is controlled by SW 0: HALL PHASE is controlled - by FSM in ULP-coprocessor*/ -#define SENS_HALL_PHASE_FORCE (BIT(27)) -#define SENS_HALL_PHASE_FORCE_M (BIT(27)) -#define SENS_HALL_PHASE_FORCE_V 0x1 -#define SENS_HALL_PHASE_FORCE_S 27 -/* SENS_XPD_HALL_FORCE : R/W ;bitpos:[26] ;default: 1'b0 ; */ -/*description: 1: XPD HALL is controlled by SW. 0: XPD HALL is controlled by - FSM in ULP-coprocessor*/ -#define SENS_XPD_HALL_FORCE (BIT(26)) -#define SENS_XPD_HALL_FORCE_M (BIT(26)) -#define SENS_XPD_HALL_FORCE_V 0x1 -#define SENS_XPD_HALL_FORCE_S 26 -/* SENS_TOUCH_OUT_1EN : R/W ;bitpos:[25] ;default: 1'b1 ; */ -/*description: 1: wakeup interrupt is generated if SET1 is “touched” 0: - wakeup interrupt is generated only if SET1 & SET2 is both “touched”*/ -#define SENS_TOUCH_OUT_1EN (BIT(25)) -#define SENS_TOUCH_OUT_1EN_M (BIT(25)) -#define SENS_TOUCH_OUT_1EN_V 0x1 -#define SENS_TOUCH_OUT_1EN_S 25 -/* SENS_TOUCH_OUT_SEL : R/W ;bitpos:[24] ;default: 1'b0 ; */ -/*description: 1: when the counter is greater then the threshold the touch - pad is considered as “touched” 0: when the counter is less than the threshold the touch pad is considered as “touched”*/ -#define SENS_TOUCH_OUT_SEL (BIT(24)) -#define SENS_TOUCH_OUT_SEL_M (BIT(24)) -#define SENS_TOUCH_OUT_SEL_V 0x1 -#define SENS_TOUCH_OUT_SEL_S 24 -/* SENS_TOUCH_XPD_WAIT : R/W ;bitpos:[23:16] ;default: 8'h4 ; */ -/*description: the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD*/ -#define SENS_TOUCH_XPD_WAIT 0x000000FF -#define SENS_TOUCH_XPD_WAIT_M ((SENS_TOUCH_XPD_WAIT_V)<<(SENS_TOUCH_XPD_WAIT_S)) -#define SENS_TOUCH_XPD_WAIT_V 0xFF -#define SENS_TOUCH_XPD_WAIT_S 16 -/* SENS_TOUCH_MEAS_DELAY : R/W ;bitpos:[15:0] ;default: 16'h1000 ; */ -/*description: the meas length (in 8MHz)*/ -#define SENS_TOUCH_MEAS_DELAY 0x0000FFFF -#define SENS_TOUCH_MEAS_DELAY_M ((SENS_TOUCH_MEAS_DELAY_V)<<(SENS_TOUCH_MEAS_DELAY_S)) -#define SENS_TOUCH_MEAS_DELAY_V 0xFFFF -#define SENS_TOUCH_MEAS_DELAY_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_TOUCH_THRES1_REG (DR_REG_SENS_BASE + 0x005c) -/* SENS_TOUCH_OUT_TH0 : R/W ;bitpos:[31:16] ;default: 16'h0 ; */ -/*description: the threshold for touch pad 0*/ -#define SENS_TOUCH_OUT_TH0 0x0000FFFF -#define SENS_TOUCH_OUT_TH0_M ((SENS_TOUCH_OUT_TH0_V)<<(SENS_TOUCH_OUT_TH0_S)) -#define SENS_TOUCH_OUT_TH0_V 0xFFFF -#define SENS_TOUCH_OUT_TH0_S 16 -/* SENS_TOUCH_OUT_TH1 : R/W ;bitpos:[15:0] ;default: 16'h0 ; */ -/*description: the threshold for touch pad 1*/ -#define SENS_TOUCH_OUT_TH1 0x0000FFFF -#define SENS_TOUCH_OUT_TH1_M ((SENS_TOUCH_OUT_TH1_V)<<(SENS_TOUCH_OUT_TH1_S)) -#define SENS_TOUCH_OUT_TH1_V 0xFFFF -#define SENS_TOUCH_OUT_TH1_S 0 +#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_TOUCH_THRES2_REG (DR_REG_SENS_BASE + 0x0060) -/* SENS_TOUCH_OUT_TH2 : R/W ;bitpos:[31:16] ;default: 16'h0 ; */ -/*description: the threshold for touch pad 2*/ -#define SENS_TOUCH_OUT_TH2 0x0000FFFF -#define SENS_TOUCH_OUT_TH2_M ((SENS_TOUCH_OUT_TH2_V)<<(SENS_TOUCH_OUT_TH2_S)) -#define SENS_TOUCH_OUT_TH2_V 0xFFFF -#define SENS_TOUCH_OUT_TH2_S 16 -/* SENS_TOUCH_OUT_TH3 : R/W ;bitpos:[15:0] ;default: 16'h0 ; */ -/*description: the threshold for touch pad 3*/ -#define SENS_TOUCH_OUT_TH3 0x0000FFFF -#define SENS_TOUCH_OUT_TH3_M ((SENS_TOUCH_OUT_TH3_V)<<(SENS_TOUCH_OUT_TH3_S)) -#define SENS_TOUCH_OUT_TH3_V 0xFFFF -#define SENS_TOUCH_OUT_TH3_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_TOUCH_THRES3_REG (DR_REG_SENS_BASE + 0x0064) -/* SENS_TOUCH_OUT_TH4 : R/W ;bitpos:[31:16] ;default: 16'h0 ; */ -/*description: the threshold for touch pad 4*/ -#define SENS_TOUCH_OUT_TH4 0x0000FFFF -#define SENS_TOUCH_OUT_TH4_M ((SENS_TOUCH_OUT_TH4_V)<<(SENS_TOUCH_OUT_TH4_S)) -#define SENS_TOUCH_OUT_TH4_V 0xFFFF -#define SENS_TOUCH_OUT_TH4_S 16 -/* SENS_TOUCH_OUT_TH5 : R/W ;bitpos:[15:0] ;default: 16'h0 ; */ -/*description: the threshold for touch pad 5*/ -#define SENS_TOUCH_OUT_TH5 0x0000FFFF -#define SENS_TOUCH_OUT_TH5_M ((SENS_TOUCH_OUT_TH5_V)<<(SENS_TOUCH_OUT_TH5_S)) -#define SENS_TOUCH_OUT_TH5_V 0xFFFF -#define SENS_TOUCH_OUT_TH5_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_TOUCH_THRES4_REG (DR_REG_SENS_BASE + 0x0068) -/* SENS_TOUCH_OUT_TH6 : R/W ;bitpos:[31:16] ;default: 16'h0 ; */ -/*description: the threshold for touch pad 6*/ -#define SENS_TOUCH_OUT_TH6 0x0000FFFF -#define SENS_TOUCH_OUT_TH6_M ((SENS_TOUCH_OUT_TH6_V)<<(SENS_TOUCH_OUT_TH6_S)) -#define SENS_TOUCH_OUT_TH6_V 0xFFFF -#define SENS_TOUCH_OUT_TH6_S 16 -/* SENS_TOUCH_OUT_TH7 : R/W ;bitpos:[15:0] ;default: 16'h0 ; */ -/*description: the threshold for touch pad 7*/ -#define SENS_TOUCH_OUT_TH7 0x0000FFFF -#define SENS_TOUCH_OUT_TH7_M ((SENS_TOUCH_OUT_TH7_V)<<(SENS_TOUCH_OUT_TH7_S)) -#define SENS_TOUCH_OUT_TH7_V 0xFFFF -#define SENS_TOUCH_OUT_TH7_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_TOUCH_THRES5_REG (DR_REG_SENS_BASE + 0x006c) -/* SENS_TOUCH_OUT_TH8 : R/W ;bitpos:[31:16] ;default: 16'h0 ; */ -/*description: the threshold for touch pad 8*/ -#define SENS_TOUCH_OUT_TH8 0x0000FFFF -#define SENS_TOUCH_OUT_TH8_M ((SENS_TOUCH_OUT_TH8_V)<<(SENS_TOUCH_OUT_TH8_S)) -#define SENS_TOUCH_OUT_TH8_V 0xFFFF -#define SENS_TOUCH_OUT_TH8_S 16 -/* SENS_TOUCH_OUT_TH9 : R/W ;bitpos:[15:0] ;default: 16'h0 ; */ -/*description: the threshold for touch pad 9*/ -#define SENS_TOUCH_OUT_TH9 0x0000FFFF -#define SENS_TOUCH_OUT_TH9_M ((SENS_TOUCH_OUT_TH9_V)<<(SENS_TOUCH_OUT_TH9_S)) -#define SENS_TOUCH_OUT_TH9_V 0xFFFF -#define SENS_TOUCH_OUT_TH9_S 0 - -#define SENS_SAR_TOUCH_OUT1_REG (DR_REG_SENS_BASE + 0x0070) -/* SENS_TOUCH_MEAS_OUT0 : RO ;bitpos:[31:16] ;default: 16'h0 ; */ -/*description: the counter for touch pad 0*/ -#define SENS_TOUCH_MEAS_OUT0 0x0000FFFF -#define SENS_TOUCH_MEAS_OUT0_M ((SENS_TOUCH_MEAS_OUT0_V)<<(SENS_TOUCH_MEAS_OUT0_S)) -#define SENS_TOUCH_MEAS_OUT0_V 0xFFFF -#define SENS_TOUCH_MEAS_OUT0_S 16 -/* SENS_TOUCH_MEAS_OUT1 : RO ;bitpos:[15:0] ;default: 16'h0 ; */ -/*description: the counter for touch pad 1*/ -#define SENS_TOUCH_MEAS_OUT1 0x0000FFFF -#define SENS_TOUCH_MEAS_OUT1_M ((SENS_TOUCH_MEAS_OUT1_V)<<(SENS_TOUCH_MEAS_OUT1_S)) -#define SENS_TOUCH_MEAS_OUT1_V 0xFFFF -#define SENS_TOUCH_MEAS_OUT1_S 0 - -#define SENS_SAR_TOUCH_OUT2_REG (DR_REG_SENS_BASE + 0x0074) -/* SENS_TOUCH_MEAS_OUT2 : RO ;bitpos:[31:16] ;default: 16'h0 ; */ -/*description: the counter for touch pad 2*/ -#define SENS_TOUCH_MEAS_OUT2 0x0000FFFF -#define SENS_TOUCH_MEAS_OUT2_M ((SENS_TOUCH_MEAS_OUT2_V)<<(SENS_TOUCH_MEAS_OUT2_S)) -#define SENS_TOUCH_MEAS_OUT2_V 0xFFFF -#define SENS_TOUCH_MEAS_OUT2_S 16 -/* SENS_TOUCH_MEAS_OUT3 : RO ;bitpos:[15:0] ;default: 16'h0 ; */ -/*description: the counter for touch pad 3*/ -#define SENS_TOUCH_MEAS_OUT3 0x0000FFFF -#define SENS_TOUCH_MEAS_OUT3_M ((SENS_TOUCH_MEAS_OUT3_V)<<(SENS_TOUCH_MEAS_OUT3_S)) -#define SENS_TOUCH_MEAS_OUT3_V 0xFFFF -#define SENS_TOUCH_MEAS_OUT3_S 0 - -#define SENS_SAR_TOUCH_OUT3_REG (DR_REG_SENS_BASE + 0x0078) -/* SENS_TOUCH_MEAS_OUT4 : RO ;bitpos:[31:16] ;default: 16'h0 ; */ -/*description: the counter for touch pad 4*/ -#define SENS_TOUCH_MEAS_OUT4 0x0000FFFF -#define SENS_TOUCH_MEAS_OUT4_M ((SENS_TOUCH_MEAS_OUT4_V)<<(SENS_TOUCH_MEAS_OUT4_S)) -#define SENS_TOUCH_MEAS_OUT4_V 0xFFFF -#define SENS_TOUCH_MEAS_OUT4_S 16 -/* SENS_TOUCH_MEAS_OUT5 : RO ;bitpos:[15:0] ;default: 16'h0 ; */ -/*description: the counter for touch pad 5*/ -#define SENS_TOUCH_MEAS_OUT5 0x0000FFFF -#define SENS_TOUCH_MEAS_OUT5_M ((SENS_TOUCH_MEAS_OUT5_V)<<(SENS_TOUCH_MEAS_OUT5_S)) -#define SENS_TOUCH_MEAS_OUT5_V 0xFFFF -#define SENS_TOUCH_MEAS_OUT5_S 0 - -#define SENS_SAR_TOUCH_OUT4_REG (DR_REG_SENS_BASE + 0x007c) -/* SENS_TOUCH_MEAS_OUT6 : RO ;bitpos:[31:16] ;default: 16'h0 ; */ -/*description: the counter for touch pad 6*/ -#define SENS_TOUCH_MEAS_OUT6 0x0000FFFF -#define SENS_TOUCH_MEAS_OUT6_M ((SENS_TOUCH_MEAS_OUT6_V)<<(SENS_TOUCH_MEAS_OUT6_S)) -#define SENS_TOUCH_MEAS_OUT6_V 0xFFFF -#define SENS_TOUCH_MEAS_OUT6_S 16 -/* SENS_TOUCH_MEAS_OUT7 : RO ;bitpos:[15:0] ;default: 16'h0 ; */ -/*description: the counter for touch pad 7*/ -#define SENS_TOUCH_MEAS_OUT7 0x0000FFFF -#define SENS_TOUCH_MEAS_OUT7_M ((SENS_TOUCH_MEAS_OUT7_V)<<(SENS_TOUCH_MEAS_OUT7_S)) -#define SENS_TOUCH_MEAS_OUT7_V 0xFFFF -#define SENS_TOUCH_MEAS_OUT7_S 0 - -#define SENS_SAR_TOUCH_OUT5_REG (DR_REG_SENS_BASE + 0x0080) -/* SENS_TOUCH_MEAS_OUT8 : RO ;bitpos:[31:16] ;default: 16'h0 ; */ -/*description: the counter for touch pad 8*/ -#define SENS_TOUCH_MEAS_OUT8 0x0000FFFF -#define SENS_TOUCH_MEAS_OUT8_M ((SENS_TOUCH_MEAS_OUT8_V)<<(SENS_TOUCH_MEAS_OUT8_S)) -#define SENS_TOUCH_MEAS_OUT8_V 0xFFFF -#define SENS_TOUCH_MEAS_OUT8_S 16 -/* SENS_TOUCH_MEAS_OUT9 : RO ;bitpos:[15:0] ;default: 16'h0 ; */ -/*description: the counter for touch pad 9*/ -#define SENS_TOUCH_MEAS_OUT9 0x0000FFFF -#define SENS_TOUCH_MEAS_OUT9_M ((SENS_TOUCH_MEAS_OUT9_V)<<(SENS_TOUCH_MEAS_OUT9_S)) -#define SENS_TOUCH_MEAS_OUT9_V 0xFFFF -#define SENS_TOUCH_MEAS_OUT9_S 0 - -#define SENS_SAR_TOUCH_CTRL2_REG (DR_REG_SENS_BASE + 0x0084) -/* SENS_TOUCH_MEAS_EN_CLR : WO ;bitpos:[30] ;default: 1'h0 ; */ -/*description: to clear reg_touch_meas_en*/ -#define SENS_TOUCH_MEAS_EN_CLR (BIT(30)) -#define SENS_TOUCH_MEAS_EN_CLR_M (BIT(30)) -#define SENS_TOUCH_MEAS_EN_CLR_V 0x1 -#define SENS_TOUCH_MEAS_EN_CLR_S 30 -/* SENS_TOUCH_SLEEP_CYCLES : R/W ;bitpos:[29:14] ;default: 16'h100 ; */ -/*description: sleep cycles for timer*/ -#define SENS_TOUCH_SLEEP_CYCLES 0x0000FFFF -#define SENS_TOUCH_SLEEP_CYCLES_M ((SENS_TOUCH_SLEEP_CYCLES_V)<<(SENS_TOUCH_SLEEP_CYCLES_S)) -#define SENS_TOUCH_SLEEP_CYCLES_V 0xFFFF -#define SENS_TOUCH_SLEEP_CYCLES_S 14 -/* SENS_TOUCH_START_FORCE : R/W ;bitpos:[13] ;default: 1'h0 ; */ -/*description: 1: to start touch fsm by SW 0: to start touch fsm by timer*/ -#define SENS_TOUCH_START_FORCE (BIT(13)) -#define SENS_TOUCH_START_FORCE_M (BIT(13)) -#define SENS_TOUCH_START_FORCE_V 0x1 -#define SENS_TOUCH_START_FORCE_S 13 -/* SENS_TOUCH_START_EN : R/W ;bitpos:[12] ;default: 1'h0 ; */ -/*description: 1: start touch fsm valid when reg_touch_start_force is set*/ -#define SENS_TOUCH_START_EN (BIT(12)) -#define SENS_TOUCH_START_EN_M (BIT(12)) -#define SENS_TOUCH_START_EN_V 0x1 -#define SENS_TOUCH_START_EN_S 12 -/* SENS_TOUCH_START_FSM_EN : R/W ;bitpos:[11] ;default: 1'h1 ; */ -/*description: 1: TOUCH_START & TOUCH_XPD is controlled by touch fsm 0: TOUCH_START - & TOUCH_XPD is controlled by registers*/ -#define SENS_TOUCH_START_FSM_EN (BIT(11)) -#define SENS_TOUCH_START_FSM_EN_M (BIT(11)) -#define SENS_TOUCH_START_FSM_EN_V 0x1 -#define SENS_TOUCH_START_FSM_EN_S 11 -/* SENS_TOUCH_MEAS_DONE : RO ;bitpos:[10] ;default: 1'h0 ; */ -/*description: fsm set 1 to indicate touch touch meas is done*/ -#define SENS_TOUCH_MEAS_DONE (BIT(10)) -#define SENS_TOUCH_MEAS_DONE_M (BIT(10)) -#define SENS_TOUCH_MEAS_DONE_V 0x1 -#define SENS_TOUCH_MEAS_DONE_S 10 -/* SENS_TOUCH_MEAS_EN : RO ;bitpos:[9:0] ;default: 10'h0 ; */ -/*description: 10-bit register to indicate which pads are “touched”*/ -#define SENS_TOUCH_MEAS_EN 0x000003FF -#define SENS_TOUCH_MEAS_EN_M ((SENS_TOUCH_MEAS_EN_V)<<(SENS_TOUCH_MEAS_EN_S)) -#define SENS_TOUCH_MEAS_EN_V 0x3FF -#define SENS_TOUCH_MEAS_EN_S 0 - -#define SENS_SAR_TOUCH_ENABLE_REG (DR_REG_SENS_BASE + 0x008c) -/* SENS_TOUCH_PAD_OUTEN1 : R/W ;bitpos:[29:20] ;default: 10'h3ff ; */ -/*description: Bitmap defining SET1 for generating wakeup interrupt. SET1 is - “touched” only if at least one of touch pad in SET1 is “touched”.*/ -#define SENS_TOUCH_PAD_OUTEN1 0x000003FF -#define SENS_TOUCH_PAD_OUTEN1_M ((SENS_TOUCH_PAD_OUTEN1_V)<<(SENS_TOUCH_PAD_OUTEN1_S)) -#define SENS_TOUCH_PAD_OUTEN1_V 0x3FF -#define SENS_TOUCH_PAD_OUTEN1_S 20 -/* SENS_TOUCH_PAD_OUTEN2 : R/W ;bitpos:[19:10] ;default: 10'h3ff ; */ -/*description: Bitmap defining SET2 for generating wakeup interrupt. SET2 is - “touched” only if at least one of touch pad in SET2 is “touched”.*/ -#define SENS_TOUCH_PAD_OUTEN2 0x000003FF -#define SENS_TOUCH_PAD_OUTEN2_M ((SENS_TOUCH_PAD_OUTEN2_V)<<(SENS_TOUCH_PAD_OUTEN2_S)) -#define SENS_TOUCH_PAD_OUTEN2_V 0x3FF -#define SENS_TOUCH_PAD_OUTEN2_S 10 -/* SENS_TOUCH_PAD_WORKEN : R/W ;bitpos:[9:0] ;default: 10'h3ff ; */ -/*description: Bitmap defining the working set during the measurement.*/ -#define SENS_TOUCH_PAD_WORKEN 0x000003FF -#define SENS_TOUCH_PAD_WORKEN_M ((SENS_TOUCH_PAD_WORKEN_V)<<(SENS_TOUCH_PAD_WORKEN_S)) -#define SENS_TOUCH_PAD_WORKEN_V 0x3FF -#define SENS_TOUCH_PAD_WORKEN_S 0 - -#define SENS_SAR_TOUCH_CTRL3_REG (DR_REG_SENS_BASE + 0x0090) -/* SENS_TOUCH_MEAS_RAW : RO ;bitpos:[9:0] ;default: 10'h0 ; */ -/*description: touch sensor raw result*/ -#define SENS_TOUCH_MEAS_RAW 0x000003FF -#define SENS_TOUCH_MEAS_RAW_M ((SENS_TOUCH_MEAS_RAW_V)<<(SENS_TOUCH_MEAS_RAW_S)) -#define SENS_TOUCH_MEAS_RAW_V 0x3FF -#define SENS_TOUCH_MEAS_RAW_S 0 - -#define SENS_SAR_READ_CTRL2_REG (DR_REG_SENS_BASE + 0x0094) +#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_DIG_FORCE : R/W ;bitpos:[28] ;default: 1'b0 ; */ -/*description: 1: SAR ADC2 controlled by DIG ADC2 CTRL or PWDET CTRL 0: SAR - ADC2 controlled by RTC ADC2 CTRL*/ -#define SENS_SAR2_DIG_FORCE (BIT(28)) -#define SENS_SAR2_DIG_FORCE_M (BIT(28)) -#define SENS_SAR2_DIG_FORCE_V 0x1 -#define SENS_SAR2_DIG_FORCE_S 28 -/* SENS_SAR2_PWDET_FORCE : R/W ;bitpos:[27] ;default: 1'b0 ; */ -/*description: */ -#define SENS_SAR2_PWDET_FORCE (BIT(27)) -#define SENS_SAR2_PWDET_FORCE_M (BIT(27)) -#define SENS_SAR2_PWDET_FORCE_V 0x1 -#define SENS_SAR2_PWDET_FORCE_S 27 /* SENS_SAR2_SAMPLE_NUM : R/W ;bitpos:[26:19] ;default: 8'd0 ; */ /*description: */ #define SENS_SAR2_SAMPLE_NUM 0x000000FF @@ -830,8 +297,7 @@ extern "C" { #define SENS_SAR2_CLK_GATED_V 0x1 #define SENS_SAR2_CLK_GATED_S 18 /* SENS_SAR2_SAMPLE_BIT : R/W ;bitpos:[17:16] ;default: 2'd3 ; */ -/*description: 00: for 9-bit width 01: for 10-bit width 10: for 11-bit width - 11: for 12-bit width*/ +/*description: 00: for 9-bit width*/ #define SENS_SAR2_SAMPLE_BIT 0x00000003 #define SENS_SAR2_SAMPLE_BIT_M ((SENS_SAR2_SAMPLE_BIT_V)<<(SENS_SAR2_SAMPLE_BIT_S)) #define SENS_SAR2_SAMPLE_BIT_V 0x3 @@ -849,30 +315,91 @@ extern "C" { #define SENS_SAR2_CLK_DIV_V 0xFF #define SENS_SAR2_CLK_DIV_S 0 -#define SENS_SAR_MEAS_START2_REG (DR_REG_SENS_BASE + 0x0098) +#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_STOP : R/W ;bitpos:[2] ;default: 1'b0 ; */ +/*description: stop SAR ADC2 conversion*/ +#define SENS_SAR2_STOP (BIT(2)) +#define SENS_SAR2_STOP_M (BIT(2)) +#define SENS_SAR2_STOP_V 0x1 +#define SENS_SAR2_STOP_S 2 +/* SENS_SAR2_BIT_WIDTH : R/W ;bitpos:[1:0] ;default: 2'b11 ; */ +/*description: 00: 9 bit*/ +#define SENS_SAR2_BIT_WIDTH 0x00000003 +#define SENS_SAR2_BIT_WIDTH_M ((SENS_SAR2_BIT_WIDTH_V)<<(SENS_SAR2_BIT_WIDTH_S)) +#define SENS_SAR2_BIT_WIDTH_V 0x3 +#define SENS_SAR2_BIT_WIDTH_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 0: SAR ADC2 - pad enable bitmap is controlled by ULP-coprocessor*/ +/*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 only active when reg_sar2_en_pad_force = 1*/ +/*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 0: SAR ADC2 - controller is started by ULP-coprocessor*/ +/*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 only active when - reg_meas2_start_force = 1*/ +/*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 @@ -890,7 +417,773 @@ extern "C" { #define SENS_MEAS2_DATA_SAR_V 0xFFFF #define SENS_MEAS2_DATA_SAR_S 0 -#define SENS_SAR_DAC_CTRL1_REG (DR_REG_SENS_BASE + 0x009c) +#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 +/* SENS_SAR1_DREF : R/W ;bitpos:[28:26] ;default: 3'd0 ; */ +/*description: Adjust saradc1 offset*/ +#define SENS_SAR1_DREF 0x00000007 +#define SENS_SAR1_DREF_M ((SENS_SAR1_DREF_V)<<(SENS_SAR1_DREF_S)) +#define SENS_SAR1_DREF_V 0x7 +#define SENS_SAR1_DREF_S 26 +/* SENS_SAR2_DREF : R/W ;bitpos:[25:23] ;default: 3'd0 ; */ +/*description: Adjust saradc2 offset*/ +#define SENS_SAR2_DREF 0x00000007 +#define SENS_SAR2_DREF_M ((SENS_SAR2_DREF_V)<<(SENS_SAR2_DREF_S)) +#define SENS_SAR2_DREF_V 0x7 +#define SENS_SAR2_DREF_S 23 + +#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_DAC : R/W ;bitpos:[31:28] ;default: 4'hF ; */ +/*description: Temperature sensor offset dac. 15 for 0 offset 5 for -2 7 for + -1 11 for 1 10 for 2*/ +#define SENS_TSENS_DAC 0x0000000F +#define SENS_TSENS_DAC_M ((SENS_TSENS_DAC_V)<<(SENS_TSENS_DAC_S)) +#define SENS_TSENS_DAC_V 0xF +#define SENS_TSENS_DAC_S 28 +/* SENS_TSENS_DIV_CHOP : R/W ;bitpos:[27:26] ;default: 2'b10 ; */ +/*description: 0 for steady phase 0 1 for steady phase 1 2 for chopping with + ½ frequency of TSENS_CK 3 for chopping with ¼*/ +#define SENS_TSENS_DIV_CHOP 0x00000003 +#define SENS_TSENS_DIV_CHOP_M ((SENS_TSENS_DIV_CHOP_V)<<(SENS_TSENS_DIV_CHOP_S)) +#define SENS_TSENS_DIV_CHOP_V 0x3 +#define SENS_TSENS_DIV_CHOP_S 26 +/* SENS_TSENS_DIZ : R/W ;bitpos:[25] ;default: 1'b0 ; */ +/*description: ADC input short*/ +#define SENS_TSENS_DIZ (BIT(25)) +#define SENS_TSENS_DIZ_M (BIT(25)) +#define SENS_TSENS_DIZ_V 0x1 +#define SENS_TSENS_DIZ_S 25 +/* 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_RESET : R/W ;bitpos:[16] ;default: 1'b0 ; */ +/*description: temperature sensor reset*/ +#define SENS_TSENS_RESET (BIT(16)) +#define SENS_TSENS_RESET_M (BIT(16)) +#define SENS_TSENS_RESET_V 0x1 +#define SENS_TSENS_RESET_S 16 +/* SENS_TSENS_CLKGATE_EN : R/W ;bitpos:[15] ;default: 1'b0 ; */ +/*description: temperature sensor clock enable*/ +#define SENS_TSENS_CLKGATE_EN (BIT(15)) +#define SENS_TSENS_CLKGATE_EN_M (BIT(15)) +#define SENS_TSENS_CLKGATE_EN_V 0x1 +#define SENS_TSENS_CLKGATE_EN_S 15 +/* 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_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_OUT0_REG (DR_REG_SENS_BASE + 0x0098) +/* SENS_TOUCH_MEAS_OUT0 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 0*/ +#define SENS_TOUCH_MEAS_OUT0 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT0_M ((SENS_TOUCH_MEAS_OUT0_V)<<(SENS_TOUCH_MEAS_OUT0_S)) +#define SENS_TOUCH_MEAS_OUT0_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT0_S 0 + +#define SENS_SAR_TOUCH_OUT1_REG (DR_REG_SENS_BASE + 0x009c) +/* SENS_TOUCH_MEAS_OUT1 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 1*/ +#define SENS_TOUCH_MEAS_OUT1 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT1_M ((SENS_TOUCH_MEAS_OUT1_V)<<(SENS_TOUCH_MEAS_OUT1_S)) +#define SENS_TOUCH_MEAS_OUT1_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT1_S 0 + +#define SENS_SAR_TOUCH_OUT2_REG (DR_REG_SENS_BASE + 0x00a0) +/* SENS_TOUCH_MEAS_OUT2 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 2*/ +#define SENS_TOUCH_MEAS_OUT2 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT2_M ((SENS_TOUCH_MEAS_OUT2_V)<<(SENS_TOUCH_MEAS_OUT2_S)) +#define SENS_TOUCH_MEAS_OUT2_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT2_S 0 + +#define SENS_SAR_TOUCH_OUT3_REG (DR_REG_SENS_BASE + 0x00a4) +/* SENS_TOUCH_MEAS_OUT3 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 3*/ +#define SENS_TOUCH_MEAS_OUT3 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT3_M ((SENS_TOUCH_MEAS_OUT3_V)<<(SENS_TOUCH_MEAS_OUT3_S)) +#define SENS_TOUCH_MEAS_OUT3_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT3_S 0 + +#define SENS_SAR_TOUCH_OUT4_REG (DR_REG_SENS_BASE + 0x00a8) +/* SENS_TOUCH_MEAS_OUT4 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 4*/ +#define SENS_TOUCH_MEAS_OUT4 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT4_M ((SENS_TOUCH_MEAS_OUT4_V)<<(SENS_TOUCH_MEAS_OUT4_S)) +#define SENS_TOUCH_MEAS_OUT4_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT4_S 0 + +#define SENS_SAR_TOUCH_OUT5_REG (DR_REG_SENS_BASE + 0x00ac) +/* SENS_TOUCH_MEAS_OUT5 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 5*/ +#define SENS_TOUCH_MEAS_OUT5 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT5_M ((SENS_TOUCH_MEAS_OUT5_V)<<(SENS_TOUCH_MEAS_OUT5_S)) +#define SENS_TOUCH_MEAS_OUT5_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT5_S 0 + +#define SENS_SAR_TOUCH_OUT6_REG (DR_REG_SENS_BASE + 0x00b0) +/* SENS_TOUCH_MEAS_OUT6 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 6*/ +#define SENS_TOUCH_MEAS_OUT6 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT6_M ((SENS_TOUCH_MEAS_OUT6_V)<<(SENS_TOUCH_MEAS_OUT6_S)) +#define SENS_TOUCH_MEAS_OUT6_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT6_S 0 + +#define SENS_SAR_TOUCH_OUT7_REG (DR_REG_SENS_BASE + 0x00b4) +/* SENS_TOUCH_MEAS_OUT7 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 7*/ +#define SENS_TOUCH_MEAS_OUT7 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT7_M ((SENS_TOUCH_MEAS_OUT7_V)<<(SENS_TOUCH_MEAS_OUT7_S)) +#define SENS_TOUCH_MEAS_OUT7_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT7_S 0 + +#define SENS_SAR_TOUCH_OUT8_REG (DR_REG_SENS_BASE + 0x00b8) +/* SENS_TOUCH_MEAS_OUT8 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 8*/ +#define SENS_TOUCH_MEAS_OUT8 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT8_M ((SENS_TOUCH_MEAS_OUT8_V)<<(SENS_TOUCH_MEAS_OUT8_S)) +#define SENS_TOUCH_MEAS_OUT8_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT8_S 0 + +#define SENS_SAR_TOUCH_OUT9_REG (DR_REG_SENS_BASE + 0x00bc) +/* SENS_TOUCH_MEAS_OUT9 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 9*/ +#define SENS_TOUCH_MEAS_OUT9 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT9_M ((SENS_TOUCH_MEAS_OUT9_V)<<(SENS_TOUCH_MEAS_OUT9_S)) +#define SENS_TOUCH_MEAS_OUT9_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT9_S 0 + +#define SENS_SAR_TOUCH_OUT10_REG (DR_REG_SENS_BASE + 0x00c0) +/* SENS_TOUCH_MEAS_OUT10 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 10*/ +#define SENS_TOUCH_MEAS_OUT10 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT10_M ((SENS_TOUCH_MEAS_OUT10_V)<<(SENS_TOUCH_MEAS_OUT10_S)) +#define SENS_TOUCH_MEAS_OUT10_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT10_S 0 + +#define SENS_SAR_TOUCH_OUT11_REG (DR_REG_SENS_BASE + 0x00c4) +/* SENS_TOUCH_MEAS_OUT11 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 11*/ +#define SENS_TOUCH_MEAS_OUT11 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT11_M ((SENS_TOUCH_MEAS_OUT11_V)<<(SENS_TOUCH_MEAS_OUT11_S)) +#define SENS_TOUCH_MEAS_OUT11_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT11_S 0 + +#define SENS_SAR_TOUCH_OUT12_REG (DR_REG_SENS_BASE + 0x00c8) +/* SENS_TOUCH_MEAS_OUT12 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 12*/ +#define SENS_TOUCH_MEAS_OUT12 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT12_M ((SENS_TOUCH_MEAS_OUT12_V)<<(SENS_TOUCH_MEAS_OUT12_S)) +#define SENS_TOUCH_MEAS_OUT12_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT12_S 0 + +#define SENS_SAR_TOUCH_OUT13_REG (DR_REG_SENS_BASE + 0x00cc) +/* SENS_TOUCH_MEAS_OUT13 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 13*/ +#define SENS_TOUCH_MEAS_OUT13 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT13_M ((SENS_TOUCH_MEAS_OUT13_V)<<(SENS_TOUCH_MEAS_OUT13_S)) +#define SENS_TOUCH_MEAS_OUT13_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT13_S 0 + +#define SENS_SAR_TOUCH_OUT14_REG (DR_REG_SENS_BASE + 0x00d0) +/* SENS_TOUCH_MEAS_OUT14 : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: the counter for touch pad 14*/ +#define SENS_TOUCH_MEAS_OUT14 0x003FFFFF +#define SENS_TOUCH_MEAS_OUT14_M ((SENS_TOUCH_MEAS_OUT14_V)<<(SENS_TOUCH_MEAS_OUT14_S)) +#define SENS_TOUCH_MEAS_OUT14_V 0x3FFFFF +#define SENS_TOUCH_MEAS_OUT14_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD1_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD1_BASELINE_M ((SENS_TOUCH_PAD1_BASELINE_V)<<(SENS_TOUCH_PAD1_BASELINE_S)) +#define SENS_TOUCH_PAD1_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD1_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD2_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD2_BASELINE_M ((SENS_TOUCH_PAD2_BASELINE_V)<<(SENS_TOUCH_PAD2_BASELINE_S)) +#define SENS_TOUCH_PAD2_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD2_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD3_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD3_BASELINE_M ((SENS_TOUCH_PAD3_BASELINE_V)<<(SENS_TOUCH_PAD3_BASELINE_S)) +#define SENS_TOUCH_PAD3_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD3_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD4_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD4_BASELINE_M ((SENS_TOUCH_PAD4_BASELINE_V)<<(SENS_TOUCH_PAD4_BASELINE_S)) +#define SENS_TOUCH_PAD4_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD4_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD5_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD5_BASELINE_M ((SENS_TOUCH_PAD5_BASELINE_V)<<(SENS_TOUCH_PAD5_BASELINE_S)) +#define SENS_TOUCH_PAD5_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD5_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD6_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD6_BASELINE_M ((SENS_TOUCH_PAD6_BASELINE_V)<<(SENS_TOUCH_PAD6_BASELINE_S)) +#define SENS_TOUCH_PAD6_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD6_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD7_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD7_BASELINE_M ((SENS_TOUCH_PAD7_BASELINE_V)<<(SENS_TOUCH_PAD7_BASELINE_S)) +#define SENS_TOUCH_PAD7_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD7_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD8_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD8_BASELINE_M ((SENS_TOUCH_PAD8_BASELINE_V)<<(SENS_TOUCH_PAD8_BASELINE_S)) +#define SENS_TOUCH_PAD8_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD8_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD9_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD9_BASELINE_M ((SENS_TOUCH_PAD9_BASELINE_V)<<(SENS_TOUCH_PAD9_BASELINE_S)) +#define SENS_TOUCH_PAD9_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD9_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD10_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD10_BASELINE_M ((SENS_TOUCH_PAD10_BASELINE_V)<<(SENS_TOUCH_PAD10_BASELINE_S)) +#define SENS_TOUCH_PAD10_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD10_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD11_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD11_BASELINE_M ((SENS_TOUCH_PAD11_BASELINE_V)<<(SENS_TOUCH_PAD11_BASELINE_S)) +#define SENS_TOUCH_PAD11_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD11_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD12_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD12_BASELINE_M ((SENS_TOUCH_PAD12_BASELINE_V)<<(SENS_TOUCH_PAD12_BASELINE_S)) +#define SENS_TOUCH_PAD12_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD12_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD13_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD13_BASELINE_M ((SENS_TOUCH_PAD13_BASELINE_V)<<(SENS_TOUCH_PAD13_BASELINE_S)) +#define SENS_TOUCH_PAD13_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD13_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_PAD14_BASELINE 0x003FFFFF +#define SENS_TOUCH_PAD14_BASELINE_M ((SENS_TOUCH_PAD14_BASELINE_V)<<(SENS_TOUCH_PAD14_BASELINE_S)) +#define SENS_TOUCH_PAD14_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_PAD14_BASELINE_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_BASELINE : RO ;bitpos:[21:0] ;default: 22'h0 ; */ +/*description: */ +#define SENS_TOUCH_SLP_BASELINE 0x003FFFFF +#define SENS_TOUCH_SLP_BASELINE_M ((SENS_TOUCH_SLP_BASELINE_V)<<(SENS_TOUCH_SLP_BASELINE_S)) +#define SENS_TOUCH_SLP_BASELINE_V 0x3FFFFF +#define SENS_TOUCH_SLP_BASELINE_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)) @@ -910,7 +1203,7 @@ extern "C" { #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 0: DAC1 & DAC2 do not use DMA*/ +/*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 @@ -922,55 +1215,51 @@ extern "C" { #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 0: disable CW generator*/ +/*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 can be used to adjust the frequency*/ +/*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 + 0x00a0) +#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] 0: to - select register reg_pdac2_dac[7:0] as source to PDAC2_DAC[7:0]*/ +/*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] 0: to - select register reg_pdac1_dac[7:0] as source to PDAC1_DAC[7:0]*/ +/*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 01: invert all bits 10: invert MSB - 11: invert all bits except MSB*/ +/*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 01: invert all bits 10: invert MSB - 11: invert all bits except MSB*/ +/*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 01: scale to 1/2 10: scale to 1/4 scale to 1/8*/ +/*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 01: scale to 1/2 10: scale to 1/4 scale to 1/8*/ +/*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 @@ -988,259 +1277,329 @@ extern "C" { #define SENS_DAC_DC1_V 0xFF #define SENS_DAC_DC1_S 0 -#define SENS_SAR_MEAS_CTRL2_REG (DR_REG_SENS_BASE + 0x00a4) -/* SENS_AMP_SHORT_REF_GND_FORCE : R/W ;bitpos:[18:17] ;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 17 -/* SENS_AMP_SHORT_REF_FORCE : R/W ;bitpos:[16:15] ;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 15 -/* SENS_AMP_RST_FB_FORCE : R/W ;bitpos:[14:13] ;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 13 -/* SENS_SAR2_RSTB_FORCE : R/W ;bitpos:[12:11] ;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 11 -/* SENS_SAR_RSTB_FSM_IDLE : R/W ;bitpos:[10] ;default: 1'b0 ; */ -/*description: */ -#define SENS_SAR_RSTB_FSM_IDLE (BIT(10)) -#define SENS_SAR_RSTB_FSM_IDLE_M (BIT(10)) -#define SENS_SAR_RSTB_FSM_IDLE_V 0x1 -#define SENS_SAR_RSTB_FSM_IDLE_S 10 -/* SENS_XPD_SAR_FSM_IDLE : R/W ;bitpos:[9] ;default: 1'b0 ; */ -/*description: */ -#define SENS_XPD_SAR_FSM_IDLE (BIT(9)) -#define SENS_XPD_SAR_FSM_IDLE_M (BIT(9)) -#define SENS_XPD_SAR_FSM_IDLE_V 0x1 -#define SENS_XPD_SAR_FSM_IDLE_S 9 -/* SENS_AMP_SHORT_REF_GND_FSM_IDLE : R/W ;bitpos:[8] ;default: 1'b0 ; */ -/*description: */ -#define SENS_AMP_SHORT_REF_GND_FSM_IDLE (BIT(8)) -#define SENS_AMP_SHORT_REF_GND_FSM_IDLE_M (BIT(8)) -#define SENS_AMP_SHORT_REF_GND_FSM_IDLE_V 0x1 -#define SENS_AMP_SHORT_REF_GND_FSM_IDLE_S 8 -/* SENS_AMP_SHORT_REF_FSM_IDLE : R/W ;bitpos:[7] ;default: 1'b0 ; */ -/*description: */ -#define SENS_AMP_SHORT_REF_FSM_IDLE (BIT(7)) -#define SENS_AMP_SHORT_REF_FSM_IDLE_M (BIT(7)) -#define SENS_AMP_SHORT_REF_FSM_IDLE_V 0x1 -#define SENS_AMP_SHORT_REF_FSM_IDLE_S 7 -/* SENS_AMP_RST_FB_FSM_IDLE : R/W ;bitpos:[6] ;default: 1'b0 ; */ -/*description: */ -#define SENS_AMP_RST_FB_FSM_IDLE (BIT(6)) -#define SENS_AMP_RST_FB_FSM_IDLE_M (BIT(6)) -#define SENS_AMP_RST_FB_FSM_IDLE_V 0x1 -#define SENS_AMP_RST_FB_FSM_IDLE_S 6 -/* SENS_XPD_SAR_AMP_FSM_IDLE : R/W ;bitpos:[5] ;default: 1'b0 ; */ -/*description: */ -#define SENS_XPD_SAR_AMP_FSM_IDLE (BIT(5)) -#define SENS_XPD_SAR_AMP_FSM_IDLE_M (BIT(5)) -#define SENS_XPD_SAR_AMP_FSM_IDLE_V 0x1 -#define SENS_XPD_SAR_AMP_FSM_IDLE_S 5 -/* SENS_SAR1_DAC_XPD_FSM_IDLE : R/W ;bitpos:[4] ;default: 1'b0 ; */ -/*description: */ -#define SENS_SAR1_DAC_XPD_FSM_IDLE (BIT(4)) -#define SENS_SAR1_DAC_XPD_FSM_IDLE_M (BIT(4)) -#define SENS_SAR1_DAC_XPD_FSM_IDLE_V 0x1 -#define SENS_SAR1_DAC_XPD_FSM_IDLE_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_COCPU_CTRL_REG (DR_REG_SENS_BASE + 0x00a8) -/* SENS_COCPU_TRAP : RO ;bitpos:[28] ;default: 1'b0 ; */ +#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(28)) -#define SENS_COCPU_TRAP_M (BIT(28)) +#define SENS_COCPU_TRAP (BIT(29)) +#define SENS_COCPU_TRAP_M (BIT(29)) #define SENS_COCPU_TRAP_V 0x1 -#define SENS_COCPU_TRAP_S 28 -/* SENS_COCPU_EOI : RO ;bitpos:[27] ;default: 1'b0 ; */ +#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(27)) -#define SENS_COCPU_EOI_M (BIT(27)) +#define SENS_COCPU_EOI (BIT(28)) +#define SENS_COCPU_EOI_M (BIT(28)) #define SENS_COCPU_EOI_V 0x1 -#define SENS_COCPU_EOI_S 27 -/* SENS_COCPU_RESET_N : RO ;bitpos:[26] ;default: 1'b0 ; */ +#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(26)) -#define SENS_COCPU_RESET_N_M (BIT(26)) +#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 26 -/* SENS_COCPU_CLK_EN : RO ;bitpos:[25] ;default: 1'b0 ; */ +#define SENS_COCPU_RESET_N_S 27 +/* SENS_COCPU_CLK_EN : RO ;bitpos:[26] ;default: 1'b0 ; */ /*description: check cocpu whether clk on*/ -#define SENS_COCPU_CLK_EN (BIT(25)) -#define SENS_COCPU_CLK_EN_M (BIT(25)) +#define SENS_COCPU_CLK_EN (BIT(26)) +#define SENS_COCPU_CLK_EN_M (BIT(26)) #define SENS_COCPU_CLK_EN_V 0x1 -#define SENS_COCPU_CLK_EN_S 25 -/* SENS_COCPU_INT_TRIGGER : R/W ;bitpos:[24] ;default: 1'b0 ; */ -/*description: trigger cocpu register interrupt*/ -#define SENS_COCPU_INT_TRIGGER (BIT(24)) -#define SENS_COCPU_INT_TRIGGER_M (BIT(24)) -#define SENS_COCPU_INT_TRIGGER_V 0x1 -#define SENS_COCPU_INT_TRIGGER_S 24 -/* SENS_COCPU_DONE : R/W ;bitpos:[23] ;default: 1'b0 ; */ -/*description: done signal used by riscv to control timer.*/ -#define SENS_COCPU_DONE (BIT(23)) -#define SENS_COCPU_DONE_M (BIT(23)) -#define SENS_COCPU_DONE_V 0x1 -#define SENS_COCPU_DONE_S 23 -/* SENS_COCPU_DONE_FORCE : R/W ;bitpos:[22] ;default: 1'b0 ; */ -/*description: 1: select riscv done 0: select ulp done*/ -#define SENS_COCPU_DONE_FORCE (BIT(22)) -#define SENS_COCPU_DONE_FORCE_M (BIT(22)) -#define SENS_COCPU_DONE_FORCE_V 0x1 -#define SENS_COCPU_DONE_FORCE_S 22 -/* SENS_COCPU_SEL : R/W ;bitpos:[21] ;default: 1'b1 ; */ -/*description: 1: old ULP 0: new riscV*/ -#define SENS_COCPU_SEL (BIT(21)) -#define SENS_COCPU_SEL_M (BIT(21)) -#define SENS_COCPU_SEL_V 0x1 -#define SENS_COCPU_SEL_S 21 -/* SENS_COCPU_SHUT_RESET_EN : R/W ;bitpos:[20] ;default: 1'b0 ; */ -/*description: to reset cocpu*/ -#define SENS_COCPU_SHUT_RESET_EN (BIT(20)) -#define SENS_COCPU_SHUT_RESET_EN_M (BIT(20)) -#define SENS_COCPU_SHUT_RESET_EN_V 0x1 -#define SENS_COCPU_SHUT_RESET_EN_S 20 -/* SENS_COCPU_SHUT_2_CLK_DIS : R/W ;bitpos:[19:14] ;default: 6'd24 ; */ -/*description: time from shut cocpu to disable clk*/ -#define SENS_COCPU_SHUT_2_CLK_DIS 0x0000003F -#define SENS_COCPU_SHUT_2_CLK_DIS_M ((SENS_COCPU_SHUT_2_CLK_DIS_V)<<(SENS_COCPU_SHUT_2_CLK_DIS_S)) -#define SENS_COCPU_SHUT_2_CLK_DIS_V 0x3F -#define SENS_COCPU_SHUT_2_CLK_DIS_S 14 -/* SENS_COCPU_SHUT : R/W ;bitpos:[13] ;default: 1'b0 ; */ -/*description: to shut cocpu*/ -#define SENS_COCPU_SHUT (BIT(13)) -#define SENS_COCPU_SHUT_M (BIT(13)) -#define SENS_COCPU_SHUT_V 0x1 -#define SENS_COCPU_SHUT_S 13 -/* SENS_COCPU_START_2_INTR_EN : R/W ;bitpos:[12:7] ;default: 6'd16 ; */ -/*description: time from start cocpu to give start interrupt*/ -#define SENS_COCPU_START_2_INTR_EN 0x0000003F -#define SENS_COCPU_START_2_INTR_EN_M ((SENS_COCPU_START_2_INTR_EN_V)<<(SENS_COCPU_START_2_INTR_EN_S)) -#define SENS_COCPU_START_2_INTR_EN_V 0x3F -#define SENS_COCPU_START_2_INTR_EN_S 7 -/* SENS_COCPU_START_2_RESET_DIS : R/W ;bitpos:[6:1] ;default: 6'd8 ; */ -/*description: time from start cocpu to pull down reset*/ -#define SENS_COCPU_START_2_RESET_DIS 0x0000003F -#define SENS_COCPU_START_2_RESET_DIS_M ((SENS_COCPU_START_2_RESET_DIS_V)<<(SENS_COCPU_START_2_RESET_DIS_S)) -#define SENS_COCPU_START_2_RESET_DIS_V 0x3F -#define SENS_COCPU_START_2_RESET_DIS_S 1 -/* SENS_COCPU_CLK_FO : R/W ;bitpos:[0] ;default: 1'b0 ; */ -/*description: cocpu clk force on*/ -#define SENS_COCPU_CLK_FO (BIT(0)) -#define SENS_COCPU_CLK_FO_M (BIT(0)) -#define SENS_COCPU_CLK_FO_V 0x1 -#define SENS_COCPU_CLK_FO_S 0 +#define SENS_COCPU_CLK_EN_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_REG (DR_REG_SENS_BASE + 0x00ac) -/* SENS_COCPU_EBREAK_INT : RO ;bitpos:[24] ;default: 1'b0 ; */ -/*description: int from ebreak*/ -#define SENS_COCPU_EBREAK_INT (BIT(24)) -#define SENS_COCPU_EBREAK_INT_M (BIT(24)) -#define SENS_COCPU_EBREAK_INT_V 0x1 -#define SENS_COCPU_EBREAK_INT_S 24 -/* SENS_COCPU_INT : RO ;bitpos:[23] ;default: 1'b0 ; */ -/*description: int from register*/ -#define SENS_COCPU_INT (BIT(23)) -#define SENS_COCPU_INT_M (BIT(23)) -#define SENS_COCPU_INT_V 0x1 -#define SENS_COCPU_INT_S 23 -/* SENS_COCPU_START_INT : RO ;bitpos:[22] ;default: 1'b0 ; */ +#define SENS_SAR_COCPU_INT_RAW_REG (DR_REG_SENS_BASE + 0x0128) +/* 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 (BIT(22)) -#define SENS_COCPU_START_INT_M (BIT(22)) -#define SENS_COCPU_START_INT_V 0x1 -#define SENS_COCPU_START_INT_S 22 -/* SENS_COCPU_TSENS_INT : RO ;bitpos:[21] ;default: 1'b0 ; */ +#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 (BIT(21)) -#define SENS_COCPU_TSENS_INT_M (BIT(21)) -#define SENS_COCPU_TSENS_INT_V 0x1 -#define SENS_COCPU_TSENS_INT_S 21 -/* SENS_COCPU_SARADC_INT : RO ;bitpos:[20] ;default: 1'b0 ; */ -/*description: int from saradc*/ -#define SENS_COCPU_SARADC_INT (BIT(20)) -#define SENS_COCPU_SARADC_INT_M (BIT(20)) -#define SENS_COCPU_SARADC_INT_V 0x1 -#define SENS_COCPU_SARADC_INT_S 20 -/* SENS_COCPU_EBREAK_INT_CLR : WO ;bitpos:[14] ;default: 1'b0 ; */ -/*description: int clear entry*/ -#define SENS_COCPU_EBREAK_INT_CLR (BIT(14)) -#define SENS_COCPU_EBREAK_INT_CLR_M (BIT(14)) -#define SENS_COCPU_EBREAK_INT_CLR_V 0x1 -#define SENS_COCPU_EBREAK_INT_CLR_S 14 -/* SENS_COCPU_INT_CLR : WO ;bitpos:[13] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_INT_CLR (BIT(13)) -#define SENS_COCPU_INT_CLR_M (BIT(13)) -#define SENS_COCPU_INT_CLR_V 0x1 -#define SENS_COCPU_INT_CLR_S 13 -/* SENS_COCPU_START_INT_CLR : WO ;bitpos:[12] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_START_INT_CLR (BIT(12)) -#define SENS_COCPU_START_INT_CLR_M (BIT(12)) -#define SENS_COCPU_START_INT_CLR_V 0x1 -#define SENS_COCPU_START_INT_CLR_S 12 -/* SENS_COCPU_TSENS_INT_CLR : WO ;bitpos:[11] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_TSENS_INT_CLR (BIT(11)) -#define SENS_COCPU_TSENS_INT_CLR_M (BIT(11)) -#define SENS_COCPU_TSENS_INT_CLR_V 0x1 -#define SENS_COCPU_TSENS_INT_CLR_S 11 -/* SENS_COCPU_SARADC_INT_CLR : WO ;bitpos:[10] ;default: 1'b0 ; */ -/*description: */ -#define SENS_COCPU_SARADC_INT_CLR (BIT(10)) -#define SENS_COCPU_SARADC_INT_CLR_M (BIT(10)) -#define SENS_COCPU_SARADC_INT_CLR_V 0x1 -#define SENS_COCPU_SARADC_INT_CLR_S 10 -/* SENS_COCPU_EBREAK_INT_ENA : R/W ;bitpos:[4] ;default: 1'b1 ; */ -/*description: int enable entry*/ -#define SENS_COCPU_EBREAK_INT_ENA (BIT(4)) -#define SENS_COCPU_EBREAK_INT_ENA_M (BIT(4)) -#define SENS_COCPU_EBREAK_INT_ENA_V 0x1 -#define SENS_COCPU_EBREAK_INT_ENA_S 4 -/* SENS_COCPU_INT_ENA : R/W ;bitpos:[3] ;default: 1'b1 ; */ -/*description: */ -#define SENS_COCPU_INT_ENA (BIT(3)) -#define SENS_COCPU_INT_ENA_M (BIT(3)) -#define SENS_COCPU_INT_ENA_V 0x1 -#define SENS_COCPU_INT_ENA_S 3 -/* SENS_COCPU_START_INT_ENA : R/W ;bitpos:[2] ;default: 1'b1 ; */ -/*description: */ -#define SENS_COCPU_START_INT_ENA (BIT(2)) -#define SENS_COCPU_START_INT_ENA_M (BIT(2)) -#define SENS_COCPU_START_INT_ENA_V 0x1 -#define SENS_COCPU_START_INT_ENA_S 2 -/* SENS_COCPU_TSENS_INT_ENA : R/W ;bitpos:[1] ;default: 1'b1 ; */ -/*description: */ -#define SENS_COCPU_TSENS_INT_ENA (BIT(1)) -#define SENS_COCPU_TSENS_INT_ENA_M (BIT(1)) -#define SENS_COCPU_TSENS_INT_ENA_V 0x1 -#define SENS_COCPU_TSENS_INT_ENA_S 1 -/* SENS_COCPU_SARADC_INT_ENA : R/W ;bitpos:[0] ;default: 1'b1 ; */ -/*description: */ -#define SENS_COCPU_SARADC_INT_ENA (BIT(0)) -#define SENS_COCPU_SARADC_INT_ENA_M (BIT(0)) -#define SENS_COCPU_SARADC_INT_ENA_V 0x1 -#define SENS_COCPU_SARADC_INT_ENA_S 0 +#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_NOUSE_REG (DR_REG_SENS_BASE + 0x00F8) +#define SENS_SAR_COCPU_INT_ENA_REG (DR_REG_SENS_BASE + 0x012c) +/* 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_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_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 @@ -1248,8 +1607,8 @@ extern "C" { #define SENS_SAR_NOUSE_V 0xFFFFFFFF #define SENS_SAR_NOUSE_S 0 -#define SENS_SARDATE_REG (DR_REG_SENS_BASE + 0x00FC) -/* SENS_SAR_DATE : R/W ;bitpos:[27:0] ;default: 28'h1703080 ; */ +#define SENS_SARDATE_REG (DR_REG_SENS_BASE + 0x0144) +/* SENS_SAR_DATE : R/W ;bitpos:[27:0] ;default: 28'h1809210 ; */ /*description: */ #define SENS_SAR_DATE 0x0FFFFFFF #define SENS_SAR_DATE_M ((SENS_SAR_DATE_V)<<(SENS_SAR_DATE_S)) diff --git a/components/soc/esp32s2beta/include/soc/sens_struct.h b/components/soc/esp32s2beta/include/soc/sens_struct.h index fb0ec358f0..7ad7a8570a 100644 --- a/components/soc/esp32s2beta/include/soc/sens_struct.h +++ b/components/soc/esp32s2beta/include/soc/sens_struct.h @@ -1,9 +1,9 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// Copyright 2017-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 @@ -20,82 +20,143 @@ extern "C" { typedef volatile struct { union { struct { - uint32_t sar1_clk_div: 8; /*clock divider*/ - uint32_t sar1_sample_cycle: 8; /*sample cycles for SAR ADC1*/ - uint32_t sar1_sample_bit: 2; /*00: for 9-bit width 01: for 10-bit width 10: for 11-bit width 11: for 12-bit width*/ + uint32_t sar1_clk_div: 8; /*clock divider*/ + uint32_t sar1_sample_cycle: 8; /*sample cycles for SAR ADC1*/ + uint32_t sar1_sample_bit: 2; /*00: for 9-bit width*/ uint32_t sar1_clk_gated: 1; uint32_t sar1_sample_num: 8; - uint32_t sar1_dig_force: 1; /*1: SAR ADC1 controlled by DIG ADC1 CTRL 0: SAR ADC1 controlled by RTC ADC1 CTRL*/ - uint32_t sar1_data_inv: 1; /*Invert SAR ADC1 data*/ - uint32_t reserved29: 3; + 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_read_ctrl; - uint32_t sar_read_status1; /**/ + } sar_reader1_ctrl; + uint32_t sar_reader1_status; /**/ + union { + struct { + uint32_t sar1_bit_width: 2; /*00: 9 bit*/ + uint32_t sar1_stop: 1; /*stop SAR ADC1 conversion*/ + uint32_t reserved3: 21; + 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_meas_wait1; + } sar_amp_ctrl1; union { struct { - uint32_t sar_amp_wait3: 16; - uint32_t force_xpd_amp: 2; - uint32_t force_xpd_sar: 2; - uint32_t sar2_rstb_wait: 8; - uint32_t reserved28: 4; + 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_meas_wait2; + } 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 sar2_xpd_wait: 8; + uint32_t reserved28: 4; }; uint32_t val; - } sar_meas_ctrl; - uint32_t sar_read_status2; /**/ - uint32_t ulp_cp_sleep_cyc0; /*sleep cycles for ULP-coprocessor timer*/ - uint32_t ulp_cp_sleep_cyc1; /**/ - uint32_t ulp_cp_sleep_cyc2; /**/ - uint32_t ulp_cp_sleep_cyc3; /**/ - uint32_t ulp_cp_sleep_cyc4; /**/ + } sar_amp_ctrl3; union { struct { - uint32_t sar1_bit_width: 2; /*00: 9 bit 01: 10 bits 10: 11bits 11: 12bits*/ - uint32_t sar2_bit_width: 2; /*00: 9 bit 01: 10 bits 10: 11bits 11: 12bits*/ - uint32_t sar2_en_test: 1; /*SAR2_EN_TEST only active when reg_sar2_dig_force = 0*/ - uint32_t sar2_pwdet_cct: 3; /*SAR2_PWDET_CCT PA power detector capacitance tuning.*/ - uint32_t ulp_cp_force_start_top: 1; /*1: ULP-coprocessor is started by SW 0: ULP-coprocessor is started by timer*/ - uint32_t ulp_cp_start_top: 1; /*Write 1 to start ULP-coprocessor only active when reg_ulp_cp_force_start_top = 1*/ - uint32_t sarclk_en: 1; - uint32_t pc_init: 11; /*initialized PC for ULP-coprocessor*/ - uint32_t sar2_stop: 1; /*stop SAR ADC2 conversion*/ - uint32_t sar1_stop: 1; /*stop SAR ADC1 conversion*/ - uint32_t sar2_pwdet_en: 1; /*N/A*/ - uint32_t reserved25: 7; + uint32_t sar2_clk_div: 8; /*clock divider*/ + uint32_t sar2_sample_cycle: 8; /*sample cycles for SAR ADC2*/ + uint32_t sar2_sample_bit: 2; /*00: for 9-bit width*/ + 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_start_force; + } sar_reader2_ctrl; + uint32_t sar_reader2_status; /**/ union { struct { - uint32_t mem_wr_addr_init: 11; - uint32_t mem_wr_addr_size: 11; - uint32_t rtc_mem_wr_offst_clr: 1; - uint32_t ulp_cp_clk_fo: 1; /*ulp coprocessor clk force on*/ - uint32_t reserved24: 8; + uint32_t sar2_bit_width: 2; /*00: 9 bit*/ + uint32_t sar2_stop: 1; /*stop SAR ADC2 conversion*/ + 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_mem_wr_ctrl; - uint32_t sar_atten1; /*2-bit attenuation for each pad 11:1dB 10:6dB 01:3dB 00:0dB*/ - uint32_t sar_atten2; /*2-bit attenuation for each pad 11:1dB 10:6dB 01:3dB 00:0dB*/ + } 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: 23; + uint32_t sar2_dref: 3; /*Adjust saradc2 offset*/ + uint32_t sar1_dref: 3; /*Adjust saradc1 offset*/ + 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; @@ -117,9 +178,7 @@ typedef volatile struct { struct { uint32_t i2c_slave_addr5:11; uint32_t i2c_slave_addr4:11; - uint32_t tsens_out: 8; /*temperature sensor data out*/ - uint32_t tsens_rdy_out: 1; /*indicate temperature sensor out ready*/ - uint32_t reserved31: 1; + uint32_t reserved22: 10; }; uint32_t val; } sar_slave_addr3; @@ -127,236 +186,339 @@ typedef volatile struct { struct { uint32_t i2c_slave_addr7:11; uint32_t i2c_slave_addr6:11; - uint32_t i2c_rdata: 8; /*I2C read data*/ - uint32_t i2c_done: 1; /*indicate I2C done*/ - uint32_t reserved31: 1; + uint32_t reserved22: 10; }; uint32_t val; } sar_slave_addr4; union { struct { - uint32_t tsens_xpd_wait: 12; - uint32_t tsens_xpd_force: 1; - uint32_t tsens_clk_inv: 1; - uint32_t tsens_clk_gated: 1; - 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 0: by FSM*/ - uint32_t tsens_dump_out: 1; /*temperature sensor dump out only active when reg_tsens_power_up_force = 1*/ - uint32_t tsens_dos: 4; /*Temperature sensor calibration bits*/ - uint32_t tsens_force: 1; /*1: select saradc_reg 0: select efuse*/ + 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 tsens_diz: 1; /*ADC input short*/ + uint32_t tsens_div_chop: 2; /*0 for steady phase 0 1 for steady phase 1 2 for chopping with ½ frequency of TSENS_CK 3 for chopping with ¼*/ + uint32_t tsens_dac: 4; /*Temperature sensor offset dac. 15 for 0 offset 5 for -2 7 for -1 11 for 1 10 for 2*/ }; uint32_t val; } sar_tctrl; union { struct { - uint32_t sar_i2c_ctrl: 28; /*I2C control data only active when reg_sar_i2c_start_force = 1*/ - uint32_t sar_i2c_start: 1; /*start I2C only active when reg_sar_i2c_start_force = 1*/ - uint32_t sar_i2c_start_force: 1; /*1: I2C started by SW 0: I2C started by FSM*/ + uint32_t tsens_xpd_wait: 12; + uint32_t tsens_xpd_force: 2; + uint32_t tsens_clk_inv: 1; + uint32_t tsens_clkgate_en: 1; /*temperature sensor clock enable*/ + uint32_t tsens_reset: 1; /*temperature sensor reset*/ + uint32_t reserved17: 15; + }; + 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 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 only active when reg_meas1_start_force = 1*/ - uint32_t meas1_start_force: 1; /*1: SAR ADC1 controller (in RTC) is started by SW 0: SAR ADC1 controller is started by ULP-coprocessor*/ - uint32_t sar1_en_pad: 12; /*SAR ADC1 pad enable bitmap only active when reg_sar1_en_pad_force = 1*/ - uint32_t sar1_en_pad_force: 1; /*1: SAR ADC1 pad enable bitmap is controlled by SW 0: SAR ADC1 pad enable bitmap is controlled by ULP-coprocessor*/ + uint32_t touch_outen: 15; /*touch controller output enable*/ + uint32_t touch_status_clr: 1; /*clear all touch active status*/ + uint32_t reserved16: 4; + 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_meas_start1; + } sar_touch_conf; union { struct { - uint32_t touch_meas_delay:16; /*the meas length (in 8MHz)*/ - uint32_t touch_xpd_wait: 8; /*the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD*/ - uint32_t touch_out_sel: 1; /*1: when the counter is greater then the threshold the touch pad is considered as “touched” 0: when the counter is less than the threshold the touch pad is considered as “touched”*/ - uint32_t touch_out_1en: 1; /*1: wakeup interrupt is generated if SET1 is “touched” 0: wakeup interrupt is generated only if SET1 & SET2 is both “touched”*/ - 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_force: 1; /*1: HALL PHASE is controlled by SW 0: HALL PHASE is controlled by FSM in ULP-coprocessor*/ - uint32_t reserved28: 4; + uint32_t thresh: 22; /*Finger threshold for touch pad 1*/ + uint32_t reserved22: 10; }; uint32_t val; - } sar_touch_ctrl1; + } touch_thresh[14]; union { struct { - uint32_t l_thresh: 16; /*the threshold for touch pad 1*/ - uint32_t h_thresh: 16; /*the threshold for touch pad 0*/ + uint32_t meas_out: 22; /*the counter for touch pad 1*/ + uint32_t reserved22: 10; }; uint32_t val; - } touch_thresh[5]; + } touch_meas[15]; union { struct { - uint32_t l_val: 16; /*the counter for touch pad 1*/ - uint32_t h_val: 16; /*the counter for touch pad 0*/ + 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; - } touch_meas[5]; + } sar_touch_chn_st; union { struct { - uint32_t touch_meas_en: 10; /*10-bit register to indicate which pads are “touched”*/ - uint32_t touch_meas_done: 1; /*fsm set 1 to indicate touch touch meas is done*/ - uint32_t touch_start_fsm_en: 1; /*1: TOUCH_START & TOUCH_XPD is controlled by touch fsm 0: TOUCH_START & TOUCH_XPD is controlled by registers*/ - uint32_t touch_start_en: 1; /*1: start touch fsm valid when reg_touch_start_force is set*/ - uint32_t touch_start_force: 1; /*1: to start touch fsm by SW 0: to start touch fsm by timer*/ - uint32_t touch_sleep_cycles:16; /*sleep cycles for timer*/ - uint32_t touch_meas_en_clr: 1; /*to clear reg_touch_meas_en*/ - uint32_t reserved31: 1; + 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_ctrl2; - uint32_t reserved_88; + } sar_touch_status0; union { struct { - uint32_t touch_pad_worken:10; /*Bitmap defining the working set during the measurement.*/ - uint32_t touch_pad_outen2:10; /*Bitmap defining SET2 for generating wakeup interrupt. SET2 is “touched” only if at least one of touch pad in SET2 is “touched”.*/ - uint32_t touch_pad_outen1:10; /*Bitmap defining SET1 for generating wakeup interrupt. SET1 is “touched” only if at least one of touch pad in SET1 is “touched”.*/ - uint32_t reserved30: 2; + uint32_t touch_pad_baseline: 22; + uint32_t reserved22: 7; + uint32_t touch_pad_debounce: 3; }; uint32_t val; - } sar_touch_enable; + } sar_touch_status[14]; +// union { +// struct { +// uint32_t touch_pad2_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad2_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status2; +// union { +// struct { +// uint32_t touch_pad3_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad3_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status3; +// union { +// struct { +// uint32_t touch_pad4_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad4_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status4; +// union { +// struct { +// uint32_t touch_pad5_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad5_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status5; +// union { +// struct { +// uint32_t touch_pad6_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad6_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status6; +// union { +// struct { +// uint32_t touch_pad7_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad7_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status7; +// union { +// struct { +// uint32_t touch_pad8_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad8_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status8; +// union { +// struct { +// uint32_t touch_pad9_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad9_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status9; +// union { +// struct { +// uint32_t touch_pad10_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad10_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status10; +// union { +// struct { +// uint32_t touch_pad11_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad11_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status11; +// union { +// struct { +// uint32_t touch_pad12_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad12_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status12; +// union { +// struct { +// uint32_t touch_pad13_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad13_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status13; +// union { +// struct { +// uint32_t touch_pad14_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_pad14_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status14; +// union { +// struct { +// uint32_t touch_slp_baseline:22; +// uint32_t reserved22: 7; +// uint32_t touch_slp_debounce: 3; +// }; +// uint32_t val; +// } sar_touch_status15; union { struct { - uint32_t touch_meas_raw:10; /*touch sensor raw result*/ - uint32_t reserved10: 22; + 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_ctrl3; + } sar_touch_status16; union { struct { - uint32_t sar2_clk_div: 8; /*clock divider*/ - uint32_t sar2_sample_cycle: 8; /*sample cycles for SAR ADC2*/ - uint32_t sar2_sample_bit: 2; /*00: for 9-bit width 01: for 10-bit width 10: for 11-bit width 11: for 12-bit width*/ - uint32_t sar2_clk_gated: 1; - uint32_t sar2_sample_num: 8; - uint32_t sar2_pwdet_force: 1; - uint32_t sar2_dig_force: 1; /*1: SAR ADC2 controlled by DIG ADC2 CTRL or PWDET CTRL 0: SAR ADC2 controlled by RTC ADC2 CTRL*/ - uint32_t sar2_data_inv: 1; /*Invert SAR ADC2 data*/ - uint32_t reserved30: 2; - }; - uint32_t val; - } sar_read_ctrl2; - 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 only active when reg_meas2_start_force = 1*/ - uint32_t meas2_start_force: 1; /*1: SAR ADC2 controller (in RTC) is started by SW 0: SAR ADC2 controller is started by ULP-coprocessor*/ - uint32_t sar2_en_pad: 12; /*SAR ADC2 pad enable bitmap only active when reg_sar2_en_pad_force = 1*/ - uint32_t sar2_en_pad_force: 1; /*1: SAR ADC2 pad enable bitmap is controlled by SW 0: SAR ADC2 pad enable bitmap is controlled by ULP-coprocessor*/ - }; - uint32_t val; - } sar_meas_start2; - union { - struct { - uint32_t sw_fstep: 16; /*frequency step for CW generator can be used to adjust the frequency*/ - uint32_t sw_tone_en: 1; /*1: enable CW generator 0: disable CW generator*/ + 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 0: DAC1 & DAC2 do not 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 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 01: scale to 1/2 10: scale to 1/4 scale to 1/8*/ - uint32_t dac_scale2: 2; /*00: no scale 01: scale to 1/2 10: scale to 1/4 scale to 1/8*/ - uint32_t dac_inv1: 2; /*00: do not invert any bits 01: invert all bits 10: invert MSB 11: invert all bits except MSB*/ - uint32_t dac_inv2: 2; /*00: do not invert any bits 01: invert all bits 10: invert MSB 11: invert all bits except MSB*/ - uint32_t dac_cw_en1: 1; /*1: to select CW generator as source to PDAC1_DAC[7:0] 0: to select register reg_pdac1_dac[7:0] 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] 0: to select register reg_pdac2_dac[7:0] as source to PDAC2_DAC[7:0]*/ + 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 sar1_dac_xpd_fsm: 4; - 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 sar2_rstb_force: 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 reserved19: 13; + uint32_t reserved0: 25; + uint32_t dbg_trigger: 1; /*trigger cocpu debug registers*/ + uint32_t clk_en: 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_meas_ctrl2; + } sar_cocpu_state; union { struct { - uint32_t clk_fo: 1; /*cocpu clk force on*/ - uint32_t start_2_reset_dis: 6; /*time from start cocpu to pull down reset*/ - uint32_t start_2_intr_en: 6; /*time from start cocpu to give start interrupt*/ - uint32_t shut: 1; /*to shut cocpu*/ - uint32_t shut_2_clk_dis: 6; /*time from shut cocpu to disable clk*/ - uint32_t shut_reset_en: 1; /*to reset cocpu*/ - uint32_t sel: 1; /*1: old ULP 0: new riscV*/ - uint32_t done_force: 1; /*1: select riscv done 0: select ulp done*/ - uint32_t done: 1; /*done signal used by riscv to control timer.*/ - uint32_t int_trigger: 1; /*trigger cocpu register interrupt*/ - uint32_t clk_en: 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 reserved29: 3; + 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 reserved9: 23; }; uint32_t val; - } sar_cocpu_ctrl; + } sar_cocpu_int_raw; union { struct { - uint32_t saradc_int_ena: 1; - uint32_t tsens_int_ena: 1; - uint32_t start_int_ena: 1; - uint32_t cocpu_int_ena: 1; - uint32_t ebreak_int_ena: 1; /*int enable entry*/ - uint32_t reserved5: 5; - uint32_t saradc_int_clr: 1; - uint32_t tsens_int_clr: 1; - uint32_t start_int_clr: 1; - uint32_t cocpu_int_clr: 1; - uint32_t ebreak_int_clr: 1; /*int clear entry*/ - uint32_t reserved15: 5; - uint32_t saradc_int: 1; /*int from saradc*/ - uint32_t tsens_int: 1; /*int from tsens*/ - uint32_t start_int: 1; /*int from start*/ - uint32_t cocpu_int: 1; /*int from register*/ - uint32_t ebreak_int: 1; /*int from ebreak*/ - uint32_t reserved25: 7; + 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 reserved9: 23; }; uint32_t val; - } sar_cocpu_int; - 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; - uint32_t reserved_d4; - uint32_t reserved_d8; - uint32_t reserved_dc; - uint32_t reserved_e0; - uint32_t reserved_e4; - uint32_t reserved_e8; - uint32_t reserved_ec; - uint32_t reserved_f0; - uint32_t reserved_f4; - uint32_t sar_nouse; /**/ + } 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 reserved9: 23; + }; + 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 reserved9: 23; + }; + 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 sar_date: 28; diff --git a/components/soc/esp32s2beta/include/soc/touch_channel.h b/components/soc/esp32s2beta/include/soc/touch_channel.h index a9aa838b4e..0ee4389118 100644 --- a/components/soc/esp32s2beta/include/soc/touch_channel.h +++ b/components/soc/esp32s2beta/include/soc/touch_channel.h @@ -16,34 +16,46 @@ #define _SOC_TOUCH_CHANNEL_H //Touch channels -#define TOUCH_PAD_GPIO4_CHANNEL TOUCH_PAD_NUM0 -#define TOUCH_PAD_NUM0_GPIO_NUM 4 - -#define TOUCH_PAD_GPIO0_CHANNEL TOUCH_PAD_NUM1 -#define TOUCH_PAD_NUM1_GPIO_NUM 0 +#define TOUCH_PAD_GPIO1_CHANNEL TOUCH_PAD_NUM1 +#define TOUCH_PAD_NUM1_GPIO_NUM 1 #define TOUCH_PAD_GPIO2_CHANNEL TOUCH_PAD_NUM2 #define TOUCH_PAD_NUM2_GPIO_NUM 2 -#define TOUCH_PAD_GPIO15_CHANNEL TOUCH_PAD_NUM3 -#define TOUCH_PAD_NUM3_GPIO_NUM 15 +#define TOUCH_PAD_GPIO3_CHANNEL TOUCH_PAD_NUM3 +#define TOUCH_PAD_NUM3_GPIO_NUM 3 -#define TOUCH_PAD_GPIO13_CHANNEL TOUCH_PAD_NUM4 -#define TOUCH_PAD_NUM4_GPIO_NUM 13 +#define TOUCH_PAD_GPIO4_CHANNEL TOUCH_PAD_NUM4 +#define TOUCH_PAD_NUM4_GPIO_NUM 4 -#define TOUCH_PAD_GPIO12_CHANNEL TOUCH_PAD_NUM5 -#define TOUCH_PAD_NUM5_GPIO_NUM 12 +#define TOUCH_PAD_GPIO5_CHANNEL TOUCH_PAD_NUM5 +#define TOUCH_PAD_NUM5_GPIO_NUM 5 -#define TOUCH_PAD_GPIO14_CHANNEL TOUCH_PAD_NUM6 -#define TOUCH_PAD_NUM6_GPIO_NUM 14 +#define TOUCH_PAD_GPIO6_CHANNEL TOUCH_PAD_NUM6 +#define TOUCH_PAD_NUM6_GPIO_NUM 6 -#define TOUCH_PAD_GPIO27_CHANNEL TOUCH_PAD_NUM7 -#define TOUCH_PAD_NUM7_GPIO_NUM 27 +#define TOUCH_PAD_GPIO7_CHANNEL TOUCH_PAD_NUM7 +#define TOUCH_PAD_NUM7_GPIO_NUM 7 -#define TOUCH_PAD_GPIO33_CHANNEL TOUCH_PAD_NUM8 -#define TOUCH_PAD_NUM8_GPIO_NUM 33 +#define TOUCH_PAD_GPIO8_CHANNEL TOUCH_PAD_NUM8 +#define TOUCH_PAD_NUM8_GPIO_NUM 8 -#define TOUCH_PAD_GPIO32_CHANNEL TOUCH_PAD_NUM9 -#define TOUCH_PAD_NUM9_GPIO_NUM 32 +#define TOUCH_PAD_GPIO9_CHANNEL TOUCH_PAD_NUM9 +#define TOUCH_PAD_NUM9_GPIO_NUM 9 + +#define TOUCH_PAD_GPIO10_CHANNEL TOUCH_PAD_NUM10 +#define TOUCH_PAD_NUM10_GPIO_NUM 10 + +#define TOUCH_PAD_GPIO11_CHANNEL TOUCH_PAD_NUM11 +#define TOUCH_PAD_NUM11_GPIO_NUM 11 + +#define TOUCH_PAD_GPIO12_CHANNEL TOUCH_PAD_NUM12 +#define TOUCH_PAD_NUM12_GPIO_NUM 12 + +#define TOUCH_PAD_GPIO13_CHANNEL TOUCH_PAD_NUM13 +#define TOUCH_PAD_NUM13_GPIO_NUM 13 + +#define TOUCH_PAD_GPIO14_CHANNEL TOUCH_PAD_NUM14 +#define TOUCH_PAD_NUM14_GPIO_NUM 14 #endif diff --git a/components/ulp/ulp.c b/components/ulp/ulp.c index fb5760ebd2..c19130b729 100644 --- a/components/ulp/ulp.c +++ b/components/ulp/ulp.c @@ -48,6 +48,7 @@ static const char* TAG = "ulp"; esp_err_t ulp_run(uint32_t entry_point) { +#if CONFIG_IDF_TARGET_ESP32 // disable ULP timer CLEAR_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN); // wait for at least 1 RTC_SLOW_CLK cycle @@ -64,6 +65,7 @@ esp_err_t ulp_run(uint32_t entry_point) SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_BIAS_SLEEP_FOLW_8M); // enable ULP timer SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN); +#endif return ESP_OK; } @@ -112,6 +114,7 @@ esp_err_t ulp_load_binary(uint32_t load_addr, const uint8_t* program_binary, siz esp_err_t ulp_set_wakeup_period(size_t period_index, uint32_t period_us) { +#if CONFIG_IDF_TARGET_ESP32 if (period_index > 4) { return ESP_ERR_INVALID_ARG; } @@ -128,5 +131,6 @@ esp_err_t ulp_set_wakeup_period(size_t period_index, uint32_t period_us) } REG_SET_FIELD(SENS_ULP_CP_SLEEP_CYC0_REG + period_index * sizeof(uint32_t), SENS_SLEEP_CYCLES_S0, (uint32_t) period_cycles); +#endif return ESP_OK; } diff --git a/examples/peripherals/adc/main/adc1_example_main.c b/examples/peripherals/adc/main/adc1_example_main.c index 00de0ab8bf..ddedbdc519 100644 --- a/examples/peripherals/adc/main/adc1_example_main.c +++ b/examples/peripherals/adc/main/adc1_example_main.c @@ -12,8 +12,9 @@ #include "freertos/task.h" #include "driver/gpio.h" #include "driver/adc.h" -#include "esp_adc_cal.h" +#if CONFIG_IDF_TARGET_ESP32 +#include "esp_adc_cal.h" #define DEFAULT_VREF 1100 //Use adc2_vref_to_gpio() to obtain a better estimate #define NO_OF_SAMPLES 64 //Multisampling @@ -89,4 +90,42 @@ void app_main() } } +#elif CONFIG_IDF_TARGET_ESP32S2BETA + +#define NO_OF_SAMPLES 64 //Multisampling + +static const adc_channel_t channel = ADC_CHANNEL_6; // GPIO7 if ADC1, GPIO17 if ADC2 +static const adc_atten_t atten = ADC_ATTEN_DB_11; // Detect 0 ~ 3.6v +static const adc_unit_t unit = ADC_UNIT_2; +static const adc_unit_t width = ADC_WIDTH_BIT_12; + +void app_main() +{ + //Configure ADC + if (unit == ADC_UNIT_1) { + adc1_config_width(width); + adc1_config_channel_atten(channel, atten); + } else { + adc2_config_channel_atten((adc2_channel_t)channel, atten); + } + + //Continuously sample ADC1 + while (1) { + uint32_t adc_reading = 0; + // Multisampling + for (int i = 0; i < NO_OF_SAMPLES; i++) { + if (unit == ADC_UNIT_1) { + adc_reading += adc1_get_raw((adc1_channel_t)channel); + } else { + int raw; + adc2_get_raw((adc2_channel_t)channel, width, &raw); + adc_reading += raw; + } + } + adc_reading /= NO_OF_SAMPLES; + printf("ADC%d CH%d Raw: %d\t\n", unit, channel, adc_reading); + vTaskDelay(pdMS_TO_TICKS(1000)); + } +} +#endif diff --git a/examples/peripherals/adc2/main/adc2_example_main.c b/examples/peripherals/adc2/main/adc2_example_main.c index ccf32b3d5f..bfd305b647 100644 --- a/examples/peripherals/adc2/main/adc2_example_main.c +++ b/examples/peripherals/adc2/main/adc2_example_main.c @@ -15,7 +15,6 @@ #include "driver/adc.h" #include "driver/dac.h" #include "esp_system.h" -#include "esp_adc_cal.h" #define DAC_EXAMPLE_CHANNEL CONFIG_EXAMPLE_DAC_CHANNEL #define ADC2_EXAMPLE_CHANNEL CONFIG_EXAMPLE_ADC2_CHANNEL diff --git a/examples/peripherals/temp_sensor/CMakeLists.txt b/examples/peripherals/temp_sensor/CMakeLists.txt new file mode 100644 index 0000000000..bd14a9425f --- /dev/null +++ b/examples/peripherals/temp_sensor/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(temp_sensor) diff --git a/examples/peripherals/temp_sensor/Makefile b/examples/peripherals/temp_sensor/Makefile new file mode 100644 index 0000000000..7cb5326291 --- /dev/null +++ b/examples/peripherals/temp_sensor/Makefile @@ -0,0 +1,9 @@ +# +# This is a project Makefile. It is assumed the directory this Makefile resides in is a +# project subdirectory. +# + +PROJECT_NAME := temp_sensor + +include $(IDF_PATH)/make/project.mk + diff --git a/examples/peripherals/temp_sensor/README.md b/examples/peripherals/temp_sensor/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/peripherals/temp_sensor/main/CMakeLists.txt b/examples/peripherals/temp_sensor/main/CMakeLists.txt new file mode 100644 index 0000000000..91425ac9f4 --- /dev/null +++ b/examples/peripherals/temp_sensor/main/CMakeLists.txt @@ -0,0 +1,4 @@ +set(COMPONENT_SRCS "temp_sensor_main.c") +set(COMPONENT_ADD_INCLUDEDIRS ".") + +register_component() diff --git a/examples/peripherals/temp_sensor/main/component.mk b/examples/peripherals/temp_sensor/main/component.mk new file mode 100644 index 0000000000..44bd2b5273 --- /dev/null +++ b/examples/peripherals/temp_sensor/main/component.mk @@ -0,0 +1,3 @@ +# +# Main Makefile. This is basically the same as a component makefile. +# diff --git a/examples/peripherals/temp_sensor/main/temp_sensor_main.c b/examples/peripherals/temp_sensor/main/temp_sensor_main.c new file mode 100644 index 0000000000..6d63d764a8 --- /dev/null +++ b/examples/peripherals/temp_sensor/main/temp_sensor_main.c @@ -0,0 +1,46 @@ +/* ADC1 Example + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include +#include "esp_log.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "driver/temp_sensor.h" + +#if CONFIG_IDF_TARGET_ESP32S2BETA + +static const char* TAG = "TempSensor"; + +void tempsensor_example(void *arg) +{ + // Initialize touch pad peripheral, it will start a timer to run a filter + ESP_LOGI(TAG, "Initializing temp sensor"); + uint8_t temp_out; + temp_sensor_t temp_sensor; + temp_sensor_get_config(&temp_sensor); + ESP_LOGI(TAG, "default dac %d, clk_div %d", temp_sensor.dac_offset, temp_sensor.clk_div); + temp_sensor.dac_offset = TEMP_SENSOR_DAC_DEFAULT; // DEFAULT: range:-10℃ ~ 80℃, error < 1℃. + temp_sensor_set_config(temp_sensor); + temp_sensor_start(); + ESP_LOGI(TAG, "temp sensor started"); + while(1) { + vTaskDelay(1000 / portTICK_RATE_MS); + temp_sensor_read(&temp_out); + ESP_LOGI(TAG, "temp out %d", temp_out); + } + ESP_LOGI(TAG, "test over"); + vTaskDelete(NULL); +} + +void app_main() +{ + xTaskCreate(tempsensor_example, "temp", 2048, NULL, 5, NULL); +} +#endif + diff --git a/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c b/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c index 1ed6bcabd3..2381ef8b2f 100644 --- a/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c +++ b/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c @@ -9,6 +9,7 @@ #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#include "freertos/queue.h" #include "esp_log.h" #include "driver/touch_pad.h" @@ -16,6 +17,8 @@ #include "soc/sens_periph.h" static const char* TAG = "Touch pad"; + +#if CONFIG_IDF_TARGET_ESP32 #define TOUCH_THRESH_NO_USE (0) #define TOUCH_THRESH_PERCENT (80) #define TOUCHPAD_FILTER_TOUCH_PERIOD (10) @@ -167,3 +170,187 @@ void app_main() // Start a task to show what pads have been touched xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); } +#elif CONFIG_IDF_TARGET_ESP32S2BETA + +static QueueHandle_t que_touch = NULL; +typedef struct touch_msg { + touch_pad_intr_mask_t intr_mask; + uint32_t pad_num; + uint32_t pad_status; + uint32_t pad_val; +}touch_event_t; + +#define TOUCH_BUTTON_NUM 4 +#define TOUCH_BUTTON_WATERPROOF_ENABLE 1 +#define TOUCH_BUTTON_DENOISE_ENABLE 1 + +static const touch_pad_t button[TOUCH_BUTTON_NUM] = { + TOUCH_PAD_NUM7, // 'SELECT' button. + TOUCH_PAD_NUM9, // 'MENU' button. + TOUCH_PAD_NUM11, // 'BACK' button. + TOUCH_PAD_NUM13, // Guard ring for waterproof design. + // if this pad be touched, other pads no response. +}; + +/* + * Touch threshold. The threshold determines the sensitivity of the touch. + * This threshold is derived by testing changes in readings from different touch channels. + * If (raw_data - baseline) > baseline * threshold, the pad be actived. + * If (raw_data - baseline) < baseline * threshold, the pad be inactived. + */ +static const float button_threshold[TOUCH_BUTTON_NUM] = { + 0.2, // 20%. + 0.2, // 20%. + 0.2, // 20%. + 0.1, // 10%. +}; + +/* + Handle an interrupt triggered when a pad is touched. + Recognize what pad has been touched and save it in a table. + */ +static void touchsensor_interrupt_cb(void * arg) +{ + int task_awoken = pdFALSE; + touch_event_t evt; + + evt.intr_mask = touch_pad_get_int_status(); + evt.pad_status = touch_pad_get_status(); + evt.pad_num = touch_pad_get_scan_curr(); + + if(evt.intr_mask & TOUCH_PAD_INTR_MASK_DONE) { + touch_pad_filter_baseline_read(evt.pad_num, &evt.pad_val); + } + xQueueSendFromISR(que_touch, &evt, &task_awoken); + if (task_awoken == pdTRUE) { + portYIELD_FROM_ISR(); + } +} + +static void tp_example_set_thresholds(void) +{ + uint32_t touch_value; + for (int i = 0; i Date: Thu, 13 Jun 2019 15:37:58 +0800 Subject: [PATCH 3/5] Driver: gpio and rtcio dirver update --- components/driver/include/driver/gpio.h | 8 ----- components/driver/rtc_module.c | 42 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/components/driver/include/driver/gpio.h b/components/driver/include/driver/gpio.h index fc746bbc1c..91242180bb 100644 --- a/components/driver/include/driver/gpio.h +++ b/components/driver/include/driver/gpio.h @@ -317,14 +317,6 @@ typedef enum { GPIO_NUM_27 = 27, /*!< GPIO27, input and output */ GPIO_NUM_28 = 28, /*!< GPIO28, input and output */ GPIO_NUM_32 = 32, /*!< GPIO32, input and output */ - GPIO_NUM_33 = 33, /*!< GPIO33, input and output */ - GPIO_NUM_34 = 34, /*!< GPIO34, input and output */ - GPIO_NUM_35 = 35, /*!< GPIO35, input and output */ - GPIO_NUM_36 = 36, /*!< GPIO36, input and output */ - GPIO_NUM_37 = 37, /*!< GPIO37, input and output */ - GPIO_NUM_38 = 38, /*!< GPIO38, input and output */ - GPIO_NUM_39 = 39, /*!< GPIO39, input and output */ - GPIO_NUM_40 = 40, /*!< GPIO40, input and output */ GPIO_NUM_41 = 41, /*!< GPIO41, input and output */ GPIO_NUM_42 = 42, /*!< GPIO42, input and output */ GPIO_NUM_43 = 43, /*!< GPIO43, input and output */ diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index 4c732660fd..eb7646837b 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -166,6 +166,48 @@ static rtc_gpio_info_t* rtc_gpio[RTC_GPIO_NUMBER] = { }; #endif +#if CONFIG_IDF_TARGET_ESP32S2BETA +typedef volatile struct { + uint32_t reserved0: 13; + uint32_t fun_ie: 1; /*input enable in work mode*/ + uint32_t slp_oe: 1; /*output enable in sleep mode*/ + uint32_t slp_ie: 1; /*input enable in sleep mode*/ + uint32_t slp_sel: 1; /*1: enable sleep mode during sleep 0: no sleep mode*/ + uint32_t fun_sel: 2; /*function sel*/ + uint32_t mux_sel: 1; /*1: use RTC GPIO 0: use digital GPIO*/ + uint32_t reserved20: 7; + uint32_t rue: 1; /*RUE*/ + uint32_t rde: 1; /*RDE*/ + uint32_t drv: 2; /*DRV*/ + uint32_t reserved31: 1; +} rtc_gpio_info_t; + +static rtc_gpio_info_t* rtc_gpio[RTC_GPIO_NUMBER] = { + &RTCIO.touch_pad[0].val, + &RTCIO.touch_pad[1].val, + &RTCIO.touch_pad[2].val, + &RTCIO.touch_pad[3].val, + &RTCIO.touch_pad[4].val, + &RTCIO.touch_pad[5].val, + &RTCIO.touch_pad[6].val, + &RTCIO.touch_pad[7].val, + &RTCIO.touch_pad[8].val, + &RTCIO.touch_pad[9].val, + &RTCIO.touch_pad[10].val, + &RTCIO.touch_pad[11].val, + &RTCIO.touch_pad[12].val, + &RTCIO.touch_pad[13].val, + &RTCIO.touch_pad[14].val, + &RTCIO.xtal_32p_pad.val, + &RTCIO.xtal_32n_pad.val, + &RTCIO.pad_dac[0].val, + &RTCIO.pad_dac[1].val, + &RTCIO.rtc_pad19.val, + &RTCIO.rtc_pad20.val, + &RTCIO.rtc_pad21.val +}; +#endif + typedef enum { ADC_CTRL_RTC = 0, ADC_CTRL_ULP = 1, From fbb0687b97b6983dad2524f0f7dd742fb664eb33 Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Thu, 13 Jun 2019 19:34:01 +0800 Subject: [PATCH 4/5] 1.update touch driver; 2.update adc/dac driver; 3.add temp sensor driver; --- components/driver/rtc_module.c | 42 ---------------------------------- 1 file changed, 42 deletions(-) diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index eb7646837b..4c732660fd 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -166,48 +166,6 @@ static rtc_gpio_info_t* rtc_gpio[RTC_GPIO_NUMBER] = { }; #endif -#if CONFIG_IDF_TARGET_ESP32S2BETA -typedef volatile struct { - uint32_t reserved0: 13; - uint32_t fun_ie: 1; /*input enable in work mode*/ - uint32_t slp_oe: 1; /*output enable in sleep mode*/ - uint32_t slp_ie: 1; /*input enable in sleep mode*/ - uint32_t slp_sel: 1; /*1: enable sleep mode during sleep 0: no sleep mode*/ - uint32_t fun_sel: 2; /*function sel*/ - uint32_t mux_sel: 1; /*1: use RTC GPIO 0: use digital GPIO*/ - uint32_t reserved20: 7; - uint32_t rue: 1; /*RUE*/ - uint32_t rde: 1; /*RDE*/ - uint32_t drv: 2; /*DRV*/ - uint32_t reserved31: 1; -} rtc_gpio_info_t; - -static rtc_gpio_info_t* rtc_gpio[RTC_GPIO_NUMBER] = { - &RTCIO.touch_pad[0].val, - &RTCIO.touch_pad[1].val, - &RTCIO.touch_pad[2].val, - &RTCIO.touch_pad[3].val, - &RTCIO.touch_pad[4].val, - &RTCIO.touch_pad[5].val, - &RTCIO.touch_pad[6].val, - &RTCIO.touch_pad[7].val, - &RTCIO.touch_pad[8].val, - &RTCIO.touch_pad[9].val, - &RTCIO.touch_pad[10].val, - &RTCIO.touch_pad[11].val, - &RTCIO.touch_pad[12].val, - &RTCIO.touch_pad[13].val, - &RTCIO.touch_pad[14].val, - &RTCIO.xtal_32p_pad.val, - &RTCIO.xtal_32n_pad.val, - &RTCIO.pad_dac[0].val, - &RTCIO.pad_dac[1].val, - &RTCIO.rtc_pad19.val, - &RTCIO.rtc_pad20.val, - &RTCIO.rtc_pad21.val -}; -#endif - typedef enum { ADC_CTRL_RTC = 0, ADC_CTRL_ULP = 1, From 572084821b74191ab31b14b77271c591cc80392a Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Thu, 20 Jun 2019 16:13:47 +0800 Subject: [PATCH 5/5] add Comment for touchpad --- .../src/bootloader_random.c | 7 - components/driver/CMakeLists.txt | 9 +- components/driver/component.mk | 3 +- .../driver/esp32s2beta/include/temp_sensor.h | 96 ++ .../driver/esp32s2beta/rtc_tempsensor.c | 144 +++ components/driver/esp32s2beta/rtc_touchpad.c | 674 +++++++++++++ components/driver/include/driver/adc.h | 68 +- components/driver/include/driver/dac.h | 12 +- components/driver/include/driver/gpio.h | 11 + .../driver/include/driver/temp_sensor.h | 36 - components/driver/include/driver/touch_pad.h | 920 +++++++++++++----- components/driver/rtc_module.c | 80 +- components/driver/rtc_tempsensor.c | 99 -- components/driver/rtc_touchpad.c | 738 -------------- components/esp32s2beta/sleep_modes.c | 43 +- .../esp32s2beta/include/soc/apb_ctrl_struct.h | 31 +- .../esp32s2beta/include/soc/rtc_i2c_struct.h | 8 +- .../soc/esp32s2beta/include/soc/sens_struct.h | 112 --- .../esp32s2beta/include/soc/syscon_struct.h | 543 +++++++++-- docs/Doxyfile | 1 + docs/en/api-reference/peripherals/index.rst | 1 + .../api-reference/peripherals/temp_sensor.rst | 32 + .../zh_CN/api-reference/peripherals/index.rst | 1 + .../api-reference/peripherals/temp_sensor.rst | 1 + .../peripherals/adc/main/adc1_example_main.c | 53 +- examples/peripherals/temp_sensor/README.md | 0 .../peripherals/temp_sensor/main/component.mk | 3 - .../CMakeLists.txt | 2 +- .../Makefile | 2 +- .../peripherals/temp_sensor_esp32s2/README.md | 27 + .../main/CMakeLists.txt | 0 .../temp_sensor_esp32s2/main/component.mk | 5 + .../main/temp_sensor_main.c | 34 +- .../touch_pad_interrupt/main/CMakeLists.txt | 3 +- .../touch_pad_interrupt/main/component.mk | 1 + .../main/esp32/tp_interrupt_main.c | 171 ++++ .../main/esp32s2beta/tp_interrupt_main.c | 201 ++++ .../main/tp_interrupt_main.c | 356 ------- .../touch_pad_read/main/CMakeLists.txt | 3 +- .../touch_pad_read/main/component.mk | 1 + .../main/{ => esp32}/tp_read_main.c | 72 -- .../main/esp32s2beta/tp_read_main.c | 82 ++ .../deep_sleep/main/deep_sleep_example_main.c | 46 +- 43 files changed, 2780 insertions(+), 1952 deletions(-) create mode 100644 components/driver/esp32s2beta/include/temp_sensor.h create mode 100644 components/driver/esp32s2beta/rtc_tempsensor.c create mode 100644 components/driver/esp32s2beta/rtc_touchpad.c delete mode 100644 components/driver/include/driver/temp_sensor.h delete mode 100644 components/driver/rtc_tempsensor.c delete mode 100644 components/driver/rtc_touchpad.c create mode 100644 docs/en/api-reference/peripherals/temp_sensor.rst create mode 100644 docs/zh_CN/api-reference/peripherals/temp_sensor.rst delete mode 100644 examples/peripherals/temp_sensor/README.md delete mode 100644 examples/peripherals/temp_sensor/main/component.mk rename examples/peripherals/{temp_sensor => temp_sensor_esp32s2}/CMakeLists.txt (88%) rename examples/peripherals/{temp_sensor => temp_sensor_esp32s2}/Makefile (81%) create mode 100644 examples/peripherals/temp_sensor_esp32s2/README.md rename examples/peripherals/{temp_sensor => temp_sensor_esp32s2}/main/CMakeLists.txt (100%) create mode 100644 examples/peripherals/temp_sensor_esp32s2/main/component.mk rename examples/peripherals/{temp_sensor => temp_sensor_esp32s2}/main/temp_sensor_main.c (57%) create mode 100644 examples/peripherals/touch_pad_interrupt/main/esp32/tp_interrupt_main.c create mode 100644 examples/peripherals/touch_pad_interrupt/main/esp32s2beta/tp_interrupt_main.c delete mode 100644 examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c rename examples/peripherals/touch_pad_read/main/{ => esp32}/tp_read_main.c (54%) create mode 100644 examples/peripherals/touch_pad_read/main/esp32s2beta/tp_read_main.c diff --git a/components/bootloader_support/src/bootloader_random.c b/components/bootloader_support/src/bootloader_random.c index 99766abd72..ed1eed16b2 100644 --- a/components/bootloader_support/src/bootloader_random.c +++ b/components/bootloader_support/src/bootloader_random.c @@ -20,7 +20,6 @@ #include "soc/dport_reg.h" #include "soc/i2s_periph.h" #include "esp_log.h" -#include "soc/io_mux_reg.h" #ifndef BOOTLOADER_BUILD #include "esp_system.h" @@ -89,12 +88,6 @@ void bootloader_random_enable(void) CLEAR_PERI_REG_MASK(SENS_SAR_START_FORCE_REG, SENS_ULP_CP_FORCE_START_TOP); CLEAR_PERI_REG_MASK(SENS_SAR_START_FORCE_REG, SENS_ULP_CP_START_TOP); #elif CONFIG_IDF_TARGET_ESP32S2BETA - /* Disable IO1 digital function for random function. */ - PIN_INPUT_DISABLE(PERIPHS_IO_MUX_GPIO1_U); - PIN_PULLDWN_DIS(PERIPHS_IO_MUX_GPIO1_U); - PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO1_U); - WRITE_PERI_REG(SYSCON_SARADC_SAR1_PATT_TAB1_REG, 0xFFFFFFFF); - SET_PERI_REG_MASK(SENS_SAR_MEAS2_CTRL1_REG, SENS_SAR2_EN_TEST); DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2S0_CLK_EN); CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_CTRL_REG, RTC_CNTL_ULP_CP_FORCE_START_TOP); diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 743d213322..94900e3606 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -6,8 +6,6 @@ set(COMPONENT_SRCS "can.c" "periph_ctrl.c" "rmt.c" "rtc_module.c" - "rtc_tempsensor.c" - "rtc_touchpad.c" "sdspi_crc.c" "sdspi_host.c" "sdspi_transaction.c" @@ -31,6 +29,13 @@ set(COMPONENT_ADD_INCLUDEDIRS "include") set(COMPONENT_PRIV_INCLUDEDIRS "include/driver") set(COMPONENT_REQUIRES esp_ringbuf soc) #cannot totally hide soc headers, since there are a lot arguments in the driver are chip-dependent +if(CONFIG_IDF_TARGET_ESP32S2BETA) + list(APPEND COMPONENT_SRCS "${CONFIG_IDF_TARGET}/rtc_tempsensor.c" + "${CONFIG_IDF_TARGET}/rtc_touchpad.c") + + list(APPEND COMPONENT_ADD_INCLUDEDIRS "${CONFIG_IDF_TARGET}/include") +endif() + register_component() diff --git a/components/driver/component.mk b/components/driver/component.mk index bff34c912e..31aa32c297 100644 --- a/components/driver/component.mk +++ b/components/driver/component.mk @@ -1,8 +1,9 @@ # # Component Makefile # +COMPONENT_SRCDIRS := . $(IDF_TARGET) -COMPONENT_ADD_INCLUDEDIRS := include +COMPONENT_ADD_INCLUDEDIRS := include $(IDF_TARGET)/include COMPONENT_PRIV_INCLUDEDIRS := include/driver diff --git a/components/driver/esp32s2beta/include/temp_sensor.h b/components/driver/esp32s2beta/include/temp_sensor.h new file mode 100644 index 0000000000..66142824c5 --- /dev/null +++ b/components/driver/esp32s2beta/include/temp_sensor.h @@ -0,0 +1,96 @@ +// 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; + +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 \ No newline at end of file diff --git a/components/driver/esp32s2beta/rtc_tempsensor.c b/components/driver/esp32s2beta/rtc_tempsensor.c new file mode 100644 index 0000000000..0f8d2a2d04 --- /dev/null +++ b/components/driver/esp32s2beta/rtc_tempsensor.c @@ -0,0 +1,144 @@ +// 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_io_reg.h" +#include "soc/rtc_io_struct.h" +#include "soc/sens_reg.h" +#include "soc/sens_struct.h" +#include "temp_sensor.h" +#include "esp32s2beta/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) + +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) +{ + SENS.sar_tctrl.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); + tsens->dac_offset = SENS.sar_tctrl.tsens_dac; + for(int i=TSENS_DAC_L0; idac_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; +} \ No newline at end of file diff --git a/components/driver/esp32s2beta/rtc_touchpad.c b/components/driver/esp32s2beta/rtc_touchpad.c new file mode 100644 index 0000000000..f31de9e662 --- /dev/null +++ b/components/driver/esp32s2beta/rtc_touchpad.c @@ -0,0 +1,674 @@ +// 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 "esp_log.h" +#include "soc/rtc_periph.h" +#include "soc/sens_periph.h" +#include "soc/rtc_io_reg.h" +#include "soc/rtc_io_struct.h" +#include "soc/sens_reg.h" +#include "soc/sens_struct.h" +#include "soc/rtc_cntl_reg.h" +#include "soc/rtc_cntl_struct.h" +#include "soc/rtc.h" +#include "soc/periph_defs.h" +#include "rtc_io.h" +#include "touch_pad.h" +#include "freertos/FreeRTOS.h" +#include "freertos/xtensa_api.h" +#include "freertos/semphr.h" +#include "freertos/timers.h" +#include "esp_intr_alloc.h" +#include "sys/lock.h" +#include "driver/rtc_cntl.h" +#include "driver/gpio.h" +#include "sdkconfig.h" + +#include "esp32s2beta/rom/ets_sys.h" + +#ifndef NDEBUG +// Enable built-in checks in queue.h in debug builds +#define INVARIANTS +#endif +#include "sys/queue.h" + +#define TOUCH_PAD_FILTER_FACTOR_DEFAULT (4) // IIR filter coefficient. +#define TOUCH_PAD_SHIFT_DEFAULT (4) // Increase computing accuracy. +#define TOUCH_PAD_SHIFT_ROUND_DEFAULT (8) // ROUND = 2^(n-1); rounding off for fractional. +#define TOUCH_PAD_MEASURE_WAIT_DEFAULT (0xFF) // The timer frequency is 8Mhz, the max value is 0xff +#define DAC_ERR_STR_CHANNEL_ERROR "DAC channel error" + +#define RTC_MODULE_CHECK(a, str, ret_val) ({ \ + if (!(a)) { \ + ESP_LOGE(RTC_MODULE_TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \ + return (ret_val); \ + } \ +}) + +#define RTC_RES_CHECK(res, ret_val) ({ \ + if ( (res) != ESP_OK) { \ + ESP_LOGE(RTC_MODULE_TAG,"%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__);\ + return (ret_val); \ + } \ +}) + +static portMUX_TYPE rtc_spinlock = portMUX_INITIALIZER_UNLOCKED; +#define RTC_TOUCH_ENTER_CRITICAL() portENTER_CRITICAL(&rtc_spinlock) +#define RTC_TOUCH_EXIT_CRITICAL() portEXIT_CRITICAL(&rtc_spinlock) + +static SemaphoreHandle_t rtc_touch_mux = NULL; +static const char *RTC_MODULE_TAG = "RTC_MODULE"; + +/*--------------------------------------------------------------- + Touch Pad +---------------------------------------------------------------*/ +esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg, touch_pad_intr_mask_t intr_mask) +{ + assert(fn != NULL); + return rtc_isr_register(fn, arg, TOUCH_PAD_INTR_MASK_ALL & (intr_mask << RTC_CNTL_TOUCH_DONE_INT_ENA_S)); +} + +esp_err_t touch_pad_isr_deregister(intr_handler_t fn, void *arg) +{ + return rtc_isr_deregister(fn, arg); +} + +esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_times) +{ + RTC_TOUCH_ENTER_CRITICAL(); + // touch sensor sleep cycle Time = sleep_cycle / RTC_SLOW_CLK( can be 150k or 32k depending on the options) + RTCCNTL.touch_ctrl1.touch_sleep_cycles = sleep_cycle; + //The times of charge and discharge in each measure process of touch channels. + RTCCNTL.touch_ctrl1.touch_meas_num = meas_times; + //the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD + RTCCNTL.touch_ctrl2.touch_xpd_wait = TOUCH_PAD_MEASURE_WAIT_DEFAULT; //wait volt stable + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_times) +{ + if (sleep_cycle) { + *sleep_cycle = RTCCNTL.touch_ctrl1.touch_sleep_cycles; + } + if (meas_times) { + *meas_times = RTCCNTL.touch_ctrl1.touch_meas_num; + } + return ESP_OK; +} + +esp_err_t touch_pad_set_inactive_connect(touch_pad_conn_type_t type) +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_scan_ctrl.touch_inactive_connection = type; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_get_inactive_connect(touch_pad_conn_type_t *type) +{ + RTC_MODULE_CHECK(type != NULL, "parameter is NULL", ESP_ERR_INVALID_ARG); + *type = RTCCNTL.touch_scan_ctrl.touch_inactive_connection; + return ESP_OK; +} + +esp_err_t touch_pad_set_voltage(touch_high_volt_t refh, touch_low_volt_t refl, touch_volt_atten_t atten) +{ + RTC_TOUCH_ENTER_CRITICAL(); + if (refh > TOUCH_HVOLT_KEEP) { + RTCCNTL.touch_ctrl2.touch_drefh = refh; + } + if (refl > TOUCH_LVOLT_KEEP) { + RTCCNTL.touch_ctrl2.touch_drefl = refl; + } + if (atten > TOUCH_HVOLT_ATTEN_KEEP) { + RTCCNTL.touch_ctrl2.touch_drange = atten; + } + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_get_voltage(touch_high_volt_t *refh, touch_low_volt_t *refl, touch_volt_atten_t *atten) +{ + if (refh) { + *refh = RTCCNTL.touch_ctrl2.touch_drefh; + } + if (refl) { + *refl = RTCCNTL.touch_ctrl2.touch_drefl; + } + if (atten) { + *atten = RTCCNTL.touch_ctrl2.touch_drange; + } + return ESP_OK; +} + +esp_err_t touch_pad_set_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t slope, touch_tie_opt_t opt) +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCIO.touch_pad[touch_num].tie_opt = opt; + RTCIO.touch_pad[touch_num].dac = slope; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_get_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t *slope, touch_tie_opt_t *opt) +{ + if (slope) { + *slope = RTCIO.touch_pad[touch_num].dac; + } + if (opt) { + *opt = RTCIO.touch_pad[touch_num].tie_opt; + } + return ESP_OK; +} + +esp_err_t touch_pad_io_init(touch_pad_t touch_num) +{ + RTC_MODULE_CHECK(touch_num != TOUCH_DENOISE_CHANNEL, + "please use `touch_pad_denoise_enable` to set denoise channel", ESP_ERR_INVALID_ARG); + rtc_gpio_init(touch_num); + rtc_gpio_set_direction(touch_num, RTC_GPIO_MODE_DISABLED); + rtc_gpio_pulldown_dis(touch_num); + rtc_gpio_pullup_dis(touch_num); + return ESP_OK; +} + +esp_err_t touch_pad_wait_init_done() +{ + // TODO + return ESP_FAIL; +} + +esp_err_t touch_pad_fsm_start() +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_ctrl2.touch_clkgate_en = 1; //enable touch clock for FSM. or force enable. + SENS.sar_touch_chn_st.touch_channel_clr = TOUCH_PAD_BIT_MASK_MAX; // clear SENS_TOUCH_SLP_BASELINE + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_fsm_stop() +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_ctrl2.touch_start_en = 0; //stop touch fsm + RTCCNTL.touch_ctrl2.touch_slp_timer_en = 0; + RTCCNTL.touch_ctrl2.touch_clkgate_en = 0; //enable touch clock for FSM. or force enable. + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_set_fsm_mode(touch_fsm_mode_t mode) +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_ctrl2.touch_start_en = 0; //stop touch fsm + RTCCNTL.touch_ctrl2.touch_start_force = mode; + RTCCNTL.touch_ctrl2.touch_slp_timer_en = (mode == TOUCH_FSM_MODE_TIMER ? 1 : 0); + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_get_fsm_mode(touch_fsm_mode_t *mode) +{ + assert(mode != NULL); + *mode = RTCCNTL.touch_ctrl2.touch_start_force; + return ESP_OK; +} + +bool touch_pad_meas_is_done(void) +{ + return SENS.sar_touch_chn_st.touch_meas_done; +} + +esp_err_t touch_pad_sw_start(void) +{ + RTC_MODULE_CHECK((RTCCNTL.touch_ctrl2.touch_start_force == TOUCH_FSM_MODE_SW), + "touch fsm mode error", ESP_ERR_INVALID_STATE); + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_ctrl2.touch_start_en = 0; + RTCCNTL.touch_ctrl2.touch_start_en = 1; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_set_thresh(touch_pad_t touch_num, uint32_t threshold) +{ + RTC_MODULE_CHECK((touch_num < TOUCH_PAD_MAX) && (touch_num != TOUCH_DENOISE_CHANNEL), "touch num error", ESP_ERR_INVALID_ARG); + RTC_TOUCH_ENTER_CRITICAL(); + SENS.touch_thresh[touch_num - 1].thresh = threshold; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_get_thresh(touch_pad_t touch_num, uint32_t *threshold) +{ + if (threshold) { + *threshold = SENS.touch_thresh[touch_num - 1].thresh; + } + return ESP_OK; +} + +esp_err_t touch_pad_set_group_mask(uint16_t enable_mask) +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_scan_ctrl.touch_scan_pad_map |= (enable_mask & TOUCH_PAD_BIT_MASK_MAX); + SENS.sar_touch_conf.touch_outen |= (enable_mask & TOUCH_PAD_BIT_MASK_MAX); + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_get_group_mask(uint16_t *enable_mask) +{ + RTC_TOUCH_ENTER_CRITICAL(); + *enable_mask = SENS.sar_touch_conf.touch_outen \ + & RTCCNTL.touch_scan_ctrl.touch_scan_pad_map \ + & TOUCH_PAD_BIT_MASK_MAX; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_clear_group_mask(uint16_t enable_mask) +{ + RTC_TOUCH_ENTER_CRITICAL(); + SENS.sar_touch_conf.touch_outen &= ~(enable_mask & TOUCH_PAD_BIT_MASK_MAX); + RTCCNTL.touch_scan_ctrl.touch_scan_pad_map &= ~(enable_mask & TOUCH_PAD_BIT_MASK_MAX); + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +uint32_t IRAM_ATTR touch_pad_get_status(void) +{ + return (SENS.sar_touch_chn_st.touch_pad_active & TOUCH_PAD_BIT_MASK_MAX); +} + +static esp_err_t touch_pad_clear_status(void) +{ + SENS.sar_touch_conf.touch_status_clr = 1; + return ESP_OK; +} + +touch_pad_t IRAM_ATTR touch_pad_get_scan_curr(void) +{ + return (touch_pad_t)(SENS.sar_touch_status0.touch_scan_curr); +} + +esp_err_t touch_pad_intr_enable(touch_pad_intr_mask_t int_mask) +{ + RTC_TOUCH_ENTER_CRITICAL(); + if (int_mask & TOUCH_PAD_INTR_MASK_DONE) { + RTCCNTL.int_ena.rtc_touch_done = 1; + } + if (int_mask & TOUCH_PAD_INTR_MASK_ACTIVE) { + RTCCNTL.int_ena.rtc_touch_active = 1; + } + if (int_mask & TOUCH_PAD_INTR_MASK_INACTIVE) { + RTCCNTL.int_ena.rtc_touch_inactive = 1; + } + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_intr_disable(touch_pad_intr_mask_t int_mask) +{ + RTC_TOUCH_ENTER_CRITICAL(); + if (int_mask & TOUCH_PAD_INTR_MASK_DONE) { + RTCCNTL.int_ena.rtc_touch_done = 0; + } + if (int_mask & TOUCH_PAD_INTR_MASK_ACTIVE) { + RTCCNTL.int_ena.rtc_touch_active = 0; + } + if (int_mask & TOUCH_PAD_INTR_MASK_INACTIVE) { + RTCCNTL.int_ena.rtc_touch_inactive = 0; + } + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +uint32_t touch_pad_intr_status_get_mask() +{ + return ((REG_READ(RTC_CNTL_INT_ST_REG) >> (RTC_CNTL_TOUCH_DONE_INT_ST_S)) & TOUCH_PAD_INTR_MASK_ALL); +} + +esp_err_t touch_pad_config(touch_pad_t touch_num) +{ + RTC_MODULE_CHECK(touch_num != TOUCH_DENOISE_CHANNEL, \ + "please use `touch_pad_denoise_enable` to set denoise channel", ESP_ERR_INVALID_ARG); + touch_pad_io_init(touch_num); + touch_pad_set_cnt_mode(touch_num, TOUCH_PAD_SLOPE_7, TOUCH_PAD_TIE_OPT_LOW); + touch_pad_set_thresh(touch_num, TOUCH_PAD_THRESHOLD_MAX); + touch_pad_set_group_mask(BIT(touch_num)); + return ESP_OK; +} + +esp_err_t touch_pad_init() +{ + if (rtc_touch_mux == NULL) { + rtc_touch_mux = xSemaphoreCreateMutex(); + } + if (rtc_touch_mux == NULL) { + return ESP_ERR_NO_MEM; + } + touch_pad_intr_disable(TOUCH_PAD_INTR_ALL); + touch_pad_clear_group_mask(TOUCH_PAD_BIT_MASK_MAX); + touch_pad_clear_status(); + touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_MEASURE_CYCLE_DEFAULT); + // Set reference voltage for charging/discharging + touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V5); + touch_pad_set_inactive_connect(TOUCH_PAD_CONN_GND); + return ESP_OK; +} + +esp_err_t touch_pad_deinit() +{ + RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); + touch_pad_fsm_stop(); + touch_pad_clear_status(); + touch_pad_intr_disable(TOUCH_PAD_INTR_ALL); + xSemaphoreGive(rtc_touch_mux); + vSemaphoreDelete(rtc_touch_mux); + rtc_touch_mux = NULL; + return ESP_OK; +} + +esp_err_t IRAM_ATTR touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data) +{ + if (raw_data) { + *raw_data = SENS.touch_meas[touch_num].meas_out; + } + return ESP_OK; +} + + +esp_err_t IRAM_ATTR touch_pad_filter_baseline_read(touch_pad_t touch_num, uint32_t *basedata) +{ + RTC_MODULE_CHECK(touch_num != TOUCH_DENOISE_CHANNEL, "denoise channel don't support", ESP_ERR_INVALID_ARG); + if (basedata) { + *basedata = SENS.sar_touch_status[touch_num - 1].touch_pad_baseline; + } + return ESP_OK; +} + +esp_err_t touch_pad_filter_debounce_read(touch_pad_t touch_num, uint32_t *debounce) +{ + RTC_MODULE_CHECK(touch_num != TOUCH_DENOISE_CHANNEL, "denoise channel don't support", ESP_ERR_INVALID_ARG); + if (debounce) { + *debounce = SENS.sar_touch_status[touch_num - 1].touch_pad_debounce; + } + return ESP_OK; +} + +/* Should be call after clk enable and filter enable. */ +esp_err_t touch_pad_filter_baseline_reset(touch_pad_t touch_num) +{ + RTC_TOUCH_ENTER_CRITICAL(); + if (touch_num == TOUCH_PAD_MAX) { + SENS.sar_touch_chn_st.touch_channel_clr = TOUCH_PAD_BIT_MASK_MAX; + } else { + SENS.sar_touch_chn_st.touch_channel_clr = BIT(touch_num); + } + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info) +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_filter_ctrl.touch_filter_mode = filter_info->mode; + RTCCNTL.touch_filter_ctrl.touch_debounce = filter_info->debounce_cnt; + RTCCNTL.touch_filter_ctrl.touch_hysteresis = filter_info->hysteresis_thr; + RTCCNTL.touch_filter_ctrl.touch_noise_thres = filter_info->noise_thr; + RTCCNTL.touch_filter_ctrl.touch_neg_noise_thres = filter_info->noise_neg_thr; + RTCCNTL.touch_filter_ctrl.touch_neg_noise_limit = filter_info->neg_noise_limit; + RTCCNTL.touch_filter_ctrl.touch_jitter_step = filter_info->jitter_step; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info) +{ + RTC_TOUCH_ENTER_CRITICAL(); + filter_info->mode = RTCCNTL.touch_filter_ctrl.touch_filter_mode; + filter_info->debounce_cnt = RTCCNTL.touch_filter_ctrl.touch_debounce; + filter_info->hysteresis_thr = RTCCNTL.touch_filter_ctrl.touch_hysteresis; + filter_info->noise_thr = RTCCNTL.touch_filter_ctrl.touch_noise_thres; + filter_info->noise_neg_thr = RTCCNTL.touch_filter_ctrl.touch_neg_noise_thres; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_filter_enable() +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_filter_ctrl.touch_filter_en = 1; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_filter_disable() +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_filter_ctrl.touch_filter_en = 0; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_enable() +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_scan_ctrl.touch_scan_pad_map &= ~(BIT(TOUCH_DENOISE_CHANNEL)); + RTCCNTL.touch_scan_ctrl.touch_denoise_en = 1; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_disable() +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_scan_ctrl.touch_denoise_en = 0; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t denoise) +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCIO.touch_pad[TOUCH_DENOISE_CHANNEL].tie_opt = TOUCH_PAD_TIE_OPT_LOW; + RTCIO.touch_pad[TOUCH_DENOISE_CHANNEL].dac = TOUCH_PAD_SLOPE_7; + RTCCNTL.touch_ctrl2.touch_refc = denoise.cap_level; + RTCCNTL.touch_scan_ctrl.touch_denoise_res = denoise.grade; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise) +{ + RTC_TOUCH_ENTER_CRITICAL(); + denoise->grade = RTCCNTL.touch_scan_ctrl.touch_denoise_res; + denoise->cap_level = RTCCNTL.touch_ctrl2.touch_refc; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_denoise_data_get(uint32_t *data) +{ + if (data) { + *data = SENS.sar_touch_status0.touch_denoise_data; + } + return ESP_OK; +} + +esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t waterproof) +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_scan_ctrl.touch_out_ring = waterproof.guard_ring_pad; + RTCCNTL.touch_scan_ctrl.touch_bufdrv = waterproof.shield_driver; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof) +{ + if (waterproof) { + RTC_TOUCH_ENTER_CRITICAL(); + waterproof->guard_ring_pad = RTCCNTL.touch_scan_ctrl.touch_out_ring; + waterproof->shield_driver = RTCCNTL.touch_scan_ctrl.touch_bufdrv; + RTC_TOUCH_EXIT_CRITICAL(); + } + return ESP_OK; +} + +esp_err_t touch_pad_waterproof_enable() +{ + touch_pad_io_init(TOUCH_SHIELD_CHANNEL); + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_scan_ctrl.touch_scan_pad_map &= ~(BIT(TOUCH_SHIELD_CHANNEL)); + RTCCNTL.touch_scan_ctrl.touch_shield_pad_en = 1; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_waterproof_disable() +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_scan_ctrl.touch_shield_pad_en = 0; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_proximity_set_config(touch_pad_proximity_t proximity) +{ + RTC_TOUCH_ENTER_CRITICAL(); + if (proximity.select_pad0) { + SENS.sar_touch_conf.touch_approach_pad0 = proximity.select_pad0; + } + if (proximity.select_pad1) { + SENS.sar_touch_conf.touch_approach_pad1 = proximity.select_pad1; + } + if (proximity.select_pad2) { + SENS.sar_touch_conf.touch_approach_pad2 = proximity.select_pad2; + } + RTCCNTL.touch_approach.touch_approach_meas_time = proximity.meas_num; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_proximity_get_config(touch_pad_proximity_t *proximity) +{ + if (proximity) { + RTC_TOUCH_ENTER_CRITICAL(); + proximity->select_pad0 = SENS.sar_touch_conf.touch_approach_pad0; + proximity->select_pad1 = SENS.sar_touch_conf.touch_approach_pad1; + proximity->select_pad2 = SENS.sar_touch_conf.touch_approach_pad2; + proximity->meas_num = RTCCNTL.touch_approach.touch_approach_meas_time; + RTC_TOUCH_EXIT_CRITICAL(); + } else { + return ESP_ERR_INVALID_ARG; + } + return ESP_OK; +} + +esp_err_t touch_pad_proximity_get_meas_cnt(touch_pad_t touch_num, uint32_t *cnt) +{ + if (cnt == NULL) { + return ESP_ERR_INVALID_ARG; + } + if (SENS.sar_touch_conf.touch_approach_pad0 == touch_num) { + *cnt = SENS.sar_touch_status16.touch_approach_pad0_cnt; + } else if (SENS.sar_touch_conf.touch_approach_pad1 == touch_num) { + *cnt = SENS.sar_touch_status16.touch_approach_pad1_cnt; + } else if (SENS.sar_touch_conf.touch_approach_pad2 == touch_num) { + *cnt = SENS.sar_touch_status16.touch_approach_pad2_cnt; + } else { + return ESP_ERR_INVALID_ARG; + } + return ESP_OK; +} + +esp_err_t touch_pad_proximity_data_get(touch_pad_t touch_num, uint32_t *measure_out) +{ + if ((SENS.sar_touch_conf.touch_approach_pad0 != touch_num) + && (SENS.sar_touch_conf.touch_approach_pad1 != touch_num) + && (SENS.sar_touch_conf.touch_approach_pad2 != touch_num)) { + return ESP_ERR_INVALID_ARG; + } + if (ESP_OK != touch_pad_filter_baseline_read(touch_num, measure_out)) { + return ESP_ERR_INVALID_ARG; + } + return ESP_OK; +} + +esp_err_t touch_pad_reset() +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_ctrl2.touch_reset = 0; + RTCCNTL.touch_ctrl2.touch_reset = 1; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +/************** sleep pad setting ***********************/ + +esp_err_t touch_pad_sleep_channel_config(touch_pad_sleep_channel_t slp_config) +{ + RTC_TOUCH_ENTER_CRITICAL(); + RTCCNTL.touch_slp_thres.touch_slp_pad = slp_config.touch_num; + RTCCNTL.touch_slp_thres.touch_slp_th = slp_config.sleep_pad_threshold; + RTCCNTL.touch_slp_thres.touch_slp_approach_en = slp_config.en_proximity; + RTC_TOUCH_EXIT_CRITICAL(); + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_baseline_get(uint32_t *baseline) +{ + if (baseline) { + *baseline = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS15_REG, SENS_TOUCH_SLP_BASELINE); + } else { + return ESP_ERR_INVALID_ARG; + } + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_debounce_get(uint32_t *debounce) +{ + if (debounce) { + *debounce = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS15_REG, SENS_TOUCH_SLP_DEBOUNCE); + } else { + return ESP_ERR_INVALID_ARG; + } + return ESP_OK; +} + +esp_err_t touch_pad_sleep_channel_proximity_cnt_get(uint32_t *approach_cnt) +{ + if (approach_cnt) { + *approach_cnt = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS16_REG, SENS_TOUCH_SLP_APPROACH_CNT); + } else { + return ESP_ERR_INVALID_ARG; + } + return ESP_OK; +} + +esp_err_t touch_pad_get_wakeup_status(touch_pad_t *pad_num) +{ + if (pad_num) { + *pad_num = (touch_pad_t)RTCCNTL.touch_slp_thres.touch_slp_pad; + } else { + return ESP_ERR_INVALID_ARG; + } + return ESP_OK; +} \ No newline at end of file diff --git a/components/driver/include/driver/adc.h b/components/driver/include/driver/adc.h index a890a8ab22..bc108847d8 100644 --- a/components/driver/include/driver/adc.h +++ b/components/driver/include/driver/adc.h @@ -52,61 +52,37 @@ typedef enum { #define ADC_WIDTH_11Bit ADC_WIDTH_BIT_11 #define ADC_WIDTH_12Bit ADC_WIDTH_BIT_12 +typedef enum { + ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO36 (ESP32), GPIO1 (ESP32-S2) */ + ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO37 (ESP32), GPIO2 (ESP32-S2) */ + ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO38 (ESP32), GPIO3 (ESP32-S2) */ + ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO39 (ESP32), GPIO4 (ESP32-S2) */ + ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO32 (ESP32), GPIO5 (ESP32-S2) */ + ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO33 (ESP32), GPIO6 (ESP32-S2) */ + ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO34 (ESP32), GPIO7 (ESP32-S2) */ + ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO35 (ESP32), GPIO8 (ESP32-S2) */ #if CONFIG_IDF_TARGET_ESP32 -typedef enum { - ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO36 */ - ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO37 */ - ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO38 */ - ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO39 */ - ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO32 */ - ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO33 */ - ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO34 */ - ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO35 */ ADC1_CHANNEL_MAX, -} adc1_channel_t; - -typedef enum { - ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO4 */ - ADC2_CHANNEL_1, /*!< ADC2 channel 1 is GPIO0 */ - ADC2_CHANNEL_2, /*!< ADC2 channel 2 is GPIO2 */ - ADC2_CHANNEL_3, /*!< ADC2 channel 3 is GPIO15 */ - ADC2_CHANNEL_4, /*!< ADC2 channel 4 is GPIO13 */ - ADC2_CHANNEL_5, /*!< ADC2 channel 5 is GPIO12 */ - ADC2_CHANNEL_6, /*!< ADC2 channel 6 is GPIO14 */ - ADC2_CHANNEL_7, /*!< ADC2 channel 7 is GPIO27 */ - ADC2_CHANNEL_8, /*!< ADC2 channel 8 is GPIO25 */ - ADC2_CHANNEL_9, /*!< ADC2 channel 9 is GPIO26 */ - ADC2_CHANNEL_MAX, -} adc2_channel_t; #elif CONFIG_IDF_TARGET_ESP32S2BETA -typedef enum { - ADC1_CHANNEL_0 = 0, /*!< ADC1 channel 0 is GPIO1 */ - ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO2 */ - ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO3 */ - ADC1_CHANNEL_3, /*!< ADC1 channel 3 is GPIO4 */ - ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO5 */ - ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO6 */ - ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO7 */ - ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO8 */ - ADC1_CHANNEL_8, /*!< ADC1 channel 6 is GPIO9 */ - ADC1_CHANNEL_9, /*!< ADC1 channel 7 is GPIO10 */ + ADC1_CHANNEL_8, /*!< ADC1 channel 6 is GPIO9 (ESP32-S2)*/ + ADC1_CHANNEL_9, /*!< ADC1 channel 7 is GPIO10 (ESP32-S2) */ ADC1_CHANNEL_MAX, +#endif } adc1_channel_t; typedef enum { - ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO11 */ - ADC2_CHANNEL_1, /*!< ADC2 channel 1 is GPIO12 */ - ADC2_CHANNEL_2, /*!< ADC2 channel 2 is GPIO13 */ - ADC2_CHANNEL_3, /*!< ADC2 channel 3 is GPIO14 */ - ADC2_CHANNEL_4, /*!< ADC2 channel 4 is GPIO15 */ - ADC2_CHANNEL_5, /*!< ADC2 channel 5 is GPIO16 */ - ADC2_CHANNEL_6, /*!< ADC2 channel 6 is GPIO17 */ - ADC2_CHANNEL_7, /*!< ADC2 channel 7 is GPIO18 */ - ADC2_CHANNEL_8, /*!< ADC2 channel 8 is GPIO19 */ - ADC2_CHANNEL_9, /*!< ADC2 channel 9 is GPIO20 */ + ADC2_CHANNEL_0 = 0, /*!< ADC2 channel 0 is GPIO4 (ESP32), GPIO11 (ESP32-S2) */ + ADC2_CHANNEL_1, /*!< ADC2 channel 1 is GPIO0 (ESP32), GPIO12 (ESP32-S2) */ + ADC2_CHANNEL_2, /*!< ADC2 channel 2 is GPIO2 (ESP32), GPIO13 (ESP32-S2) */ + ADC2_CHANNEL_3, /*!< ADC2 channel 3 is GPIO15 (ESP32), GPIO14 (ESP32-S2) */ + ADC2_CHANNEL_4, /*!< ADC2 channel 4 is GPIO13 (ESP32), GPIO15 (ESP32-S2) */ + ADC2_CHANNEL_5, /*!< ADC2 channel 5 is GPIO12 (ESP32), GPIO16 (ESP32-S2) */ + ADC2_CHANNEL_6, /*!< ADC2 channel 6 is GPIO14 (ESP32), GPIO17 (ESP32-S2) */ + ADC2_CHANNEL_7, /*!< ADC2 channel 7 is GPIO27 (ESP32), GPIO18 (ESP32-S2) */ + ADC2_CHANNEL_8, /*!< ADC2 channel 8 is GPIO25 (ESP32), GPIO19 (ESP32-S2) */ + ADC2_CHANNEL_9, /*!< ADC2 channel 9 is GPIO26 (ESP32), GPIO20 (ESP32-S2) */ ADC2_CHANNEL_MAX, } adc2_channel_t; -#endif typedef enum { ADC_CHANNEL_0 = 0, /*!< ADC channel */ diff --git a/components/driver/include/driver/dac.h b/components/driver/include/driver/dac.h index cdde967398..8318d9cb05 100644 --- a/components/driver/include/driver/dac.h +++ b/components/driver/include/driver/dac.h @@ -23,19 +23,11 @@ extern "C" { #include "esp_err.h" #include "soc/dac_periph.h" -#if CONFIG_IDF_TARGET_ESP32 typedef enum { - DAC_CHANNEL_1 = 1, /*!< DAC channel 1 is GPIO25 */ - DAC_CHANNEL_2, /*!< DAC channel 2 is GPIO26 */ + DAC_CHANNEL_1 = 1, /*!< DAC channel 1 is GPIO25 (ESP32), GPIO17 (ESP32-S2) */ + DAC_CHANNEL_2, /*!< DAC channel 2 is GPIO26 (ESP32), GPIO18 (ESP32-S2) */ DAC_CHANNEL_MAX, } dac_channel_t; -#elif CONFIG_IDF_TARGET_ESP32S2BETA -typedef enum { - DAC_CHANNEL_1 = 1, /*!< DAC channel 1 is GPIO17 */ - DAC_CHANNEL_2, /*!< DAC channel 2 is GPIO18 */ - DAC_CHANNEL_MAX, -} dac_channel_t; -#endif /** * @brief Get the gpio number of a specific DAC channel. diff --git a/components/driver/include/driver/gpio.h b/components/driver/include/driver/gpio.h index 91242180bb..87c68b95d4 100644 --- a/components/driver/include/driver/gpio.h +++ b/components/driver/include/driver/gpio.h @@ -316,7 +316,18 @@ typedef enum { GPIO_NUM_26 = 26, /*!< GPIO26, input and output */ GPIO_NUM_27 = 27, /*!< GPIO27, input and output */ GPIO_NUM_28 = 28, /*!< GPIO28, input and output */ + GPIO_NUM_29 = 29, /*!< GPIO29, input and output */ + GPIO_NUM_30 = 30, /*!< GPIO30, input and output */ + GPIO_NUM_31 = 31, /*!< GPIO31, input and output */ GPIO_NUM_32 = 32, /*!< GPIO32, input and output */ + GPIO_NUM_33 = 33, /*!< GPIO33, input and output */ + GPIO_NUM_34 = 34, /*!< GPIO34, input and output */ + GPIO_NUM_35 = 35, /*!< GPIO35, input and output */ + GPIO_NUM_36 = 36, /*!< GPIO36, input and output */ + GPIO_NUM_37 = 37, /*!< GPIO37, input and output */ + GPIO_NUM_38 = 38, /*!< GPIO38, input and output */ + GPIO_NUM_39 = 39, /*!< GPIO39, input and output */ + GPIO_NUM_40 = 40, /*!< GPIO40, input and output */ GPIO_NUM_41 = 41, /*!< GPIO41, input and output */ GPIO_NUM_42 = 42, /*!< GPIO42, input and output */ GPIO_NUM_43 = 43, /*!< GPIO43, input and output */ diff --git a/components/driver/include/driver/temp_sensor.h b/components/driver/include/driver/temp_sensor.h deleted file mode 100644 index eaf7c2cbcb..0000000000 --- a/components/driver/include/driver/temp_sensor.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _TEMP_SENSOR_H_ -#define _TEMP_SENSOR_H_ - -#include -#include "esp_err.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if CONFIG_IDF_TARGET_ESP32S2BETA -typedef enum { - TEMP_SENSOR_DAC_L0 = 5, // offset = -2, range: 50℃ ~ 125℃, error < 3℃. - TEMP_SENSOR_DAC_L1 = 7, // offset = -1, range: 20℃ ~ 100℃, error < 2℃. - TEMP_SENSOR_DAC_L2 = 15, // offset = 0, range:-10℃ ~ 80℃, error < 1℃. - TEMP_SENSOR_DAC_L3 = 11, // offset = 1, range:-30℃ ~ 50℃, error < 2℃. - TEMP_SENSOR_DAC_L4 = 10, // offset = 2, range:-40℃ ~ 20℃, error < 3℃. - TEMP_SENSOR_DAC_DEFAULT = TEMP_SENSOR_DAC_L2, -} temp_sensor_dac_offset_t;; - -typedef struct temp_sensor { - temp_sensor_dac_offset_t dac_offset; - uint8_t clk_div; -} temp_sensor_t; - -esp_err_t temp_sensor_set_config(temp_sensor_t temps); -esp_err_t temp_sensor_get_config(temp_sensor_t *temps); -esp_err_t temp_sensor_start(void); -esp_err_t temp_sensor_stop(void); -esp_err_t temp_sensor_read(uint8_t *temp_out); -#endif - -#ifdef __cplusplus -} -#endif -#endif \ No newline at end of file diff --git a/components/driver/include/driver/touch_pad.h b/components/driver/include/driver/touch_pad.h index bbfab6ab72..f0e8355e54 100644 --- a/components/driver/include/driver/touch_pad.h +++ b/components/driver/include/driver/touch_pad.h @@ -21,6 +21,7 @@ extern "C" { #include "esp_intr_alloc.h" #include "soc/touch_periph.h" +#if CONFIG_IDF_TARGET_ESP32 typedef enum { TOUCH_PAD_NUM0 = 0, /*!< Touch pad channel 0 is GPIO4 */ TOUCH_PAD_NUM1, /*!< Touch pad channel 1 is GPIO0 */ @@ -32,15 +33,34 @@ typedef enum { TOUCH_PAD_NUM7, /*!< Touch pad channel 7 is GPIO27*/ TOUCH_PAD_NUM8, /*!< Touch pad channel 8 is GPIO33*/ TOUCH_PAD_NUM9, /*!< Touch pad channel 9 is GPIO32*/ -#if CONFIG_IDF_TARGET_ESP32S2BETA - TOUCH_PAD_NUM10, /*!< Touch pad channel 6 is */ - TOUCH_PAD_NUM11, /*!< Touch pad channel 7 is */ - TOUCH_PAD_NUM12, /*!< Touch pad channel 8 is */ - TOUCH_PAD_NUM13, /*!< Touch pad channel 9 is */ - TOUCH_PAD_NUM14, /*!< Touch pad channel 9 is */ -#endif TOUCH_PAD_MAX, } touch_pad_t; +#elif CONFIG_IDF_TARGET_ESP32S2BETA +typedef enum { + TOUCH_PAD_NUM0 = 0, /*!< Internal channel, be used for denoise */ +#define TOUCH_DENOISE_CHANNEL TOUCH_PAD_NUM0 /*!< T0 is an internal channel that does not have a corresponding external GPIO. + T0 will work simultaneously with the measured channel Tn. Finally, the actual + measured value of Tn is the value after subtracting lower bits of T0. */ + TOUCH_PAD_NUM1, /*!< Touch channel 1 is GPIO1 */ + TOUCH_PAD_NUM2, /*!< Touch channel 2 is GPIO2 */ + TOUCH_PAD_NUM3, /*!< Touch channel 3 is GPIO3 */ + TOUCH_PAD_NUM4, /*!< Touch channel 4 is GPIO4 */ + TOUCH_PAD_NUM5, /*!< Touch channel 5 is GPIO5 */ + TOUCH_PAD_NUM6, /*!< Touch channel 6 is GPIO6 */ + TOUCH_PAD_NUM7, /*!< Touch channel 7 is GPIO7 */ + TOUCH_PAD_NUM8, /*!< Touch channel 8 is GPIO8 */ + TOUCH_PAD_NUM9, /*!< Touch channel 9 is GPIO9 */ + TOUCH_PAD_NUM10, /*!< Touch channel 9 is GPIO10 */ + TOUCH_PAD_NUM11, /*!< Touch channel 9 is GPIO11 */ + TOUCH_PAD_NUM12, /*!< Touch channel 9 is GPIO12 */ + TOUCH_PAD_NUM13, /*!< Touch channel 9 is GPIO13 */ + TOUCH_PAD_NUM14, /*!< Touch channel 9 is GPIO14 */ +#define TOUCH_SHIELD_CHANNEL TOUCH_PAD_NUM14 /*!< The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) + The shielded channel outputs the same signal as the channel being measured. + It is generally designed as a grid and is placed around the touch buttons. */ + TOUCH_PAD_MAX, +} touch_pad_t; +#endif typedef enum { TOUCH_HVOLT_KEEP = -1, /*! (touch threshold + hysteresis), the touch channel be touched. + If (raw data - baseline) < (touch threshold - hysteresis), the touch channel be released. + Range: 0 ~ 3. The coefficient is 0: 1/8; 1: 3/32; 2: 1/16; 3: 1/32 */ + uint8_t noise_thr; /*! (noise), the baseline stop updating. + If (raw data - baseline) < (noise), the baseline start updating. + Range: 0 ~ 3. The coefficient is 0: 1/2; 1: 3/8; 2: 1/4; 3: 1/8; */ + uint8_t noise_neg_thr; /*! (- negative noise), the baseline start updating. + If (raw data - baseline) < (- negative noise), the baseline stop updating. + Range: 0 ~ 3. The coefficient is 0: 1/2; 1: 3/8; 2: 1/4; 3: 1/8; */ + uint8_t neg_noise_limit; /*! BIT(14) + * @return + * - ESP_OK on success + */ +esp_err_t touch_pad_set_group_mask(uint16_t enable_mask); + +/** + * @brief Get the touch sensor scan group bit mask. + * @param enable_mask Pointer to bitmask of touch sensor scan group. + * e.g. TOUCH_PAD_NUM14 -> BIT(14) + * @return + * - ESP_OK on success + */ +esp_err_t touch_pad_get_group_mask(uint16_t *enable_mask); + +/** + * @brief Clear touch channel from touch sensor scan group. + * The working mode of the touch sensor is cyclically scanned. + * This function will clear the scan bits according to the given bitmask. + * @note If clear all mask, the FSM timer should be stop firsty. + * @param enable_mask bitmask of touch sensor scan group. + * e.g. TOUCH_PAD_NUM14 -> BIT(14) + * @return + * - ESP_OK on success + */ +esp_err_t touch_pad_clear_group_mask(uint16_t enable_mask); + +/** + * @brief Configure parameter for each touch channel. + * @note Touch num 0 is denoise channel, please use `touch_pad_denoise_enable` to set denoise function + * @param touch_num touch pad index + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG if argument wrong + * - ESP_FAIL if touch pad not initialized + */ +esp_err_t touch_pad_config(touch_pad_t touch_num); + +/** + * @brief Reset the whole of touch module. + * @note Call this funtion after `touch_pad_fsm_stop`, + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_reset(); + +/** + * @brief Check touch sensor measurement status. + * If doing measurement, the flag will be clear. + * If finish measurement. the flag will be set. + * @return + * - TRUE finish measurement + * - FALSE doing measurement + */ +bool touch_pad_meas_is_done(void); + +/** + * @brief Get the current scan channel. + * usually used in ISR to decide channel scaning, and then, get the current measurement value. + * The role of each bit is reference to type `touch_pad_intr_mask_t`. + * @return + * - touch channel number + */ +touch_pad_t touch_pad_get_scan_curr(); + +/** + * @brief Get the touch sensor interrupt status mask. usually used in ISR to decide interrupt type. + * The role of each bit is reference to type `touch_pad_intr_mask_t`. + * @return + * - touch intrrupt bit + */ +uint32_t touch_pad_intr_status_get_mask(); + +/** + * @brief Enable touch sensor interrupt. + * @param type interrupt type + * @return + * - ESP_OK on success + */ +esp_err_t touch_pad_intr_enable(touch_pad_intr_mask_t int_mask); + +/** + * @brief Disable touch sensor interrupt. + * @param type interrupt type + * @return + * - ESP_OK on success + */ +esp_err_t touch_pad_intr_disable(touch_pad_intr_mask_t int_mask); + +/** + * @brief Register touch-pad ISR. + * The handler will be attached to the same CPU core that this function is running on. + * @param fn Pointer to ISR handler + * @param arg Parameter for ISR + * @return + * - ESP_OK Success ; + * - ESP_ERR_INVALID_ARG GPIO error + * - ESP_ERR_NO_MEM No memory + */ +esp_err_t touch_pad_isr_register(intr_handler_t fn, void* arg, touch_pad_intr_mask_t intr_mask); + +/** + * @brief get raw data of touch sensor. + * @note After the initialization is complete, the "raw_data" is max value. You need to wait for a measurement + * cycle before you can read the correct touch value. + * @param touch_num touch pad index + * @param raw_data pointer to accept touch sensor value + * @return + * - ESP_OK Success + * - ESP_FAIL Touch channel 0 havent this parameter. + */ + +esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint32_t *raw_data); + +/** + * @brief get baseline of touch sensor. + * @note After the initialization is complete, the "touch_value" is max value. You need to wait for a measurement + * cycle before you can read the correct touch value. + * @param touch_num touch pad index + * @param touch_value pointer to accept touch sensor value + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG Touch channel 0 havent this parameter. + */ +esp_err_t touch_pad_filter_baseline_read(touch_pad_t touch_num, uint32_t *basedata); + +/** + * @brief Reset baseline to raw data of touch sensor. + * @param touch_num touch pad index + * - TOUCH_PAD_MAX Reset basaline of all channels + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_filter_baseline_reset(touch_pad_t touch_num); + +/** + * @brief get debounce count of touch sensor. + * @param touch_num touch pad index + * @param debounce pointer to debounce value + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG Touch channel 0 havent this parameter. + */ +esp_err_t touch_pad_filter_debounce_read(touch_pad_t touch_num, uint32_t *debounce); + +/** + * @brief set parameter of touch sensor filter and detection algorithm. + * For more details on the detection algorithm, please refer to the application documentation. + * @param filter_info select filter type and threshold of detection algorithm + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_filter_set_config(touch_filter_config_t *filter_info); + +/** + * @brief get parameter of touch sensor filter and detection algorithm. + * For more details on the detection algorithm, please refer to the application documentation. + * @param filter_info select filter type and threshold of detection algorithm + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info); + +/** + * @brief enable touch sensor filter and detection algorithm. + * For more details on the detection algorithm, please refer to the application documentation. + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_filter_enable(); + +/** + * @brief diaable touch sensor filter and detection algorithm. + * For more details on the detection algorithm, please refer to the application documentation. + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_filter_disable(); + +/** + * @brief set parameter of denoise pad (TOUCH_PAD_NUM0). + * T0 is an internal channel that does not have a corresponding external GPIO. + * T0 will work simultaneously with the measured channel Tn. Finally, the actual + * measured value of Tn is the value after subtracting lower bits of T0. + * This denoise function filters out interference introduced on all channels, + * such as noise introduced by the power supply and external EMI. + * @param denoise parameter of denoise + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t denoise); + +/** + * @brief get parameter of denoise pad (TOUCH_PAD_NUM0). + * @param denoise Pointer to parameter of denoise + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise); + +/** + * @brief enable denoise function. + * T0 is an internal channel that does not have a corresponding external GPIO. + * T0 will work simultaneously with the measured channel Tn. Finally, the actual + * measured value of Tn is the value after subtracting lower bits of T0. + * This denoise function filters out interference introduced on all channels, + * such as noise introduced by the power supply and external EMI. + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_denoise_enable(); + +/** + * @brief disable denoise function. + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_denoise_disable(); + +/** + * @brief get denoise measure value (TOUCH_PAD_NUM0). + * @param denoise value of denoise + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_denoise_data_get(uint32_t *data); + +/** + * @brief set parameter of waterproof function. + * The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel. + * The shielded channel outputs the same signal as the channel being measured. + * It is generally designed as a grid and is placed around the touch buttons. + * The shielded channel does not follow the measurement signal of the protection channel. + * So that the guard channel can detect a large area of water. + * @param waterproof parameter of waterproof + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t waterproof); + +/** + * @brief get parameter of waterproof function. + * @param waterproof parameter of waterproof + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof); + +/** + * @brief Enable parameter of waterproof function. + * The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel. + * The shielded channel outputs the same signal as the channel being measured. + * It is generally designed as a grid and is placed around the touch buttons. + * The shielded channel does not follow the measurement signal of the protection channel. + * So that the guard channel can detect a large area of water. + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_waterproof_enable(); + +/** + * @brief Enable parameter of waterproof function. + * The waterproof function includes a shielded channel (TOUCH_PAD_NUM14) and a guard channel. + * The shielded channel outputs the same signal as the channel being measured. + * It is generally designed as a grid and is placed around the touch buttons. + * The shielded channel does not follow the measurement signal of the protection channel. + * So that the guard channel can detect a large area of water. + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_waterproof_disable(); + +/** + * @brief Set parameter of proximity channel. Three proximity sensing channels can be set. + * The proximity sensor measurement is the accumulation of touch channel measurements. + * @note If stop the proximity function for the channel, point this proximity channel to `TOUCH_PAD_NUM0`. + * @param proximity parameter of proximity + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_proximity_set_config(touch_pad_proximity_t proximity); + +/** + * @brief Get parameter of proximity channel. Three proximity sensing channels can be set. + * The proximity sensor measurement is the accumulation of touch channel measurements. + * @param proximity parameter of proximity + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_proximity_get_config(touch_pad_proximity_t *proximity); + +/** + * @brief Get measure count of proximity channel. + * The proximity sensor measurement is the accumulation of touch channel measurements. + * @param touch_num touch pad index + * @param proximity parameter of proximity + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG parameter is NULL + */ +esp_err_t touch_pad_proximity_get_meas_cnt(touch_pad_t touch_num, uint32_t *cnt); + +/** + * @brief Get the accumulated measurement of the proximity sensor. + * The proximity sensor measurement is the accumulation of touch channel measurements. + * @param touch_num touch pad index + * @param measure_out If the accumulation process does not end, the `measure_out` is the process value. + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_proximity_data_get(touch_pad_t touch_num, uint32_t *measure_out); + +/** + * @brief Set parameter of touch sensor in sleep mode. + * In order to achieve low power consumption in sleep mode, other circuits except the RTC part of the register are in a power-off state. + * Only one touch channel is supported in the sleep state, which can be used as a wake-up function. + * If in non-sleep mode, the sleep parameters do not work. + * @param slp_config touch pad config + * @return + * - ESP_OK Success + */ +esp_err_t touch_pad_sleep_channel_config(touch_pad_sleep_channel_t slp_config); + +/** + * @brief get baseline of touch sensor in sleep mode. + * @param baseline pointer to accept touch sensor baseline value + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG parameter is NULL + */ +esp_err_t touch_pad_sleep_channel_baseline_get(uint32_t *baseline); + +/** + * @brief get debounce of touch sensor in sleep mode. + * @param debounce pointer to accept touch sensor debounce value + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG parameter is NULL + */ +esp_err_t touch_pad_sleep_channel_debounce_get(uint32_t *debounce); + +/** + * @brief get proximity count of touch sensor in sleep mode. + * @param proximity_cnt pointer to accept touch sensor proximity count value + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG parameter is NULL + */ +esp_err_t touch_pad_sleep_channel_proximity_cnt_get(uint32_t *proximity_cnt); + +#endif // CONFIG_IDF_TARGET_ESP32S2BETA #ifdef __cplusplus } diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index 4c732660fd..c871405ca8 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -86,7 +86,9 @@ static const char *RTC_MODULE_TAG = "RTC_MODULE"; } }while (0) portMUX_TYPE rtc_spinlock = portMUX_INITIALIZER_UNLOCKED; +#if CONFIG_IDF_TARGET_ESP32 static SemaphoreHandle_t rtc_touch_mux = NULL; +#endif /* In ADC2, there're two locks used for different cases: 1. lock shared with app and WIFI: @@ -124,48 +126,6 @@ static uint16_t s_touch_pad_init_bit = 0x0000; static filter_cb_t s_filter_cb = NULL; #endif -#if CONFIG_IDF_TARGET_ESP32S2BETA -typedef volatile struct { - uint32_t reserved0: 13; - uint32_t fun_ie: 1; /*input enable in work mode*/ - uint32_t slp_oe: 1; /*output enable in sleep mode*/ - uint32_t slp_ie: 1; /*input enable in sleep mode*/ - uint32_t slp_sel: 1; /*1: enable sleep mode during sleep 0: no sleep mode*/ - uint32_t fun_sel: 2; /*function sel*/ - uint32_t mux_sel: 1; /*1: use RTC GPIO 0: use digital GPIO*/ - uint32_t reserved20: 7; - uint32_t rue: 1; /*RUE*/ - uint32_t rde: 1; /*RDE*/ - uint32_t drv: 2; /*DRV*/ - uint32_t reserved31: 1; -} rtc_gpio_info_t; - -static rtc_gpio_info_t* rtc_gpio[RTC_GPIO_NUMBER] = { - &RTCIO.touch_pad[0].val, - &RTCIO.touch_pad[1].val, - &RTCIO.touch_pad[2].val, - &RTCIO.touch_pad[3].val, - &RTCIO.touch_pad[4].val, - &RTCIO.touch_pad[5].val, - &RTCIO.touch_pad[6].val, - &RTCIO.touch_pad[7].val, - &RTCIO.touch_pad[8].val, - &RTCIO.touch_pad[9].val, - &RTCIO.touch_pad[10].val, - &RTCIO.touch_pad[11].val, - &RTCIO.touch_pad[12].val, - &RTCIO.touch_pad[13].val, - &RTCIO.touch_pad[14].val, - &RTCIO.xtal_32p_pad.val, - &RTCIO.xtal_32n_pad.val, - &RTCIO.pad_dac[0].val, - &RTCIO.pad_dac[1].val, - &RTCIO.rtc_pad19.val, - &RTCIO.rtc_pad20.val, - &RTCIO.rtc_pad21.val -}; -#endif - typedef enum { ADC_CTRL_RTC = 0, ADC_CTRL_ULP = 1, @@ -529,10 +489,13 @@ esp_err_t rtc_gpio_hold_dis(gpio_num_t gpio_num) esp_err_t rtc_gpio_isolate(gpio_num_t gpio_num) { +#if CONFIG_IDF_TARGET_ESP32 if (rtc_gpio_desc[gpio_num].reg == 0) { return ESP_ERR_INVALID_ARG; } - +#elif CONFIG_IDF_TARGET_ESP32S2BETA + RTC_MODULE_CHECK(rtc_gpio_is_valid_gpio(gpio_num), "RTC_GPIO number error", ESP_ERR_INVALID_ARG); +#endif rtc_gpio_pullup_dis(gpio_num); rtc_gpio_pulldown_dis(gpio_num); rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_DISABLED); @@ -994,11 +957,9 @@ uint32_t IRAM_ATTR touch_pad_get_status() return TOUCH_BITS_SWAP(status); } -esp_err_t IRAM_ATTR touch_pad_clear_status() +esp_err_t touch_pad_clear_status() { - portENTER_CRITICAL(&rtc_spinlock); SENS.sar_touch_ctrl2.touch_meas_en_clr = 1; - portEXIT_CRITICAL(&rtc_spinlock); return ESP_OK; } @@ -1281,6 +1242,7 @@ esp_err_t touch_pad_get_wakeup_status(touch_pad_t *pad_num) static esp_err_t adc_set_fsm_time(int rst_wait, int start_wait, int standby_wait, int sample_cycle) { portENTER_CRITICAL(&rtc_spinlock); +#if CONFIG_IDF_TARGET_ESP32 // Internal FSM reset wait time if (rst_wait >= 0) { SYSCON.saradc_fsm.rstb_wait = rst_wait; @@ -1293,6 +1255,20 @@ static esp_err_t adc_set_fsm_time(int rst_wait, int start_wait, int standby_wait if (standby_wait >= 0) { SYSCON.saradc_fsm.standby_wait = standby_wait; } +#elif CONFIG_IDF_TARGET_ESP32S2BETA + // Internal FSM reset wait time + if (rst_wait >= 0) { + SYSCON.saradc_fsm_wait.rstb_wait = rst_wait; + } + // Internal FSM start wait time + if (start_wait >= 0) { + SYSCON.saradc_fsm_wait.xpd_wait = start_wait; + } + // Internal FSM standby wait time + if (standby_wait >= 0) { + SYSCON.saradc_fsm_wait.standby_wait = standby_wait; + } +#endif // Internal FSM standby sample cycle if (sample_cycle >= 0) { SYSCON.saradc_fsm.sample_cycle = sample_cycle; @@ -1617,31 +1593,19 @@ static void adc_set_controller(adc_unit_t unit, adc_controller_t ctrl ) case ADC_CTRL_RTC: SENS.sar_meas2_ctrl2.meas2_start_force = true; //RTC controller controls the ADC,not ulp coprocessor SENS.sar_meas2_ctrl2.sar2_en_pad_force = true; //RTC controller controls the data port, not ulp coprocessor - // SENS.sar_read_ctrl2.sar2_dig_force = false; //RTC controller controls the ADC, not digital controller - // SENS.sar_read_ctrl2.sar2_pwdet_force = false; //RTC controller controls the ADC, not PWDET - SYSCON.saradc_ctrl.sar2_mux = true; //RTC controller controls the ADC, not PWDET break; case ADC_CTRL_ULP: SENS.sar_meas2_ctrl2.meas2_start_force = false; SENS.sar_meas2_ctrl2.sar2_en_pad_force = false; - // SENS.sar_read_ctrl2.sar2_dig_force = false; - // SENS.sar_read_ctrl2.sar2_pwdet_force = false; - SYSCON.saradc_ctrl.sar2_mux = true; break; case ADC_CTRL_DIG: SENS.sar_meas2_ctrl2.meas2_start_force = true; SENS.sar_meas2_ctrl2.sar2_en_pad_force = true; - // SENS.sar_read_ctrl2.sar2_dig_force = true; - // SENS.sar_read_ctrl2.sar2_pwdet_force = false; - SYSCON.saradc_ctrl.sar2_mux = true; break; case ADC2_CTRL_PWDET: //currently only used by Wi-Fi SENS.sar_meas2_ctrl2.meas2_start_force = true; SENS.sar_meas2_ctrl2.sar2_en_pad_force = true; - // SENS.sar_read_ctrl2.sar2_dig_force = false; - // SENS.sar_read_ctrl2.sar2_pwdet_force = true; - SYSCON.saradc_ctrl.sar2_mux = false; break; default: ESP_LOGE(TAG, "adc2 selects invalid controller"); diff --git a/components/driver/rtc_tempsensor.c b/components/driver/rtc_tempsensor.c deleted file mode 100644 index 26d40fe211..0000000000 --- a/components/driver/rtc_tempsensor.c +++ /dev/null @@ -1,99 +0,0 @@ -// 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_io_reg.h" -#include "soc/rtc_io_struct.h" -#include "soc/sens_reg.h" -#include "soc/sens_struct.h" -#include "temp_sensor.h" -#if CONFIG_IDF_TARGET_ESP32 -#include "esp32/rom/ets_sys.h" -#elif CONFIG_IDF_TARGET_ESP32S2BETA -#include "esp32s2beta/rom/ets_sys.h" -#endif - -#if CONFIG_IDF_TARGET_ESP32S2BETA - -#define TEMP_SENSOR_XPD_WAIT_DEFAULT 0xFF /* Set wait cycle time(8MHz) from power up to reset enable. */ - -portMUX_TYPE rtc_temp_spinlock = portMUX_INITIALIZER_UNLOCKED; -static SemaphoreHandle_t rtc_touch_mux = NULL; - -esp_err_t temp_sensor_set_config(temp_sensor_t temps) -{ - portENTER_CRITICAL(&rtc_temp_spinlock); - SENS.sar_tctrl.tsens_dac = temps.dac_offset; - SENS.sar_tctrl.tsens_clk_div = temps.clk_div; - SENS.sar_tctrl.tsens_power_up_force = 1; - SENS.sar_tctrl2.tsens_xpd_wait = TEMP_SENSOR_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. - portEXIT_CRITICAL(&rtc_temp_spinlock); - return ESP_OK; -} - -esp_err_t temp_sensor_get_config(temp_sensor_t *temps) -{ - if(temps) { - portENTER_CRITICAL(&rtc_temp_spinlock); - temps->dac_offset = SENS.sar_tctrl.tsens_dac; - temps->clk_div = SENS.sar_tctrl.tsens_clk_div; - portEXIT_CRITICAL(&rtc_temp_spinlock); - return ESP_OK; - } else { - return ESP_FAIL; - } -} - -esp_err_t temp_sensor_start(void) -{ - portENTER_CRITICAL(&rtc_temp_spinlock); - SENS.sar_tctrl.tsens_dump_out = 0; - SENS.sar_tctrl2.tsens_clkgate_en = 1; - SENS.sar_tctrl.tsens_power_up = 1; - portEXIT_CRITICAL(&rtc_temp_spinlock); - return ESP_OK; -} - -esp_err_t temp_sensor_stop(void) -{ - portENTER_CRITICAL(&rtc_temp_spinlock); - SENS.sar_tctrl.tsens_power_up = 0; - SENS.sar_tctrl2.tsens_clkgate_en = 0; - portEXIT_CRITICAL(&rtc_temp_spinlock); - return ESP_OK; -} - -esp_err_t temp_sensor_read(uint8_t *temp_out) -{ - if(temp_out) { - portENTER_CRITICAL(&rtc_temp_spinlock); - SENS.sar_tctrl.tsens_dump_out = 1; - while(!SENS.sar_tctrl.tsens_ready); - *temp_out = SENS.sar_tctrl.tsens_out; - SENS.sar_tctrl.tsens_dump_out = 0; - portEXIT_CRITICAL(&rtc_temp_spinlock); - return ESP_OK; - } else { - return ESP_FAIL; - } -} -#endif \ No newline at end of file diff --git a/components/driver/rtc_touchpad.c b/components/driver/rtc_touchpad.c deleted file mode 100644 index 5843d5665d..0000000000 --- a/components/driver/rtc_touchpad.c +++ /dev/null @@ -1,738 +0,0 @@ -// 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 "esp_log.h" -#include "soc/rtc_periph.h" -#include "soc/sens_periph.h" -#include "soc/rtc_io_reg.h" -#include "soc/rtc_io_struct.h" -#include "soc/sens_reg.h" -#include "soc/sens_struct.h" -#include "soc/rtc_cntl_reg.h" -#include "soc/rtc_cntl_struct.h" -#include "soc/rtc.h" -#include "soc/periph_defs.h" -#include "rtc_io.h" -#include "touch_pad.h" -#include "freertos/FreeRTOS.h" -#include "freertos/xtensa_api.h" -#include "freertos/semphr.h" -#include "freertos/timers.h" -#include "esp_intr_alloc.h" -#include "sys/lock.h" -#include "driver/rtc_cntl.h" -#include "driver/gpio.h" -#include "sdkconfig.h" -#if CONFIG_IDF_TARGET_ESP32 -#include "esp32/rom/ets_sys.h" -#elif CONFIG_IDF_TARGET_ESP32S2BETA -#include "esp32s2beta/rom/ets_sys.h" -#endif - -#ifndef NDEBUG -// Enable built-in checks in queue.h in debug builds -#define INVARIANTS -#endif -#include "sys/queue.h" - -#if CONFIG_IDF_TARGET_ESP32S2BETA - -#define TOUCH_PAD_FILTER_FACTOR_DEFAULT (4) // IIR filter coefficient. -#define TOUCH_PAD_SHIFT_DEFAULT (4) // Increase computing accuracy. -#define TOUCH_PAD_SHIFT_ROUND_DEFAULT (8) // ROUND = 2^(n-1); rounding off for fractional. -#define DAC_ERR_STR_CHANNEL_ERROR "DAC channel error" - -static portMUX_TYPE rtc_spinlock = portMUX_INITIALIZER_UNLOCKED; -static const char *RTC_MODULE_TAG = "RTC_MODULE"; - -#define RTC_MODULE_CHECK(a, str, ret_val) if (!(a)) { \ - ESP_LOGE(RTC_MODULE_TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \ - return (ret_val); \ -} - -#define RTC_RES_CHECK(res, ret_val) if ( (a) != ESP_OK) { \ - ESP_LOGE(RTC_MODULE_TAG,"%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__); \ - return (ret_val); \ -} -static SemaphoreHandle_t rtc_touch_mux = NULL; - -// check if touch pad be inited. -static uint16_t s_touch_pad_init_bit = 0x0000; - -/*--------------------------------------------------------------- - Touch Pad ----------------------------------------------------------------*/ -esp_err_t touch_pad_isr_register(intr_handler_t fn, void* arg, touch_pad_intr_mask_t intr_mask) -{ - RTC_MODULE_CHECK(intr_mask < TOUCH_PAD_INTR_MASK_MAX, "intr mask err", ESP_ERR_INVALID_ARG); - RTC_MODULE_CHECK(fn, "Touch_Pad ISR null", ESP_ERR_INVALID_ARG); - return rtc_isr_register(fn, arg, intr_mask << RTC_CNTL_TOUCH_DONE_INT_ENA_S); -} - -esp_err_t touch_pad_isr_deregister(intr_handler_t fn, void *arg) -{ - return rtc_isr_deregister(fn, arg); -} - -esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_cycle) -{ - xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); - portENTER_CRITICAL(&rtc_spinlock); - // touch sensor sleep cycle Time = sleep_cycle / RTC_SLOW_CLK( can be 150k or 32k depending on the options) - RTCCNTL.touch_ctrl1.touch_sleep_cycles = sleep_cycle; - //touch sensor measure time= meas_cycle / 8Mhz - RTCCNTL.touch_ctrl1.touch_meas_num = meas_cycle; - //the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD - RTCCNTL.touch_ctrl2.touch_xpd_wait = 255; //wait volt stable - portEXIT_CRITICAL(&rtc_spinlock); - xSemaphoreGive(rtc_touch_mux); - return ESP_OK; -} - -esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_cycle) -{ - RTC_MODULE_CHECK(sleep_cycle != NULL, "parameter is NULL", ESP_ERR_INVALID_ARG); - RTC_MODULE_CHECK(meas_cycle != NULL, "parameter is NULL", ESP_ERR_INVALID_ARG); - portENTER_CRITICAL(&rtc_spinlock); - *sleep_cycle = RTCCNTL.touch_ctrl1.touch_sleep_cycles; - *meas_cycle = RTCCNTL.touch_ctrl1.touch_meas_num; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_set_inactive_connect(touch_pad_conn_type_t type) -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_scan_ctrl.touch_inactive_connection = type; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_get_inactive_connect(touch_pad_conn_type_t *type) -{ - if(type) { - *type = RTCCNTL.touch_scan_ctrl.touch_inactive_connection; - return ESP_FAIL; - } else { - return ESP_OK; - } -} - -esp_err_t touch_pad_set_voltage(touch_high_volt_t refh, touch_low_volt_t refl, touch_volt_atten_t atten) -{ - portENTER_CRITICAL(&rtc_spinlock); - if (refh > TOUCH_HVOLT_KEEP) { - RTCCNTL.touch_ctrl2.touch_drefh = refh; - } - if (refl > TOUCH_LVOLT_KEEP) { - RTCCNTL.touch_ctrl2.touch_drefl = refl; - } - if (atten > TOUCH_HVOLT_ATTEN_KEEP) { - RTCCNTL.touch_ctrl2.touch_drange = atten; - } - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_get_voltage(touch_high_volt_t *refh, touch_low_volt_t *refl, touch_volt_atten_t *atten) -{ - portENTER_CRITICAL(&rtc_spinlock); - if (refh) { - *refh = RTCCNTL.touch_ctrl2.touch_drefh; - } - if (refl) { - *refl = RTCCNTL.touch_ctrl2.touch_drefl; - } - if (atten) { - *atten = RTCCNTL.touch_ctrl2.touch_drange; - } - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_set_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t slope) -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCIO.touch_pad[touch_num].tie_opt = TOUCH_PAD_TIE_OPT_LOW; - RTCIO.touch_pad[touch_num].dac = slope; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_get_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t *slope) -{ - portENTER_CRITICAL(&rtc_spinlock); - if(slope) { - *slope = RTCIO.touch_pad[touch_num].dac; - } - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_io_init(touch_pad_t touch_num) -{ - RTC_MODULE_CHECK((touch_num < TOUCH_PAD_MAX), "touch IO error", ESP_ERR_INVALID_ARG); - RTC_MODULE_CHECK((touch_num > TOUCH_PAD_NUM0), "touch IO error", ESP_ERR_INVALID_ARG); - gpio_num_t gpio_num = GPIO_NUM_1; - gpio_num = touch_num; - rtc_gpio_init(gpio_num); - rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_DISABLED); - rtc_gpio_pulldown_dis(gpio_num); - rtc_gpio_pullup_dis(gpio_num); - return ESP_OK; -} - -esp_err_t touch_pad_wait_init_done() -{ - // TODO - return ESP_FAIL; -} - -/*touch_pad_fsm_start_vf, after set mask*/ -esp_err_t touch_pad_fsm_start(touch_fsm_mode_t mode) -{ - RTC_MODULE_CHECK((mode < TOUCH_FSM_MODE_MAX), "touch fsm mode error", ESP_ERR_INVALID_ARG); - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_ctrl2.touch_start_en = 0; //stop touch fsm - RTCCNTL.touch_ctrl2.touch_start_force = mode; - RTCCNTL.touch_ctrl2.touch_slp_timer_en = (mode == TOUCH_FSM_MODE_TIMER ? 1 : 0); - RTCCNTL.touch_ctrl2.touch_clkgate_en = 1; //enable touch clock for FSM. or force enable. - SENS.sar_touch_chn_st.touch_channel_clr = TOUCH_PAD_BIT_MASK_MAX; // clear baseline - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_fsm_stop() -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_ctrl2.touch_start_en = 0; //stop touch fsm - RTCCNTL.touch_ctrl2.touch_slp_timer_en = 0; - RTCCNTL.touch_ctrl2.touch_clkgate_en = 0; //enable touch clock for FSM. or force enable. - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_get_fsm_mode(touch_fsm_mode_t *mode) -{ - if (mode) { - *mode = RTCCNTL.touch_ctrl2.touch_start_force; - } - return ESP_OK; -} - -/* - * If doing measure, the flag will be self-clear. - * After measure, the flag will be set. - */ -uint8_t touch_pad_means_is_done() -{ - return SENS.sar_touch_chn_st.touch_meas_done; -} - -/* return the current scan channel. */ -esp_err_t touch_pad_sw_start(touch_pad_t *current_scan) -{ - RTC_MODULE_CHECK((RTCCNTL.touch_ctrl2.touch_start_force == TOUCH_FSM_MODE_SW), - "touch IO error", ESP_FAIL); - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_ctrl2.touch_start_en = 0; - RTCCNTL.touch_ctrl2.touch_start_en = 1; - portEXIT_CRITICAL(&rtc_spinlock); - if(current_scan) { - *current_scan = SENS.sar_touch_status0.touch_scan_curr; - } - return ESP_OK; -} - -/* If set "TOUCH_PAD_THRESHOLD_MAX", the filter is not triger. */ -esp_err_t touch_pad_set_thresh(touch_pad_t touch_num, uint32_t threshold) -{ - RTC_MODULE_CHECK((threshold != 0), "threshold error", ESP_ERR_INVALID_ARG); - RTC_MODULE_CHECK((touch_num < TOUCH_PAD_MAX), "touch IO error", ESP_ERR_INVALID_ARG); - RTC_MODULE_CHECK((touch_num > TOUCH_PAD_NUM0), "touch0 no thresh", ESP_ERR_INVALID_ARG); - portENTER_CRITICAL(&rtc_spinlock); - SENS.touch_thresh[touch_num-1].thresh = threshold; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_get_thresh(touch_pad_t touch_num, uint32_t *threshold) -{ - RTC_MODULE_CHECK((touch_num < TOUCH_PAD_MAX), "touch IO error", ESP_ERR_INVALID_ARG); - if (threshold) { - *threshold = SENS.touch_thresh[touch_num-1].thresh; - } - return ESP_OK; -} - -/* If set mask, the FSM timer should be stop firsty. - * Noitce: The touchpad that in scan map ,should be deinit digital function firstly. - * */ -esp_err_t touch_pad_set_group_mask(uint16_t enable_mask) -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_scan_ctrl.touch_scan_pad_map |= (enable_mask&TOUCH_PAD_BIT_MASK_MAX); - SENS.sar_touch_conf.touch_outen |= (enable_mask&TOUCH_PAD_BIT_MASK_MAX); - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_get_group_mask(uint16_t *enable_mask) -{ - portENTER_CRITICAL(&rtc_spinlock); - *enable_mask = SENS.sar_touch_conf.touch_outen \ - & RTCCNTL.touch_scan_ctrl.touch_scan_pad_map \ - & TOUCH_PAD_BIT_MASK_MAX; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -/* If clear all mask, the FSM timer should be stop firsty. */ -esp_err_t touch_pad_clear_group_mask(uint16_t enable_mask) -{ - portENTER_CRITICAL(&rtc_spinlock); - SENS.sar_touch_conf.touch_outen &= ~(enable_mask&TOUCH_PAD_BIT_MASK_MAX); - RTCCNTL.touch_scan_ctrl.touch_scan_pad_map &= ~(enable_mask&TOUCH_PAD_BIT_MASK_MAX); - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -uint32_t IRAM_ATTR touch_pad_get_int_status() -{ - return REG_READ(RTC_CNTL_INT_ST_REG) >> (RTC_CNTL_TOUCH_DONE_INT_ST_S) & (TOUCH_PAD_INTR_MASK_ALL); -} - -/* - * The "touch_pad_active" will be change auto. - * If status bit is 1, this pad is be active, else, this pad is inactive. - */ -uint32_t IRAM_ATTR touch_pad_get_status() -{ - return (SENS.sar_touch_chn_st.touch_pad_active & TOUCH_PAD_BIT_MASK_MAX); -} -// get current scan channel. note: in interrupt and set a litter sleep time. -uint32_t IRAM_ATTR touch_pad_get_scan_curr() -{ - return (SENS.sar_touch_status0.touch_scan_curr); -} - -/* - * Normaly, Should't call this function manual. . - */ -esp_err_t IRAM_ATTR touch_pad_clear_status() -{ - portENTER_CRITICAL(&rtc_spinlock); - SENS.sar_touch_conf.touch_status_clr = 1; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_intr_enable(touch_pad_intr_type_t type) -{ - portENTER_CRITICAL(&rtc_spinlock); - if(type == TOUCH_PAD_INTR_DONE) { - RTCCNTL.int_ena.rtc_touch_done = 1; - } else if(type == TOUCH_PAD_INTR_ACTIVE) { - RTCCNTL.int_ena.rtc_touch_active = 1; - } else if(type == TOUCH_PAD_INTR_INACTIVE) { - RTCCNTL.int_ena.rtc_touch_inactive = 1; - } else if(type == TOUCH_PAD_INTR_ALL){ - RTCCNTL.int_ena.rtc_touch_done = 1; - RTCCNTL.int_ena.rtc_touch_active = 1; - RTCCNTL.int_ena.rtc_touch_inactive = 1; - } else { - ESP_LOGE(RTC_MODULE_TAG, "no this intr type"); - } - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_intr_disable(touch_pad_intr_type_t type) -{ - portENTER_CRITICAL(&rtc_spinlock); - if(type == TOUCH_PAD_INTR_DONE) { - RTCCNTL.int_ena.rtc_touch_done = 0; - } else if(type == TOUCH_PAD_INTR_ACTIVE) { - RTCCNTL.int_ena.rtc_touch_active = 0; - } else if(type == TOUCH_PAD_INTR_INACTIVE) { - RTCCNTL.int_ena.rtc_touch_inactive = 0; - } else if(type == TOUCH_PAD_INTR_ALL){ - RTCCNTL.int_ena.rtc_touch_done = 0; - RTCCNTL.int_ena.rtc_touch_active = 0; - RTCCNTL.int_ena.rtc_touch_inactive = 0; - } else { - ESP_LOGE(RTC_MODULE_TAG, "no this intr type"); - } - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -uint32_t IRAM_ATTR touch_pad_intr_get_mask() -{ - return REG_READ(RTC_CNTL_INT_ENA_REG) >> (RTC_CNTL_TOUCH_DONE_INT_ENA_S) & (TOUCH_PAD_INTR_MASK_ALL); -} - -esp_err_t touch_pad_config(touch_pad_t touch_num) -{ - RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); - RTC_MODULE_CHECK(touch_num < TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG); - - touch_pad_io_init(touch_num); - touch_pad_set_cnt_mode(touch_num, TOUCH_PAD_SLOPE_7); - touch_pad_set_thresh(touch_num, TOUCH_PAD_THRESHOLD_MAX); - touch_pad_set_group_mask(BIT(touch_num)); - - return ESP_OK; -} - -esp_err_t touch_pad_init() -{ - if (rtc_touch_mux == NULL) { - rtc_touch_mux = xSemaphoreCreateMutex(); - } - if (rtc_touch_mux == NULL) { - return ESP_FAIL; - } - touch_pad_intr_disable(TOUCH_PAD_INTR_ALL); - touch_pad_clear_group_mask(TOUCH_PAD_BIT_MASK_MAX); - touch_pad_clear_status(); - touch_pad_set_meas_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT, TOUCH_PAD_MEASURE_CYCLE_DEFAULT); - // Set reference voltage for charging/discharging - touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V5); - touch_pad_set_inactive_connect(TOUCH_PAD_CONN_GND); - return ESP_OK; -} - -esp_err_t touch_pad_deinit() -{ - RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); - xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); - s_touch_pad_init_bit = 0x0000; - touch_pad_fsm_stop(); - touch_pad_clear_status(); - touch_pad_intr_disable(TOUCH_PAD_INTR_ALL); - xSemaphoreGive(rtc_touch_mux); - vSemaphoreDelete(rtc_touch_mux); - rtc_touch_mux = NULL; - return ESP_OK; -} - -/*raw data 的单位是时间,单位是 1/8MHz */ -IRAM_ATTR esp_err_t touch_pad_read_raw(touch_pad_t touch_num, uint32_t *raw_data) -{ - RTC_MODULE_CHECK(touch_num > TOUCH_PAD_NUM0, "Touch pad0 is forbidden", ESP_FAIL); - if (raw_data) { - *raw_data = SENS.touch_meas[touch_num].meas_out; - } - return ESP_OK; -} - - -IRAM_ATTR esp_err_t touch_pad_filter_baseline_read(touch_pad_t touch_num, uint32_t *basedata) -{ - RTC_MODULE_CHECK(touch_num > TOUCH_PAD_NUM0, "Touch pad0 is forbidden", ESP_FAIL); - if (basedata) { - *basedata = SENS.sar_touch_status[touch_num-1].touch_pad_baseline; - } - return ESP_OK; -} - -IRAM_ATTR esp_err_t touch_pad_read_debounce(touch_pad_t touch_num, uint32_t *debounce) -{ - RTC_MODULE_CHECK(touch_num > TOUCH_PAD_NUM0, "Touch pad0 is forbidden", ESP_FAIL); - if (debounce) { - *debounce = SENS.sar_touch_status[touch_num-1].touch_pad_debounce; - } - return ESP_OK; -} - -IRAM_ATTR esp_err_t touch_pad_read_thresh(touch_pad_t touch_num, uint32_t *thresh_out) -{ - RTC_MODULE_CHECK(touch_num > TOUCH_PAD_NUM0, "Touch pad0 is forbidden", ESP_FAIL); - if (thresh_out) { - *thresh_out = SENS.touch_thresh[touch_num-1].thresh; - } - return ESP_OK; -} - -/* Should be call after clk enable and filter enable. */ -esp_err_t touch_pad_filter_baseline_reset(touch_pad_t touch_num) -{ - RTC_MODULE_CHECK(touch_num <= TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG); - portENTER_CRITICAL(&rtc_spinlock); - if(touch_num == TOUCH_PAD_MAX) { - SENS.sar_touch_chn_st.touch_channel_clr = TOUCH_PAD_BIT_MASK_MAX; - } else { - SENS.sar_touch_chn_st.touch_channel_clr = BIT(touch_num); - } - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_filter_set_config(touch_filter_config_t filter_info) -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_filter_ctrl.touch_filter_mode = filter_info.mode; - RTCCNTL.touch_filter_ctrl.touch_debounce = filter_info.debounce_cnt; - RTCCNTL.touch_filter_ctrl.touch_hysteresis = filter_info.hysteresis_thr; - RTCCNTL.touch_filter_ctrl.touch_noise_thres = filter_info.noise_thr; - RTCCNTL.touch_filter_ctrl.touch_neg_noise_thres = filter_info.noise_neg_thr; - RTCCNTL.touch_filter_ctrl.touch_neg_noise_limit = filter_info.neg_noise_limit; - RTCCNTL.touch_filter_ctrl.touch_jitter_step = filter_info.jitter_step; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_filter_get_config(touch_filter_config_t *filter_info) -{ - portENTER_CRITICAL(&rtc_spinlock); - filter_info->mode = RTCCNTL.touch_filter_ctrl.touch_filter_mode; - filter_info->debounce_cnt = RTCCNTL.touch_filter_ctrl.touch_debounce; - filter_info->hysteresis_thr = RTCCNTL.touch_filter_ctrl.touch_hysteresis; - filter_info->noise_thr = RTCCNTL.touch_filter_ctrl.touch_noise_thres; - filter_info->noise_neg_thr = RTCCNTL.touch_filter_ctrl.touch_neg_noise_thres; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_filter_start() -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_filter_ctrl.touch_filter_en = 1; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_filter_stop() -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_filter_ctrl.touch_filter_en = 0; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_denoise_enable() -{ - touch_pad_clear_group_mask(BIT(TOUCH_PAD_NUM0)); - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_scan_ctrl.touch_denoise_en = 1; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_denoise_disable() -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_scan_ctrl.touch_denoise_en = 0; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_denoise_set_config(touch_pad_denoise_t denoise) -{ - touch_pad_set_cnt_mode(TOUCH_PAD_NUM0, TOUCH_PAD_SLOPE_7); - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_ctrl2.touch_refc = denoise.cap_level; - RTCCNTL.touch_scan_ctrl.touch_denoise_res = denoise.grade; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_denoise_get_config(touch_pad_denoise_t *denoise) -{ - if(denoise) { - denoise->grade = RTCCNTL.touch_scan_ctrl.touch_denoise_res; - denoise->cap_level = RTCCNTL.touch_ctrl2.touch_refc; - return ESP_OK; - } else { - return ESP_FAIL; - } -} - -esp_err_t touch_pad_denoise_data_get(uint32_t *data) -{ - *data = SENS.sar_touch_status0.touch_denoise_data; - return ESP_OK; -} - -/* - * waterproof function include two setting part: 'shield pad driver' and 'guard ring pad num' - * @note waterproof and touch function are mutually exclusive. if config touch14, dont use shield. - * @note self-calibration is implemented in hardware. - * @note touch_out_ring point to touch0, can disable the guatd ring function ? - * @note "touch_bufdrv" should user config ? - */ -esp_err_t touch_pad_waterproof_set_config(touch_pad_waterproof_t waterproof) -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_scan_ctrl.touch_out_ring = waterproof.guard_ring_pad; - RTCCNTL.touch_scan_ctrl.touch_bufdrv = waterproof.shield_driver; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_waterproof_get_config(touch_pad_waterproof_t *waterproof) -{ - if(waterproof) { - waterproof->guard_ring_pad = RTCCNTL.touch_scan_ctrl.touch_out_ring; - waterproof->shield_driver = RTCCNTL.touch_scan_ctrl.touch_bufdrv; - return ESP_OK; - } else { - return ESP_FAIL; - } -} - -esp_err_t touch_pad_waterproof_enable() -{ - touch_pad_clear_group_mask(BIT(TOUCH_PAD_NUM14)); - touch_pad_io_init(TOUCH_PAD_NUM14); - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_scan_ctrl.touch_shield_pad_en = 1; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_waterproof_disable() -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_scan_ctrl.touch_shield_pad_en = 0; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -/* - * @note approach pad can set three pin. - * @note if clear the approach pad, point this pad to touch0 and then reset this channel baseline. - * @note the approach thresh is abs value. - * @note TODO: add channel reset reg. - */ -esp_err_t touch_pad_approach_set_config(touch_pad_approach_t approach) -{ - portENTER_CRITICAL(&rtc_spinlock); - if(approach.select_pad0) { - SENS.sar_touch_conf.touch_approach_pad0 = approach.select_pad0; - } - if(approach.select_pad1) { - SENS.sar_touch_conf.touch_approach_pad1 = approach.select_pad1; - } - if(approach.select_pad2) { - SENS.sar_touch_conf.touch_approach_pad2 = approach.select_pad2; - } - RTCCNTL.touch_approach.touch_approach_meas_time = approach.means_num; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -esp_err_t touch_pad_approach_get_config(touch_pad_approach_t *approach) -{ - if(approach) { - approach->select_pad0 = SENS.sar_touch_conf.touch_approach_pad0; - approach->select_pad1 = SENS.sar_touch_conf.touch_approach_pad1; - approach->select_pad2 = SENS.sar_touch_conf.touch_approach_pad2; - approach->means_num = RTCCNTL.touch_approach.touch_approach_meas_time; - return ESP_OK; - } else { - return ESP_FAIL; - } -} - -uint32_t touch_pad_approach_get_cnt(uint8_t pad) -{ - uint32_t cnt = 0; - if(pad == 0){ - cnt = SENS.sar_touch_status16.touch_approach_pad0_cnt; - } else if(pad == 1) { - cnt = SENS.sar_touch_status16.touch_approach_pad1_cnt; - } else if(pad == 2) { - cnt = SENS.sar_touch_status16.touch_approach_pad2_cnt; - } else if(pad == 3) { - cnt = SENS.sar_touch_status16.touch_slp_approach_cnt; - } - return cnt; -} - -/* TODO */ -esp_err_t touch_pad_approach_disable() -{ - portENTER_CRITICAL(&rtc_spinlock); - SENS.sar_touch_conf.touch_approach_pad0 = 0; - SENS.sar_touch_conf.touch_approach_pad1 = 0; - SENS.sar_touch_conf.touch_approach_pad2 = 0; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -/* After touch_clkgate_en = 0, reset the whole of touch module. */ -esp_err_t touch_pad_reset() -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_ctrl2.touch_reset = 0; - RTCCNTL.touch_ctrl2.touch_reset = 1; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -/************** sleep pad setting ***********************/ - -esp_err_t touch_pad_sleep_pad_config(touch_pad_t pad, uint32_t sleep_thr, uint8_t is_approach) -{ - portENTER_CRITICAL(&rtc_spinlock); - RTCCNTL.touch_slp_thres.touch_slp_pad = pad; - RTCCNTL.touch_slp_thres.touch_slp_th = sleep_thr; - RTCCNTL.touch_slp_thres.touch_slp_approach_en = is_approach?1:0; - portEXIT_CRITICAL(&rtc_spinlock); - return ESP_OK; -} - -/** - * Get sleep touch pad baseline data. - * - * @param baseline - */ -void touch_sleep_baseline_get(uint32_t *baseline) -{ - *baseline = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS15_REG, SENS_TOUCH_SLP_BASELINE); -} - -/** - * Get sleep touch pad debounce data. - * - * @param debounce - */ -void touch_sleep_debounce_get(uint32_t *debounce) -{ - *debounce = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS15_REG, SENS_TOUCH_SLP_DEBOUNCE); -} - -/** - * Get sleep touch pad approach cnt data. - * - * @param approach_cnt - */ -void touch_sleep_approach_cnt_get(uint32_t *approach_cnt) -{ - *approach_cnt = REG_GET_FIELD(SENS_SAR_TOUCH_STATUS16_REG, SENS_TOUCH_SLP_APPROACH_CNT); -} - -esp_err_t touch_pad_get_wakeup_status(touch_pad_t *pad_num) -{ - uint32_t touch_mask = SENS.sar_touch_chn_st.touch_pad_active; - *pad_num = __builtin_ffs(touch_mask) - 1; - return ESP_OK; -} - -#endif \ No newline at end of file diff --git a/components/esp32s2beta/sleep_modes.c b/components/esp32s2beta/sleep_modes.c index c5e5181fd4..b6f6c79adb 100644 --- a/components/esp32s2beta/sleep_modes.c +++ b/components/esp32s2beta/sleep_modes.c @@ -406,9 +406,10 @@ touch_pad_t esp_sleep_get_touchpad_wakeup_status() if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_TOUCHPAD) { return TOUCH_PAD_MAX; } - uint32_t touch_mask = REG_GET_FIELD(RTC_CNTL_TOUCH_CTRL1_REG, RTC_CNTL_TOUCH_MEAS_NUM); - assert(touch_mask != 0 && "wakeup reason is RTC_TOUCH_TRIG_EN but SENS_TOUCH_MEAS_EN is zero"); - return (touch_pad_t) (__builtin_ffs(touch_mask) - 1); + touch_pad_t pad_num; + esp_err_t ret = touch_pad_get_wakeup_status(&pad_num); + assert(ret == ESP_OK && "wakeup reason is RTC_TOUCH_TRIG_EN but SENS_TOUCH_MEAS_EN is zero"); + return pad_num; } esp_err_t esp_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level) @@ -423,7 +424,7 @@ esp_err_t esp_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level) ESP_LOGE(TAG, "Conflicting wake-up triggers: touch / ULP"); return ESP_ERR_INVALID_STATE; } - s_config.ext0_rtc_gpio_num = rtc_gpio_desc[gpio_num].rtc_num; + s_config.ext0_rtc_gpio_num = gpio_num; s_config.ext0_trigger_level = level; s_config.wakeup_triggers |= RTC_EXT0_TRIG_EN; return ESP_OK; @@ -437,13 +438,12 @@ static void ext0_wakeup_prepare() // Set level which will trigger wakeup SET_PERI_REG_BITS(RTC_CNTL_EXT_WAKEUP_CONF_REG, 0x1, s_config.ext0_trigger_level, RTC_CNTL_EXT_WAKEUP0_LV_S); - // Find GPIO descriptor in the rtc_gpio_desc table and configure the pad + // Find GPIO descriptor in the rtc_gpio_reg table and configure the pad for (size_t gpio_num = 0; gpio_num < GPIO_PIN_COUNT; ++gpio_num) { - const rtc_gpio_desc_t* desc = &rtc_gpio_desc[gpio_num]; - if (desc->rtc_num == rtc_gpio_num) { - REG_SET_BIT(desc->reg, desc->mux); - SET_PERI_REG_BITS(desc->reg, 0x3, 0, desc->func); - REG_SET_BIT(desc->reg, desc->ie); + if (gpio_num == rtc_gpio_num && RTC_GPIO_IS_VALID_GPIO(gpio_num)) { + rtc_gpio_reg[gpio_num]->mux_sel = 1; + rtc_gpio_reg[gpio_num]->fun_sel = 0; + rtc_gpio_reg[gpio_num]->fun_ie = 1; break; } } @@ -464,7 +464,7 @@ esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t mask, esp_sleep_ext1_wakeup_mode ESP_LOGE(TAG, "Not an RTC IO: GPIO%d", gpio); return ESP_ERR_INVALID_ARG; } - rtc_gpio_mask |= BIT(rtc_gpio_desc[gpio].rtc_num); + rtc_gpio_mask |= BIT(gpio); } s_config.ext1_rtc_gpio_mask = rtc_gpio_mask; s_config.ext1_trigger_mode = mode; @@ -477,26 +477,27 @@ static void ext1_wakeup_prepare() // Configure all RTC IOs selected as ext1 wakeup inputs uint32_t rtc_gpio_mask = s_config.ext1_rtc_gpio_mask; for (int gpio = 0; gpio < GPIO_PIN_COUNT && rtc_gpio_mask != 0; ++gpio) { - int rtc_pin = rtc_gpio_desc[gpio].rtc_num; - if ((rtc_gpio_mask & BIT(rtc_pin)) == 0) { + if(!RTC_GPIO_IS_VALID_GPIO(gpio)) { + continue; + } + if ((rtc_gpio_mask & BIT(gpio)) == 0) { continue; } - const rtc_gpio_desc_t* desc = &rtc_gpio_desc[gpio]; // Route pad to RTC - REG_SET_BIT(desc->reg, desc->mux); - SET_PERI_REG_BITS(desc->reg, 0x3, 0, desc->func); + rtc_gpio_reg[gpio]->mux_sel = 1; + rtc_gpio_reg[gpio]->fun_sel = 0; // set input enable in sleep mode - REG_SET_BIT(desc->reg, desc->ie); + rtc_gpio_reg[gpio]->fun_ie = 1; // Pad configuration depends on RTC_PERIPH state in sleep mode if (s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] != ESP_PD_OPTION_ON) { // RTC_PERIPH will be powered down, so RTC_IO_ registers will // loose their state. Lock pad configuration. // Pullups/pulldowns also need to be disabled. - REG_CLR_BIT(desc->reg, desc->pulldown); - REG_CLR_BIT(desc->reg, desc->pullup); + rtc_gpio_reg[gpio]->rue = 0; + rtc_gpio_reg[gpio]->rde = 0; } // Keep track of pins which are processed to bail out early - rtc_gpio_mask &= ~BIT(rtc_pin); + rtc_gpio_mask &= ~BIT(gpio); } // Clear state from previous wakeup REG_SET_BIT(RTC_CNTL_EXT_WAKEUP1_REG, RTC_CNTL_EXT_WAKEUP1_STATUS_CLR); @@ -519,7 +520,7 @@ uint64_t esp_sleep_get_ext1_wakeup_status() if (!RTC_GPIO_IS_VALID_GPIO(gpio)) { continue; } - int rtc_pin = rtc_gpio_desc[gpio].rtc_num; + int rtc_pin = gpio; if ((status & BIT(rtc_pin)) == 0) { continue; } diff --git a/components/soc/esp32s2beta/include/soc/apb_ctrl_struct.h b/components/soc/esp32s2beta/include/soc/apb_ctrl_struct.h index 0e002330f3..9447912e91 100644 --- a/components/soc/esp32s2beta/include/soc/apb_ctrl_struct.h +++ b/components/soc/esp32s2beta/include/soc/apb_ctrl_struct.h @@ -91,14 +91,8 @@ typedef volatile struct { } saradc_fsm_wait; uint32_t saradc_sar1_status; /**/ uint32_t saradc_sar2_status; /**/ - uint32_t saradc_sar1_patt_tab1; /*item 0 ~ 3 for pattern table 1 (each item one byte)*/ - uint32_t saradc_sar1_patt_tab2; /*Item 4 ~ 7 for pattern table 1 (each item one byte)*/ - uint32_t saradc_sar1_patt_tab3; /*Item 8 ~ 11 for pattern table 1 (each item one byte)*/ - uint32_t saradc_sar1_patt_tab4; /*Item 12 ~ 15 for pattern table 1 (each item one byte)*/ - uint32_t saradc_sar2_patt_tab1; /*item 0 ~ 3 for pattern table 2 (each item one byte)*/ - uint32_t saradc_sar2_patt_tab2; /*Item 4 ~ 7 for pattern table 2 (each item one byte)*/ - uint32_t saradc_sar2_patt_tab3; /*Item 8 ~ 11 for pattern table 2 (each item one byte)*/ - uint32_t saradc_sar2_patt_tab4; /*Item 12 ~ 15 for pattern table 2 (each item one byte)*/ + uint32_t saradc_sar1_patt_tab[4]; /*item 0 ~ 15 for pattern table 1 (each item one byte)*/ + uint32_t saradc_sar2_patt_tab[4]; /*item 0 ~ 15 for pattern table 2 (each item one byte)*/ union { struct { uint32_t reserved0: 2; @@ -310,11 +304,22 @@ typedef volatile struct { }; uint32_t val; } redcy_sig1; - uint32_t reserved_cc; - uint32_t reserved_d0; - uint32_t reserved_d4; - uint32_t reserved_d8; - uint32_t reserved_dc; + uint32_t wifi_bb_cfg; /**/ + uint32_t wifi_bb_cfg_2; /**/ + uint32_t wifi_clk_en; /**/ + uint32_t wifi_rst_en; /**/ + union { + struct { + uint32_t agc_mem_force_pu: 1; + uint32_t agc_mem_force_pd: 1; + uint32_t pbus_mem_force_pu: 1; + uint32_t pbus_mem_force_pd: 1; + uint32_t dc_mem_force_pu: 1; + uint32_t dc_mem_force_pd: 1; + uint32_t reserved6: 26; + }; + uint32_t val; + } front_end_mem_pd; uint32_t reserved_e0; uint32_t reserved_e4; uint32_t reserved_e8; diff --git a/components/soc/esp32s2beta/include/soc/rtc_i2c_struct.h b/components/soc/esp32s2beta/include/soc/rtc_i2c_struct.h index 938df0c58f..7f6193c17b 100644 --- a/components/soc/esp32s2beta/include/soc/rtc_i2c_struct.h +++ b/components/soc/esp32s2beta/include/soc/rtc_i2c_struct.h @@ -171,13 +171,9 @@ typedef volatile struct { } fifo_data; union { struct { - uint32_t byte_num: 8; /*Byte_num represent the number of data need to be send or data need to be received.*/ - uint32_t ack_en: 1; /*ack_check_en ack_exp and ack value are used to control the ack bit.*/ - uint32_t ack_exp: 1; /*ack_check_en ack_exp and ack value are used to control the ack bit.*/ - uint32_t ack_val: 1; /*ack_check_en ack_exp and ack value are used to control the ack bit.*/ - uint32_t op_code: 3; /*op_code is the command 0:RSTART 1:WRITE 2:READ 3:STOP . 4:END.*/ + uint32_t command: 14; /*command*/ uint32_t reserved14: 17; - uint32_t done: 1; /*command0_done*/ + uint32_t done: 1; /*command_done*/ }; uint32_t val; } command[16]; diff --git a/components/soc/esp32s2beta/include/soc/sens_struct.h b/components/soc/esp32s2beta/include/soc/sens_struct.h index 7ad7a8570a..98808fc618 100644 --- a/components/soc/esp32s2beta/include/soc/sens_struct.h +++ b/components/soc/esp32s2beta/include/soc/sens_struct.h @@ -277,118 +277,6 @@ typedef volatile struct { }; uint32_t val; } sar_touch_status[14]; -// union { -// struct { -// uint32_t touch_pad2_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad2_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status2; -// union { -// struct { -// uint32_t touch_pad3_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad3_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status3; -// union { -// struct { -// uint32_t touch_pad4_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad4_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status4; -// union { -// struct { -// uint32_t touch_pad5_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad5_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status5; -// union { -// struct { -// uint32_t touch_pad6_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad6_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status6; -// union { -// struct { -// uint32_t touch_pad7_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad7_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status7; -// union { -// struct { -// uint32_t touch_pad8_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad8_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status8; -// union { -// struct { -// uint32_t touch_pad9_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad9_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status9; -// union { -// struct { -// uint32_t touch_pad10_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad10_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status10; -// union { -// struct { -// uint32_t touch_pad11_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad11_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status11; -// union { -// struct { -// uint32_t touch_pad12_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad12_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status12; -// union { -// struct { -// uint32_t touch_pad13_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad13_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status13; -// union { -// struct { -// uint32_t touch_pad14_baseline:22; -// uint32_t reserved22: 7; -// uint32_t touch_pad14_debounce: 3; -// }; -// uint32_t val; -// } sar_touch_status14; -// union { -// struct { -// uint32_t touch_slp_baseline: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; diff --git a/components/soc/esp32s2beta/include/soc/syscon_struct.h b/components/soc/esp32s2beta/include/soc/syscon_struct.h index 42bd643d16..8278a82008 100644 --- a/components/soc/esp32s2beta/include/soc/syscon_struct.h +++ b/components/soc/esp32s2beta/include/soc/syscon_struct.h @@ -21,98 +21,505 @@ extern "C" { typedef volatile struct { union { struct { - uint32_t pre_div: 10; - uint32_t clk_320m_en: 1; - uint32_t clk_en: 1; - uint32_t rst_tick: 1; - uint32_t quick_clk_chng: 1; - uint32_t reserved14: 18; + uint32_t pre_div: 10; + uint32_t clk_320m_en: 1; + uint32_t clk_en: 1; + uint32_t rst_tick: 1; + uint32_t reserved13: 1; + uint32_t soc_clk_sel: 2; + uint32_t reserved16: 16; }; uint32_t val; - }clk_conf; + } clk_conf; union { struct { uint32_t xtal_tick: 8; - uint32_t reserved8: 24; - }; - uint32_t val; - }xtal_tick_conf; - union { - struct { - uint32_t pll_tick: 8; - uint32_t reserved8: 24; - }; - uint32_t val; - }pll_tick_conf; - union { - struct { uint32_t ck8m_tick: 8; - uint32_t reserved8: 24; + uint32_t tick_enable: 1; + uint32_t reserved17: 15; }; uint32_t val; - }ck8m_tick_conf; + } tick_conf; union { struct { - uint32_t start_force: 1; - uint32_t start: 1; - uint32_t sar2_mux: 1; /*1: SAR ADC2 is controlled by DIG ADC2 CTRL 0: SAR ADC2 is controlled by PWDET CTRL*/ - uint32_t work_mode: 2; /*0: single mode 1: double mode 2: alternate mode*/ - uint32_t sar_sel: 1; /*0: SAR1 1: SAR2 only work for single SAR mode*/ - uint32_t sar_clk_gated: 1; - uint32_t sar_clk_div: 8; /*SAR clock divider*/ - uint32_t sar1_patt_len: 4; /*0 ~ 15 means length 1 ~ 16*/ - uint32_t sar2_patt_len: 4; /*0 ~ 15 means length 1 ~ 16*/ - uint32_t sar1_patt_p_clear: 1; /*clear the pointer of pattern table for DIG ADC1 CTRL*/ - uint32_t sar2_patt_p_clear: 1; /*clear the pointer of pattern table for DIG ADC2 CTRL*/ - uint32_t data_sar_sel: 1; /*1: sar_sel will be coded by the MSB of the 16-bit output data in this case the resolution should not be larger than 11 bits.*/ - uint32_t data_to_i2s: 1; /*1: I2S input data is from SAR ADC (for DMA) 0: I2S input data is from GPIO matrix*/ - uint32_t reserved27: 5; + uint32_t start_force: 1; + uint32_t start: 1; + uint32_t reserved2: 1; + uint32_t work_mode: 2; /*0: single mode 1: double mode 2: alternate mode*/ + uint32_t sar_sel: 1; /*0: SAR1 1: SAR2 only work for single SAR mode*/ + uint32_t sar_clk_gated: 1; + uint32_t sar_clk_div: 8; /*SAR clock divider*/ + uint32_t sar1_patt_len: 4; /*0 ~ 15 means length 1 ~ 16*/ + uint32_t sar2_patt_len: 4; /*0 ~ 15 means length 1 ~ 16*/ + uint32_t sar1_patt_p_clear: 1; /*clear the pointer of pattern table for DIG ADC1 CTRL*/ + uint32_t sar2_patt_p_clear: 1; /*clear the pointer of pattern table for DIG ADC2 CTRL*/ + uint32_t data_sar_sel: 1; /*1: sar_sel will be coded by the MSB of the 16-bit output data in this case the resolution should not be larger than 11 bits.*/ + uint32_t data_to_i2s: 1; /*1: I2S input data is from SAR ADC (for DMA) 0: I2S input data is from GPIO matrix*/ + uint32_t xpd_sar_force: 2; /*force option to xpd sar blocks*/ + uint32_t reserved29: 3; }; uint32_t val; - }saradc_ctrl; + } saradc_ctrl; union { struct { - uint32_t meas_num_limit: 1; - uint32_t max_meas_num: 8; /*max conversion number*/ - uint32_t sar1_inv: 1; /*1: data to DIG ADC1 CTRL is inverted otherwise not*/ - uint32_t sar2_inv: 1; /*1: data to DIG ADC2 CTRL is inverted otherwise not*/ - uint32_t reserved11: 21; + uint32_t meas_num_limit: 1; + uint32_t max_meas_num: 8; /*max conversion number*/ + uint32_t sar1_inv: 1; /*1: data to DIG ADC1 CTRL is inverted otherwise not*/ + uint32_t sar2_inv: 1; /*1: data to DIG ADC2 CTRL is inverted otherwise not*/ + uint32_t timer_sel: 1; /*1: select saradc timer 0: i2s_ws trigger*/ + uint32_t timer_target: 8; /*to set saradc timer target*/ + uint32_t timer_en: 1; /*to enable saradc timer trigger*/ + uint32_t reserved21: 11; }; uint32_t val; - }saradc_ctrl2; + } saradc_ctrl2; union { struct { - uint32_t rstb_wait: 8; - uint32_t standby_wait: 8; - uint32_t start_wait: 8; - uint32_t sample_cycle: 8; /*sample cycles*/ + uint32_t reserved0: 16; + uint32_t sample_num: 8; /*sample number*/ + uint32_t sample_cycle: 8; /*sample cycles*/ }; uint32_t val; - }saradc_fsm; - uint32_t saradc_sar1_patt_tab[4]; /*item 0 ~ 3 for ADC1 pattern table*/ - uint32_t saradc_sar2_patt_tab[4]; /*item 0 ~ 3 for ADC2 pattern table*/ + } saradc_fsm; union { struct { - uint32_t apll_tick: 8; - uint32_t reserved8: 24; + uint32_t xpd_wait: 8; + uint32_t rstb_wait: 8; + uint32_t standby_wait: 8; + uint32_t reserved24: 8; }; uint32_t val; - }apll_tick_conf; - uint32_t reserved_40; - uint32_t reserved_44; - uint32_t reserved_48; - uint32_t reserved_4c; - uint32_t reserved_50; - uint32_t reserved_54; - uint32_t reserved_58; - uint32_t reserved_5c; - uint32_t reserved_60; - uint32_t reserved_64; - uint32_t reserved_68; - uint32_t reserved_6c; - uint32_t reserved_70; - uint32_t reserved_74; - uint32_t reserved_78; + } saradc_fsm_wait; + uint32_t saradc_sar1_status; /**/ + uint32_t saradc_sar2_status; /**/ + uint32_t saradc_sar1_patt_tab[4]; /*item 0 ~ 15 for pattern table 1 (each item one byte)*/ + uint32_t saradc_sar2_patt_tab[4]; /*item 0 ~ 15 for pattern table 2 (each item one byte)*/ + union { + struct { + uint32_t reserved0: 2; + uint32_t adc_arb_apb_force: 1; /*adc2 arbiter force to enableapb controller*/ + uint32_t adc_arb_rtc_force: 1; /*adc2 arbiter force to enable rtc controller*/ + uint32_t adc_arb_wifi_force: 1; /*adc2 arbiter force to enable wifi controller*/ + uint32_t adc_arb_grant_force: 1; /*adc2 arbiter force grant*/ + uint32_t adc_arb_apb_priority: 2; /*Set adc2 arbiterapb priority*/ + uint32_t adc_arb_rtc_priority: 2; /*Set adc2 arbiter rtc priority*/ + uint32_t adc_arb_wifi_priority: 2; /*Set adc2 arbiter wifi priority*/ + uint32_t adc_arb_fix_priority: 1; /*adc2 arbiter uses fixed priority*/ + uint32_t reserved13: 19; + }; + uint32_t val; + } adc_arb_ctrl; + union { + struct { + uint32_t clk20_oen: 1; + uint32_t clk22_oen: 1; + uint32_t clk44_oen: 1; + uint32_t clk_bb_oen: 1; + uint32_t clk80_oen: 1; + uint32_t clk160_oen: 1; + uint32_t clk_320m_oen: 1; + uint32_t clk_adc_inf_oen: 1; + uint32_t clk_dac_cpu_oen: 1; + uint32_t clk40x_bb_oen: 1; + uint32_t clk_xtal_oen: 1; + uint32_t reserved11: 21; + }; + uint32_t val; + } clk_out_en; + union { + struct { + uint32_t peri_io_swap: 8; + uint32_t spi0_hold: 1; + uint32_t spi1_hold: 1; + uint32_t reserved10: 3; + uint32_t spi_prior: 1; + uint32_t reserved14: 18; + }; + uint32_t val; + } host_inf_sel; + union { + struct { + uint32_t ext_mem_pms_lock: 1; + uint32_t reserved1: 31; + }; + uint32_t val; + } ext_mem_pms_lock; + union { + struct { + uint32_t flash_ace0_attr: 3; + uint32_t reserved3: 29; + }; + uint32_t val; + } flash_ace0_attr; + union { + struct { + uint32_t flash_ace1_attr: 3; + uint32_t reserved3: 29; + }; + uint32_t val; + } flash_ace1_attr; + union { + struct { + uint32_t flash_ace2_attr: 3; + uint32_t reserved3: 29; + }; + uint32_t val; + } flash_ace2_attr; + union { + struct { + uint32_t flash_ace3_attr: 3; + uint32_t reserved3: 29; + }; + uint32_t val; + } flash_ace3_attr; + uint32_t flash_ace0_addr; /**/ + uint32_t flash_ace1_addr; /**/ + uint32_t flash_ace2_addr; /**/ + uint32_t flash_ace3_addr; /**/ + union { + struct { + uint32_t flash_ace0_size:16; + uint32_t reserved16: 16; + }; + uint32_t val; + } flash_ace0_size; + union { + struct { + uint32_t flash_ace1_size:16; + uint32_t reserved16: 16; + }; + uint32_t val; + } flash_ace1_size; + union { + struct { + uint32_t flash_ace2_size:16; + uint32_t reserved16: 16; + }; + uint32_t val; + } flash_ace2_size; + union { + struct { + uint32_t flash_ace3_size:16; + uint32_t reserved16: 16; + }; + uint32_t val; + } flash_ace3_size; + union { + struct { + uint32_t sram_ace0_attr: 3; + uint32_t reserved3: 29; + }; + uint32_t val; + } sram_ace0_attr; + union { + struct { + uint32_t sram_ace1_attr: 3; + uint32_t reserved3: 29; + }; + uint32_t val; + } sram_ace1_attr; + union { + struct { + uint32_t sram_ace2_attr: 3; + uint32_t reserved3: 29; + }; + uint32_t val; + } sram_ace2_attr; + union { + struct { + uint32_t sram_ace3_attr: 3; + uint32_t reserved3: 29; + }; + uint32_t val; + } sram_ace3_attr; + uint32_t sram_ace0_addr; /**/ + uint32_t sram_ace1_addr; /**/ + uint32_t sram_ace2_addr; /**/ + uint32_t sram_ace3_addr; /**/ + union { + struct { + uint32_t sram_ace0_size:16; + uint32_t reserved16: 16; + }; + uint32_t val; + } sram_ace0_size; + union { + struct { + uint32_t sram_ace1_size:16; + uint32_t reserved16: 16; + }; + uint32_t val; + } sram_ace1_size; + union { + struct { + uint32_t sram_ace2_size:16; + uint32_t reserved16: 16; + }; + uint32_t val; + } sram_ace2_size; + union { + struct { + uint32_t sram_ace3_size:16; + uint32_t reserved16: 16; + }; + uint32_t val; + } sram_ace3_size; + union { + struct { + uint32_t spi0_reject_int: 1; + uint32_t spi0_reject_clr: 1; + uint32_t spi0_reject_cde: 5; + uint32_t reserved7: 25; + }; + uint32_t val; + } spi0_pms_ctrl; + uint32_t spi0_reject_addr; /**/ + union { + struct { + uint32_t spi1_reject_int: 1; + uint32_t spi1_reject_clr: 1; + uint32_t spi1_reject_cde: 5; + uint32_t reserved7: 25; + }; + uint32_t val; + } spi1_pms_ctrl; + uint32_t spi1_reject_addr; /**/ + union { + struct { + uint32_t sdio_win_access_en: 1; + uint32_t reserved1: 31; + }; + uint32_t val; + } sdio_ctrl; + union { + struct { + uint32_t redcy_sig0: 31; + uint32_t redcy_andor: 1; + }; + uint32_t val; + } redcy_sig0; + union { + struct { + uint32_t redcy_sig1: 31; + uint32_t redcy_nandor: 1; + }; + uint32_t val; + } redcy_sig1; + uint32_t wifi_bb_cfg; /**/ + uint32_t wifi_bb_cfg_2; /**/ + uint32_t wifi_clk_en; /**/ + uint32_t wifi_rst_en; /**/ + union { + struct { + uint32_t agc_mem_force_pu: 1; + uint32_t agc_mem_force_pd: 1; + uint32_t pbus_mem_force_pu: 1; + uint32_t pbus_mem_force_pd: 1; + uint32_t dc_mem_force_pu: 1; + uint32_t dc_mem_force_pd: 1; + uint32_t reserved6: 26; + }; + uint32_t val; + } front_end_mem_pd; + uint32_t reserved_e0; + uint32_t reserved_e4; + uint32_t reserved_e8; + uint32_t reserved_ec; + uint32_t reserved_f0; + uint32_t reserved_f4; + uint32_t reserved_f8; + uint32_t reserved_fc; + uint32_t reserved_100; + uint32_t reserved_104; + uint32_t reserved_108; + uint32_t reserved_10c; + uint32_t reserved_110; + uint32_t reserved_114; + uint32_t reserved_118; + uint32_t reserved_11c; + uint32_t reserved_120; + uint32_t reserved_124; + uint32_t reserved_128; + uint32_t reserved_12c; + uint32_t reserved_130; + uint32_t reserved_134; + uint32_t reserved_138; + uint32_t reserved_13c; + uint32_t reserved_140; + uint32_t reserved_144; + uint32_t reserved_148; + uint32_t reserved_14c; + uint32_t reserved_150; + uint32_t reserved_154; + uint32_t reserved_158; + uint32_t reserved_15c; + uint32_t reserved_160; + uint32_t reserved_164; + uint32_t reserved_168; + uint32_t reserved_16c; + uint32_t reserved_170; + uint32_t reserved_174; + uint32_t reserved_178; + uint32_t reserved_17c; + uint32_t reserved_180; + uint32_t reserved_184; + uint32_t reserved_188; + uint32_t reserved_18c; + uint32_t reserved_190; + uint32_t reserved_194; + uint32_t reserved_198; + uint32_t reserved_19c; + uint32_t reserved_1a0; + uint32_t reserved_1a4; + uint32_t reserved_1a8; + uint32_t reserved_1ac; + uint32_t reserved_1b0; + uint32_t reserved_1b4; + uint32_t reserved_1b8; + uint32_t reserved_1bc; + uint32_t reserved_1c0; + uint32_t reserved_1c4; + uint32_t reserved_1c8; + uint32_t reserved_1cc; + uint32_t reserved_1d0; + uint32_t reserved_1d4; + uint32_t reserved_1d8; + uint32_t reserved_1dc; + uint32_t reserved_1e0; + uint32_t reserved_1e4; + uint32_t reserved_1e8; + uint32_t reserved_1ec; + uint32_t reserved_1f0; + uint32_t reserved_1f4; + uint32_t reserved_1f8; + uint32_t reserved_1fc; + uint32_t reserved_200; + uint32_t reserved_204; + uint32_t reserved_208; + uint32_t reserved_20c; + uint32_t reserved_210; + uint32_t reserved_214; + uint32_t reserved_218; + uint32_t reserved_21c; + uint32_t reserved_220; + uint32_t reserved_224; + uint32_t reserved_228; + uint32_t reserved_22c; + uint32_t reserved_230; + uint32_t reserved_234; + uint32_t reserved_238; + uint32_t reserved_23c; + uint32_t reserved_240; + uint32_t reserved_244; + uint32_t reserved_248; + uint32_t reserved_24c; + uint32_t reserved_250; + uint32_t reserved_254; + uint32_t reserved_258; + uint32_t reserved_25c; + uint32_t reserved_260; + uint32_t reserved_264; + uint32_t reserved_268; + uint32_t reserved_26c; + uint32_t reserved_270; + uint32_t reserved_274; + uint32_t reserved_278; + uint32_t reserved_27c; + uint32_t reserved_280; + uint32_t reserved_284; + uint32_t reserved_288; + uint32_t reserved_28c; + uint32_t reserved_290; + uint32_t reserved_294; + uint32_t reserved_298; + uint32_t reserved_29c; + uint32_t reserved_2a0; + uint32_t reserved_2a4; + uint32_t reserved_2a8; + uint32_t reserved_2ac; + uint32_t reserved_2b0; + uint32_t reserved_2b4; + uint32_t reserved_2b8; + uint32_t reserved_2bc; + uint32_t reserved_2c0; + uint32_t reserved_2c4; + uint32_t reserved_2c8; + uint32_t reserved_2cc; + uint32_t reserved_2d0; + uint32_t reserved_2d4; + uint32_t reserved_2d8; + uint32_t reserved_2dc; + uint32_t reserved_2e0; + uint32_t reserved_2e4; + uint32_t reserved_2e8; + uint32_t reserved_2ec; + uint32_t reserved_2f0; + uint32_t reserved_2f4; + uint32_t reserved_2f8; + uint32_t reserved_2fc; + uint32_t reserved_300; + uint32_t reserved_304; + uint32_t reserved_308; + uint32_t reserved_30c; + uint32_t reserved_310; + uint32_t reserved_314; + uint32_t reserved_318; + uint32_t reserved_31c; + uint32_t reserved_320; + uint32_t reserved_324; + uint32_t reserved_328; + uint32_t reserved_32c; + uint32_t reserved_330; + uint32_t reserved_334; + uint32_t reserved_338; + uint32_t reserved_33c; + uint32_t reserved_340; + uint32_t reserved_344; + uint32_t reserved_348; + uint32_t reserved_34c; + uint32_t reserved_350; + uint32_t reserved_354; + uint32_t reserved_358; + uint32_t reserved_35c; + uint32_t reserved_360; + uint32_t reserved_364; + uint32_t reserved_368; + uint32_t reserved_36c; + uint32_t reserved_370; + uint32_t reserved_374; + uint32_t reserved_378; + uint32_t reserved_37c; + uint32_t reserved_380; + uint32_t reserved_384; + uint32_t reserved_388; + uint32_t reserved_38c; + uint32_t reserved_390; + uint32_t reserved_394; + uint32_t reserved_398; + uint32_t reserved_39c; + uint32_t reserved_3a0; + uint32_t reserved_3a4; + uint32_t reserved_3a8; + uint32_t reserved_3ac; + uint32_t reserved_3b0; + uint32_t reserved_3b4; + uint32_t reserved_3b8; + uint32_t reserved_3bc; + uint32_t reserved_3c0; + uint32_t reserved_3c4; + uint32_t reserved_3c8; + uint32_t reserved_3cc; + uint32_t reserved_3d0; + uint32_t reserved_3d4; + uint32_t reserved_3d8; + uint32_t reserved_3dc; + uint32_t reserved_3e0; + uint32_t reserved_3e4; + uint32_t reserved_3e8; + uint32_t reserved_3ec; + uint32_t reserved_3f0; + uint32_t reserved_3f4; + uint32_t reserved_3f8; uint32_t date; /**/ } syscon_dev_t; diff --git a/docs/Doxyfile b/docs/Doxyfile index 995897f015..7d00c4cc1c 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -83,6 +83,7 @@ INPUT = \ ../../components/driver/include/driver/spi_common.h \ ../../components/driver/include/driver/spi_master.h \ ../../components/driver/include/driver/spi_slave.h \ + ../../components/driver/esp32s2beta/include/temp_sensor.h \ ../../components/driver/include/driver/timer.h \ ../../components/driver/include/driver/touch_pad.h \ ../../components/driver/include/driver/uart.h \ diff --git a/docs/en/api-reference/peripherals/index.rst b/docs/en/api-reference/peripherals/index.rst index b9b85c2033..77913eab91 100644 --- a/docs/en/api-reference/peripherals/index.rst +++ b/docs/en/api-reference/peripherals/index.rst @@ -22,6 +22,7 @@ Peripherals API Sigma-delta Modulation SPI Master SPI Slave + Temp sensor Timer Touch Sensor UART diff --git a/docs/en/api-reference/peripherals/temp_sensor.rst b/docs/en/api-reference/peripherals/temp_sensor.rst new file mode 100644 index 0000000000..b246ac8f2d --- /dev/null +++ b/docs/en/api-reference/peripherals/temp_sensor.rst @@ -0,0 +1,32 @@ +ESP32-S2 Temperature Sensor +================== + +Overview +-------- + +The ESP32-S2 has a built-in temperature sensor. The temperature sensor module contains an 8-bit Sigma-Delta ADC and a temperature offset DAC. +The conversion relationship is the first columns of the table below. Among them, offset = 0 is the main measurement option, and other values are extended measurement options. + ++--------+------------------------+------------------------+ +| offset | measure range(Celsius) | measure error(Celsius) | ++========+========================+========================+ +| -2 | 50 ~ 125 | < 3 | ++--------+------------------------+------------------------+ +| -1 | 20 ~ 100 | < 2 | ++--------+------------------------+------------------------+ +| 0 | -10 ~ 80 | < 1 | ++--------+------------------------+------------------------+ +| 1 | -30 ~ 50 | < 2 | ++--------+------------------------+------------------------+ +| 2 | -40 ~ 20 | < 3 | ++--------+------------------------+------------------------+ + +Application Example +------------------- + +Temperature sensor reading example: :example:`peripherals/temp_sensor`. + +API Reference - Normal Temp Sensor +---------------------------------- + +.. include:: /_build/inc/temp_sensor.inc diff --git a/docs/zh_CN/api-reference/peripherals/index.rst b/docs/zh_CN/api-reference/peripherals/index.rst index c985d687e6..22d2cd55da 100644 --- a/docs/zh_CN/api-reference/peripherals/index.rst +++ b/docs/zh_CN/api-reference/peripherals/index.rst @@ -22,6 +22,7 @@ Sigma-delta Modulation SPI Master SPI Slave + Temp sensor Timer Touch Sensor UART diff --git a/docs/zh_CN/api-reference/peripherals/temp_sensor.rst b/docs/zh_CN/api-reference/peripherals/temp_sensor.rst new file mode 100644 index 0000000000..e5a634c707 --- /dev/null +++ b/docs/zh_CN/api-reference/peripherals/temp_sensor.rst @@ -0,0 +1 @@ +.. include:: ../../../en/api-reference/peripherals/temp_sensor.rst \ No newline at end of file diff --git a/examples/peripherals/adc/main/adc1_example_main.c b/examples/peripherals/adc/main/adc1_example_main.c index ddedbdc519..a9bfe08733 100644 --- a/examples/peripherals/adc/main/adc1_example_main.c +++ b/examples/peripherals/adc/main/adc1_example_main.c @@ -12,17 +12,23 @@ #include "freertos/task.h" #include "driver/gpio.h" #include "driver/adc.h" - #if CONFIG_IDF_TARGET_ESP32 #include "esp_adc_cal.h" +#endif + #define DEFAULT_VREF 1100 //Use adc2_vref_to_gpio() to obtain a better estimate #define NO_OF_SAMPLES 64 //Multisampling +#if CONFIG_IDF_TARGET_ESP32 static esp_adc_cal_characteristics_t *adc_chars; static const adc_channel_t channel = ADC_CHANNEL_6; //GPIO34 if ADC1, GPIO14 if ADC2 +#elif CONFIG_IDF_TARGET_ESP32S2BETA +static const adc_channel_t channel = ADC_CHANNEL_6; // GPIO7 if ADC1, GPIO17 if ADC2 +#endif static const adc_atten_t atten = ADC_ATTEN_DB_0; static const adc_unit_t unit = ADC_UNIT_1; +#if CONFIG_IDF_TARGET_ESP32 static void check_efuse() { //Check TP is burned into eFuse @@ -50,11 +56,14 @@ static void print_char_val_type(esp_adc_cal_value_t val_type) printf("Characterized using Default Vref\n"); } } +#endif void app_main() { +#if CONFIG_IDF_TARGET_ESP32 //Check if Two Point or Vref are burned into eFuse check_efuse(); +#endif //Configure ADC if (unit == ADC_UNIT_1) { @@ -64,10 +73,12 @@ void app_main() adc2_config_channel_atten((adc2_channel_t)channel, atten); } +#if CONFIG_IDF_TARGET_ESP32 //Characterize ADC adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t)); esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, atten, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars); print_char_val_type(val_type); +#endif //Continuously sample ADC1 while (1) { @@ -83,49 +94,13 @@ void app_main() } } adc_reading /= NO_OF_SAMPLES; +#if CONFIG_IDF_TARGET_ESP32 //Convert adc_reading to voltage in mV uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_chars); printf("Raw: %d\tVoltage: %dmV\n", adc_reading, voltage); - vTaskDelay(pdMS_TO_TICKS(1000)); - } -} - #elif CONFIG_IDF_TARGET_ESP32S2BETA - -#define NO_OF_SAMPLES 64 //Multisampling - -static const adc_channel_t channel = ADC_CHANNEL_6; // GPIO7 if ADC1, GPIO17 if ADC2 -static const adc_atten_t atten = ADC_ATTEN_DB_11; // Detect 0 ~ 3.6v -static const adc_unit_t unit = ADC_UNIT_2; -static const adc_unit_t width = ADC_WIDTH_BIT_12; - -void app_main() -{ - //Configure ADC - if (unit == ADC_UNIT_1) { - adc1_config_width(width); - adc1_config_channel_atten(channel, atten); - } else { - adc2_config_channel_atten((adc2_channel_t)channel, atten); - } - - //Continuously sample ADC1 - while (1) { - uint32_t adc_reading = 0; - // Multisampling - for (int i = 0; i < NO_OF_SAMPLES; i++) { - if (unit == ADC_UNIT_1) { - adc_reading += adc1_get_raw((adc1_channel_t)channel); - } else { - int raw; - adc2_get_raw((adc2_channel_t)channel, width, &raw); - adc_reading += raw; - } - } - adc_reading /= NO_OF_SAMPLES; printf("ADC%d CH%d Raw: %d\t\n", unit, channel, adc_reading); +#endif vTaskDelay(pdMS_TO_TICKS(1000)); } } -#endif - diff --git a/examples/peripherals/temp_sensor/README.md b/examples/peripherals/temp_sensor/README.md deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/examples/peripherals/temp_sensor/main/component.mk b/examples/peripherals/temp_sensor/main/component.mk deleted file mode 100644 index 44bd2b5273..0000000000 --- a/examples/peripherals/temp_sensor/main/component.mk +++ /dev/null @@ -1,3 +0,0 @@ -# -# Main Makefile. This is basically the same as a component makefile. -# diff --git a/examples/peripherals/temp_sensor/CMakeLists.txt b/examples/peripherals/temp_sensor_esp32s2/CMakeLists.txt similarity index 88% rename from examples/peripherals/temp_sensor/CMakeLists.txt rename to examples/peripherals/temp_sensor_esp32s2/CMakeLists.txt index bd14a9425f..61bb8c9c57 100644 --- a/examples/peripherals/temp_sensor/CMakeLists.txt +++ b/examples/peripherals/temp_sensor_esp32s2/CMakeLists.txt @@ -3,4 +3,4 @@ cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(temp_sensor) +project(temp_sensor_esp32s2) diff --git a/examples/peripherals/temp_sensor/Makefile b/examples/peripherals/temp_sensor_esp32s2/Makefile similarity index 81% rename from examples/peripherals/temp_sensor/Makefile rename to examples/peripherals/temp_sensor_esp32s2/Makefile index 7cb5326291..fb95185800 100644 --- a/examples/peripherals/temp_sensor/Makefile +++ b/examples/peripherals/temp_sensor_esp32s2/Makefile @@ -3,7 +3,7 @@ # project subdirectory. # -PROJECT_NAME := temp_sensor +PROJECT_NAME := temp_sensor_esp32s2 include $(IDF_PATH)/make/project.mk diff --git a/examples/peripherals/temp_sensor_esp32s2/README.md b/examples/peripherals/temp_sensor_esp32s2/README.md new file mode 100644 index 0000000000..3b6e22535a --- /dev/null +++ b/examples/peripherals/temp_sensor_esp32s2/README.md @@ -0,0 +1,27 @@ +# ESP32-S2 Temperature Sensor Example + +The ESP32-S2 has a built-in temperature sensor. The temperature sensor module contains an 8-bit Sigma-Delta ADC and a temperature offset DAC. + +The conversion relationship is the first two columns of the table below. Among them, `offset = 0`(default) is the main measurement option, and other values are extended measurement options. + +DAC level | offset | measure range(℃) | measure error(℃) + :-: | :-: | :-: | :-: + 0 | -2 | 50 ~ 125 | < 3 + 1 | -1 | 20 ~ 100 | < 2 + 2 | 0 | -10 ~ 80 | < 1 + 3 | 1 | -30 ~ 50 | < 2 + 4 | 2 | -40 ~ 20 | < 3 + +* Log output : + +``` +I (243) TempSensor: Initializing Temperature sensor +I (243) TempSensor: default dac 2, clk_div 6 +I (243) TempSensor: Config temperature range [-10°C ~ 80°C], error < 1°C +I (253) TempSensor: Temperature sensor started +I (1253) TempSensor: Temperature out celsius 27.287399°C +I (2253) TempSensor: Temperature out celsius 26.848801°C +I (3253) TempSensor: Temperature out celsius 26.848801°C +I (4253) TempSensor: Temperature out celsius 27.287399°C +I (5253) TempSensor: Temperature out celsius 27.287399°C +``` \ No newline at end of file diff --git a/examples/peripherals/temp_sensor/main/CMakeLists.txt b/examples/peripherals/temp_sensor_esp32s2/main/CMakeLists.txt similarity index 100% rename from examples/peripherals/temp_sensor/main/CMakeLists.txt rename to examples/peripherals/temp_sensor_esp32s2/main/CMakeLists.txt diff --git a/examples/peripherals/temp_sensor_esp32s2/main/component.mk b/examples/peripherals/temp_sensor_esp32s2/main/component.mk new file mode 100644 index 0000000000..0b9d7585e7 --- /dev/null +++ b/examples/peripherals/temp_sensor_esp32s2/main/component.mk @@ -0,0 +1,5 @@ +# +# "main" pseudo-component makefile. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) + diff --git a/examples/peripherals/temp_sensor/main/temp_sensor_main.c b/examples/peripherals/temp_sensor_esp32s2/main/temp_sensor_main.c similarity index 57% rename from examples/peripherals/temp_sensor/main/temp_sensor_main.c rename to examples/peripherals/temp_sensor_esp32s2/main/temp_sensor_main.c index 6d63d764a8..70ede5d9a5 100644 --- a/examples/peripherals/temp_sensor/main/temp_sensor_main.c +++ b/examples/peripherals/temp_sensor_esp32s2/main/temp_sensor_main.c @@ -1,4 +1,4 @@ -/* ADC1 Example +/* Temperature Sensor Example This example code is in the Public Domain (or CC0 licensed, at your option.) @@ -11,30 +11,31 @@ #include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "driver/temp_sensor.h" + +/* Note: ESP32 don't support temperature sensor */ #if CONFIG_IDF_TARGET_ESP32S2BETA +#include "temp_sensor.h" -static const char* TAG = "TempSensor"; +static const char *TAG = "TempSensor"; void tempsensor_example(void *arg) { // Initialize touch pad peripheral, it will start a timer to run a filter - ESP_LOGI(TAG, "Initializing temp sensor"); - uint8_t temp_out; - temp_sensor_t temp_sensor; + ESP_LOGI(TAG, "Initializing Temperature sensor"); + float tsens_out; + temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT(); temp_sensor_get_config(&temp_sensor); ESP_LOGI(TAG, "default dac %d, clk_div %d", temp_sensor.dac_offset, temp_sensor.clk_div); - temp_sensor.dac_offset = TEMP_SENSOR_DAC_DEFAULT; // DEFAULT: range:-10℃ ~ 80℃, error < 1℃. + temp_sensor.dac_offset = TSENS_DAC_DEFAULT; // DEFAULT: range:-10℃ ~ 80℃, error < 1℃. temp_sensor_set_config(temp_sensor); temp_sensor_start(); - ESP_LOGI(TAG, "temp sensor started"); - while(1) { + ESP_LOGI(TAG, "Temperature sensor started"); + while (1) { vTaskDelay(1000 / portTICK_RATE_MS); - temp_sensor_read(&temp_out); - ESP_LOGI(TAG, "temp out %d", temp_out); + temp_sensor_read_celsius(&tsens_out); + ESP_LOGI(TAG, "Temperature out celsius %f°C", tsens_out); } - ESP_LOGI(TAG, "test over"); vTaskDelete(NULL); } @@ -42,5 +43,12 @@ void app_main() { xTaskCreate(tempsensor_example, "temp", 2048, NULL, 5, NULL); } -#endif +#elif CONFIG_IDF_TARGET_ESP32 + +void app_main() +{ + printf("ESP32 don't support temperature sensor\n"); +} + +#endif diff --git a/examples/peripherals/touch_pad_interrupt/main/CMakeLists.txt b/examples/peripherals/touch_pad_interrupt/main/CMakeLists.txt index b77bf9c7be..37586a738f 100644 --- a/examples/peripherals/touch_pad_interrupt/main/CMakeLists.txt +++ b/examples/peripherals/touch_pad_interrupt/main/CMakeLists.txt @@ -1,4 +1,3 @@ -set(COMPONENT_SRCS "tp_interrupt_main.c") -set(COMPONENT_ADD_INCLUDEDIRS ".") +set(COMPONENT_SRCS "${CONFIG_IDF_TARGET}/tp_interrupt_main.c") register_component() diff --git a/examples/peripherals/touch_pad_interrupt/main/component.mk b/examples/peripherals/touch_pad_interrupt/main/component.mk index 0b9d7585e7..c6ea8a0a5a 100644 --- a/examples/peripherals/touch_pad_interrupt/main/component.mk +++ b/examples/peripherals/touch_pad_interrupt/main/component.mk @@ -3,3 +3,4 @@ # # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) +COMPONENT_SRCDIRS := $(IDF_TARGET) \ No newline at end of file diff --git a/examples/peripherals/touch_pad_interrupt/main/esp32/tp_interrupt_main.c b/examples/peripherals/touch_pad_interrupt/main/esp32/tp_interrupt_main.c new file mode 100644 index 0000000000..e823f9b6ec --- /dev/null +++ b/examples/peripherals/touch_pad_interrupt/main/esp32/tp_interrupt_main.c @@ -0,0 +1,171 @@ +/* Touch Pad Interrupt Example + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "esp_log.h" + +#include "driver/touch_pad.h" +#include "soc/rtc_periph.h" +#include "soc/sens_periph.h" + +static const char *TAG = "Touch pad"; + +#define TOUCH_THRESH_NO_USE (0) +#define TOUCH_THRESH_PERCENT (80) +#define TOUCHPAD_FILTER_TOUCH_PERIOD (10) + +static bool s_pad_activated[TOUCH_PAD_MAX]; +static uint32_t s_pad_init_val[TOUCH_PAD_MAX]; + +/* + Read values sensed at all available touch pads. + Use 2 / 3 of read value as the threshold + to trigger interrupt when the pad is touched. + Note: this routine demonstrates a simple way + to configure activation threshold for the touch pads. + Do not touch any pads when this routine + is running (on application start). + */ +static void tp_example_set_thresholds(void) +{ + uint16_t touch_value; + for (int i = 0; i < TOUCH_PAD_MAX; i++) { + //read filtered value + touch_pad_read_filtered(i, &touch_value); + s_pad_init_val[i] = touch_value; + ESP_LOGI(TAG, "test init: touch pad [%d] val is %d", i, touch_value); + //set interrupt threshold. + ESP_ERROR_CHECK(touch_pad_set_thresh(i, touch_value * 2 / 3)); + + } +} + +/* + Check if any of touch pads has been activated + by reading a table updated by rtc_intr() + If so, then print it out on a serial monitor. + Clear related entry in the table afterwards + + In interrupt mode, the table is updated in touch ISR. + + In filter mode, we will compare the current filtered value with the initial one. + If the current filtered value is less than 80% of the initial value, we can + regard it as a 'touched' event. + When calling touch_pad_init, a timer will be started to run the filter. + This mode is designed for the situation that the pad is covered + by a 2-or-3-mm-thick medium, usually glass or plastic. + The difference caused by a 'touch' action could be very small, but we can still use + filter mode to detect a 'touch' event. + */ +static void tp_example_read_task(void *pvParameter) +{ + static int show_message; + int change_mode = 0; + int filter_mode = 0; + while (1) { + if (filter_mode == 0) { + //interrupt mode, enable touch interrupt + touch_pad_intr_enable(); + for (int i = 0; i < TOUCH_PAD_MAX; i++) { + if (s_pad_activated[i] == true) { + ESP_LOGI(TAG, "T%d activated!", i); + // Wait a while for the pad being released + vTaskDelay(200 / portTICK_PERIOD_MS); + // Clear information on pad activation + s_pad_activated[i] = false; + // Reset the counter triggering a message + // that application is running + show_message = 1; + } + } + } else { + //filter mode, disable touch interrupt + touch_pad_intr_disable(); + touch_pad_clear_status(); + for (int i = 0; i < TOUCH_PAD_MAX; i++) { + uint16_t value = 0; + touch_pad_read_filtered(i, &value); + if (value < s_pad_init_val[i] * TOUCH_THRESH_PERCENT / 100) { + ESP_LOGI(TAG, "T%d activated!", i); + ESP_LOGI(TAG, "value: %d; init val: %d", value, s_pad_init_val[i]); + vTaskDelay(200 / portTICK_PERIOD_MS); + // Reset the counter to stop changing mode. + change_mode = 1; + show_message = 1; + } + } + } + + vTaskDelay(10 / portTICK_PERIOD_MS); + + // If no pad is touched, every couple of seconds, show a message + // that application is running + if (show_message++ % 500 == 0) { + ESP_LOGI(TAG, "Waiting for any pad being touched..."); + } + // Change mode if no pad is touched for a long time. + // We can compare the two different mode. + if (change_mode++ % 2000 == 0) { + filter_mode = !filter_mode; + ESP_LOGW(TAG, "Change mode...%s", filter_mode == 0 ? "interrupt mode" : "filter mode"); + } + } +} + +/* + Handle an interrupt triggered when a pad is touched. + Recognize what pad has been touched and save it in a table. + */ +static void tp_example_rtc_intr(void *arg) +{ + uint32_t pad_intr = touch_pad_get_status(); + //clear interrupt + touch_pad_clear_status(); + for (int i = 0; i < TOUCH_PAD_MAX; i++) { + if ((pad_intr >> i) & 0x01) { + s_pad_activated[i] = true; + } + } +} + +/* + * Before reading touch pad, we need to initialize the RTC IO. + */ +static void tp_example_touch_pad_init() +{ + for (int i = 0; i < TOUCH_PAD_MAX; i++) { + //init RTC IO and mode for touch pad. + touch_pad_config(i, TOUCH_THRESH_NO_USE); + } +} + +void app_main() +{ + // Initialize touch pad peripheral, it will start a timer to run a filter + ESP_LOGI(TAG, "Initializing touch pad"); + touch_pad_init(); + // If use interrupt trigger mode, should set touch sensor FSM mode at 'TOUCH_FSM_MODE_TIMER'. + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); + // Set reference voltage for charging/discharging + // For most usage scenarios, we recommend using the following combination: + // the high reference valtage will be 2.7V - 1V = 1.7V, The low reference voltage will be 0.5V. + touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_1V); + // Init touch pad IO + tp_example_touch_pad_init(); + // Initialize and start a software filter to detect slight change of capacitance. + touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD); + // Set thresh hold + tp_example_set_thresholds(); + // Register touch interrupt ISR + touch_pad_isr_register(tp_example_rtc_intr, NULL); + // Start a task to show what pads have been touched + xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); +} diff --git a/examples/peripherals/touch_pad_interrupt/main/esp32s2beta/tp_interrupt_main.c b/examples/peripherals/touch_pad_interrupt/main/esp32s2beta/tp_interrupt_main.c new file mode 100644 index 0000000000..a65be4d01c --- /dev/null +++ b/examples/peripherals/touch_pad_interrupt/main/esp32s2beta/tp_interrupt_main.c @@ -0,0 +1,201 @@ +/* Touch Pad Interrupt Example + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "esp_log.h" + +#include "driver/touch_pad.h" +#include "soc/rtc_periph.h" +#include "soc/sens_periph.h" + +static const char *TAG = "Touch pad"; + +static QueueHandle_t que_touch = NULL; +typedef struct touch_msg { + touch_pad_intr_mask_t intr_mask; + uint32_t pad_num; + uint32_t pad_status; + uint32_t pad_val; +} touch_event_t; + +#define TOUCH_BUTTON_NUM 4 +#define TOUCH_BUTTON_WATERPROOF_ENABLE 1 +#define TOUCH_BUTTON_DENOISE_ENABLE 1 + +static const touch_pad_t button[TOUCH_BUTTON_NUM] = { + TOUCH_PAD_NUM7, // 'SELECT' button. + TOUCH_PAD_NUM9, // 'MENU' button. + TOUCH_PAD_NUM11, // 'BACK' button. + TOUCH_PAD_NUM13, // Guard ring for waterproof design. + // if this pad be touched, other pads no response. +}; + +/* + * Touch threshold. The threshold determines the sensitivity of the touch. + * This threshold is derived by testing changes in readings from different touch channels. + * If (raw_data - baseline) > baseline * threshold, the pad be actived. + * If (raw_data - baseline) < baseline * threshold, the pad be inactived. + */ +static const float button_threshold[TOUCH_BUTTON_NUM] = { + 0.2, // 20%. + 0.2, // 20%. + 0.2, // 20%. + 0.1, // 10%. +}; + +/* + Handle an interrupt triggered when a pad is touched. + Recognize what pad has been touched and save it in a table. + */ +static void touchsensor_interrupt_cb(void *arg) +{ + int task_awoken = pdFALSE; + touch_event_t evt; + + evt.intr_mask = touch_pad_intr_status_get_mask(); + evt.pad_status = touch_pad_get_status(); + evt.pad_num = touch_pad_get_scan_curr(); + + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_DONE) { + touch_pad_filter_baseline_read(evt.pad_num, &evt.pad_val); + } + xQueueSendFromISR(que_touch, &evt, &task_awoken); + if (task_awoken == pdTRUE) { + portYIELD_FROM_ISR(); + } +} + +static void tp_example_set_thresholds(void) +{ + uint32_t touch_value; + for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { + //read baseline value + touch_pad_read_raw_data(button[i], &touch_value); + //set interrupt threshold. + touch_pad_set_thresh(button[i], touch_value * button_threshold[i]); + ESP_LOGI(TAG, "test init: touch pad [%d] base %d, thresh %d", \ + button[i], touch_value, (uint32_t)(touch_value * button_threshold[i])); + } +} + +static void touchsensor_filter_set(touch_filter_mode_t mode) +{ + /* Filter function */ + touch_filter_config_t filter_info = { + .mode = mode, // Test jitter and filter 1/4. + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 1, // 9.4% + .noise_thr = 1, // 37.5% + .noise_neg_thr = 1, // 37.5% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + }; + touch_pad_filter_set_config(&filter_info); + touch_pad_filter_enable(); + touch_pad_filter_baseline_reset(TOUCH_PAD_MAX); + ESP_LOGI(TAG, "touch pad filter init %d", mode); +} + +static void tp_example_read_task(void *pvParameter) +{ + touch_event_t evt = {0}; + static uint8_t guard_mode_flag = 0; + /* Wait touch sensor init done */ + vTaskDelay(100 / portTICK_RATE_MS); + tp_example_set_thresholds(); + + while (1) { + int ret = xQueueReceive(que_touch, &evt, (portTickType)portMAX_DELAY); + if (ret != pdTRUE) { + continue; + } + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_ACTIVE) { + /* if guard pad be touched, other pads no response. */ + if (evt.pad_num == button[3]) { + guard_mode_flag = 1; + ESP_LOGW(TAG, "TouchSensor [%d] be actived, enter guard mode", evt.pad_num); + } else { + if (guard_mode_flag == 0) { + ESP_LOGI(TAG, "TouchSensor [%d] be actived, status mask 0x%x", evt.pad_num, evt.pad_status); + } else { + ESP_LOGW(TAG, "In guard mode. No response"); + } + } + } + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_INACTIVE) { + /* if guard pad be touched, other pads no response. */ + if (evt.pad_num == button[3]) { + guard_mode_flag = 0; + ESP_LOGW(TAG, "TouchSensor [%d] be actived, exit guard mode", evt.pad_num); + } else { + if (guard_mode_flag == 0) { + ESP_LOGI(TAG, "TouchSensor [%d] be inactived, status mask 0x%x", evt.pad_num, evt.pad_status); + } + } + } + if (evt.intr_mask & TOUCH_PAD_INTR_MASK_DONE) { + ESP_LOGI(TAG, "TouchSensor [%d] measure done, raw data %d", evt.pad_num, evt.pad_val); + } + } +} + +void app_main() +{ + if (que_touch == NULL) { + que_touch = xQueueCreate(TOUCH_BUTTON_NUM, sizeof(touch_event_t)); + } + // Initialize touch pad peripheral, it will start a timer to run a filter + ESP_LOGI(TAG, "Initializing touch pad"); + /* Initialize touch pad peripheral. */ + touch_pad_init(); + for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { + touch_pad_config(button[i]); + touch_pad_set_thresh(button[i], TOUCH_PAD_THRESHOLD_MAX); + } + +#if TOUCH_BUTTON_DENOISE_ENABLE + /* Denoise setting at TouchSensor 0. */ + touch_pad_denoise_t denoise = { + /* The bits to be cancelled are determined according to the noise level. */ + .grade = TOUCH_PAD_DENOISE_BIT4, + .cap_level = TOUCH_PAD_DENOISE_CAP_L7, + }; + touch_pad_denoise_set_config(denoise); + touch_pad_denoise_enable(); + ESP_LOGI(TAG, "Denoise function init"); +#endif + +#if TOUCH_BUTTON_WATERPROOF_ENABLE + /* Waterproof function */ + touch_pad_waterproof_t waterproof = { + .guard_ring_pad = button[3], // If no ring pad, set 0; + /* It depends on the number of the parasitic capacitance of the shield pad. */ + .shield_driver = TOUCH_PAD_SHIELD_DRV_L0, //40pf + }; + touch_pad_waterproof_set_config(waterproof); + touch_pad_waterproof_enable(); + ESP_LOGI(TAG, "touch pad waterproof init"); +#endif + + /* Filter setting */ + touchsensor_filter_set(TOUCH_PAD_FILTER_IIR_8); + /* Register touch interrupt ISR, enable intr type. */ + touch_pad_isr_register(touchsensor_interrupt_cb, NULL, TOUCH_PAD_INTR_MASK_ALL); + touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); + // touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_DONE); // Use for debug + + /* Enable touch sensor clock. Work mode is "timer trigger". */ + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); + touch_pad_fsm_start(); + + // Start a task to show what pads have been touched + xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); +} diff --git a/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c b/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c deleted file mode 100644 index 2381ef8b2f..0000000000 --- a/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c +++ /dev/null @@ -1,356 +0,0 @@ -/* Touch Pad Interrupt Example - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/queue.h" -#include "esp_log.h" - -#include "driver/touch_pad.h" -#include "soc/rtc_periph.h" -#include "soc/sens_periph.h" - -static const char* TAG = "Touch pad"; - -#if CONFIG_IDF_TARGET_ESP32 -#define TOUCH_THRESH_NO_USE (0) -#define TOUCH_THRESH_PERCENT (80) -#define TOUCHPAD_FILTER_TOUCH_PERIOD (10) - -static bool s_pad_activated[TOUCH_PAD_MAX]; -static uint32_t s_pad_init_val[TOUCH_PAD_MAX]; - -/* - Read values sensed at all available touch pads. - Use 2 / 3 of read value as the threshold - to trigger interrupt when the pad is touched. - Note: this routine demonstrates a simple way - to configure activation threshold for the touch pads. - Do not touch any pads when this routine - is running (on application start). - */ -static void tp_example_set_thresholds(void) -{ - uint16_t touch_value; - for (int i = 0; i> i) & 0x01) { - s_pad_activated[i] = true; - } - } -} - -/* - * Before reading touch pad, we need to initialize the RTC IO. - */ -static void tp_example_touch_pad_init() -{ - for (int i = 0;i< TOUCH_PAD_MAX;i++) { - //init RTC IO and mode for touch pad. - touch_pad_config(i, TOUCH_THRESH_NO_USE); - } -} - -void app_main() -{ - // Initialize touch pad peripheral, it will start a timer to run a filter - ESP_LOGI(TAG, "Initializing touch pad"); - touch_pad_init(); - // If use interrupt trigger mode, should set touch sensor FSM mode at 'TOUCH_FSM_MODE_TIMER'. - touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); - // Set reference voltage for charging/discharging - // For most usage scenarios, we recommend using the following combination: - // the high reference valtage will be 2.7V - 1V = 1.7V, The low reference voltage will be 0.5V. - touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_1V); - // Init touch pad IO - tp_example_touch_pad_init(); - // Initialize and start a software filter to detect slight change of capacitance. - touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD); - // Set thresh hold - tp_example_set_thresholds(); - // Register touch interrupt ISR - touch_pad_isr_register(tp_example_rtc_intr, NULL); - // Start a task to show what pads have been touched - xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); -} -#elif CONFIG_IDF_TARGET_ESP32S2BETA - -static QueueHandle_t que_touch = NULL; -typedef struct touch_msg { - touch_pad_intr_mask_t intr_mask; - uint32_t pad_num; - uint32_t pad_status; - uint32_t pad_val; -}touch_event_t; - -#define TOUCH_BUTTON_NUM 4 -#define TOUCH_BUTTON_WATERPROOF_ENABLE 1 -#define TOUCH_BUTTON_DENOISE_ENABLE 1 - -static const touch_pad_t button[TOUCH_BUTTON_NUM] = { - TOUCH_PAD_NUM7, // 'SELECT' button. - TOUCH_PAD_NUM9, // 'MENU' button. - TOUCH_PAD_NUM11, // 'BACK' button. - TOUCH_PAD_NUM13, // Guard ring for waterproof design. - // if this pad be touched, other pads no response. -}; - -/* - * Touch threshold. The threshold determines the sensitivity of the touch. - * This threshold is derived by testing changes in readings from different touch channels. - * If (raw_data - baseline) > baseline * threshold, the pad be actived. - * If (raw_data - baseline) < baseline * threshold, the pad be inactived. - */ -static const float button_threshold[TOUCH_BUTTON_NUM] = { - 0.2, // 20%. - 0.2, // 20%. - 0.2, // 20%. - 0.1, // 10%. -}; - -/* - Handle an interrupt triggered when a pad is touched. - Recognize what pad has been touched and save it in a table. - */ -static void touchsensor_interrupt_cb(void * arg) -{ - int task_awoken = pdFALSE; - touch_event_t evt; - - evt.intr_mask = touch_pad_get_int_status(); - evt.pad_status = touch_pad_get_status(); - evt.pad_num = touch_pad_get_scan_curr(); - - if(evt.intr_mask & TOUCH_PAD_INTR_MASK_DONE) { - touch_pad_filter_baseline_read(evt.pad_num, &evt.pad_val); - } - xQueueSendFromISR(que_touch, &evt, &task_awoken); - if (task_awoken == pdTRUE) { - portYIELD_FROM_ISR(); - } -} - -static void tp_example_set_thresholds(void) -{ - uint32_t touch_value; - for (int i = 0; i +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "driver/touch_pad.h" +#include "esp_log.h" + +#define TOUCH_BUTTON_NUM 14 + +static const char * TAG = "touch read"; +static const touch_pad_t button[TOUCH_BUTTON_NUM] = { + TOUCH_PAD_NUM1, + TOUCH_PAD_NUM2, + TOUCH_PAD_NUM3, + TOUCH_PAD_NUM4, + TOUCH_PAD_NUM5, + TOUCH_PAD_NUM6, + TOUCH_PAD_NUM7, + TOUCH_PAD_NUM8, + TOUCH_PAD_NUM9, + TOUCH_PAD_NUM10, + TOUCH_PAD_NUM11, + TOUCH_PAD_NUM12, + TOUCH_PAD_NUM13, + TOUCH_PAD_NUM14 +}; + +/* + Read values sensed at all available touch pads. + Print out values in a loop on a serial monitor. + */ +static void tp_example_read_task(void *pvParameter) +{ + uint32_t touch_value; + + /* Wait touch sensor init done */ + vTaskDelay(100 / portTICK_RATE_MS); + printf("Touch Sensor read, the output format is: \nTouchpad num:[raw data]\n\n"); + + while (1) { + for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { + touch_pad_read_raw_data(button[i], &touch_value); // read raw data. + printf("T%d: [%4d] ", button[i], touch_value); + } + printf("\n"); + vTaskDelay(200 / portTICK_PERIOD_MS); + } +} + +void app_main() +{ + /* Initialize touch pad peripheral. */ + touch_pad_init(); + for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { + touch_pad_config(button[i]); + touch_pad_set_thresh(button[i], TOUCH_PAD_THRESHOLD_MAX); + } + + /* Denoise setting at TouchSensor 0. */ + touch_pad_denoise_t denoise = { + /* The bits to be cancelled are determined according to the noise level. */ + .grade = TOUCH_PAD_DENOISE_BIT4, + .cap_level = TOUCH_PAD_DENOISE_CAP_L7, + }; + touch_pad_denoise_set_config(denoise); + touch_pad_denoise_enable(); + ESP_LOGI(TAG, "Denoise function init"); + + /* Enable touch sensor clock. Work mode is "timer trigger". */ + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); + touch_pad_fsm_start(); + + /* Start task to read values by pads. */ + xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); +} \ No newline at end of file diff --git a/examples/system/deep_sleep/main/deep_sleep_example_main.c b/examples/system/deep_sleep/main/deep_sleep_example_main.c index 5843e64aa9..84af5a5c3b 100644 --- a/examples/system/deep_sleep/main/deep_sleep_example_main.c +++ b/examples/system/deep_sleep/main/deep_sleep_example_main.c @@ -145,6 +145,7 @@ void app_main() esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, ESP_EXT1_WAKEUP_ANY_HIGH); #ifdef CONFIG_ENABLE_TOUCH_WAKEUP +#if CONFIG_IDF_TARGET_ESP32 // Initialize touch pad peripheral. // The default fsm mode is software trigger mode. touch_pad_init(); @@ -160,9 +161,50 @@ void app_main() touch_pad_config(TOUCH_PAD_NUM9, TOUCH_THRESH_NO_USE); calibrate_touch_pad(TOUCH_PAD_NUM8); calibrate_touch_pad(TOUCH_PAD_NUM9); +#elif CONFIG_IDF_TARGET_ESP32S2BETA + /* Initialize touch pad peripheral. */ + touch_pad_init(); + /* Only support one touch channel in sleep mode. */ + touch_pad_set_thresh(TOUCH_PAD_NUM8, TOUCH_PAD_THRESHOLD_MAX); + touch_pad_sleep_channel_t slp_config = { + .touch_num = TOUCH_PAD_NUM8, + .sleep_pad_threshold = TOUCH_PAD_THRESHOLD_MAX, + .en_proximity = false, + }; + touch_pad_sleep_channel_config(slp_config); + /* Filter setting */ + touch_filter_config_t filter_info = { + .mode = TOUCH_PAD_FILTER_IIR_8, + .debounce_cnt = 1, // 1 time count. + .hysteresis_thr = 1, // 9.4% + .noise_thr = 1, // 37.5% + .noise_neg_thr = 1, // 37.5% + .neg_noise_limit = 10, // 10 time count. + .jitter_step = 4, // use for jitter mode. + }; + touch_pad_filter_set_config(&filter_info); + touch_pad_filter_enable(); + touch_pad_filter_baseline_reset(TOUCH_PAD_MAX); + printf("touch pad filter init %d", TOUCH_PAD_FILTER_IIR_8); + + /* Enable touch sensor clock. Work mode is "timer trigger". */ + touch_pad_fsm_start(TOUCH_FSM_MODE_TIMER); + + uint32_t touch_value; + //read baseline value + touch_pad_read_raw(TOUCH_PAD_NUM8, &touch_value); + //set interrupt threshold. + touch_pad_sleep_channel_t slp_config = { + .touch_num = TOUCH_PAD_NUM8, + .sleep_pad_threshold = touch_value * 0.2, + .en_proximity = false, + }; + touch_pad_sleep_channel_config(slp_config); //20% + printf("test init: touch pad [%d] base %d, thresh %d", \ + TOUCH_PAD_NUM8, touch_value, (uint32_t)(touch_value * 0.2)); +#endif printf("Enabling touch pad wakeup\n"); esp_sleep_enable_touchpad_wakeup(); - #endif // CONFIG_ENABLE_TOUCH_WAKEUP #ifdef CONFIG_ENABLE_ULP_TEMPERATURE_WAKEUP @@ -186,6 +228,7 @@ void app_main() } #ifdef CONFIG_ENABLE_TOUCH_WAKEUP +#if CONFIG_IDF_TARGET_ESP32 static void calibrate_touch_pad(touch_pad_t pad) { int avg = 0; @@ -207,6 +250,7 @@ static void calibrate_touch_pad(touch_pad_t pad) touch_pad_config(pad, threshold); } } +#endif #endif // CONFIG_ENABLE_TOUCH_WAKEUP #ifdef CONFIG_ENABLE_ULP_TEMPERATURE_WAKEUP