aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/action_layer.c12
-rw-r--r--tmk_core/common/action_layer.h29
-rw-r--r--tmk_core/common/action_util.c28
-rw-r--r--tmk_core/common/arm_atsam/_timer.h19
-rw-r--r--tmk_core/common/avr/_timer.h19
-rw-r--r--tmk_core/common/avr/gpio.h15
-rw-r--r--tmk_core/common/chibios/_timer.h19
-rw-r--r--tmk_core/common/chibios/bootloader.c5
-rw-r--r--tmk_core/common/chibios/gpio.h16
-rw-r--r--tmk_core/common/host.c14
-rw-r--r--tmk_core/common/keyboard.c24
-rw-r--r--tmk_core/common/progmem.h1
-rw-r--r--tmk_core/common/sync_timer.c2
-rw-r--r--tmk_core/common/sync_timer.h2
-rw-r--r--tmk_core/common/timer.h20
-rw-r--r--tmk_core/common/usb_util.c2
-rw-r--r--tmk_core/common/usb_util.h2
17 files changed, 211 insertions, 18 deletions
diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c
index af2d7d964..ed1a4bd20 100644
--- a/tmk_core/common/action_layer.c
+++ b/tmk_core/common/action_layer.c
@@ -131,32 +131,32 @@ bool layer_state_cmp(layer_state_t cmp_layer_state, uint8_t layer) {
131 if (!cmp_layer_state) { 131 if (!cmp_layer_state) {
132 return layer == 0; 132 return layer == 0;
133 } 133 }
134 return (cmp_layer_state & (1UL << layer)) != 0; 134 return (cmp_layer_state & ((layer_state_t)1 << layer)) != 0;
135} 135}
136 136
137/** \brief Layer move 137/** \brief Layer move
138 * 138 *
139 * Turns on the given layer and turn off all other layers 139 * Turns on the given layer and turn off all other layers
140 */ 140 */
141void layer_move(uint8_t layer) { layer_state_set(1UL << layer); } 141void layer_move(uint8_t layer) { layer_state_set((layer_state_t)1 << layer); }
142 142
143/** \brief Layer on 143/** \brief Layer on
144 * 144 *
145 * Turns on given layer 145 * Turns on given layer
146 */ 146 */
147void layer_on(uint8_t layer) { layer_state_set(layer_state | (1UL << layer)); } 147void layer_on(uint8_t layer) { layer_state_set(layer_state | ((layer_state_t)1 << layer)); }
148 148
149/** \brief Layer off 149/** \brief Layer off
150 * 150 *
151 * Turns off given layer 151 * Turns off given layer
152 */ 152 */
153void layer_off(uint8_t layer) { layer_state_set(layer_state & ~(1UL << layer)); } 153void layer_off(uint8_t layer) { layer_state_set(layer_state & ~((layer_state_t)1 << layer)); }
154 154
155/** \brief Layer invert 155/** \brief Layer invert
156 * 156 *
157 * Toggle the given layer (set it if it's unset, or unset it if it's set) 157 * Toggle the given layer (set it if it's unset, or unset it if it's set)
158 */ 158 */
159void layer_invert(uint8_t layer) { layer_state_set(layer_state ^ (1UL << layer)); } 159void layer_invert(uint8_t layer) { layer_state_set(layer_state ^ ((layer_state_t)1 << layer)); }
160 160
161/** \brief Layer or 161/** \brief Layer or
162 * 162 *
@@ -258,7 +258,7 @@ uint8_t layer_switch_get_layer(keypos_t key) {
258 layer_state_t layers = layer_state | default_layer_state; 258 layer_state_t layers = layer_state | default_layer_state;
259 /* check top layer first */ 259 /* check top layer first */
260 for (int8_t i = MAX_LAYER - 1; i >= 0; i--) { 260 for (int8_t i = MAX_LAYER - 1; i >= 0; i--) {
261 if (layers & (1UL << i)) { 261 if (layers & ((layer_state_t)1 << i)) {
262 action = action_for_key(i, key); 262 action = action_for_key(i, key);
263 if (action.code != ACTION_TRANSPARENT) { 263 if (action.code != ACTION_TRANSPARENT) {
264 return i; 264 return i;
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h
index d72cd3e3a..b87d096ee 100644
--- a/tmk_core/common/action_layer.h
+++ b/tmk_core/common/action_layer.h
@@ -21,6 +21,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include "keyboard.h" 21#include "keyboard.h"
22#include "action.h" 22#include "action.h"
23 23
24#ifdef DYNAMIC_KEYMAP_ENABLE
25# ifndef DYNAMIC_KEYMAP_LAYER_COUNT
26# define DYNAMIC_KEYMAP_LAYER_COUNT 4
27# endif
28# if DYNAMIC_KEYMAP_LAYER_COUNT <= 8
29# ifndef LAYER_STATE_8BIT
30# define LAYER_STATE_8BIT
31# endif
32# elif DYNAMIC_KEYMAP_LAYER_COUNT <= 16
33# ifndef LAYER_STATE_16BIT
34# define LAYER_STATE_16BIT
35# endif
36# else
37# ifndef LAYER_STATE_32BIT
38# define LAYER_STATE_32BIT
39# endif
40# endif
41#endif
42
43#if !defined(LAYER_STATE_8BIT) && !defined(LAYER_STATE_16BIT) && !defined(LAYER_STATE_32BIT)
44# define LAYER_STATE_32BIT
45#endif
46
24#if defined(LAYER_STATE_8BIT) 47#if defined(LAYER_STATE_8BIT)
25typedef uint8_t layer_state_t; 48typedef uint8_t layer_state_t;
26# define MAX_LAYER_BITS 3 49# define MAX_LAYER_BITS 3
@@ -35,13 +58,15 @@ typedef uint16_t layer_state_t;
35# define MAX_LAYER 16 58# define MAX_LAYER 16
36# endif 59# endif
37# define get_highest_layer(state) biton16(state) 60# define get_highest_layer(state) biton16(state)
38#else 61#elif defined(LAYER_STATE_32BIT)
39typedef uint32_t layer_state_t; 62typedef uint32_t layer_state_t;
40# define MAX_LAYER_BITS 5 63# define MAX_LAYER_BITS 5
41# ifndef MAX_LAYER 64# ifndef MAX_LAYER
42# define MAX_LAYER 32 65# define MAX_LAYER 32
43# endif 66# endif
44# define get_highest_layer(state) biton32(state) 67# define get_highest_layer(state) biton32(state)
68#else
69# error Layer Mask size not specified. HOW?!
45#endif 70#endif
46 71
47/* 72/*
@@ -92,7 +117,7 @@ layer_state_t layer_state_set_kb(layer_state_t state);
92 117
93# define layer_state_set(layer) 118# define layer_state_set(layer)
94# define layer_state_is(layer) (layer == 0) 119# define layer_state_is(layer) (layer == 0)
95# define layer_state_cmp(state, layer) (state == 0 ? layer == 0 : (state & 1UL << layer) != 0) 120# define layer_state_cmp(state, layer) (state == 0 ? layer == 0 : (state & (layer_state_t)1 << layer) != 0)
96 121
97# define layer_debug() 122# define layer_debug()
98# define layer_clear() 123# define layer_clear()
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c
index a57c8bf66..2b3c00cba 100644
--- a/tmk_core/common/action_util.c
+++ b/tmk_core/common/action_util.c
@@ -27,6 +27,10 @@ extern keymap_config_t keymap_config;
27static uint8_t real_mods = 0; 27static uint8_t real_mods = 0;
28static uint8_t weak_mods = 0; 28static uint8_t weak_mods = 0;
29static uint8_t macro_mods = 0; 29static uint8_t macro_mods = 0;
30#ifdef KEY_OVERRIDE_ENABLE
31static uint8_t weak_override_mods = 0;
32static uint8_t suppressed_mods = 0;
33#endif
30 34
31#ifdef USB_6KRO_ENABLE 35#ifdef USB_6KRO_ENABLE
32# define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) 36# define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS)
@@ -229,6 +233,7 @@ void send_keyboard_report(void) {
229 keyboard_report->mods = real_mods; 233 keyboard_report->mods = real_mods;
230 keyboard_report->mods |= weak_mods; 234 keyboard_report->mods |= weak_mods;
231 keyboard_report->mods |= macro_mods; 235 keyboard_report->mods |= macro_mods;
236
232#ifndef NO_ACTION_ONESHOT 237#ifndef NO_ACTION_ONESHOT
233 if (oneshot_mods) { 238 if (oneshot_mods) {
234# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) 239# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
@@ -244,6 +249,13 @@ void send_keyboard_report(void) {
244 } 249 }
245 250
246#endif 251#endif
252
253#ifdef KEY_OVERRIDE_ENABLE
254 // These need to be last to be able to properly control key overrides
255 keyboard_report->mods &= ~suppressed_mods;
256 keyboard_report->mods |= weak_override_mods;
257#endif
258
247 host_keyboard_send(keyboard_report); 259 host_keyboard_send(keyboard_report);
248} 260}
249 261
@@ -299,6 +311,22 @@ void set_weak_mods(uint8_t mods) { weak_mods = mods; }
299 */ 311 */
300void clear_weak_mods(void) { weak_mods = 0; } 312void clear_weak_mods(void) { weak_mods = 0; }
301 313
314#ifdef KEY_OVERRIDE_ENABLE
315/** \brief set weak mods used by key overrides. DO not call this manually
316 */
317void set_weak_override_mods(uint8_t mods) { weak_override_mods = mods; }
318/** \brief clear weak mods used by key overrides. DO not call this manually
319 */
320void clear_weak_override_mods(void) { weak_override_mods = 0; }
321
322/** \brief set suppressed mods used by key overrides. DO not call this manually
323 */
324void set_suppressed_override_mods(uint8_t mods) { suppressed_mods = mods; }
325/** \brief clear suppressed mods used by key overrides. DO not call this manually
326 */
327void clear_suppressed_override_mods(void) { suppressed_mods = 0; }
328#endif
329
302/* macro modifier */ 330/* macro modifier */
303/** \brief get macro mods 331/** \brief get macro mods
304 * 332 *
diff --git a/tmk_core/common/arm_atsam/_timer.h b/tmk_core/common/arm_atsam/_timer.h
new file mode 100644
index 000000000..77402b612
--- /dev/null
+++ b/tmk_core/common/arm_atsam/_timer.h
@@ -0,0 +1,19 @@
1/* Copyright 2021 Simon Arlott
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#pragma once
17
18// The platform is 32-bit, so prefer 32-bit timers to avoid overflow
19#define FAST_TIMER_T_SIZE 32
diff --git a/tmk_core/common/avr/_timer.h b/tmk_core/common/avr/_timer.h
new file mode 100644
index 000000000..b81e0f68b
--- /dev/null
+++ b/tmk_core/common/avr/_timer.h
@@ -0,0 +1,19 @@
1/* Copyright 2021 Simon Arlott
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#pragma once
17
18// The platform is 8-bit, so prefer 16-bit timers to reduce code size
19#define FAST_TIMER_T_SIZE 16
diff --git a/tmk_core/common/avr/gpio.h b/tmk_core/common/avr/gpio.h
index 231556c29..e9be68491 100644
--- a/tmk_core/common/avr/gpio.h
+++ b/tmk_core/common/avr/gpio.h
@@ -20,6 +20,8 @@
20 20
21typedef uint8_t pin_t; 21typedef uint8_t pin_t;
22 22
23/* Operation of GPIO by pin. */
24
23#define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) 25#define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
24#define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) 26#define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
25#define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") 27#define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low")
@@ -32,3 +34,16 @@ typedef uint8_t pin_t;
32#define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) 34#define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
33 35
34#define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) 36#define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF))
37
38/* Operation of GPIO by port. */
39
40typedef uint8_t port_data_t;
41
42#define readPort(port) PINx_ADDRESS(port)
43
44#define setPortBitInput(port, bit) (DDRx_ADDRESS(port) &= ~_BV((bit)&0xF), PORTx_ADDRESS(port) &= ~_BV((bit)&0xF))
45#define setPortBitInputHigh(port, bit) (DDRx_ADDRESS(port) &= ~_BV((bit)&0xF), PORTx_ADDRESS(port) |= _BV((bit)&0xF))
46#define setPortBitOutput(port, bit) (DDRx_ADDRESS(port) |= _BV((bit)&0xF))
47
48#define writePortBitLow(port, bit) (PORTx_ADDRESS(port) &= ~_BV((bit)&0xF))
49#define writePortBitHigh(port, bit) (PORTx_ADDRESS(port) |= _BV((bit)&0xF))
diff --git a/tmk_core/common/chibios/_timer.h b/tmk_core/common/chibios/_timer.h
new file mode 100644
index 000000000..77402b612
--- /dev/null
+++ b/tmk_core/common/chibios/_timer.h
@@ -0,0 +1,19 @@
1/* Copyright 2021 Simon Arlott
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#pragma once
17
18// The platform is 32-bit, so prefer 32-bit timers to avoid overflow
19#define FAST_TIMER_T_SIZE 32
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c
index 11f7abf43..f9514ee5f 100644
--- a/tmk_core/common/chibios/bootloader.c
+++ b/tmk_core/common/chibios/bootloader.c
@@ -95,7 +95,7 @@ void enter_bootloader_mode_if_requested(void) {
95 } 95 }
96} 96}
97 97
98#elif defined(KL2x) || defined(K20x) || defined(MK66F18) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS 98#elif defined(KL2x) || defined(K20x) || defined(MK66F18) || defined(MIMXRT1062) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS
99/* Kinetis */ 99/* Kinetis */
100 100
101# if defined(BOOTLOADER_KIIBOHD) 101# if defined(BOOTLOADER_KIIBOHD)
@@ -103,7 +103,8 @@ void enter_bootloader_mode_if_requested(void) {
103# define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000 103# define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
104const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff"; 104const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
105__attribute__((weak)) void bootloader_jump(void) { 105__attribute__((weak)) void bootloader_jump(void) {
106 __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic)); 106 void *volatile vbat = (void *)VBAT;
107 __builtin_memcpy(vbat, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
107 // request reset 108 // request reset
108 SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk; 109 SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
109} 110}
diff --git a/tmk_core/common/chibios/gpio.h b/tmk_core/common/chibios/gpio.h
index 5d0e142ab..4d057f1ca 100644
--- a/tmk_core/common/chibios/gpio.h
+++ b/tmk_core/common/chibios/gpio.h
@@ -20,6 +20,8 @@
20 20
21typedef ioline_t pin_t; 21typedef ioline_t pin_t;
22 22
23/* Operation of GPIO by pin. */
24
23#define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) 25#define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
24#define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) 26#define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
25#define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) 27#define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
@@ -32,3 +34,17 @@ typedef ioline_t pin_t;
32#define readPin(pin) palReadLine(pin) 34#define readPin(pin) palReadLine(pin)
33 35
34#define togglePin(pin) palToggleLine(pin) 36#define togglePin(pin) palToggleLine(pin)
37
38/* Operation of GPIO by port. */
39
40typedef uint16_t port_data_t;
41
42#define readPort(pin) palReadPort(PAL_PORT(pin))
43
44#define setPortBitInput(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT)
45#define setPortBitInputHigh(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT_PULLUP)
46#define setPortBitInputLow(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT_PULLDOWN)
47#define setPortBitOutput(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_OUTPUT_PUSHPULL)
48
49#define writePortBitLow(pin, bit) palClearLine(PAL_LINE(PAL_PORT(pin), bit))
50#define writePortBitHigh(pin, bit) palSetLine(PAL_LINE(PAL_PORT(pin), bit))
diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c
index e7d92cfac..a8b391e89 100644
--- a/tmk_core/common/host.c
+++ b/tmk_core/common/host.c
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18#include <stdint.h> 18#include <stdint.h>
19//#include <avr/interrupt.h> 19//#include <avr/interrupt.h>
20#include "keyboard.h"
20#include "keycode.h" 21#include "keycode.h"
21#include "host.h" 22#include "host.h"
22#include "util.h" 23#include "util.h"
@@ -35,15 +36,20 @@ void host_set_driver(host_driver_t *d) { driver = d; }
35 36
36host_driver_t *host_get_driver(void) { return driver; } 37host_driver_t *host_get_driver(void) { return driver; }
37 38
39#ifdef SPLIT_KEYBOARD
40uint8_t split_led_state = 0;
41void set_split_host_keyboard_leds(uint8_t led_state) { split_led_state = led_state; }
42#endif
43
38uint8_t host_keyboard_leds(void) { 44uint8_t host_keyboard_leds(void) {
45#ifdef SPLIT_KEYBOARD
46 if (!is_keyboard_master()) return split_led_state;
47#endif
39 if (!driver) return 0; 48 if (!driver) return 0;
40 return (*driver->keyboard_leds)(); 49 return (*driver->keyboard_leds)();
41} 50}
42 51
43led_t host_keyboard_led_state(void) { 52led_t host_keyboard_led_state(void) { return (led_t)host_keyboard_leds(); }
44 if (!driver) return (led_t){0};
45 return (led_t)((*driver->keyboard_leds)());
46}
47 53
48/* send report */ 54/* send report */
49void host_keyboard_send(report_keyboard_t *report) { 55void host_keyboard_send(report_keyboard_t *report) {
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 3d6092e71..28fa97bc8 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -85,6 +85,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
85#ifdef OLED_DRIVER_ENABLE 85#ifdef OLED_DRIVER_ENABLE
86# include "oled_driver.h" 86# include "oled_driver.h"
87#endif 87#endif
88#ifdef ST7565_ENABLE
89# include "st7565.h"
90#endif
88#ifdef VELOCIKEY_ENABLE 91#ifdef VELOCIKEY_ENABLE
89# include "velocikey.h" 92# include "velocikey.h"
90#endif 93#endif
@@ -100,6 +103,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
100#ifdef EEPROM_DRIVER 103#ifdef EEPROM_DRIVER
101# include "eeprom_driver.h" 104# include "eeprom_driver.h"
102#endif 105#endif
106#if defined(CRC_ENABLE)
107# include "crc.h"
108#endif
103 109
104static uint32_t last_input_modification_time = 0; 110static uint32_t last_input_modification_time = 0;
105uint32_t last_input_activity_time(void) { return last_input_modification_time; } 111uint32_t last_input_activity_time(void) { return last_input_modification_time; }
@@ -297,6 +303,9 @@ void keyboard_init(void) {
297 timer_init(); 303 timer_init();
298 sync_timer_init(); 304 sync_timer_init();
299 matrix_init(); 305 matrix_init();
306#if defined(CRC_ENABLE)
307 crc_init();
308#endif
300#ifdef VIA_ENABLE 309#ifdef VIA_ENABLE
301 via_init(); 310 via_init();
302#endif 311#endif
@@ -306,6 +315,9 @@ void keyboard_init(void) {
306#ifdef OLED_DRIVER_ENABLE 315#ifdef OLED_DRIVER_ENABLE
307 oled_init(OLED_ROTATION_0); 316 oled_init(OLED_ROTATION_0);
308#endif 317#endif
318#ifdef ST7565_ENABLE
319 st7565_init(DISPLAY_ROTATION_0);
320#endif
309#ifdef PS2_MOUSE_ENABLE 321#ifdef PS2_MOUSE_ENABLE
310 ps2_mouse_init(); 322 ps2_mouse_init();
311#endif 323#endif
@@ -470,6 +482,18 @@ MATRIX_LOOP_END:
470# endif 482# endif
471#endif 483#endif
472 484
485#ifdef ST7565_ENABLE
486 st7565_task();
487# ifndef ST7565_DISABLE_TIMEOUT
488 // Wake up display if user is using those fabulous keys or spinning those encoders!
489# ifdef ENCODER_ENABLE
490 if (matrix_changed || encoders_changed) st7565_on();
491# else
492 if (matrix_changed) st7565_on();
493# endif
494# endif
495#endif
496
473#ifdef MOUSEKEY_ENABLE 497#ifdef MOUSEKEY_ENABLE
474 // mousekey repeat & acceleration 498 // mousekey repeat & acceleration
475 mousekey_task(); 499 mousekey_task();
diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h
index 4e4771e52..3a7a16968 100644
--- a/tmk_core/common/progmem.h
+++ b/tmk_core/common/progmem.h
@@ -3,6 +3,7 @@
3#if defined(__AVR__) 3#if defined(__AVR__)
4# include <avr/pgmspace.h> 4# include <avr/pgmspace.h>
5#else 5#else
6# include <string.h>
6# define PROGMEM 7# define PROGMEM
7# define PSTR(x) x 8# define PSTR(x) x
8# define PGM_P const char* 9# define PGM_P const char*
diff --git a/tmk_core/common/sync_timer.c b/tmk_core/common/sync_timer.c
index de24b463b..68b92d8b4 100644
--- a/tmk_core/common/sync_timer.c
+++ b/tmk_core/common/sync_timer.c
@@ -26,7 +26,7 @@ SOFTWARE.
26#include "sync_timer.h" 26#include "sync_timer.h"
27#include "keyboard.h" 27#include "keyboard.h"
28 28
29#if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER) 29#if (defined(SPLIT_KEYBOARD) || defined(SERIAL_LINK_ENABLE)) && !defined(DISABLE_SYNC_TIMER)
30volatile int32_t sync_timer_ms; 30volatile int32_t sync_timer_ms;
31 31
32void sync_timer_init(void) { sync_timer_ms = 0; } 32void sync_timer_init(void) { sync_timer_ms = 0; }
diff --git a/tmk_core/common/sync_timer.h b/tmk_core/common/sync_timer.h
index 9ddef45bb..744e2b50d 100644
--- a/tmk_core/common/sync_timer.h
+++ b/tmk_core/common/sync_timer.h
@@ -32,7 +32,7 @@ SOFTWARE.
32extern "C" { 32extern "C" {
33#endif 33#endif
34 34
35#if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER) 35#if (defined(SPLIT_KEYBOARD) || defined(SERIAL_LINK_ENABLE)) && !defined(DISABLE_SYNC_TIMER)
36void sync_timer_init(void); 36void sync_timer_init(void);
37void sync_timer_update(uint32_t time); 37void sync_timer_update(uint32_t time);
38uint16_t sync_timer_read(void); 38uint16_t sync_timer_read(void);
diff --git a/tmk_core/common/timer.h b/tmk_core/common/timer.h
index abddcea85..02e39e79e 100644
--- a/tmk_core/common/timer.h
+++ b/tmk_core/common/timer.h
@@ -1,5 +1,6 @@
1/* 1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com> 2Copyright 2011 Jun Wako <wakojun@gmail.com>
3Copyright 2021 Simon Arlott
3 4
4This program is free software: you can redistribute it and/or modify 5This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by 6it under the terms of the GNU General Public License as published by
@@ -17,6 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17 18
18#pragma once 19#pragma once
19 20
21#if __has_include_next("_timer.h")
22# include_next "_timer.h" /* Include the platform's _timer.h */
23#endif
24
20#include <stdint.h> 25#include <stdint.h>
21 26
22#define TIMER_DIFF(a, b, max) ((max == UINT8_MAX) ? ((uint8_t)((a) - (b))) : ((max == UINT16_MAX) ? ((uint16_t)((a) - (b))) : ((max == UINT32_MAX) ? ((uint32_t)((a) - (b))) : ((a) >= (b) ? (a) - (b) : (max) + 1 - (b) + (a))))) 27#define TIMER_DIFF(a, b, max) ((max == UINT8_MAX) ? ((uint8_t)((a) - (b))) : ((max == UINT16_MAX) ? ((uint16_t)((a) - (b))) : ((max == UINT32_MAX) ? ((uint32_t)((a) - (b))) : ((a) >= (b) ? (a) - (b) : (max) + 1 - (b) + (a)))))
@@ -42,6 +47,21 @@ uint32_t timer_elapsed32(uint32_t last);
42#define timer_expired(current, future) ((uint16_t)(current - future) < UINT16_MAX / 2) 47#define timer_expired(current, future) ((uint16_t)(current - future) < UINT16_MAX / 2)
43#define timer_expired32(current, future) ((uint32_t)(current - future) < UINT32_MAX / 2) 48#define timer_expired32(current, future) ((uint32_t)(current - future) < UINT32_MAX / 2)
44 49
50// Use an appropriate timer integer size based on architecture (16-bit will overflow sooner)
51#if FAST_TIMER_T_SIZE < 32
52# define TIMER_DIFF_FAST(a, b) TIMER_DIFF_16(a, b)
53# define timer_expired_fast(current, future) timer_expired(current, future)
54typedef uint16_t fast_timer_t;
55fast_timer_t inline timer_read_fast(void) { return timer_read(); }
56fast_timer_t inline timer_elapsed_fast(fast_timer_t last) { return timer_elapsed(last); }
57#else
58# define TIMER_DIFF_FAST(a, b) TIMER_DIFF_32(a, b)
59# define timer_expired_fast(current, future) timer_expired32(current, future)
60typedef uint32_t fast_timer_t;
61fast_timer_t inline timer_read_fast(void) { return timer_read32(); }
62fast_timer_t inline timer_elapsed_fast(fast_timer_t last) { return timer_elapsed32(last); }
63#endif
64
45#ifdef __cplusplus 65#ifdef __cplusplus
46} 66}
47#endif 67#endif
diff --git a/tmk_core/common/usb_util.c b/tmk_core/common/usb_util.c
index d4134a044..dd1deeaa1 100644
--- a/tmk_core/common/usb_util.c
+++ b/tmk_core/common/usb_util.c
@@ -16,7 +16,7 @@
16#include "quantum.h" 16#include "quantum.h"
17#include "usb_util.h" 17#include "usb_util.h"
18 18
19__attribute__((weak)) void usb_disable(void) {} 19__attribute__((weak)) void usb_disconnect(void) {}
20__attribute__((weak)) bool usb_connected_state(void) { return true; } 20__attribute__((weak)) bool usb_connected_state(void) { return true; }
21__attribute__((weak)) bool usb_vbus_state(void) { 21__attribute__((weak)) bool usb_vbus_state(void) {
22#ifdef USB_VBUS_PIN 22#ifdef USB_VBUS_PIN
diff --git a/tmk_core/common/usb_util.h b/tmk_core/common/usb_util.h
index 4ebedb1e7..13db9fbfb 100644
--- a/tmk_core/common/usb_util.h
+++ b/tmk_core/common/usb_util.h
@@ -17,6 +17,6 @@
17 17
18#include <stdbool.h> 18#include <stdbool.h>
19 19
20void usb_disable(void); 20void usb_disconnect(void);
21bool usb_connected_state(void); 21bool usb_connected_state(void);
22bool usb_vbus_state(void); 22bool usb_vbus_state(void);