aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/handwired/symmetric70_proto/matrix_debug/matrix.c69
-rw-r--r--keyboards/handwired/symmetric70_proto/proton_c/proton_c.c6
-rw-r--r--keyboards/kinesis/kint41/kint41.c26
-rw-r--r--keyboards/rgbkb/mun/matrix.c6
-rw-r--r--keyboards/rgbkb/mun/mun.c10
5 files changed, 59 insertions, 58 deletions
diff --git a/keyboards/handwired/symmetric70_proto/matrix_debug/matrix.c b/keyboards/handwired/symmetric70_proto/matrix_debug/matrix.c
index c84efe291..a892707f8 100644
--- a/keyboards/handwired/symmetric70_proto/matrix_debug/matrix.c
+++ b/keyboards/handwired/symmetric70_proto/matrix_debug/matrix.c
@@ -32,7 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
32# define MATRIX_DEBUG_DELAY_END() 32# define MATRIX_DEBUG_DELAY_END()
33# define MATRIX_DEBUG_GAP() 33# define MATRIX_DEBUG_GAP()
34#else 34#else
35# define MATRIX_DEBUG_GAP() asm volatile("nop \n nop":::"memory") 35# define MATRIX_DEBUG_GAP() asm volatile("nop \n nop" ::: "memory")
36#endif 36#endif
37 37
38#ifndef MATRIX_IO_DELAY_ALWAYS 38#ifndef MATRIX_IO_DELAY_ALWAYS
@@ -44,16 +44,16 @@ static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS;
44#elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) 44#elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW)
45static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; 45static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
46static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; 46static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
47# ifdef MATRIX_MUL_SELECT 47# ifdef MATRIX_MUL_SELECT
48static const pin_t col_sel[MATRIX_COLS] = MATRIX_MUL_SEL; 48static const pin_t col_sel[MATRIX_COLS] = MATRIX_MUL_SEL;
49# endif 49# endif
50#endif 50#endif
51 51
52#ifdef MATRIX_IO_DELAY_PORTS 52#ifdef MATRIX_IO_DELAY_PORTS
53static const pin_t delay_ports[] = { MATRIX_IO_DELAY_PORTS }; 53static const pin_t delay_ports[] = {MATRIX_IO_DELAY_PORTS};
54static const port_data_t delay_masks[] = { MATRIX_IO_DELAY_MASKS }; 54static const port_data_t delay_masks[] = {MATRIX_IO_DELAY_MASKS};
55# ifdef MATRIX_IO_DELAY_MULSEL 55# ifdef MATRIX_IO_DELAY_MULSEL
56static const uint8_t delay_sel[] = { MATRIX_IO_DELAY_MULSEL }; 56static const uint8_t delay_sel[] = {MATRIX_IO_DELAY_MULSEL};
57# endif 57# endif
58#endif 58#endif
59 59
@@ -120,10 +120,10 @@ static void unselect_rows(void) {
120} 120}
121 121
122static void init_pins(void) { 122static void init_pins(void) {
123#ifdef MATRIX_MUL_SELECT 123# ifdef MATRIX_MUL_SELECT
124 setPinOutput(MATRIX_MUL_SELECT); 124 setPinOutput(MATRIX_MUL_SELECT);
125 writePinLow(MATRIX_MUL_SELECT); 125 writePinLow(MATRIX_MUL_SELECT);
126#endif 126# endif
127 unselect_rows(); 127 unselect_rows();
128 for (uint8_t x = 0; x < MATRIX_COLS; x++) { 128 for (uint8_t x = 0; x < MATRIX_COLS; x++) {
129 setPinInputHigh_atomic(col_pins[x]); 129 setPinInputHigh_atomic(col_pins[x]);
@@ -141,10 +141,10 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
141 // For each col... 141 // For each col...
142 for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { 142 for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
143 // Select the col pin to read (active low) 143 // Select the col pin to read (active low)
144#ifdef MATRIX_MUL_SELECT 144# ifdef MATRIX_MUL_SELECT
145 writePin(MATRIX_MUL_SELECT,col_sel[col_index]); 145 writePin(MATRIX_MUL_SELECT, col_sel[col_index]);
146 waitInputPinDelay(); 146 waitInputPinDelay();
147#endif 147# endif
148 uint8_t pin_state = readPin(col_pins[col_index]); 148 uint8_t pin_state = readPin(col_pins[col_index]);
149 149
150 // Populate the matrix row with the state of the col pin 150 // Populate the matrix row with the state of the col pin
@@ -153,37 +153,38 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
153 153
154 // Unselect row 154 // Unselect row
155 unselect_row(current_row); 155 unselect_row(current_row);
156#ifdef MATRIX_IO_DELAY_PORTS 156# ifdef MATRIX_IO_DELAY_PORTS
157 if (current_row_value) { // wait for col signal to go HIGH 157 if (current_row_value) { // wait for col signal to go HIGH
158 bool is_pressed; 158 bool is_pressed;
159 do { 159 do {
160 MATRIX_DEBUG_DELAY_START(); 160 MATRIX_DEBUG_DELAY_START();
161 is_pressed = false; 161 is_pressed = false;
162 for (uint8_t i = 0; i < sizeof(delay_ports)/sizeof(pin_t); i++ ) { 162 for (uint8_t i = 0; i < sizeof(delay_ports) / sizeof(pin_t); i++) {
163# ifdef MATRIX_IO_DELAY_MULSEL 163# ifdef MATRIX_IO_DELAY_MULSEL
164 writePin(MATRIX_MUL_SELECT, delay_sel[i]); 164 writePin(MATRIX_MUL_SELECT, delay_sel[i]);
165 waitInputPinDelay(); 165 waitInputPinDelay();
166# endif 166# endif
167 is_pressed |= ( (readPort(delay_ports[i]) & delay_masks[i]) != delay_masks[i] ); 167 is_pressed |= ((readPort(delay_ports[i]) & delay_masks[i]) != delay_masks[i]);
168 } 168 }
169 MATRIX_DEBUG_DELAY_END(); 169 MATRIX_DEBUG_DELAY_END();
170 } while (is_pressed); 170 } while (is_pressed);
171 } 171 }
172#endif 172# endif
173#ifdef MATRIX_IO_DELAY_ADAPTIVE 173# ifdef MATRIX_IO_DELAY_ADAPTIVE
174 if (current_row_value) { // wait for col signal to go HIGH 174 if (current_row_value) { // wait for col signal to go HIGH
175 for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { 175 for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
176 MATRIX_DEBUG_DELAY_START(); 176 MATRIX_DEBUG_DELAY_START();
177#ifdef MATRIX_MUL_SELECT 177# ifdef MATRIX_MUL_SELECT
178 writePin(MATRIX_MUL_SELECT,col_sel[col_index]); 178 writePin(MATRIX_MUL_SELECT, col_sel[col_index]);
179 waitInputPinDelay(); 179 waitInputPinDelay();
180#endif 180# endif
181 while (readPin(col_pins[col_index]) == 0) {} 181 while (readPin(col_pins[col_index]) == 0) {
182 }
182 MATRIX_DEBUG_DELAY_END(); 183 MATRIX_DEBUG_DELAY_END();
183 } 184 }
184 } 185 }
185#endif 186# endif
186#ifdef MATRIX_IO_DELAY_ADAPTIVE2 187# ifdef MATRIX_IO_DELAY_ADAPTIVE2
187 if (current_row_value) { // wait for col signal to go HIGH 188 if (current_row_value) { // wait for col signal to go HIGH
188 pin_t state; 189 pin_t state;
189 do { 190 do {
@@ -192,19 +193,19 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
192 for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { 193 for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
193 MATRIX_DEBUG_DELAY_END(); 194 MATRIX_DEBUG_DELAY_END();
194 MATRIX_DEBUG_DELAY_START(); 195 MATRIX_DEBUG_DELAY_START();
195#ifdef MATRIX_MUL_SELECT 196# ifdef MATRIX_MUL_SELECT
196 writePin(MATRIX_MUL_SELECT,col_sel[col_index]); 197 writePin(MATRIX_MUL_SELECT, col_sel[col_index]);
197 waitInputPinDelay(); 198 waitInputPinDelay();
198#endif 199# endif
199 state |= (readPin(col_pins[col_index]) == 0); 200 state |= (readPin(col_pins[col_index]) == 0);
200 } 201 }
201 MATRIX_DEBUG_DELAY_END(); 202 MATRIX_DEBUG_DELAY_END();
202 } while (state); 203 } while (state);
203 } 204 }
204#endif 205# endif
205 if (MATRIX_IO_DELAY_ALWAYS || current_row + 1 < MATRIX_ROWS) { 206 if (MATRIX_IO_DELAY_ALWAYS || current_row + 1 < MATRIX_ROWS) {
206 MATRIX_DEBUG_DELAY_START(); 207 MATRIX_DEBUG_DELAY_START();
207 matrix_output_unselect_delay(); // wait for col signal to go HIGH 208 matrix_output_unselect_delay(current_row, current_row_value != 0);
208 MATRIX_DEBUG_DELAY_END(); 209 MATRIX_DEBUG_DELAY_END();
209 } 210 }
210 211
@@ -267,7 +268,7 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
267 // Unselect col 268 // Unselect col
268 unselect_col(current_col); 269 unselect_col(current_col);
269 if (MATRIX_IO_DELAY_ALWAYS || current_col + 1 < MATRIX_COLS) { 270 if (MATRIX_IO_DELAY_ALWAYS || current_col + 1 < MATRIX_COLS) {
270 matrix_output_unselect_delay(); // wait for col signal to go HIGH 271 matrix_output_unselect_delay(current_row, current_row_value != 0);
271 } 272 }
272 273
273 return matrix_changed; 274 return matrix_changed;
@@ -311,11 +312,13 @@ uint8_t matrix_scan(void) {
311 changed |= read_rows_on_col(raw_matrix, current_col); 312 changed |= read_rows_on_col(raw_matrix, current_col);
312 } 313 }
313#endif 314#endif
314 MATRIX_DEBUG_SCAN_END(); MATRIX_DEBUG_GAP(); 315 MATRIX_DEBUG_SCAN_END();
316 MATRIX_DEBUG_GAP();
315 317
316 MATRIX_DEBUG_SCAN_START(); 318 MATRIX_DEBUG_SCAN_START();
317 debounce(raw_matrix, matrix, MATRIX_ROWS, changed); 319 debounce(raw_matrix, matrix, MATRIX_ROWS, changed);
318 MATRIX_DEBUG_SCAN_END(); MATRIX_DEBUG_GAP(); 320 MATRIX_DEBUG_SCAN_END();
321 MATRIX_DEBUG_GAP();
319 322
320 MATRIX_DEBUG_SCAN_START(); 323 MATRIX_DEBUG_SCAN_START();
321 matrix_scan_quantum(); 324 matrix_scan_quantum();
diff --git a/keyboards/handwired/symmetric70_proto/proton_c/proton_c.c b/keyboards/handwired/symmetric70_proto/proton_c/proton_c.c
index 3fe5bc297..dfdc9d759 100644
--- a/keyboards/handwired/symmetric70_proto/proton_c/proton_c.c
+++ b/keyboards/handwired/symmetric70_proto/proton_c/proton_c.c
@@ -4,9 +4,9 @@
4/* In tmk_core/common/wait.h, the implementation for PROTOCOL_CHIBIOS 4/* In tmk_core/common/wait.h, the implementation for PROTOCOL_CHIBIOS
5 * calls 'chThdSleepMicroseconds(1)' when 'wait_us(0)'. 5 * calls 'chThdSleepMicroseconds(1)' when 'wait_us(0)'.
6 * However, 'wait_us(0)' should do nothing. */ 6 * However, 'wait_us(0)' should do nothing. */
7void matrix_output_unselect_delay(void) { 7void matrix_output_unselect_delay(uint8_t line, bool key_pressed) {
8# if !defined(MATRIX_IO_DELAY) || MATRIX_IO_DELAY > 0 8# if !defined(MATRIX_IO_DELAY) || MATRIX_IO_DELAY > 0
9 matrix_io_delay(); 9 matrix_io_delay();
10# endif 10# endif
11} 11}
12#endif 12#endif
diff --git a/keyboards/kinesis/kint41/kint41.c b/keyboards/kinesis/kint41/kint41.c
index e23a639f9..ab6567d09 100644
--- a/keyboards/kinesis/kint41/kint41.c
+++ b/keyboards/kinesis/kint41/kint41.c
@@ -32,21 +32,21 @@ void matrix_init_kb(void) {
32// ChibiOS enables the cycle counter in chcore_v7m.c: 32// ChibiOS enables the cycle counter in chcore_v7m.c:
33// https://github.com/ChibiOS/ChibiOS/blob/b63023915c304092acb9f33bbab40f3ec07a7f0e/os/common/ports/ARMCMx/chcore_v7m.c#L263 33// https://github.com/ChibiOS/ChibiOS/blob/b63023915c304092acb9f33bbab40f3ec07a7f0e/os/common/ports/ARMCMx/chcore_v7m.c#L263
34static void delay_inline(const uint32_t cycles) { 34static void delay_inline(const uint32_t cycles) {
35 const uint32_t start = DWT->CYCCNT; 35 const uint32_t start = DWT->CYCCNT;
36 while ((DWT->CYCCNT - start) < cycles) { 36 while ((DWT->CYCCNT - start) < cycles) {
37 // busy-loop until time has passed 37 // busy-loop until time has passed
38 } 38 }
39} 39}
40 40
41void matrix_output_unselect_delay(void) { 41void matrix_output_unselect_delay(uint8_t line, bool key_pressed) {
42 // Use the cycle counter to do precise timing in microseconds. The ChibiOS 42 // Use the cycle counter to do precise timing in microseconds. The ChibiOS
43 // thread sleep functions only allow sleep durations starting at 1 tick, which 43 // thread sleep functions only allow sleep durations starting at 1 tick, which
44 // is 100μs in our configuration. 44 // is 100μs in our configuration.
45 45
46 // Empirically: e.g. 5μs is not enough, will result in keys that don’t work 46 // Empirically: e.g. 5μs is not enough, will result in keys that don’t work
47 // and ghost key presses. 10μs seems to work well. 47 // and ghost key presses. 10μs seems to work well.
48 48
49 // 600 cycles at 0.6 cycles/ns == 1μs 49 // 600 cycles at 0.6 cycles/ns == 1μs
50 const uint32_t cycles_per_us = 600; 50 const uint32_t cycles_per_us = 600;
51 delay_inline(10 * cycles_per_us); 51 delay_inline(10 * cycles_per_us);
52} 52}
diff --git a/keyboards/rgbkb/mun/matrix.c b/keyboards/rgbkb/mun/matrix.c
index a0cb7df51..497ab041f 100644
--- a/keyboards/rgbkb/mun/matrix.c
+++ b/keyboards/rgbkb/mun/matrix.c
@@ -19,7 +19,7 @@
19#include "transactions.h" 19#include "transactions.h"
20 20
21#define ERROR_DISCONNECT_COUNT 5 21#define ERROR_DISCONNECT_COUNT 5
22#define ROWS_PER_HAND (MATRIX_ROWS / 2) 22#define ROWS_PER_HAND (MATRIX_ROWS / 2)
23 23
24static const pin_t row_pins[ROWS_PER_HAND] = MATRIX_ROW_PINS; 24static const pin_t row_pins[ROWS_PER_HAND] = MATRIX_ROW_PINS;
25static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; 25static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
@@ -141,7 +141,7 @@ uint8_t matrix_scan(void) {
141 141
142 /* Drive row pin high again. */ 142 /* Drive row pin high again. */
143 ATOMIC_BLOCK_FORCEON { writePinHigh(row_pins[row_idx]); } 143 ATOMIC_BLOCK_FORCEON { writePinHigh(row_pins[row_idx]); }
144 matrix_output_unselect_delay(); 144 matrix_output_unselect_delay(row_idx, row_pins[row_idx] != 0);
145 } 145 }
146 146
147 if (memcmp(raw_matrix, current_matrix, sizeof(current_matrix)) != 0) { 147 if (memcmp(raw_matrix, current_matrix, sizeof(current_matrix)) != 0) {
@@ -153,4 +153,4 @@ uint8_t matrix_scan(void) {
153 153
154 bool remote_changed = matrix_post_scan(); 154 bool remote_changed = matrix_post_scan();
155 return (uint8_t)(local_changed || remote_changed); 155 return (uint8_t)(local_changed || remote_changed);
156} \ No newline at end of file 156}
diff --git a/keyboards/rgbkb/mun/mun.c b/keyboards/rgbkb/mun/mun.c
index 5dabecc13..6cc95c46e 100644
--- a/keyboards/rgbkb/mun/mun.c
+++ b/keyboards/rgbkb/mun/mun.c
@@ -12,24 +12,22 @@
12#include "common_oled.h" 12#include "common_oled.h"
13#include <transactions.h> 13#include <transactions.h>
14 14
15void keyboard_post_init_kb(void) 15void keyboard_post_init_kb(void) {
16{
17 touch_encoder_init(); 16 touch_encoder_init();
18 transaction_register_rpc(TOUCH_ENCODER_SYNC, touch_encoder_slave_sync); 17 transaction_register_rpc(TOUCH_ENCODER_SYNC, touch_encoder_slave_sync);
19 transaction_register_rpc(RGB_MENU_SYNC, rgb_menu_slave_sync); 18 transaction_register_rpc(RGB_MENU_SYNC, rgb_menu_slave_sync);
20 keyboard_post_init_user(); 19 keyboard_post_init_user();
21} 20}
22 21
23void housekeeping_task_kb(void) 22void housekeeping_task_kb(void) {
24{
25 touch_encoder_update(TOUCH_ENCODER_SYNC); 23 touch_encoder_update(TOUCH_ENCODER_SYNC);
26 rgb_menu_update(RGB_MENU_SYNC); 24 rgb_menu_update(RGB_MENU_SYNC);
27} 25}
28 26
29#if defined(BUSY_WAIT) 27#if defined(BUSY_WAIT)
30void matrix_output_unselect_delay(void) { 28void matrix_output_unselect_delay(uint8_t line, bool key_pressed) {
31 for (int32_t i = 0; i < BUSY_WAIT_INSTRUCTIONS; i++) { 29 for (int32_t i = 0; i < BUSY_WAIT_INSTRUCTIONS; i++) {
32 __asm__ volatile("nop" ::: "memory"); 30 __asm__ volatile("nop" ::: "memory");
33 } 31 }
34} 32}
35#endif \ No newline at end of file 33#endif