rtc_io_hal.h 7.4 KB

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