touch_sensor_common.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. * - ESP_ERR_NOT_SUPPORTED Touch pad is providing current to external XTAL
  27. */
  28. esp_err_t touch_pad_init(void);
  29. /**
  30. * @brief Un-install touch pad driver.
  31. * @note After this function is called, other touch functions are prohibited from being called.
  32. * @return
  33. * - ESP_OK Success
  34. * - ESP_FAIL Touch pad driver not initialized
  35. */
  36. esp_err_t touch_pad_deinit(void);
  37. /**
  38. * @brief Initialize touch pad GPIO
  39. * @param touch_num touch pad index
  40. * @return
  41. * - ESP_OK on success
  42. * - ESP_ERR_INVALID_ARG if argument is wrong
  43. */
  44. esp_err_t touch_pad_io_init(touch_pad_t touch_num);
  45. /**
  46. * @brief Set touch sensor high voltage threshold of chanrge.
  47. * The touch sensor measures the channel capacitance value by charging and discharging the channel.
  48. * So the high threshold should be less than the supply voltage.
  49. * @param refh the value of DREFH
  50. * @param refl the value of DREFL
  51. * @param atten the attenuation on DREFH
  52. * @return
  53. * - ESP_OK on success
  54. * - ESP_ERR_INVALID_ARG if argument is wrong
  55. */
  56. esp_err_t touch_pad_set_voltage(touch_high_volt_t refh, touch_low_volt_t refl, touch_volt_atten_t atten);
  57. /**
  58. * @brief Get touch sensor reference voltage,
  59. * @param refh pointer to accept DREFH value
  60. * @param refl pointer to accept DREFL value
  61. * @param atten pointer to accept the attenuation on DREFH
  62. * @return
  63. * - ESP_OK on success
  64. */
  65. esp_err_t touch_pad_get_voltage(touch_high_volt_t *refh, touch_low_volt_t *refl, touch_volt_atten_t *atten);
  66. /**
  67. * @brief Set touch sensor charge/discharge speed for each pad.
  68. * If the slope is 0, the counter would always be zero.
  69. * If the slope is 1, the charging and discharging would be slow, accordingly.
  70. * If the slope is set 7, which is the maximum value, the charging and discharging would be fast.
  71. * @note The higher the charge and discharge current, the greater the immunity of the touch channel,
  72. * but it will increase the system power consumption.
  73. * @param touch_num touch pad index
  74. * @param slope touch pad charge/discharge speed
  75. * @param opt the initial voltage
  76. * @return
  77. * - ESP_OK on success
  78. * - ESP_ERR_INVALID_ARG if argument is wrong
  79. */
  80. esp_err_t touch_pad_set_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t slope, touch_tie_opt_t opt);
  81. /**
  82. * @brief Get touch sensor charge/discharge speed for each pad
  83. * @param touch_num touch pad index
  84. * @param slope pointer to accept touch pad charge/discharge slope
  85. * @param opt pointer to accept the initial voltage
  86. * @return
  87. * - ESP_OK on success
  88. * - ESP_ERR_INVALID_ARG if argument is wrong
  89. */
  90. esp_err_t touch_pad_get_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t *slope, touch_tie_opt_t *opt);
  91. /**
  92. * @brief Deregister the handler previously registered using touch_pad_isr_handler_register
  93. * @param fn handler function to call (as passed to touch_pad_isr_handler_register)
  94. * @param arg argument of the handler (as passed to touch_pad_isr_handler_register)
  95. * @return
  96. * - ESP_OK on success
  97. * - ESP_ERR_INVALID_STATE if a handler matching both fn and
  98. * arg isn't registered
  99. */
  100. esp_err_t touch_pad_isr_deregister(void(*fn)(void *), void *arg);
  101. /**
  102. * @brief Get the touch pad which caused wakeup from deep sleep.
  103. * @param pad_num pointer to touch pad which caused wakeup
  104. * @return
  105. * - ESP_OK Success
  106. * - ESP_ERR_INVALID_ARG parameter is NULL
  107. */
  108. esp_err_t touch_pad_get_wakeup_status(touch_pad_t *pad_num);
  109. /**
  110. * @brief Set touch sensor FSM mode, the test action can be triggered by the timer,
  111. * as well as by the software.
  112. * @param mode FSM mode
  113. * @return
  114. * - ESP_OK on success
  115. * - ESP_ERR_INVALID_ARG if argument is wrong
  116. */
  117. esp_err_t touch_pad_set_fsm_mode(touch_fsm_mode_t mode);
  118. /**
  119. * @brief Get touch sensor FSM mode
  120. * @param mode pointer to accept FSM mode
  121. * @return
  122. * - ESP_OK on success
  123. */
  124. esp_err_t touch_pad_get_fsm_mode(touch_fsm_mode_t *mode);
  125. /**
  126. * @brief To clear the touch sensor channel active status.
  127. *
  128. * @note The FSM automatically updates the touch sensor status. It is generally not necessary to call this API to clear the status.
  129. * @return
  130. * - ESP_OK on success
  131. */
  132. esp_err_t touch_pad_clear_status(void);
  133. /**
  134. * @brief Get the touch sensor channel active status mask.
  135. * The bit position represents the channel number. The 0/1 status of the bit represents the trigger status.
  136. *
  137. * @return
  138. * - The touch sensor status. e.g. Touch1 trigger status is `status_mask & (BIT1)`.
  139. */
  140. uint32_t touch_pad_get_status(void);
  141. /**
  142. * @brief Check touch sensor measurement status.
  143. *
  144. * @return
  145. * - True measurement is under way
  146. * - False measurement done
  147. */
  148. bool touch_pad_meas_is_done(void);
  149. #ifdef __cplusplus
  150. }
  151. #endif