touch_sensor_common.h 5.1 KB

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