@@ -170,7 +170,16 @@ static const _gpio_port gpio_ports[] = {
170170};
171171static const _gpio_sequence gpio_init_seq [] = {};
172172static const _gpio_sequence gpio_deinit_seq [] = {};
173- static rg_gpio_mode_t PCF8575_mode = -1 ;
173+ static rg_gpio_mode_t PCF857x_mode = -1 ;
174+
175+ #elif RG_I2C_GPIO_DRIVER == 5 // PCF8574
176+
177+ static const _gpio_port gpio_ports [] = {
178+ {-1 , -1 , -1 , -1 }, // PORT 0
179+ };
180+ static const _gpio_sequence gpio_init_seq [] = {};
181+ static const _gpio_sequence gpio_deinit_seq [] = {};
182+ static rg_gpio_mode_t PCF857x_mode = -1 ;
174183
175184#else
176185
@@ -240,14 +249,15 @@ bool rg_i2c_gpio_configure_port(int port, uint8_t mask, rg_gpio_mode_t mode)
240249{
241250 if (port < 0 || port >= gpio_ports_count )
242251 return false;
243- #if RG_I2C_GPIO_DRIVER == 4 // PCF8575
244- uint16_t temp = 0xFFFF ;
245- if (mask != 0xFF && mode != PCF8575_mode && (mode == RG_GPIO_OUTPUT || PCF8575_mode == RG_GPIO_OUTPUT ))
246- RG_LOGW ("PCF8575 mode cannot be set by pin. (mask is 0x%02X, expected 0xFF)" , mask );
247- PCF8575_mode = mode ;
252+ #if RG_I2C_GPIO_DRIVER == 4 || RG_I2C_GPIO_DRIVER == 5 // PCF8575/PCF8574
253+ uint32_t temp = 0xFFFFFFFF ;
254+ if (mask != 0xFF && mode != PCF857x_mode && (mode == RG_GPIO_OUTPUT || PCF857x_mode == RG_GPIO_OUTPUT ))
255+ RG_LOGW ("PCF857x mode cannot be set by pin. (mask is 0x%02X, expected 0xFF)" , mask );
256+ PCF857x_mode = mode ;
248257 if (mode != RG_GPIO_OUTPUT )
249- return rg_i2c_write (gpio_address , -1 , & temp , 2 ) && rg_i2c_read (gpio_address , -1 , & temp , 2 );
250- return rg_i2c_write (gpio_address , -1 , & gpio_output_values , 2 );
258+ return rg_i2c_write (gpio_address , -1 , & temp , gpio_ports_count )
259+ && rg_i2c_read (gpio_address , -1 , & temp , gpio_ports_count );
260+ return rg_i2c_write (gpio_address , -1 , & gpio_output_values , gpio_ports_count );
251261#else
252262 int direction_reg = gpio_ports [port ].direction_reg ;
253263 int pullup_reg = gpio_ports [port ].pullup_reg ;
@@ -261,9 +271,9 @@ int rg_i2c_gpio_read_port(int port)
261271{
262272 if (port < 0 || port >= gpio_ports_count )
263273 return -1 ;
264- #if RG_I2C_GPIO_DRIVER == 4 // PCF8575
265- uint8_t values [2 ];
266- return rg_i2c_read (gpio_address , -1 , & values , 2 ) ? values [port & 1 ] : -1 ;
274+ #if RG_I2C_GPIO_DRIVER == 4 || RG_I2C_GPIO_DRIVER == 5 // PCF8575/PCF8574
275+ uint8_t values [gpio_ports_count ];
276+ return rg_i2c_read (gpio_address , -1 , & values , gpio_ports_count ) ? values [port ] : -1 ;
267277#else
268278 return rg_i2c_read_byte (gpio_address , gpio_ports [port ].input_reg );
269279#endif
@@ -274,10 +284,10 @@ bool rg_i2c_gpio_write_port(int port, uint8_t value)
274284 if (port < 0 || port >= gpio_ports_count )
275285 return false;
276286 gpio_output_values [port ] = value ;
277- #if RG_I2C_GPIO_DRIVER == 4 // PCF8575
278- if (PCF8575_mode != RG_GPIO_OUTPUT )
287+ #if RG_I2C_GPIO_DRIVER == 4 || RG_I2C_GPIO_DRIVER == 5 // PCF8575/PCF8574
288+ if (PCF857x_mode != RG_GPIO_OUTPUT )
279289 return true; // This is consistent with other extenders, where the output latch is updated even in input mode
280- return rg_i2c_write (gpio_address , -1 , & gpio_output_values , 2 );
290+ return rg_i2c_write (gpio_address , -1 , & gpio_output_values , gpio_ports_count );
281291#else
282292 return rg_i2c_write_byte (gpio_address , gpio_ports [port ].output_reg , value );
283293#endif
0 commit comments