1 // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // The HAL layer for Touch Sensor (common part)
16 
17 #include "hal/touch_sensor_hal.h"
18 #include "hal/touch_sensor_types.h"
19 #include "soc/soc_caps.h"
20 
touch_hal_config(touch_pad_t touch_num)21 void touch_hal_config(touch_pad_t touch_num)
22 {
23     touch_ll_set_threshold(touch_num, SOC_TOUCH_PAD_THRESHOLD_MAX);
24     touch_ll_set_slope(touch_num, TOUCH_PAD_SLOPE_DEFAULT);
25     touch_ll_set_tie_option(touch_num, TOUCH_PAD_TIE_OPT_DEFAULT);
26 }
27 
touch_hal_set_voltage(const touch_hal_volt_t * volt)28 void touch_hal_set_voltage(const touch_hal_volt_t *volt)
29 {
30     touch_ll_set_voltage_high(volt->refh);
31     touch_ll_set_voltage_low(volt->refl);
32     touch_ll_set_voltage_attenuation(volt->atten);
33 }
34 
touch_hal_get_voltage(touch_hal_volt_t * volt)35 void touch_hal_get_voltage(touch_hal_volt_t *volt)
36 {
37     touch_ll_get_voltage_high(&volt->refh);
38     touch_ll_get_voltage_low(&volt->refl);
39     touch_ll_get_voltage_attenuation(&volt->atten);
40 }
41 
touch_hal_set_meas_mode(touch_pad_t touch_num,const touch_hal_meas_mode_t * meas)42 void touch_hal_set_meas_mode(touch_pad_t touch_num, const touch_hal_meas_mode_t *meas)
43 {
44     touch_ll_set_slope(touch_num, meas->slope);
45     touch_ll_set_tie_option(touch_num, meas->tie_opt);
46 }
47 
touch_hal_get_meas_mode(touch_pad_t touch_num,touch_hal_meas_mode_t * meas)48 void touch_hal_get_meas_mode(touch_pad_t touch_num, touch_hal_meas_mode_t *meas)
49 {
50     touch_ll_get_slope(touch_num, &meas->slope);
51     touch_ll_get_tie_option(touch_num, &meas->tie_opt);
52 }
53