touch_sensor_common.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // Copyright 2015-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #include "esp_err.h"
  15. #include "esp_intr_alloc.h"
  16. #include "hal/touch_sensor_types.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * @brief Initialize touch module.
  22. * @note If default parameter don't match the usage scenario, it can be changed after this function.
  23. * @return
  24. * - ESP_OK Success
  25. * - ESP_ERR_NO_MEM Touch pad init error
  26. */
  27. esp_err_t touch_pad_init(void);
  28. /**
  29. * @brief Un-install touch pad driver.
  30. * @note After this function is called, other touch functions are prohibited from being called.
  31. * @return
  32. * - ESP_OK Success
  33. * - ESP_FAIL Touch pad driver not initialized
  34. */
  35. esp_err_t touch_pad_deinit(void);
  36. /**
  37. * @brief Initialize touch pad GPIO
  38. * @param touch_num touch pad index
  39. * @return
  40. * - ESP_OK on success
  41. * - ESP_ERR_INVALID_ARG if argument is wrong
  42. */
  43. esp_err_t touch_pad_io_init(touch_pad_t touch_num);
  44. /**
  45. * @brief Set touch sensor high voltage threshold of chanrge.
  46. * The touch sensor measures the channel capacitance value by charging and discharging the channel.
  47. * So the high threshold should be less than the supply voltage.
  48. * @param refh the value of DREFH
  49. * @param refl the value of DREFL
  50. * @param atten the attenuation on DREFH
  51. * @return
  52. * - ESP_OK on success
  53. * - ESP_ERR_INVALID_ARG if argument is wrong
  54. */
  55. esp_err_t touch_pad_set_voltage(touch_high_volt_t refh, touch_low_volt_t refl, touch_volt_atten_t atten);
  56. /**
  57. * @brief Get touch sensor reference voltage,
  58. * @param refh pointer to accept DREFH value
  59. * @param refl pointer to accept DREFL value
  60. * @param atten pointer to accept the attenuation on DREFH
  61. * @return
  62. * - ESP_OK on success
  63. */
  64. esp_err_t touch_pad_get_voltage(touch_high_volt_t *refh, touch_low_volt_t *refl, touch_volt_atten_t *atten);
  65. /**
  66. * @brief Set touch sensor charge/discharge speed for each pad.
  67. * If the slope is 0, the counter would always be zero.
  68. * If the slope is 1, the charging and discharging would be slow, accordingly.
  69. * If the slope is set 7, which is the maximum value, the charging and discharging would be fast.
  70. * @note The higher the charge and discharge current, the greater the immunity of the touch channel,
  71. * but it will increase the system power consumption.
  72. * @param touch_num touch pad index
  73. * @param slope touch pad charge/discharge speed
  74. * @param opt the initial voltage
  75. * @return
  76. * - ESP_OK on success
  77. * - ESP_ERR_INVALID_ARG if argument is wrong
  78. */
  79. esp_err_t touch_pad_set_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t slope, touch_tie_opt_t opt);
  80. /**
  81. * @brief Get touch sensor charge/discharge speed for each pad
  82. * @param touch_num touch pad index
  83. * @param slope pointer to accept touch pad charge/discharge slope
  84. * @param opt pointer to accept the initial voltage
  85. * @return
  86. * - ESP_OK on success
  87. * - ESP_ERR_INVALID_ARG if argument is wrong
  88. */
  89. esp_err_t touch_pad_get_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t *slope, touch_tie_opt_t *opt);
  90. /**
  91. * @brief Deregister the handler previously registered using touch_pad_isr_handler_register
  92. * @param fn handler function to call (as passed to touch_pad_isr_handler_register)
  93. * @param arg argument of the handler (as passed to touch_pad_isr_handler_register)
  94. * @return
  95. * - ESP_OK on success
  96. * - ESP_ERR_INVALID_STATE if a handler matching both fn and
  97. * arg isn't registered
  98. */
  99. esp_err_t touch_pad_isr_deregister(void(*fn)(void *), void *arg);
  100. /**
  101. * @brief Get the touch pad which caused wakeup from deep sleep.
  102. * @param pad_num pointer to touch pad which caused wakeup
  103. * @return
  104. * - ESP_OK Success
  105. * - ESP_ERR_INVALID_ARG parameter is NULL
  106. */
  107. esp_err_t touch_pad_get_wakeup_status(touch_pad_t *pad_num);
  108. /**
  109. * @brief Set touch sensor FSM mode, the test action can be triggered by the timer,
  110. * as well as by the software.
  111. * @param mode FSM mode
  112. * @return
  113. * - ESP_OK on success
  114. * - ESP_ERR_INVALID_ARG if argument is wrong
  115. */
  116. esp_err_t touch_pad_set_fsm_mode(touch_fsm_mode_t mode);
  117. /**
  118. * @brief Get touch sensor FSM mode
  119. * @param mode pointer to accept FSM mode
  120. * @return
  121. * - ESP_OK on success
  122. */
  123. esp_err_t touch_pad_get_fsm_mode(touch_fsm_mode_t *mode);
  124. /**
  125. * @brief To clear the touch sensor channel active status.
  126. *
  127. * @note The FSM automatically updates the touch sensor status. It is generally not necessary to call this API to clear the status.
  128. * @return
  129. * - ESP_OK on success
  130. */
  131. esp_err_t touch_pad_clear_status(void);
  132. /**
  133. * @brief Get the touch sensor channel active status mask.
  134. * The bit position represents the channel number. The 0/1 status of the bit represents the trigger status.
  135. *
  136. * @return
  137. * - The touch sensor status. e.g. Touch1 trigger status is `status_mask & (BIT1)`.
  138. */
  139. uint32_t touch_pad_get_status(void);
  140. /**
  141. * @brief Check touch sensor measurement status.
  142. *
  143. * @return
  144. * - True measurement is under way
  145. * - False measurement done
  146. */
  147. bool touch_pad_meas_is_done(void);
  148. #ifdef __cplusplus
  149. }
  150. #endif