Skip to content

Commit 6b65489

Browse files
committed
Fix TCA9554 power on relay toggle
1 parent 5951ea6 commit 6b65489

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

CODE_OWNERS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ In addition to @arendst the following code is mainly owned by:
8080
| xdrv_66_tm1638 | @arendst
8181
| xdrv_67_mcp23xxx | @arendst
8282
| xdrv_68_zerocrossDimmer | @stefanbode
83-
| xdrv_69_pca9557 | @cctweaker
83+
| xdrv_69_pca9557 | @cctweaker, @arendst
8484
| xdrv_70_1_hdmi_cec | @s-hadinger
8585
| xdrv_71_magic_switch | @barbudor
8686
| xdrv_72_pipsolar | @chefpro

tasmota/tasmota_xdrv_driver/xdrv_69_pca9557.ino

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
xdrv_69_pca9557.ino - PCA9557 or TCA9554 GPIO Expander support for Tasmota
33
4-
SPDX-FileCopyrightText: 2023 Theo Arends
4+
SPDX-FileCopyrightText: 2023 @cctweaker and Theo Arends
55
66
SPDX-License-Identifier: GPL-3.0-only
77
*/
@@ -390,31 +390,35 @@ void PCA9557ModuleInit(void) {
390390
return;
391391
}
392392

393+
uint8_t pca9557_address = PCA9557_ADDR_START;
394+
while ((Pca9557.max_devices < PCA9557_MAX_DEVICES) && (pca9557_address < PCA9557_ADDR_END)) {
395+
Pca9557.chip = Pca9557.max_devices;
396+
if (I2cSetDevice(pca9557_address)) {
397+
Pca9557.device[Pca9557.chip].address = pca9557_address;
393398

394-
uint8_t pca9557_address = PCA9557_ADDR_START;
395-
while ((Pca9557.max_devices < PCA9557_MAX_DEVICES) && (pca9557_address < PCA9557_ADDR_END)) {
396-
Pca9557.chip = Pca9557.max_devices;
397-
if (I2cSetDevice(pca9557_address)) {
398-
Pca9557.device[Pca9557.chip].address = pca9557_address;
399-
400-
uint8_t buffer;
401-
if (PCA9557ValidRead(PCA9557_R2, &buffer)) {
402-
I2cSetActiveFound(pca9557_address, PCA9557_NAME);
403-
Pca9557.device[Pca9557.chip].pins = 8;
404-
PCA9557Write(PCA9557_R2, 0b00000000); // disable polarity inversion
405-
Pca9557.max_devices++;
406-
407-
Pca9557.max_pins += Pca9557.device[Pca9557.chip].pins;
408-
pins_needed -= Pca9557.device[Pca9557.chip].pins;
399+
uint8_t buffer;
400+
if (PCA9557ValidRead(PCA9557_R2, &buffer)) {
401+
I2cSetActiveFound(pca9557_address, PCA9557_NAME);
402+
Pca9557.device[Pca9557.chip].pins = 8;
403+
#ifdef USE_TCA9554
404+
if (ResetReasonPowerOn()) { // Fix power on relay toggle
405+
PCA9557Write(PCA9557_R1, 0x00); // Output state (TCA9554 power on is 0xFF, PCA9557 is 0x00)
406+
// PCA9557Write(PCA9557_R3, 0x00); // Config direction as output
409407
}
410-
}
411-
if (pins_needed) {
412-
pca9557_address++;
413-
} else {
414-
pca9557_address = PCA9557_ADDR_END;
408+
#endif // USE_TCA9554
409+
PCA9557Write(PCA9557_R2, 0b00000000); // Disable polarity inversion
410+
Pca9557.max_devices++;
411+
412+
Pca9557.max_pins += Pca9557.device[Pca9557.chip].pins;
413+
pins_needed -= Pca9557.device[Pca9557.chip].pins;
415414
}
416415
}
417-
416+
if (pins_needed) {
417+
pca9557_address++;
418+
} else {
419+
pca9557_address = PCA9557_ADDR_END;
420+
}
421+
}
418422

419423
if (!Pca9557.max_devices) { return; }
420424

@@ -463,10 +467,6 @@ void PCA9557ServiceInput(void) {
463467
}
464468
}
465469

466-
void PCA9557Init(void) {
467-
PCA9557Write(PCA9557_R2, 0b00000000); // disable polarity inversion
468-
}
469-
470470
void PCA9557Power(void) {
471471
// XdrvMailbox.index = 32-bit rpower bit mask
472472
// Use absolute relay indexes unique with main template
@@ -544,9 +544,6 @@ bool Xdrv69(uint32_t function) {
544544
case FUNC_SET_POWER:
545545
PCA9557Power();
546546
break;
547-
case FUNC_INIT:
548-
PCA9557Init();
549-
break;
550547
case FUNC_ADD_BUTTON:
551548
result = PCA9557AddButton();
552549
break;

0 commit comments

Comments
 (0)