rtc_io_hal.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. /*******************************************************************************
  15. * NOTICE
  16. * The hal is not public api, don't use in application code.
  17. * See readme.md in hal/include/hal/readme.md
  18. ******************************************************************************/
  19. // The HAL layer for RTC IO master (common part)
  20. #pragma once
  21. #include <esp_err.h>
  22. #if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2
  23. #include "soc/soc_caps.h"
  24. #include "hal/rtc_io_ll.h"
  25. #endif
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
  30. /**
  31. * Select the rtcio function.
  32. *
  33. * @note The RTC function must be selected before the pad analog function is enabled.
  34. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  35. * @param func Select pin function.
  36. */
  37. #define rtcio_hal_function_select(rtcio_num, func) rtcio_ll_function_select(rtcio_num, func)
  38. /**
  39. * Enable rtcio output.
  40. *
  41. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  42. */
  43. #define rtcio_hal_output_enable(rtcio_num) rtcio_ll_output_enable(rtcio_num)
  44. /**
  45. * Disable rtcio output.
  46. *
  47. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  48. */
  49. #define rtcio_hal_output_disable(rtcio_num) rtcio_ll_output_disable(rtcio_num)
  50. /**
  51. * Set RTCIO output level.
  52. *
  53. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  54. * @param level 0: output low; ~0: output high.
  55. */
  56. #define rtcio_hal_set_level(rtcio_num, level) rtcio_ll_set_level(rtcio_num, level)
  57. /**
  58. * Enable rtcio input.
  59. *
  60. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  61. */
  62. #define rtcio_hal_input_enable(rtcio_num) rtcio_ll_input_enable(rtcio_num)
  63. /**
  64. * Disable rtcio input.
  65. *
  66. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  67. */
  68. #define rtcio_hal_input_disable(rtcio_num) rtcio_ll_input_disable(rtcio_num)
  69. /**
  70. * Get RTCIO input level.
  71. *
  72. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  73. * @return 0: input low; ~0: input high.
  74. */
  75. #define rtcio_hal_get_level(rtcio_num) rtcio_ll_get_level(rtcio_num)
  76. /**
  77. * @brief Set RTC GPIO pad drive capability.
  78. *
  79. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  80. * @param strength Drive capability of the pad. Range: 0 ~ 3.
  81. */
  82. #define rtcio_hal_set_drive_capability(rtcio_num, strength) rtcio_ll_set_drive_capability(rtcio_num, strength)
  83. /**
  84. * @brief Get RTC GPIO pad drive capability.
  85. *
  86. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  87. * @return Drive capability of the pad. Range: 0 ~ 3.
  88. */
  89. #define rtcio_hal_get_drive_capability(rtcio_num) rtcio_ll_get_drive_capability(rtcio_num)
  90. /**
  91. * Set RTCIO output level.
  92. *
  93. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  94. * @param level 0: output low; ~0: output high.
  95. */
  96. #define rtcio_hal_set_level(rtcio_num, level) rtcio_ll_set_level(rtcio_num, level)
  97. /**
  98. * Get RTCIO input level.
  99. *
  100. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  101. * @return 0: input low; ~0: input high.
  102. */
  103. #define rtcio_hal_get_level(rtcio_num) rtcio_ll_get_level(rtcio_num)
  104. /**
  105. * Set RTC IO direction.
  106. *
  107. * Configure RTC IO direction, such as output only, input only,
  108. * output and input.
  109. *
  110. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  111. * @param mode IO direction.
  112. */
  113. void rtcio_hal_set_direction(int rtcio_num, rtc_gpio_mode_t mode);
  114. /**
  115. * Set RTC IO direction in deep sleep or disable sleep status.
  116. *
  117. * NOTE: ESP32 support INPUT_ONLY mode.
  118. * ESP32S2 support INPUT_ONLY, OUTPUT_ONLY, INPUT_OUTPUT mode.
  119. *
  120. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  121. * @param mode IO direction.
  122. */
  123. void rtcio_hal_set_direction_in_sleep(int rtcio_num, rtc_gpio_mode_t mode);
  124. /**
  125. * RTC GPIO pullup enable.
  126. *
  127. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  128. */
  129. #define rtcio_hal_pullup_enable(rtcio_num) rtcio_ll_pullup_enable(rtcio_num)
  130. /**
  131. * RTC GPIO pullup disable.
  132. *
  133. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  134. */
  135. #define rtcio_hal_pullup_disable(rtcio_num) rtcio_ll_pullup_disable(rtcio_num)
  136. /**
  137. * RTC GPIO pulldown enable.
  138. *
  139. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  140. */
  141. #define rtcio_hal_pulldown_enable(rtcio_num) rtcio_ll_pulldown_enable(rtcio_num)
  142. /**
  143. * RTC GPIO pulldown disable.
  144. *
  145. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  146. */
  147. #define rtcio_hal_pulldown_disable(rtcio_num) rtcio_ll_pulldown_disable(rtcio_num)
  148. #endif // SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
  149. #if SOC_RTCIO_HOLD_SUPPORTED
  150. /**
  151. * Enable force hold function for RTC IO pad.
  152. *
  153. * Enabling HOLD function will cause the pad to lock current status, such as,
  154. * input/output enable, input/output value, function, drive strength values.
  155. * This function is useful when going into light or deep sleep mode to prevent
  156. * the pin configuration from changing.
  157. *
  158. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  159. */
  160. #define rtcio_hal_hold_enable(rtcio_num) rtcio_ll_force_hold_enable(rtcio_num)
  161. /**
  162. * Disable hold function on an RTC IO pad
  163. *
  164. * @note If disable the pad hold, the status of pad maybe changed in sleep mode.
  165. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  166. */
  167. #define rtcio_hal_hold_disable(rtcio_num) rtcio_ll_force_hold_disable(rtcio_num)
  168. /**
  169. * Enable force hold function for RTC IO pads.
  170. *
  171. * Enabling HOLD function will cause the pad to lock current status, such as,
  172. * input/output enable, input/output value, function, drive strength values.
  173. * This function is useful when going into light or deep sleep mode to prevent
  174. * the pin configuration from changing.
  175. *
  176. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  177. */
  178. #define rtcio_hal_hold_all() rtcio_ll_force_hold_all()
  179. /**
  180. * Disable hold function on an RTC IO pads.
  181. *
  182. * @note If disable the pad hold, the status of pad maybe changed in sleep mode.
  183. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  184. */
  185. #define rtcio_hal_unhold_all() rtcio_ll_force_unhold_all()
  186. #endif // SOC_RTCIO_HOLD_SUPPORTED
  187. #if SOC_RTCIO_WAKE_SUPPORTED
  188. /**
  189. * Enable wakeup function and set wakeup type from light sleep status for rtcio.
  190. *
  191. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  192. * @param type Wakeup on high level or low level.
  193. */
  194. #define rtcio_hal_wakeup_enable(rtcio_num, type) rtcio_ll_wakeup_enable(rtcio_num, type)
  195. /**
  196. * Disable wakeup function from light sleep status for rtcio.
  197. *
  198. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  199. */
  200. #define rtcio_hal_wakeup_disable(rtcio_num) rtcio_ll_wakeup_disable(rtcio_num)
  201. /**
  202. * Set specific logic level on an RTC IO pin as a wakeup trigger.
  203. *
  204. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  205. * @param level Logic level (0)
  206. */
  207. #define rtcio_hal_ext0_set_wakeup_pin(rtcio_num, level) rtcio_ll_ext0_set_wakeup_pin(rtcio_num, level)
  208. #endif
  209. #if SOC_RTCIO_HOLD_SUPPORTED || SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
  210. /**
  211. * Helper function to disconnect internal circuits from an RTC IO
  212. * This function disables input, output, pullup, pulldown, and enables
  213. * hold feature for an RTC IO.
  214. * Use this function if an RTC IO needs to be disconnected from internal
  215. * circuits in deep sleep, to minimize leakage current.
  216. *
  217. * In particular, for ESP32-WROVER module, call
  218. * rtc_gpio_isolate(GPIO_NUM_12) before entering deep sleep, to reduce
  219. * deep sleep current.
  220. *
  221. * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT.
  222. */
  223. void rtcio_hal_isolate(int rtc_num);
  224. #endif
  225. #ifdef __cplusplus
  226. }
  227. #endif