driver(touch): support touch sensor for esp32s3 platform

This commit is contained in:
fuzhibo
2021-06-22 21:53:16 +08:00
committed by laokaiyao
parent 9711e8e0aa
commit 057b9d61b5
26 changed files with 531 additions and 104 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
// Copyright 2015-2021 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.
@@ -174,7 +174,11 @@ static inline void touch_ll_get_voltage_attenuation(touch_volt_atten_t *atten)
*/
static inline void touch_ll_set_slope(touch_pad_t touch_num, touch_cnt_slope_t slope)
{
abort();//IDF-3417
if (touch_num < TOUCH_PAD_NUM10) {
SET_PERI_REG_BITS(RTC_CNTL_TOUCH_DAC_REG, RTC_CNTL_TOUCH_PAD0_DAC_V, slope, (RTC_CNTL_TOUCH_PAD0_DAC_S - touch_num * 3));
} else {
SET_PERI_REG_BITS(RTC_CNTL_TOUCH_DAC1_REG, RTC_CNTL_TOUCH_PAD10_DAC_V, slope, (RTC_CNTL_TOUCH_PAD10_DAC_S - (touch_num - TOUCH_PAD_NUM10) * 3));
}
}
/**
@@ -189,7 +193,11 @@ static inline void touch_ll_set_slope(touch_pad_t touch_num, touch_cnt_slope_t s
*/
static inline void touch_ll_get_slope(touch_pad_t touch_num, touch_cnt_slope_t *slope)
{
abort();//IDF-3417
if (touch_num < TOUCH_PAD_NUM10) {
*slope = GET_PERI_REG_BITS2(RTC_CNTL_TOUCH_DAC_REG, RTC_CNTL_TOUCH_PAD0_DAC_V, (RTC_CNTL_TOUCH_PAD0_DAC_S - touch_num * 3));
} else {
*slope = GET_PERI_REG_BITS2(RTC_CNTL_TOUCH_DAC1_REG, RTC_CNTL_TOUCH_PAD10_DAC_V, (RTC_CNTL_TOUCH_PAD10_DAC_S - (touch_num - TOUCH_PAD_NUM10) * 3));
}
}
/**
@@ -413,7 +421,7 @@ static inline void touch_ll_clear_trigger_status_mask(void)
static inline uint32_t IRAM_ATTR touch_ll_read_raw_data(touch_pad_t touch_num)
{
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_RAW;
return SENS.sar_touch_status[touch_num - 1].touch_pad1_data;
return SENS.sar_touch_status[touch_num - 1].touch_pad_data;
}
/**
@@ -490,19 +498,22 @@ static inline touch_pad_t IRAM_ATTR touch_ll_get_current_meas_channel(void)
static inline void touch_ll_intr_enable(touch_pad_intr_mask_t int_mask)
{
if (int_mask & TOUCH_PAD_INTR_MASK_DONE) {
RTCCNTL.int_ena.rtc_touch_done = 1;
RTCCNTL.int_ena_w1ts.rtc_touch_done_w1ts = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_ACTIVE) {
RTCCNTL.int_ena.rtc_touch_active = 1;
RTCCNTL.int_ena_w1ts.rtc_touch_active_w1ts = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_INACTIVE) {
RTCCNTL.int_ena.rtc_touch_inactive = 1;
RTCCNTL.int_ena_w1ts.rtc_touch_inactive_w1ts = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) {
RTCCNTL.int_ena.rtc_touch_scan_done = 1;
RTCCNTL.int_ena_w1ts.rtc_touch_scan_done_w1ts = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) {
RTCCNTL.int_ena.rtc_touch_timeout = 1;
RTCCNTL.int_ena_w1ts.rtc_touch_timeout_w1ts = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) {
RTCCNTL.int_ena_w1ts.rtc_touch_approach_loop_done_w1ts = 1;
}
}
@@ -514,19 +525,22 @@ static inline void touch_ll_intr_enable(touch_pad_intr_mask_t int_mask)
static inline void touch_ll_intr_disable(touch_pad_intr_mask_t int_mask)
{
if (int_mask & TOUCH_PAD_INTR_MASK_DONE) {
RTCCNTL.int_ena.rtc_touch_done = 0;
RTCCNTL.int_ena_w1tc.rtc_touch_done_w1tc = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_ACTIVE) {
RTCCNTL.int_ena.rtc_touch_active = 0;
RTCCNTL.int_ena_w1tc.rtc_touch_active_w1tc = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_INACTIVE) {
RTCCNTL.int_ena.rtc_touch_inactive = 0;
RTCCNTL.int_ena_w1tc.rtc_touch_inactive_w1tc = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) {
RTCCNTL.int_ena.rtc_touch_scan_done = 0;
RTCCNTL.int_ena_w1tc.rtc_touch_scan_done_w1tc = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) {
RTCCNTL.int_ena.rtc_touch_timeout = 0;
RTCCNTL.int_ena_w1tc.rtc_touch_timeout_w1tc = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) {
RTCCNTL.int_ena_w1tc.rtc_touch_approach_loop_done_w1tc = 1;
}
}
@@ -552,6 +566,9 @@ static inline void touch_ll_intr_clear(touch_pad_intr_mask_t int_mask)
if (int_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) {
RTCCNTL.int_clr.rtc_touch_timeout = 1;
}
if (int_mask & TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE) {
RTCCNTL.int_clr.rtc_touch_approach_loop_done = 1;
}
}
/**
@@ -579,6 +596,9 @@ static inline uint32_t touch_ll_read_intr_status_mask(void)
if (intr_st & RTC_CNTL_TOUCH_TIMEOUT_INT_ST_M) {
intr_msk |= TOUCH_PAD_INTR_MASK_TIMEOUT;
}
if (intr_st & RTC_CNTL_TOUCH_APPROACH_LOOP_DONE_INT_ST_M) {
intr_msk |= TOUCH_PAD_INTR_MASK_PROXI_MEAS_DONE;
}
return (intr_msk & TOUCH_PAD_INTR_MASK_ALL);
}
@@ -641,7 +661,7 @@ static inline void touch_ll_timeout_get_threshold(uint32_t *threshold)
static inline void IRAM_ATTR touch_ll_filter_read_smooth(touch_pad_t touch_num, uint32_t *smooth_data)
{
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_SMOOTH;
*smooth_data = SENS.sar_touch_status[touch_num - 1].touch_pad1_data;
*smooth_data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
}
/**
@@ -654,7 +674,7 @@ static inline void IRAM_ATTR touch_ll_filter_read_smooth(touch_pad_t touch_num,
static inline void IRAM_ATTR touch_ll_read_benchmark(touch_pad_t touch_num, uint32_t *benchmark)
{
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_BENCHMARK;
*benchmark = SENS.sar_touch_status[touch_num - 1].touch_pad1_data;
*benchmark = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
}
/**
@@ -749,9 +769,9 @@ static inline void touch_ll_filter_get_debounce(uint32_t *dbc_cnt)
static inline void touch_ll_filter_set_noise_thres(uint32_t noise_thr)
{
RTCCNTL.touch_filter_ctrl.touch_noise_thres = noise_thr;
RTCCNTL.touch_filter_ctrl.touch_neg_noise_thres = noise_thr;
RTCCNTL.touch_filter_ctrl.touch_neg_noise_limit = 0xF;
RTCCNTL.touch_filter_ctrl.touch_hysteresis = 2;
RTCCNTL.touch_filter_ctrl.config2 = noise_thr;
RTCCNTL.touch_filter_ctrl.config1 = 0xF;
RTCCNTL.touch_filter_ctrl.config3 = 2;
}
/**
@@ -889,7 +909,7 @@ static inline void touch_ll_denoise_get_grade(touch_pad_denoise_grade_t *grade)
*/
static inline void touch_ll_denoise_read_data(uint32_t *data)
{
*data = SENS.sar_touch_status0.touch_denoise_data;
*data = SENS.sar_touch_denoise.touch_denoise_data;
}
/************************ Waterproof register setting ************************/
@@ -1014,6 +1034,13 @@ static inline void touch_ll_proximity_get_meas_times(uint32_t *times)
*/
static inline void touch_ll_proximity_read_meas_cnt(touch_pad_t touch_num, uint32_t *cnt)
{
if (SENS.sar_touch_conf.touch_approach_pad0 == touch_num) {
*cnt = SENS.sar_touch_appr_status.touch_approach_pad0_cnt;
} else if (SENS.sar_touch_conf.touch_approach_pad1 == touch_num) {
*cnt = SENS.sar_touch_appr_status.touch_approach_pad1_cnt;
} else if (SENS.sar_touch_conf.touch_approach_pad2 == touch_num) {
*cnt = SENS.sar_touch_appr_status.touch_approach_pad2_cnt;
}
}
/**
@@ -1111,17 +1138,22 @@ static inline bool touch_ll_sleep_get_approach_status(void)
*/
static inline void touch_ll_sleep_read_benchmark(uint32_t *benchmark)
{
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_BENCHMARK;
*benchmark = SENS.sar_touch_slp_status.touch_slp_data;
}
static inline void touch_ll_sleep_read_smooth(uint32_t *smooth_data)
{
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_SMOOTH;
*smooth_data = SENS.sar_touch_slp_status.touch_slp_data;
}
/* Workaround: Note: sleep pad raw data is not in `sar_touch_slp_status` */
static inline void touch_ll_sleep_read_data(uint32_t *raw_data)
{
uint32_t touch_num = RTCCNTL.touch_slp_thres.touch_slp_pad;
SENS.sar_touch_conf.touch_data_sel = TOUCH_LL_READ_RAW;
*raw_data = SENS.sar_touch_status[touch_num - 1].touch_pad1_data;
*raw_data = SENS.sar_touch_status[touch_num - 1].touch_pad_data;
}
static inline void touch_ll_sleep_reset_benchmark(void)
@@ -1146,6 +1178,7 @@ static inline void touch_ll_sleep_low_power(bool is_low_power)
*/
static inline void touch_ll_sleep_read_debounce(uint32_t *debounce)
{
*debounce = SENS.sar_touch_slp_status.touch_slp_debounce;
}
/**
@@ -1154,6 +1187,7 @@ static inline void touch_ll_sleep_read_debounce(uint32_t *debounce)
*/
static inline void touch_ll_sleep_read_proximity_cnt(uint32_t *approach_cnt)
{
*approach_cnt = SENS.sar_touch_appr_status.touch_slp_approach_cnt;
}
/**