Fix TCA9554 power on relay toggle
This commit is contained in:
parent
5951ea63e4
commit
6b65489b1f
@ -80,7 +80,7 @@ In addition to @arendst the following code is mainly owned by:
|
|||||||
| xdrv_66_tm1638 | @arendst
|
| xdrv_66_tm1638 | @arendst
|
||||||
| xdrv_67_mcp23xxx | @arendst
|
| xdrv_67_mcp23xxx | @arendst
|
||||||
| xdrv_68_zerocrossDimmer | @stefanbode
|
| xdrv_68_zerocrossDimmer | @stefanbode
|
||||||
| xdrv_69_pca9557 | @cctweaker
|
| xdrv_69_pca9557 | @cctweaker, @arendst
|
||||||
| xdrv_70_1_hdmi_cec | @s-hadinger
|
| xdrv_70_1_hdmi_cec | @s-hadinger
|
||||||
| xdrv_71_magic_switch | @barbudor
|
| xdrv_71_magic_switch | @barbudor
|
||||||
| xdrv_72_pipsolar | @chefpro
|
| xdrv_72_pipsolar | @chefpro
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
xdrv_69_pca9557.ino - PCA9557 or TCA9554 GPIO Expander support for Tasmota
|
xdrv_69_pca9557.ino - PCA9557 or TCA9554 GPIO Expander support for Tasmota
|
||||||
|
|
||||||
SPDX-FileCopyrightText: 2023 Theo Arends
|
SPDX-FileCopyrightText: 2023 @cctweaker and Theo Arends
|
||||||
|
|
||||||
SPDX-License-Identifier: GPL-3.0-only
|
SPDX-License-Identifier: GPL-3.0-only
|
||||||
*/
|
*/
|
||||||
@ -390,31 +390,35 @@ void PCA9557ModuleInit(void) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t pca9557_address = PCA9557_ADDR_START;
|
||||||
|
while ((Pca9557.max_devices < PCA9557_MAX_DEVICES) && (pca9557_address < PCA9557_ADDR_END)) {
|
||||||
|
Pca9557.chip = Pca9557.max_devices;
|
||||||
|
if (I2cSetDevice(pca9557_address)) {
|
||||||
|
Pca9557.device[Pca9557.chip].address = pca9557_address;
|
||||||
|
|
||||||
uint8_t pca9557_address = PCA9557_ADDR_START;
|
uint8_t buffer;
|
||||||
while ((Pca9557.max_devices < PCA9557_MAX_DEVICES) && (pca9557_address < PCA9557_ADDR_END)) {
|
if (PCA9557ValidRead(PCA9557_R2, &buffer)) {
|
||||||
Pca9557.chip = Pca9557.max_devices;
|
I2cSetActiveFound(pca9557_address, PCA9557_NAME);
|
||||||
if (I2cSetDevice(pca9557_address)) {
|
Pca9557.device[Pca9557.chip].pins = 8;
|
||||||
Pca9557.device[Pca9557.chip].address = pca9557_address;
|
#ifdef USE_TCA9554
|
||||||
|
if (ResetReasonPowerOn()) { // Fix power on relay toggle
|
||||||
uint8_t buffer;
|
PCA9557Write(PCA9557_R1, 0x00); // Output state (TCA9554 power on is 0xFF, PCA9557 is 0x00)
|
||||||
if (PCA9557ValidRead(PCA9557_R2, &buffer)) {
|
// PCA9557Write(PCA9557_R3, 0x00); // Config direction as output
|
||||||
I2cSetActiveFound(pca9557_address, PCA9557_NAME);
|
|
||||||
Pca9557.device[Pca9557.chip].pins = 8;
|
|
||||||
PCA9557Write(PCA9557_R2, 0b00000000); // disable polarity inversion
|
|
||||||
Pca9557.max_devices++;
|
|
||||||
|
|
||||||
Pca9557.max_pins += Pca9557.device[Pca9557.chip].pins;
|
|
||||||
pins_needed -= Pca9557.device[Pca9557.chip].pins;
|
|
||||||
}
|
}
|
||||||
}
|
#endif // USE_TCA9554
|
||||||
if (pins_needed) {
|
PCA9557Write(PCA9557_R2, 0b00000000); // Disable polarity inversion
|
||||||
pca9557_address++;
|
Pca9557.max_devices++;
|
||||||
} else {
|
|
||||||
pca9557_address = PCA9557_ADDR_END;
|
Pca9557.max_pins += Pca9557.device[Pca9557.chip].pins;
|
||||||
|
pins_needed -= Pca9557.device[Pca9557.chip].pins;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (pins_needed) {
|
||||||
|
pca9557_address++;
|
||||||
|
} else {
|
||||||
|
pca9557_address = PCA9557_ADDR_END;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!Pca9557.max_devices) { return; }
|
if (!Pca9557.max_devices) { return; }
|
||||||
|
|
||||||
@ -463,10 +467,6 @@ void PCA9557ServiceInput(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PCA9557Init(void) {
|
|
||||||
PCA9557Write(PCA9557_R2, 0b00000000); // disable polarity inversion
|
|
||||||
}
|
|
||||||
|
|
||||||
void PCA9557Power(void) {
|
void PCA9557Power(void) {
|
||||||
// XdrvMailbox.index = 32-bit rpower bit mask
|
// XdrvMailbox.index = 32-bit rpower bit mask
|
||||||
// Use absolute relay indexes unique with main template
|
// Use absolute relay indexes unique with main template
|
||||||
@ -544,9 +544,6 @@ bool Xdrv69(uint32_t function) {
|
|||||||
case FUNC_SET_POWER:
|
case FUNC_SET_POWER:
|
||||||
PCA9557Power();
|
PCA9557Power();
|
||||||
break;
|
break;
|
||||||
case FUNC_INIT:
|
|
||||||
PCA9557Init();
|
|
||||||
break;
|
|
||||||
case FUNC_ADD_BUTTON:
|
case FUNC_ADD_BUTTON:
|
||||||
result = PCA9557AddButton();
|
result = PCA9557AddButton();
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user