summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2020-06-07 15:00:21 +1000
committerDrashna Jael're <drashna@live.com>2020-09-30 02:53:02 -0700
commit85360eee26332cf38c181446e1ad8e6cdfff52b0 (patch)
tree4c788d9fb9647778ba777fe312b0a588daeaa4ea /tmk_core
parent1dd723510e0d69724f30243f49812f8e8e1c4744 (diff)
Various tidyups for USB descriptor code (#9005)
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/protocol/chibios/usb_main.c8
-rw-r--r--tmk_core/protocol/lufa/lufa.c120
-rw-r--r--tmk_core/protocol/lufa/lufa.h4
-rw-r--r--tmk_core/protocol/usb_descriptor.c10
-rw-r--r--tmk_core/protocol/usb_descriptor.h5
-rw-r--r--tmk_core/protocol/vusb/vusb.c24
6 files changed, 80 insertions, 91 deletions
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 5c582b7308..2f17efa511 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -65,7 +65,7 @@ extern keymap_config_t keymap_config;
uint8_t keyboard_idle __attribute__((aligned(2))) = 0;
uint8_t keyboard_protocol __attribute__((aligned(2))) = 1;
-uint8_t keyboard_led_stats = 0;
+uint8_t keyboard_led_state = 0;
volatile uint16_t keyboard_idle_count = 0;
static virtual_timer_t keyboard_idle_timer;
static void keyboard_idle_timer_cb(void *arg);
@@ -416,10 +416,10 @@ static void set_led_transfer_cb(USBDriver *usbp) {
if (usbp->setup[6] == 2) { /* LSB(wLength) */
uint8_t report_id = set_report_buf[0];
if ((report_id == REPORT_ID_KEYBOARD) || (report_id == REPORT_ID_NKRO)) {
- keyboard_led_stats = set_report_buf[1];
+ keyboard_led_state = set_report_buf[1];
}
} else {
- keyboard_led_stats = set_report_buf[0];
+ keyboard_led_state = set_report_buf[0];
}
}
@@ -661,7 +661,7 @@ static void keyboard_idle_timer_cb(void *arg) {
}
/* LED status */
-uint8_t keyboard_leds(void) { return keyboard_led_stats; }
+uint8_t keyboard_leds(void) { return keyboard_led_state; }
/* prepare and start sending a report IN
* not callable from ISR or locked state */
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 7162b8b208..8fa3b39b2d 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -92,7 +92,7 @@ extern keymap_config_t keymap_config;
uint8_t keyboard_idle = 0;
/* 0: Boot Protocol, 1: Report Protocol(default) */
uint8_t keyboard_protocol = 1;
-static uint8_t keyboard_led_stats = 0;
+static uint8_t keyboard_led_state = 0;
static report_keyboard_t keyboard_report_sent;
@@ -107,30 +107,30 @@ host_driver_t lufa_driver = {
};
#ifdef VIRTSER_ENABLE
+// clang-format off
+
USB_ClassInfo_CDC_Device_t cdc_device = {
- .Config =
- {
- .ControlInterfaceNumber = CCI_INTERFACE,
- .DataINEndpoint =
- {
- .Address = CDC_IN_EPADDR,
- .Size = CDC_EPSIZE,
- .Banks = 1,
- },
- .DataOUTEndpoint =
- {
- .Address = CDC_OUT_EPADDR,
- .Size = CDC_EPSIZE,
- .Banks = 1,
- },
- .NotificationEndpoint =
- {
- .Address = CDC_NOTIFICATION_EPADDR,
- .Size = CDC_NOTIFICATION_EPSIZE,
- .Banks = 1,
- },
+ .Config = {
+ .ControlInterfaceNumber = CCI_INTERFACE,
+ .DataINEndpoint = {
+ .Address = (CDC_IN_EPNUM | ENDPOINT_DIR_IN),
+ .Size = CDC_EPSIZE,
+ .Banks = 1
+ },
+ .DataOUTEndpoint = {
+ .Address = (CDC_OUT_EPNUM | ENDPOINT_DIR_OUT),
+ .Size = CDC_EPSIZE,
+ .Banks = 1
},
+ .NotificationEndpoint = {
+ .Address = (CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN),
+ .Size = CDC_NOTIFICATION_EPSIZE,
+ .Banks = 1
+ }
+ }
};
+
+// clang-format on
#endif
#ifdef RAW_ENABLE
@@ -258,7 +258,7 @@ static void Console_Task(void) {
// fill empty bank
while (Endpoint_IsReadWriteAllowed()) Endpoint_Write_8(0);
- // flash senchar packet
+ // flush sendchar packet
if (Endpoint_IsINReady()) {
Endpoint_ClearIN();
}
@@ -434,33 +434,32 @@ void EVENT_USB_Device_StartOfFrame(void) {
void EVENT_USB_Device_ConfigurationChanged(void) {
bool ConfigSuccess = true;
- /* Setup Keyboard HID Report Endpoints */
#ifndef KEYBOARD_SHARED_EP
- ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup keyboard report endpoint */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((KEYBOARD_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, KEYBOARD_EPSIZE, 1);
#endif
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
- /* Setup Mouse HID Report Endpoint */
- ConfigSuccess &= ENDPOINT_CONFIG(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup mouse report endpoint */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((MOUSE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, MOUSE_EPSIZE, 1);
#endif
#ifdef SHARED_EP_ENABLE
- /* Setup Shared HID Report Endpoint */
- ConfigSuccess &= ENDPOINT_CONFIG(SHARED_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, SHARED_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup shared report endpoint */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((SHARED_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, SHARED_EPSIZE, 1);
#endif
#ifdef RAW_ENABLE
- /* Setup Raw HID Report Endpoints */
- ConfigSuccess &= ENDPOINT_CONFIG(RAW_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
- ConfigSuccess &= ENDPOINT_CONFIG(RAW_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, RAW_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup raw HID endpoints */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1);
#endif
#ifdef CONSOLE_ENABLE
- /* Setup Console HID Report Endpoints */
- ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup console endpoint */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1);
# if 0
- ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
- CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1);
# endif
#endif
@@ -471,14 +470,16 @@ void EVENT_USB_Device_ConfigurationChanged(void) {
#endif
#ifdef MIDI_ENABLE
- ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
- ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup MIDI stream endpoints */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1);
#endif
#ifdef VIRTSER_ENABLE
- ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE);
- ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_OUT_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE);
- ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_IN_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE);
+ /* Setup virtual serial endpoints */
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, 1);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_BULK, CDC_EPSIZE, 1);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, CDC_EPSIZE, 1);
#endif
}
@@ -542,10 +543,10 @@ void EVENT_USB_Device_ControlRequest(void) {
uint8_t report_id = Endpoint_Read_8();
if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) {
- keyboard_led_stats = Endpoint_Read_8();
+ keyboard_led_state = Endpoint_Read_8();
}
} else {
- keyboard_led_stats = Endpoint_Read_8();
+ keyboard_led_state = Endpoint_Read_8();
}
Endpoint_ClearOUT();
@@ -657,7 +658,7 @@ void EVENT_USB_Device_ControlRequest(void) {
*
* FIXME: Needs doc
*/
-static uint8_t keyboard_leds(void) { return keyboard_led_stats; }
+static uint8_t keyboard_leds(void) { return keyboard_led_state; }
/** \brief Send Keyboard
*
@@ -920,25 +921,26 @@ ERROR_EXIT:
******************************************************************************/
#ifdef MIDI_ENABLE
+// clang-format off
+
USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = {
- .Config =
- {
- .StreamingInterfaceNumber = AS_INTERFACE,
- .DataINEndpoint =
- {
- .Address = MIDI_STREAM_IN_EPADDR,
- .Size = MIDI_STREAM_EPSIZE,
- .Banks = 1,
- },
- .DataOUTEndpoint =
- {
- .Address = MIDI_STREAM_OUT_EPADDR,
- .Size = MIDI_STREAM_EPSIZE,
- .Banks = 1,
- },
+ .Config = {
+ .StreamingInterfaceNumber = AS_INTERFACE,
+ .DataINEndpoint = {
+ .Address = (MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN),
+ .Size = MIDI_STREAM_EPSIZE,
+ .Banks = 1
},
+ .DataOUTEndpoint = {
+ .Address = (MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_OUT),
+ .Size = MIDI_STREAM_EPSIZE,
+ .Banks = 1
+ }
+ }
};
+// clang-format on
+
void send_midi_packet(MIDI_EventPacket_t *event) { MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event); }
bool recv_midi_packet(MIDI_EventPacket_t *const event) { return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event); }
diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h
index 82a5f8e05f..71fd7aad85 100644
--- a/tmk_core/protocol/lufa/lufa.h
+++ b/tmk_core/protocol/lufa/lufa.h
@@ -69,8 +69,4 @@ extern host_driver_t lufa_driver;
# define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0))
#endif
-#define ENDPOINT_BANK_SINGLE 1
-#define ENDPOINT_BANK_DOUBLE 2
-#define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum), eptype, epsize, epbank)
-
#endif
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index 7a88516035..253d897a51 100644
--- a/tmk_core/protocol/usb_descriptor.c
+++ b/tmk_core/protocol/usb_descriptor.c
@@ -719,7 +719,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t),
.Type = DTYPE_Endpoint
},
- .EndpointAddress = MIDI_STREAM_OUT_EPADDR,
+ .EndpointAddress = (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = MIDI_STREAM_EPSIZE,
.PollingIntervalMS = 0x05
@@ -742,7 +742,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t),
.Type = DTYPE_Endpoint
},
- .EndpointAddress = MIDI_STREAM_IN_EPADDR,
+ .EndpointAddress = (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = MIDI_STREAM_EPSIZE,
.PollingIntervalMS = 0x05
@@ -820,7 +820,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.Size = sizeof(USB_Descriptor_Endpoint_t),
.Type = DTYPE_Endpoint
},
- .EndpointAddress = CDC_NOTIFICATION_EPADDR,
+ .EndpointAddress = (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM),
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_NOTIFICATION_EPSIZE,
.PollingIntervalMS = 0xFF
@@ -843,7 +843,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.Size = sizeof(USB_Descriptor_Endpoint_t),
.Type = DTYPE_Endpoint
},
- .EndpointAddress = CDC_OUT_EPADDR,
+ .EndpointAddress = (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_EPSIZE,
.PollingIntervalMS = 0x05
@@ -853,7 +853,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.Size = sizeof(USB_Descriptor_Endpoint_t),
.Type = DTYPE_Endpoint
},
- .EndpointAddress = CDC_IN_EPADDR,
+ .EndpointAddress = (ENDPOINT_DIR_IN | CDC_IN_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_EPSIZE,
.PollingIntervalMS = 0x05
diff --git a/tmk_core/protocol/usb_descriptor.h b/tmk_core/protocol/usb_descriptor.h
index 8ee576cc0d..5ae52735bd 100644
--- a/tmk_core/protocol/usb_descriptor.h
+++ b/tmk_core/protocol/usb_descriptor.h
@@ -225,17 +225,12 @@ enum usb_endpoints {
#ifdef MIDI_ENABLE
MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM,
-# define MIDI_STREAM_IN_EPADDR (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM)
-# define MIDI_STREAM_OUT_EPADDR (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
#endif
#ifdef VIRTSER_ENABLE
CDC_NOTIFICATION_EPNUM = NEXT_EPNUM,
CDC_IN_EPNUM = NEXT_EPNUM,
CDC_OUT_EPNUM = NEXT_EPNUM,
-# define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM)
-# define CDC_IN_EPADDR (ENDPOINT_DIR_IN | CDC_IN_EPNUM)
-# define CDC_OUT_EPADDR (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM)
#endif
#ifdef WEBUSB_ENABLE
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 640cc8ff7f..c61577f919 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -65,7 +65,7 @@ enum usb_interfaces {
# 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
#endif
-static uint8_t vusb_keyboard_leds = 0;
+static uint8_t keyboard_led_state = 0;
static uint8_t vusb_idle_rate = 0;
/* Keyboard report send buffer */
@@ -74,13 +74,7 @@ static report_keyboard_t kbuf[KBUF_SIZE];
static uint8_t kbuf_head = 0;
static uint8_t kbuf_tail = 0;
-typedef struct {
- uint8_t modifier;
- uint8_t reserved;
- uint8_t keycode[6];
-} keyboard_report_t;
-
-static keyboard_report_t keyboard_report; // sent to PC
+static report_keyboard_t keyboard_report_sent;
#define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10
@@ -218,7 +212,7 @@ static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_sy
host_driver_t *vusb_driver(void) { return &driver; }
-static uint8_t keyboard_leds(void) { return vusb_keyboard_leds; }
+static uint8_t keyboard_leds(void) { return keyboard_led_state; }
static void send_keyboard(report_keyboard_t *report) {
uint8_t next = (kbuf_head + 1) % KBUF_SIZE;
@@ -232,6 +226,7 @@ static void send_keyboard(report_keyboard_t *report) {
// NOTE: send key strokes of Macro
usbPoll();
vusb_transfer_keyboard();
+ keyboard_report_sent = *report;
}
typedef struct {
@@ -289,9 +284,10 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */
if (rq->bRequest == USBRQ_HID_GET_REPORT) {
debug("GET_REPORT:");
- /* we only have one report type, so don't look at wValue */
- usbMsgPtr = (usbMsgPtr_t)&keyboard_report;
- return sizeof(keyboard_report);
+ if (rq->wIndex.word == KEYBOARD_INTERFACE) {
+ usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent;
+ return sizeof(keyboard_report_sent);
+ }
} else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
debug("GET_IDLE: ");
// debug_hex(vusb_idle_rate);
@@ -304,7 +300,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
} else if (rq->bRequest == USBRQ_HID_SET_REPORT) {
debug("SET_REPORT: ");
// Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard)
- if (rq->wValue.word == 0x0200 && rq->wIndex.word == 0) {
+ if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) {
debug("SET_LED: ");
last_req.kind = SET_LED;
last_req.len = rq->wLength.word;
@@ -335,7 +331,7 @@ uchar usbFunctionWrite(uchar *data, uchar len) {
debug("SET_LED: ");
debug_hex(data[0]);
debug("\n");
- vusb_keyboard_leds = data[0];
+ keyboard_led_state = data[0];
last_req.len = 0;
return 1;
break;