touch_sensor_hal.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_intr_disable(TOUCH_PAD_INTR_ALL);
  20. touch_ll_clear_channel_mask(SOC_TOUCH_SENSOR_BIT_MASK_MAX);
  21. touch_ll_clear_trigger_status_mask();
  22. touch_ll_set_meas_times(TOUCH_PAD_MEASURE_CYCLE_DEFAULT);
  23. touch_ll_set_sleep_time(TOUCH_PAD_SLEEP_CYCLE_DEFAULT);
  24. touch_ll_set_voltage_high(TOUCH_PAD_HIGH_VOLTAGE_THRESHOLD);
  25. touch_ll_set_voltage_low(TOUCH_PAD_LOW_VOLTAGE_THRESHOLD);
  26. touch_ll_set_voltage_attenuation(TOUCH_PAD_ATTEN_VOLTAGE_THRESHOLD);
  27. touch_ll_set_inactive_connect(TOUCH_PAD_INACTIVE_CONNECT_DEFAULT);
  28. }
  29. void touch_hal_deinit(void)
  30. {
  31. touch_hal_stop_fsm();
  32. touch_hal_clear_trigger_status_mask();
  33. touch_ll_intr_disable(TOUCH_PAD_INTR_ALL);
  34. }
  35. void touch_hal_filter_set_config(const touch_filter_config_t *filter_info)
  36. {
  37. touch_ll_filter_set_filter_mode(filter_info->mode);
  38. touch_ll_filter_set_debounce(filter_info->debounce_cnt);
  39. touch_ll_filter_set_noise_thres(filter_info->noise_thr);
  40. touch_ll_filter_set_jitter_step(filter_info->jitter_step);
  41. }
  42. void touch_hal_filter_get_config(touch_filter_config_t *filter_info)
  43. {
  44. touch_ll_filter_get_filter_mode(&filter_info->mode);
  45. touch_ll_filter_get_debounce(&filter_info->debounce_cnt);
  46. touch_ll_filter_get_noise_thres(&filter_info->noise_thr);
  47. touch_ll_filter_get_jitter_step(&filter_info->jitter_step);
  48. }
  49. void touch_hal_denoise_set_config(const touch_pad_denoise_t *denoise)
  50. {
  51. touch_ll_denoise_set_cap_level(denoise->cap_level);
  52. touch_ll_denoise_set_grade(denoise->grade);
  53. }
  54. void touch_hal_denoise_get_config(touch_pad_denoise_t *denoise)
  55. {
  56. touch_ll_denoise_get_cap_level(&denoise->cap_level);
  57. touch_ll_denoise_get_grade(&denoise->grade);
  58. }
  59. void touch_hal_denoise_enable(void)
  60. {
  61. touch_ll_clear_channel_mask(1U << SOC_TOUCH_DENOISE_CHANNEL);
  62. touch_ll_denoise_enable();
  63. }
  64. void touch_hal_waterproof_set_config(const touch_pad_waterproof_t *waterproof)
  65. {
  66. touch_ll_waterproof_set_guard_pad(waterproof->guard_ring_pad);
  67. touch_ll_waterproof_set_sheild_driver(waterproof->shield_driver);
  68. }
  69. void touch_hal_waterproof_get_config(touch_pad_waterproof_t *waterproof)
  70. {
  71. touch_ll_waterproof_get_guard_pad(&waterproof->guard_ring_pad);
  72. touch_ll_waterproof_get_sheild_driver(&waterproof->shield_driver);
  73. }
  74. void touch_hal_waterproof_enable(void)
  75. {
  76. touch_ll_clear_channel_mask(1U << SOC_TOUCH_SHIELD_CHANNEL);
  77. touch_ll_waterproof_enable();
  78. }
  79. void touch_hal_proximity_set_config(const touch_pad_proximity_t *proximity)
  80. {
  81. touch_ll_proximity_set_channel_num(proximity->select_pad);
  82. touch_ll_proximity_set_meas_times(proximity->meas_num);
  83. }
  84. void touch_hal_proximity_get_config(touch_pad_proximity_t *proximity)
  85. {
  86. touch_ll_proximity_get_channel_num(proximity->select_pad);
  87. touch_ll_proximity_get_meas_times(&proximity->meas_num);
  88. }
  89. void touch_hal_sleep_channel_config(const touch_pad_sleep_channel_t *slp_config)
  90. {
  91. touch_ll_sleep_set_channel_num(slp_config->touch_num);
  92. touch_ll_sleep_set_threshold(slp_config->sleep_pad_threshold);
  93. if (slp_config->en_proximity) {
  94. touch_ll_sleep_enable_approach();
  95. } else {
  96. touch_ll_sleep_disable_approach();
  97. }
  98. }