diff options
author | Florian Didron <fd@librem.one> | 2019-11-04 16:30:23 +0900 |
---|---|---|
committer | Florian Didron <fd@librem.one> | 2019-11-04 16:30:23 +0900 |
commit | 04113a76acc93df411027666a053f132c03a6206 (patch) | |
tree | 4db9810cefdf6816bae538f5c4d7603ed0f4b925 | |
parent | 8e142defed97b54764c32c83107a0fc848e46e05 (diff) |
chore: code cleanup and refactorsfeat/webusb
-rw-r--r-- | tmk_core/protocol/chibios/usb_main.c | 52 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 44 | ||||
-rw-r--r-- | tmk_core/protocol/usb_descriptor.c | 16 | ||||
-rw-r--r-- | tmk_core/protocol/webusb.h | 50 |
4 files changed, 65 insertions, 97 deletions
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 7abff24780..0ff761bf31 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -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 diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 6f224dbbc7..f67bce204d 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -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 diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index aeba363eae..7b05e8b7f8 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c @@ -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; diff --git a/tmk_core/protocol/webusb.h b/tmk_core/protocol/webusb.h index a18f0ccfee..c0b45c758e 100644 --- a/tmk_core/protocol/webusb.h +++ b/tmk_core/protocol/webusb.h @@ -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; - -} MS_OS_20_Descriptor_Prefix_t; - -typedef struct { - MS_OS_20_CompatibleID_Descriptor CompatibleID; -} MS_OS_20_Descriptor_Suffix_t; +#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 \ + } \ +} -typedef struct { - MS_OS_20_Registry_Property_Descriptor RegistryProperty; -} MS_OS_20_Descriptor_Custom_Property_t; |