allow setting internal pull resistors for any mode and enable them for I2C

This commit is contained in:
me-no-dev 2016-12-14 13:11:10 +02:00
parent c19fc061b0
commit 917a4fd6f0
2 changed files with 12 additions and 9 deletions

View File

@ -103,7 +103,10 @@ extern void IRAM_ATTR __pinMode(uint8_t pin, uint8_t mode)
//unlock rtc //unlock rtc
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; 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;
return; return;
} else if(rtc_reg) { }
//RTC pins PULL settings
if(rtc_reg) {
//lock rtc //lock rtc
ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_gpio_desc[pin].mux); ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_gpio_desc[pin].mux);
if(mode & PULLUP) { if(mode & PULLUP) {
@ -125,12 +128,6 @@ extern void IRAM_ATTR __pinMode(uint8_t pin, uint8_t mode)
} else { } else {
GPIO.enable1_w1tc.val = ((uint32_t)1 << (pin - 32)); GPIO.enable1_w1tc.val = ((uint32_t)1 << (pin - 32));
} }
if(mode & PULLUP) {
pinFunction |= FUN_PU;
} else if(mode & PULLDOWN) {
pinFunction |= FUN_PD;
}
} else if(mode & OUTPUT) { } else if(mode & OUTPUT) {
if(pin > 33){ if(pin > 33){
//unlock gpio //unlock gpio
@ -142,6 +139,12 @@ extern void IRAM_ATTR __pinMode(uint8_t pin, uint8_t mode)
} }
} }
if(mode & PULLUP) {
pinFunction |= FUN_PU;
} else if(mode & PULLDOWN) {
pinFunction |= FUN_PD;
}
pinFunction |= ((uint32_t)2 << FUN_DRV_S);//what are the drivers? pinFunction |= ((uint32_t)2 << FUN_DRV_S);//what are the drivers?
pinFunction |= FUN_IE;//input enable but required for output as well? pinFunction |= FUN_IE;//input enable but required for output as well?

View File

@ -67,7 +67,7 @@ i2c_err_t i2cAttachSCL(i2c_t * i2c, int8_t scl)
if(i2c == NULL){ if(i2c == NULL){
return I2C_ERROR_DEV; return I2C_ERROR_DEV;
} }
pinMode(scl, OUTPUT_OPEN_DRAIN); pinMode(scl, OUTPUT_OPEN_DRAIN | PULLUP);
pinMatrixOutAttach(scl, I2C_SCL_IDX(i2c->num), false, false); pinMatrixOutAttach(scl, I2C_SCL_IDX(i2c->num), false, false);
pinMatrixInAttach(scl, I2C_SCL_IDX(i2c->num), false); pinMatrixInAttach(scl, I2C_SCL_IDX(i2c->num), false);
return I2C_ERROR_OK; return I2C_ERROR_OK;
@ -89,7 +89,7 @@ i2c_err_t i2cAttachSDA(i2c_t * i2c, int8_t sda)
if(i2c == NULL){ if(i2c == NULL){
return I2C_ERROR_DEV; return I2C_ERROR_DEV;
} }
pinMode(sda, OUTPUT_OPEN_DRAIN); pinMode(sda, OUTPUT_OPEN_DRAIN | PULLUP);
pinMatrixOutAttach(sda, I2C_SDA_IDX(i2c->num), false, false); pinMatrixOutAttach(sda, I2C_SDA_IDX(i2c->num), false, false);
pinMatrixInAttach(sda, I2C_SDA_IDX(i2c->num), false); pinMatrixInAttach(sda, I2C_SDA_IDX(i2c->num), false);
return I2C_ERROR_OK; return I2C_ERROR_OK;