File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -169,6 +169,7 @@ static const _gpio_sequence gpio_deinit_seq[] = {};
169169#endif
170170
171171static const size_t gpio_ports_count = RG_COUNT (gpio_ports );
172+ static uint8_t gpio_output_values [gpio_ports_count ];
172173static uint8_t gpio_address = RG_I2C_GPIO_ADDR ;
173174static bool gpio_initialized = false;
174175
@@ -247,6 +248,7 @@ bool rg_i2c_gpio_write_port(int port, uint8_t value)
247248{
248249 if (port < 0 || port >= gpio_ports_count )
249250 return false;
251+ gpio_output_values [port ] = value ;
250252 return rg_i2c_write_byte (gpio_address , gpio_ports [port ].output_reg , value );
251253}
252254
@@ -262,7 +264,8 @@ int rg_i2c_gpio_get_level(int pin)
262264
263265bool rg_i2c_gpio_set_level (int pin , int level )
264266{
265- int reg = gpio_ports [(pin >> 3 ) % gpio_ports_count ].output_reg , mask = 1 << (pin & 7 );
266- return update_register (reg , mask , level ? mask : 0 );
267+ uint8_t port = (pin >> 3 ) % gpio_ports_count , mask = 1 << (pin & 7 );
268+ uint8_t value = (gpio_output_values [port ] & ~mask ) | (level ? mask : 0 );
269+ return rg_i2c_gpio_write_port (port , value );
267270}
268271#endif
You can’t perform that action at this time.
0 commit comments