Merge branch 'bugfix/rename_some_touch_regs' into 'master'

refactor(lp_ana_periph): sync the reg names to TRM

See merge request espressif/esp-idf!31474
This commit is contained in:
Kevin (Lao Kaiyao)
2024-06-18 20:47:45 +08:00
5 changed files with 50 additions and 120 deletions

View File

@@ -55,11 +55,7 @@ extern "C" {
.benchmark = { \
.filter_mode = TOUCH_BM_IIR_FILTER_4, \
.jitter_step = 4, \
.update = { \
.pos_thresh = TOUCH_UPDATE_BM_POS_THRESH_1_4, \
.neg_thresh = TOUCH_UPDATE_BM_NEG_THRESH_1_4, \
.neg_limit = 5, \
}, \
.denoise_lvl = 1, \
}, \
.data = { \
.smooth_filter = TOUCH_SMOOTH_IIR_FILTER_2, \
@@ -115,35 +111,6 @@ typedef enum {
TOUCH_BM_JITTER_FILTER, /*!< Jitter Filter for benchmark, raw value +/- jitter_step */
} touch_benchmark_filter_mode_t;
/**
* @brief Positive noise limitation of benchmark
* benchmark will only update gradually when
* the smooth data within the positive noise limitation
*
*/
typedef enum {
TOUCH_UPDATE_BM_POS_ALWAYS = -1, /*!< Always update benchmark when (smooth_data - benchmark) > 0 */
TOUCH_UPDATE_BM_POS_THRESH_1_2 = 0, /*!< Only update benchmark when the (smooth_data - benchmark) < 1/2 * activate_threshold */
TOUCH_UPDATE_BM_POS_THRESH_3_8, /*!< Only update benchmark when the (smooth_data - benchmark) < 3/8 * activate_threshold */
TOUCH_UPDATE_BM_POS_THRESH_1_4, /*!< Only update benchmark when the (smooth_data - benchmark) < 1/4 * activate_threshold */
TOUCH_UPDATE_BM_POS_THRESH_1, /*!< Only update benchmark when the (smooth_data - benchmark) < 1 * activate_threshold */
} touch_benchmark_pos_thresh_t;
/**
* @brief Negative noise limitation of benchmark
* benchmark will only update gradually when
* the smooth data within the negative noise limitation
*
*/
typedef enum {
TOUCH_UPDATE_BM_NEG_NEVER = -2, /*!< Never update benchmark when (benchmark - smooth_data) > 0 */
TOUCH_UPDATE_BM_NEG_ALWAYS = -1, /*!< Always update benchmark when (benchmark - smooth_data) > 0 */
TOUCH_UPDATE_BM_NEG_THRESH_1_2 = 0, /*!< Only update benchmark when the (benchmark - smooth_data) < 1/2 * activate_threshold */
TOUCH_UPDATE_BM_NEG_THRESH_3_8, /*!< Only update benchmark when the (benchmark - smooth_data) < 3/8 * activate_threshold */
TOUCH_UPDATE_BM_NEG_THRESH_1_4, /*!< Only update benchmark when the (benchmark - smooth_data) < 1/4 * activate_threshold */
TOUCH_UPDATE_BM_NEG_THRESH_1, /*!< Only update benchmark when the (benchmark - smooth_data) < 1 * activate_threshold */
} touch_benchmark_neg_thresh_t;
/**
* @brief Touch channel Infinite Impulse Response (IIR) filter for smooth data
*
@@ -222,31 +189,11 @@ typedef struct {
touch_benchmark_filter_mode_t filter_mode; /*!< Benchmark filter mode. IIR filter and Jitter filter can be selected,
* TOUCH_BM_IIR_FILTER_16 is recommended
*/
uint32_t jitter_step; /*!< Jitter filter step size, only takes effect when the `filter_mode` is TOUCH_BM_JITTER_FILTER. Range: 0 ~ 15 */
/**
* @brief Benchmark update strategy
*/
struct {
touch_benchmark_pos_thresh_t pos_thresh; /*!< Select the positive noise threshold. Higher = More noise resistance.
* Range: [-1 ~ 3]. The coefficient of the positive threshold are -1: always; 0: 4/8; 1: 3/8; 2: 2/8; 3: 1;
* Once the data of the channel exceeded the positive threshold (i.e., benchmark + coefficient * touch threshold),
* the benchmark will stop updated to that value.
* -1: ignore the positive threshold and always update the benchmark for positive noise
uint32_t jitter_step; /*!< Jitter filter step size, only takes effect when the `filter_mode` is TOUCH_BM_JITTER_FILTER. Range: [0 ~ 15] */
int denoise_lvl; /*!< The denoise level, which determines the noise bouncing range that won't trigger benchmark update.
* Range: [0 ~ 4]. The greater the denoise_lvl is, more noise resistance will be. Specially, `0` stands for no denoise
* Typically, recommend to set this field to 1.
*/
touch_benchmark_neg_thresh_t neg_thresh; /*!< Select the negative noise threshold. Higher = More noise resistance.
* Range: [-2 ~ 3]. The coefficient of the negative threshold are -2: never; -1: always; 0: 4/8; 1: 3/8; 2: 2/8; 3: 1;
* Once the data of the channel below the negative threshold (i.e., benchmark - coefficient * touch threshold),
* the benchmark will stop updated to that value,
* unless the data keep below the negative threshold for more than the limitation of `neg_limit`
* -1: ignore the negative threshold and always update the benchmark for negative noise
* -2: never update the benchmark for negative noise
*/
uint32_t neg_limit; /*!< Set the time limitation of the negative threshold.
* The benchmark will be updated to the value that below to the negative threshold after the limited time.
* Normally the negative update is used at the beginning, as the initial benchmark is a very large value.
* (the unit of `neg_limit` is the tick of the slow clock source)
*/
} update; /*!< The benchmark update strategy */
} benchmark; /*!< Benchmark filter */
/**
* @brief Data configuration

View File

@@ -282,8 +282,8 @@ esp_err_t touch_sensor_config_filter(touch_sensor_handle_t sens_handle, const to
{
TOUCH_NULL_POINTER_CHECK(sens_handle);
if (filter_cfg) {
ESP_RETURN_ON_FALSE(filter_cfg->benchmark.update.neg_limit >= filter_cfg->data.debounce_cnt,
ESP_ERR_INVALID_ARG, TAG, "The neg_limit should be greater than debounce_cnt");
ESP_RETURN_ON_FALSE(filter_cfg->benchmark.denoise_lvl >= 0 && filter_cfg->benchmark.denoise_lvl <= 4,
ESP_ERR_INVALID_ARG, TAG, "denoise_lvl is out of range");
}
esp_err_t ret = ESP_OK;
@@ -297,8 +297,7 @@ esp_err_t touch_sensor_config_filter(touch_sensor_handle_t sens_handle, const to
if (filter_cfg->benchmark.filter_mode == TOUCH_BM_JITTER_FILTER) {
touch_ll_filter_set_jitter_step(filter_cfg->benchmark.jitter_step);
}
touch_ll_filter_set_pos_noise_thresh(filter_cfg->benchmark.update.pos_thresh);
touch_ll_filter_set_neg_noise_thresh(filter_cfg->benchmark.update.neg_thresh, filter_cfg->benchmark.update.neg_limit);
touch_ll_filter_set_denoise_level(filter_cfg->benchmark.denoise_lvl);
/* Configure the touch data filter */
touch_ll_filter_set_smooth_mode(filter_cfg->data.smooth_filter);
touch_ll_filter_set_active_hysteresis(filter_cfg->data.active_hysteresis);

View File

@@ -695,39 +695,23 @@ static inline void touch_ll_filter_set_debounce(uint32_t dbc_cnt)
}
/**
* Set the positive noise threshold coefficient. Higher = More noise resistance.
* The benchmark will update to the new value if the touch data is within (benchmark + active_threshold * pos_coeff)
* Set the denoise coefficient regarding the denoise level.
*
*
* @param pos_noise_thresh Range [-1 ~ 3]. The coefficient is -1: always; 0: 4/8; 1: 3/8; 2: 2/8; 3: 1;
* -1: the benchmark will always update to the new touch data without considering the positive noise threshold
* @param denoise_lvl Range [0 ~ 4]. 0 = no noise resistance, otherwise higher denoise_lvl means more noise resistance.
*/
static inline void touch_ll_filter_set_pos_noise_thresh(int pos_noise_thresh)
static inline void touch_ll_filter_set_denoise_level(int denoise_lvl)
{
bool always_update = pos_noise_thresh < 0;
LP_ANA_PERI.touch_filter2.touch_bypass_noise_thres = always_update;
LP_ANA_PERI.touch_filter1.touch_noise_thres = always_update ? 0 : pos_noise_thresh;
}
HAL_ASSERT(denoise_lvl >= 0 && denoise_lvl <= 4);
bool always_update = denoise_lvl == 0;
// Map denoise level to actual noise threshold coefficients
uint32_t noise_thresh = denoise_lvl == 4 ? 3 : 3 - denoise_lvl;
/**
* Set the negative noise threshold coefficient. Higher = More noise resistance.
* The benchmark will update to the new value if the touch data is greater than (benchmark - active_threshold * neg_coeff)
*
* @param neg_noise_thresh Range [-2 ~ 3]. The coefficient is -2: never; -1: always; 0: 4/8; 1: 3/8; 2: 2/8; 3: 1;
* -1: the benchmark will always update to the new touch data without considering the negative noise threshold
* -2: the benchmark will never update to the new touch data with negative growth
* @param neg_noise_limit Only when neg_noise_thresh >= 0, if the touch data keep blow the negative threshold for mare than neg_noise_limit ticks,
* the benchmark will still update to the new value.
* It is normally used for updating the benchmark at the first scanning
*/
static inline void touch_ll_filter_set_neg_noise_thresh(int neg_noise_thresh, uint8_t neg_noise_limit)
{
bool always_update = neg_noise_thresh == -1;
bool stop_update = neg_noise_thresh == -2;
LP_ANA_PERI.touch_filter2.touch_bypass_neg_noise_thres = always_update;
LP_ANA_PERI.touch_filter1.touch_neg_noise_disupdate_baseline_en = stop_update;
LP_ANA_PERI.touch_filter1.touch_neg_noise_thres = always_update || stop_update ? 0 : neg_noise_thresh;
LP_ANA_PERI.touch_filter1.touch_neg_noise_limit = always_update || stop_update ? 5 : neg_noise_limit; // 5 is the default value
LP_ANA_PERI.touch_filter2.touch_bypass_noise_thres = always_update;
LP_ANA_PERI.touch_filter1.touch_noise_thres = always_update ? 0 : noise_thresh;
LP_ANA_PERI.touch_filter2.touch_bypass_nn_thres = always_update;
LP_ANA_PERI.touch_filter1.touch_nn_thres = always_update ? 0 : noise_thresh;
LP_ANA_PERI.touch_filter1.touch_nn_limit = 5; // 5 is the default value
}
/**

View File

@@ -1,5 +1,5 @@
/**
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -619,13 +619,13 @@ extern "C" {
* need_des
*/
#define LP_ANALOG_PERI_TOUCH_FILTER1_REG (DR_REG_LP_ANALOG_PERI_BASE + 0x110)
/** LP_ANALOG_PERI_TOUCH_NEG_NOISE_DISUPDATE_BASELINE_EN : R/W; bitpos: [0]; default: 0;
/** LP_ANALOG_PERI_TOUCH_NN_DISUPDATE_BASELINE_EN : R/W; bitpos: [0]; default: 0;
* Reserved
*/
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_DISUPDATE_BASELINE_EN (BIT(0))
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_DISUPDATE_BASELINE_EN_M (LP_ANALOG_PERI_TOUCH_NEG_NOISE_DISUPDATE_BASELINE_EN_V << LP_ANALOG_PERI_TOUCH_NEG_NOISE_DISUPDATE_BASELINE_EN_S)
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_DISUPDATE_BASELINE_EN_V 0x00000001U
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_DISUPDATE_BASELINE_EN_S 0
#define LP_ANALOG_PERI_TOUCH_NN_DISUPDATE_BASELINE_EN (BIT(0))
#define LP_ANALOG_PERI_TOUCH_NN_DISUPDATE_BASELINE_EN_M (LP_ANALOG_PERI_TOUCH_NN_DISUPDATE_BASELINE_EN_V << LP_ANALOG_PERI_TOUCH_NN_DISUPDATE_BASELINE_EN_S)
#define LP_ANALOG_PERI_TOUCH_NN_DISUPDATE_BASELINE_EN_V 0x00000001U
#define LP_ANALOG_PERI_TOUCH_NN_DISUPDATE_BASELINE_EN_S 0
/** LP_ANALOG_PERI_TOUCH_HYSTERESIS : R/W; bitpos: [2:1]; default: 0;
* need_des
*/
@@ -633,13 +633,13 @@ extern "C" {
#define LP_ANALOG_PERI_TOUCH_HYSTERESIS_M (LP_ANALOG_PERI_TOUCH_HYSTERESIS_V << LP_ANALOG_PERI_TOUCH_HYSTERESIS_S)
#define LP_ANALOG_PERI_TOUCH_HYSTERESIS_V 0x00000003U
#define LP_ANALOG_PERI_TOUCH_HYSTERESIS_S 1
/** LP_ANALOG_PERI_TOUCH_NEG_NOISE_THRES : R/W; bitpos: [4:3]; default: 0;
/** LP_ANALOG_PERI_TOUCH_NN_THRES : R/W; bitpos: [4:3]; default: 0;
* need_des
*/
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_THRES 0x00000003U
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_THRES_M (LP_ANALOG_PERI_TOUCH_NEG_NOISE_THRES_V << LP_ANALOG_PERI_TOUCH_NEG_NOISE_THRES_S)
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_THRES_V 0x00000003U
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_THRES_S 3
#define LP_ANALOG_PERI_TOUCH_NN_THRES 0x00000003U
#define LP_ANALOG_PERI_TOUCH_NN_THRES_M (LP_ANALOG_PERI_TOUCH_NN_THRES_V << LP_ANALOG_PERI_TOUCH_NN_THRES_S)
#define LP_ANALOG_PERI_TOUCH_NN_THRES_V 0x00000003U
#define LP_ANALOG_PERI_TOUCH_NN_THRES_S 3
/** LP_ANALOG_PERI_TOUCH_NOISE_THRES : R/W; bitpos: [6:5]; default: 0;
* need_des
*/
@@ -675,13 +675,13 @@ extern "C" {
#define LP_ANALOG_PERI_TOUCH_FILTER_EN_M (LP_ANALOG_PERI_TOUCH_FILTER_EN_V << LP_ANALOG_PERI_TOUCH_FILTER_EN_S)
#define LP_ANALOG_PERI_TOUCH_FILTER_EN_V 0x00000001U
#define LP_ANALOG_PERI_TOUCH_FILTER_EN_S 16
/** LP_ANALOG_PERI_TOUCH_NEG_NOISE_LIMIT : R/W; bitpos: [20:17]; default: 5;
/** LP_ANALOG_PERI_TOUCH_NN_LIMIT : R/W; bitpos: [20:17]; default: 5;
* need_des
*/
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_LIMIT 0x0000000FU
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_LIMIT_M (LP_ANALOG_PERI_TOUCH_NEG_NOISE_LIMIT_V << LP_ANALOG_PERI_TOUCH_NEG_NOISE_LIMIT_S)
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_LIMIT_V 0x0000000FU
#define LP_ANALOG_PERI_TOUCH_NEG_NOISE_LIMIT_S 17
#define LP_ANALOG_PERI_TOUCH_NN_LIMIT 0x0000000FU
#define LP_ANALOG_PERI_TOUCH_NN_LIMIT_M (LP_ANALOG_PERI_TOUCH_NN_LIMIT_V << LP_ANALOG_PERI_TOUCH_NN_LIMIT_S)
#define LP_ANALOG_PERI_TOUCH_NN_LIMIT_V 0x0000000FU
#define LP_ANALOG_PERI_TOUCH_NN_LIMIT_S 17
/** LP_ANALOG_PERI_TOUCH_APPROACH_LIMIT : R/W; bitpos: [28:21]; default: 80;
* need_des
*/
@@ -715,13 +715,13 @@ extern "C" {
#define LP_ANALOG_PERI_TOUCH_BYPASS_NOISE_THRES_M (LP_ANALOG_PERI_TOUCH_BYPASS_NOISE_THRES_V << LP_ANALOG_PERI_TOUCH_BYPASS_NOISE_THRES_S)
#define LP_ANALOG_PERI_TOUCH_BYPASS_NOISE_THRES_V 0x00000001U
#define LP_ANALOG_PERI_TOUCH_BYPASS_NOISE_THRES_S 30
/** LP_ANALOG_PERI_TOUCH_BYPASS_NEG_NOISE_THRES : R/W; bitpos: [31]; default: 0;
/** LP_ANALOG_PERI_TOUCH_BYPASS_NN_THRES : R/W; bitpos: [31]; default: 0;
* need_des
*/
#define LP_ANALOG_PERI_TOUCH_BYPASS_NEG_NOISE_THRES (BIT(31))
#define LP_ANALOG_PERI_TOUCH_BYPASS_NEG_NOISE_THRES_M (LP_ANALOG_PERI_TOUCH_BYPASS_NEG_NOISE_THRES_V << LP_ANALOG_PERI_TOUCH_BYPASS_NEG_NOISE_THRES_S)
#define LP_ANALOG_PERI_TOUCH_BYPASS_NEG_NOISE_THRES_V 0x00000001U
#define LP_ANALOG_PERI_TOUCH_BYPASS_NEG_NOISE_THRES_S 31
#define LP_ANALOG_PERI_TOUCH_BYPASS_NN_THRES (BIT(31))
#define LP_ANALOG_PERI_TOUCH_BYPASS_NN_THRES_M (LP_ANALOG_PERI_TOUCH_BYPASS_NN_THRES_V << LP_ANALOG_PERI_TOUCH_BYPASS_NN_THRES_S)
#define LP_ANALOG_PERI_TOUCH_BYPASS_NN_THRES_V 0x00000001U
#define LP_ANALOG_PERI_TOUCH_BYPASS_NN_THRES_S 31
/** LP_ANALOG_PERI_TOUCH_FILTER3_REG register
* need_des

View File

@@ -510,18 +510,18 @@ typedef union {
*/
typedef union {
struct {
/** touch_neg_noise_disupdate_baseline_en : R/W; bitpos: [0]; default: 0;
/** touch_nn_disupdate_baseline_en : R/W; bitpos: [0]; default: 0;
* Reserved
*/
uint32_t touch_neg_noise_disupdate_baseline_en:1;
uint32_t touch_nn_disupdate_baseline_en:1;
/** touch_hysteresis : R/W; bitpos: [2:1]; default: 0;
* need_des
*/
uint32_t touch_hysteresis:2;
/** touch_neg_noise_thres : R/W; bitpos: [4:3]; default: 0;
/** touch_nn_thres : R/W; bitpos: [4:3]; default: 0;
* need_des
*/
uint32_t touch_neg_noise_thres:2;
uint32_t touch_nn_thres:2;
/** touch_noise_thres : R/W; bitpos: [6:5]; default: 0;
* need_des
*/
@@ -542,10 +542,10 @@ typedef union {
* need_des
*/
uint32_t touch_filter_en:1;
/** touch_neg_noise_limit : R/W; bitpos: [20:17]; default: 5;
/** touch_nn_limit : R/W; bitpos: [20:17]; default: 5;
* need_des
*/
uint32_t touch_neg_noise_limit:4;
uint32_t touch_nn_limit:4;
/** touch_approach_limit : R/W; bitpos: [28:21]; default: 80;
* need_des
*/
@@ -572,10 +572,10 @@ typedef union {
* need_des
*/
uint32_t touch_bypass_noise_thres:1;
/** touch_bypass_neg_noise_thres : R/W; bitpos: [31]; default: 0;
/** touch_bypass_nn_thres : R/W; bitpos: [31]; default: 0;
* need_des
*/
uint32_t touch_bypass_neg_noise_thres:1;
uint32_t touch_bypass_nn_thres:1;
};
uint32_t val;
} lp_analog_peri_touch_filter2_reg_t;