forked from mirror/qmk_firmware
Testing
This commit is contained in:
@@ -62,7 +62,7 @@ static pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
|
||||
|
||||
/* matrix state(1:on, 0:off) */
|
||||
static matrix_row_t raw_matrix[MATRIX_ROWS]; //raw values
|
||||
static matrix_row_t matrix[MATRIX_ROWS]; //debounced values //ROWS_PER_HAND?
|
||||
static matrix_row_t matrix[MATRIX_ROWS]; //debounced values
|
||||
|
||||
__attribute__ ((weak))
|
||||
void matrix_init_quantum(void) {
|
||||
@@ -181,7 +181,7 @@ static void select_col(uint8_t col) {
|
||||
static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); }
|
||||
|
||||
static void unselect_cols(void) {
|
||||
for (uint8_t x = 0; x < MATRIX_COLS / 2 ; x++) {
|
||||
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
|
||||
setPinInputHigh(col_pins[x]);
|
||||
}
|
||||
}
|
||||
@@ -191,6 +191,7 @@ static void init_pins(void) {
|
||||
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
|
||||
setPinInputHigh(col_pins[x]);
|
||||
}
|
||||
//NOTE rowもcolも同じピンだから、片方やれば十分かな?
|
||||
unselect_cols();
|
||||
for (uint8_t x = 0; x < ROWS_PER_HAND; x++) {
|
||||
setPinInputHigh(row_pins[x]);
|
||||
@@ -212,21 +213,27 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
||||
wait_us(30);
|
||||
|
||||
// For each col...
|
||||
for (uint8_t col_index = 0; col_index < MATRIX_COLS / 2; col_index++) {
|
||||
uint8_t matrix_index = 0;
|
||||
for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
|
||||
// // Select the col pin to read (active low)
|
||||
// uint8_t pin_state = readPin(col_pins[col_index]);
|
||||
//
|
||||
// // Populate the matrix row with the state of the col pin
|
||||
// current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
|
||||
|
||||
// Check col pin pin_state
|
||||
if (readPin(col_pins[col_index]) == 0) {
|
||||
// Pin LO, set col bit
|
||||
current_matrix[current_row] |= (ROW_SHIFTER << col_index);
|
||||
} else {
|
||||
// Pin HI, clear col bit
|
||||
current_matrix[current_row] &= ~(ROW_SHIFTER << col_index);
|
||||
// rowと同じインデックスのcol(=同じピン)は読まない
|
||||
if (col_index != current_row) {
|
||||
// Check col pin pin_state
|
||||
if (readPin(col_pins[col_index]) == 0) {
|
||||
// Pin LO, set col bit
|
||||
current_matrix[current_row] |= (ROW_SHIFTER << matrix_index);
|
||||
} else {
|
||||
// Pin HI, clear col bit
|
||||
current_matrix[current_row] &= ~(ROW_SHIFTER << matrix_index);
|
||||
}
|
||||
}
|
||||
|
||||
matrix_index++;
|
||||
}
|
||||
|
||||
// Unselect row
|
||||
@@ -246,23 +253,28 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
|
||||
wait_us(30);
|
||||
|
||||
// For each row...
|
||||
uint8_t matrix_index = 0;
|
||||
for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) {
|
||||
// Store last value of row prior to reading
|
||||
matrix_row_t last_row_value = current_matrix[row_index];
|
||||
|
||||
// Check row pin state
|
||||
if (readPin(row_pins[row_index]) == 0) {
|
||||
// Pin LO, set col bit
|
||||
current_matrix[row_index] |= (ROW_SHIFTER << (current_col + MATRIX_COLS / 2));
|
||||
} else {
|
||||
// Pin HI, clear col bit
|
||||
current_matrix[row_index] &= ~(ROW_SHIFTER << (current_col + MATRIX_COLS / 2));
|
||||
}
|
||||
if (row_index != current_col) {
|
||||
// Check row pin state
|
||||
if (readPin(row_pins[row_index]) == 0) {
|
||||
// Pin LO, set col bit
|
||||
current_matrix[row_index] |= (ROW_SHIFTER << (current_col + MATRIX_COLS / 2));
|
||||
} else {
|
||||
// Pin HI, clear col bit
|
||||
current_matrix[row_index] &= ~(ROW_SHIFTER << (current_col + MATRIX_COLS / 2));
|
||||
}
|
||||
// dprintf("\nRoC %d\n", current_matrix[row_index]);
|
||||
// Determine if the matrix changed state
|
||||
if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) {
|
||||
matrix_changed = true;
|
||||
if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) {
|
||||
matrix_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
matrix_index++;
|
||||
}
|
||||
|
||||
// Unselect col
|
||||
@@ -354,7 +366,7 @@ uint8_t matrix_scan(void) {
|
||||
changed |= read_cols_on_row(raw_matrix, current_row);
|
||||
}
|
||||
// Set col, read rows
|
||||
for (uint8_t current_col = 0; current_col < MATRIX_COLS / 2; current_col++) {
|
||||
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
|
||||
changed |= read_rows_on_col(raw_matrix, current_col);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user