diff options
author | XScorpion2 <rcalt2vt@gmail.com> | 2020-12-01 12:04:42 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-01 10:04:42 -0800 |
commit | a8d0ec0749046b0ab89c18b1b7083b1e8674de2a (patch) | |
tree | 06c81bed47c6f4128bf0fc33697646994bffab00 /tmk_core | |
parent | 9c03a8959621016d27fdd7cdfbabce28fd7d1757 (diff) | |
download | qmk_firmware-a8d0ec0749046b0ab89c18b1b7083b1e8674de2a.tar.gz qmk_firmware-a8d0ec0749046b0ab89c18b1b7083b1e8674de2a.zip |
[Split] Sync Timer feature (#10997)
A timer that is kept in sync between the halves of a split keyboard
Diffstat (limited to 'tmk_core')
-rw-r--r-- | tmk_core/common.mk | 1 | ||||
-rw-r--r-- | tmk_core/common/keyboard.c | 2 | ||||
-rw-r--r-- | tmk_core/common/sync_timer.c | 58 | ||||
-rw-r--r-- | tmk_core/common/sync_timer.h | 54 |
4 files changed, 115 insertions, 0 deletions
diff --git a/tmk_core/common.mk b/tmk_core/common.mk index fdf2aa097..05839824c 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk | |||
@@ -18,6 +18,7 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ | |||
18 | $(COMMON_DIR)/report.c \ | 18 | $(COMMON_DIR)/report.c \ |
19 | $(PLATFORM_COMMON_DIR)/suspend.c \ | 19 | $(PLATFORM_COMMON_DIR)/suspend.c \ |
20 | $(PLATFORM_COMMON_DIR)/timer.c \ | 20 | $(PLATFORM_COMMON_DIR)/timer.c \ |
21 | $(COMMON_DIR)/sync_timer.c \ | ||
21 | $(PLATFORM_COMMON_DIR)/bootloader.c \ | 22 | $(PLATFORM_COMMON_DIR)/bootloader.c \ |
22 | 23 | ||
23 | ifeq ($(PLATFORM),AVR) | 24 | ifeq ($(PLATFORM),AVR) |
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 8c7bdc8b5..a1fbc01da 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c | |||
@@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
23 | #include "led.h" | 23 | #include "led.h" |
24 | #include "keycode.h" | 24 | #include "keycode.h" |
25 | #include "timer.h" | 25 | #include "timer.h" |
26 | #include "sync_timer.h" | ||
26 | #include "print.h" | 27 | #include "print.h" |
27 | #include "debug.h" | 28 | #include "debug.h" |
28 | #include "command.h" | 29 | #include "command.h" |
@@ -255,6 +256,7 @@ __attribute__((weak)) void housekeeping_task_user(void) {} | |||
255 | */ | 256 | */ |
256 | void keyboard_init(void) { | 257 | void keyboard_init(void) { |
257 | timer_init(); | 258 | timer_init(); |
259 | sync_timer_init(); | ||
258 | matrix_init(); | 260 | matrix_init(); |
259 | #ifdef VIA_ENABLE | 261 | #ifdef VIA_ENABLE |
260 | via_init(); | 262 | via_init(); |
diff --git a/tmk_core/common/sync_timer.c b/tmk_core/common/sync_timer.c new file mode 100644 index 000000000..de24b463b --- /dev/null +++ b/tmk_core/common/sync_timer.c | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | Copyright (C) 2020 Ryan Caltabiano <https://github.com/XScorpion2> | ||
3 | |||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
5 | this software and associated documentation files (the "Software"), to deal in | ||
6 | the Software without restriction, including without limitation the rights to | ||
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
8 | of the Software, and to permit persons to whom the Software is furnished to do | ||
9 | so, subject to the following conditions: | ||
10 | |||
11 | The above copyright notice and this permission notice shall be included in all | ||
12 | copies or substantial portions of the Software. | ||
13 | |||
14 | If you happen to meet one of the copyright holders in a bar you are obligated | ||
15 | to buy them one pint of beer. | ||
16 | |||
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
23 | SOFTWARE. | ||
24 | */ | ||
25 | |||
26 | #include "sync_timer.h" | ||
27 | #include "keyboard.h" | ||
28 | |||
29 | #if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER) | ||
30 | volatile int32_t sync_timer_ms; | ||
31 | |||
32 | void sync_timer_init(void) { sync_timer_ms = 0; } | ||
33 | |||
34 | void sync_timer_update(uint32_t time) { | ||
35 | if (is_keyboard_master()) return; | ||
36 | sync_timer_ms = time - timer_read32(); | ||
37 | } | ||
38 | |||
39 | uint16_t sync_timer_read(void) { | ||
40 | if (is_keyboard_master()) return timer_read(); | ||
41 | return sync_timer_read32(); | ||
42 | } | ||
43 | |||
44 | uint32_t sync_timer_read32(void) { | ||
45 | if (is_keyboard_master()) return timer_read32(); | ||
46 | return sync_timer_ms + timer_read32(); | ||
47 | } | ||
48 | |||
49 | uint16_t sync_timer_elapsed(uint16_t last) { | ||
50 | if (is_keyboard_master()) return timer_elapsed(last); | ||
51 | return TIMER_DIFF_16(sync_timer_read(), last); | ||
52 | } | ||
53 | |||
54 | uint32_t sync_timer_elapsed32(uint32_t last) { | ||
55 | if (is_keyboard_master()) return timer_elapsed32(last); | ||
56 | return TIMER_DIFF_32(sync_timer_read32(), last); | ||
57 | } | ||
58 | #endif | ||
diff --git a/tmk_core/common/sync_timer.h b/tmk_core/common/sync_timer.h new file mode 100644 index 000000000..9ddef45bb --- /dev/null +++ b/tmk_core/common/sync_timer.h | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | Copyright (C) 2020 Ryan Caltabiano <https://github.com/XScorpion2> | ||
3 | |||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
5 | this software and associated documentation files (the "Software"), to deal in | ||
6 | the Software without restriction, including without limitation the rights to | ||
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
8 | of the Software, and to permit persons to whom the Software is furnished to do | ||
9 | so, subject to the following conditions: | ||
10 | |||
11 | The above copyright notice and this permission notice shall be included in all | ||
12 | copies or substantial portions of the Software. | ||
13 | |||
14 | If you happen to meet one of the copyright holders in a bar you are obligated | ||
15 | to buy them one pint of beer. | ||
16 | |||
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
23 | SOFTWARE. | ||
24 | */ | ||
25 | |||
26 | #pragma once | ||
27 | |||
28 | #include <stdint.h> | ||
29 | #include "timer.h" | ||
30 | |||
31 | #ifdef __cplusplus | ||
32 | extern "C" { | ||
33 | #endif | ||
34 | |||
35 | #if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER) | ||
36 | void sync_timer_init(void); | ||
37 | void sync_timer_update(uint32_t time); | ||
38 | uint16_t sync_timer_read(void); | ||
39 | uint32_t sync_timer_read32(void); | ||
40 | uint16_t sync_timer_elapsed(uint16_t last); | ||
41 | uint32_t sync_timer_elapsed32(uint32_t last); | ||
42 | #else | ||
43 | # define sync_timer_init() | ||
44 | # define sync_timer_clear() | ||
45 | # define sync_timer_update(t) | ||
46 | # define sync_timer_read() timer_read() | ||
47 | # define sync_timer_read32() timer_read32() | ||
48 | # define sync_timer_elapsed(t) timer_elapsed(t) | ||
49 | # define sync_timer_elapsed32(t) timer_elapsed32(t) | ||
50 | #endif | ||
51 | |||
52 | #ifdef __cplusplus | ||
53 | } | ||
54 | #endif | ||