From ef2a46999f0aea63b12010cec73b7e4fc5a13843 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Mon, 18 Oct 2021 18:50:56 +0200 Subject: [PATCH] WIP: Workaround for failing HID enumeration --- tmk_core/protocol/chibios/usb_main.c | 20 ++-- tmk_core/protocol/usb_descriptor.c | 159 +++++---------------------- 2 files changed, 37 insertions(+), 142 deletions(-) diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 541c44b574e2..c62fd426206a 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -129,8 +129,8 @@ static const USBEndpointConfig kbd_ep_config = { 0, /* OUT maximum packet size */ &kbd_ep_state, /* IN Endpoint state */ NULL, /* OUT endpoint state */ - 2, /* IN multiplier */ - NULL /* SETUP buffer (not a SETUP endpoint) */ + /* 2, */ /* IN multiplier */ + /* NULL */ /* SETUP buffer (not a SETUP endpoint) */ }; #endif @@ -167,8 +167,8 @@ static const USBEndpointConfig shared_ep_config = { 0, /* OUT maximum packet size */ &shared_ep_state, /* IN Endpoint state */ NULL, /* OUT endpoint state */ - 2, /* IN multiplier */ - NULL /* SETUP buffer (not a SETUP endpoint) */ + /*2,*/ /* IN multiplier */ + /*NULL */ /* SETUP buffer (not a SETUP endpoint) */ }; #endif @@ -259,8 +259,8 @@ typedef struct { 0, /* OUT maximum packet size */ \ NULL, /* IN Endpoint state */ \ NULL, /* OUT endpoint state */ \ - 2, /* IN multiplier */ \ - NULL /* SETUP buffer (not a SETUP endpoint) */ \ + /*2,*/ /* IN multiplier */ \ + /* NULL */ /* SETUP buffer (not a SETUP endpoint) */ \ }, \ .out_ep_config = \ { \ @@ -272,8 +272,8 @@ typedef struct { stream##_EPSIZE, /* OUT maximum packet size */ \ NULL, /* IN Endpoint state */ \ NULL, /* OUT endpoint state */ \ - 2, /* IN multiplier */ \ - NULL, /* SETUP buffer (not a SETUP endpoint) */ \ + /* 2,*/ /* IN multiplier */ \ + /*NULL,*/ /* SETUP buffer (not a SETUP endpoint) */ \ }, \ .int_ep_config = \ { \ @@ -285,8 +285,8 @@ typedef struct { 0, /* OUT maximum packet size */ \ NULL, /* IN Endpoint state */ \ NULL, /* OUT endpoint state */ \ - 2, /* IN multiplier */ \ - NULL, /* SETUP buffer (not a SETUP endpoint) */ \ + /*2, */ /* IN multiplier */ \ + /*NULL, */ /* SETUP buffer (not a SETUP endpoint) */ \ }, \ .config = { \ .usbp = &USB_DRIVER, \ diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index 0b992ba6c5dd..843ed4cb9c4d 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c @@ -91,11 +91,14 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = { HID_RI_USAGE_MAXIMUM(8, 0x05), // Kana HID_RI_REPORT_COUNT(8, 0x05), HID_RI_REPORT_SIZE(8, 0x01), - HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), - // LED padding (3 bits) - HID_RI_REPORT_COUNT(8, 0x01), - HID_RI_REPORT_SIZE(8, 0x03), - HID_RI_OUTPUT(8, HID_IOF_CONSTANT), + // 0x91, 0x2, // stock - broken + // 0x90, 0x00, // broken + 0x00, 0x00, // working + // HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE), + // // LED padding (3 bits) + // HID_RI_REPORT_COUNT(8, 0x01), + // HID_RI_REPORT_SIZE(8, 0x03), + // HID_RI_OUTPUT(8, HID_IOF_CONSTANT), HID_RI_END_COLLECTION(0), #ifndef KEYBOARD_SHARED_EP }; @@ -116,15 +119,19 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { # endif HID_RI_USAGE(8, 0x01), // Pointer HID_RI_COLLECTION(8, 0x00), // Physical - // Buttons (8 bits) + // Buttons (5 bits) HID_RI_USAGE_PAGE(8, 0x09), // Button HID_RI_USAGE_MINIMUM(8, 0x01), // Button 1 - HID_RI_USAGE_MAXIMUM(8, 0x08), // Button 8 + HID_RI_USAGE_MAXIMUM(8, 0x05), // Button 5 HID_RI_LOGICAL_MINIMUM(8, 0x00), HID_RI_LOGICAL_MAXIMUM(8, 0x01), - HID_RI_REPORT_COUNT(8, 0x08), + HID_RI_REPORT_COUNT(8, 0x05), HID_RI_REPORT_SIZE(8, 0x01), HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + // Button padding (3 bits) + HID_RI_REPORT_COUNT(8, 0x01), + HID_RI_REPORT_SIZE(8, 0x03), + HID_RI_INPUT(8, HID_IOF_CONSTANT), // X/Y position (2 bytes) HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop @@ -158,53 +165,6 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { # endif #endif -#ifdef DIGITIZER_ENABLE -# ifndef DIGITIZER_SHARED_EP -const USB_Descriptor_HIDReport_Datatype_t PROGMEM DigitizerReport[] = { -# elif !defined(SHARED_REPORT_STARTED) -const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { -# define SHARED_REPORT_STARTED -# endif - HID_RI_USAGE_PAGE(8, 0x0D), // Digitizers - HID_RI_USAGE(8, 0x01), // Digitizer - HID_RI_COLLECTION(8, 0x01), // Application -# ifdef DIGITIZER_SHARED_EP - HID_RI_REPORT_ID(8, REPORT_ID_DIGITIZER), -# endif - HID_RI_USAGE(8, 0x20), // Stylus - HID_RI_COLLECTION(8, 0x00), // Physical - // Tip Switch (1 bit) - HID_RI_USAGE(8, 0x42), // Tip Switch - HID_RI_LOGICAL_MINIMUM(8, 0x00), - HID_RI_LOGICAL_MAXIMUM(8, 0x01), - HID_RI_REPORT_SIZE(8, 0x01), - HID_RI_REPORT_COUNT(8, 0x01), - HID_RI_INPUT(8, HID_IOF_VARIABLE), - // In Range (1 bit) - HID_RI_USAGE(8, 0x32), // In Range - HID_RI_INPUT(8, HID_IOF_VARIABLE), - // Padding (6 bits) - HID_RI_REPORT_COUNT(8, 0x06), - HID_RI_INPUT(8, HID_IOF_CONSTANT | HID_IOF_VARIABLE), - - // X/Y Position (4 bytes) - HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop - HID_RI_LOGICAL_MAXIMUM(16, 0x7FFF), - HID_RI_REPORT_SIZE(8, 0x10), - HID_RI_REPORT_COUNT(8, 0x01), - HID_RI_UNIT(8, 0x33), // Inch, English Linear - HID_RI_UNIT_EXPONENT(8, 0x0E), // -2 - HID_RI_USAGE(8, 0x30), // X - HID_RI_INPUT(8, HID_IOF_VARIABLE), - HID_RI_USAGE(8, 0x31), // Y - HID_RI_INPUT(8, HID_IOF_VARIABLE), - HID_RI_END_COLLECTION(0), - HID_RI_END_COLLECTION(0), -# ifndef DIGITIZER_SHARED_EP -}; -# endif -#endif - #if defined(SHARED_EP_ENABLE) && !defined(SHARED_REPORT_STARTED) const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { #endif @@ -237,25 +197,6 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { HID_RI_END_COLLECTION(0), #endif -#ifdef PROGRAMMABLE_BUTTON_ENABLE - HID_RI_USAGE_PAGE(8, 0x0C), // Consumer - HID_RI_USAGE(8, 0x01), // Consumer Control - HID_RI_COLLECTION(8, 0x01), // Application - HID_RI_REPORT_ID(8, REPORT_ID_PROGRAMMABLE_BUTTON), - HID_RI_USAGE(8, 0x03), // Programmable Buttons - HID_RI_COLLECTION(8, 0x04), // Named Array - HID_RI_USAGE_PAGE(8, 0x09), // Button - HID_RI_USAGE_MINIMUM(8, 0x01), // Button 1 - HID_RI_USAGE_MAXIMUM(8, 0x20), // Button 32 - HID_RI_LOGICAL_MINIMUM(8, 0x00), - HID_RI_LOGICAL_MAXIMUM(8, 0x01), - HID_RI_REPORT_COUNT(8, 32), - HID_RI_REPORT_SIZE(8, 1), - HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), - HID_RI_END_COLLECTION(0), - HID_RI_END_COLLECTION(0), -#endif - #ifdef NKRO_ENABLE HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop HID_RI_USAGE(8, 0x06), // Keyboard @@ -293,7 +234,6 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { HID_RI_OUTPUT(8, HID_IOF_CONSTANT), HID_RI_END_COLLECTION(0), #endif - #ifdef SHARED_EP_ENABLE }; #endif @@ -410,6 +350,14 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = { }; #endif +#ifndef SERIAL_NUMBER +#ifdef VIAL_ENABLE +# define SERIAL_NUMBER vial:f64c2b3c +#else +# define SERIAL_NUMBER 0 +#endif +#endif + /* * Device descriptor */ @@ -418,8 +366,8 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = { .Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device }, - .USBSpecification = VERSION_BCD(2, 0, 0), - + .USBSpecification = VERSION_BCD(1, 1, 0), + #if VIRTSER_ENABLE .Class = USB_CSCP_IADDeviceClass, .SubClass = USB_CSCP_IADDeviceSubclass, @@ -988,46 +936,6 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .PollingIntervalMS = USB_POLLING_INTERVAL_MS } #endif - -#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP) - /* - * Digitizer - */ - .Digitizer_Interface = { - .Header = { - .Size = sizeof(USB_Descriptor_Interface_t), - .Type = DTYPE_Interface - }, - .InterfaceNumber = DIGITIZER_INTERFACE, - .AlternateSetting = 0x00, - .TotalEndpoints = 1, - .Class = HID_CSCP_HIDClass, - .SubClass = HID_CSCP_NonBootSubclass, - .Protocol = HID_CSCP_NonBootProtocol, - .InterfaceStrIndex = NO_DESCRIPTOR - }, - .Digitizer_HID = { - .Header = { - .Size = sizeof(USB_HID_Descriptor_HID_t), - .Type = HID_DTYPE_HID - }, - .HIDSpec = VERSION_BCD(1, 1, 1), - .CountryCode = 0x00, - .TotalReportDescriptors = 1, - .HIDReportType = HID_DTYPE_Report, - .HIDReportLength = sizeof(DigitizerReport) - }, - .Digitizer_INEndpoint = { - .Header = { - .Size = sizeof(USB_Descriptor_Endpoint_t), - .Type = DTYPE_Endpoint - }, - .EndpointAddress = (ENDPOINT_DIR_IN | DIGITIZER_IN_EPNUM), - .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), - .EndpointSize = DIGITIZER_EPSIZE, - .PollingIntervalMS = USB_POLLING_INTERVAL_MS - }, -#endif }; /* @@ -1060,10 +968,10 @@ const USB_Descriptor_String_t PROGMEM ProductString = { #if defined(SERIAL_NUMBER) const USB_Descriptor_String_t PROGMEM SerialNumberString = { .Header = { - .Size = USB_STRING_LEN(sizeof(SERIAL_NUMBER) - 1), // Subtract 1 for null terminator + .Size = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1), // Subtract 1 for null terminator .Type = DTYPE_String }, - .UnicodeString = USBSTR(SERIAL_NUMBER) + .UnicodeString = LSTR(SERIAL_NUMBER) }; #endif @@ -1166,13 +1074,6 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const Size = sizeof(USB_HID_Descriptor_HID_t); break; #endif -#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP) - case DIGITIZER_INTERFACE: - Address = &ConfigurationDescriptor.Digitizer_HID; - Size = sizeof(USB_HID_Descriptor_HID_t); - - break; -#endif } break; @@ -1222,12 +1123,6 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const Address = &JoystickReport; Size = sizeof(JoystickReport); break; -#endif -#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP) - case DIGITIZER_INTERFACE: - Address = &DigitizerReport; - Size = sizeof(DigitizerReport); - break; #endif }