summaryrefslogtreecommitdiff
path: root/tmk_core/protocol
diff options
context:
space:
mode:
authorFlorian Didron <fdidron@users.noreply.github.com>2022-05-31 19:03:21 +0900
committerGitHub <noreply@github.com>2022-05-31 19:03:21 +0900
commitfc773ff0cf9c528773fa81be0fc8880ca5153d81 (patch)
treee917ed871290cc78cff818ee896b838d12ccc654 /tmk_core/protocol
parent1fbd91aa106a4beb6ab84614dde14165a43f009a (diff)
Reimplements Oryx's live training over raw hid (#345)
* feat: initial commit, random pairing sequence generation, host - board pairing handshakes * feat: reimplements ory's live training over raw hid * feat: adds planck / ergodox support * chore: some code styling fixes * fix: build smoke tests * fix: code lint * fix: disable console / command on moonlander, fixes build ci test * fix: code lint * fix: remove unused define(MATRIX_SIZE)
Diffstat (limited to 'tmk_core/protocol')
-rw-r--r--tmk_core/protocol/chibios/usb_main.c41
-rw-r--r--tmk_core/protocol/lufa/lufa.c67
2 files changed, 62 insertions, 46 deletions
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 66cef7838a..04ae3d7f4d 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -49,6 +49,14 @@
extern keymap_config_t keymap_config;
#endif
+#ifdef RAW_ENABLE
+# include "raw_hid.h"
+#endif
+
+#ifdef ORYX_ENABLE
+# include "oryx.h"
+#endif
+
#ifdef WEBUSB_ENABLE
# include "webusb.h"
#endif
@@ -176,7 +184,6 @@ static const USBEndpointConfig shared_ep_config = {
};
#endif
-
#ifdef WEBUSB_ENABLE
/** Microsoft OS 2.0 Descriptor. This is used by Windows to select the USB driver for the device.
*
@@ -391,10 +398,10 @@ static usb_driver_configs_t drivers = {
#endif
#ifdef WEBUSB_ENABLE
-# define WEBUSB_IN_CAPACITY 4
-# define WEBUSB_OUT_CAPACITY 4
-# define WEBUSB_IN_MODE USB_EP_MODE_TYPE_INTR
-# define WEBUSB_OUT_MODE USB_EP_MODE_TYPE_INTR
+# define WEBUSB_IN_CAPACITY 4
+# define WEBUSB_OUT_CAPACITY 4
+# define WEBUSB_IN_MODE USB_EP_MODE_TYPE_INTR
+# define WEBUSB_OUT_MODE USB_EP_MODE_TYPE_INTR
.webusb_driver = QMK_USB_DRIVER_CONFIG(WEBUSB, 0, false),
#endif
#ifdef JOYSTICK_ENABLE
@@ -463,9 +470,9 @@ static inline void usb_event_wakeup_handler(void) {
suspend_wakeup_init();
usb_device_state_set_resume(USB_DRIVER.configuration != 0, USB_DRIVER.configuration);
#ifdef SLEEP_LED_ENABLE
- sleep_led_disable();
- // NOTE: converters may not accept this
- led_set(host_keyboard_leds());
+ sleep_led_disable();
+ // NOTE: converters may not accept this
+ led_set(host_keyboard_leds());
#endif /* SLEEP_LED_ENABLE */
}
@@ -1145,7 +1152,15 @@ void raw_hid_send(uint8_t *data, uint8_t length) {
if (length != RAW_EPSIZE) {
return;
}
+
+# ifdef ORYX_ENABLE
+ if (chnWriteTimeout(&drivers.raw_driver.driver, data, length, TIME_IMMEDIATE) != length) {
+ rawhid_state.pairing = false;
+ rawhid_state.paired = false;
+ }
+# else
chnWrite(&drivers.raw_driver.driver, data, length);
+# endif
}
__attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) {
@@ -1169,15 +1184,15 @@ void raw_hid_task(void) {
#ifdef WEBUSB_ENABLE
void webusb_send(uint8_t *data, uint8_t length) {
- if(chnWriteTimeout(&drivers.webusb_driver.driver, data, length, TIME_IMMEDIATE) != length){
- webusb_state.paired = false;
+ if (chnWriteTimeout(&drivers.webusb_driver.driver, data, length, TIME_IMMEDIATE) != length) {
+ webusb_state.paired = false;
webusb_state.pairing = false;
}
}
- // Users should #include "raw_hid.h" in their own code
- // and implement this function there. Leave this as weak linkage
- // so users can opt to not handle data coming in.
+// Users should #include "raw_hid.h" in their own code
+// and implement this function there. Leave this as weak linkage
+// so users can opt to not handle data coming in.
void webusb_task(void) {
uint8_t buffer[WEBUSB_EPSIZE];
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index bf005d519f..1084f67659 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -161,7 +161,10 @@ void raw_hid_send(uint8_t *data, uint8_t length) {
// Check to see if the host is ready to accept another packet
if (Endpoint_IsINReady()) {
// Write data
- Endpoint_Write_Stream_LE(data, RAW_EPSIZE, NULL);
+ if (Endpoint_Write_Stream_LE(data, RAW_EPSIZE, NULL)) {
+ rawhid_state.pairing = false;
+ rawhid_state.paired = false;
+ }
// Finalize the stream transfer to send the last packet
Endpoint_ClearIN();
}
@@ -279,9 +282,9 @@ void webusb_send(uint8_t *data, uint8_t length) {
Endpoint_SelectEndpoint(WEBUSB_IN_EPNUM);
- if(Endpoint_Write_Stream_LE(data, length, NULL)) {
+ if (Endpoint_Write_Stream_LE(data, length, NULL)) {
// Stream failed to complete, resetting WEBUSB's state
- webusb_state.paired = false;
+ webusb_state.paired = false;
webusb_state.pairing = false;
}
Endpoint_ClearIN();
@@ -292,7 +295,6 @@ static void webusb_task(void) {
uint8_t data[WEBUSB_EPSIZE];
bool data_read = false;
-
// Device must be connected and configured for the task to run
if (USB_DeviceState != DEVICE_STATE_Configured) return;
@@ -543,9 +545,9 @@ void EVENT_USB_Device_ConfigurationChanged(void) {
#endif
#ifdef WEBUSB_ENABLE
- /* Setup Webusb Endpoints */
- ConfigSuccess &= Endpoint_ConfigureEndpoint(WEBUSB_IN_EPADDR, EP_TYPE_INTERRUPT, WEBUSB_EPSIZE, 1);
- ConfigSuccess &= Endpoint_ConfigureEndpoint(WEBUSB_OUT_EPADDR, EP_TYPE_INTERRUPT, WEBUSB_EPSIZE, 1);
+ /* Setup Webusb Endpoints */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint(WEBUSB_IN_EPADDR, EP_TYPE_INTERRUPT, WEBUSB_EPSIZE, 1);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint(WEBUSB_OUT_EPADDR, EP_TYPE_INTERRUPT, WEBUSB_EPSIZE, 1);
#endif
#ifdef MIDI_ENABLE
@@ -697,23 +699,23 @@ void EVENT_USB_Device_ControlRequest(void) {
case WEBUSB_VENDOR_CODE:
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE)) {
switch (USB_ControlRequest.wIndex) {
- case WebUSB_RTYPE_GetURL:
- switch (USB_ControlRequest.wValue) {
- case WEBUSB_LANDING_PAGE_INDEX:
- Endpoint_ClearSETUP();
- /* Write the descriptor data to the control endpoint */
- Endpoint_Write_Control_PStream_LE(&WebUSB_LandingPage, WebUSB_LandingPage.Header.Size);
- /* Release the endpoint after transaction. */
- Endpoint_ClearStatusStage();
+ case WebUSB_RTYPE_GetURL:
+ switch (USB_ControlRequest.wValue) {
+ case WEBUSB_LANDING_PAGE_INDEX:
+ Endpoint_ClearSETUP();
+ /* Write the descriptor data to the control endpoint */
+ Endpoint_Write_Control_PStream_LE(&WebUSB_LandingPage, WebUSB_LandingPage.Header.Size);
+ /* Release the endpoint after transaction. */
+ Endpoint_ClearStatusStage();
+ break;
+ default: /* Stall transfer on invalid index. */
+ Endpoint_StallTransaction();
+ break;
+ }
break;
- default: /* Stall transfer on invalid index. */
+ default: /* Stall on unknown WebUSB request */
Endpoint_StallTransaction();
break;
- }
- break;
- default: /* Stall on unknown WebUSB request */
- Endpoint_StallTransaction();
- break;
}
}
@@ -721,16 +723,16 @@ void EVENT_USB_Device_ControlRequest(void) {
case MS_OS_20_VENDOR_CODE:
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE)) {
switch (USB_ControlRequest.wIndex) {
- case MS_OS_20_DESCRIPTOR_INDEX:
- Endpoint_ClearSETUP();
- /* Write the descriptor data to the control endpoint */
- Endpoint_Write_Control_PStream_LE(&MS_OS_20_Descriptor, MS_OS_20_Descriptor.Header.TotalLength);
- /* Release the endpoint after transaction. */
- Endpoint_ClearStatusStage();
- break;
- default: /* Stall on unknown MS OS 2.0 request */
- Endpoint_StallTransaction();
- break;
+ case MS_OS_20_DESCRIPTOR_INDEX:
+ Endpoint_ClearSETUP();
+ /* Write the descriptor data to the control endpoint */
+ Endpoint_Write_Control_PStream_LE(&MS_OS_20_Descriptor, MS_OS_20_Descriptor.Header.TotalLength);
+ /* Release the endpoint after transaction. */
+ Endpoint_ClearStatusStage();
+ break;
+ default: /* Stall on unknown MS OS 2.0 request */
+ Endpoint_StallTransaction();
+ break;
}
}
break;
@@ -896,7 +898,6 @@ static void send_consumer(uint16_t data) {
#endif
}
-
static void send_programmable_button(uint32_t data) {
#ifdef PROGRAMMABLE_BUTTON_ENABLE
static report_programmable_button_t r;
@@ -1209,7 +1210,7 @@ void protocol_post_task(void) {
#endif
#ifdef WEBUSB_ENABLE
- webusb_task();
+ webusb_task();
#endif
#if !defined(INTERRUPT_CONTROL_ENDPOINT)