diff options
| author | Josh Hinnebusch <joshhinnebusch@gmail.com> | 2020-04-18 21:06:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-18 18:06:28 -0700 |
| commit | f3595f65b7080b3276d956544d86bbb7924adaf0 (patch) | |
| tree | 8be1764027be9504b1deb68c780f92c611d67be2 | |
| parent | 23df763a310d739859e070f67b16018652531615 (diff) | |
| download | qmk_firmware-f3595f65b7080b3276d956544d86bbb7924adaf0.tar.gz qmk_firmware-f3595f65b7080b3276d956544d86bbb7924adaf0.zip | |
[Keyboard] add dual-direction diode capability for hbcp (#8795)
* add dual-direction diode capability
* update per PR requests
Co-authored-by: hineybush <hineybushkeyboards@gmail.com>
| -rw-r--r-- | keyboards/hineybush/hbcp/config.h | 3 | ||||
| -rw-r--r-- | keyboards/hineybush/hbcp/matrix.c | 139 | ||||
| -rw-r--r-- | keyboards/hineybush/hbcp/rules.mk | 2 |
3 files changed, 142 insertions, 2 deletions
diff --git a/keyboards/hineybush/hbcp/config.h b/keyboards/hineybush/hbcp/config.h index 8a5b96ec3..4f3f2a1cd 100644 --- a/keyboards/hineybush/hbcp/config.h +++ b/keyboards/hineybush/hbcp/config.h | |||
| @@ -45,8 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 45 | #define MATRIX_COL_PINS { F0, F1, F2, F3, F4, F5, F6, F7, A0, A1, A2, A3, A4, A5, B5, B4, B3, B2 } | 45 | #define MATRIX_COL_PINS { F0, F1, F2, F3, F4, F5, F6, F7, A0, A1, A2, A3, A4, A5, B5, B4, B3, B2 } |
| 46 | #define UNUSED_PINS | 46 | #define UNUSED_PINS |
| 47 | 47 | ||
| 48 | /* COL2ROW, ROW2COL*/ | 48 | #define DIODE_DIRECTION EITHERWAY |
| 49 | #define DIODE_DIRECTION COL2ROW | ||
| 50 | 49 | ||
| 51 | #define BACKLIGHT_PIN B7 | 50 | #define BACKLIGHT_PIN B7 |
| 52 | #define BACKLIGHT_BREATHING | 51 | #define BACKLIGHT_BREATHING |
diff --git a/keyboards/hineybush/hbcp/matrix.c b/keyboards/hineybush/hbcp/matrix.c new file mode 100644 index 000000000..d493a7e9e --- /dev/null +++ b/keyboards/hineybush/hbcp/matrix.c | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012-2020 Jun Wako, Jack Humbert, Yiancar, Ein Terakawa, Drashna, Josh Hinnebusch | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include <stdint.h> | ||
| 18 | #include <stdbool.h> | ||
| 19 | #include "util.h" | ||
| 20 | #include "matrix.h" | ||
| 21 | #include "debounce.h" | ||
| 22 | #include "quantum.h" | ||
| 23 | |||
| 24 | static const pin_t row_pins[] = MATRIX_ROW_PINS; | ||
| 25 | static const pin_t col_pins[] = MATRIX_COL_PINS; | ||
| 26 | |||
| 27 | /* matrix state(1:on, 0:off) */ | ||
| 28 | static matrix_row_t last_matrix[MATRIX_ROWS]; // raw values of last scan | ||
| 29 | |||
| 30 | // matrix code | ||
| 31 | |||
| 32 | void select_row(uint8_t row) { | ||
| 33 | setPinOutput(row_pins[row]); | ||
| 34 | writePinLow(row_pins[row]); | ||
| 35 | } | ||
| 36 | |||
| 37 | void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); } | ||
| 38 | |||
| 39 | bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | ||
| 40 | // Store last value of row prior to reading | ||
| 41 | matrix_row_t last_row_value = current_matrix[current_row]; | ||
| 42 | |||
| 43 | // Clear data in matrix row | ||
| 44 | current_matrix[current_row] = 0; | ||
| 45 | |||
| 46 | // Select row and wait for row selecton to stabilize | ||
| 47 | select_row(current_row); | ||
| 48 | matrix_io_delay(); | ||
| 49 | |||
| 50 | // For each col... | ||
| 51 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | ||
| 52 | // Select the col pin to read (active low) | ||
| 53 | uint8_t pin_state = readPin(col_pins[col_index]); | ||
| 54 | |||
| 55 | // Populate the matrix row with the state of the col pin | ||
| 56 | current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); | ||
| 57 | } | ||
| 58 | |||
| 59 | // Unselect row | ||
| 60 | unselect_row(current_row); | ||
| 61 | |||
| 62 | return (last_row_value != current_matrix[current_row]); | ||
| 63 | } | ||
| 64 | |||
| 65 | void select_col(uint8_t col) { | ||
| 66 | setPinOutput(col_pins[col]); | ||
| 67 | writePinLow(col_pins[col]); | ||
| 68 | } | ||
| 69 | |||
| 70 | void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); } | ||
| 71 | |||
| 72 | bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { | ||
| 73 | bool matrix_changed = false; | ||
| 74 | |||
| 75 | // Select col and wait for col selecton to stabilize | ||
| 76 | select_col(current_col); | ||
| 77 | matrix_io_delay(); | ||
| 78 | |||
| 79 | // For each row... | ||
| 80 | for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { | ||
| 81 | // Store last value of row prior to reading | ||
| 82 | matrix_row_t last_row_value = current_matrix[row_index]; | ||
| 83 | |||
| 84 | // Check row pin state | ||
| 85 | if (readPin(row_pins[row_index]) == 0) { | ||
| 86 | // Pin LO, set col bit | ||
| 87 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); | ||
| 88 | } | ||
| 89 | |||
| 90 | // Determine if the matrix changed state | ||
| 91 | if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) { | ||
| 92 | matrix_changed = true; | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | // Unselect col | ||
| 97 | unselect_col(current_col); | ||
| 98 | |||
| 99 | return matrix_changed; | ||
| 100 | } | ||
| 101 | |||
| 102 | void unselect_rows(void) { | ||
| 103 | for (uint8_t x = 0; x < MATRIX_ROWS; x++) { | ||
| 104 | setPinInputHigh(row_pins[x]); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | void unselect_cols(void) { | ||
| 109 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | ||
| 110 | setPinInputHigh(col_pins[x]); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | void init_pins(void) { | ||
| 115 | unselect_rows(); | ||
| 116 | unselect_cols(); | ||
| 117 | } | ||
| 118 | |||
| 119 | void matrix_init_custom(void) { | ||
| 120 | // initialize key pins | ||
| 121 | init_pins(); | ||
| 122 | } | ||
| 123 | |||
| 124 | bool matrix_scan_custom(matrix_row_t current_matrix[]) { | ||
| 125 | bool changed = false; | ||
| 126 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { | ||
| 127 | last_matrix[current_row] = current_matrix[current_row]; | ||
| 128 | read_cols_on_row(current_matrix, current_row); | ||
| 129 | } | ||
| 130 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { | ||
| 131 | read_rows_on_col(current_matrix, current_col); | ||
| 132 | } | ||
| 133 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { | ||
| 134 | if (last_matrix[current_row] != current_matrix[current_row]) { | ||
| 135 | changed = true; | ||
| 136 | } | ||
| 137 | } | ||
| 138 | return (uint8_t)changed; | ||
| 139 | } | ||
diff --git a/keyboards/hineybush/hbcp/rules.mk b/keyboards/hineybush/hbcp/rules.mk index 869fa029c..1e973bc85 100644 --- a/keyboards/hineybush/hbcp/rules.mk +++ b/keyboards/hineybush/hbcp/rules.mk | |||
| @@ -31,3 +31,5 @@ BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | |||
| 31 | AUDIO_ENABLE = no # Audio output on port C6 | 31 | AUDIO_ENABLE = no # Audio output on port C6 |
| 32 | FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches | 32 | FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches |
| 33 | HD44780_ENABLE = no # Enable support for HD44780 based LCDs | 33 | HD44780_ENABLE = no # Enable support for HD44780 based LCDs |
| 34 | CUSTOM_MATRIX = lite | ||
| 35 | SRC += matrix.c | ||
