aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/vusb/vusb.c
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2020-06-07 15:00:21 +1000
committerJames Young <18669334+noroadsleft@users.noreply.github.com>2020-08-29 14:30:02 -0700
commitf209f91c7ce073aa0381e79c10219616cb7db523 (patch)
treee27464d1c993f960f508edbd52a47c646cfaee42 /tmk_core/protocol/vusb/vusb.c
parent385d49cc39b57e74203e0c1c78c0789d249e4742 (diff)
downloadqmk_firmware-f209f91c7ce073aa0381e79c10219616cb7db523.tar.gz
qmk_firmware-f209f91c7ce073aa0381e79c10219616cb7db523.zip
Various tidyups for USB descriptor code (#9005)
Diffstat (limited to 'tmk_core/protocol/vusb/vusb.c')
-rw-r--r--tmk_core/protocol/vusb/vusb.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 5feff889a..f4727a0c3 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -65,7 +65,7 @@ enum usb_interfaces {
65# error There are not enough available interfaces to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Raw HID, Console 65# error There are not enough available interfaces to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Raw HID, Console
66#endif 66#endif
67 67
68static uint8_t vusb_keyboard_leds = 0; 68static uint8_t keyboard_led_state = 0;
69static uint8_t vusb_idle_rate = 0; 69static uint8_t vusb_idle_rate = 0;
70 70
71/* Keyboard report send buffer */ 71/* Keyboard report send buffer */
@@ -74,13 +74,7 @@ static report_keyboard_t kbuf[KBUF_SIZE];
74static uint8_t kbuf_head = 0; 74static uint8_t kbuf_head = 0;
75static uint8_t kbuf_tail = 0; 75static uint8_t kbuf_tail = 0;
76 76
77typedef struct { 77static report_keyboard_t keyboard_report_sent;
78 uint8_t modifier;
79 uint8_t reserved;
80 uint8_t keycode[6];
81} keyboard_report_t;
82
83static keyboard_report_t keyboard_report; // sent to PC
84 78
85#define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10 79#define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10
86 80
@@ -218,7 +212,7 @@ static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_sy
218 212
219host_driver_t *vusb_driver(void) { return &driver; } 213host_driver_t *vusb_driver(void) { return &driver; }
220 214
221static uint8_t keyboard_leds(void) { return vusb_keyboard_leds; } 215static uint8_t keyboard_leds(void) { return keyboard_led_state; }
222 216
223static void send_keyboard(report_keyboard_t *report) { 217static void send_keyboard(report_keyboard_t *report) {
224 uint8_t next = (kbuf_head + 1) % KBUF_SIZE; 218 uint8_t next = (kbuf_head + 1) % KBUF_SIZE;
@@ -232,6 +226,7 @@ static void send_keyboard(report_keyboard_t *report) {
232 // NOTE: send key strokes of Macro 226 // NOTE: send key strokes of Macro
233 usbPoll(); 227 usbPoll();
234 vusb_transfer_keyboard(); 228 vusb_transfer_keyboard();
229 keyboard_report_sent = *report;
235} 230}
236 231
237typedef struct { 232typedef struct {
@@ -289,9 +284,10 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
289 if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */ 284 if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */
290 if (rq->bRequest == USBRQ_HID_GET_REPORT) { 285 if (rq->bRequest == USBRQ_HID_GET_REPORT) {
291 debug("GET_REPORT:"); 286 debug("GET_REPORT:");
292 /* we only have one report type, so don't look at wValue */ 287 if (rq->wIndex.word == KEYBOARD_INTERFACE) {
293 usbMsgPtr = (usbMsgPtr_t)&keyboard_report; 288 usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent;
294 return sizeof(keyboard_report); 289 return sizeof(keyboard_report_sent);
290 }
295 } else if (rq->bRequest == USBRQ_HID_GET_IDLE) { 291 } else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
296 debug("GET_IDLE: "); 292 debug("GET_IDLE: ");
297 // debug_hex(vusb_idle_rate); 293 // debug_hex(vusb_idle_rate);
@@ -304,7 +300,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
304 } else if (rq->bRequest == USBRQ_HID_SET_REPORT) { 300 } else if (rq->bRequest == USBRQ_HID_SET_REPORT) {
305 debug("SET_REPORT: "); 301 debug("SET_REPORT: ");
306 // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) 302 // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard)
307 if (rq->wValue.word == 0x0200 && rq->wIndex.word == 0) { 303 if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) {
308 debug("SET_LED: "); 304 debug("SET_LED: ");
309 last_req.kind = SET_LED; 305 last_req.kind = SET_LED;
310 last_req.len = rq->wLength.word; 306 last_req.len = rq->wLength.word;
@@ -330,7 +326,7 @@ uchar usbFunctionWrite(uchar *data, uchar len) {
330 debug("SET_LED: "); 326 debug("SET_LED: ");
331 debug_hex(data[0]); 327 debug_hex(data[0]);
332 debug("\n"); 328 debug("\n");
333 vusb_keyboard_leds = data[0]; 329 keyboard_led_state = data[0];
334 last_req.len = 0; 330 last_req.len = 0;
335 return 1; 331 return 1;
336 break; 332 break;