summaryrefslogtreecommitdiffstats
path: root/keyboards/keychron/q8_pro/matrix.c
diff options
context:
space:
mode:
authorlalalademaxiya1 <2831039915@qq.com>2023-06-30 09:50:52 +0800
committerlalalademaxiya1 <2831039915@qq.com>2023-06-30 09:50:52 +0800
commitf877082a650896cb62a51f8d682d033a27c2a879 (patch)
tree93994c33eb52957502ccf2c9ad27350cbfebbde8 /keyboards/keychron/q8_pro/matrix.c
parentd90608debfbe0f7f11d020dbbaf515448f530078 (diff)
Updated q8 pro
Diffstat (limited to 'keyboards/keychron/q8_pro/matrix.c')
-rw-r--r--keyboards/keychron/q8_pro/matrix.c100
1 files changed, 72 insertions, 28 deletions
diff --git a/keyboards/keychron/q8_pro/matrix.c b/keyboards/keychron/q8_pro/matrix.c
index 663dae5ff9..4f39280e95 100644
--- a/keyboards/keychron/q8_pro/matrix.c
+++ b/keyboards/keychron/q8_pro/matrix.c
@@ -38,10 +38,9 @@ static inline void setPinOutput_writeLow(pin_t pin) {
writePinLow(pin);
}
-static inline void HC595_initPin(void) {
- setPinOutput(HC595_DS);
- setPinOutput(HC595_STCP);
- setPinOutput(HC595_SHCP);
+static inline void setPinOutput_writeHigh(pin_t pin) {
+ setPinOutput(pin);
+ writePinHigh(pin);
}
static inline void HC595_delay(uint16_t n) {
@@ -50,11 +49,12 @@ static inline void HC595_delay(uint16_t n) {
}
}
-static void HC595_output(uint16_t data, bool bit) {
- uint8_t n = 1;
+static void HC595_output(uint16_t data) {
uint8_t i;
+ uint8_t n = 1;
- for (i = 1; i < 16; i++) {
+ for (i = 1; i < (MATRIX_COLS - DIRECT_COL_NUM); i++) {
+ writePinLow(HC595_SHCP);
if (data & 0x1) {
writePinHigh(HC595_DS);
} else {
@@ -63,43 +63,86 @@ static void HC595_output(uint16_t data, bool bit) {
HC595_delay(n);
writePinHigh(HC595_SHCP);
HC595_delay(n);
- writePinLow(HC595_SHCP);
- if (bit) {
- break;
- } else {
- data >>= 1;
- }
+
+ data = data >> 1;
}
+ writePinLow(HC595_STCP);
+ HC595_delay(n);
writePinHigh(HC595_STCP);
+}
+
+static void HC595_output_bit(uint8_t data) {
+ uint8_t n = 1;
+
+ writePinLow(HC595_SHCP);
+ if (data & 0x1) {
+ writePinHigh(HC595_DS);
+ } else {
+ writePinLow(HC595_DS);
+ }
HC595_delay(n);
+
+ writePinHigh(HC595_SHCP);
+ HC595_delay(n);
+
writePinLow(HC595_STCP);
+ HC595_delay(n);
+ writePinHigh(HC595_STCP);
}
static void select_col(uint8_t col) {
- if (col == DIRECT_COL_NUM) {
- HC595_output(0x0, 1);
- HC595_output(0x1, 1);
+ if (col < DIRECT_COL_NUM) {
+ setPinOutput_writeLow(col_pins[col]);
+ } else {
+ if (col == DIRECT_COL_NUM) {
+ HC595_output_bit(0x00);
+ HC595_output_bit(0x01);
+ }
}
}
-static void unselect_col(void) {
- HC595_output(0x1, 1);
+static void unselect_col(uint8_t col) {
+ if (col < DIRECT_COL_NUM) {
+#ifdef MATRIX_UNSELECT_DRIVE_HIGH
+ setPinOutput_writeHigh(col_pins[col]);
+#else
+ setPinInputHigh(col_pins[col]);
+#endif
+ } else {
+ HC595_output_bit(0x01);
+ }
}
static void unselect_cols(void) {
- HC595_output(0xFFFF, 0);
+ for (uint8_t x = 0; x < MATRIX_COLS; x++) {
+ if (x < DIRECT_COL_NUM) {
+#ifdef MATRIX_UNSELECT_DRIVE_HIGH
+ setPinOutput_writeHigh(col_pins[x]);
+#else
+ setPinInputHigh(col_pins[x]);
+#endif
+ } else {
+ if (x == DIRECT_COL_NUM) HC595_output(0xFFFF);
+ break;
+ }
+ }
}
void select_all_cols(void) {
- HC595_output(0x0, 0);
+ for (uint8_t x = 0; x < MATRIX_COLS; x++) {
+ if (x < DIRECT_COL_NUM) {
+ setPinOutput_writeLow(col_pins[x]);
+ } else {
+ if (x == DIRECT_COL_NUM) HC595_output(0x0000);
+ break;
+ }
+ }
}
static void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col, matrix_row_t row_shifter) {
- bool key_pressed = false;
-
// Select col
- select_col(current_col);
- matrix_output_select_delay();
+ select_col(current_col); // select col
+ HC595_delay(200);
// For each row...
for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) {
@@ -107,7 +150,6 @@ static void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t curre
if (readMatrixPin(row_pins[row_index]) == 0) {
// Pin LO, set col bit
current_matrix[row_index] |= row_shifter;
- key_pressed = true;
} else {
// Pin HI, clear col bit
current_matrix[row_index] &= ~row_shifter;
@@ -115,12 +157,14 @@ static void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t curre
}
// Unselect col
- unselect_col();
- matrix_output_unselect_delay(current_col, key_pressed); // wait for all Row signals to go HIGH
+ unselect_col(current_col);
+ HC595_delay(200); // wait for all Row signals to go HIGH
}
void matrix_init_custom(void) {
- HC595_initPin();
+ setPinOutput(HC595_DS);
+ setPinOutput(HC595_STCP);
+ setPinOutput(HC595_SHCP);
for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
if (row_pins[x] != NO_PIN) {