From 4eb018ae73d25f592b23d294117ab7d7ccbd060b Mon Sep 17 00:00:00 2001 From: Erin Call Date: Sun, 25 Mar 2018 15:22:29 -0700 Subject: [PATCH] Only initialize expander_input_mask once [#2065] ...and rename input_mask to expander_input_mask, since now that it isn't scoped to init_expander it isn't clear that it's only for the expander. --- keyboards/handwired/dactyl/dactyl.h | 1 + keyboards/handwired/dactyl/matrix.c | 54 +++++++++++++++-------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/keyboards/handwired/dactyl/dactyl.h b/keyboards/handwired/dactyl/dactyl.h index a994c7ffb33e..3e33930e32a9 100644 --- a/keyboards/handwired/dactyl/dactyl.h +++ b/keyboards/handwired/dactyl/dactyl.h @@ -23,6 +23,7 @@ #define OLATB 0x15 extern uint8_t expander_status; +extern uint8_t expander_input_pin_mask; extern bool i2c_initialized; void init_dactyl(void); diff --git a/keyboards/handwired/dactyl/matrix.c b/keyboards/handwired/dactyl/matrix.c index 49107346b4c8..52c76fadd495 100644 --- a/keyboards/handwired/dactyl/matrix.c +++ b/keyboards/handwired/dactyl/matrix.c @@ -73,6 +73,7 @@ static matrix_row_t matrix_debouncing[MATRIX_ROWS]; static uint8_t expander_reset_loop; uint8_t expander_status; +uint8_t expander_input_pin_mask; bool i2c_initialized = false; #ifdef DEBUG_MATRIX_SCAN_RATE @@ -146,18 +147,19 @@ void init_expander(void) { wait_us(1000000); } - uint8_t input_pin_mask = 0; + if (! expander_input_pin_mask) { #if (DIODE_DIRECTION == COL2ROW) - for (int col = 0; col < MATRIX_COLS; col++) { - if (col_expanded[col]) { - input_pin_mask |= (1 << expander_col_pins[col]); + for (int col = 0; col < MATRIX_COLS; col++) { + if (col_expanded[col]) { + expander_input_pin_mask |= (1 << expander_col_pins[col]); + } } - } #elif (DIODE_DIRECTION == ROW2COL) - for (int row = 0; row < MATRIX_ROWS; row++) { - input_pin_mask |= (1 << expander_row_pins[row]); - } + for (int row = 0; row < MATRIX_ROWS; row++) { + expander_input_pin_mask |= (1 << expander_row_pins[row]); + } #endif + } expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; expander_status = i2c_write(IODIRA); if (expander_status) goto out; @@ -176,19 +178,19 @@ void init_expander(void) { #if (EXPANDER_COLUMN_REGISTER == 0) # if (DIODE_DIRECTION == COL2ROW) - expander_status = i2c_write(input_pin_mask); if (expander_status) goto out; - expander_status = i2c_write(0); if (expander_status) goto out; + expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; + expander_status = i2c_write(0); if (expander_status) goto out; # elif (DIODE_DIRECTION == ROW2COL) - expander_status = i2c_write(0); if (expander_status) goto out; - expander_status = i2c_write(input_pin_mask); if (expander_status) goto out; + 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) # if (DIODE_DIRECTION == COL2ROW) - expander_status = i2c_write(0); if (expander_status) goto out; - expander_status = i2c_write(input_pin_mask); if (expander_status) goto out; + expander_status = i2c_write(0); if (expander_status) goto out; + expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; # elif (DIODE_DIRECTION == ROW2COL) - expander_status = i2c_write(input_pin_mask); if (expander_status) goto out; - expander_status = i2c_write(0); if (expander_status) goto out; + expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; + expander_status = i2c_write(0); if (expander_status) goto out; # endif #endif @@ -198,23 +200,23 @@ void init_expander(void) { // - unused : off : 0 // - input : on : 1 // - 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; + 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 (DIODE_DIRECTION == COL2ROW) - expander_status = i2c_write(input_pin_mask); if (expander_status) goto out; - expander_status = i2c_write(0); if (expander_status) goto out; + expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; + expander_status = i2c_write(0); if (expander_status) goto out; # elif (DIODE_DIRECTION == ROW2COL) - expander_status = i2c_write(0); if (expander_status) goto out; - expander_status = i2c_write(input_pin_mask); if (expander_status) goto out; + 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) # if (DIODE_DIRECTION == COL2ROW) - expander_status = i2c_write(0); if (expander_status) goto out; - expander_status = i2c_write(input_pin_mask); if (expander_status) goto out; + expander_status = i2c_write(0); if (expander_status) goto out; + expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; # elif (DIODE_DIRECTION == ROW2COL) - expander_status = i2c_write(input_pin_mask); if (expander_status) goto out; - expander_status = i2c_write(0); if (expander_status) goto out; + expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; + expander_status = i2c_write(0); if (expander_status) goto out; # endif #endif