touch_sensor_hal.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. // Copyright 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. * NOTICE
  16. * The hal is not public api, don't use in application code.
  17. * See readme.md in soc/include/hal/readme.md
  18. ******************************************************************************/
  19. // The HAL layer for touch sensor (common part)
  20. #pragma once
  21. #include "hal/touch_sensor_ll.h"
  22. #include "hal/touch_sensor_types.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. typedef struct {
  27. touch_high_volt_t refh;
  28. touch_low_volt_t refl;
  29. touch_volt_atten_t atten;
  30. }touch_hal_volt_t;
  31. typedef struct {
  32. touch_cnt_slope_t slope; /*!<Set touch sensor charge/discharge speed(currents) for each pad.*/
  33. touch_tie_opt_t tie_opt; /*!<Set initial voltage state of touch channel for each measurement.*/
  34. } touch_hal_meas_mode_t;
  35. /**
  36. * Set touch sensor sleep time (interval of measurement).
  37. *
  38. * @param sleep_time The touch sensor will sleep after each measurement.
  39. * sleep_cycle decide the interval between each measurement.
  40. * t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency).
  41. * The approximate frequency value of RTC_SLOW_CLK can be obtained using `rtc_clk_slow_freq_get_hz` function.
  42. */
  43. #define touch_hal_set_sleep_time(sleep_time) touch_ll_set_sleep_time(sleep_time)
  44. /**
  45. * Get touch sensor sleep time.
  46. *
  47. * @param sleep_time Pointer to accept sleep cycle count.
  48. */
  49. #define touch_hal_get_sleep_time(sleep_time) touch_ll_get_sleep_time(sleep_time)
  50. /**
  51. * Set touch sensor high / low voltage threshold of chanrge.
  52. * The touch sensor measures the channel capacitance value by charging and discharging the channel.
  53. * So charge threshold should be less than the supply voltage.
  54. * The actual charge threshold is high voltage threshold minus attenuation value.
  55. *
  56. * @param refh The high voltage threshold of chanrge.
  57. */
  58. void touch_hal_set_voltage(const touch_hal_volt_t *volt);
  59. /**
  60. * Get touch sensor high / low voltage threshold of chanrge.
  61. * The touch sensor measures the channel capacitance value by charging and discharging the channel.
  62. * So charge threshold should be less than the supply voltage.
  63. * The actual charge threshold is high voltage threshold minus attenuation value.
  64. *
  65. * @param refh The voltage threshold of chanrge / discharge.
  66. */
  67. void touch_hal_get_voltage(touch_hal_volt_t *volt);
  68. /**
  69. * Set touch sensor charge/discharge speed(currents) and initial voltage state for each pad measurement.
  70. *
  71. * @param touch_num Touch pad index.
  72. * @param meas Touch pad measurement config.
  73. */
  74. void touch_hal_set_meas_mode(touch_pad_t touch_num, const touch_hal_meas_mode_t *meas);
  75. /**
  76. * Get touch sensor charge/discharge speed(currents) and initial voltage state for each pad measurement.
  77. *
  78. * @param touch_num Touch pad index.
  79. * @param meas Touch pad measurement config.
  80. */
  81. void touch_hal_get_meas_mode(touch_pad_t touch_num, touch_hal_meas_mode_t *meas);
  82. /**
  83. * Set touch sensor FSM mode.
  84. * The measurement action can be triggered by the hardware timer, as well as by the software instruction.
  85. *
  86. * @param mode FSM mode.
  87. */
  88. #define touch_hal_set_fsm_mode(mode) touch_ll_set_fsm_mode(mode)
  89. /**
  90. * Get touch sensor FSM mode.
  91. * The measurement action can be triggered by the hardware timer, as well as by the software instruction.
  92. *
  93. * @param mode FSM mode.
  94. */
  95. #define touch_hal_get_fsm_mode(mode) touch_ll_get_fsm_mode(mode)
  96. /**
  97. * Start touch sensor FSM timer.
  98. * The measurement action can be triggered by the hardware timer, as well as by the software instruction.
  99. *
  100. * @param mode FSM mode.
  101. */
  102. #define touch_hal_start_fsm() touch_ll_start_fsm()
  103. /**
  104. * Stop touch sensor FSM timer.
  105. * The measurement action can be triggered by the hardware timer, as well as by the software instruction.
  106. *
  107. * @param mode FSM mode.
  108. */
  109. #define touch_hal_stop_fsm() touch_ll_stop_fsm()
  110. /**
  111. * Trigger a touch sensor measurement, only support in SW mode of FSM.
  112. */
  113. #define touch_hal_start_sw_meas() touch_ll_start_sw_meas()
  114. /**
  115. * Set touch sensor interrupt threshold.
  116. *
  117. * @note Refer to `touch_pad_set_trigger_mode` to see how to set trigger mode.
  118. * @param touch_num touch pad index.
  119. * @param threshold threshold of touchpad count.
  120. */
  121. #define touch_hal_set_threshold(touch_num, threshold) touch_ll_set_threshold(touch_num, threshold)
  122. /**
  123. * Get touch sensor interrupt threshold.
  124. *
  125. * @param touch_num touch pad index.
  126. * @param threshold pointer to accept threshold.
  127. */
  128. #define touch_hal_get_threshold(touch_num, threshold) touch_ll_get_threshold(touch_num, threshold)
  129. /**
  130. * Enable touch sensor channel. Register touch channel into touch sensor measurement group.
  131. * The working mode of the touch sensor is simultaneous measurement.
  132. * This function will set the measure bits according to the given bitmask.
  133. *
  134. * @note If set this mask, the FSM timer should be stop firsty.
  135. * @note The touch sensor that in scan map, should be deinit GPIO function firstly.
  136. * @param enable_mask bitmask of touch sensor scan group.
  137. * e.g. TOUCH_PAD_NUM1 -> BIT(1)
  138. * @return
  139. * - ESP_OK on success
  140. */
  141. #define touch_hal_set_channel_mask(enable_mask) touch_ll_set_channel_mask(enable_mask)
  142. /**
  143. * Get touch sensor channel mask.
  144. *
  145. * @param enable_mask bitmask of touch sensor scan group.
  146. * e.g. TOUCH_PAD_NUM1 -> BIT(1)
  147. */
  148. #define touch_hal_get_channel_mask(enable_mask) touch_ll_get_channel_mask(enable_mask)
  149. /**
  150. * Disable touch sensor channel by bitmask.
  151. *
  152. * @param enable_mask bitmask of touch sensor scan group.
  153. * e.g. TOUCH_PAD_NUM1 -> BIT(1)
  154. */
  155. #define touch_hal_clear_channel_mask(disable_mask) touch_ll_clear_channel_mask(disable_mask)
  156. /**
  157. * Get the touch sensor status, usually used in ISR to decide which pads are 'touched'.
  158. *
  159. * @param status_mask The touch sensor status. e.g. Touch1 trigger status is `status_mask & (BIT1)`.
  160. */
  161. #define touch_hal_read_trigger_status_mask(status_mask) touch_ll_read_trigger_status_mask(status_mask)
  162. /**
  163. * Clear all touch sensor status.
  164. */
  165. #define touch_hal_clear_trigger_status_mask() touch_ll_clear_trigger_status_mask()
  166. /**
  167. * Get touch sensor raw data (touch sensor counter value) from register. No block.
  168. *
  169. * @param touch_num touch pad index.
  170. * @return touch_value pointer to accept touch sensor value.
  171. */
  172. #define touch_hal_read_raw_data(touch_num) touch_ll_read_raw_data(touch_num)
  173. /**
  174. * Get touch sensor measure status. No block.
  175. *
  176. * @return
  177. * - If touch sensors measure done.
  178. */
  179. #define touch_hal_meas_is_done() touch_ll_meas_is_done()
  180. /**
  181. * Initialize touch module.
  182. *
  183. * @note If default parameter don't match the usage scenario, it can be changed after this function.
  184. */
  185. void touch_hal_init(void);
  186. /**
  187. * Un-install touch pad driver.
  188. *
  189. * @note After this function is called, other touch functions are prohibited from being called.
  190. */
  191. void touch_hal_deinit(void);
  192. /**
  193. * Configure touch sensor for each channel.
  194. */
  195. void touch_hal_config(touch_pad_t touch_num);
  196. #ifdef __cplusplus
  197. }
  198. #endif