1 /* 2 * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /******************************************************************************* 8 * NOTICE 9 * The hal is not public api, don't use in application code. 10 * See readme.md in hal/include/hal/readme.md 11 ******************************************************************************/ 12 13 // The HAL layer for RTC IO master (common part) 14 15 #pragma once 16 17 #include <esp_err.h> 18 #include "sdkconfig.h" 19 20 #include "soc/soc_caps.h" 21 #if SOC_RTCIO_PIN_COUNT > 0 22 #include "hal/rtc_io_ll.h" 23 #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED 24 #include "hal/rtc_io_types.h" 25 #endif 26 #endif //SOC_RTCIO_PIN_COUNT > 0 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 #if SOC_RTCIO_PIN_COUNT > 0 33 /** 34 * Select the rtcio function. 35 * 36 * @note The RTC function must be selected before the pad analog function is enabled. 37 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 38 * @param func Select pin function. 39 */ 40 #define rtcio_hal_function_select(rtcio_num, func) rtcio_ll_function_select(rtcio_num, func) 41 42 #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED 43 /** 44 * Enable rtcio output. 45 * 46 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 47 */ 48 #define rtcio_hal_output_enable(rtcio_num) rtcio_ll_output_enable(rtcio_num) 49 50 /** 51 * Disable rtcio output. 52 * 53 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 54 */ 55 #define rtcio_hal_output_disable(rtcio_num) rtcio_ll_output_disable(rtcio_num) 56 57 /** 58 * Set RTCIO output level. 59 * 60 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 61 * @param level 0: output low; ~0: output high. 62 */ 63 #define rtcio_hal_set_level(rtcio_num, level) rtcio_ll_set_level(rtcio_num, level) 64 65 /** 66 * Enable rtcio input. 67 * 68 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 69 */ 70 #define rtcio_hal_input_enable(rtcio_num) rtcio_ll_input_enable(rtcio_num) 71 72 /** 73 * Disable rtcio input. 74 * 75 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 76 */ 77 #define rtcio_hal_input_disable(rtcio_num) rtcio_ll_input_disable(rtcio_num) 78 79 /** 80 * Get RTCIO input level. 81 * 82 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 83 * @return 0: input low; ~0: input high. 84 */ 85 #define rtcio_hal_get_level(rtcio_num) rtcio_ll_get_level(rtcio_num) 86 87 /** 88 * @brief Set RTC GPIO pad drive capability. 89 * 90 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 91 * @param strength Drive capability of the pad. Range: 0 ~ 3. 92 */ 93 #define rtcio_hal_set_drive_capability(rtcio_num, strength) rtcio_ll_set_drive_capability(rtcio_num, strength) 94 95 /** 96 * @brief Get RTC GPIO pad drive capability. 97 * 98 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 99 * @return Drive capability of the pad. Range: 0 ~ 3. 100 */ 101 #define rtcio_hal_get_drive_capability(rtcio_num) rtcio_ll_get_drive_capability(rtcio_num) 102 103 /** 104 * Set RTCIO output level. 105 * 106 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 107 * @param level 0: output low; ~0: output high. 108 */ 109 #define rtcio_hal_set_level(rtcio_num, level) rtcio_ll_set_level(rtcio_num, level) 110 111 /** 112 * Get RTCIO input level. 113 * 114 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 115 * @return 0: input low; ~0: input high. 116 */ 117 #define rtcio_hal_get_level(rtcio_num) rtcio_ll_get_level(rtcio_num) 118 119 /** 120 * Set RTC IO direction. 121 * 122 * Configure RTC IO direction, such as output only, input only, 123 * output and input. 124 * 125 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 126 * @param mode IO direction. 127 */ 128 void rtcio_hal_set_direction(int rtcio_num, rtc_gpio_mode_t mode); 129 130 /** 131 * Set RTC IO direction in deep sleep or disable sleep status. 132 * 133 * NOTE: ESP32 support INPUT_ONLY mode. 134 * ESP32S2 support INPUT_ONLY, OUTPUT_ONLY, INPUT_OUTPUT mode. 135 * 136 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 137 * @param mode IO direction. 138 */ 139 void rtcio_hal_set_direction_in_sleep(int rtcio_num, rtc_gpio_mode_t mode); 140 141 /** 142 * RTC GPIO pullup enable. 143 * 144 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 145 */ 146 #define rtcio_hal_pullup_enable(rtcio_num) rtcio_ll_pullup_enable(rtcio_num) 147 148 /** 149 * RTC GPIO pullup disable. 150 * 151 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 152 */ 153 #define rtcio_hal_pullup_disable(rtcio_num) rtcio_ll_pullup_disable(rtcio_num) 154 155 /** 156 * RTC GPIO pulldown enable. 157 * 158 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 159 */ 160 #define rtcio_hal_pulldown_enable(rtcio_num) rtcio_ll_pulldown_enable(rtcio_num) 161 162 /** 163 * RTC GPIO pulldown disable. 164 * 165 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 166 */ 167 #define rtcio_hal_pulldown_disable(rtcio_num) rtcio_ll_pulldown_disable(rtcio_num) 168 169 #endif // SOC_RTCIO_INPUT_OUTPUT_SUPPORTED 170 171 #if SOC_RTCIO_HOLD_SUPPORTED 172 173 /** 174 * Enable force hold function on an RTC IO pad. 175 * 176 * Enabling HOLD function will cause the pad to lock current status, such as, 177 * input/output enable, input/output value, function, drive strength values. 178 * This function is useful when going into light or deep sleep mode to prevent 179 * the pin configuration from changing. 180 * 181 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 182 */ 183 #define rtcio_hal_hold_enable(rtcio_num) rtcio_ll_force_hold_enable(rtcio_num) 184 185 /** 186 * Disable hold function on an RTC IO pad. 187 * 188 * @note If disable the pad hold, the status of pad maybe changed in sleep mode. 189 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 190 */ 191 #define rtcio_hal_hold_disable(rtcio_num) rtcio_ll_force_hold_disable(rtcio_num) 192 193 /** 194 * Enable force hold function on all RTC IO pads. 195 * 196 * Enabling HOLD function will cause the pad to lock current status, such as, 197 * input/output enable, input/output value, function, drive strength values. 198 * This function is useful when going into light or deep sleep mode to prevent 199 * the pin configuration from changing. 200 * 201 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 202 */ 203 #define rtcio_hal_hold_all() rtcio_ll_force_hold_all() 204 205 /** 206 * Disable hold function on all RTC IO pads. 207 * 208 * @note If disable the pad hold, the status of pad maybe changed in sleep mode. 209 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 210 */ 211 #define rtcio_hal_unhold_all() rtcio_ll_force_unhold_all() 212 #endif // SOC_RTCIO_HOLD_SUPPORTED 213 214 #if SOC_RTCIO_WAKE_SUPPORTED 215 216 /** 217 * Enable wakeup function and set wakeup type from light sleep status for rtcio. 218 * 219 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 220 * @param type Wakeup on high level or low level. 221 */ 222 #define rtcio_hal_wakeup_enable(rtcio_num, type) rtcio_ll_wakeup_enable(rtcio_num, type) 223 224 /** 225 * Disable wakeup function from light sleep status for rtcio. 226 * 227 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 228 */ 229 #define rtcio_hal_wakeup_disable(rtcio_num) rtcio_ll_wakeup_disable(rtcio_num) 230 231 /** 232 * Set specific logic level on an RTC IO pin as a wakeup trigger. 233 * 234 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 235 * @param level Logic level (0) 236 */ 237 #define rtcio_hal_ext0_set_wakeup_pin(rtcio_num, level) rtcio_ll_ext0_set_wakeup_pin(rtcio_num, level) 238 239 #endif 240 241 #if SOC_RTCIO_HOLD_SUPPORTED && SOC_RTCIO_INPUT_OUTPUT_SUPPORTED 242 243 /** 244 * Helper function to disconnect internal circuits from an RTC IO 245 * This function disables input, output, pullup, pulldown, and enables 246 * hold feature for an RTC IO. 247 * Use this function if an RTC IO needs to be disconnected from internal 248 * circuits in deep sleep, to minimize leakage current. 249 * 250 * In particular, for ESP32-WROVER module, call 251 * rtc_gpio_isolate(GPIO_NUM_12) before entering deep sleep, to reduce 252 * deep sleep current. 253 * 254 * @param rtcio_num The index of rtcio. 0 ~ SOC_RTCIO_PIN_COUNT. 255 */ 256 void rtcio_hal_isolate(int rtc_num); 257 258 #endif 259 260 #endif //SOC_RTCIO_PIN_COUNT > 0 261 262 #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && (SOC_RTCIO_PIN_COUNT > 0) 263 264 #define gpio_hal_deepsleep_wakeup_enable(hal, gpio_num, intr_type) rtcio_hal_wakeup_enable(gpio_num, intr_type) 265 #define gpio_hal_deepsleep_wakeup_disable(hal, gpio_num) rtcio_hal_wakeup_disable(gpio_num) 266 #define gpio_hal_deepsleep_wakeup_is_enabled(hal, gpio_num) rtcio_hal_wakeup_is_enabled(gpio_num) 267 #define rtc_hal_gpio_get_wakeup_status() rtcio_hal_get_interrupt_status() 268 #define rtc_hal_gpio_clear_wakeup_status() rtcio_hal_clear_interrupt_status() 269 270 /** 271 * @brief Get the status of whether an IO is used for sleep wake-up. 272 * 273 * @param hw Peripheral GPIO hardware instance address. 274 * @param rtcio_num GPIO number 275 * @return True if the pin is enabled to wake up from deep-sleep 276 */ 277 #define rtcio_hal_wakeup_is_enabled(rtcio_num) rtcio_ll_wakeup_is_enabled(rtcio_num) 278 279 /** 280 * @brief Get the rtc io interrupt status 281 * 282 * @return bit 0~7 corresponding to 0 ~ SOC_RTCIO_PIN_COUNT. 283 */ 284 #define rtcio_hal_get_interrupt_status() rtcio_ll_get_interrupt_status() 285 286 /** 287 * @brief Clear all LP IO pads status 288 */ 289 #define rtcio_hal_clear_interrupt_status() rtcio_ll_clear_interrupt_status() 290 291 #endif //SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && (SOC_RTCIO_PIN_COUNT > 0) 292 293 #ifdef __cplusplus 294 } 295 #endif 296