From 682555faac8a67deff5688b956165cd1c39389cb Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 15 May 2018 22:30:58 -0400 Subject: i2c fix --- keyboards/ergodox_ez/matrix.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'keyboards/ergodox_ez/matrix.c') diff --git a/keyboards/ergodox_ez/matrix.c b/keyboards/ergodox_ez/matrix.c index e101711334..2aad997817 100644 --- a/keyboards/ergodox_ez/matrix.c +++ b/keyboards/ergodox_ez/matrix.c @@ -34,7 +34,6 @@ along with this program. If not, see . #include "util.h" #include "matrix.h" #include QMK_KEYBOARD_H -#include "i2cmaster.h" #ifdef DEBUG_MATRIX_SCAN_RATE #include "timer.h" #endif @@ -297,7 +296,7 @@ static matrix_row_t read_cols(uint8_t row) 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_readNak(); + data = i2c_read_nack(); data = ~data; out: i2c_stop(); -- cgit v1.2.3 From c0095710a7c7e9bd94aa9f4dd814dc28d718c731 Mon Sep 17 00:00:00 2001 From: Erez Zukerman Date: Thu, 24 May 2018 09:18:36 -0400 Subject: a failed attempt at hot-plugging --- keyboards/ergodox_ez/matrix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'keyboards/ergodox_ez/matrix.c') diff --git a/keyboards/ergodox_ez/matrix.c b/keyboards/ergodox_ez/matrix.c index 2aad997817..6660af46a4 100644 --- a/keyboards/ergodox_ez/matrix.c +++ b/keyboards/ergodox_ez/matrix.c @@ -68,7 +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 uint8_t mcp23018_reset_loop; +static uint16_t mcp23018_reset_loop; #ifdef DEBUG_MATRIX_SCAN_RATE uint32_t matrix_timer; @@ -175,7 +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 == 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"); -- cgit v1.2.3 From b8564f5dd08f49ee0fc6d28957a376132bd7038d Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 12 Jun 2018 14:27:22 -0400 Subject: revert some attempts, update i2c --- keyboards/ergodox_ez/matrix.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'keyboards/ergodox_ez/matrix.c') diff --git a/keyboards/ergodox_ez/matrix.c b/keyboards/ergodox_ez/matrix.c index 6660af46a4..8b117166fb 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"); -- cgit v1.2.3 From 6380f8319057d33bb6d07c66789867e49c634504 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 22 Jun 2018 21:26:30 -0400 Subject: refactor, non-working --- keyboards/ergodox_ez/matrix.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'keyboards/ergodox_ez/matrix.c') diff --git a/keyboards/ergodox_ez/matrix.c b/keyboards/ergodox_ez/matrix.c index 8b117166fb..d8b708a163 100644 --- a/keyboards/ergodox_ez/matrix.c +++ b/keyboards/ergodox_ez/matrix.c @@ -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< Date: Sat, 23 Jun 2018 14:18:47 -0400 Subject: adds immediate i2c return, fixes ez matrix code --- keyboards/ergodox_ez/matrix.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'keyboards/ergodox_ez/matrix.c') diff --git a/keyboards/ergodox_ez/matrix.c b/keyboards/ergodox_ez/matrix.c index d8b708a163..2e95c83b65 100644 --- a/keyboards/ergodox_ez/matrix.c +++ b/keyboards/ergodox_ez/matrix.c @@ -295,13 +295,14 @@ static matrix_row_t read_cols(uint8_t row) return 0; } else { uint8_t data = 0; - 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; + mcp23018_status = i2c_start(I2C_ADDR_WRITE, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(GPIOB, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_start(I2C_ADDR_READ, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out; + mcp23018_status = i2c_read_nack(ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status < 0) goto out; data = ~((uint8_t)mcp23018_status); + mcp23018_status = I2C_STATUS_SUCCESS; out: - i2c_stop(0); + i2c_stop(ERGODOX_EZ_I2C_TIMEOUT); return data; } } else { @@ -350,11 +351,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, 0); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(GPIOA, 0); if (mcp23018_status) goto out; - mcp23018_status = i2c_write(0xFF & ~(1<