Deallocate interface pins.

This commit is contained in:
Blaz Kristan 2022-08-10 21:23:00 +02:00
parent 1cb3ab82c2
commit ebe9499e97
2 changed files with 8 additions and 0 deletions

View File

@ -276,6 +276,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
Wire.setPins(i2c_sda, i2c_scl); // this will fail if Wire is initilised (Wire.begin() called prior) Wire.setPins(i2c_sda, i2c_scl); // this will fail if Wire is initilised (Wire.begin() called prior)
#endif #endif
Wire.begin(); Wire.begin();
uint8_t i2c[2] = {i2c_sda, i2c_scl};
pinManager.deallocateMultiplePins(i2c, 2, PinOwner::HW_I2C);
} else { } else {
i2c_sda = -1; i2c_sda = -1;
i2c_scl = -1; i2c_scl = -1;
@ -291,6 +293,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
#else #else
SPI.begin(spi_sclk, (int8_t)-1, spi_mosi, spi_cs); SPI.begin(spi_sclk, (int8_t)-1, spi_mosi, spi_cs);
#endif #endif
uint8_t spi[3] = { spi_mosi, spi_sclk, spi_cs };
pinManager.deallocateMultiplePins(spi, 3, PinOwner::HW_SPI);
} else { } else {
spi_mosi = -1; spi_mosi = -1;
spi_sclk = -1; spi_sclk = -1;

View File

@ -495,6 +495,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
i2c_scl = hw_scl_pin; i2c_scl = hw_scl_pin;
#ifdef ESP32 #ifdef ESP32
Wire.setPins(i2c_sda, i2c_scl); // this will fail if Wire is initilised (Wire.begin() called) Wire.setPins(i2c_sda, i2c_scl); // this will fail if Wire is initilised (Wire.begin() called)
uint8_t i2c[2] = {i2c_sda, i2c_scl};
pinManager.deallocateMultiplePins(i2c, 2, PinOwner::HW_I2C);
#endif #endif
} else { } else {
i2c_sda = -1; i2c_sda = -1;
@ -518,6 +520,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
spi_mosi = hw_mosi_pin; spi_mosi = hw_mosi_pin;
spi_sclk = hw_sclk_pin; spi_sclk = hw_sclk_pin;
spi_cs = hw_cs_pin; spi_cs = hw_cs_pin;
uint8_t spi[3] = { hw_mosi_pin, hw_sclk_pin, hw_cs_pin };
pinManager.deallocateMultiplePins(spi, 3, PinOwner::HW_SPI);
} else { } else {
spi_mosi = -1; spi_mosi = -1;
spi_sclk = -1; spi_sclk = -1;