Skip to content

Commit e88356b

Browse files
committed
fix pcf8574 set method
1 parent de68d26 commit e88356b

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

firmware-src/sources/devices/pcf8574.c

+14-13
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ DHI2C_STATUS ICACHE_FLASH_ATTR pcf8574_read(int sda, int scl, unsigned int *pins
3535
}
3636

3737
DHI2C_STATUS ICACHE_FLASH_ATTR pcf8574_write(int sda, int scl, unsigned int pins_to_set, unsigned int pins_to_clear) {
38-
char buf;
39-
DHI2C_STATUS status;
40-
unsigned int current_state;
41-
if((status = pcf8574_read(sda, scl, &current_state)) != DHI2C_OK) {
42-
return status;
43-
}
44-
buf = (char)(((current_state | pins_to_set) ^ pins_to_clear) & PCF8574_SUITABLE_PINS);
45-
if((status = dhi2c_write(mAddress, &buf, 1, 1)) != DHI2C_OK) {
46-
dhdebug("pcf8574: failed to write");
47-
return status;
48-
}
49-
50-
return DHI2C_OK;
38+
char buf;
39+
DHI2C_STATUS status;
40+
unsigned int current_state;
41+
if(pins_to_set & pins_to_clear)
42+
return DHI2C_WRONG_PARAMETERS;
43+
if((status = pcf8574_read(sda, scl, &current_state)) != DHI2C_OK) {
44+
return status;
45+
}
46+
buf = (char)((current_state | pins_to_set) & (~pins_to_clear) & PCF8574_SUITABLE_PINS);
47+
if((status = dhi2c_write(mAddress, &buf, 1, 1)) != DHI2C_OK) {
48+
dhdebug("pcf8574: failed to write");
49+
return status;
50+
}
51+
return DHI2C_OK;
5152
}
5253

5354
DHI2C_STATUS ICACHE_FLASH_ATTR pcf8574_set(int sda, int scl, unsigned int pins) {

0 commit comments

Comments
 (0)