Select one of the symbols to view example projects that use it.
 
Outline
#include <string.h>
#include "esp_log.h"
#include "esp_err.h"
#include "esp_check.h"
#include "esp_private/periph_ctrl.h"
#include "esp_private/io_mux.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/timers.h"
#include "driver/rtc_io.h"
#include "driver/lp_io.h"
#include "hal/rtc_io_hal.h"
#include "soc/rtc_io_periph.h"
#include "soc/soc_caps.h"
RTCIO_TAG
#define RTCIO_ENTER_CRITICAL
#define RTCIO_EXIT_CRITICAL
rtc_gpio_is_valid_gpio(gpio_num_t)
rtc_io_number_get(gpio_num_t)
rtc_gpio_init(gpio_num_t)
rtc_gpio_deinit(gpio_num_t)
rtc_gpio_set_level(gpio_num_t, uint32_t)
rtc_gpio_get_level(gpio_num_t)
rtc_gpio_set_drive_capability(gpio_num_t, gpio_drive_cap_t)
rtc_gpio_get_drive_capability(gpio_num_t, gpio_drive_cap_t *)
rtc_gpio_set_direction(gpio_num_t, rtc_gpio_mode_t)
rtc_gpio_set_direction_in_sleep(gpio_num_t, rtc_gpio_mode_t)
rtc_gpio_pullup_en(gpio_num_t)
rtc_gpio_pullup_dis(gpio_num_t)
rtc_gpio_pulldown_en(gpio_num_t)
rtc_gpio_pulldown_dis(gpio_num_t)
rtc_gpio_iomux_func_sel(gpio_num_t, int)
rtc_gpio_hold_en(gpio_num_t)
rtc_gpio_hold_dis(gpio_num_t)
rtc_gpio_force_hold_en_all()
rtc_gpio_force_hold_dis_all()
rtc_gpio_isolate(gpio_num_t)
rtc_gpio_wakeup_enable(gpio_num_t, gpio_int_type_t)
rtc_gpio_wakeup_disable(gpio_num_t)
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/esp_driver_gpio/src/rtc_io.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <string.h> #include "esp_log.h" #include "esp_err.h" #include "esp_check.h" #include "esp_private/periph_ctrl.h" #include "esp_private/io_mux.h" #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "freertos/timers.h" #include "driver/rtc_io.h" #include "driver/lp_io.h" #include "hal/rtc_io_hal.h" #include "soc/rtc_io_periph.h" #include "soc/soc_caps.h"14 includes static const char __attribute__((__unused__)) *RTCIO_TAG = "RTCIO"; extern portMUX_TYPE rtc_spinlock; //TODO: Will be placed in the appropriate position after the rtc module is finished. #define RTCIO_ENTER_CRITICAL() portENTER_CRITICAL(&rtc_spinlock) #define RTCIO_EXIT_CRITICAL() portEXIT_CRITICAL(&rtc_spinlock) bool rtc_gpio_is_valid_gpio(gpio_num_t gpio_num) { #if SOC_RTCIO_PIN_COUNT > 0 return (gpio_num < GPIO_PIN_COUNT && rtc_io_num_map[gpio_num] >= 0); #else return false; #endif }{ ... } #if SOC_RTCIO_PIN_COUNT > 0 /*--------------------------------------------------------------- RTC IO ---------------------------------------------------------------*//* ... */ int rtc_io_number_get(gpio_num_t gpio_num) { return rtc_io_num_map[gpio_num]; }{ ... } esp_err_t rtc_gpio_init(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); #if SOC_LP_IO_CLOCK_IS_INDEPENDENT io_mux_enable_lp_io_clock(gpio_num, true); #endif rtcio_hal_function_select(rtc_io_number_get(gpio_num), RTCIO_LL_FUNC_RTC); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_deinit(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); // Select Gpio as Digital Gpio rtcio_hal_function_select(rtc_io_number_get(gpio_num), RTCIO_LL_FUNC_DIGITAL); #if SOC_LP_IO_CLOCK_IS_INDEPENDENT io_mux_enable_lp_io_clock(gpio_num, false); #endif RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED esp_err_t rtc_gpio_set_level(gpio_num_t gpio_num, uint32_t level) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_set_level(rtc_io_number_get(gpio_num), level); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } uint32_t rtc_gpio_get_level(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); return rtcio_hal_get_level(rtc_io_number_get(gpio_num)); }{ ... } esp_err_t rtc_gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); ESP_RETURN_ON_FALSE(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "Output pad only"); ESP_RETURN_ON_FALSE(strength < GPIO_DRIVE_CAP_MAX, ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO drive capability error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_set_drive_capability(rtc_io_number_get(gpio_num), strength); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t *strength) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); ESP_RETURN_ON_FALSE(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "Output pad only"); ESP_RETURN_ON_FALSE(strength != NULL, ESP_ERR_INVALID_ARG, RTCIO_TAG, "GPIO drive pointer error"); *strength = (gpio_drive_cap_t)rtcio_hal_get_drive_capability(rtc_io_number_get(gpio_num)); return ESP_OK; }{ ... } esp_err_t rtc_gpio_set_direction(gpio_num_t gpio_num, rtc_gpio_mode_t mode) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_set_direction(rtc_io_number_get(gpio_num), mode); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_set_direction_in_sleep(gpio_num_t gpio_num, rtc_gpio_mode_t mode) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_set_direction_in_sleep(rtc_io_number_get(gpio_num), mode); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_pullup_en(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_pullup_enable(rtc_io_number_get(gpio_num)); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_pullup_dis(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_pullup_disable(rtc_io_number_get(gpio_num)); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_pulldown_en(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_pulldown_enable(rtc_io_number_get(gpio_num)); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_pulldown_dis(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_pulldown_disable(rtc_io_number_get(gpio_num)); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_iomux_func_sel(gpio_num_t gpio_num, int func) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_iomux_func_sel(rtc_io_number_get(gpio_num), func); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } #if SOC_LP_GPIO_MATRIX_SUPPORTED esp_err_t lp_gpio_connect_in_signal(gpio_num_t gpio_num, uint32_t signal_idx, bool inv) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "LP_IO number error"); rtcio_hal_matrix_in(rtc_io_number_get(gpio_num), signal_idx, inv); return ESP_OK; }{...} esp_err_t lp_gpio_connect_out_signal(gpio_num_t gpio_num, uint32_t signal_idx, bool out_inv, bool out_en_inv) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "LP_IO number error"); rtcio_hal_matrix_out(rtc_io_number_get(gpio_num), signal_idx, out_inv, out_en_inv); return ESP_OK; }{...} /* ... */#endif // SOC_LP_GPIO_MATRIX_SUPPORTED /* ... */ #endif // SOC_RTCIO_INPUT_OUTPUT_SUPPORTED #if SOC_RTCIO_HOLD_SUPPORTED esp_err_t rtc_gpio_hold_en(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_hold_enable(rtc_io_number_get(gpio_num)); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_hold_dis(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_hold_disable(rtc_io_number_get(gpio_num)); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_force_hold_en_all(void) { RTCIO_ENTER_CRITICAL(); rtcio_hal_hold_all(); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_force_hold_dis_all(void) { RTCIO_ENTER_CRITICAL(); rtcio_hal_unhold_all(); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } #endif/* ... */ // SOC_RTCIO_HOLD_SUPPORTED #if SOC_RTCIO_HOLD_SUPPORTED && SOC_RTCIO_INPUT_OUTPUT_SUPPORTED esp_err_t rtc_gpio_isolate(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_isolate(rtc_io_number_get(gpio_num)); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } /* ... */#endif // SOC_RTCIO_HOLD_SUPPORTED && SOC_RTCIO_INPUT_OUTPUT_SUPPORTED #if SOC_RTCIO_WAKE_SUPPORTED esp_err_t rtc_gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); if (intr_type == GPIO_INTR_POSEDGE || intr_type == GPIO_INTR_NEGEDGE || intr_type == GPIO_INTR_ANYEDGE) { return ESP_ERR_INVALID_ARG; // Dont support this mode. }{...} RTCIO_ENTER_CRITICAL(); rtcio_hal_wakeup_enable(rtc_io_number_get(gpio_num), intr_type); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } esp_err_t rtc_gpio_wakeup_disable(gpio_num_t gpio_num) { ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error"); RTCIO_ENTER_CRITICAL(); rtcio_hal_wakeup_disable(rtc_io_number_get(gpio_num)); RTCIO_EXIT_CRITICAL(); return ESP_OK; }{ ... } /* ... */#endif // SOC_RTCIO_WAKE_SUPPORTED /* ... */ #endif // SOC_RTCIO_PIN_COUNT > 0
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.