Skip to content

Commit 35a93f3

Browse files
authored
Fix i2c timeouts (#401)
* MCP23018: make timeout configurable * Fix i2c timeouts for all boards
1 parent 0be58d4 commit 35a93f3

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

drivers/gpio/mcp23018.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include "debug.h"
88

99
#define SLAVE_TO_ADDR(n) (n << 1)
10-
#define TIMEOUT 100
10+
#ifndef MCP23018_TIMEOUT
11+
# define MCP23018_TIMEOUT 100
12+
#endif // MCP23018_TIMEOUT
1113

1214
enum {
1315
CMD_IODIRA = 0x00, // i/o direction register
@@ -33,13 +35,13 @@ bool mcp23018_set_config(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf)
3335
uint8_t cmdDirection = port ? CMD_IODIRB : CMD_IODIRA;
3436
uint8_t cmdPullup = port ? CMD_GPPUB : CMD_GPPUA;
3537

36-
i2c_status_t ret = i2c_write_register(addr, cmdDirection, &conf, sizeof(conf), TIMEOUT);
38+
i2c_status_t ret = i2c_write_register(addr, cmdDirection, &conf, sizeof(conf), MCP23018_TIMEOUT);
3739
if (ret != I2C_STATUS_SUCCESS) {
3840
dprintf("mcp23018_set_config::directionFAILED::%u\n", ret);
3941
return false;
4042
}
4143

42-
ret = i2c_write_register(addr, cmdPullup, &conf, sizeof(conf), TIMEOUT);
44+
ret = i2c_write_register(addr, cmdPullup, &conf, sizeof(conf), MCP23018_TIMEOUT);
4345
if (ret != I2C_STATUS_SUCCESS) {
4446
dprintf("mcp23018_set_config::pullupFAILED::%u\n", ret);
4547
return false;
@@ -52,7 +54,7 @@ bool mcp23018_set_output(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf)
5254
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
5355
uint8_t cmd = port ? CMD_GPIOB : CMD_GPIOA;
5456

55-
i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
57+
i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), MCP23018_TIMEOUT);
5658
if (ret != I2C_STATUS_SUCCESS) {
5759
dprintf("mcp23018_set_output::FAILED::%u\n", ret);
5860
return false;
@@ -65,7 +67,7 @@ bool mcp23018_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB) {
6567
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
6668
uint8_t conf[2] = {confA, confB};
6769

68-
i2c_status_t ret = i2c_write_register(addr, CMD_GPIOA, &conf[0], sizeof(conf), TIMEOUT);
70+
i2c_status_t ret = i2c_write_register(addr, CMD_GPIOA, &conf[0], sizeof(conf), MCP23018_TIMEOUT);
6971
if (ret != I2C_STATUS_SUCCESS) {
7072
dprintf("mcp23018_set_output::FAILED::%u\n", ret);
7173
return false;
@@ -78,7 +80,7 @@ bool mcp23018_read_pins(uint8_t slave_addr, mcp23018_port_t port, uint8_t* out)
7880
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
7981
uint8_t cmd = port ? CMD_GPIOB : CMD_GPIOA;
8082

81-
i2c_status_t ret = i2c_read_register(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
83+
i2c_status_t ret = i2c_read_register(addr, cmd, out, sizeof(uint8_t), MCP23018_TIMEOUT);
8284
if (ret != I2C_STATUS_SUCCESS) {
8385
dprintf("mcp23018_read_pins::FAILED::%u\n", ret);
8486
return false;
@@ -97,7 +99,7 @@ bool mcp23018_read_pins_all(uint8_t slave_addr, uint16_t* out) {
9799

98100
data16 data = {.u16 = 0};
99101

100-
i2c_status_t ret = i2c_read_register(addr, CMD_GPIOA, &data.u8[0], sizeof(data), TIMEOUT);
102+
i2c_status_t ret = i2c_read_register(addr, CMD_GPIOA, &data.u8[0], sizeof(data), MCP23018_TIMEOUT);
101103
if (ret != I2C_STATUS_SUCCESS) {
102104
dprintf("mcp23018_read_pins_all::FAILED::%u\n", ret);
103105
return false;

keyboards/zsa/ergodox_ez/ergodox_ez.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3131
extern i2c_status_t mcp23018_status;
3232

3333
#ifndef ERGODOX_EZ_I2C_TIMEOUT
34-
# define ERGODOX_EZ_I2C_TIMEOUT 80
34+
# define ERGODOX_EZ_I2C_TIMEOUT 10
3535
#endif
3636
#ifndef MCP23018_EXPANDER_I2C_ADDR
3737
# define MCP23018_EXPANDER_I2C_ADDR (0x20 << 1)

keyboards/zsa/ergodox_ez/post_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4040
#endif
4141
#define WS2812_LED_COUNT RGBLIGHT_LED_COUNT
4242

43-
#ifndef ISSI_TIMEOUT
44-
# define ISSI_TIMEOUT 3
43+
#ifndef IS31FL3731_I2C_TIMEOUT
44+
# define IS31FL3731_I2C_TIMEOUT 3
4545
#endif

keyboards/zsa/moonlander/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#define MATRIX_ROWS 12
2323
#define MATRIX_COLS 7
2424

25+
#define MCP23018_TIMEOUT 10
26+
27+
2528
#define EEPROM_I2C_24LC128
2629

2730
#define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND

keyboards/zsa/planck_ez/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
#define AUDIO_PIN_ALT_AS_NEGATIVE
2525

2626
#define IS31FL3737_I2C_ADDRESS_1 IS31FL3737_I2C_ADDRESS_GND
27+
#define IS31FL3737_I2C_TIMEOUT 5

keyboards/zsa/voyager/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#define MATRIX_COLS 7
88
#define MATRIX_ROWS 12
99

10+
#define MCP23018_TIMEOUT 10
11+
1012
#define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND
1113
#define IS31FL3731_I2C_ADDRESS_2 IS31FL3731_I2C_ADDRESS_VCC
1214

0 commit comments

Comments
 (0)