Select one of the symbols to view example projects that use it.
 
Outline
#include <esp_types.h>
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "esp_heap_caps.h"
#include "driver/gpio.h"
#include "driver/rtc_io.h"
#include "soc/interrupts.h"
#include "esp_ipc.h"
#include "soc/soc_caps.h"
#include "soc/gpio_periph.h"
#include "esp_log.h"
#include "esp_check.h"
#include "hal/gpio_hal.h"
#include "esp_private/esp_gpio_reserve.h"
#include "esp_private/io_mux.h"
#include "hal/rtc_io_hal.h"
GPIO_TAG
#define GPIO_CHECK
#define GPIO_ISR_CORE_ID_UNINIT
#define SOC_GPIO_SUPPORT_RTC_INDEPENDENT
gpio_isr_func_t
gpio_isr_alloc_t
gpio_context_t
_gpio_hal
gpio_context
gpio_pullup_en(gpio_num_t)
gpio_pullup_dis(gpio_num_t)
gpio_pulldown_en(gpio_num_t)
gpio_pulldown_dis(gpio_num_t)
gpio_set_intr_type(gpio_num_t, gpio_int_type_t)
gpio_intr_enable_on_core(gpio_num_t, uint32_t)
gpio_intr_enable(gpio_num_t)
gpio_intr_disable(gpio_num_t)
gpio_input_disable(gpio_num_t)
gpio_input_enable(gpio_num_t)
gpio_output_disable(gpio_num_t)
gpio_output_enable(gpio_num_t)
gpio_od_disable(gpio_num_t)
gpio_od_enable(gpio_num_t)
gpio_set_level(gpio_num_t, uint32_t)
gpio_get_level(gpio_num_t)
gpio_set_pull_mode(gpio_num_t, gpio_pull_mode_t)
gpio_set_direction(gpio_num_t, gpio_mode_t)
gpio_config(const gpio_config_t *)
gpio_reset_pin(gpio_num_t)
gpio_isr_loop(uint32_t, const uint32_t)
gpio_intr_service(void *)
gpio_install_isr_service(int)
gpio_isr_handler_add(gpio_num_t, gpio_isr_t, void *)
gpio_isr_handler_remove(gpio_num_t)
gpio_uninstall_isr_service()
gpio_isr_register_on_core_static(void *)
gpio_isr_register(void (*)(void *), void *, int, gpio_isr_handle_t *)
gpio_wakeup_enable(gpio_num_t, gpio_int_type_t)
gpio_wakeup_disable(gpio_num_t)
gpio_set_drive_capability(gpio_num_t, gpio_drive_cap_t)
gpio_get_drive_capability(gpio_num_t, gpio_drive_cap_t *)
gpio_hold_en(gpio_num_t)
gpio_hold_dis(gpio_num_t)
gpio_deep_sleep_hold_en()
gpio_deep_sleep_hold_dis()
gpio_iomux_in(uint32_t, uint32_t)
gpio_iomux_out(uint8_t, int, bool)
gpio_sleep_pullup_en(gpio_num_t)
gpio_sleep_pullup_dis(gpio_num_t)
gpio_sleep_pulldown_en(gpio_num_t)
gpio_sleep_pulldown_dis(gpio_num_t)
gpio_sleep_input_disable(gpio_num_t)
gpio_sleep_input_enable(gpio_num_t)
gpio_sleep_output_disable(gpio_num_t)
gpio_sleep_output_enable(gpio_num_t)
gpio_sleep_set_direction(gpio_num_t, gpio_mode_t)
gpio_sleep_set_pull_mode(gpio_num_t, gpio_pull_mode_t)
gpio_sleep_sel_en(gpio_num_t)
gpio_sleep_sel_dis(gpio_num_t)
gpio_dump_io_configuration(FILE *, uint64_t)
gpio_func_sel(gpio_num_t, uint32_t)
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/esp_driver_gpio/src/gpio.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <esp_types.h> #include "esp_err.h" #include "freertos/FreeRTOS.h" #include "esp_heap_caps.h" #include "driver/gpio.h" #include "driver/rtc_io.h" #include "soc/interrupts.h"7 includes #if !CONFIG_FREERTOS_UNICORE #include "esp_ipc.h" #endif #include "soc/soc_caps.h" #include "soc/gpio_periph.h" #include "esp_log.h" #include "esp_check.h" #include "hal/gpio_hal.h" #include "esp_private/esp_gpio_reserve.h" #include "esp_private/io_mux.h"7 includes #if (SOC_RTCIO_PIN_COUNT > 0) #include "hal/rtc_io_hal.h" #endif static const char *GPIO_TAG = "gpio"; #define GPIO_CHECK(a, str, ret_val) ESP_RETURN_ON_FALSE(a, ret_val, GPIO_TAG, "%s", str) #define GPIO_ISR_CORE_ID_UNINIT (3) //default value for SOC_GPIO_SUPPORT_RTC_INDEPENDENT is 0 #ifndef SOC_GPIO_SUPPORT_RTC_INDEPENDENT #define SOC_GPIO_SUPPORT_RTC_INDEPENDENT 0 #endif typedef struct { gpio_isr_t fn; /*!< isr function */ void *args; /*!< isr function args */ }{ ... } gpio_isr_func_t; // Used by the IPC call to register the interrupt service routine. typedef struct { int source; /*!< ISR source */ int intr_alloc_flags; /*!< ISR alloc flag */ void (*fn)(void *); /*!< ISR function */ void *arg; /*!< ISR function args*/ void *handle; /*!< ISR handle */ esp_err_t ret; }{ ... } gpio_isr_alloc_t; typedef struct { gpio_hal_context_t *gpio_hal; portMUX_TYPE gpio_spinlock; uint32_t isr_core_id; gpio_isr_func_t *gpio_isr_func; gpio_isr_handle_t gpio_isr_handle; uint64_t isr_clr_on_entry_mask; // for edge-triggered interrupts, interrupt status bits should be cleared before entering per-pin handlers }{ ... } gpio_context_t; static gpio_hal_context_t _gpio_hal = { .dev = GPIO_HAL_GET_HW(GPIO_PORT_0) }{...}; static gpio_context_t gpio_context = { .gpio_hal = &_gpio_hal, .gpio_spinlock = portMUX_INITIALIZER_UNLOCKED, .isr_core_id = GPIO_ISR_CORE_ID_UNINIT, .gpio_isr_func = NULL, .isr_clr_on_entry_mask = 0, }{...}; esp_err_t gpio_pullup_en(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); if (!rtc_gpio_is_valid_gpio(gpio_num) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) { portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_pullup_en(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); }{...} else { #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED rtc_gpio_pullup_en(gpio_num); #else abort(); // This should be eliminated as unreachable, unless a programming error has occurred #endif }{...} return ESP_OK; }{ ... } esp_err_t gpio_pullup_dis(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); if (!rtc_gpio_is_valid_gpio(gpio_num) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) { portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_pullup_dis(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); }{...} else { #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED rtc_gpio_pullup_dis(gpio_num); #else abort(); // This should be eliminated as unreachable, unless a programming error has occurred #endif }{...} return ESP_OK; }{ ... } esp_err_t gpio_pulldown_en(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); if (!rtc_gpio_is_valid_gpio(gpio_num) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) { portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_pulldown_en(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); }{...} else { #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED rtc_gpio_pulldown_en(gpio_num); #else abort(); // This should be eliminated as unreachable, unless a programming error has occurred #endif }{...} return ESP_OK; }{ ... } esp_err_t gpio_pulldown_dis(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); if (!rtc_gpio_is_valid_gpio(gpio_num) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) { portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_pulldown_dis(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); }{...} else { #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED rtc_gpio_pulldown_dis(gpio_num); #else abort(); // This should be eliminated as unreachable, unless a programming error has occurred #endif }{...} return ESP_OK; }{ ... } esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); GPIO_CHECK(intr_type < GPIO_INTR_MAX, "GPIO interrupt type error", ESP_ERR_INVALID_ARG); portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_set_intr_type(gpio_context.gpio_hal, gpio_num, intr_type); if (intr_type == GPIO_INTR_POSEDGE || intr_type == GPIO_INTR_NEGEDGE || intr_type == GPIO_INTR_ANYEDGE) { gpio_context.isr_clr_on_entry_mask |= (1ULL << (gpio_num)); }{...} else { gpio_context.isr_clr_on_entry_mask &= ~(1ULL << (gpio_num)); }{...} portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{ ... } static inline esp_err_t gpio_intr_enable_on_core(gpio_num_t gpio_num, uint32_t core_id) { gpio_hal_intr_enable_on_core(gpio_context.gpio_hal, gpio_num, core_id); return ESP_OK; }{ ... } esp_err_t gpio_intr_enable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); portENTER_CRITICAL(&gpio_context.gpio_spinlock); if (gpio_context.isr_core_id == GPIO_ISR_CORE_ID_UNINIT) { gpio_context.isr_core_id = xPortGetCoreID(); }{...} portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return gpio_intr_enable_on_core(gpio_num, gpio_context.isr_core_id); }{ ... } esp_err_t gpio_intr_disable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_intr_disable(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{ ... } static esp_err_t gpio_input_disable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_input_disable(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{ ... } esp_err_t gpio_input_enable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_input_enable(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{ ... } esp_err_t gpio_output_disable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_output_disable(gpio_context.gpio_hal, gpio_num); gpio_hal_matrix_out_default(gpio_context.gpio_hal, gpio_num); // Ensure no other output signal is routed via GPIO matrix to this pin return ESP_OK; }{ ... } esp_err_t gpio_output_enable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO output gpio_num error", ESP_ERR_INVALID_ARG); gpio_hal_matrix_out_default(gpio_context.gpio_hal, gpio_num); // No peripheral output signal routed to the pin, just as a simple GPIO output gpio_hal_output_enable(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{ ... } esp_err_t gpio_od_disable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_od_disable(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{ ... } esp_err_t gpio_od_enable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_od_enable(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{ ... } esp_err_t gpio_set_level(gpio_num_t gpio_num, uint32_t level) { GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO output gpio_num error", ESP_ERR_INVALID_ARG); gpio_hal_set_level(gpio_context.gpio_hal, gpio_num, level); return ESP_OK; }{ ... } int gpio_get_level(gpio_num_t gpio_num) { return gpio_hal_get_level(gpio_context.gpio_hal, gpio_num); }{ ... } #if SOC_GPIO_SUPPORT_PIN_HYS_FILTER static esp_err_t gpio_hysteresis_enable(gpio_num_t gpio_num) { gpio_hal_hysteresis_soft_enable(gpio_context.gpio_hal, gpio_num, true); return ESP_OK; }{...} static esp_err_t gpio_hysteresis_disable(gpio_num_t gpio_num) { gpio_hal_hysteresis_soft_enable(gpio_context.gpio_hal, gpio_num, false); return ESP_OK; }{...} #if SOC_GPIO_SUPPORT_PIN_HYS_CTRL_BY_EFUSE static esp_err_t gpio_hysteresis_by_efuse(gpio_num_t gpio_num) { gpio_hal_hysteresis_from_efuse(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{...} /* ... */#endif/* ... */ #endif //SOC_GPIO_SUPPORT_PIN_HYS_FILTER esp_err_t gpio_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); GPIO_CHECK(pull <= GPIO_FLOATING, "GPIO pull mode error", ESP_ERR_INVALID_ARG); esp_err_t ret = ESP_OK; switch (pull) { case GPIO_PULLUP_ONLY: gpio_pulldown_dis(gpio_num); gpio_pullup_en(gpio_num); break; ... case GPIO_PULLDOWN_ONLY: gpio_pulldown_en(gpio_num); gpio_pullup_dis(gpio_num); break; ... case GPIO_PULLUP_PULLDOWN: gpio_pulldown_en(gpio_num); gpio_pullup_en(gpio_num); break; ... case GPIO_FLOATING: gpio_pulldown_dis(gpio_num); gpio_pullup_dis(gpio_num); break; ... default: ESP_LOGE(GPIO_TAG, "Unknown pull up/down mode,gpio_num=%u,pull=%u", gpio_num, pull); ret = ESP_ERR_INVALID_ARG; break;... }{...} return ret; }{ ... } esp_err_t gpio_set_direction(gpio_num_t gpio_num, gpio_mode_t mode) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); if ((GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) != true) && (mode & GPIO_MODE_DEF_OUTPUT)) { ESP_LOGE(GPIO_TAG, "io_num=%d can only be input", gpio_num); return ESP_ERR_INVALID_ARG; }{...} esp_err_t ret = ESP_OK; if (mode & GPIO_MODE_DEF_INPUT) { gpio_input_enable(gpio_num); }{...} else { gpio_input_disable(gpio_num); }{...} if (mode & GPIO_MODE_DEF_OUTPUT) { gpio_output_enable(gpio_num); }{...} else { gpio_output_disable(gpio_num); }{...} if (mode & GPIO_MODE_DEF_OD) { gpio_od_enable(gpio_num); }{...} else { gpio_od_disable(gpio_num); }{...} return ret; }{ ... } esp_err_t gpio_config(const gpio_config_t *pGPIOConfig) { uint64_t gpio_pin_mask = (pGPIOConfig->pin_bit_mask); uint32_t io_num = 0; uint8_t input_en = 0; uint8_t output_en = 0; uint8_t od_en = 0; uint8_t pu_en = 0; uint8_t pd_en = 0; if (pGPIOConfig->pin_bit_mask == 0 || pGPIOConfig->pin_bit_mask & ~SOC_GPIO_VALID_GPIO_MASK) { ESP_LOGE(GPIO_TAG, "GPIO_PIN mask error "); return ESP_ERR_INVALID_ARG; }{...} if (pGPIOConfig->mode & GPIO_MODE_DEF_OUTPUT && pGPIOConfig->pin_bit_mask & ~SOC_GPIO_VALID_OUTPUT_GPIO_MASK) { ESP_LOGE(GPIO_TAG, "GPIO can only be used as input mode"); return ESP_ERR_INVALID_ARG; }{...} do { if (((gpio_pin_mask >> io_num) & BIT(0))) { #if SOC_RTCIO_PIN_COUNT > 0 if (rtc_gpio_is_valid_gpio(io_num)) { rtc_gpio_deinit(io_num); }{...} #endif/* ... */ if ((pGPIOConfig->mode) & GPIO_MODE_DEF_INPUT) { input_en = 1; gpio_input_enable(io_num); }{...} else { gpio_input_disable(io_num); }{...} if ((pGPIOConfig->mode) & GPIO_MODE_DEF_OD) { od_en = 1; gpio_od_enable(io_num); }{...} else { gpio_od_disable(io_num); }{...} if ((pGPIOConfig->mode) & GPIO_MODE_DEF_OUTPUT) { output_en = 1; gpio_output_enable(io_num); }{...} else { gpio_output_disable(io_num); }{...} if (pGPIOConfig->pull_up_en) { pu_en = 1; gpio_pullup_en(io_num); }{...} else { gpio_pullup_dis(io_num); }{...} if (pGPIOConfig->pull_down_en) { pd_en = 1; gpio_pulldown_en(io_num); }{...} else { gpio_pulldown_dis(io_num); }{...} ESP_LOGI(GPIO_TAG, "GPIO[%"PRIu32"]| InputEn: %d| OutputEn: %d| OpenDrain: %d| Pullup: %d| Pulldown: %d| Intr:%d ", io_num, input_en, output_en, od_en, pu_en, pd_en, pGPIOConfig->intr_type); gpio_set_intr_type(io_num, pGPIOConfig->intr_type); if (pGPIOConfig->intr_type) { gpio_intr_enable(io_num); }{...} else { gpio_intr_disable(io_num); }{...} #if SOC_GPIO_SUPPORT_PIN_HYS_FILTER if (pGPIOConfig->hys_ctrl_mode == GPIO_HYS_SOFT_ENABLE) { gpio_hysteresis_enable(io_num); }{...} else if (pGPIOConfig->hys_ctrl_mode == GPIO_HYS_SOFT_DISABLE) { gpio_hysteresis_disable(io_num); }{...} #if SOC_GPIO_SUPPORT_PIN_HYS_CTRL_BY_EFUSE else { gpio_hysteresis_by_efuse(io_num); }{...} #endif/* ... */ /* ... */#endif //SOC_GPIO_SUPPORT_PIN_HYS_FILTER /* By default, all the pins have to be configured as GPIO pins. */ gpio_hal_func_sel(gpio_context.gpio_hal, io_num, PIN_FUNC_GPIO); }{...} io_num++; }{...} while (io_num < GPIO_PIN_COUNT); return ESP_OK; }{ ... } esp_err_t gpio_reset_pin(gpio_num_t gpio_num) { assert(GPIO_IS_VALID_GPIO(gpio_num)); gpio_config_t cfg = { .pin_bit_mask = BIT64(gpio_num), .mode = GPIO_MODE_DISABLE, //for powersave reasons, the GPIO should not be floating, select pullup .pull_up_en = true, .pull_down_en = false, .intr_type = GPIO_INTR_DISABLE, }{...}; gpio_config(&cfg); return ESP_OK; }{ ... } static inline void IRAM_ATTR gpio_isr_loop(uint32_t status, const uint32_t gpio_num_start) { while (status) { int nbit = __builtin_ffs(status) - 1; status &= ~(1 << nbit); int gpio_num = gpio_num_start + nbit; bool intr_status_bit_cleared = false; // Edge-triggered type interrupt can clear the interrupt status bit before entering per-pin interrupt handler if ((1ULL << (gpio_num)) & gpio_context.isr_clr_on_entry_mask) { intr_status_bit_cleared = true; gpio_hal_clear_intr_status_bit(gpio_context.gpio_hal, gpio_num); }{...} if (gpio_context.gpio_isr_func[gpio_num].fn != NULL) { gpio_context.gpio_isr_func[gpio_num].fn(gpio_context.gpio_isr_func[gpio_num].args); }{...} // If the interrupt status bit was not cleared at the entry, then must clear it before exiting if (!intr_status_bit_cleared) { gpio_hal_clear_intr_status_bit(gpio_context.gpio_hal, gpio_num); }{...} }{...} }{ ... } static void IRAM_ATTR gpio_intr_service(void *arg) { //GPIO intr process if (gpio_context.gpio_isr_func == NULL) { return; }{...} //read status to get interrupt status for GPIO0-31 uint32_t gpio_intr_status; gpio_hal_get_intr_status(gpio_context.gpio_hal, gpio_context.isr_core_id, &gpio_intr_status); if (gpio_intr_status) { gpio_isr_loop(gpio_intr_status, 0); }{...} //read status1 to get interrupt status for GPIO32-39 uint32_t gpio_intr_status_h; gpio_hal_get_intr_status_high(gpio_context.gpio_hal, gpio_context.isr_core_id, &gpio_intr_status_h); if (gpio_intr_status_h) { gpio_isr_loop(gpio_intr_status_h, 32); }{...} }{ ... } esp_err_t gpio_install_isr_service(int intr_alloc_flags) { GPIO_CHECK(gpio_context.gpio_isr_func == NULL, "GPIO isr service already installed", ESP_ERR_INVALID_STATE); esp_err_t ret = ESP_ERR_NO_MEM; const uint32_t alloc_caps = (intr_alloc_flags & ESP_INTR_FLAG_IRAM) ? MALLOC_CAP_INTERNAL : MALLOC_CAP_DEFAULT; gpio_isr_func_t *isr_func = (gpio_isr_func_t *) heap_caps_calloc(GPIO_NUM_MAX, sizeof(gpio_isr_func_t), alloc_caps); if (isr_func) { portENTER_CRITICAL(&gpio_context.gpio_spinlock); if (gpio_context.gpio_isr_func == NULL) { gpio_context.gpio_isr_func = isr_func; portEXIT_CRITICAL(&gpio_context.gpio_spinlock); ret = gpio_isr_register(gpio_intr_service, NULL, intr_alloc_flags, &gpio_context.gpio_isr_handle); if (ret != ESP_OK) { // registering failed, uninstall isr service gpio_uninstall_isr_service(); }{...} }{...} else { // isr service already installed, free allocated resource portEXIT_CRITICAL(&gpio_context.gpio_spinlock); ret = ESP_ERR_INVALID_STATE; free(isr_func); }{...} }{...} return ret; }{ ... } esp_err_t gpio_isr_handler_add(gpio_num_t gpio_num, gpio_isr_t isr_handler, void *args) { GPIO_CHECK(gpio_context.gpio_isr_func != NULL, "GPIO isr service is not installed, call gpio_install_isr_service() first", ESP_ERR_INVALID_STATE); GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_intr_disable(gpio_num); if (gpio_context.gpio_isr_func) { gpio_context.gpio_isr_func[gpio_num].fn = isr_handler; gpio_context.gpio_isr_func[gpio_num].args = args; }{...} gpio_intr_enable_on_core(gpio_num, esp_intr_get_cpu(gpio_context.gpio_isr_handle)); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{ ... } esp_err_t gpio_isr_handler_remove(gpio_num_t gpio_num) { GPIO_CHECK(gpio_context.gpio_isr_func != NULL, "GPIO isr service is not installed, call gpio_install_isr_service() first", ESP_ERR_INVALID_STATE); GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_intr_disable(gpio_num); if (gpio_context.gpio_isr_func) { gpio_context.gpio_isr_func[gpio_num].fn = NULL; gpio_context.gpio_isr_func[gpio_num].args = NULL; }{...} portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{ ... } void gpio_uninstall_isr_service(void) { gpio_isr_func_t *gpio_isr_func_free = NULL; gpio_isr_handle_t gpio_isr_handle_free = NULL; portENTER_CRITICAL(&gpio_context.gpio_spinlock); if (gpio_context.gpio_isr_func == NULL) { portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return; }{...} gpio_isr_func_free = gpio_context.gpio_isr_func; gpio_context.gpio_isr_func = NULL; gpio_isr_handle_free = gpio_context.gpio_isr_handle; gpio_context.gpio_isr_handle = NULL; gpio_context.isr_core_id = GPIO_ISR_CORE_ID_UNINIT; portEXIT_CRITICAL(&gpio_context.gpio_spinlock); esp_intr_free(gpio_isr_handle_free); free(gpio_isr_func_free); return; }{ ... } static void gpio_isr_register_on_core_static(void *param) { gpio_isr_alloc_t *p = (gpio_isr_alloc_t *)param; //We need to check the return value. p->ret = esp_intr_alloc(p->source, p->intr_alloc_flags, p->fn, p->arg, p->handle); }{ ... } esp_err_t gpio_isr_register(void (*fn)(void *), void *arg, int intr_alloc_flags, gpio_isr_handle_t *handle) { GPIO_CHECK(fn, "GPIO ISR null", ESP_ERR_INVALID_ARG); gpio_isr_alloc_t p; #if !CONFIG_IDF_TARGET_ESP32P4 //TODO: IDF-7995 p.source = ETS_GPIO_INTR_SOURCE; #else p.source = ETS_GPIO_INTR0_SOURCE; #endif p.intr_alloc_flags = intr_alloc_flags; #if SOC_ANA_CMPR_INTR_SHARE_WITH_GPIO p.intr_alloc_flags |= ESP_INTR_FLAG_SHARED; #endif p.fn = fn; p.arg = arg; p.handle = handle; portENTER_CRITICAL(&gpio_context.gpio_spinlock); if (gpio_context.isr_core_id == GPIO_ISR_CORE_ID_UNINIT) { gpio_context.isr_core_id = xPortGetCoreID(); }{...} portEXIT_CRITICAL(&gpio_context.gpio_spinlock); esp_err_t ret; #if CONFIG_FREERTOS_UNICORE gpio_isr_register_on_core_static(&p); ret = ESP_OK;/* ... */ #else /* CONFIG_FREERTOS_UNICORE */ ret = esp_ipc_call_blocking(gpio_context.isr_core_id, gpio_isr_register_on_core_static, (void *)&p); #endif /* !CONFIG_FREERTOS_UNICORE */ if (ret != ESP_OK) { ESP_LOGE(GPIO_TAG, "esp_ipc_call_blocking failed (0x%x)", ret); return ESP_ERR_NOT_FOUND; }{...} if (p.ret != ESP_OK) { ESP_LOGE(GPIO_TAG, "esp_intr_alloc failed (0x%x)", p.ret); return ESP_ERR_NOT_FOUND; }{...} return ESP_OK; }{ ... } esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); esp_err_t ret = ESP_OK; if ((intr_type == GPIO_INTR_LOW_LEVEL) || (intr_type == GPIO_INTR_HIGH_LEVEL)) { #if SOC_RTCIO_WAKE_SUPPORTED if (rtc_gpio_is_valid_gpio(gpio_num)) { #if SOC_LP_IO_CLOCK_IS_INDEPENDENT // LP_IO Wake-up function does not depend on LP_IO Matrix, but uses its clock to // sample the wake-up signal, we need to enable the LP_IO clock here. io_mux_enable_lp_io_clock(gpio_num, true);/* ... */ #endif ret = rtc_gpio_wakeup_enable(gpio_num, intr_type); }{...} #endif/* ... */ portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_set_intr_type(gpio_context.gpio_hal, gpio_num, intr_type); gpio_hal_wakeup_enable(gpio_context.gpio_hal, gpio_num); #if CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND || CONFIG_PM_SLP_DISABLE_GPIO gpio_hal_sleep_sel_dis(gpio_context.gpio_hal, gpio_num); #endif portEXIT_CRITICAL(&gpio_context.gpio_spinlock); }{...} else { ESP_LOGE(GPIO_TAG, "GPIO wakeup only supports level mode, but edge mode set. gpio_num:%u", gpio_num); ret = ESP_ERR_INVALID_ARG; }{...} return ret; }{ ... } esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); esp_err_t ret = ESP_OK; #if SOC_RTCIO_WAKE_SUPPORTED if (rtc_gpio_is_valid_gpio(gpio_num)) { ret = rtc_gpio_wakeup_disable(gpio_num); #if SOC_LP_IO_CLOCK_IS_INDEPENDENT io_mux_enable_lp_io_clock(gpio_num, false); #endif }{...} #endif/* ... */ portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_wakeup_disable(gpio_context.gpio_hal, gpio_num); #if CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND || CONFIG_PM_SLP_DISABLE_GPIO gpio_hal_sleep_sel_en(gpio_context.gpio_hal, gpio_num); #endif portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ret; }{ ... } esp_err_t gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength) { GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); GPIO_CHECK(strength < GPIO_DRIVE_CAP_MAX, "GPIO drive capability error", ESP_ERR_INVALID_ARG); esp_err_t ret = ESP_OK; if (!rtc_gpio_is_valid_gpio(gpio_num) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) { portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_set_drive_capability(gpio_context.gpio_hal, gpio_num, strength); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); }{...} else { #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED ret = rtc_gpio_set_drive_capability(gpio_num, strength); #else abort(); // This should be eliminated as unreachable, unless a programming error has occurred #endif }{...} return ret; }{ ... } esp_err_t gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t *strength) { GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); GPIO_CHECK(strength != NULL, "GPIO drive capability pointer error", ESP_ERR_INVALID_ARG); esp_err_t ret = ESP_OK; if (!rtc_gpio_is_valid_gpio(gpio_num) || SOC_GPIO_SUPPORT_RTC_INDEPENDENT) { portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_get_drive_capability(gpio_context.gpio_hal, gpio_num, strength); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); }{...} else { #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED ret = rtc_gpio_get_drive_capability(gpio_num, strength); #else abort(); // This should be eliminated as unreachable, unless a programming error has occurred #endif }{...} return ret; }{ ... } esp_err_t gpio_hold_en(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "Only output-capable GPIO support this function", ESP_ERR_NOT_SUPPORTED); int ret = ESP_OK; if (rtc_gpio_is_valid_gpio(gpio_num)) { #if SOC_RTCIO_HOLD_SUPPORTED ret = rtc_gpio_hold_en(gpio_num); #endif }{...} else if (GPIO_HOLD_MASK[gpio_num]) { portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_hold_en(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); }{...} else { ret = ESP_ERR_NOT_SUPPORTED; }{...} return ret; }{ ... } esp_err_t gpio_hold_dis(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "Only output-capable GPIO support this function", ESP_ERR_NOT_SUPPORTED); int ret = ESP_OK; if (rtc_gpio_is_valid_gpio(gpio_num)) { #if SOC_RTCIO_HOLD_SUPPORTED ret = rtc_gpio_hold_dis(gpio_num); #endif }{...} else if (GPIO_HOLD_MASK[gpio_num]) { portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_hold_dis(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); }{...} else { ret = ESP_ERR_NOT_SUPPORTED; }{...} return ret; }{ ... } #if SOC_GPIO_SUPPORT_HOLD_IO_IN_DSLP && !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP void gpio_deep_sleep_hold_en(void) { portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_deep_sleep_hold_en(gpio_context.gpio_hal); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); }{ ... } void gpio_deep_sleep_hold_dis(void) { portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_deep_sleep_hold_dis(gpio_context.gpio_hal); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); }{ ... } #endif/* ... */ //SOC_GPIO_SUPPORT_HOLD_IO_IN_DSLP && !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP #if SOC_GPIO_SUPPORT_FORCE_HOLD esp_err_t IRAM_ATTR gpio_force_hold_all() { #if SOC_RTCIO_HOLD_SUPPORTED rtc_gpio_force_hold_en_all(); #endif portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_force_hold_all(); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{...} esp_err_t IRAM_ATTR gpio_force_unhold_all() { portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_force_unhold_all(); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); #if SOC_RTCIO_HOLD_SUPPORTED rtc_gpio_force_hold_dis_all(); #endif return ESP_OK; }{...} /* ... */#endif //SOC_GPIO_SUPPORT_FORCE_HOLD void gpio_iomux_in(uint32_t gpio, uint32_t signal_idx) { gpio_hal_iomux_in(gpio_context.gpio_hal, gpio, signal_idx); }{ ... } void gpio_iomux_out(uint8_t gpio_num, int func, bool out_en_inv) { gpio_hal_iomux_out(gpio_context.gpio_hal, gpio_num, func, (uint32_t)out_en_inv); }{ ... } static esp_err_t gpio_sleep_pullup_en(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_sleep_pullup_en(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{ ... } static esp_err_t gpio_sleep_pullup_dis(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_sleep_pullup_dis(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{ ... } static esp_err_t gpio_sleep_pulldown_en(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_sleep_pulldown_en(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{ ... } static esp_err_t gpio_sleep_pulldown_dis(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_sleep_pulldown_dis(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{ ... } static esp_err_t gpio_sleep_input_disable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_sleep_input_disable(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{ ... } static esp_err_t gpio_sleep_input_enable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_sleep_input_enable(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{ ... } static esp_err_t gpio_sleep_output_disable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_sleep_output_disable(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{ ... } static esp_err_t gpio_sleep_output_enable(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO output gpio_num error", ESP_ERR_INVALID_ARG); gpio_hal_sleep_output_enable(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{ ... } esp_err_t gpio_sleep_set_direction(gpio_num_t gpio_num, gpio_mode_t mode) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); if ((GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) != true) && (mode & GPIO_MODE_DEF_OUTPUT)) { ESP_LOGE(GPIO_TAG, "io_num=%d can only be input", gpio_num); return ESP_ERR_INVALID_ARG; }{...} esp_err_t ret = ESP_OK; if (mode & GPIO_MODE_DEF_INPUT) { gpio_sleep_input_enable(gpio_num); }{...} else { gpio_sleep_input_disable(gpio_num); }{...} if (mode & GPIO_MODE_DEF_OUTPUT) { gpio_sleep_output_enable(gpio_num); }{...} else { gpio_sleep_output_disable(gpio_num); }{...} return ret; }{ ... } esp_err_t gpio_sleep_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); GPIO_CHECK(pull <= GPIO_FLOATING, "GPIO pull mode error", ESP_ERR_INVALID_ARG); esp_err_t ret = ESP_OK; switch (pull) { case GPIO_PULLUP_ONLY: gpio_sleep_pulldown_dis(gpio_num); gpio_sleep_pullup_en(gpio_num); break; ... case GPIO_PULLDOWN_ONLY: gpio_sleep_pulldown_en(gpio_num); gpio_sleep_pullup_dis(gpio_num); break; ... case GPIO_PULLUP_PULLDOWN: gpio_sleep_pulldown_en(gpio_num); gpio_sleep_pullup_en(gpio_num); break; ... case GPIO_FLOATING: gpio_sleep_pulldown_dis(gpio_num); gpio_sleep_pullup_dis(gpio_num); break; ... default: ESP_LOGE(GPIO_TAG, "Unknown pull up/down mode,gpio_num=%u,pull=%u", gpio_num, pull); ret = ESP_ERR_INVALID_ARG; break;... }{...} return ret; }{ ... } esp_err_t gpio_sleep_sel_en(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_sleep_sel_en(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{ ... } esp_err_t gpio_sleep_sel_dis(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_sleep_sel_dis(gpio_context.gpio_hal, gpio_num); portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{ ... } #if CONFIG_GPIO_ESP32_SUPPORT_SWITCH_SLP_PULL esp_err_t gpio_sleep_pupd_config_apply(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_sleep_pupd_config_apply(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{...} esp_err_t gpio_sleep_pupd_config_unapply(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_sleep_pupd_config_unapply(gpio_context.gpio_hal, gpio_num); return ESP_OK; }{...} /* ... */#endif // CONFIG_GPIO_ESP32_SUPPORT_SWITCH_SLP_PULL #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED esp_err_t gpio_deep_sleep_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type) { if (!GPIO_IS_DEEP_SLEEP_WAKEUP_VALID_GPIO(gpio_num)) { ESP_LOGE(GPIO_TAG, "GPIO %d does not support deep sleep wakeup", gpio_num); return ESP_ERR_INVALID_ARG; }{...} if ((intr_type != GPIO_INTR_LOW_LEVEL) && (intr_type != GPIO_INTR_HIGH_LEVEL)) { ESP_LOGE(GPIO_TAG, "GPIO wakeup only supports level mode, but edge mode set. gpio_num:%u", gpio_num); return ESP_ERR_INVALID_ARG; }{...} portENTER_CRITICAL(&gpio_context.gpio_spinlock); #if SOC_LP_IO_CLOCK_IS_INDEPENDENT io_mux_enable_lp_io_clock(gpio_num, true); #endif gpio_hal_deepsleep_wakeup_enable(gpio_context.gpio_hal, gpio_num, intr_type); #if CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND || CONFIG_PM_SLP_DISABLE_GPIO gpio_hal_sleep_sel_dis(gpio_context.gpio_hal, gpio_num); #endif portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{...} esp_err_t gpio_deep_sleep_wakeup_disable(gpio_num_t gpio_num) { if (!GPIO_IS_DEEP_SLEEP_WAKEUP_VALID_GPIO(gpio_num)) { ESP_LOGE(GPIO_TAG, "GPIO %d does not support deep sleep wakeup", gpio_num); return ESP_ERR_INVALID_ARG; }{...} portENTER_CRITICAL(&gpio_context.gpio_spinlock); gpio_hal_deepsleep_wakeup_disable(gpio_context.gpio_hal, gpio_num); #if CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND || CONFIG_PM_SLP_DISABLE_GPIO gpio_hal_sleep_sel_en(gpio_context.gpio_hal, gpio_num); #endif #if SOC_LP_IO_CLOCK_IS_INDEPENDENT io_mux_enable_lp_io_clock(gpio_num, false); #endif portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ESP_OK; }{...} /* ... */#endif // SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED esp_err_t gpio_dump_io_configuration(FILE *out_stream, uint64_t io_bit_mask) { ESP_RETURN_ON_FALSE(out_stream, ESP_ERR_INVALID_ARG, GPIO_TAG, "out_stream error"); ESP_RETURN_ON_FALSE(!(io_bit_mask & ~SOC_GPIO_VALID_GPIO_MASK), ESP_ERR_INVALID_ARG, GPIO_TAG, "io_bit_mask error"); fprintf(out_stream, "================IO DUMP Start================\n"); while (io_bit_mask) { uint32_t gpio_num = __builtin_ffsll(io_bit_mask) - 1; io_bit_mask &= ~(1ULL << gpio_num); bool pu, pd, ie, oe, od, slp_sel; uint32_t drv, fun_sel, sig_out; gpio_hal_get_io_config(gpio_context.gpio_hal, gpio_num, &pu, &pd, &ie, &oe, &od, &drv, &fun_sel, &sig_out, &slp_sel); fprintf(out_stream, "IO[%"PRIu32"]%s -\n", gpio_num, esp_gpio_is_reserved(BIT64(gpio_num)) ? " **RESERVED**" : ""); fprintf(out_stream, " Pullup: %d, Pulldown: %d, DriveCap: %"PRIu32"\n", pu, pd, drv); fprintf(out_stream, " InputEn: %d, OutputEn: %d, OpenDrain: %d\n", ie, oe, od); fprintf(out_stream, " FuncSel: %"PRIu32" (%s)\n", fun_sel, (fun_sel == PIN_FUNC_GPIO) ? "GPIO" : "IOMUX"); if (oe && fun_sel == PIN_FUNC_GPIO) { fprintf(out_stream, " GPIO Matrix SigOut ID: %"PRIu32"%s\n", sig_out, (sig_out == SIG_GPIO_OUT_IDX) ? " (simple GPIO output)" : ""); }{...} if (ie && fun_sel == PIN_FUNC_GPIO) { uint32_t cnt = 0; fprintf(out_stream, " GPIO Matrix SigIn ID:"); for (int i = 0; i < SIG_GPIO_OUT_IDX; i++) { if (gpio_hal_get_in_signal_connected_io(gpio_context.gpio_hal, i) == gpio_num) { cnt++; fprintf(out_stream, " %d", i); }{...} }{...} if (cnt == 0) { fprintf(out_stream, " (simple GPIO input)"); }{...} fprintf(out_stream, "\n"); }{...} fprintf(out_stream, " SleepSelEn: %d\n", slp_sel); fprintf(out_stream, "\n"); }{...} fprintf(out_stream, "=================IO DUMP End==================\n"); return ESP_OK; }{ ... } esp_err_t gpio_func_sel(gpio_num_t gpio_num, uint32_t func) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); gpio_hal_func_sel(gpio_context.gpio_hal, gpio_num, func); return ESP_OK; }{ ... }
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.