diff options
Diffstat (limited to 'keyboards/gboards/gergoplex')
-rw-r--r-- | keyboards/gboards/gergoplex/gergoplex.c | 34 | ||||
-rw-r--r-- | keyboards/gboards/gergoplex/gergoplex.h | 4 | ||||
-rw-r--r-- | keyboards/gboards/gergoplex/matrix.c | 28 |
3 files changed, 19 insertions, 47 deletions
diff --git a/keyboards/gboards/gergoplex/gergoplex.c b/keyboards/gboards/gergoplex/gergoplex.c index 1e44583895..b621201c16 100644 --- a/keyboards/gboards/gergoplex/gergoplex.c +++ b/keyboards/gboards/gergoplex/gergoplex.c @@ -39,30 +39,16 @@ uint8_t init_mcp23018(void) { // - unused : input : 1 // - input : input : 1 // - driving : output : 0 - mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); - if (mcp23018_status) goto out; - mcp23018_status = i2c_write(IODIRA, I2C_TIMEOUT); - if (mcp23018_status) goto out; - mcp23018_status = i2c_write(0b11000001, I2C_TIMEOUT); - if (mcp23018_status) goto out; - mcp23018_status = i2c_write(0b11111111, I2C_TIMEOUT); - if (mcp23018_status) goto out; - i2c_stop(); - - // set pull-up - // - unused : on : 1 - // - input : on : 1 - // - driving : off : 0 - mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); - if (mcp23018_status) goto out; - mcp23018_status = i2c_write(GPPUA, I2C_TIMEOUT); - if (mcp23018_status) goto out; - mcp23018_status = i2c_write(0b11000001, I2C_TIMEOUT); - if (mcp23018_status) goto out; - mcp23018_status = i2c_write(0b11111111, I2C_TIMEOUT); - if (mcp23018_status) goto out; + uint8_t data[] = {0b11000001, 0b11111111}; + mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT); + + if (!mcp23018_status) { + // set pull-up + // - unused : on : 1 + // - input : on : 1 + // - driving : off : 0 + mcp23018_status = i2c_writeReg(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT); + } -out: - i2c_stop(); return mcp23018_status; } diff --git a/keyboards/gboards/gergoplex/gergoplex.h b/keyboards/gboards/gergoplex/gergoplex.h index 549228104a..217cb8dff1 100644 --- a/keyboards/gboards/gergoplex/gergoplex.h +++ b/keyboards/gboards/gergoplex/gergoplex.h @@ -25,9 +25,7 @@ extern i2c_status_t mcp23018_status; #define XXX KC_NO // I2C aliases and register addresses (see "mcp23018.md") -#define I2C_ADDR 0x20 // 0b0100000 -#define I2C_ADDR_WRITE ((I2C_ADDR << 1) | I2C_WRITE) -#define I2C_ADDR_READ ((I2C_ADDR << 1) | I2C_READ) +#define I2C_ADDR (0x20 << 1) // 0b0100000 #define IODIRA 0x00 // i/o direction register #define IODIRB 0x01 #define GPPUA 0x0C // GPIO pull-up resistor register diff --git a/keyboards/gboards/gergoplex/matrix.c b/keyboards/gboards/gergoplex/matrix.c index c9f5528b74..9437b24377 100644 --- a/keyboards/gboards/gergoplex/matrix.c +++ b/keyboards/gboards/gergoplex/matrix.c @@ -177,20 +177,12 @@ static matrix_row_t read_cols(uint8_t row) { if (mcp23018_status) { // if there was an error return 0; } else { - uint8_t data = 0; - mcp23018_status = i2c_start(I2C_ADDR_READ, I2C_TIMEOUT); - if (mcp23018_status) goto out; - mcp23018_status = i2c_read_nack(I2C_TIMEOUT); - if (mcp23018_status < 0) goto out; - data = ~((uint8_t)mcp23018_status); - mcp23018_status = I2C_STATUS_SUCCESS; - out: - i2c_stop(); - + uint8_t data = 0; + mcp23018_status = i2c_receive(I2C_ADDR, &data, 1, I2C_TIMEOUT); #ifdef DEBUG_MATRIX - if (data != 0x00) xprintf("I2C: %d\n", data); + if (~data != 0x00) xprintf("I2C: %d\n", ~data); #endif - return data; + return ~data; } } else { return ~((((PINF & COL4) >> 1) | ((PINF & (COL1 | COL2 | COL3)) >> 3)) & 0xF); @@ -213,14 +205,10 @@ static void select_row(uint8_t row) { // select on mcp23018 if (mcp23018_status) { // do nothing on error } else { // set active row low : 0 // set other rows hi-Z : 1 - mcp23018_status = i2c_start(I2C_ADDR_WRITE, I2C_TIMEOUT); - if (mcp23018_status) goto out; - mcp23018_status = i2c_write(GPIOA, I2C_TIMEOUT); - if (mcp23018_status) goto out; - mcp23018_status = i2c_write(0xFF & ~(1 << (row + 1)), I2C_TIMEOUT); - if (mcp23018_status) goto out; - out: - i2c_stop(); + uint8_t data; + data = 0xFF & ~(1 << (row + 1)); + mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT); + } } else { setPinOutput(row_pins[row - MATRIX_ROWS_PER_SIDE]); |