diff options
| author | Joel Challis <git@zvecr.com> | 2019-12-03 19:39:21 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-03 19:39:21 +0000 |
| commit | 1718dfa658dbe8ad144100b561794c5596ac5f08 (patch) | |
| tree | b6252940f7b149efb3fd65bea40b4d353e01e973 | |
| parent | 1c8208ad9a0d1a8cd423aea3ffb0aa5e370e1541 (diff) | |
| download | qmk_firmware-1718dfa658dbe8ad144100b561794c5596ac5f08.tar.gz qmk_firmware-1718dfa658dbe8ad144100b561794c5596ac5f08.zip | |
Increase matrix scanning speed on xd84 (#7517)
* Increase matrix scanning speed
* Fix func name in failure output
| -rw-r--r-- | drivers/gpio/pca9555.c | 17 | ||||
| -rw-r--r-- | drivers/gpio/pca9555.h | 2 | ||||
| -rw-r--r-- | keyboards/xd84/matrix.c | 80 |
3 files changed, 61 insertions, 38 deletions
diff --git a/drivers/gpio/pca9555.c b/drivers/gpio/pca9555.c index 496bbca04..02b5abbdd 100644 --- a/drivers/gpio/pca9555.c +++ b/drivers/gpio/pca9555.c | |||
| @@ -76,3 +76,20 @@ uint8_t pca9555_readPins(uint8_t slave_addr, uint8_t port) { | |||
| 76 | } | 76 | } |
| 77 | return data; | 77 | return data; |
| 78 | } | 78 | } |
| 79 | |||
| 80 | uint16_t pca9555_readAllPins(uint8_t slave_addr) { | ||
| 81 | uint8_t addr = SLAVE_TO_ADDR(slave_addr); | ||
| 82 | |||
| 83 | typedef union { | ||
| 84 | uint8_t u8[2]; | ||
| 85 | uint16_t u16; | ||
| 86 | } data16; | ||
| 87 | |||
| 88 | data16 data; | ||
| 89 | |||
| 90 | i2c_status_t ret = i2c_readReg(addr, CMD_INPUT_0, &data.u8[0], sizeof(data), TIMEOUT); | ||
| 91 | if (ret != I2C_STATUS_SUCCESS) { | ||
| 92 | print("pca9555_readAllPins::FAILED\n"); | ||
| 93 | } | ||
| 94 | return data.u16; | ||
| 95 | } | ||
diff --git a/drivers/gpio/pca9555.h b/drivers/gpio/pca9555.h index ebb97e2f3..3341ec3eb 100644 --- a/drivers/gpio/pca9555.h +++ b/drivers/gpio/pca9555.h | |||
| @@ -53,3 +53,5 @@ void pca9555_set_config(uint8_t slave_addr, uint8_t port, uint8_t conf); | |||
| 53 | void pca9555_set_output(uint8_t slave_addr, uint8_t port, uint8_t conf); | 53 | void pca9555_set_output(uint8_t slave_addr, uint8_t port, uint8_t conf); |
| 54 | 54 | ||
| 55 | uint8_t pca9555_readPins(uint8_t slave_addr, uint8_t port); | 55 | uint8_t pca9555_readPins(uint8_t slave_addr, uint8_t port); |
| 56 | |||
| 57 | uint16_t pca9555_readAllPins(uint8_t slave_addr); | ||
diff --git a/keyboards/xd84/matrix.c b/keyboards/xd84/matrix.c index 4cb5544ca..a4ddbee9a 100644 --- a/keyboards/xd84/matrix.c +++ b/keyboards/xd84/matrix.c | |||
| @@ -30,65 +30,69 @@ | |||
| 30 | //_____Utility funcs___________________________________________________________ | 30 | //_____Utility funcs___________________________________________________________ |
| 31 | 31 | ||
| 32 | static void init_pins(void) { | 32 | static void init_pins(void) { |
| 33 | // init all cols high - IC2 all input | 33 | // init all cols high - IC2 all input |
| 34 | pca9555_set_config(IC2, PCA9555_PORT0, ALL_INPUT);//same as initial state | 34 | pca9555_set_config(IC2, PCA9555_PORT0, ALL_INPUT); // same as initial state |
| 35 | pca9555_set_config(IC2, PCA9555_PORT1, ALL_INPUT);//same as initial state | 35 | pca9555_set_config(IC2, PCA9555_PORT1, ALL_INPUT); // same as initial state |
| 36 | 36 | ||
| 37 | // init all rows - IC1 port0 input | 37 | // init all rows - IC1 port0 input |
| 38 | pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT);//same as initial state | 38 | pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT); // same as initial state |
| 39 | pca9555_set_output(IC1, PCA9555_PORT0, ALL_LOW); | ||
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | static void select_row(uint8_t row) { | 42 | static void select_row(uint8_t row) { |
| 42 | // For the XD84 all rows are on the same IC and port | 43 | // For the XD84 all rows are on the same IC and port |
| 43 | // so its safe enough to assume here row == pin | 44 | // so its safe enough to assume here row == pin |
| 44 | uint8_t pin = row; | 45 | uint8_t pin = row; |
| 45 | uint8_t mask = 1 << pin; | 46 | uint8_t mask = 1 << pin; |
| 46 | 47 | ||
| 47 | pca9555_set_output(IC1, PCA9555_PORT0, ALL_HIGH & (~mask)); | 48 | // we configure output once in init, as pca9555 remembers state when flipping between input/output |
| 48 | pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT & (~mask)); | 49 | // pca9555_set_output(IC1, PCA9555_PORT0, ALL_HIGH & (~mask)); |
| 50 | pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT & (~mask)); | ||
| 49 | } | 51 | } |
| 50 | 52 | ||
| 51 | static uint16_t read_cols(void) { | 53 | static uint16_t read_cols(void) { |
| 52 | uint16_t state_1 = pca9555_readPins(IC2, PCA9555_PORT0); | 54 | // uint16_t state_1 = pca9555_readPins(IC2, PCA9555_PORT0); |
| 53 | uint16_t state_2 = pca9555_readPins(IC2, PCA9555_PORT1); | 55 | // uint16_t state_2 = pca9555_readPins(IC2, PCA9555_PORT1); |
| 54 | 56 | uint16_t state = pca9555_readAllPins(IC2); | |
| 55 | // For the XD84 all cols are on the same IC and mapped sequentially | 57 | |
| 56 | // while this technically gives 16 column reads, | 58 | // For the XD84 all cols are on the same IC and mapped sequentially |
| 57 | // the 16th column can never be set so is safely ignored | 59 | // while this technically gives 16 column reads, |
| 58 | return ~((state_2 << 8) | state_1); | 60 | // the 16th column can never be set so is safely ignored |
| 61 | // return ~((state_2 << 8) | state_1); | ||
| 62 | return ~state; | ||
| 59 | } | 63 | } |
| 60 | 64 | ||
| 61 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | 65 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { |
| 62 | // Store last value of row prior to reading | 66 | // Store last value of row prior to reading |
| 63 | matrix_row_t last_row_value = current_matrix[current_row]; | 67 | matrix_row_t last_row_value = current_matrix[current_row]; |
| 64 | 68 | ||
| 65 | // Clear data in matrix row | 69 | // Clear data in matrix row |
| 66 | current_matrix[current_row] = 0; | 70 | current_matrix[current_row] = 0; |
| 67 | 71 | ||
| 68 | // Select row and wait for row selection to stabilize | 72 | // Select row and wait for row selection to stabilize |
| 69 | select_row(current_row); | 73 | select_row(current_row); |
| 70 | wait_us(30); | 74 | // Skip the wait_us(30); as i2c is slow enough to debounce the io changes |
| 71 | 75 | ||
| 72 | current_matrix[current_row] = read_cols(); | 76 | current_matrix[current_row] = read_cols(); |
| 73 | 77 | ||
| 74 | // No need to Unselect row as the next `select_row` will blank everything | 78 | // No need to Unselect row as the next `select_row` will blank everything |
| 75 | 79 | ||
| 76 | return (last_row_value != current_matrix[current_row]); | 80 | return (last_row_value != current_matrix[current_row]); |
| 77 | } | 81 | } |
| 78 | 82 | ||
| 79 | //_____CUSTOM MATRIX IMPLEMENTATION____________________________________________________ | 83 | //_____CUSTOM MATRIX IMPLEMENTATION____________________________________________________ |
| 80 | 84 | ||
| 81 | void custom_matrix_init(void) { | 85 | void custom_matrix_init(void) { |
| 82 | pca9555_init(IC1); | 86 | pca9555_init(IC1); |
| 83 | pca9555_init(IC2); | 87 | pca9555_init(IC2); |
| 84 | 88 | ||
| 85 | init_pins(); | 89 | init_pins(); |
| 86 | } | 90 | } |
| 87 | 91 | ||
| 88 | bool custom_matrix_scan(matrix_row_t current_matrix[]) { | 92 | bool custom_matrix_scan(matrix_row_t current_matrix[]) { |
| 89 | bool changed = false; | 93 | bool changed = false; |
| 90 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { | 94 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { |
| 91 | changed |= read_cols_on_row(current_matrix, current_row); | 95 | changed |= read_cols_on_row(current_matrix, current_row); |
| 92 | } | 96 | } |
| 93 | return changed; | 97 | return changed; |
| 94 | } \ No newline at end of file | 98 | } |
