mirror of
https://github.com/zsa/qmk_firmware.git
synced 2026-05-07 11:59:00 +00:00
chore: code cleanup and refactors
This commit is contained in:
@@ -31,10 +31,6 @@
|
||||
#include "usb_descriptor.h"
|
||||
#include "usb_driver.h"
|
||||
|
||||
#ifdef WEBUSB_ENABLE
|
||||
# include "webusb.h"
|
||||
#endif
|
||||
|
||||
#ifdef NKRO_ENABLE
|
||||
# include "keycode_config.h"
|
||||
|
||||
@@ -159,44 +155,18 @@ static const USBEndpointConfig shared_ep_config = {
|
||||
#endif
|
||||
|
||||
#ifdef WEBUSB_ENABLE
|
||||
const MS_OS_20_Descriptor_t PROGMEM MS_OS_20_Descriptor = {
|
||||
.Header = {
|
||||
.Length = CPU_TO_LE16(10),
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_SET_HEADER_DESCRIPTOR),
|
||||
.WindowsVersion = MS_OS_20_WINDOWS_VERSION_8_1,
|
||||
.TotalLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_SET_TOTAL_LENGTH)
|
||||
},
|
||||
.ConfigurationSubsetHeader = {
|
||||
.Length = CPU_TO_LE16(8),
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_SUBSET_HEADER_CONFIGURATION),
|
||||
.ConfigurationValue = 0,
|
||||
.Reserved = 0,
|
||||
.TotalLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_CONFIGURATION_HEADER_LENGTH)
|
||||
},
|
||||
.FunctionSubsetHeader = {
|
||||
.Length = CPU_TO_LE16(8),
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_SUBSET_HEADER_FUNCTION),
|
||||
.FirstInterface = INTERFACE_ID_WebUSB,
|
||||
.Reserved = 0,
|
||||
.SubsetLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_FUNCTION_HEADER_LENGTH)
|
||||
},
|
||||
.CompatibleID = {
|
||||
.Length = CPU_TO_LE16(20),
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_FEATURE_COMPATBLE_ID),
|
||||
.CompatibleID = MS_OS_20_DESCRIPTOR_COMPATIBILITY_ID,
|
||||
.SubCompatibleID = MS_OS_20_DESCRIPTOR_SUB_COMPATIBILITY_ID
|
||||
},
|
||||
.RegistryProperty = {
|
||||
.Length = CPU_TO_LE16(132),
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_FEATURE_REG_PROPERTY),
|
||||
.PropertyDataType = CPU_TO_LE16(MS_OS_20_REG_MULTI_SZ),
|
||||
.PropertyNameLength = CPU_TO_LE16(MS_OS_20_PROPERTY_NAME_LENGTH),
|
||||
.PropertyName = MS_OS_20_PROPERTY_NAME,
|
||||
.PropertyDataLength = CPU_TO_LE16(MS_OS_20_PROPERTY_DATA_LENGTH),
|
||||
.PropertyData = MS_OS_20_PROPERTY_DATA
|
||||
}
|
||||
};
|
||||
/** Microsoft OS 2.0 Descriptor. This is used by Windows to select the USB driver for the device.
|
||||
*
|
||||
* For WebUSB in Chrome, the correct driver is WinUSB, which is selected via CompatibleID.
|
||||
*
|
||||
* Additionally, while Chrome is built using libusb, a magic registry key needs to be set containing a GUID for
|
||||
* the device.
|
||||
*/
|
||||
const MS_OS_20_Descriptor_t PROGMEM MS_OS_20_Descriptor = MS_OS_20_DESCRIPTOR;
|
||||
|
||||
/** URL descriptor string. This is a UTF-8 string containing a URL excluding the prefix. At least one of these must be
|
||||
* defined and returned when the Landing Page descriptor index is requested.
|
||||
*/
|
||||
const WebUSB_URL_Descriptor_t PROGMEM WebUSB_LandingPage = WEBUSB_URL_DESCRIPTOR(WEBUSB_LANDING_PAGE_URL);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -269,7 +269,6 @@ static void Console_Task(void) {
|
||||
#endif
|
||||
|
||||
#ifdef WEBUSB_ENABLE
|
||||
|
||||
void webusb_send(uint8_t *data, uint8_t length) {
|
||||
if (USB_DeviceState != DEVICE_STATE_Configured) {
|
||||
return;
|
||||
@@ -320,43 +319,7 @@ static void webusb_task(void) {
|
||||
* Additionally, while Chrome is built using libusb, a magic registry key needs to be set containing a GUID for
|
||||
* the device.
|
||||
*/
|
||||
const MS_OS_20_Descriptor_t PROGMEM MS_OS_20_Descriptor = {
|
||||
.Header = {
|
||||
.Length = CPU_TO_LE16(10),
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_SET_HEADER_DESCRIPTOR),
|
||||
.WindowsVersion = MS_OS_20_WINDOWS_VERSION_8_1,
|
||||
.TotalLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_SET_TOTAL_LENGTH)
|
||||
},
|
||||
.ConfigurationSubsetHeader = {
|
||||
.Length = CPU_TO_LE16(8),
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_SUBSET_HEADER_CONFIGURATION),
|
||||
.ConfigurationValue = 0,
|
||||
.Reserved = 0,
|
||||
.TotalLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_CONFIGURATION_HEADER_LENGTH)
|
||||
},
|
||||
.FunctionSubsetHeader = {
|
||||
.Length = CPU_TO_LE16(8),
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_SUBSET_HEADER_FUNCTION),
|
||||
.FirstInterface = INTERFACE_ID_WebUSB,
|
||||
.Reserved = 0,
|
||||
.SubsetLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_FUNCTION_HEADER_LENGTH)
|
||||
},
|
||||
.CompatibleID = {
|
||||
.Length = CPU_TO_LE16(20),
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_FEATURE_COMPATBLE_ID),
|
||||
.CompatibleID = MS_OS_20_DESCRIPTOR_COMPATIBILITY_ID,
|
||||
.SubCompatibleID = MS_OS_20_DESCRIPTOR_SUB_COMPATIBILITY_ID
|
||||
},
|
||||
.RegistryProperty = {
|
||||
.Length = CPU_TO_LE16(132),
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_FEATURE_REG_PROPERTY),
|
||||
.PropertyDataType = CPU_TO_LE16(MS_OS_20_REG_MULTI_SZ),
|
||||
.PropertyNameLength = CPU_TO_LE16(MS_OS_20_PROPERTY_NAME_LENGTH),
|
||||
.PropertyName = MS_OS_20_PROPERTY_NAME,
|
||||
.PropertyDataLength = CPU_TO_LE16(MS_OS_20_PROPERTY_DATA_LENGTH),
|
||||
.PropertyData = MS_OS_20_PROPERTY_DATA
|
||||
}
|
||||
};
|
||||
const MS_OS_20_Descriptor_t PROGMEM MS_OS_20_Descriptor = MS_OS_20_DESCRIPTOR;
|
||||
|
||||
/** URL descriptor string. This is a UTF-8 string containing a URL excluding the prefix. At least one of these must be
|
||||
* defined and returned when the Landing Page descriptor index is requested.
|
||||
@@ -502,8 +465,11 @@ void EVENT_USB_Device_ConfigurationChanged(void) {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef WEBUSB_ENABLE
|
||||
/* Setup Webusb Endpoints */
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(WEBUSB_IN_EPADDR, EP_TYPE_INTERRUPT, WEBUSB_EPSIZE, 1);
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(WEBUSB_OUT_EPADDR, EP_TYPE_INTERRUPT, WEBUSB_EPSIZE, 1);
|
||||
#endif
|
||||
|
||||
#ifdef MIDI_ENABLE
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
|
||||
@@ -636,6 +602,7 @@ void EVENT_USB_Device_ControlRequest(void) {
|
||||
}
|
||||
|
||||
break;
|
||||
#ifdef WEBUSB_ENABLE
|
||||
case WEBUSB_VENDOR_CODE:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE)) {
|
||||
switch (USB_ControlRequest.wIndex) {
|
||||
@@ -675,6 +642,7 @@ void EVENT_USB_Device_ControlRequest(void) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef VIRTSER_ENABLE
|
||||
|
||||
@@ -40,7 +40,9 @@
|
||||
#include "report.h"
|
||||
#include "usb_descriptor.h"
|
||||
#include "print.h"
|
||||
|
||||
#ifdef WEBUSB_ENABLE
|
||||
# include "webusb.h"
|
||||
#endif
|
||||
/*
|
||||
* HID report descriptors
|
||||
*/
|
||||
@@ -275,10 +277,12 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef WEBUSB_ENABLE
|
||||
const USB_Descriptor_BOS_t PROGMEM BOSDescriptor = BOS_DESCRIPTOR(
|
||||
(MS_OS_20_PLATFORM_DESCRIPTOR(MS_OS_20_VENDOR_CODE, MS_OS_20_DESCRIPTOR_SET_TOTAL_LENGTH))
|
||||
(WEBUSB_PLATFORM_DESCRIPTOR(WEBUSB_VENDOR_CODE, WEBUSB_LANDING_PAGE_INDEX))
|
||||
);
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@@ -555,10 +559,12 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
|
||||
Size = sizeof(USB_Descriptor_Device_t);
|
||||
|
||||
break;
|
||||
case DTYPE_BOS:
|
||||
Address = &BOSDescriptor;
|
||||
Size = pgm_read_byte(&BOSDescriptor.TotalLength);
|
||||
break;
|
||||
#ifdef WEBUSB_ENABLE
|
||||
case DTYPE_BOS:
|
||||
Address = &BOSDescriptor;
|
||||
Size = pgm_read_byte(&BOSDescriptor.TotalLength);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case DTYPE_Configuration:
|
||||
Address = &ConfigurationDescriptor;
|
||||
|
||||
@@ -215,17 +215,41 @@ typedef struct {
|
||||
MS_OS_20_Registry_Property_Descriptor RegistryProperty;
|
||||
} MS_OS_20_Descriptor_t;
|
||||
|
||||
typedef struct {
|
||||
MS_OS_20_Descriptor_Set_Header_t Header;
|
||||
MS_OS_20_Configuration_Subset_Header ConfigurationSubsetHeader;
|
||||
MS_OS_20_Function_Subset_Header FunctionSubsetHeader;
|
||||
#define MS_OS_20_DESCRIPTOR { \
|
||||
.Header = { \
|
||||
.Length = CPU_TO_LE16(10), \
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_SET_HEADER_DESCRIPTOR), \
|
||||
.WindowsVersion = MS_OS_20_WINDOWS_VERSION_8_1, \
|
||||
.TotalLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_SET_TOTAL_LENGTH) \
|
||||
}, \
|
||||
.ConfigurationSubsetHeader = { \
|
||||
.Length = CPU_TO_LE16(8), \
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_SUBSET_HEADER_CONFIGURATION), \
|
||||
.ConfigurationValue = 0, \
|
||||
.Reserved = 0, \
|
||||
.TotalLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_CONFIGURATION_HEADER_LENGTH) \
|
||||
}, \
|
||||
.FunctionSubsetHeader = { \
|
||||
.Length = CPU_TO_LE16(8), \
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_SUBSET_HEADER_FUNCTION), \
|
||||
.FirstInterface = INTERFACE_ID_WebUSB, \
|
||||
.Reserved = 0, \
|
||||
.SubsetLength = CPU_TO_LE16(MS_OS_20_DESCRIPTOR_FUNCTION_HEADER_LENGTH) \
|
||||
}, \
|
||||
.CompatibleID = { \
|
||||
.Length = CPU_TO_LE16(20), \
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_FEATURE_COMPATBLE_ID), \
|
||||
.CompatibleID = MS_OS_20_DESCRIPTOR_COMPATIBILITY_ID, \
|
||||
.SubCompatibleID = MS_OS_20_DESCRIPTOR_SUB_COMPATIBILITY_ID \
|
||||
}, \
|
||||
.RegistryProperty = { \
|
||||
.Length = CPU_TO_LE16(132), \
|
||||
.DescriptorType = CPU_TO_LE16(MS_OS_20_FEATURE_REG_PROPERTY), \
|
||||
.PropertyDataType = CPU_TO_LE16(MS_OS_20_REG_MULTI_SZ), \
|
||||
.PropertyNameLength = CPU_TO_LE16(MS_OS_20_PROPERTY_NAME_LENGTH), \
|
||||
.PropertyName = MS_OS_20_PROPERTY_NAME, \
|
||||
.PropertyDataLength = CPU_TO_LE16(MS_OS_20_PROPERTY_DATA_LENGTH), \
|
||||
.PropertyData = MS_OS_20_PROPERTY_DATA \
|
||||
} \
|
||||
}
|
||||
|
||||
} MS_OS_20_Descriptor_Prefix_t;
|
||||
|
||||
typedef struct {
|
||||
MS_OS_20_CompatibleID_Descriptor CompatibleID;
|
||||
} MS_OS_20_Descriptor_Suffix_t;
|
||||
|
||||
typedef struct {
|
||||
MS_OS_20_Registry_Property_Descriptor RegistryProperty;
|
||||
} MS_OS_20_Descriptor_Custom_Property_t;
|
||||
|
||||
Reference in New Issue
Block a user