diff options
Diffstat (limited to 'tmk_core/common')
-rw-r--r-- | tmk_core/common/arm_atsam/_timer.h | 19 | ||||
-rw-r--r-- | tmk_core/common/avr/_timer.h | 19 | ||||
-rw-r--r-- | tmk_core/common/avr/gpio.h | 15 | ||||
-rw-r--r-- | tmk_core/common/chibios/_timer.h | 19 | ||||
-rw-r--r-- | tmk_core/common/chibios/bootloader.c | 2 | ||||
-rw-r--r-- | tmk_core/common/chibios/gpio.h | 16 | ||||
-rw-r--r-- | tmk_core/common/host.c | 14 | ||||
-rw-r--r-- | tmk_core/common/keyboard.c | 24 | ||||
-rw-r--r-- | tmk_core/common/timer.h | 24 |
9 files changed, 143 insertions, 9 deletions
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 | ||
21 | typedef uint8_t pin_t; | 21 | typedef 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 | |||
40 | typedef 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..76d52ea60 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) |
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 | ||
21 | typedef ioline_t pin_t; | 21 | typedef 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 | |||
40 | typedef 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 | ||
36 | host_driver_t *host_get_driver(void) { return driver; } | 37 | host_driver_t *host_get_driver(void) { return driver; } |
37 | 38 | ||
39 | #ifdef SPLIT_KEYBOARD | ||
40 | uint8_t split_led_state = 0; | ||
41 | void set_split_host_keyboard_leds(uint8_t led_state) { split_led_state = led_state; } | ||
42 | #endif | ||
43 | |||
38 | uint8_t host_keyboard_leds(void) { | 44 | uint8_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 | ||
43 | led_t host_keyboard_led_state(void) { | 52 | led_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 */ |
49 | void host_keyboard_send(report_keyboard_t *report) { | 55 | void 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 | ||
104 | static uint32_t last_input_modification_time = 0; | 110 | static uint32_t last_input_modification_time = 0; |
105 | uint32_t last_input_activity_time(void) { return last_input_modification_time; } | 111 | uint32_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/timer.h b/tmk_core/common/timer.h index 58f637dd9..928811a2b 100644 --- a/tmk_core/common/timer.h +++ b/tmk_core/common/timer.h | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> |
3 | Copyright 2021 Simon Arlott | ||
3 | 4 | ||
4 | This program is free software: you can redistribute it and/or modify | 5 | 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 | it under the terms of the GNU General Public License as published by |
@@ -17,13 +18,13 @@ 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 | #include <stdbool.h> | 26 | #include <stdbool.h> |
22 | 27 | ||
23 | #if defined(__AVR__) | ||
24 | # include "avr/timer_avr.h" | ||
25 | #endif | ||
26 | |||
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))))) | 28 | #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))))) |
28 | #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) | 29 | #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) |
29 | #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) | 30 | #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) |
@@ -47,6 +48,21 @@ uint32_t timer_elapsed32(uint32_t last); | |||
47 | #define timer_expired(current, future) ((uint16_t)(current - future) < UINT16_MAX / 2) | 48 | #define timer_expired(current, future) ((uint16_t)(current - future) < UINT16_MAX / 2) |
48 | #define timer_expired32(current, future) ((uint32_t)(current - future) < UINT32_MAX / 2) | 49 | #define timer_expired32(current, future) ((uint32_t)(current - future) < UINT32_MAX / 2) |
49 | 50 | ||
51 | // Use an appropriate timer integer size based on architecture (16-bit will overflow sooner) | ||
52 | #if FAST_TIMER_T_SIZE < 32 | ||
53 | # define TIMER_DIFF_FAST(a, b) TIMER_DIFF_16(a, b) | ||
54 | # define timer_expired_fast(current, future) timer_expired(current, future) | ||
55 | typedef uint16_t fast_timer_t; | ||
56 | fast_timer_t inline timer_read_fast(void) { return timer_read(); } | ||
57 | fast_timer_t inline timer_elapsed_fast(fast_timer_t last) { return timer_elapsed(last); } | ||
58 | #else | ||
59 | # define TIMER_DIFF_FAST(a, b) TIMER_DIFF_32(a, b) | ||
60 | # define timer_expired_fast(current, future) timer_expired32(current, future) | ||
61 | typedef uint32_t fast_timer_t; | ||
62 | fast_timer_t inline timer_read_fast(void) { return timer_read32(); } | ||
63 | fast_timer_t inline timer_elapsed_fast(fast_timer_t last) { return timer_elapsed32(last); } | ||
64 | #endif | ||
65 | |||
50 | #ifdef __cplusplus | 66 | #ifdef __cplusplus |
51 | } | 67 | } |
52 | #endif | 68 | #endif |