rtc_io.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. #ifndef _DRIVER_RTC_GPIO_H_
  14. #define _DRIVER_RTC_GPIO_H_
  15. #include <stdint.h>
  16. #include "esp_err.h"
  17. #include "driver/gpio.h"
  18. #include "soc/rtc_gpio_channel.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /**
  23. * @brief Pin function information for a single GPIO pad's RTC functions.
  24. *
  25. * This is an internal function of the driver, and is not usually useful
  26. * for external use.
  27. */
  28. typedef struct {
  29. uint32_t reg; /*!< Register of RTC pad, or 0 if not an RTC GPIO */
  30. uint32_t mux; /*!< Bit mask for selecting digital pad or RTC pad */
  31. uint32_t func; /*!< Shift of pad function (FUN_SEL) field */
  32. uint32_t ie; /*!< Mask of input enable */
  33. uint32_t pullup; /*!< Mask of pullup enable */
  34. uint32_t pulldown; /*!< Mask of pulldown enable */
  35. uint32_t slpsel; /*!< If slpsel bit is set, slpie will be used as pad input enabled signal in sleep mode */
  36. uint32_t slpie; /*!< Mask of input enable in sleep mode */
  37. uint32_t hold; /*!< Mask of hold enable */
  38. uint32_t hold_force;/*!< Mask of hold_force bit for RTC IO in RTC_CNTL_HOLD_FORCE_REG */
  39. uint32_t drv_v; /*!< Mask of drive capability */
  40. uint32_t drv_s; /*!< Offset of drive capability */
  41. int rtc_num; /*!< RTC IO number, or -1 if not an RTC GPIO */
  42. } rtc_gpio_desc_t;
  43. typedef enum {
  44. RTC_GPIO_MODE_INPUT_ONLY , /*!< Pad output */
  45. RTC_GPIO_MODE_OUTPUT_ONLY, /*!< Pad input */
  46. RTC_GPIO_MODE_INPUT_OUTUT, /*!< Pad pull output + input */
  47. RTC_GPIO_MODE_DISABLED, /*!< Pad (output + input) disable */
  48. } rtc_gpio_mode_t;
  49. /**
  50. * @brief Provides access to a constant table of RTC I/O pin
  51. * function information.
  52. *
  53. * This is an internal function of the driver, and is not usually useful
  54. * for external use.
  55. */
  56. extern const rtc_gpio_desc_t rtc_gpio_desc[GPIO_PIN_COUNT];
  57. /**
  58. * @brief Determine if the specified GPIO is a valid RTC GPIO.
  59. *
  60. * @param gpio_num GPIO number
  61. * @return true if GPIO is valid for RTC GPIO use. talse otherwise.
  62. */
  63. inline static bool rtc_gpio_is_valid_gpio(gpio_num_t gpio_num)
  64. {
  65. return gpio_num < GPIO_PIN_COUNT
  66. && rtc_gpio_desc[gpio_num].reg != 0;
  67. }
  68. #define RTC_GPIO_IS_VALID_GPIO(gpio_num) rtc_gpio_is_valid_gpio(gpio_num) // Deprecated, use rtc_gpio_is_valid_gpio()
  69. /**
  70. * @brief Init a GPIO as RTC GPIO
  71. *
  72. * This function must be called when initializing a pad for an analog function.
  73. *
  74. * @param gpio_num GPIO number (e.g. GPIO_NUM_12)
  75. *
  76. * @return
  77. * - ESP_OK success
  78. * - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
  79. */
  80. esp_err_t rtc_gpio_init(gpio_num_t gpio_num);
  81. /**
  82. * @brief Init a GPIO as digital GPIO
  83. *
  84. * @param gpio_num GPIO number (e.g. GPIO_NUM_12)
  85. *
  86. * @return
  87. * - ESP_OK success
  88. * - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
  89. */
  90. esp_err_t rtc_gpio_deinit(gpio_num_t gpio_num);
  91. /**
  92. * @brief Get the RTC IO input level
  93. *
  94. * @param gpio_num GPIO number (e.g. GPIO_NUM_12)
  95. *
  96. * @return
  97. * - 1 High level
  98. * - 0 Low level
  99. * - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
  100. */
  101. uint32_t rtc_gpio_get_level(gpio_num_t gpio_num);
  102. /**
  103. * @brief Set the RTC IO output level
  104. *
  105. * @param gpio_num GPIO number (e.g. GPIO_NUM_12)
  106. * @param level output level
  107. *
  108. * @return
  109. * - ESP_OK Success
  110. * - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
  111. */
  112. esp_err_t rtc_gpio_set_level(gpio_num_t gpio_num, uint32_t level);
  113. /**
  114. * @brief RTC GPIO set direction
  115. *
  116. * Configure RTC GPIO direction, such as output only, input only,
  117. * output and input.
  118. *
  119. * @param gpio_num GPIO number (e.g. GPIO_NUM_12)
  120. * @param mode GPIO direction
  121. *
  122. * @return
  123. * - ESP_OK Success
  124. * - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
  125. */
  126. esp_err_t rtc_gpio_set_direction(gpio_num_t gpio_num, rtc_gpio_mode_t mode);
  127. /**
  128. * @brief RTC GPIO pullup enable
  129. *
  130. * This function only works for RTC IOs. In general, call gpio_pullup_en,
  131. * which will work both for normal GPIOs and RTC IOs.
  132. *
  133. * @param gpio_num GPIO number (e.g. GPIO_NUM_12)
  134. *
  135. * @return
  136. * - ESP_OK Success
  137. * - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
  138. */
  139. esp_err_t rtc_gpio_pullup_en(gpio_num_t gpio_num);
  140. /**
  141. * @brief RTC GPIO pulldown enable
  142. *
  143. * This function only works for RTC IOs. In general, call gpio_pulldown_en,
  144. * which will work both for normal GPIOs and RTC IOs.
  145. *
  146. * @param gpio_num GPIO number (e.g. GPIO_NUM_12)
  147. *
  148. * @return
  149. * - ESP_OK Success
  150. * - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
  151. */
  152. esp_err_t rtc_gpio_pulldown_en(gpio_num_t gpio_num);
  153. /**
  154. * @brief RTC GPIO pullup disable
  155. *
  156. * This function only works for RTC IOs. In general, call gpio_pullup_dis,
  157. * which will work both for normal GPIOs and RTC IOs.
  158. *
  159. * @param gpio_num GPIO number (e.g. GPIO_NUM_12)
  160. *
  161. * @return
  162. * - ESP_OK Success
  163. * - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
  164. */
  165. esp_err_t rtc_gpio_pullup_dis(gpio_num_t gpio_num);
  166. /**
  167. * @brief RTC GPIO pulldown disable
  168. *
  169. * This function only works for RTC IOs. In general, call gpio_pulldown_dis,
  170. * which will work both for normal GPIOs and RTC IOs.
  171. *
  172. * @param gpio_num GPIO number (e.g. GPIO_NUM_12)
  173. *
  174. * @return
  175. * - ESP_OK Success
  176. * - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
  177. */
  178. esp_err_t rtc_gpio_pulldown_dis(gpio_num_t gpio_num);
  179. /**
  180. * @brief Enable hold function on an RTC IO pad
  181. *
  182. * Enabling HOLD function will cause the pad to latch current values of
  183. * input enable, output enable, output value, function, drive strength values.
  184. * This function is useful when going into light or deep sleep mode to prevent
  185. * the pin configuration from changing.
  186. *
  187. * @param gpio_num GPIO number (e.g. GPIO_NUM_12)
  188. * @return
  189. * - ESP_OK Success
  190. * - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
  191. */
  192. esp_err_t rtc_gpio_hold_en(gpio_num_t gpio_num);
  193. /**
  194. * @brief Disable hold function on an RTC IO pad
  195. *
  196. * Disabling hold function will allow the pad receive the values of
  197. * input enable, output enable, output value, function, drive strength from
  198. * RTC_IO peripheral.
  199. *
  200. * @param gpio_num GPIO number (e.g. GPIO_NUM_12)
  201. * @return
  202. * - ESP_OK Success
  203. * - ESP_ERR_INVALID_ARG GPIO is not an RTC IO
  204. */
  205. esp_err_t rtc_gpio_hold_dis(gpio_num_t gpio_num);
  206. /**
  207. * @brief Disable force hold signal for all RTC IOs
  208. *
  209. * Each RTC pad has a "force hold" input signal from the RTC controller.
  210. * If this signal is set, pad latches current values of input enable,
  211. * function, output enable, and other signals which come from the RTC mux.
  212. * Force hold signal is enabled before going into deep sleep for pins which
  213. * are used for EXT1 wakeup.
  214. */
  215. void rtc_gpio_force_hold_dis_all();
  216. /**
  217. * @brief Set RTC GPIO pad drive capability
  218. *
  219. * @param gpio_num GPIO number, only support output GPIOs
  220. * @param strength Drive capability of the pad
  221. *
  222. * @return
  223. * - ESP_OK Success
  224. * - ESP_ERR_INVALID_ARG Parameter error
  225. */
  226. esp_err_t rtc_gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength);
  227. /**
  228. * @brief Get RTC GPIO pad drive capability
  229. *
  230. * @param gpio_num GPIO number, only support output GPIOs
  231. * @param strength Pointer to accept drive capability of the pad
  232. *
  233. * @return
  234. * - ESP_OK Success
  235. * - ESP_ERR_INVALID_ARG Parameter error
  236. */
  237. esp_err_t rtc_gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength);
  238. #ifdef __cplusplus
  239. }
  240. #endif
  241. #endif