|
|
|
@ -36,6 +36,7 @@ static void init_pins(void) { |
|
|
|
|
|
|
|
|
|
// init all rows - IC1 port0 input
|
|
|
|
|
pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT); // same as initial state
|
|
|
|
|
pca9555_set_output(IC1, PCA9555_PORT0, ALL_LOW); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void select_row(uint8_t row) { |
|
|
|
@ -44,18 +45,21 @@ static void select_row(uint8_t row) { |
|
|
|
|
uint8_t pin = row; |
|
|
|
|
uint8_t mask = 1 << pin; |
|
|
|
|
|
|
|
|
|
pca9555_set_output(IC1, PCA9555_PORT0, ALL_HIGH & (~mask)); |
|
|
|
|
// we configure output once in init, as pca9555 remembers state when flipping between input/output
|
|
|
|
|
// pca9555_set_output(IC1, PCA9555_PORT0, ALL_HIGH & (~mask));
|
|
|
|
|
pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT & (~mask)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static uint16_t read_cols(void) { |
|
|
|
|
uint16_t state_1 = pca9555_readPins(IC2, PCA9555_PORT0); |
|
|
|
|
uint16_t state_2 = pca9555_readPins(IC2, PCA9555_PORT1); |
|
|
|
|
// uint16_t state_1 = pca9555_readPins(IC2, PCA9555_PORT0);
|
|
|
|
|
// uint16_t state_2 = pca9555_readPins(IC2, PCA9555_PORT1);
|
|
|
|
|
uint16_t state = pca9555_readAllPins(IC2); |
|
|
|
|
|
|
|
|
|
// For the XD84 all cols are on the same IC and mapped sequentially
|
|
|
|
|
// while this technically gives 16 column reads,
|
|
|
|
|
// the 16th column can never be set so is safely ignored
|
|
|
|
|
return ~((state_2 << 8) | state_1); |
|
|
|
|
// return ~((state_2 << 8) | state_1);
|
|
|
|
|
return ~state; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { |
|
|
|
@ -67,7 +71,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) |
|
|
|
|
|
|
|
|
|
// Select row and wait for row selection to stabilize
|
|
|
|
|
select_row(current_row); |
|
|
|
|
wait_us(30); |
|
|
|
|
// Skip the wait_us(30); as i2c is slow enough to debounce the io changes
|
|
|
|
|
|
|
|
|
|
current_matrix[current_row] = read_cols(); |
|
|
|
|
|
|
|
|
|