diff options
author | Ryan <fauxpark@gmail.com> | 2020-06-07 15:00:21 +1000 |
---|---|---|
committer | James Young <18669334+noroadsleft@users.noreply.github.com> | 2020-08-29 14:30:02 -0700 |
commit | f209f91c7ce073aa0381e79c10219616cb7db523 (patch) | |
tree | e27464d1c993f960f508edbd52a47c646cfaee42 /tmk_core/protocol/lufa/lufa.c | |
parent | 385d49cc39b57e74203e0c1c78c0789d249e4742 (diff) | |
download | qmk_firmware-f209f91c7ce073aa0381e79c10219616cb7db523.tar.gz qmk_firmware-f209f91c7ce073aa0381e79c10219616cb7db523.zip |
Various tidyups for USB descriptor code (#9005)
Diffstat (limited to 'tmk_core/protocol/lufa/lufa.c')
-rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 120 |
1 files changed, 61 insertions, 59 deletions
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 374add20f..19f417770 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
@@ -88,7 +88,7 @@ extern keymap_config_t keymap_config; | |||
88 | uint8_t keyboard_idle = 0; | 88 | uint8_t keyboard_idle = 0; |
89 | /* 0: Boot Protocol, 1: Report Protocol(default) */ | 89 | /* 0: Boot Protocol, 1: Report Protocol(default) */ |
90 | uint8_t keyboard_protocol = 1; | 90 | uint8_t keyboard_protocol = 1; |
91 | static uint8_t keyboard_led_stats = 0; | 91 | static uint8_t keyboard_led_state = 0; |
92 | 92 | ||
93 | static report_keyboard_t keyboard_report_sent; | 93 | static report_keyboard_t keyboard_report_sent; |
94 | 94 | ||
@@ -103,30 +103,30 @@ host_driver_t lufa_driver = { | |||
103 | }; | 103 | }; |
104 | 104 | ||
105 | #ifdef VIRTSER_ENABLE | 105 | #ifdef VIRTSER_ENABLE |
106 | // clang-format off | ||
107 | |||
106 | USB_ClassInfo_CDC_Device_t cdc_device = { | 108 | USB_ClassInfo_CDC_Device_t cdc_device = { |
107 | .Config = | 109 | .Config = { |
108 | { | 110 | .ControlInterfaceNumber = CCI_INTERFACE, |
109 | .ControlInterfaceNumber = CCI_INTERFACE, | 111 | .DataINEndpoint = { |
110 | .DataINEndpoint = | 112 | .Address = (CDC_IN_EPNUM | ENDPOINT_DIR_IN), |
111 | { | 113 | .Size = CDC_EPSIZE, |
112 | .Address = CDC_IN_EPADDR, | 114 | .Banks = 1 |
113 | .Size = CDC_EPSIZE, | 115 | }, |
114 | .Banks = 1, | 116 | .DataOUTEndpoint = { |
115 | }, | 117 | .Address = (CDC_OUT_EPNUM | ENDPOINT_DIR_OUT), |
116 | .DataOUTEndpoint = | 118 | .Size = CDC_EPSIZE, |
117 | { | 119 | .Banks = 1 |
118 | .Address = CDC_OUT_EPADDR, | ||
119 | .Size = CDC_EPSIZE, | ||
120 | .Banks = 1, | ||
121 | }, | ||
122 | .NotificationEndpoint = | ||
123 | { | ||
124 | .Address = CDC_NOTIFICATION_EPADDR, | ||
125 | .Size = CDC_NOTIFICATION_EPSIZE, | ||
126 | .Banks = 1, | ||
127 | }, | ||
128 | }, | 120 | }, |
121 | .NotificationEndpoint = { | ||
122 | .Address = (CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN), | ||
123 | .Size = CDC_NOTIFICATION_EPSIZE, | ||
124 | .Banks = 1 | ||
125 | } | ||
126 | } | ||
129 | }; | 127 | }; |
128 | |||
129 | // clang-format on | ||
130 | #endif | 130 | #endif |
131 | 131 | ||
132 | #ifdef RAW_ENABLE | 132 | #ifdef RAW_ENABLE |
@@ -254,7 +254,7 @@ static void Console_Task(void) { | |||
254 | // fill empty bank | 254 | // fill empty bank |
255 | while (Endpoint_IsReadWriteAllowed()) Endpoint_Write_8(0); | 255 | while (Endpoint_IsReadWriteAllowed()) Endpoint_Write_8(0); |
256 | 256 | ||
257 | // flash senchar packet | 257 | // flush sendchar packet |
258 | if (Endpoint_IsINReady()) { | 258 | if (Endpoint_IsINReady()) { |
259 | Endpoint_ClearIN(); | 259 | Endpoint_ClearIN(); |
260 | } | 260 | } |
@@ -370,45 +370,46 @@ void EVENT_USB_Device_StartOfFrame(void) { | |||
370 | void EVENT_USB_Device_ConfigurationChanged(void) { | 370 | void EVENT_USB_Device_ConfigurationChanged(void) { |
371 | bool ConfigSuccess = true; | 371 | bool ConfigSuccess = true; |
372 | 372 | ||
373 | /* Setup Keyboard HID Report Endpoints */ | ||
374 | #ifndef KEYBOARD_SHARED_EP | 373 | #ifndef KEYBOARD_SHARED_EP |
375 | ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE); | 374 | /* Setup keyboard report endpoint */ |
375 | ConfigSuccess &= Endpoint_ConfigureEndpoint((KEYBOARD_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, KEYBOARD_EPSIZE, 1); | ||
376 | #endif | 376 | #endif |
377 | 377 | ||
378 | #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP) | 378 | #if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP) |
379 | /* Setup Mouse HID Report Endpoint */ | 379 | /* Setup mouse report endpoint */ |
380 | ConfigSuccess &= ENDPOINT_CONFIG(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE); | 380 | ConfigSuccess &= Endpoint_ConfigureEndpoint((MOUSE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, MOUSE_EPSIZE, 1); |
381 | #endif | 381 | #endif |
382 | 382 | ||
383 | #ifdef SHARED_EP_ENABLE | 383 | #ifdef SHARED_EP_ENABLE |
384 | /* Setup Shared HID Report Endpoint */ | 384 | /* Setup shared report endpoint */ |
385 | ConfigSuccess &= ENDPOINT_CONFIG(SHARED_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, SHARED_EPSIZE, ENDPOINT_BANK_SINGLE); | 385 | ConfigSuccess &= Endpoint_ConfigureEndpoint((SHARED_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, SHARED_EPSIZE, 1); |
386 | #endif | 386 | #endif |
387 | 387 | ||
388 | #ifdef RAW_ENABLE | 388 | #ifdef RAW_ENABLE |
389 | /* Setup Raw HID Report Endpoints */ | 389 | /* Setup raw HID endpoints */ |
390 | ConfigSuccess &= ENDPOINT_CONFIG(RAW_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, RAW_EPSIZE, ENDPOINT_BANK_SINGLE); | 390 | ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1); |
391 | ConfigSuccess &= ENDPOINT_CONFIG(RAW_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, RAW_EPSIZE, ENDPOINT_BANK_SINGLE); | 391 | ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1); |
392 | #endif | 392 | #endif |
393 | 393 | ||
394 | #ifdef CONSOLE_ENABLE | 394 | #ifdef CONSOLE_ENABLE |
395 | /* Setup Console HID Report Endpoints */ | 395 | /* Setup console endpoint */ |
396 | ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); | 396 | ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1); |
397 | # if 0 | 397 | # if 0 |
398 | ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, | 398 | ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1); |
399 | CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); | ||
400 | # endif | 399 | # endif |
401 | #endif | 400 | #endif |
402 | 401 | ||
403 | #ifdef MIDI_ENABLE | 402 | #ifdef MIDI_ENABLE |
404 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); | 403 | /* Setup MIDI stream endpoints */ |
405 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); | 404 | ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1); |
405 | ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1); | ||
406 | #endif | 406 | #endif |
407 | 407 | ||
408 | #ifdef VIRTSER_ENABLE | 408 | #ifdef VIRTSER_ENABLE |
409 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE); | 409 | /* Setup virtual serial endpoints */ |
410 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_OUT_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE); | 410 | ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, 1); |
411 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_IN_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE); | 411 | ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_BULK, CDC_EPSIZE, 1); |
412 | ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, CDC_EPSIZE, 1); | ||
412 | #endif | 413 | #endif |
413 | } | 414 | } |
414 | 415 | ||
@@ -472,10 +473,10 @@ void EVENT_USB_Device_ControlRequest(void) { | |||
472 | uint8_t report_id = Endpoint_Read_8(); | 473 | uint8_t report_id = Endpoint_Read_8(); |
473 | 474 | ||
474 | if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) { | 475 | if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) { |
475 | keyboard_led_stats = Endpoint_Read_8(); | 476 | keyboard_led_state = Endpoint_Read_8(); |
476 | } | 477 | } |
477 | } else { | 478 | } else { |
478 | keyboard_led_stats = Endpoint_Read_8(); | 479 | keyboard_led_state = Endpoint_Read_8(); |
479 | } | 480 | } |
480 | 481 | ||
481 | Endpoint_ClearOUT(); | 482 | Endpoint_ClearOUT(); |
@@ -545,7 +546,7 @@ void EVENT_USB_Device_ControlRequest(void) { | |||
545 | * | 546 | * |
546 | * FIXME: Needs doc | 547 | * FIXME: Needs doc |
547 | */ | 548 | */ |
548 | static uint8_t keyboard_leds(void) { return keyboard_led_stats; } | 549 | static uint8_t keyboard_leds(void) { return keyboard_led_state; } |
549 | 550 | ||
550 | /** \brief Send Keyboard | 551 | /** \brief Send Keyboard |
551 | * | 552 | * |
@@ -808,25 +809,26 @@ ERROR_EXIT: | |||
808 | ******************************************************************************/ | 809 | ******************************************************************************/ |
809 | 810 | ||
810 | #ifdef MIDI_ENABLE | 811 | #ifdef MIDI_ENABLE |
812 | // clang-format off | ||
813 | |||
811 | USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = { | 814 | USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = { |
812 | .Config = | 815 | .Config = { |
813 | { | 816 | .StreamingInterfaceNumber = AS_INTERFACE, |
814 | .StreamingInterfaceNumber = AS_INTERFACE, | 817 | .DataINEndpoint = { |
815 | .DataINEndpoint = | 818 | .Address = (MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN), |
816 | { | 819 | .Size = MIDI_STREAM_EPSIZE, |
817 | .Address = MIDI_STREAM_IN_EPADDR, | 820 | .Banks = 1 |
818 | .Size = MIDI_STREAM_EPSIZE, | ||
819 | .Banks = 1, | ||
820 | }, | ||
821 | .DataOUTEndpoint = | ||
822 | { | ||
823 | .Address = MIDI_STREAM_OUT_EPADDR, | ||
824 | .Size = MIDI_STREAM_EPSIZE, | ||
825 | .Banks = 1, | ||
826 | }, | ||
827 | }, | 821 | }, |
822 | .DataOUTEndpoint = { | ||
823 | .Address = (MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_OUT), | ||
824 | .Size = MIDI_STREAM_EPSIZE, | ||
825 | .Banks = 1 | ||
826 | } | ||
827 | } | ||
828 | }; | 828 | }; |
829 | 829 | ||
830 | // clang-format on | ||
831 | |||
830 | void send_midi_packet(MIDI_EventPacket_t *event) { MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event); } | 832 | void send_midi_packet(MIDI_EventPacket_t *event) { MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event); } |
831 | 833 | ||
832 | bool recv_midi_packet(MIDI_EventPacket_t *const event) { return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event); } | 834 | bool recv_midi_packet(MIDI_EventPacket_t *const event) { return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event); } |