diff options
| author | roggan87 <robertrosman@gmx.com> | 2019-06-13 20:47:31 +0200 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-06-13 11:47:31 -0700 |
| commit | 1cd26607bd4bd5bd718e5c1e2e3884fbcdf50f5d (patch) | |
| tree | 319906a25c658ab577459df7a66bffaca8fac48a | |
| parent | 03ce37052f16bd5fca00e3196a8e22ae1acee9bd (diff) | |
| download | qmk_firmware-1cd26607bd4bd5bd718e5c1e2e3884fbcdf50f5d.tar.gz qmk_firmware-1cd26607bd4bd5bd718e5c1e2e3884fbcdf50f5d.zip | |
[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
| -rw-r--r-- | keyboards/handwired/dactyl/config.h | 3 | ||||
| -rw-r--r-- | keyboards/handwired/dactyl/matrix.c | 44 |
2 files changed, 22 insertions, 25 deletions
diff --git a/keyboards/handwired/dactyl/config.h b/keyboards/handwired/dactyl/config.h index 8d42c0ae4..49524c209 100644 --- a/keyboards/handwired/dactyl/config.h +++ b/keyboards/handwired/dactyl/config.h | |||
| @@ -36,7 +36,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 36 | #define COL_EXPANDED { true, true, true, true, true, true, false, false, false, false, false, false} | 36 | #define COL_EXPANDED { true, true, true, true, true, true, false, false, false, false, false, false} |
| 37 | #define MATRIX_ONBOARD_ROW_PINS { F0, F1, F4, F5, F6, F7 } | 37 | #define MATRIX_ONBOARD_ROW_PINS { F0, F1, F4, F5, F6, F7 } |
| 38 | #define MATRIX_ONBOARD_COL_PINS { 0, 0, 0, 0, 0, 0, B1, B2, B3, D2, D3, C6 } | 38 | #define MATRIX_ONBOARD_COL_PINS { 0, 0, 0, 0, 0, 0, B1, B2, B3, D2, D3, C6 } |
| 39 | #define EXPANDER_COL_REGISTER 0 | 39 | #define EXPANDER_COL_REGISTER GPIOA |
| 40 | #define EXPANDER_ROW_REGISTER GPIOB | ||
| 40 | #define MATRIX_EXPANDER_COL_PINS {0, 1, 2, 3, 4, 5} | 41 | #define MATRIX_EXPANDER_COL_PINS {0, 1, 2, 3, 4, 5} |
| 41 | #define MATRIX_EXPANDER_ROW_PINS {0, 1, 2, 3, 4, 5} | 42 | #define MATRIX_EXPANDER_ROW_PINS {0, 1, 2, 3, 4, 5} |
| 42 | 43 | ||
diff --git a/keyboards/handwired/dactyl/matrix.c b/keyboards/handwired/dactyl/matrix.c index 73423bfbd..28cf37522 100644 --- a/keyboards/handwired/dactyl/matrix.c +++ b/keyboards/handwired/dactyl/matrix.c | |||
| @@ -82,10 +82,6 @@ uint32_t matrix_scan_count; | |||
| 82 | #endif | 82 | #endif |
| 83 | 83 | ||
| 84 | #define ROW_SHIFTER ((matrix_row_t)1) | 84 | #define ROW_SHIFTER ((matrix_row_t)1) |
| 85 | #if (DIODE_DIRECTION == COL2ROW) | ||
| 86 | // bitmask to ensure the row state from the expander only applies to its columns | ||
| 87 | #define EXPANDER_MASK ((matrix_row_t)0b00111111) | ||
| 88 | #endif | ||
| 89 | 85 | ||
| 90 | __attribute__ ((weak)) | 86 | __attribute__ ((weak)) |
| 91 | void matrix_init_user(void) {} | 87 | void matrix_init_user(void) {} |
| @@ -166,17 +162,17 @@ void init_expander(void) { | |||
| 166 | 162 | ||
| 167 | /* | 163 | /* |
| 168 | Pin direction and pull-up depends on both the diode direction | 164 | Pin direction and pull-up depends on both the diode direction |
| 169 | and on whether the column register is 0 ("A") or 1 ("B"): | 165 | and on whether the column register is GPIOA or GPIOB |
| 170 | +-------+---------------+---------------+ | 166 | +-------+---------------+---------------+ |
| 171 | | | ROW2COL | COL2ROW | | 167 | | | ROW2COL | COL2ROW | |
| 172 | +-------+---------------+---------------+ | 168 | +-------+---------------+---------------+ |
| 173 | | Reg 0 | input, output | output, input | | 169 | | GPIOA | input, output | output, input | |
| 174 | +-------+---------------+---------------+ | 170 | +-------+---------------+---------------+ |
| 175 | | Reg 1 | output, input | input, output | | 171 | | GPIOB | output, input | input, output | |
| 176 | +-------+---------------+---------------+ | 172 | +-------+---------------+---------------+ |
| 177 | */ | 173 | */ |
| 178 | 174 | ||
| 179 | #if (EXPANDER_COLUMN_REGISTER == 0) | 175 | #if (EXPANDER_COL_REGISTER == GPIOA) |
| 180 | # if (DIODE_DIRECTION == COL2ROW) | 176 | # if (DIODE_DIRECTION == COL2ROW) |
| 181 | expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; | 177 | expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; |
| 182 | expander_status = i2c_write(0); if (expander_status) goto out; | 178 | expander_status = i2c_write(0); if (expander_status) goto out; |
| @@ -184,7 +180,7 @@ void init_expander(void) { | |||
| 184 | expander_status = i2c_write(0); if (expander_status) goto out; | 180 | expander_status = i2c_write(0); if (expander_status) goto out; |
| 185 | expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; | 181 | expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; |
| 186 | # endif | 182 | # endif |
| 187 | #elif (EXPANDER_COLUMN_REGISTER == 1) | 183 | #elif (EXPANDER_COL_REGISTER == GPIOB) |
| 188 | # if (DIODE_DIRECTION == COL2ROW) | 184 | # if (DIODE_DIRECTION == COL2ROW) |
| 189 | expander_status = i2c_write(0); if (expander_status) goto out; | 185 | expander_status = i2c_write(0); if (expander_status) goto out; |
| 190 | expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; | 186 | expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; |
| @@ -202,7 +198,7 @@ void init_expander(void) { | |||
| 202 | // - driving : off : 0 | 198 | // - driving : off : 0 |
| 203 | expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; | 199 | expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; |
| 204 | expander_status = i2c_write(GPPUA); if (expander_status) goto out; | 200 | expander_status = i2c_write(GPPUA); if (expander_status) goto out; |
| 205 | #if (EXPANDER_COLUMN_REGISTER == 0) | 201 | #if (EXPANDER_COL_REGISTER == GPIOA) |
| 206 | # if (DIODE_DIRECTION == COL2ROW) | 202 | # if (DIODE_DIRECTION == COL2ROW) |
| 207 | expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; | 203 | expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; |
| 208 | expander_status = i2c_write(0); if (expander_status) goto out; | 204 | expander_status = i2c_write(0); if (expander_status) goto out; |
| @@ -210,7 +206,7 @@ void init_expander(void) { | |||
| 210 | expander_status = i2c_write(0); if (expander_status) goto out; | 206 | expander_status = i2c_write(0); if (expander_status) goto out; |
| 211 | expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; | 207 | expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; |
| 212 | # endif | 208 | # endif |
| 213 | #elif (EXPANDER_COLUMN_REGISTER == 1) | 209 | #elif (EXPANDER_COL_REGISTER == GPIOB) |
| 214 | # if (DIODE_DIRECTION == COL2ROW) | 210 | # if (DIODE_DIRECTION == COL2ROW) |
| 215 | expander_status = i2c_write(0); if (expander_status) goto out; | 211 | expander_status = i2c_write(0); if (expander_status) goto out; |
| 216 | expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out; | 212 | 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) | |||
| 365 | 361 | ||
| 366 | // Read columns from expander, unless it's in an error state | 362 | // Read columns from expander, unless it's in an error state |
| 367 | if (! expander_status) { | 363 | if (! expander_status) { |
| 368 | expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; | 364 | expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; |
| 369 | expander_status = i2c_write(GPIOA); if (expander_status) goto out; | 365 | expander_status = i2c_write(EXPANDER_COL_REGISTER); if (expander_status) goto out; |
| 370 | expander_status = i2c_start(I2C_ADDR_READ); if (expander_status) goto out; | 366 | expander_status = i2c_start(I2C_ADDR_READ); if (expander_status) goto out; |
| 371 | 367 | ||
| 372 | current_matrix[current_row] |= (~i2c_readNak()) & EXPANDER_MASK; | 368 | current_matrix[current_row] |= (~i2c_readNak()) & expander_input_pin_mask; |
| 373 | 369 | ||
| 374 | out: | 370 | out: |
| 375 | i2c_stop(); | 371 | i2c_stop(); |
| @@ -394,9 +390,9 @@ static void select_row(uint8_t row) { | |||
| 394 | if (! expander_status) { | 390 | if (! expander_status) { |
| 395 | // set active row low : 0 | 391 | // set active row low : 0 |
| 396 | // set other rows hi-Z : 1 | 392 | // set other rows hi-Z : 1 |
| 397 | expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; | 393 | expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; |
| 398 | expander_status = i2c_write(GPIOB); if (expander_status) goto out; | 394 | expander_status = i2c_write(EXPANDER_ROW_REGISTER); if (expander_status) goto out; |
| 399 | expander_status = i2c_write(0xFF & ~(1<<row)); if (expander_status) goto out; | 395 | expander_status = i2c_write(0xFF & ~(1<<row)); if (expander_status) goto out; |
| 400 | out: | 396 | out: |
| 401 | i2c_stop(); | 397 | i2c_stop(); |
| 402 | } | 398 | } |
| @@ -454,9 +450,9 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) | |||
| 454 | return false; | 450 | return false; |
| 455 | } | 451 | } |
| 456 | 452 | ||
| 457 | expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; | 453 | expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; |
| 458 | expander_status = i2c_write(GPIOB); if (expander_status) goto out; | 454 | expander_status = i2c_write(EXPANDER_ROW_REGISTER); if (expander_status) goto out; |
| 459 | expander_status = i2c_start(I2C_ADDR_READ); if (expander_status) goto out; | 455 | expander_status = i2c_start(I2C_ADDR_READ); if (expander_status) goto out; |
| 460 | column_state = i2c_readNak(); | 456 | column_state = i2c_readNak(); |
| 461 | 457 | ||
| 462 | out: | 458 | out: |
| @@ -504,9 +500,9 @@ static void select_col(uint8_t col) | |||
| 504 | } else { | 500 | } else { |
| 505 | // set active col low : 0 | 501 | // set active col low : 0 |
| 506 | // set other cols hi-Z : 1 | 502 | // set other cols hi-Z : 1 |
| 507 | expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; | 503 | expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out; |
| 508 | expander_status = i2c_write(GPIOA); if (expander_status) goto out; | 504 | expander_status = i2c_write(EXPANDER_COL_REGISTER); if (expander_status) goto out; |
| 509 | expander_status = i2c_write(0xFF & ~(1<<col)); if (expander_status) goto out; | 505 | expander_status = i2c_write(0xFF & ~(1<<col)); if (expander_status) goto out; |
| 510 | out: | 506 | out: |
| 511 | i2c_stop(); | 507 | i2c_stop(); |
| 512 | } | 508 | } |
