summaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/webusb.c27
-rw-r--r--tmk_core/common/webusb.h13
2 files changed, 16 insertions, 24 deletions
diff --git a/tmk_core/common/webusb.c b/tmk_core/common/webusb.c
index 2488e75de7..bc349e6afa 100644
--- a/tmk_core/common/webusb.c
+++ b/tmk_core/common/webusb.c
@@ -1,12 +1,15 @@
-#include QMK_KEYBOARD_H
+#include "quantum.h"
#include <string.h>
#include "webusb.h"
#include "wait.h"
+
webusb_state_t webusb_state = {
.paired = 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) {
uint8_t command = data[0];
@@ -21,7 +24,7 @@ void webusb_receive(uint8_t *data, uint8_t length) {
return;
}
- if(command == WEBUSB_GET_FW_VERSION) {
+ if(command == WEBUSB_CMD_GET_FW_VERSION) {
// Landing page + packet headers(2) + stop bit(1)
uint8_t lp_size = sizeof(FIRMWARE_VERSION) + 3;
uint8_t url[lp_size];
@@ -41,30 +44,14 @@ void webusb_receive(uint8_t *data, uint8_t length) {
}
if(webusb_state.paired == true) {
- switch(command) {
- //Handle commands in here
- case WEBUSB_GET_LAYER:
- webusb_layer_event();
- break;
- default:
- break;
+ if (!webusb_receive_quantum(data, length)) {
+ webusb_error(WEBUSB_STATUS_UNKNOWN_COMMAND);
}
} else {
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) {
uint8_t buffer[1];
buffer[0] = code;
diff --git a/tmk_core/common/webusb.h b/tmk_core/common/webusb.h
index 18e884f1ab..7958cb4586 100644
--- a/tmk_core/common/webusb.h
+++ b/tmk_core/common/webusb.h
@@ -13,8 +13,9 @@
void webusb_receive(uint8_t *data, uint8_t length);
void webusb_send(uint8_t *data, uint8_t length);
void webusb_layer_event(void);
-void webusb_error(uint8_t);
+void webusb_error(uint8_t code);
void webusb_set_pairing_state(void);
+bool webusb_receive_quantum(uint8_t *data, uint8_t length);
typedef struct{
bool paired;
@@ -31,14 +32,18 @@ enum Webusb_Status_Code {
enum Webusb_Command_Code {
WEBUSB_CMD_PAIR,
- WEBUSB_GET_FW_VERSION,
- WEBUSB_GET_LAYER
+ WEBUSB_CMD_GET_FW_VERSION,
+ WEBUSB_CMD_SAFE_RANGE,
+
+ WEBUSB_GET_LAYER,
};
enum Webusb_Event_Code {
WEBUSB_EVT_PAIRED,
+ WEBUSB_EVT_FW_VERSION,
+ WEBUSB_EVT_SAFE_RANGE,
+
WEBUSB_EVT_KEYDOWN,
WEBUSB_EVT_KEYUP,
WEBUSB_EVT_LAYER,
- WEBUSB_EVT_FW_VERSION
};