diff options
Diffstat (limited to 'keyboards/handwired/dactyl/matrix.c')
-rw-r--r-- | keyboards/handwired/dactyl/matrix.c | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/keyboards/handwired/dactyl/matrix.c b/keyboards/handwired/dactyl/matrix.c index f63cf1188f..28cf37522b 100644 --- a/keyboards/handwired/dactyl/matrix.c +++ b/keyboards/handwired/dactyl/matrix.c @@ -31,11 +31,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /* Set 0 if debouncing isn't needed */ -#ifndef DEBOUNCING_DELAY -# define DEBOUNCING_DELAY 5 +#ifndef DEBOUNCE +# define DEBOUNCE 5 #endif -#if (DEBOUNCING_DELAY > 0) +#if (DEBOUNCE > 0) static uint16_t debouncing_time; static bool debouncing = false; #endif @@ -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; @@ -256,7 +252,7 @@ uint8_t matrix_scan(void) #if (DIODE_DIRECTION == COL2ROW) for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { -# if (DEBOUNCING_DELAY > 0) +# if (DEBOUNCE > 0) bool matrix_changed = read_cols_on_row(matrix_debouncing, current_row); if (matrix_changed) { @@ -270,7 +266,7 @@ uint8_t matrix_scan(void) #elif (DIODE_DIRECTION == ROW2COL) for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { -# if (DEBOUNCING_DELAY > 0) +# if (DEBOUNCE > 0) bool matrix_changed = read_rows_on_col(matrix_debouncing, current_col); if (matrix_changed) { @@ -284,8 +280,8 @@ uint8_t matrix_scan(void) } #endif -# if (DEBOUNCING_DELAY > 0) - if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) { +# if (DEBOUNCE > 0) + if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCE)) { for (uint8_t i = 0; i < MATRIX_ROWS; i++) { matrix[i] = matrix_debouncing[i]; } @@ -299,7 +295,7 @@ uint8_t matrix_scan(void) bool matrix_is_modified(void) // deprecated and evidently not called. { -#if (DEBOUNCING_DELAY > 0) +#if (DEBOUNCE > 0) if (debouncing) return false; #endif return true; @@ -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<<row)); if (expander_status) goto out; + expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; + expander_status = i2c_write(EXPANDER_ROW_REGISTER); if (expander_status) goto out; + expander_status = i2c_write(0xFF & ~(1<<row)); if (expander_status) goto out; out: i2c_stop(); } @@ -454,9 +450,9 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) return false; } - 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_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_ROW_REGISTER); if (expander_status) goto out; + expander_status = i2c_start(I2C_ADDR_READ); if (expander_status) goto out; column_state = i2c_readNak(); out: @@ -504,9 +500,9 @@ static void select_col(uint8_t col) } else { // set active col low : 0 // set other cols hi-Z : 1 - 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_write(0xFF & ~(1<<col)); 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_write(0xFF & ~(1<<col)); if (expander_status) goto out; out: i2c_stop(); } |