aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-10-28 22:31:59 +0100
committerGitHub <noreply@github.com>2021-10-28 22:31:59 +0100
commitdcfffa7b67a072f7d9e37bd8c0029c53b61aeb0f (patch)
tree65491c3878ee76f50c4b46a318503cc27fdb4a6b /tmk_core
parent0c87e2e7025140ca6105b7fec2639c78c3cd8109 (diff)
downloadqmk_firmware-dcfffa7b67a072f7d9e37bd8c0029c53b61aeb0f.tar.gz
qmk_firmware-dcfffa7b67a072f7d9e37bd8c0029c53b61aeb0f.zip
Relocate protocol files within tmk_core/common/ (#14972)
* Relocate non platform files within tmk_core/common/ * clang
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common.mk4
-rw-r--r--tmk_core/common/raw_hid.h5
-rw-r--r--tmk_core/common/sync_timer.c58
-rw-r--r--tmk_core/common/sync_timer.h54
-rw-r--r--tmk_core/common/virtser.h7
-rw-r--r--tmk_core/protocol.mk6
-rw-r--r--tmk_core/protocol/host.c (renamed from tmk_core/common/host.c)0
-rw-r--r--tmk_core/protocol/host.h (renamed from tmk_core/common/host.h)0
-rw-r--r--tmk_core/protocol/host_driver.h (renamed from tmk_core/common/host_driver.h)0
-rw-r--r--tmk_core/protocol/report.c (renamed from tmk_core/common/report.c)4
-rw-r--r--tmk_core/protocol/report.h (renamed from tmk_core/common/report.h)0
-rw-r--r--tmk_core/protocol/usb_device_state.c51
-rw-r--r--tmk_core/protocol/usb_device_state.h39
-rw-r--r--tmk_core/protocol/usb_util.c (renamed from tmk_core/common/usb_util.c)0
-rw-r--r--tmk_core/protocol/usb_util.h (renamed from tmk_core/common/usb_util.h)0
15 files changed, 98 insertions, 130 deletions
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index ce335f0d3..8fa1a31e8 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -2,10 +2,6 @@ COMMON_DIR = common
2PLATFORM_COMMON_DIR = $(COMMON_DIR)/$(PLATFORM_KEY) 2PLATFORM_COMMON_DIR = $(COMMON_DIR)/$(PLATFORM_KEY)
3 3
4TMK_COMMON_SRC += \ 4TMK_COMMON_SRC += \
5 $(COMMON_DIR)/host.c \
6 $(COMMON_DIR)/report.c \
7 $(COMMON_DIR)/sync_timer.c \
8 $(COMMON_DIR)/usb_util.c \
9 $(PLATFORM_COMMON_DIR)/platform.c \ 5 $(PLATFORM_COMMON_DIR)/platform.c \
10 $(PLATFORM_COMMON_DIR)/suspend.c \ 6 $(PLATFORM_COMMON_DIR)/suspend.c \
11 $(PLATFORM_COMMON_DIR)/timer.c \ 7 $(PLATFORM_COMMON_DIR)/timer.c \
diff --git a/tmk_core/common/raw_hid.h b/tmk_core/common/raw_hid.h
deleted file mode 100644
index 6d60ab2bf..000000000
--- a/tmk_core/common/raw_hid.h
+++ /dev/null
@@ -1,5 +0,0 @@
1#pragma once
2
3void raw_hid_receive(uint8_t *data, uint8_t length);
4
5void raw_hid_send(uint8_t *data, uint8_t length);
diff --git a/tmk_core/common/sync_timer.c b/tmk_core/common/sync_timer.c
deleted file mode 100644
index de24b463b..000000000
--- a/tmk_core/common/sync_timer.c
+++ /dev/null
@@ -1,58 +0,0 @@
1/*
2Copyright (C) 2020 Ryan Caltabiano <https://github.com/XScorpion2>
3
4Permission is hereby granted, free of charge, to any person obtaining a copy of
5this software and associated documentation files (the "Software"), to deal in
6the Software without restriction, including without limitation the rights to
7use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8of the Software, and to permit persons to whom the Software is furnished to do
9so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14If you happen to meet one of the copyright holders in a bar you are obligated
15to buy them one pint of beer.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24*/
25
26#include "sync_timer.h"
27#include "keyboard.h"
28
29#if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER)
30volatile int32_t sync_timer_ms;
31
32void sync_timer_init(void) { sync_timer_ms = 0; }
33
34void sync_timer_update(uint32_t time) {
35 if (is_keyboard_master()) return;
36 sync_timer_ms = time - timer_read32();
37}
38
39uint16_t sync_timer_read(void) {
40 if (is_keyboard_master()) return timer_read();
41 return sync_timer_read32();
42}
43
44uint32_t sync_timer_read32(void) {
45 if (is_keyboard_master()) return timer_read32();
46 return sync_timer_ms + timer_read32();
47}
48
49uint16_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
54uint32_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
deleted file mode 100644
index 9ddef45bb..000000000
--- a/tmk_core/common/sync_timer.h
+++ /dev/null
@@ -1,54 +0,0 @@
1/*
2Copyright (C) 2020 Ryan Caltabiano <https://github.com/XScorpion2>
3
4Permission is hereby granted, free of charge, to any person obtaining a copy of
5this software and associated documentation files (the "Software"), to deal in
6the Software without restriction, including without limitation the rights to
7use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8of the Software, and to permit persons to whom the Software is furnished to do
9so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14If you happen to meet one of the copyright holders in a bar you are obligated
15to buy them one pint of beer.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24*/
25
26#pragma once
27
28#include <stdint.h>
29#include "timer.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER)
36void sync_timer_init(void);
37void sync_timer_update(uint32_t time);
38uint16_t sync_timer_read(void);
39uint32_t sync_timer_read32(void);
40uint16_t sync_timer_elapsed(uint16_t last);
41uint32_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
diff --git a/tmk_core/common/virtser.h b/tmk_core/common/virtser.h
deleted file mode 100644
index a0645f9e0..000000000
--- a/tmk_core/common/virtser.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#pragma once
2
3/* Define this function in your code to process incoming bytes */
4void virtser_recv(const uint8_t ch);
5
6/* Call this to send a character over the Virtual Serial Device */
7void virtser_send(const uint8_t byte);
diff --git a/tmk_core/protocol.mk b/tmk_core/protocol.mk
index d4ad50db6..359ddbfef 100644
--- a/tmk_core/protocol.mk
+++ b/tmk_core/protocol.mk
@@ -1,5 +1,11 @@
1PROTOCOL_DIR = protocol 1PROTOCOL_DIR = protocol
2 2
3TMK_COMMON_SRC += \
4 $(PROTOCOL_DIR)/host.c \
5 $(PROTOCOL_DIR)/report.c \
6 $(PROTOCOL_DIR)/usb_device_state.c \
7 $(PROTOCOL_DIR)/usb_util.c \
8
3ifeq ($(strip $(USB_HID_ENABLE)), yes) 9ifeq ($(strip $(USB_HID_ENABLE)), yes)
4 include $(TMK_DIR)/protocol/usb_hid.mk 10 include $(TMK_DIR)/protocol/usb_hid.mk
5endif 11endif
diff --git a/tmk_core/common/host.c b/tmk_core/protocol/host.c
index 56d4bb084..56d4bb084 100644
--- a/tmk_core/common/host.c
+++ b/tmk_core/protocol/host.c
diff --git a/tmk_core/common/host.h b/tmk_core/protocol/host.h
index 6b15f0d0c..6b15f0d0c 100644
--- a/tmk_core/common/host.h
+++ b/tmk_core/protocol/host.h
diff --git a/tmk_core/common/host_driver.h b/tmk_core/protocol/host_driver.h
index affd0dcb3..affd0dcb3 100644
--- a/tmk_core/common/host_driver.h
+++ b/tmk_core/protocol/host_driver.h
diff --git a/tmk_core/common/report.c b/tmk_core/protocol/report.c
index 2a7fc006c..854b59ae4 100644
--- a/tmk_core/common/report.c
+++ b/tmk_core/protocol/report.c
@@ -24,8 +24,8 @@
24#ifdef RING_BUFFERED_6KRO_REPORT_ENABLE 24#ifdef RING_BUFFERED_6KRO_REPORT_ENABLE
25# define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) 25# define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS)
26# define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS) 26# define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS)
27# define RO_INC(a) RO_ADD(a, 1) 27# define RO_INC(a) RO_ADD(a, 1)
28# define RO_DEC(a) RO_SUB(a, 1) 28# define RO_DEC(a) RO_SUB(a, 1)
29static int8_t cb_head = 0; 29static int8_t cb_head = 0;
30static int8_t cb_tail = 0; 30static int8_t cb_tail = 0;
31static int8_t cb_count = 0; 31static int8_t cb_count = 0;
diff --git a/tmk_core/common/report.h b/tmk_core/protocol/report.h
index 1adc892f3..1adc892f3 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/protocol/report.h
diff --git a/tmk_core/protocol/usb_device_state.c b/tmk_core/protocol/usb_device_state.c
new file mode 100644
index 000000000..5ccd309ec
--- /dev/null
+++ b/tmk_core/protocol/usb_device_state.c
@@ -0,0 +1,51 @@
1/*
2 * Copyright 2021 Andrei Purdea <andrei@purdea.ro>
3 *
4 * 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 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "usb_device_state.h"
19
20enum usb_device_state usb_device_state = USB_DEVICE_STATE_NO_INIT;
21
22__attribute__((weak)) void notify_usb_device_state_change_kb(enum usb_device_state usb_device_state) { notify_usb_device_state_change_user(usb_device_state); }
23
24__attribute__((weak)) void notify_usb_device_state_change_user(enum usb_device_state usb_device_state) {}
25
26static void notify_usb_device_state_change(enum usb_device_state usb_device_state) { notify_usb_device_state_change_kb(usb_device_state); }
27
28void usb_device_state_set_configuration(bool isConfigured, uint8_t configurationNumber) {
29 usb_device_state = isConfigured ? USB_DEVICE_STATE_CONFIGURED : USB_DEVICE_STATE_INIT;
30 notify_usb_device_state_change(usb_device_state);
31}
32
33void usb_device_state_set_suspend(bool isConfigured, uint8_t configurationNumber) {
34 usb_device_state = USB_DEVICE_STATE_SUSPEND;
35 notify_usb_device_state_change(usb_device_state);
36}
37
38void usb_device_state_set_resume(bool isConfigured, uint8_t configurationNumber) {
39 usb_device_state = isConfigured ? USB_DEVICE_STATE_CONFIGURED : USB_DEVICE_STATE_INIT;
40 notify_usb_device_state_change(usb_device_state);
41}
42
43void usb_device_state_set_reset(void) {
44 usb_device_state = USB_DEVICE_STATE_INIT;
45 notify_usb_device_state_change(usb_device_state);
46}
47
48void usb_device_state_init(void) {
49 usb_device_state = USB_DEVICE_STATE_INIT;
50 notify_usb_device_state_change(usb_device_state);
51}
diff --git a/tmk_core/protocol/usb_device_state.h b/tmk_core/protocol/usb_device_state.h
new file mode 100644
index 000000000..c229311d4
--- /dev/null
+++ b/tmk_core/protocol/usb_device_state.h
@@ -0,0 +1,39 @@
1/*
2 * Copyright 2021 Andrei Purdea <andrei@purdea.ro>
3 *
4 * 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 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <stdbool.h>
21#include <stdint.h>
22
23void usb_device_state_set_configuration(bool isConfigured, uint8_t configurationNumber);
24void usb_device_state_set_suspend(bool isConfigured, uint8_t configurationNumber);
25void usb_device_state_set_resume(bool isConfigured, uint8_t configurationNumber);
26void usb_device_state_set_reset(void);
27void usb_device_state_init(void);
28
29enum usb_device_state {
30 USB_DEVICE_STATE_NO_INIT = 0, // We're in this state before calling usb_device_state_init()
31 USB_DEVICE_STATE_INIT = 1, // Can consume up to 100mA
32 USB_DEVICE_STATE_CONFIGURED = 2, // Can consume up to what is specified in configuration descriptor, typically 500mA
33 USB_DEVICE_STATE_SUSPEND = 3 // Can consume only suspend current
34};
35
36extern enum usb_device_state usb_device_state;
37
38void notify_usb_device_state_change_kb(enum usb_device_state usb_device_state);
39void notify_usb_device_state_change_user(enum usb_device_state usb_device_state);
diff --git a/tmk_core/common/usb_util.c b/tmk_core/protocol/usb_util.c
index dd1deeaa1..dd1deeaa1 100644
--- a/tmk_core/common/usb_util.c
+++ b/tmk_core/protocol/usb_util.c
diff --git a/tmk_core/common/usb_util.h b/tmk_core/protocol/usb_util.h
index 13db9fbfb..13db9fbfb 100644
--- a/tmk_core/common/usb_util.h
+++ b/tmk_core/protocol/usb_util.h