Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05db08e

Browse files
committed
Update esp32-hal-gpio.c
1 parent ad067ea commit 05db08e

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

cores/esp32/esp32-hal-gpio.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,40 +164,41 @@ extern void IRAM_ATTR __pinMode(uint8_t pin, uint8_t mode)
164164
return;
165165
}
166166

167-
uint32_t rtc_reg = rtc_io_desc[pin].reg;
167+
int8_t rtc_io = esp32_gpioMux[pin].rtc;
168+
uint32_t rtc_reg = (rtc_io != -1)?rtc_io_desc[rtc_io].reg:0;
168169
if(mode == ANALOG) {
169170
if(!rtc_reg) {
170171
return;//not rtc pin
171172
}
172173
#if CONFIG_IDF_TARGET_ESP32S2
173174
SENS.sar_io_mux_conf.iomux_clk_gate_en = 1;
174175
#endif
175-
SET_PERI_REG_MASK(rtc_io_desc[pin].reg, (rtc_io_desc[pin].mux));
176-
SET_PERI_REG_BITS(rtc_io_desc[pin].reg, RTC_IO_TOUCH_PAD1_FUN_SEL_V, SOC_PIN_FUNC_RTC_IO, rtc_io_desc[pin].func);
176+
SET_PERI_REG_MASK(rtc_io_desc[rtc_io].reg, (rtc_io_desc[rtc_io].mux));
177+
SET_PERI_REG_BITS(rtc_io_desc[rtc_io].reg, RTC_IO_TOUCH_PAD1_FUN_SEL_V, SOC_PIN_FUNC_RTC_IO, rtc_io_desc[rtc_io].func);
177178

178-
RTCIO.pin[pin].pad_driver = 0;//OD = 1
179-
RTCIO.enable_w1tc.w1tc = (1U << pin);
180-
CLEAR_PERI_REG_MASK(rtc_io_desc[pin].reg, rtc_io_desc[pin].ie);
179+
RTCIO.pin[rtc_io].pad_driver = 0;//OD = 1
180+
RTCIO.enable_w1tc.w1tc = (1U << rtc_io);
181+
CLEAR_PERI_REG_MASK(rtc_io_desc[rtc_io].reg, rtc_io_desc[rtc_io].ie);
181182

182-
if (rtc_io_desc[pin].pullup) {
183-
CLEAR_PERI_REG_MASK(rtc_io_desc[pin].reg, rtc_io_desc[pin].pullup);
183+
if (rtc_io_desc[rtc_io].pullup) {
184+
CLEAR_PERI_REG_MASK(rtc_io_desc[rtc_io].reg, rtc_io_desc[rtc_io].pullup);
184185
}
185-
if (rtc_io_desc[pin].pulldown) {
186-
CLEAR_PERI_REG_MASK(rtc_io_desc[pin].reg, rtc_io_desc[pin].pulldown);
186+
if (rtc_io_desc[rtc_io].pulldown) {
187+
CLEAR_PERI_REG_MASK(rtc_io_desc[rtc_io].reg, rtc_io_desc[rtc_io].pulldown);
187188
}
188189
ESP_REG(DR_REG_IO_MUX_BASE + esp32_gpioMux[pin].reg) = ((uint32_t)GPIO_FUNC << MCU_SEL_S) | ((uint32_t)2 << FUN_DRV_S) | FUN_IE;
189190
return;
190191
}
191192

192193
//RTC pins PULL settings
193-
if(esp32_gpioMux[pin].rtc != -1) {
194-
ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_io_desc[pin].mux);
194+
if(rtc_reg) {
195+
ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_io_desc[rtc_io].mux);
195196
if(mode & PULLUP) {
196-
ESP_REG(rtc_reg) = (ESP_REG(rtc_reg) | rtc_io_desc[pin].pullup) & ~(rtc_io_desc[pin].pulldown);
197+
ESP_REG(rtc_reg) = (ESP_REG(rtc_reg) | rtc_io_desc[rtc_io].pullup) & ~(rtc_io_desc[rtc_io].pulldown);
197198
} else if(mode & PULLDOWN) {
198-
ESP_REG(rtc_reg) = (ESP_REG(rtc_reg) | rtc_io_desc[pin].pulldown) & ~(rtc_io_desc[pin].pullup);
199+
ESP_REG(rtc_reg) = (ESP_REG(rtc_reg) | rtc_io_desc[rtc_io].pulldown) & ~(rtc_io_desc[rtc_io].pullup);
199200
} else {
200-
ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_io_desc[pin].pullup | rtc_io_desc[pin].pulldown);
201+
ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_io_desc[rtc_io].pullup | rtc_io_desc[rtc_io].pulldown);
201202
}
202203
}
203204

0 commit comments

Comments
 (0)