diff options
author | Joel Challis <git@zvecr.com> | 2021-10-28 22:31:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-28 22:31:59 +0100 |
commit | dcfffa7b67a072f7d9e37bd8c0029c53b61aeb0f (patch) | |
tree | 65491c3878ee76f50c4b46a318503cc27fdb4a6b /tmk_core | |
parent | 0c87e2e7025140ca6105b7fec2639c78c3cd8109 (diff) | |
download | qmk_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.mk | 4 | ||||
-rw-r--r-- | tmk_core/common/raw_hid.h | 5 | ||||
-rw-r--r-- | tmk_core/common/sync_timer.c | 58 | ||||
-rw-r--r-- | tmk_core/common/sync_timer.h | 54 | ||||
-rw-r--r-- | tmk_core/common/virtser.h | 7 | ||||
-rw-r--r-- | tmk_core/protocol.mk | 6 | ||||
-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.c | 51 | ||||
-rw-r--r-- | tmk_core/protocol/usb_device_state.h | 39 | ||||
-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 ce335f0d3c..8fa1a31e80 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -2,10 +2,6 @@ COMMON_DIR = common PLATFORM_COMMON_DIR = $(COMMON_DIR)/$(PLATFORM_KEY) TMK_COMMON_SRC += \ - $(COMMON_DIR)/host.c \ - $(COMMON_DIR)/report.c \ - $(COMMON_DIR)/sync_timer.c \ - $(COMMON_DIR)/usb_util.c \ $(PLATFORM_COMMON_DIR)/platform.c \ $(PLATFORM_COMMON_DIR)/suspend.c \ $(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 6d60ab2bff..0000000000 --- a/tmk_core/common/raw_hid.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -void raw_hid_receive(uint8_t *data, uint8_t length); - -void 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 de24b463b6..0000000000 --- a/tmk_core/common/sync_timer.c +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright (C) 2020 Ryan Caltabiano <https://github.com/XScorpion2> - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -If you happen to meet one of the copyright holders in a bar you are obligated -to buy them one pint of beer. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "sync_timer.h" -#include "keyboard.h" - -#if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER) -volatile int32_t sync_timer_ms; - -void sync_timer_init(void) { sync_timer_ms = 0; } - -void sync_timer_update(uint32_t time) { - if (is_keyboard_master()) return; - sync_timer_ms = time - timer_read32(); -} - -uint16_t sync_timer_read(void) { - if (is_keyboard_master()) return timer_read(); - return sync_timer_read32(); -} - -uint32_t sync_timer_read32(void) { - if (is_keyboard_master()) return timer_read32(); - return sync_timer_ms + timer_read32(); -} - -uint16_t sync_timer_elapsed(uint16_t last) { - if (is_keyboard_master()) return timer_elapsed(last); - return TIMER_DIFF_16(sync_timer_read(), last); -} - -uint32_t sync_timer_elapsed32(uint32_t last) { - if (is_keyboard_master()) return timer_elapsed32(last); - return TIMER_DIFF_32(sync_timer_read32(), last); -} -#endif diff --git a/tmk_core/common/sync_timer.h b/tmk_core/common/sync_timer.h deleted file mode 100644 index 9ddef45bb2..0000000000 --- a/tmk_core/common/sync_timer.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright (C) 2020 Ryan Caltabiano <https://github.com/XScorpion2> - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -If you happen to meet one of the copyright holders in a bar you are obligated -to buy them one pint of beer. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#pragma once - -#include <stdint.h> -#include "timer.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER) -void sync_timer_init(void); -void sync_timer_update(uint32_t time); -uint16_t sync_timer_read(void); -uint32_t sync_timer_read32(void); -uint16_t sync_timer_elapsed(uint16_t last); -uint32_t sync_timer_elapsed32(uint32_t last); -#else -# define sync_timer_init() -# define sync_timer_clear() -# define sync_timer_update(t) -# define sync_timer_read() timer_read() -# define sync_timer_read32() timer_read32() -# define sync_timer_elapsed(t) timer_elapsed(t) -# define sync_timer_elapsed32(t) timer_elapsed32(t) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/tmk_core/common/virtser.h b/tmk_core/common/virtser.h deleted file mode 100644 index a0645f9e03..0000000000 --- a/tmk_core/common/virtser.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -/* Define this function in your code to process incoming bytes */ -void virtser_recv(const uint8_t ch); - -/* Call this to send a character over the Virtual Serial Device */ -void virtser_send(const uint8_t byte); diff --git a/tmk_core/protocol.mk b/tmk_core/protocol.mk index d4ad50db6a..359ddbfef1 100644 --- a/tmk_core/protocol.mk +++ b/tmk_core/protocol.mk @@ -1,5 +1,11 @@ PROTOCOL_DIR = protocol +TMK_COMMON_SRC += \ + $(PROTOCOL_DIR)/host.c \ + $(PROTOCOL_DIR)/report.c \ + $(PROTOCOL_DIR)/usb_device_state.c \ + $(PROTOCOL_DIR)/usb_util.c \ + ifeq ($(strip $(USB_HID_ENABLE)), yes) include $(TMK_DIR)/protocol/usb_hid.mk endif diff --git a/tmk_core/common/host.c b/tmk_core/protocol/host.c index 56d4bb0847..56d4bb0847 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 6b15f0d0c1..6b15f0d0c1 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 affd0dcb34..affd0dcb34 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 2a7fc006c4..854b59ae48 100644 --- a/tmk_core/common/report.c +++ b/tmk_core/protocol/report.c @@ -24,8 +24,8 @@ #ifdef RING_BUFFERED_6KRO_REPORT_ENABLE # define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) # define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS) -# define RO_INC(a) RO_ADD(a, 1) -# define RO_DEC(a) RO_SUB(a, 1) +# define RO_INC(a) RO_ADD(a, 1) +# define RO_DEC(a) RO_SUB(a, 1) static int8_t cb_head = 0; static int8_t cb_tail = 0; static int8_t cb_count = 0; diff --git a/tmk_core/common/report.h b/tmk_core/protocol/report.h index 1adc892f3b..1adc892f3b 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 0000000000..5ccd309ec2 --- /dev/null +++ b/tmk_core/protocol/usb_device_state.c @@ -0,0 +1,51 @@ +/* + * Copyright 2021 Andrei Purdea <andrei@purdea.ro> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "usb_device_state.h" + +enum usb_device_state usb_device_state = USB_DEVICE_STATE_NO_INIT; + +__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); } + +__attribute__((weak)) void notify_usb_device_state_change_user(enum usb_device_state usb_device_state) {} + +static void notify_usb_device_state_change(enum usb_device_state usb_device_state) { notify_usb_device_state_change_kb(usb_device_state); } + +void usb_device_state_set_configuration(bool isConfigured, uint8_t configurationNumber) { + usb_device_state = isConfigured ? USB_DEVICE_STATE_CONFIGURED : USB_DEVICE_STATE_INIT; + notify_usb_device_state_change(usb_device_state); +} + +void usb_device_state_set_suspend(bool isConfigured, uint8_t configurationNumber) { + usb_device_state = USB_DEVICE_STATE_SUSPEND; + notify_usb_device_state_change(usb_device_state); +} + +void usb_device_state_set_resume(bool isConfigured, uint8_t configurationNumber) { + usb_device_state = isConfigured ? USB_DEVICE_STATE_CONFIGURED : USB_DEVICE_STATE_INIT; + notify_usb_device_state_change(usb_device_state); +} + +void usb_device_state_set_reset(void) { + usb_device_state = USB_DEVICE_STATE_INIT; + notify_usb_device_state_change(usb_device_state); +} + +void usb_device_state_init(void) { + usb_device_state = USB_DEVICE_STATE_INIT; + notify_usb_device_state_change(usb_device_state); +} diff --git a/tmk_core/protocol/usb_device_state.h b/tmk_core/protocol/usb_device_state.h new file mode 100644 index 0000000000..c229311d46 --- /dev/null +++ b/tmk_core/protocol/usb_device_state.h @@ -0,0 +1,39 @@ +/* + * Copyright 2021 Andrei Purdea <andrei@purdea.ro> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <stdbool.h> +#include <stdint.h> + +void usb_device_state_set_configuration(bool isConfigured, uint8_t configurationNumber); +void usb_device_state_set_suspend(bool isConfigured, uint8_t configurationNumber); +void usb_device_state_set_resume(bool isConfigured, uint8_t configurationNumber); +void usb_device_state_set_reset(void); +void usb_device_state_init(void); + +enum usb_device_state { + USB_DEVICE_STATE_NO_INIT = 0, // We're in this state before calling usb_device_state_init() + USB_DEVICE_STATE_INIT = 1, // Can consume up to 100mA + USB_DEVICE_STATE_CONFIGURED = 2, // Can consume up to what is specified in configuration descriptor, typically 500mA + USB_DEVICE_STATE_SUSPEND = 3 // Can consume only suspend current +}; + +extern enum usb_device_state usb_device_state; + +void notify_usb_device_state_change_kb(enum usb_device_state usb_device_state); +void 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 dd1deeaa11..dd1deeaa11 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 13db9fbfbd..13db9fbfbd 100644 --- a/tmk_core/common/usb_util.h +++ b/tmk_core/protocol/usb_util.h |