• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
touch_hal_init(void)20 void touch_hal_init(void)
21 {
22     touch_ll_stop_fsm();
23     touch_ll_intr_disable();
24     touch_ll_intr_clear();
25     touch_ll_clear_channel_mask(TOUCH_PAD_BIT_MASK_ALL);
26     touch_ll_clear_group_mask(TOUCH_PAD_BIT_MASK_ALL, TOUCH_PAD_BIT_MASK_ALL);
27     touch_ll_set_trigger_mode(TOUCH_TRIGGER_MODE_DEFAULT);
28     touch_ll_set_trigger_source(TOUCH_TRIGGER_SOURCE_DEFAULT);
29     touch_ll_clear_trigger_status_mask();
30     touch_ll_set_meas_time(TOUCH_PAD_MEASURE_CYCLE_DEFAULT);
31     touch_ll_set_sleep_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT);
32     touch_ll_set_fsm_mode(TOUCH_FSM_MODE_DEFAULT);
33     touch_ll_start_fsm();
34 }
35 
touch_hal_deinit(void)36 void touch_hal_deinit(void)
37 {
38     touch_ll_stop_fsm();
39     touch_ll_clear_trigger_status_mask();
40     touch_ll_intr_disable();
41 }
42 
touch_hal_get_wakeup_status(touch_pad_t * pad_num)43 void touch_hal_get_wakeup_status(touch_pad_t *pad_num)
44 {
45     uint32_t touch_mask = 0;
46     touch_ll_read_trigger_status_mask(&touch_mask);
47     if (touch_mask == 0) {
48         *pad_num = -1;
49     }
50     *pad_num = (touch_pad_t)(__builtin_ffs(touch_mask) - 1);
51 }
52