|
@@ -30,65 +30,69 @@
|
|
|
|
|
|
|
|
|
static void init_pins(void) {
|
|
|
-
|
|
|
- pca9555_set_config(IC2, PCA9555_PORT0, ALL_INPUT);
|
|
|
- pca9555_set_config(IC2, PCA9555_PORT1, ALL_INPUT);
|
|
|
+
|
|
|
+ pca9555_set_config(IC2, PCA9555_PORT0, ALL_INPUT);
|
|
|
+ pca9555_set_config(IC2, PCA9555_PORT1, ALL_INPUT);
|
|
|
|
|
|
-
|
|
|
- pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT);
|
|
|
+
|
|
|
+ pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT);
|
|
|
+ pca9555_set_output(IC1, PCA9555_PORT0, ALL_LOW);
|
|
|
}
|
|
|
|
|
|
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));
|
|
|
- pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT & (~mask));
|
|
|
+
|
|
|
+
|
|
|
+ uint8_t pin = row;
|
|
|
+ uint8_t mask = 1 << pin;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return ~((state_2 << 8) | state_1);
|
|
|
+
|
|
|
+
|
|
|
+ uint16_t state = pca9555_readAllPins(IC2);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return ~state;
|
|
|
}
|
|
|
|
|
|
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
|
|
|
-
|
|
|
- matrix_row_t last_row_value = current_matrix[current_row];
|
|
|
+
|
|
|
+ matrix_row_t last_row_value = current_matrix[current_row];
|
|
|
|
|
|
-
|
|
|
- current_matrix[current_row] = 0;
|
|
|
+
|
|
|
+ current_matrix[current_row] = 0;
|
|
|
|
|
|
-
|
|
|
- select_row(current_row);
|
|
|
- wait_us(30);
|
|
|
+
|
|
|
+ select_row(current_row);
|
|
|
+
|
|
|
|
|
|
- current_matrix[current_row] = read_cols();
|
|
|
+ current_matrix[current_row] = read_cols();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- return (last_row_value != current_matrix[current_row]);
|
|
|
+ return (last_row_value != current_matrix[current_row]);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void custom_matrix_init(void) {
|
|
|
- pca9555_init(IC1);
|
|
|
- pca9555_init(IC2);
|
|
|
+ pca9555_init(IC1);
|
|
|
+ pca9555_init(IC2);
|
|
|
|
|
|
- init_pins();
|
|
|
+ init_pins();
|
|
|
}
|
|
|
|
|
|
bool custom_matrix_scan(matrix_row_t current_matrix[]) {
|
|
|
- bool changed = false;
|
|
|
- for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
|
|
- changed |= read_cols_on_row(current_matrix, current_row);
|
|
|
- }
|
|
|
- return changed;
|
|
|
-}
|
|
|
+ bool changed = false;
|
|
|
+ for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
|
|
+ changed |= read_cols_on_row(current_matrix, current_row);
|
|
|
+ }
|
|
|
+ return changed;
|
|
|
+}
|