1 // Copyright 2015-2022 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 // The HAL layer for RTC IO (common part)
16
17 #include "hal/rtc_io_hal.h"
18 #include "soc/soc_caps.h"
19
20 #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
21
rtcio_hal_set_direction(int rtcio_num,rtc_gpio_mode_t mode)22 void rtcio_hal_set_direction(int rtcio_num, rtc_gpio_mode_t mode)
23 {
24 switch (mode) {
25 case RTC_GPIO_MODE_INPUT_ONLY:
26 rtcio_ll_output_mode_set(rtcio_num, RTCIO_OUTPUT_NORMAL);
27 rtcio_ll_output_disable(rtcio_num);
28 rtcio_ll_input_enable(rtcio_num);
29 break;
30 case RTC_GPIO_MODE_OUTPUT_ONLY:
31 rtcio_ll_output_mode_set(rtcio_num, RTCIO_OUTPUT_NORMAL);
32 rtcio_ll_output_enable(rtcio_num);
33 rtcio_ll_input_disable(rtcio_num);
34 break;
35 case RTC_GPIO_MODE_INPUT_OUTPUT:
36 rtcio_ll_output_mode_set(rtcio_num, RTCIO_OUTPUT_NORMAL);
37 rtcio_ll_output_enable(rtcio_num);
38 rtcio_ll_input_enable(rtcio_num);
39 break;
40 case RTC_GPIO_MODE_DISABLED:
41 rtcio_ll_output_mode_set(rtcio_num, RTCIO_OUTPUT_NORMAL);
42 rtcio_ll_output_disable(rtcio_num);
43 rtcio_ll_input_disable(rtcio_num);
44 break;
45 case RTC_GPIO_MODE_OUTPUT_OD:
46 rtcio_ll_output_mode_set(rtcio_num, RTCIO_OUTPUT_OD);
47 rtcio_ll_output_enable(rtcio_num);
48 rtcio_ll_input_disable(rtcio_num);
49 break;
50 case RTC_GPIO_MODE_INPUT_OUTPUT_OD:
51 rtcio_ll_output_mode_set(rtcio_num, RTCIO_OUTPUT_OD);
52 rtcio_ll_output_enable(rtcio_num);
53 rtcio_ll_input_enable(rtcio_num);
54 break;
55 default:
56 break;
57 }
58 }
59
rtcio_hal_isolate(int rtcio_num)60 void rtcio_hal_isolate(int rtcio_num)
61 {
62 rtcio_ll_pullup_disable(rtcio_num);
63 rtcio_ll_pulldown_disable(rtcio_num);
64 rtcio_ll_output_disable(rtcio_num);
65 rtcio_ll_input_disable(rtcio_num);
66 rtcio_ll_force_hold_enable(rtcio_num);
67 }
68
rtcio_hal_set_direction_in_sleep(int rtcio_num,rtc_gpio_mode_t mode)69 void rtcio_hal_set_direction_in_sleep(int rtcio_num, rtc_gpio_mode_t mode)
70 {
71 switch (mode) {
72 case RTC_GPIO_MODE_INPUT_ONLY:
73 rtcio_ll_in_sleep_enable_input(rtcio_num);
74 rtcio_ll_in_sleep_disable_output(rtcio_num);
75 rtcio_ll_enable_sleep_setting(rtcio_num);
76 break;
77 case RTC_GPIO_MODE_OUTPUT_ONLY:
78 rtcio_ll_enable_output_in_sleep(rtcio_num);
79 rtcio_ll_in_sleep_disable_input(rtcio_num);
80 rtcio_ll_enable_sleep_setting(rtcio_num);
81 break;
82 case RTC_GPIO_MODE_INPUT_OUTPUT:
83 rtcio_ll_in_sleep_enable_input(rtcio_num);
84 rtcio_ll_enable_output_in_sleep(rtcio_num);
85 rtcio_ll_enable_sleep_setting(rtcio_num);
86 break;
87 case RTC_GPIO_MODE_DISABLED:
88 rtcio_ll_in_sleep_disable_input(rtcio_num);
89 rtcio_ll_in_sleep_disable_output(rtcio_num);
90 rtcio_ll_disable_sleep_setting(rtcio_num);
91 break;
92 default:
93 break;
94 }
95 }
96
97 #endif
98