Start moving code out of webusb and to Oryx feature
This commit is contained in:
committed by
Florian Didron
parent
d3f23ecfbc
commit
e41ab50016
@@ -316,9 +316,6 @@ ifeq ($(strip $(USB_HID_ENABLE)), yes)
|
|||||||
include $(TMK_DIR)/protocol/usb_hid.mk
|
include $(TMK_DIR)/protocol/usb_hid.mk
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(strip $(WEBUSB_ENABLE)), yes)
|
|
||||||
SRC += $(TMK_DIR)/common/webusb.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(strip $(ENCODER_ENABLE)), yes)
|
ifeq ($(strip $(ENCODER_ENABLE)), yes)
|
||||||
SRC += $(QUANTUM_DIR)/encoder.c
|
SRC += $(QUANTUM_DIR)/encoder.c
|
||||||
@@ -352,6 +349,13 @@ ifeq ($(strip $(VELOCIKEY_ENABLE)), yes)
|
|||||||
SRC += $(QUANTUM_DIR)/velocikey.c
|
SRC += $(QUANTUM_DIR)/velocikey.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(strip $(ORYX_ENABLE)), yes)
|
||||||
|
DYNAMIC_KEYMAP_ENABLE := yes
|
||||||
|
WEBUSB_ENABLE := yes
|
||||||
|
SRC += $(QUANTUM_DIR)/oryx.c
|
||||||
|
OPT_DEFS += -DORYX_ENABLE
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(strip $(DYNAMIC_KEYMAP_ENABLE)), yes)
|
ifeq ($(strip $(DYNAMIC_KEYMAP_ENABLE)), yes)
|
||||||
OPT_DEFS += -DDYNAMIC_KEYMAP_ENABLE
|
OPT_DEFS += -DDYNAMIC_KEYMAP_ENABLE
|
||||||
SRC += $(QUANTUM_DIR)/dynamic_keymap.c
|
SRC += $(QUANTUM_DIR)/dynamic_keymap.c
|
||||||
|
|||||||
30
quantum/oryx.c
Normal file
30
quantum/oryx.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include "oryx.h"
|
||||||
|
|
||||||
|
bool webusb_state_live_training_enabled;
|
||||||
|
|
||||||
|
bool webusb_receive_oryx(uint8_t *data, uint8_t length) {
|
||||||
|
uint8_t command = data[0];
|
||||||
|
|
||||||
|
switch (command) {
|
||||||
|
case ORYX_GET_LAYER:
|
||||||
|
oryx_layer_event();
|
||||||
|
return true; break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void oryx_layer_event(void) {
|
||||||
|
uint8_t layer;
|
||||||
|
uint8_t event[4];
|
||||||
|
layer = get_highest_layer(layer_state);
|
||||||
|
#ifdef WEBUSB_ENABLE
|
||||||
|
event[0] = WEBUSB_STATUS_OK;
|
||||||
|
event[1] = ORYX_EVT_LAYER;
|
||||||
|
event[2] = layer;
|
||||||
|
event[3] = WEBUSB_STOP_BIT;
|
||||||
|
webusb_send(event, sizeof(event));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
34
quantum/oryx.h
Normal file
34
quantum/oryx.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "quantum.h"
|
||||||
|
#include "webusb.h"
|
||||||
|
|
||||||
|
#ifndef WEBUSB_ENABLE
|
||||||
|
# error "WebUSB needs to be enabled, please enable it!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DYNAMIC_KEYMAP_ENABLE
|
||||||
|
# error "Dynamic Keymaps are not enabled. It must be aenbled "
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
enum Oryx_Command_Code {
|
||||||
|
ORYX_GET_LAYER = WEBUSB_CMD_SAFE_RANGE,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Oryx_Event_Code {
|
||||||
|
ORYX_EVT_KEYDOWN = WEBUSB_EVT_SAFE_RANGE,
|
||||||
|
ORYX_EVT_KEYUP,
|
||||||
|
ORYX_EVT_LAYER,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern bool webusb_state_live_training_enabled;
|
||||||
|
|
||||||
|
bool webusb_receive_oryx(uint8_t *data, uint8_t length);
|
||||||
|
void oryx_layer_event(void);
|
||||||
|
|
||||||
|
|
||||||
|
void keyboard_pre_init_oryx(void);
|
||||||
@@ -774,3 +774,16 @@ __attribute__((weak)) void startup_user() {}
|
|||||||
__attribute__((weak)) void shutdown_user() {}
|
__attribute__((weak)) void shutdown_user() {}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef WEBUSB_ENABLE
|
||||||
|
__attribute__((weak)) bool webusb_receive_user(uint8_t *data, uint8_t length) { return false; }
|
||||||
|
__attribute__((weak)) bool webusb_receive_kb(uint8_t *data, uint8_t length) { return webusb_receive_user(data, length); }
|
||||||
|
|
||||||
|
bool webusb_receive_quantum(uint8_t *data, uint8_t length) {
|
||||||
|
#ifdef ORYX_ENABLE
|
||||||
|
return webusb_receive_oryx(data, length);
|
||||||
|
#else
|
||||||
|
return webusb_receive_kb(data, length);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -162,6 +162,10 @@ extern layer_state_t layer_state;
|
|||||||
# include "webusb.h"
|
# include "webusb.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ORYX_ENABLE
|
||||||
|
# include "oryx.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DYNAMIC_MACRO_ENABLE
|
#ifdef DYNAMIC_MACRO_ENABLE
|
||||||
#include "process_dynamic_macro.h"
|
#include "process_dynamic_macro.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -283,3 +287,6 @@ bool led_update_user(led_t led_state);
|
|||||||
bool led_update_kb(led_t led_state);
|
bool led_update_kb(led_t led_state);
|
||||||
|
|
||||||
void api_send_unicode(uint32_t unicode);
|
void api_send_unicode(uint32_t unicode);
|
||||||
|
|
||||||
|
bool webusb_receive_kb(uint8_t *data, uint8_t length);
|
||||||
|
bool webusb_receive_user(uint8_t *data, uint8_t length);
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ ifeq ($(strip $(RAW_ENABLE)), yes)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(strip $(WEBUSB_ENABLE)), yes)
|
ifeq ($(strip $(WEBUSB_ENABLE)), yes)
|
||||||
|
TMK_COMMON_SRC += $(TMK_DIR)/common/webusb.c
|
||||||
TMK_COMMON_DEFS += -DWEBUSB_ENABLE
|
TMK_COMMON_DEFS += -DWEBUSB_ENABLE
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
#include QMK_KEYBOARD_H
|
#include "quantum.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "webusb.h"
|
#include "webusb.h"
|
||||||
#include "wait.h"
|
#include "wait.h"
|
||||||
|
|
||||||
webusb_state_t webusb_state = {
|
webusb_state_t webusb_state = {
|
||||||
.paired = false,
|
.paired = false,
|
||||||
.pairing = false,
|
.pairing = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
__attribute__((weak)) bool webusb_receive_quantum(uint8_t *data, uint8_t length) { return false; }
|
||||||
|
|
||||||
void webusb_receive(uint8_t *data, uint8_t length) {
|
void webusb_receive(uint8_t *data, uint8_t length) {
|
||||||
uint8_t command = data[0];
|
uint8_t command = data[0];
|
||||||
|
|
||||||
@@ -21,7 +24,7 @@ void webusb_receive(uint8_t *data, uint8_t length) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(command == WEBUSB_GET_FW_VERSION) {
|
if(command == WEBUSB_CMD_GET_FW_VERSION) {
|
||||||
// Landing page + packet headers(2) + stop bit(1)
|
// Landing page + packet headers(2) + stop bit(1)
|
||||||
uint8_t lp_size = sizeof(FIRMWARE_VERSION) + 3;
|
uint8_t lp_size = sizeof(FIRMWARE_VERSION) + 3;
|
||||||
uint8_t url[lp_size];
|
uint8_t url[lp_size];
|
||||||
@@ -41,30 +44,14 @@ void webusb_receive(uint8_t *data, uint8_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(webusb_state.paired == true) {
|
if(webusb_state.paired == true) {
|
||||||
switch(command) {
|
if (!webusb_receive_quantum(data, length)) {
|
||||||
//Handle commands in here
|
webusb_error(WEBUSB_STATUS_UNKNOWN_COMMAND);
|
||||||
case WEBUSB_GET_LAYER:
|
|
||||||
webusb_layer_event();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
webusb_error(WEBUSB_STATUS_NOT_PAIRED);
|
webusb_error(WEBUSB_STATUS_NOT_PAIRED);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void webusb_layer_event() {
|
|
||||||
uint8_t layer;
|
|
||||||
uint8_t event[4];
|
|
||||||
layer = biton32(layer_state);
|
|
||||||
event[0] = WEBUSB_STATUS_OK;
|
|
||||||
event[1] = WEBUSB_EVT_LAYER;
|
|
||||||
event[2] = layer;
|
|
||||||
event[3] = WEBUSB_STOP_BIT;
|
|
||||||
webusb_send(event, sizeof(event));
|
|
||||||
}
|
|
||||||
|
|
||||||
void webusb_error(uint8_t code) {
|
void webusb_error(uint8_t code) {
|
||||||
uint8_t buffer[1];
|
uint8_t buffer[1];
|
||||||
buffer[0] = code;
|
buffer[0] = code;
|
||||||
|
|||||||
@@ -13,8 +13,9 @@
|
|||||||
void webusb_receive(uint8_t *data, uint8_t length);
|
void webusb_receive(uint8_t *data, uint8_t length);
|
||||||
void webusb_send(uint8_t *data, uint8_t length);
|
void webusb_send(uint8_t *data, uint8_t length);
|
||||||
void webusb_layer_event(void);
|
void webusb_layer_event(void);
|
||||||
void webusb_error(uint8_t);
|
void webusb_error(uint8_t code);
|
||||||
void webusb_set_pairing_state(void);
|
void webusb_set_pairing_state(void);
|
||||||
|
bool webusb_receive_quantum(uint8_t *data, uint8_t length);
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
bool paired;
|
bool paired;
|
||||||
@@ -31,14 +32,18 @@ enum Webusb_Status_Code {
|
|||||||
|
|
||||||
enum Webusb_Command_Code {
|
enum Webusb_Command_Code {
|
||||||
WEBUSB_CMD_PAIR,
|
WEBUSB_CMD_PAIR,
|
||||||
WEBUSB_GET_FW_VERSION,
|
WEBUSB_CMD_GET_FW_VERSION,
|
||||||
WEBUSB_GET_LAYER
|
WEBUSB_CMD_SAFE_RANGE,
|
||||||
|
|
||||||
|
WEBUSB_GET_LAYER,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Webusb_Event_Code {
|
enum Webusb_Event_Code {
|
||||||
WEBUSB_EVT_PAIRED,
|
WEBUSB_EVT_PAIRED,
|
||||||
|
WEBUSB_EVT_FW_VERSION,
|
||||||
|
WEBUSB_EVT_SAFE_RANGE,
|
||||||
|
|
||||||
WEBUSB_EVT_KEYDOWN,
|
WEBUSB_EVT_KEYDOWN,
|
||||||
WEBUSB_EVT_KEYUP,
|
WEBUSB_EVT_KEYUP,
|
||||||
WEBUSB_EVT_LAYER,
|
WEBUSB_EVT_LAYER,
|
||||||
WEBUSB_EVT_FW_VERSION
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -880,7 +880,6 @@ void webusb_send(uint8_t *data, uint8_t length) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((weak)) void webusb_receive_kb(uint8_t *data, uint8_t length) {
|
|
||||||
// Users should #include "raw_hid.h" in their own code
|
// Users should #include "raw_hid.h" in their own code
|
||||||
// and implement this function there. Leave this as weak linkage
|
// and implement this function there. Leave this as weak linkage
|
||||||
// so users can opt to not handle data coming in.
|
// so users can opt to not handle data coming in.
|
||||||
|
|||||||
@@ -288,8 +288,6 @@ void webusb_send(uint8_t *data, uint8_t length) {
|
|||||||
Endpoint_ClearIN();
|
Endpoint_ClearIN();
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((weak)) void webusb_receive_kb(uint8_t *data, uint8_t length) { }
|
|
||||||
|
|
||||||
static void webusb_task(void) {
|
static void webusb_task(void) {
|
||||||
// Create a temporary buffer to hold the read in data from the host
|
// Create a temporary buffer to hold the read in data from the host
|
||||||
uint8_t data[WEBUSB_EPSIZE];
|
uint8_t data[WEBUSB_EPSIZE];
|
||||||
|
|||||||
Reference in New Issue
Block a user