From e7a5c006d9777a4009da934f408961aa2d2e6fb1 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Tue, 7 Sep 2021 16:34:59 +0100 Subject: Refactor use of legacy i2c implementation (#14341) --- keyboards/sx60/matrix.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'keyboards/sx60/matrix.c') diff --git a/keyboards/sx60/matrix.c b/keyboards/sx60/matrix.c index 6fa0dd1456..b7dc25425d 100644 --- a/keyboards/sx60/matrix.c +++ b/keyboards/sx60/matrix.c @@ -243,15 +243,11 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) /* if there was an error */ return 0; } else { - uint16_t data = 0; - mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(GPIOA); if (mcp23018_status) goto out; - mcp23018_status = i2c_start(I2C_ADDR_READ); if (mcp23018_status) goto out; - data = i2c_readNak(); - data = ~data; - out: - i2c_stop(); - current_matrix[current_row] |= (data << 8); + uint8_t data = 0; + mcp23018_status = i2c_readReg(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT); + if (!mcp23018_status) { + current_matrix[current_row] |= (~((uint16_t)data) << 8); + } } /* For each col... */ @@ -278,11 +274,8 @@ static void select_row(uint8_t row) /* set active row low : 0 set active row output : 1 set other rows hi-Z : 1 */ - mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(GPIOB); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(0xFF & ~(1<