diff options
Diffstat (limited to 'keyboards/kinesis/kint41/kint41.c')
| -rw-r--r-- | keyboards/kinesis/kint41/kint41.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/keyboards/kinesis/kint41/kint41.c b/keyboards/kinesis/kint41/kint41.c new file mode 100644 index 000000000..e23a639f9 --- /dev/null +++ b/keyboards/kinesis/kint41/kint41.c | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* Copyright 2020 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "kint41.h" | ||
| 18 | |||
| 19 | void matrix_init_kb(void) { | ||
| 20 | matrix_init_user(); | ||
| 21 | |||
| 22 | // Turn on the Teensy 4.x Power LED: | ||
| 23 | #define LED_POWER LINE_PIN13 | ||
| 24 | setPinOutput(LED_POWER); | ||
| 25 | writePinHigh(LED_POWER); | ||
| 26 | } | ||
| 27 | |||
| 28 | // delay_inline sleeps for |cycles| (e.g. sleeping for F_CPU will sleep 1s). | ||
| 29 | // delay_inline assumes the cycle counter has already been initialized and | ||
| 30 | // should not be modified, i.e. it is safe to call during keyboard matrix scan. | ||
| 31 | // | ||
| 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 | ||
| 34 | static void delay_inline(const uint32_t cycles) { | ||
| 35 | const uint32_t start = DWT->CYCCNT; | ||
| 36 | while ((DWT->CYCCNT - start) < cycles) { | ||
| 37 | // busy-loop until time has passed | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | void matrix_output_unselect_delay(void) { | ||
| 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 | ||
| 44 | // is 100μs in our configuration. | ||
| 45 | |||
| 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. | ||
| 48 | |||
| 49 | // 600 cycles at 0.6 cycles/ns == 1μs | ||
| 50 | const uint32_t cycles_per_us = 600; | ||
| 51 | delay_inline(10 * cycles_per_us); | ||
| 52 | } | ||
