summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common/webusb.c32
-rw-r--r--tmk_core/common/webusb.h13
-rw-r--r--tmk_core/protocol/chibios/usb_main.c9
-rw-r--r--tmk_core/protocol/lufa/lufa.c16
4 files changed, 42 insertions, 28 deletions
diff --git a/tmk_core/common/webusb.c b/tmk_core/common/webusb.c
index 5183d77543..82e8fe1c83 100644
--- a/tmk_core/common/webusb.c
+++ b/tmk_core/common/webusb.c
@@ -6,16 +6,28 @@ webusb_state_t webusb_state = {
.pairing = false,
};
-void webusb_set_pairing_state() {
- webusb_state.pairing = true;
- uint8_t tick = 0;
- do {
- tick++;
- wait_ms(1000);
- //TODO Blink some leds
- } while(webusb_state.paired == false && tick <= 30);
- webusb_state.pairing = false;
-}
+void webusb_receive(uint8_t *data, uint8_t length) {
+ uint8_t command = data[0];
+
+ if(command == WEBUSB_CMD_PAIR && webusb_state.pairing == true) {
+ uint8_t event[3];
+ webusb_state.pairing = false;
+ webusb_state.paired = true;
+ event[0] = WEBUSB_STATUS_OK;
+ event[1] = WEBUSB_EVT_PAIRED;
+ event[2] = WEBUSB_STOP_BIT;
+ webusb_send(event, sizeof(event));
+ return;
+ }
+
+ if(webusb_state.paired == true) {
+ switch(command) {
+ //Handle commands in here
+ }
+ } else {
+ webusb_error(WEBUSB_STATUS_NOT_PAIRED);
+ }
+};
void webusb_error(uint8_t code) {
uint8_t buffer[1];
diff --git a/tmk_core/common/webusb.h b/tmk_core/common/webusb.h
index 35d9610fc9..c49a9f48a8 100644
--- a/tmk_core/common/webusb.h
+++ b/tmk_core/common/webusb.h
@@ -3,6 +3,10 @@
#include <stdint.h>
#include <stdbool.h>
+#define WEBUSB_STOP_BIT -2
+#define WEBUSB_BLINK_STEPS 512
+#define WEBUSB_BLINK_END WEBUSB_BLINK_STEPS * 60
+
void webusb_receive(uint8_t *data, uint8_t length);
void webusb_send(uint8_t *data, uint8_t length);
void webusb_error(uint8_t);
@@ -21,4 +25,13 @@ enum Webusb_Status_Code {
WEBUSB_STATUS_UNKNOWN_COMMAND,
};
+enum Webusb_Command_Code {
+ WEBUSB_CMD_PAIR
+};
+enum Webusb_Event_Code {
+ WEBUSB_EVT_PAIRED,
+ WEBUSB_EVT_KEYDOWN,
+ WEBUSB_EVT_KEYUP,
+ WEBUSB_EVT_LAYER
+};
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 8a249e19e3..57b9d74d38 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -871,7 +871,7 @@ void raw_hid_task(void) {
#ifdef WEBUSB_ENABLE
void webusb_send(uint8_t *data, uint8_t length) { chnWrite(&drivers.webusb_driver.driver, data, length); }
-__attribute__((weak)) void webusb_receive(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
// and implement this function there. Leave this as weak linkage
// so users can opt to not handle data coming in.
@@ -883,12 +883,7 @@ void webusb_task(void) {
do {
size_t size = chnReadTimeout(&drivers.webusb_driver.driver, buffer, sizeof(buffer), TIME_IMMEDIATE);
if (size > 0) {
- if(webusb_state.paired == true) {
- webusb_receive(buffer, size);
- }
- else {
- webusb_error(WEBUSB_STATUS_NOT_PAIRED);
- }
+ webusb_receive(buffer, size);
}
} while (size > 0);
}
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index c68c3c2e5b..660633fd12 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -280,19 +280,18 @@ void webusb_send(uint8_t *data, uint8_t length) {
Endpoint_SelectEndpoint(WEBUSB_IN_EPNUM);
- if (Endpoint_IsINReady()) {
- Endpoint_Write_Stream_LE(data, length, NULL);
- Endpoint_ClearIN();
- }
+ Endpoint_Write_Stream_LE(data, length, NULL);
+ Endpoint_ClearIN();
}
-__attribute__((weak)) void webusb_receive(uint8_t *data, uint8_t length) { }
+__attribute__((weak)) void webusb_receive_kb(uint8_t *data, uint8_t length) { }
static void webusb_task(void) {
// Create a temporary buffer to hold the read in data from the host
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;
@@ -311,12 +310,7 @@ static void webusb_task(void) {
Endpoint_ClearOUT();
if (data_read) {
- if(webusb_state.paired == true) {
- webusb_receive(data, sizeof(data));
- }
- else {
- webusb_error(WEBUSB_STATUS_NOT_PAIRED);
- }
+ webusb_receive(data, sizeof(data));
}
}
}