aboutsummaryrefslogtreecommitdiffstats
path: root/keyboards/ergodox_ez
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2018-06-23 14:18:47 -0400
committerJack Humbert <jack.humb@gmail.com>2018-06-23 14:18:47 -0400
commit7a44ad83fce391c938d18abcc2125e15c1982078 (patch)
tree1c0db8fbaf33aa1cf408ba418cdb3705b526d618 /keyboards/ergodox_ez
parent6380f8319057d33bb6d07c66789867e49c634504 (diff)
downloadfirmware-7a44ad83fce391c938d18abcc2125e15c1982078.tar.gz
firmware-7a44ad83fce391c938d18abcc2125e15c1982078.tar.bz2
firmware-7a44ad83fce391c938d18abcc2125e15c1982078.zip
adds immediate i2c return, fixes ez matrix code
Diffstat (limited to 'keyboards/ergodox_ez')
-rw-r--r--keyboards/ergodox_ez/ergodox_ez.c31
-rw-r--r--keyboards/ergodox_ez/ergodox_ez.h1
-rw-r--r--keyboards/ergodox_ez/matrix.c19
3 files changed, 26 insertions, 25 deletions
diff --git a/keyboards/ergodox_ez/ergodox_ez.c b/keyboards/ergodox_ez/ergodox_ez.c
index 65671b38f..61f910711 100644
--- a/keyboards/ergodox_ez/ergodox_ez.c
+++ b/keyboards/ergodox_ez/ergodox_ez.c
@@ -22,7 +22,6 @@ extern inline void ergodox_right_led_set(uint8_t led, uint8_t n);
extern inline void ergodox_led_all_set(uint8_t n);
-
bool i2c_initialized = 0;
i2c_status_t mcp23018_status = 0x20;
@@ -125,23 +124,23 @@ uint8_t init_mcp23018(void) {
// - unused : input : 1
// - input : input : 1
// - driving : output : 0
- mcp23018_status = i2c_start(I2C_ADDR_WRITE, 0); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(IODIRA, 0); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0b00000000, 0); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0b00111111, 0); if (mcp23018_status) goto out;
- i2c_stop(0);
+ mcp23018_status = i2c_start(I2C_ADDR_WRITE, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(IODIRA, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(0b00000000, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(0b00111111, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ i2c_stop(ERGODOX_EZ_I2C_TIMEOUT);
// set pull-up
// - unused : on : 1
// - input : on : 1
// - driving : off : 0
- mcp23018_status = i2c_start(I2C_ADDR_WRITE, 0); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(GPPUA, 0); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0b00000000, 0); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0b00111111, 0); 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(GPPUA, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(0b00000000, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(0b00111111, ERGODOX_EZ_I2C_TIMEOUT); if (mcp23018_status) goto out;
out:
- i2c_stop(0);
+ i2c_stop(ERGODOX_EZ_I2C_TIMEOUT);
#ifdef LEFT_LEDS
if (!mcp23018_status) mcp23018_status = ergodox_left_leds_update();
@@ -165,22 +164,22 @@ uint8_t ergodox_left_leds_update(void) {
// - unused : hi-Z : 1
// - input : hi-Z : 1
// - driving : hi-Z : 1
- mcp23018_status = i2c_start(I2C_ADDR_WRITE, 0);
+ mcp23018_status = i2c_start(I2C_ADDR_WRITE, ERGODOX_EZ_I2C_TIMEOUT);
if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(OLATA, 0);
+ mcp23018_status = i2c_write(OLATA, ERGODOX_EZ_I2C_TIMEOUT);
if (mcp23018_status) goto out;
mcp23018_status = i2c_write(0b11111111
& ~(ergodox_left_led_3<<LEFT_LED_3_SHIFT),
- 0);
+ ERGODOX_EZ_I2C_TIMEOUT);
if (mcp23018_status) goto out;
mcp23018_status = i2c_write(0b11111111
& ~(ergodox_left_led_2<<LEFT_LED_2_SHIFT)
& ~(ergodox_left_led_1<<LEFT_LED_1_SHIFT),
- 0);
+ ERGODOX_EZ_I2C_TIMEOUT);
if (mcp23018_status) goto out;
out:
- i2c_stop(0);
+ i2c_stop(ERGODOX_EZ_I2C_TIMEOUT);
return mcp23018_status;
}
#endif
diff --git a/keyboards/ergodox_ez/ergodox_ez.h b/keyboards/ergodox_ez/ergodox_ez.h
index 9086db2fb..641030495 100644
--- a/keyboards/ergodox_ez/ergodox_ez.h
+++ b/keyboards/ergodox_ez/ergodox_ez.h
@@ -24,6 +24,7 @@
#define OLATB 0x15
extern i2c_status_t mcp23018_status;
+#define ERGODOX_EZ_I2C_TIMEOUT 100
void init_ergodox(void);
void ergodox_blink_all_leds(void);
diff --git a/keyboards/ergodox_ez/matrix.c b/keyboards/ergodox_ez/matrix.c
index d8b708a16..2e95c83b6 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<<row), 0); 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(0);
+ i2c_stop(ERGODOX_EZ_I2C_TIMEOUT);
}
} else {
// select on teensy