From 1cd26607bd4bd5bd718e5c1e2e3884fbcdf50f5d Mon Sep 17 00:00:00 2001 From: roggan87 Date: Thu, 13 Jun 2019 20:47:31 +0200 Subject: [Keyboard] Made it possible for real to choose register on io expander for cols and rows (#6124) * Replace deprecated EXPANDER_MASK with dynamic expander_pin_input_mask * Made it possible to switch rows and cols registers on expander --- keyboards/handwired/dactyl/matrix.c | 44 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'keyboards/handwired/dactyl/matrix.c') diff --git a/keyboards/handwired/dactyl/matrix.c b/keyboards/handwired/dactyl/matrix.c index 73423bfbdb..28cf37522b 100644 --- a/keyboards/handwired/dactyl/matrix.c +++ b/keyboards/handwired/dactyl/matrix.c @@ -82,10 +82,6 @@ uint32_t matrix_scan_count; #endif #define ROW_SHIFTER ((matrix_row_t)1) -#if (DIODE_DIRECTION == COL2ROW) -// bitmask to ensure the row state from the expander only applies to its columns -#define EXPANDER_MASK ((matrix_row_t)0b00111111) -#endif __attribute__ ((weak)) void matrix_init_user(void) {} @@ -166,17 +162,17 @@ void init_expander(void) { /* Pin direction and pull-up depends on both the diode direction - and on whether the column register is 0 ("A") or 1 ("B"): + and on whether the column register is GPIOA or GPIOB +-------+---------------+---------------+ | | ROW2COL | COL2ROW | +-------+---------------+---------------+ - | Reg 0 | input, output | output, input | + | GPIOA | input, output | output, input | +-------+---------------+---------------+ - | Reg 1 | output, input | input, output | + | GPIOB | output, input | input, output | +-------+---------------+---------------+ */ -#if (EXPANDER_COLUMN_REGISTER == 0) +#if (EXPANDER_COL_REGISTER == GPIOA) # if (DIODE_DIRECTION == COL2ROW) expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; expander_status = i2c_write(0); if (expander_status) goto out; @@ -184,7 +180,7 @@ void init_expander(void) { expander_status = i2c_write(0); if (expander_status) goto out; expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; # endif -#elif (EXPANDER_COLUMN_REGISTER == 1) +#elif (EXPANDER_COL_REGISTER == GPIOB) # if (DIODE_DIRECTION == COL2ROW) expander_status = i2c_write(0); if (expander_status) goto out; expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; @@ -202,7 +198,7 @@ void init_expander(void) { // - driving : off : 0 expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; expander_status = i2c_write(GPPUA); if (expander_status) goto out; -#if (EXPANDER_COLUMN_REGISTER == 0) +#if (EXPANDER_COL_REGISTER == GPIOA) # if (DIODE_DIRECTION == COL2ROW) expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; expander_status = i2c_write(0); if (expander_status) goto out; @@ -210,7 +206,7 @@ void init_expander(void) { expander_status = i2c_write(0); if (expander_status) goto out; expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; # endif -#elif (EXPANDER_COLUMN_REGISTER == 1) +#elif (EXPANDER_COL_REGISTER == GPIOB) # if (DIODE_DIRECTION == COL2ROW) expander_status = i2c_write(0); if (expander_status) goto out; expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; @@ -365,11 +361,11 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) // Read columns from expander, unless it's in an error state if (! expander_status) { - expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; - expander_status = i2c_write(GPIOA); if (expander_status) goto out; - expander_status = i2c_start(I2C_ADDR_READ); if (expander_status) goto out; + expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; + expander_status = i2c_write(EXPANDER_COL_REGISTER); if (expander_status) goto out; + expander_status = i2c_start(I2C_ADDR_READ); if (expander_status) goto out; - current_matrix[current_row] |= (~i2c_readNak()) & EXPANDER_MASK; + current_matrix[current_row] |= (~i2c_readNak()) & expander_input_pin_mask; out: i2c_stop(); @@ -394,9 +390,9 @@ static void select_row(uint8_t row) { if (! expander_status) { // set active row low : 0 // set other rows hi-Z : 1 - expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; - expander_status = i2c_write(GPIOB); if (expander_status) goto out; - expander_status = i2c_write(0xFF & ~(1<