| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000 |
- // Copyright 2015-2019 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.
- /*******************************************************************************
- * NOTICE
- * The ll is not public api, don't use in application code.
- * See readme.md in soc/include/hal/readme.md
- ******************************************************************************/
- // The Lowlevel layer for Touch Sensor
- #pragma once
- #include <stdlib.h>
- #include <stdbool.h>
- #include "soc/touch_sensor_periph.h"
- #include "hal/touch_sensor_types.h"
- /**
- * Set touch sensor touch sensor times of charge and discharge.
- *
- * @param meas_timers The times of charge and discharge in each measure process of touch channels.
- * The timer frequency is 8Mhz. Range: 0 ~ 0xffff.
- */
- static inline void touch_ll_set_meas_times(uint16_t meas_time)
- {
- //The times of charge and discharge in each measure process of touch channels.
- RTCCNTL.touch_ctrl1.touch_meas_num = meas_time;
- //the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD
- RTCCNTL.touch_ctrl2.touch_xpd_wait = SOC_TOUCH_PAD_MEASURE_WAIT; //wait volt stable
- }
- /**
- * Get touch sensor times of charge and discharge.
- *
- * @param meas_times Pointer to accept times count of charge and discharge.
- */
- static inline void touch_ll_get_measure_times(uint16_t *meas_time)
- {
- *meas_time = RTCCNTL.touch_ctrl1.touch_meas_num;
- }
- /**
- * Set touch sensor sleep time.
- *
- * @param sleep_cycle The touch sensor will sleep after each measurement.
- * sleep_cycle decide the interval between each measurement.
- * t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
- * The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.
- */
- static inline void touch_ll_set_sleep_time(uint16_t sleep_time)
- {
- // touch sensor sleep cycle Time = sleep_cycle / RTC_SLOW_CLK(90k)
- RTCCNTL.touch_ctrl1.touch_sleep_cycles = sleep_time;
- }
- /**
- * Get touch sensor sleep time.
- *
- * @param sleep_cycle Pointer to accept sleep cycle number.
- */
- static inline void touch_ll_get_sleep_time(uint16_t *sleep_time)
- {
- *sleep_time = RTCCNTL.touch_ctrl1.touch_sleep_cycles;
- }
- /**
- * Set touch sensor high voltage threshold of chanrge.
- * The touch sensor measures the channel capacitance value by charging and discharging the channel.
- * So the high threshold should be less than the supply voltage.
- *
- * @param refh The high voltage threshold of chanrge.
- */
- static inline void touch_ll_set_voltage_high(touch_high_volt_t refh)
- {
- RTCCNTL.touch_ctrl2.touch_drefh = refh;
- }
- /**
- * Get touch sensor high voltage threshold of chanrge.
- * The touch sensor measures the channel capacitance value by charging and discharging the channel.
- * So the high threshold should be less than the supply voltage.
- *
- * @param refh The high voltage threshold of chanrge.
- */
- static inline void touch_ll_get_voltage_high(touch_high_volt_t *refh)
- {
- *refh = (touch_high_volt_t)RTCCNTL.touch_ctrl2.touch_drefh;
- }
- /**
- * Set touch sensor low voltage threshold of discharge.
- * The touch sensor measures the channel capacitance value by charging and discharging the channel.
- *
- * @param refl The low voltage threshold of discharge.
- */
- static inline void touch_ll_set_voltage_low(touch_low_volt_t refl)
- {
- RTCCNTL.touch_ctrl2.touch_drefl = refl;
- }
- /**
- * Get touch sensor low voltage threshold of discharge.
- * The touch sensor measures the channel capacitance value by charging and discharging the channel.
- *
- * @param refl The low voltage threshold of discharge.
- */
- static inline void touch_ll_get_voltage_low(touch_low_volt_t *refl)
- {
- *refl = (touch_low_volt_t)RTCCNTL.touch_ctrl2.touch_drefl;
- }
- /**
- * Set touch sensor high voltage attenuation of chanrge. The actual charge threshold is high voltage threshold minus attenuation value.
- * The touch sensor measures the channel capacitance value by charging and discharging the channel.
- * So the high threshold should be less than the supply voltage.
- *
- * @param refh The high voltage threshold of chanrge.
- */
- static inline void touch_ll_set_voltage_attenuation(touch_volt_atten_t atten)
- {
- RTCCNTL.touch_ctrl2.touch_drange = atten;
- }
- /**
- * Get touch sensor high voltage attenuation of chanrge. The actual charge threshold is high voltage threshold minus attenuation value.
- * The touch sensor measures the channel capacitance value by charging and discharging the channel.
- * So the high threshold should be less than the supply voltage.
- *
- * @param refh The high voltage threshold of chanrge.
- */
- static inline void touch_ll_get_voltage_attenuation(touch_volt_atten_t *atten)
- {
- *atten = (touch_volt_atten_t)RTCCNTL.touch_ctrl2.touch_drange;
- }
- /**
- * Set touch sensor charge/discharge speed(currents) for each pad.
- * If the slope is 0, the counter would always be zero.
- * If the slope is 1, the charging and discharging would be slow. The measurement time becomes longer.
- * If the slope is set 7, which is the maximum value, the charging and discharging would be fast.
- * The measurement time becomes shorter.
- *
- * @note The higher the charge and discharge current, the greater the immunity of the touch channel,
- * but it will increase the system power consumption.
- * @param touch_num Touch pad index.
- * @param slope touch pad charge/discharge speed(currents).
- */
- static inline void touch_ll_set_slope(touch_pad_t touch_num, touch_cnt_slope_t slope)
- {
- RTCIO.touch_pad[touch_num].dac = slope;
- }
- /**
- * Get touch sensor charge/discharge speed(currents) for each pad.
- * If the slope is 0, the counter would always be zero.
- * If the slope is 1, the charging and discharging would be slow. The measurement time becomes longer.
- * If the slope is set 7, which is the maximum value, the charging and discharging would be fast.
- * The measurement time becomes shorter.
- *
- * @param touch_num Touch pad index.
- * @param slope touch pad charge/discharge speed(currents).
- */
- static inline void touch_ll_get_slope(touch_pad_t touch_num, touch_cnt_slope_t *slope)
- {
- *slope = (touch_cnt_slope_t)RTCIO.touch_pad[touch_num].dac;
- }
- /**
- * Set initial voltage state of touch channel for each measurement.
- *
- * @param touch_num Touch pad index.
- * @param opt Initial voltage state.
- */
- static inline void touch_ll_set_tie_option(touch_pad_t touch_num, touch_tie_opt_t opt)
- {
- RTCIO.touch_pad[touch_num].tie_opt = opt;
- }
- /**
- * Get initial voltage state of touch channel for each measurement.
- *
- * @param touch_num Touch pad index.
- * @param opt Initial voltage state.
- */
- static inline void touch_ll_get_tie_option(touch_pad_t touch_num, touch_tie_opt_t *opt)
- {
- *opt = (touch_tie_opt_t)RTCIO.touch_pad[touch_num].tie_opt;
- }
- /**
- * Set touch sensor FSM mode.
- * The measurement action can be triggered by the hardware timer, as well as by the software instruction.
- *
- * @param mode FSM mode.
- */
- static inline void touch_ll_set_fsm_mode(touch_fsm_mode_t mode)
- {
- RTCCNTL.touch_ctrl2.touch_start_force = mode;
- }
- /**
- * Get touch sensor FSM mode.
- * The measurement action can be triggered by the hardware timer, as well as by the software instruction.
- *
- * @param mode FSM mode.
- */
- static inline void touch_ll_get_fsm_mode(touch_fsm_mode_t *mode)
- {
- *mode = (touch_fsm_mode_t)RTCCNTL.touch_ctrl2.touch_start_force;
- }
- /**
- * Start touch sensor FSM timer.
- * The measurement action can be triggered by the hardware timer, as well as by the software instruction.
- *
- * @param mode FSM mode.
- */
- static inline void touch_ll_start_fsm(void)
- {
- RTCCNTL.touch_ctrl2.touch_clkgate_en = 1; //enable touch clock for FSM. or force enable.
- RTCCNTL.touch_ctrl2.touch_slp_timer_en = (RTCCNTL.touch_ctrl2.touch_start_force == TOUCH_FSM_MODE_TIMER ? 1 : 0);
- }
- /**
- * Stop touch sensor FSM timer.
- * The measurement action can be triggered by the hardware timer, as well as by the software instruction.
- *
- * @param mode FSM mode.
- */
- static inline void touch_ll_stop_fsm(void)
- {
- 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.
- }
- /**
- * Trigger a touch sensor measurement, only support in SW mode of FSM.
- */
- static inline void touch_ll_start_sw_meas(void)
- {
- RTCCNTL.touch_ctrl2.touch_start_en = 0;
- RTCCNTL.touch_ctrl2.touch_start_en = 1;
- }
- /**
- * Set touch sensor interrupt threshold.
- *
- * @param touch_num touch pad index.
- * @param threshold threshold of touchpad count.
- */
- /**
- * Set the trigger threshold of touch sensor.
- * The threshold determines the sensitivity of the touch sensor.
- * The threshold is the original value of the trigger state minus the benchmark value.
- *
- * @note If set "TOUCH_PAD_THRESHOLD_MAX", the touch is never be trigered.
- * @param touch_num touch pad index
- * @param threshold threshold of touch sensor.
- */
- static inline void touch_ll_set_threshold(touch_pad_t touch_num, uint32_t threshold)
- {
- SENS.touch_thresh[touch_num - 1].thresh = threshold;
- }
- /**
- * Get the trigger threshold of touch sensor.
- * The threshold determines the sensitivity of the touch sensor.
- * The threshold is the original value of the trigger state minus the benchmark value.
- *
- * @param touch_num touch pad index.
- * @param threshold pointer to accept threshold.
- */
- static inline void touch_ll_get_threshold(touch_pad_t touch_num, uint32_t *threshold)
- {
- *threshold = SENS.touch_thresh[touch_num - 1].thresh;
- }
- /**
- * Enable touch sensor channel. Register touch channel into touch sensor measurement group.
- * The working mode of the touch sensor is simultaneous measurement.
- * This function will set the measure bits according to the given bitmask.
- *
- * @note If set this mask, the FSM timer should be stop firsty.
- * @note The touch sensor that in scan map, should be deinit GPIO function firstly.
- * @param enable_mask bitmask of touch sensor scan group.
- * e.g. TOUCH_PAD_NUM1 -> BIT(1)
- * @return
- * - ESP_OK on success
- */
- static inline void touch_ll_set_channel_mask(uint16_t enable_mask)
- {
- RTCCNTL.touch_scan_ctrl.touch_scan_pad_map |= (enable_mask & SOC_TOUCH_SENSOR_BIT_MASK_MAX);
- SENS.sar_touch_conf.touch_outen |= (enable_mask & SOC_TOUCH_SENSOR_BIT_MASK_MAX);
- }
- /**
- * Get touch sensor channel mask.
- *
- * @param enable_mask bitmask of touch sensor scan group.
- * e.g. TOUCH_PAD_NUM1 -> BIT(1)
- */
- static inline void touch_ll_get_channel_mask(uint16_t *enable_mask)
- {
- *enable_mask = SENS.sar_touch_conf.touch_outen \
- & RTCCNTL.touch_scan_ctrl.touch_scan_pad_map \
- & SOC_TOUCH_SENSOR_BIT_MASK_MAX;
- }
- /**
- * Disable touch sensor channel by bitmask.
- *
- * @param enable_mask bitmask of touch sensor scan group.
- * e.g. TOUCH_PAD_NUM1 -> BIT(1)
- */
- static inline void touch_ll_clear_channel_mask(uint16_t disable_mask)
- {
- SENS.sar_touch_conf.touch_outen &= ~(disable_mask & SOC_TOUCH_SENSOR_BIT_MASK_MAX);
- RTCCNTL.touch_scan_ctrl.touch_scan_pad_map &= ~(disable_mask & SOC_TOUCH_SENSOR_BIT_MASK_MAX);
- }
- /**
- * Get the touch sensor trigger status, usually used in ISR to decide which pads are 'touched'.
- *
- * @param status_mask The touch sensor status. e.g. Touch1 trigger status is `status_mask & (BIT1)`.
- */
- static inline void touch_ll_read_trigger_status_mask(uint32_t *status_mask)
- {
- *status_mask = SENS.sar_touch_chn_st.touch_pad_active;
- }
- /**
- * Clear all touch sensor status.
- *
- * @note Generally no manual removal is required.
- */
- static inline void touch_ll_clear_trigger_status_mask(void)
- {
- SENS.sar_touch_conf.touch_status_clr = 1;
- }
- /**
- * To enable touch pad interrupt.
- */
- static inline void touch_ll_enable_interrupt(touch_pad_intr_mask_t int_mask)
- {
- 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;
- }
- }
- /**
- * To disable touch pad interrupt.
- */
- static inline void touch_ll_disable_interrupt(touch_pad_intr_mask_t int_mask)
- {
- 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;
- }
- }
- /**
- * Get touch sensor raw data (touch sensor counter value) from register. No block.
- *
- * @param touch_num touch pad index.
- * @return touch_value pointer to accept touch sensor value.
- */
- static inline uint32_t touch_ll_read_raw_data(touch_pad_t touch_num)
- {
- return SENS.touch_meas[touch_num].meas_out;
- }
- /**
- * Get touch sensor measure status. No block.
- *
- * @return
- * - If touch sensors measure done.
- */
- static inline bool touch_ll_meas_is_done(void)
- {
- return (bool)SENS.sar_touch_chn_st.touch_meas_done;
- }
- /************************* esp32s2beta only *************************/
- /**
- * Reset the whole of touch module.
- *
- * @note Call this funtion after `touch_pad_fsm_stop`,
- */
- static inline void touch_ll_reset(void)
- {
- RTCCNTL.touch_ctrl2.touch_reset = 0;
- RTCCNTL.touch_ctrl2.touch_reset = 1;
- }
- /**
- * Set connection type of touch channel in idle status.
- * When a channel is in measurement mode, other initialized channels are in idle mode.
- * The touch channel is generally adjacent to the trace, so the connection state of the idle channel
- * affects the stability and sensitivity of the test channel.
- * The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
- * The `CONN_GND`(grounding) setting increases the stability of touch channels.
- *
- * @param type Select idle channel connect to high resistance state or ground.
- */
- static inline void touch_ll_set_inactive_connect(touch_pad_conn_type_t type)
- {
- RTCCNTL.touch_scan_ctrl.touch_inactive_connection = type;
- }
- /**
- * Set connection type of touch channel in idle status.
- * When a channel is in measurement mode, other initialized channels are in idle mode.
- * The touch channel is generally adjacent to the trace, so the connection state of the idle channel
- * affects the stability and sensitivity of the test channel.
- * The `CONN_HIGHZ`(high resistance) setting increases the sensitivity of touch channels.
- * The `CONN_GND`(grounding) setting increases the stability of touch channels.
- *
- * @param type Select idle channel connect to high resistance state or ground.
- */
- static inline void touch_ll_get_inactive_connect(touch_pad_conn_type_t *type)
- {
- *type = RTCCNTL.touch_scan_ctrl.touch_inactive_connection;
- }
- /**
- * Get the current measure channel. Touch sensor measurement is cyclic scan mode.
- *
- * @return
- * - touch channel number
- */
- static inline touch_pad_t touch_ll_get_current_meas_channel(void)
- {
- return (touch_pad_t)(SENS.sar_touch_status0.touch_scan_curr);
- }
- /**
- * Enable touch sensor interrupt by bitmask.
- *
- * @param type interrupt type
- */
- 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;
- }
- 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;
- }
- }
- /**
- * Disable touch sensor interrupt by bitmask.
- *
- * @param type interrupt type
- */
- 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;
- }
- 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;
- }
- }
- /**
- * Get the bitmask of touch sensor interrupt status.
- *
- * @return type interrupt type
- */
- static inline uint32_t touch_ll_read_intr_status_mask(void)
- {
- uint32_t intr_st = RTCCNTL.int_st.val;
- uint32_t intr_msk = 0;
- if (intr_st & RTC_CNTL_TOUCH_DONE_INT_ST_M) {
- intr_msk |= TOUCH_PAD_INTR_MASK_DONE;
- }
- if (intr_st & RTC_CNTL_TOUCH_ACTIVE_INT_ST_M) {
- intr_msk |= TOUCH_PAD_INTR_MASK_ACTIVE;
- }
- if (intr_st & RTC_CNTL_TOUCH_INACTIVE_INT_ST_M) {
- intr_msk |= TOUCH_PAD_INTR_MASK_INACTIVE;
- }
- return (intr_msk & TOUCH_PAD_INTR_MASK_ALL);
- }
- /************************ Filter register setting ************************/
- /**
- * Get benchmark value of touch sensor.
- *
- * @note After initialization, the benchmark value is the maximum during the first measurement period.
- * @param touch_num touch pad index
- * @param touch_value pointer to accept touch sensor value
- */
- static inline void touch_ll_filter_read_benchmark(touch_pad_t touch_num, uint32_t *basedata)
- {
- *basedata = SENS.sar_touch_status[touch_num - 1].touch_pad_benchmark;
- }
- /**
- * Force reset benchmark to raw data of touch sensor.
- *
- * @param touch_num touch pad index
- * - TOUCH_PAD_MAX Reset basaline of all channels.
- */
- static inline void touch_ll_filter_reset_benchmark(touch_pad_t touch_num)
- {
- if (touch_num == TOUCH_PAD_MAX) {
- SENS.sar_touch_chn_st.touch_channel_clr = SOC_TOUCH_SENSOR_BIT_MASK_MAX;
- } else {
- SENS.sar_touch_chn_st.touch_channel_clr = (1U << touch_num);
- }
- }
- /**
- * Set filter mode. The input to the filter is raw data and the output is the benchmark value.
- * Larger filter coefficients increase the stability of the benchmark.
- *
- * @param mode Filter mode type. Refer to `touch_filter_mode_t`.
- */
- static inline void touch_ll_filter_set_filter_mode(touch_filter_mode_t mode)
- {
- RTCCNTL.touch_filter_ctrl.touch_filter_mode = mode;
- }
- /**
- * Get filter mode. The input to the filter is raw data and the output is the benchmark value.
- *
- * @param mode Filter mode type. Refer to `touch_filter_mode_t`.
- */
- static inline void touch_ll_filter_get_filter_mode(touch_filter_mode_t *mode)
- {
- *mode = (touch_filter_mode_t)RTCCNTL.touch_filter_ctrl.touch_filter_mode;
- }
- /**
- * Set debounce count, such as `n`. If the measured values continue to exceed
- * the threshold for `n` times, it is determined that the touch sensor state changes.
- *
- * @param dbc_cnt Debounce count value.
- */
- static inline void touch_ll_filter_set_debounce(uint32_t dbc_cnt)
- {
- RTCCNTL.touch_filter_ctrl.touch_debounce = dbc_cnt;
- }
- /**
- * Get debounce count.
- *
- * @param dbc_cnt Debounce count value.
- */
- static inline void touch_ll_filter_get_debounce(uint32_t *dbc_cnt)
- {
- *dbc_cnt = RTCCNTL.touch_filter_ctrl.touch_debounce;
- }
- /**
- * Set noise threshold coefficient. noise = noise_thr * touch threshold.
- * If (raw data - benchmark) > (noise), the benchmark stop updating.
- * If (raw data - benchmark) < (noise), the benchmark start updating.
- * Range: 0 ~ 3. The coefficient is 0: 1/2; 1: 3/8; 2: 1/4; 3: 1/8;
- *
- * @param hys_thr Noise threshold coefficient.
- */
- 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.config2 = noise_thr;
- RTCCNTL.touch_filter_ctrl.config1 = 0xF;
- RTCCNTL.touch_filter_ctrl.config3 = 2;
- }
- /**
- * Get noise threshold coefficient. noise = noise_thr * touch threshold.
- * If (raw data - benchmark) > (noise), the benchmark stop updating.
- * If (raw data - benchmark) < (noise), the benchmark start updating.
- * Range: 0 ~ 3. The coefficient is 0: 1/2; 1: 3/8; 2: 1/4; 3: 1/8;
- *
- * @param noise_thr Noise threshold coefficient.
- */
- static inline void touch_ll_filter_get_noise_thres(uint32_t *noise_thr)
- {
- *noise_thr = RTCCNTL.touch_filter_ctrl.touch_noise_thres;
- }
- /**
- * Set jitter filter step size.
- * If filter mode is jitter, should set filter step for jitter.
- * Range: 0 ~ 15
- *
- * @param step The step size of the data change when the benchmark is updated.
- */
- static inline void touch_ll_filter_set_jitter_step(uint32_t step)
- {
- RTCCNTL.touch_filter_ctrl.touch_jitter_step = step;
- }
- /**
- * Get jitter filter step size.
- * If filter mode is jitter, should set filter step for jitter.
- * Range: 0 ~ 15
- *
- * @param step The step size of the data change when the benchmark is updated.
- */
- static inline void touch_ll_filter_get_jitter_step(uint32_t *step)
- {
- *step = RTCCNTL.touch_filter_ctrl.touch_jitter_step;
- }
- /**
- * Enable touch sensor filter and detection algorithm.
- * For more details on the detection algorithm, please refer to the application documentation.
- */
- static inline void touch_ll_filter_enable(void)
- {
- RTCCNTL.touch_filter_ctrl.touch_filter_en = 1;
- }
- /**
- * Disable touch sensor filter and detection algorithm.
- * For more details on the detection algorithm, please refer to the application documentation.
- */
- static inline void touch_ll_filter_disable(void)
- {
- RTCCNTL.touch_filter_ctrl.touch_filter_en = 0;
- }
- /************************ Denoise register setting ************************/
- /**
- * 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.
- */
- static inline void touch_ll_denoise_enable(void)
- {
- RTCCNTL.touch_scan_ctrl.touch_denoise_en = 1;
- }
- /**
- * 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.
- */
- static inline void touch_ll_denoise_disable(void)
- {
- RTCCNTL.touch_scan_ctrl.touch_denoise_en = 0;
- }
- /**
- * Set internal reference capacitance of denoise channel.
- * Select the appropriate internal reference capacitance value so that
- * the reading of denoise channel is closest to the reading of the channel being measured.
- *
- * @param cap_level Capacitance level.
- */
- static inline void touch_ll_denoise_set_cap_level(touch_pad_denoise_cap_t cap_level)
- {
- RTCCNTL.touch_ctrl2.touch_refc = cap_level;
- }
- /**
- * Get internal reference capacitance of denoise channel.
- * Select the appropriate internal reference capacitance value so that
- * the reading of denoise channel is closest to the reading of the channel being measured.
- *
- * @param cap_level Capacitance level.
- */
- static inline void touch_ll_denoise_get_cap_level(touch_pad_denoise_cap_t *cap_level)
- {
- *cap_level = RTCCNTL.touch_ctrl2.touch_refc;
- }
- /**
- * Set denoise range of denoise channel.
- * Determined by measuring the noise amplitude of the denoise channel.
- *
- * @param grade Denoise range of denoise channel.
- */
- static inline void touch_ll_denoise_set_grade(touch_pad_denoise_grade_t grade)
- {
- RTCCNTL.touch_scan_ctrl.touch_denoise_res = grade;
- }
- /**
- * Set denoise range of denoise channel.
- * Determined by measuring the noise amplitude of the denoise channel.
- *
- * @param grade Denoise range of denoise channel.
- */
- static inline void touch_ll_denoise_get_grade(touch_pad_denoise_grade_t *grade)
- {
- *grade = RTCCNTL.touch_scan_ctrl.touch_denoise_res;
- }
- /**
- * Read denoise measure value (TOUCH_PAD_NUM0).
- *
- * @param denoise value of denoise.
- */
- static inline uint32_t touch_ll_denoise_read_data(uint32_t *data)
- {
- return (uint32_t)SENS.sar_touch_status0.touch_denoise_data;
- }
- /************************ Waterproof register setting ************************/
- /**
- * Set touch channel use for guard pad.
- *
- * @param pad_num Touch sensor channel number.
- */
- static inline void touch_ll_waterproof_set_guard_pad(touch_pad_t pad_num)
- {
- RTCCNTL.touch_scan_ctrl.touch_out_ring = pad_num;
- }
- /**
- * Get touch channel use for guard pad.
- *
- * @param pad_num Touch sensor channel number.
- */
- static inline void touch_ll_waterproof_get_guard_pad(touch_pad_t *pad_num)
- {
- *pad_num = RTCCNTL.touch_scan_ctrl.touch_out_ring;
- }
- /**
- * Set max equivalent capacitance for sheild channel.
- * The equivalent capacitance of the shielded channel can be calculated
- * from the reading of denoise channel.
- *
- * @param pad_num Touch sensor channel number.
- */
- static inline void touch_ll_waterproof_set_sheild_driver(touch_pad_shield_driver_t driver_level)
- {
- RTCCNTL.touch_scan_ctrl.touch_bufdrv = driver_level;
- }
- /**
- * Get max equivalent capacitance for sheild channel.
- * The equivalent capacitance of the shielded channel can be calculated
- * from the reading of denoise channel.
- *
- * @param pad_num Touch sensor channel number.
- */
- static inline void touch_ll_waterproof_get_sheild_driver(touch_pad_shield_driver_t *driver_level)
- {
- *driver_level = RTCCNTL.touch_scan_ctrl.touch_bufdrv;
- }
- /**
- * 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.
- */
- static inline void touch_ll_waterproof_enable(void)
- {
- RTCCNTL.touch_scan_ctrl.touch_shield_pad_en = 1;
- }
- /**
- * Disable 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.
- */
- static inline void touch_ll_waterproof_disable(void)
- {
- RTCCNTL.touch_scan_ctrl.touch_shield_pad_en = 0;
- }
- /************************ Proximity register setting ************************/
- /**
- * Set touch channel number for proximity pad.
- * If disable the proximity pad, point this pad to `TOUCH_PAD_NUM0`
- *
- * @param prox_pad The array of three proximity pads.
- */
- static inline void touch_ll_proximity_set_channel_num(const touch_pad_t prox_pad[])
- {
- SENS.sar_touch_conf.touch_approach_pad0 = prox_pad[0];
- SENS.sar_touch_conf.touch_approach_pad1 = prox_pad[1];
- SENS.sar_touch_conf.touch_approach_pad2 = prox_pad[2];
- }
- /**
- * Get touch channel number for proximity pad.
- * If disable the proximity pad, point this pad to `TOUCH_PAD_NUM0`
- *
- * @param prox_pad The array of three proximity pads.
- */
- static inline void touch_ll_proximity_get_channel_num(touch_pad_t prox_pad[])
- {
- prox_pad[0] = SENS.sar_touch_conf.touch_approach_pad0;
- prox_pad[1] = SENS.sar_touch_conf.touch_approach_pad1;
- prox_pad[2] = SENS.sar_touch_conf.touch_approach_pad2;
- }
- /**
- * Set cumulative measurement times for proximity pad.
- *
- * @param times The cumulative number of measurement cycles.
- */
- static inline void touch_ll_proximity_set_meas_times(uint32_t times)
- {
- RTCCNTL.touch_approach.touch_approach_meas_time = times;
- }
- /**
- * Get cumulative measurement times for proximity pad.
- *
- * @param times The cumulative number of measurement cycles.
- */
- static inline void touch_ll_proximity_get_meas_times(uint32_t *times)
- {
- *times = RTCCNTL.touch_approach.touch_approach_meas_time;
- }
- /**
- * Read current cumulative measurement times for proximity pad.
- *
- * @param times The cumulative number of measurement cycles.
- */
- 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;
- }
- }
- /**
- * Check if the touch sensor channel is the proximity pad.
- *
- * @param touch_num The touch sensor channel number.
- */
- static inline bool touch_ll_proximity_pad_check(touch_pad_t touch_num)
- {
- 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 false;
- } else {
- return true;
- }
- }
- /************** sleep pad setting ***********************/
- /**
- * Set touch channel number for sleep pad.
- *
- * @note Only one touch sensor channel is supported in deep sleep mode.
- * @param touch_num Touch sensor channel number.
- */
- static inline void touch_ll_sleep_set_channel_num(touch_pad_t touch_num)
- {
- RTCCNTL.touch_slp_thres.touch_slp_pad = touch_num;
- }
- /**
- * Get touch channel number for sleep pad.
- *
- * @note Only one touch sensor channel is supported in deep sleep mode.
- * @param touch_num Touch sensor channel number.
- */
- static inline void touch_ll_sleep_get_channel_num(touch_pad_t *touch_num)
- {
- *touch_num = RTCCNTL.touch_slp_thres.touch_slp_pad;
- }
- /**
- * Set the trigger threshold of touch sensor in deep sleep.
- * The threshold determines the sensitivity of the touch sensor.
- * The threshold is the original value of the trigger state minus the benchmark value.
- *
- * @note The threshold at sleep is the same as the threshold before sleep.
- */
- static inline void touch_ll_sleep_set_threshold(uint32_t touch_thres)
- {
- RTCCNTL.touch_slp_thres.touch_slp_th = touch_thres;
- }
- /**
- * Get the trigger threshold of touch sensor in deep sleep.
- * The threshold determines the sensitivity of the touch sensor.
- * The threshold is the original value of the trigger state minus the benchmark value.
- *
- * @note The threshold at sleep is the same as the threshold before sleep.
- */
- static inline void touch_ll_sleep_get_threshold(uint32_t *touch_thres)
- {
- *touch_thres = RTCCNTL.touch_slp_thres.touch_slp_th;
- }
- /**
- * Enable proximity function for sleep pad.
- */
- static inline void touch_ll_sleep_enable_approach(void)
- {
- RTCCNTL.touch_slp_thres.touch_slp_approach_en = 1;
- }
- /**
- * Disable proximity function for sleep pad.
- */
- static inline void touch_ll_sleep_disable_approach(void)
- {
- RTCCNTL.touch_slp_thres.touch_slp_approach_en = 0;
- }
- /**
- * Read benchmark of touch sensor for sleep pad.
- *
- * @param benchmark Pointer to accept touch sensor benchmark value.
- */
- static inline void touch_ll_sleep_read_benchmark(uint32_t *benchmark)
- {
- *benchmark = REG_GET_FIELD(SENS_SAR_TOUCH_SLP_STATUS_REG, SENS_TOUCH_SLP_BENCHMARK);
- }
- /**
- * Read debounce of touch sensor for sleep pad.
- *
- * @param debounce Pointer to accept touch sensor debounce value.
- */
- static inline void touch_ll_sleep_read_debounce(uint32_t *debounce)
- {
- *debounce = REG_GET_FIELD(SENS_SAR_TOUCH_SLP_STATUS_REG, SENS_TOUCH_SLP_DEBOUNCE);
- }
- /**
- * Read proximity count of touch sensor for sleep pad.
- * @param proximity_cnt Pointer to accept touch sensor proximity count value.
- */
- static inline void touch_ll_sleep_read_proximity_cnt(uint32_t *approach_cnt)
- {
- *approach_cnt = REG_GET_FIELD(SENS_SAR_TOUCH_APPR_STATUS_REG, SENS_TOUCH_SLP_APPROACH_CNT);
- }
- /**
- * Get the touch pad which caused wakeup from deep sleep.
- *
- * @param pad_num pointer to touch pad which caused wakeup.
- */
- static inline void touch_ll_get_wakeup_status(touch_pad_t *pad_num)
- {
- *pad_num = (touch_pad_t)RTCCNTL.touch_slp_thres.touch_slp_pad;
- }
|