aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryiancar <yiangosyiangou@cytanet.com.cy>2020-02-24 00:25:18 +0000
committerGitHub <noreply@github.com>2020-02-24 11:25:18 +1100
commit156c9c4ec008373f8afa44d76316f554579d079c (patch)
tree1e9fa3eb4ce987e0a78603a9586f3b2fc63d30ee
parent371ff9dd6f9c4feada34622d9a43480495b07e50 (diff)
downloadqmk_firmware-156c9c4ec008373f8afa44d76316f554579d079c.tar.gz
qmk_firmware-156c9c4ec008373f8afa44d76316f554579d079c.zip
Gingham Update (#8225)
-rw-r--r--keyboards/gingham/config.h3
-rw-r--r--keyboards/gingham/matrix.c176
-rw-r--r--keyboards/gingham/rules.mk10
3 files changed, 28 insertions, 161 deletions
diff --git a/keyboards/gingham/config.h b/keyboards/gingham/config.h
index d89120c28..4c880a8fc 100644
--- a/keyboards/gingham/config.h
+++ b/keyboards/gingham/config.h
@@ -84,9 +84,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
84// #define RGBLIGHT_EFFECT_ALTERNATING 84// #define RGBLIGHT_EFFECT_ALTERNATING
85// #endif 85// #endif
86 86
87/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
88#define DEBOUNCE 5
89
90/* define if matrix has ghost (lacks anti-ghosting diodes) */ 87/* define if matrix has ghost (lacks anti-ghosting diodes) */
91//#define MATRIX_HAS_GHOST 88//#define MATRIX_HAS_GHOST
92 89
diff --git a/keyboards/gingham/matrix.c b/keyboards/gingham/matrix.c
index 5ac81e791..47c883056 100644
--- a/keyboards/gingham/matrix.c
+++ b/keyboards/gingham/matrix.c
@@ -17,160 +17,53 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include <stdint.h> 17#include <stdint.h>
18#include <stdbool.h> 18#include <stdbool.h>
19#include "wait.h" 19#include "wait.h"
20#include "print.h"
21#include "debug.h"
22#include "util.h"
23#include "matrix.h"
24#include "debounce.h"
25#include "quantum.h" 20#include "quantum.h"
26#include "i2c_master.h" 21#include "i2c_master.h"
27 22
28#if (MATRIX_COLS <= 8)
29# define print_matrix_header() print("\nr/c 01234567\n")
30# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
31# define matrix_bitpop(i) bitpop(matrix[i])
32# define ROW_SHIFTER ((uint8_t)1)
33#elif (MATRIX_COLS <= 16)
34# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
35# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
36# define matrix_bitpop(i) bitpop16(matrix[i])
37# define ROW_SHIFTER ((uint16_t)1)
38#elif (MATRIX_COLS <= 32)
39# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
40# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
41# define matrix_bitpop(i) bitpop32(matrix[i])
42# define ROW_SHIFTER ((uint32_t)1)
43#endif
44
45#ifdef MATRIX_MASKED
46 extern const matrix_row_t matrix_mask[];
47#endif
48
49static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; 23static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
50static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; 24static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
51 25
52/* matrix state(1:on, 0:off) */ 26static void unselect_rows(void) {
53static matrix_row_t raw_matrix[MATRIX_ROWS]; //raw values 27 for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
54static matrix_row_t matrix[MATRIX_ROWS]; //debounced values 28 setPinInputHigh(row_pins[x]);
55
56__attribute__ ((weak))
57void matrix_init_quantum(void) {
58 matrix_init_kb();
59}
60
61__attribute__ ((weak))
62void matrix_scan_quantum(void) {
63 matrix_scan_kb();
64}
65
66__attribute__ ((weak))
67void matrix_init_kb(void) {
68 matrix_init_user();
69}
70
71__attribute__ ((weak))
72void matrix_scan_kb(void) {
73 matrix_scan_user();
74}
75
76__attribute__ ((weak))
77void matrix_init_user(void) {
78}
79
80__attribute__ ((weak))
81void matrix_scan_user(void) {
82}
83
84inline
85uint8_t matrix_rows(void) {
86 return MATRIX_ROWS;
87}
88
89inline
90uint8_t matrix_cols(void) {
91 return MATRIX_COLS;
92}
93
94//Deprecated.
95bool matrix_is_modified(void)
96{
97 if (debounce_active()) return false;
98 return true;
99}
100
101inline
102bool matrix_is_on(uint8_t row, uint8_t col)
103{
104 return (matrix[row] & ((matrix_row_t)1<<col));
105}
106
107inline
108matrix_row_t matrix_get_row(uint8_t row)
109{
110 // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a
111 // switch blocker installed and the switch is always pressed.
112#ifdef MATRIX_MASKED
113 return matrix[row] & matrix_mask[row];
114#else
115 return matrix[row];
116#endif
117}
118
119void matrix_print(void)
120{
121 print_matrix_header();
122
123 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
124 phex(row); print(": ");
125 print_matrix_row(row);
126 print("\n");
127 }
128}
129
130uint8_t matrix_key_count(void)
131{
132 uint8_t count = 0;
133 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
134 count += matrix_bitpop(i);
135 } 29 }
136 return count;
137} 30}
138 31
139static void select_row(uint8_t row) 32static void select_row(uint8_t row) {
140{
141 setPinOutput(row_pins[row]); 33 setPinOutput(row_pins[row]);
142 writePinLow(row_pins[row]); 34 writePinLow(row_pins[row]);
143} 35}
144 36
145static void unselect_row(uint8_t row) 37static void unselect_row(uint8_t row) {
146{
147 setPinInputHigh(row_pins[row]); 38 setPinInputHigh(row_pins[row]);
148} 39}
149 40
150static void unselect_rows(void)
151{
152 for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
153 setPinInputHigh(row_pins[x]);
154 }
155}
156
157static void init_pins(void) { 41static void init_pins(void) {
158 unselect_rows(); 42 unselect_rows();
159 // Set I/O 43 // Set I/O
160 uint8_t send_data = 0x07; 44 uint8_t send_data = 0x07;
161 i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data, 1, 20); 45 i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data, 1, 20);
162 // // Set Pull-up 46 // Set Pull-up
163 i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x06, &send_data, 1, 20); 47 i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x06, &send_data, 1, 20);
164 48
165 for (uint8_t x = 0; x < MATRIX_COLS; x++) { 49 for (uint8_t x = 0; x < MATRIX_COLS; x++) {
166 if ( (x > 0) && (x < 12) ) { 50 if ( (x > 0) && (x < 12) ) {
167 setPinInputHigh(col_pins[x]); 51 setPinInputHigh(col_pins[x]);
168 } 52 }
169 } 53 }
170} 54}
171 55
172static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) 56void matrix_init_custom(void) {
173{ 57 // TODO: initialize hardware here
58 // Initialize I2C
59 i2c_init();
60
61 // initialize key pins
62 init_pins();
63 wait_ms(50);
64}
65
66static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
174 // Store last value of row prior to reading 67 // Store last value of row prior to reading
175 matrix_row_t last_row_value = current_matrix[current_row]; 68 matrix_row_t last_row_value = current_matrix[current_row];
176 69
@@ -203,7 +96,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
203 } 96 }
204 97
205 // Populate the matrix row with the state of the col pin 98 // Populate the matrix row with the state of the col pin
206 current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); 99 current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index);
207 } 100 }
208 101
209 // Unselect row 102 // Unselect row
@@ -212,36 +105,13 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
212 return (last_row_value != current_matrix[current_row]); 105 return (last_row_value != current_matrix[current_row]);
213} 106}
214 107
215void matrix_init(void) { 108bool matrix_scan_custom(matrix_row_t current_matrix[]) {
216 109 bool matrix_has_changed = false;
217 // Initialize I2C
218 i2c_init();
219
220 // initialize key pins
221 init_pins();
222
223 // initialize matrix state: all keys off
224 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
225 raw_matrix[i] = 0;
226 matrix[i] = 0;
227 }
228
229 debounce_init(MATRIX_ROWS);
230
231 matrix_init_quantum();
232}
233
234uint8_t matrix_scan(void)
235{
236 bool changed = false;
237 110
238 // Set row, read cols 111 // Set row, read cols
239 for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { 112 for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
240 changed |= read_cols_on_row(raw_matrix, current_row); 113 matrix_has_changed |= read_cols_on_row(current_matrix, current_row);
241 } 114 }
242 115
243 debounce(raw_matrix, matrix, MATRIX_ROWS, changed); 116 return matrix_has_changed;
244
245 matrix_scan_quantum();
246 return (uint8_t)changed;
247} 117}
diff --git a/keyboards/gingham/rules.mk b/keyboards/gingham/rules.mk
index f8062eb50..8448cf646 100644
--- a/keyboards/gingham/rules.mk
+++ b/keyboards/gingham/rules.mk
@@ -20,11 +20,11 @@ OPT_DEFS = -DDEBUG_LEVEL=0
20# Build Options 20# Build Options
21# change yes to no to disable 21# change yes to no to disable
22# 22#
23BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration 23BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration
24MOUSEKEY_ENABLE = yes # Mouse keys 24MOUSEKEY_ENABLE = yes # Mouse keys
25EXTRAKEY_ENABLE = yes # Audio control and System control 25EXTRAKEY_ENABLE = yes # Audio control and System control
26CONSOLE_ENABLE = no # Console for debug 26CONSOLE_ENABLE = no # Console for debug
27COMMAND_ENABLE = no # Commands for debug and configuration 27COMMAND_ENABLE = no # Commands for debug and configuration
28# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE 28# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
29SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend 29SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
30# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 30# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
@@ -36,6 +36,6 @@ UNICODE_ENABLE = no # Unicode
36BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID 36BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
37AUDIO_ENABLE = no # Audio output on port C6 37AUDIO_ENABLE = no # Audio output on port C6
38FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches 38FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
39HD44780_ENABLE = no # Enable support for HD44780 based LCDs 39HD44780_ENABLE = no # Enable support for HD44780 based LCDs
40 40
41CUSTOM_MATRIX = yes 41CUSTOM_MATRIX = lite