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 /quantum | |
| 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 'quantum')
| -rw-r--r-- | quantum/keyboard.c | 3 | ||||
| -rw-r--r-- | quantum/raw_hid.h | 5 | ||||
| -rw-r--r-- | quantum/sync_timer.c | 58 | ||||
| -rw-r--r-- | quantum/sync_timer.h | 54 | ||||
| -rw-r--r-- | quantum/usb_device_state.c | 51 | ||||
| -rw-r--r-- | quantum/usb_device_state.h | 39 | ||||
| -rw-r--r-- | quantum/virtser.h | 9 |
7 files changed, 129 insertions, 90 deletions
diff --git a/quantum/keyboard.c b/quantum/keyboard.c index 030fec2d3..806e4ef7e 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c | |||
| @@ -94,6 +94,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 94 | #ifdef DIGITIZER_ENABLE | 94 | #ifdef DIGITIZER_ENABLE |
| 95 | # include "digitizer.h" | 95 | # include "digitizer.h" |
| 96 | #endif | 96 | #endif |
| 97 | #ifdef VIRTSER_ENABLE | ||
| 98 | # include "virtser.h" | ||
| 99 | #endif | ||
| 97 | 100 | ||
| 98 | static uint32_t last_input_modification_time = 0; | 101 | static uint32_t last_input_modification_time = 0; |
| 99 | uint32_t last_input_activity_time(void) { return last_input_modification_time; } | 102 | uint32_t last_input_activity_time(void) { return last_input_modification_time; } |
diff --git a/quantum/raw_hid.h b/quantum/raw_hid.h new file mode 100644 index 000000000..6d60ab2bf --- /dev/null +++ b/quantum/raw_hid.h | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | void raw_hid_receive(uint8_t *data, uint8_t length); | ||
| 4 | |||
| 5 | void raw_hid_send(uint8_t *data, uint8_t length); | ||
diff --git a/quantum/sync_timer.c b/quantum/sync_timer.c new file mode 100644 index 000000000..de24b463b --- /dev/null +++ b/quantum/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/quantum/sync_timer.h b/quantum/sync_timer.h new file mode 100644 index 000000000..9ddef45bb --- /dev/null +++ b/quantum/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 | ||
diff --git a/quantum/usb_device_state.c b/quantum/usb_device_state.c deleted file mode 100644 index 5ccd309ec..000000000 --- a/quantum/usb_device_state.c +++ /dev/null | |||
| @@ -1,51 +0,0 @@ | |||
| 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 | |||
| 20 | enum 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 | |||
| 26 | static void notify_usb_device_state_change(enum usb_device_state usb_device_state) { notify_usb_device_state_change_kb(usb_device_state); } | ||
| 27 | |||
| 28 | void 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 | |||
| 33 | void 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 | |||
| 38 | void 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 | |||
| 43 | void 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 | |||
| 48 | void 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/quantum/usb_device_state.h b/quantum/usb_device_state.h deleted file mode 100644 index c229311d4..000000000 --- a/quantum/usb_device_state.h +++ /dev/null | |||
| @@ -1,39 +0,0 @@ | |||
| 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 | |||
| 23 | void usb_device_state_set_configuration(bool isConfigured, uint8_t configurationNumber); | ||
| 24 | void usb_device_state_set_suspend(bool isConfigured, uint8_t configurationNumber); | ||
| 25 | void usb_device_state_set_resume(bool isConfigured, uint8_t configurationNumber); | ||
| 26 | void usb_device_state_set_reset(void); | ||
| 27 | void usb_device_state_init(void); | ||
| 28 | |||
| 29 | enum 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 | |||
| 36 | extern enum usb_device_state usb_device_state; | ||
| 37 | |||
| 38 | void notify_usb_device_state_change_kb(enum usb_device_state usb_device_state); | ||
| 39 | void notify_usb_device_state_change_user(enum usb_device_state usb_device_state); | ||
diff --git a/quantum/virtser.h b/quantum/virtser.h new file mode 100644 index 000000000..df7e87984 --- /dev/null +++ b/quantum/virtser.h | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | void virtser_init(void); | ||
| 4 | |||
| 5 | /* Define this function in your code to process incoming bytes */ | ||
| 6 | void virtser_recv(const uint8_t ch); | ||
| 7 | |||
| 8 | /* Call this to send a character over the Virtual Serial Device */ | ||
| 9 | void virtser_send(const uint8_t byte); | ||
