touch_sensor_hal.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // The HAL layer for Touch sensor (common part)
  15. #include "hal/touch_sensor_hal.h"
  16. #include "hal/touch_sensor_types.h"
  17. void touch_hal_init(void)
  18. {
  19. touch_ll_stop_fsm();
  20. touch_ll_intr_disable();
  21. touch_ll_intr_clear();
  22. touch_ll_clear_channel_mask(TOUCH_PAD_BIT_MASK_ALL);
  23. touch_ll_clear_group_mask(TOUCH_PAD_BIT_MASK_ALL, TOUCH_PAD_BIT_MASK_ALL);
  24. touch_ll_set_trigger_mode(TOUCH_TRIGGER_MODE_DEFAULT);
  25. touch_ll_set_trigger_source(TOUCH_TRIGGER_SOURCE_DEFAULT);
  26. touch_ll_clear_trigger_status_mask();
  27. touch_ll_set_meas_time(TOUCH_PAD_MEASURE_CYCLE_DEFAULT);
  28. touch_ll_set_sleep_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT);
  29. touch_ll_set_fsm_mode(TOUCH_FSM_MODE_DEFAULT);
  30. touch_ll_start_fsm();
  31. }
  32. void touch_hal_deinit(void)
  33. {
  34. touch_ll_stop_fsm();
  35. touch_ll_clear_trigger_status_mask();
  36. touch_ll_intr_disable();
  37. }
  38. void touch_hal_get_wakeup_status(touch_pad_t *pad_num)
  39. {
  40. uint32_t touch_mask = 0;
  41. touch_ll_read_trigger_status_mask(&touch_mask);
  42. if (touch_mask == 0) {
  43. *pad_num = -1;
  44. }
  45. *pad_num = (touch_pad_t)(__builtin_ffs(touch_mask) - 1);
  46. }