summaryrefslogtreecommitdiff
path: root/keyboards/ergodox_ez/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ergodox_ez/matrix.c')
-rw-r--r--keyboards/ergodox_ez/matrix.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/keyboards/ergodox_ez/matrix.c b/keyboards/ergodox_ez/matrix.c
index e101711334..2e95c83b65 100644
--- a/keyboards/ergodox_ez/matrix.c
+++ b/keyboards/ergodox_ez/matrix.c
@@ -34,7 +34,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "util.h"
#include "matrix.h"
#include QMK_KEYBOARD_H
-#include "i2cmaster.h"
#ifdef DEBUG_MATRIX_SCAN_RATE
#include "timer.h"
#endif
@@ -70,6 +69,7 @@ static void unselect_rows(void);
static void select_row(uint8_t row);
static uint8_t mcp23018_reset_loop;
+// static uint16_t mcp23018_reset_loop;
#ifdef DEBUG_MATRIX_SCAN_RATE
uint32_t matrix_timer;
@@ -177,6 +177,7 @@ uint8_t matrix_scan(void)
{
if (mcp23018_status) { // if there was an error
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");
@@ -294,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); 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 = ~data;
+ 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();
+ i2c_stop(ERGODOX_EZ_I2C_TIMEOUT);
return data;
}
} else {
@@ -349,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); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(GPIOA); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0xFF & ~(1<<row)); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_start(I2C_ADDR_WRITE, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(GPIOA, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(0xFF & ~(1<<row), ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
out:
- i2c_stop();
+ i2c_stop(ERGODOX_EZ_I2C_TIMEOUT);
}
} else {
// select on teensy