Skip to content

Commit

Permalink
Only initialize expander_input_mask once [qmk#2065]
Browse files Browse the repository at this point in the history
...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.
  • Loading branch information
ErinCall committed Mar 25, 2018
1 parent 6921f48 commit 4eb018a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
1 change: 1 addition & 0 deletions keyboards/handwired/dactyl/dactyl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
54 changes: 28 additions & 26 deletions keyboards/handwired/dactyl/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 4eb018a

Please sign in to comment.