1
0
Fork 0

[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
This commit is contained in:
roggan87 2019-06-13 20:47:31 +02:00 committed by Drashna Jaelre
parent 03ce37052f
commit 1cd26607bd
2 changed files with 22 additions and 25 deletions

View file

@ -36,7 +36,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define COL_EXPANDED { true, true, true, true, true, true, false, false, false, false, false, false}
#define MATRIX_ONBOARD_ROW_PINS { F0, F1, F4, F5, F6, F7 }
#define MATRIX_ONBOARD_COL_PINS { 0, 0, 0, 0, 0, 0, B1, B2, B3, D2, D3, C6 }
#define EXPANDER_COL_REGISTER 0
#define EXPANDER_COL_REGISTER GPIOA
#define EXPANDER_ROW_REGISTER GPIOB
#define MATRIX_EXPANDER_COL_PINS {0, 1, 2, 3, 4, 5}
#define MATRIX_EXPANDER_ROW_PINS {0, 1, 2, 3, 4, 5}

View file

@ -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<<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();
}