feat: update examples + pairing process

This commit is contained in:
Florian Didron
2019-11-20 09:41:42 +09:00
committed by Florian Didron
parent b3c0f3b0ef
commit 925c43c4c0
9 changed files with 366 additions and 541 deletions
+2 -7
View File
@@ -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);
}
+5 -11
View File
@@ -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));
}
}
}