X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=keyboards%2Fergodox_ez%2Fmatrix.c;h=d8b708a163ff12f1534bbdc36065449f5c70fdea;hb=6380f8319057d33bb6d07c66789867e49c634504;hp=6660af46a438476431bc9034a6f9bd35dc3380a3;hpb=998ddbb122c9d3e2a77bd4e88c881b225ca0d569;p=qmk_firmware.git diff --git a/keyboards/ergodox_ez/matrix.c b/keyboards/ergodox_ez/matrix.c index 6660af46a..d8b708a16 100644 --- a/keyboards/ergodox_ez/matrix.c +++ b/keyboards/ergodox_ez/matrix.c @@ -68,8 +68,8 @@ static void init_cols(void); static void unselect_rows(void); static void select_row(uint8_t row); -// static uint8_t mcp23018_reset_loop; -static uint16_t mcp23018_reset_loop; +static uint8_t mcp23018_reset_loop; +// static uint16_t mcp23018_reset_loop; #ifdef DEBUG_MATRIX_SCAN_RATE uint32_t matrix_timer; @@ -176,8 +176,8 @@ void debounce_report(matrix_row_t change, uint8_t row) { uint8_t matrix_scan(void) { if (mcp23018_status) { // if there was an error - // if (++mcp23018_reset_loop == 0) { - if (++mcp23018_reset_loop >= 1300) { + if (++mcp23018_reset_loop == 0) { + // if (++mcp23018_reset_loop >= 1300) { // since mcp23018_reset_loop is 8 bit - we'll try to reset once in 255 matrix scans // this will be approx bit more frequent than once per second print("trying to reset mcp23018\n"); @@ -295,13 +295,13 @@ static matrix_row_t read_cols(uint8_t row) return 0; } else { uint8_t data = 0; - 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_start(I2C_ADDR_READ); if (mcp23018_status) goto out; - data = i2c_read_nack(); - data = ~data; + mcp23018_status = i2c_start(I2C_ADDR_WRITE, 0); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(GPIOB, 0); if (mcp23018_status) goto out; + mcp23018_status = i2c_start(I2C_ADDR_READ, 0); if (mcp23018_status) goto out; + mcp23018_status = i2c_read_nack(0); if (mcp23018_status < 0) goto out; + data = ~((uint8_t)mcp23018_status); out: - i2c_stop(); + i2c_stop(0); return data; } } else { @@ -350,11 +350,11 @@ static void select_row(uint8_t row) } else { // set active row low : 0 // set other rows hi-Z : 1 - 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_write(0xFF & ~(1<