Skip to content

Commit 917a4fd

Browse files
committed
allow setting internal pull resistors for any mode and enable them for I2C
1 parent c19fc06 commit 917a4fd

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

cores/esp32/esp32-hal-gpio.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ extern void IRAM_ATTR __pinMode(uint8_t pin, uint8_t mode)
103103
//unlock rtc
104104
ESP_REG(DR_REG_IO_MUX_BASE + esp32_gpioMux[pin].reg) = ((uint32_t)2 << MCU_SEL_S) | ((uint32_t)2 << FUN_DRV_S) | FUN_IE;
105105
return;
106-
} else if(rtc_reg) {
106+
}
107+
108+
//RTC pins PULL settings
109+
if(rtc_reg) {
107110
//lock rtc
108111
ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_gpio_desc[pin].mux);
109112
if(mode & PULLUP) {
@@ -125,12 +128,6 @@ extern void IRAM_ATTR __pinMode(uint8_t pin, uint8_t mode)
125128
} else {
126129
GPIO.enable1_w1tc.val = ((uint32_t)1 << (pin - 32));
127130
}
128-
129-
if(mode & PULLUP) {
130-
pinFunction |= FUN_PU;
131-
} else if(mode & PULLDOWN) {
132-
pinFunction |= FUN_PD;
133-
}
134131
} else if(mode & OUTPUT) {
135132
if(pin > 33){
136133
//unlock gpio
@@ -142,6 +139,12 @@ extern void IRAM_ATTR __pinMode(uint8_t pin, uint8_t mode)
142139
}
143140
}
144141

142+
if(mode & PULLUP) {
143+
pinFunction |= FUN_PU;
144+
} else if(mode & PULLDOWN) {
145+
pinFunction |= FUN_PD;
146+
}
147+
145148
pinFunction |= ((uint32_t)2 << FUN_DRV_S);//what are the drivers?
146149
pinFunction |= FUN_IE;//input enable but required for output as well?
147150

cores/esp32/esp32-hal-i2c.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ i2c_err_t i2cAttachSCL(i2c_t * i2c, int8_t scl)
6767
if(i2c == NULL){
6868
return I2C_ERROR_DEV;
6969
}
70-
pinMode(scl, OUTPUT_OPEN_DRAIN);
70+
pinMode(scl, OUTPUT_OPEN_DRAIN | PULLUP);
7171
pinMatrixOutAttach(scl, I2C_SCL_IDX(i2c->num), false, false);
7272
pinMatrixInAttach(scl, I2C_SCL_IDX(i2c->num), false);
7373
return I2C_ERROR_OK;
@@ -89,7 +89,7 @@ i2c_err_t i2cAttachSDA(i2c_t * i2c, int8_t sda)
8989
if(i2c == NULL){
9090
return I2C_ERROR_DEV;
9191
}
92-
pinMode(sda, OUTPUT_OPEN_DRAIN);
92+
pinMode(sda, OUTPUT_OPEN_DRAIN | PULLUP);
9393
pinMatrixOutAttach(sda, I2C_SDA_IDX(i2c->num), false, false);
9494
pinMatrixInAttach(sda, I2C_SDA_IDX(i2c->num), false);
9595
return I2C_ERROR_OK;

0 commit comments

Comments
 (0)