Relocate protocol files within tmk_core/common/ (#14972)

* Relocate non platform files within tmk_core/common/

* clang
This commit is contained in:
Joel Challis
2021-10-28 22:31:59 +01:00
committed by GitHub
parent 0c87e2e702
commit dcfffa7b67
17 changed files with 14 additions and 7 deletions

View File

@ -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 \

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -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);