diff --git a/lib/usb_device/include/usb_device.h b/lib/usb_device/include/usb_device.h index 4329343..94d60bd 100644 --- a/lib/usb_device/include/usb_device.h +++ b/lib/usb_device/include/usb_device.h @@ -13,9 +13,9 @@ class USB_Device public: - static const int16_t usb_joystick_x = 511; - static const int16_t usb_joystick_y = 511; - static const int16_t usb_joystick_r = 511; + static const int16_t usb_joystick_x = 0; + static const int16_t usb_joystick_y = 0; + static const int16_t usb_joystick_r = 0x7FFF; USB_Device() {} @@ -26,11 +26,11 @@ class USB_Device void button(uint8_t button, bool val); void dpad(uint8_t dir); - void joystick_left(uint16_t x, uint16_t y); - void joystick_right(uint16_t x, uint16_t y); + void joystick_left(int16_t x, int16_t y); + void joystick_right(int16_t x, int16_t y); - void trigger_left(uint16_t val); - void trigger_right(uint16_t val); + void trigger_left(uint8_t val); + void trigger_right(uint8_t val); void sendReport(); }; diff --git a/lib/usb_device/include/usbd_descriptors.h b/lib/usb_device/include/usbd_descriptors.h index 1afc6fb..b71b728 100644 --- a/lib/usb_device/include/usbd_descriptors.h +++ b/lib/usb_device/include/usbd_descriptors.h @@ -3,7 +3,7 @@ #include -#define USB_HID_CUSTOM_CONFIG_DESC_SIZ 34U +#define USB_HID_CUSTOM_CONFIG_DESC_SIZ 153U #define USB_HID_CUSTOM_DESC_SIZ 9U #define USB_LEN_DEV_QUALIFIER_DESC 0x0AU @@ -19,11 +19,11 @@ #define HID_CUSTOM_INTERFACE 0x00U #define HID_CUSTOM_EPIN_ADDR 0x81U -#define HID_CUSTOM_EPIN_SIZE 0x08U +#define HID_CUSTOM_EPIN_SIZE 0x10U // USB HID device FS Configuration Descriptor extern uint8_t USBD_HID_CUSTOM_CfgFSDesc[USB_HID_CUSTOM_CONFIG_DESC_SIZ]; - +/* // USB HID device HS Configuration Descriptor extern uint8_t USBD_HID_CUSTOM_CfgHSDesc[USB_HID_CUSTOM_CONFIG_DESC_SIZ]; @@ -35,5 +35,5 @@ extern uint8_t USBD_HID_CUSTOM_Desc[USB_HID_CUSTOM_DESC_SIZ]; // USB Standard Device Descriptor extern uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC]; - +*/ #endif \ No newline at end of file diff --git a/lib/usb_device/include/usbd_report.h b/lib/usb_device/include/usbd_report.h index 8b30016..a74844e 100644 --- a/lib/usb_device/include/usbd_report.h +++ b/lib/usb_device/include/usbd_report.h @@ -6,8 +6,8 @@ #define HID_JOYSTICK_REPORT_DESC_SIZE 104U // USB Joystick Report Descriptor -extern uint8_t USBD_HID_Joystick_ReportDesc[HID_JOYSTICK_REPORT_DESC_SIZE]; - +//extern uint8_t USBD_HID_Joystick_ReportDesc[HID_JOYSTICK_REPORT_DESC_SIZE]; +/* struct __attribute__((packed)) USBD_HID_Joystick_Report { uint8_t reportID = 20; @@ -20,19 +20,22 @@ struct __attribute__((packed)) USBD_HID_Joystick_Report unsigned rx:10; unsigned ry:10; }; -/* +*/ struct __attribute__((packed)) USBD_HID_Joystick_Report { - unsigned header:16; - unsigned buttons:16; - //unsigned hat:4; - unsigned trigger_left:8; - unsigned trigger_right:8; - unsigned x:16; - unsigned y:16; - unsigned rx:16; - unsigned ry:16; + uint8_t msg_type:8; // byte 0 + uint8_t msg_len:8; // byte 1 + + uint16_t buttons:16; // bytes 2 and 3 + uint8_t trigger_left:8; // byte 4 + uint8_t trigger_right:8; // byte 5 + int16_t x:16; // byte 6 + int16_t y:16; // byte 7 + int16_t rx:16; // byte 8 + int16_t ry:16; // byte 9 + + //uint32_t unused0:32; + //uint16_t unused1:16; }; -*/ #endif \ No newline at end of file diff --git a/lib/usb_device/src/usb_device.cpp b/lib/usb_device/src/usb_device.cpp index f9b4241..97416ca 100644 --- a/lib/usb_device/src/usb_device.cpp +++ b/lib/usb_device/src/usb_device.cpp @@ -6,8 +6,10 @@ void USB_Device::begin() { HID_Custom_Init(); + report.msg_type = 0x00; + report.msg_len = 0x14; report.buttons = 0; - report.hat = 15; + //report.hat = 15; report.x = usb_joystick_x; report.y = usb_joystick_y; report.rx = usb_joystick_x; @@ -40,29 +42,29 @@ void USB_Device::button(uint8_t button, bool val) void USB_Device::dpad(uint8_t dir) { - report.hat = dir; + //report.hat = dir; } -void USB_Device::joystick_left(uint16_t x, uint16_t y) +void USB_Device::joystick_left(int16_t x, int16_t y) { - report.x = x & 0x3FF; - report.y = y & 0x3FF; + report.x = x; + report.y = y; } -void USB_Device::joystick_right(uint16_t x, uint16_t y) +void USB_Device::joystick_right(int16_t x, int16_t y) { - report.rx = x & 0x3FF; - report.ry = y & 0x3FF; + report.rx = x; + report.ry = y; } -void USB_Device::trigger_left(uint16_t val) +void USB_Device::trigger_left(uint8_t val) { - report.trigger_left = val & 0x3FF;; + report.trigger_left = val & 0xFF; } -void USB_Device::trigger_right(uint16_t val) +void USB_Device::trigger_right(uint8_t val) { - report.trigger_right = val & 0x3FF;; + report.trigger_right = val & 0xFF; } void USB_Device::sendReport() diff --git a/lib/usb_device/src/usbd_decriptors.cpp b/lib/usb_device/src/usbd_decriptors.cpp index fa1eaf2..b20e35d 100644 --- a/lib/usb_device/src/usbd_decriptors.cpp +++ b/lib/usb_device/src/usbd_decriptors.cpp @@ -10,46 +10,113 @@ __ALIGN_BEGIN uint8_t USBD_HID_CUSTOM_CfgFSDesc[USB_HID_CUSTOM_CONFIG_DESC_SIZ] USB_DESC_TYPE_CONFIGURATION, // bDescriptorType: Configuration LOBYTE(USB_HID_CUSTOM_CONFIG_DESC_SIZ), // wTotalLength: Bytes returned HIBYTE(USB_HID_CUSTOM_CONFIG_DESC_SIZ), - 0x01, //bNumInterfaces: 2 interface + 0x04, //bNumInterfaces: 2 interface 0x01, //bConfigurationValue: Configuration value 0x00, //iConfiguration: Index of string descriptor describing the configuration - 0xC0, //bmAttributes: bus powered and no Support Remote Wake-up - 0x32, //MaxPower 100 mA: this current is used for detecting Vbus + 0xA0, //bmAttributes: bus powered and no Support Remote Wake-up + 0xFA, //MaxPower 100 mA: this current is used for detecting Vbus - //************* Descriptor of interface *************** - // 09 - 0x09, //bLength: Interface Descriptor size - USB_DESC_TYPE_INTERFACE,//bDescriptorType: Interface descriptor type - HID_CUSTOM_INTERFACE, //bInterfaceNumber: Number of Interface - 0x00, //bAlternateSetting: Alternate setting - 0x01, //bNumEndpoints - 0x03, //bInterfaceClass: HID - 0x00, //bInterfaceSubClass : 1=BOOT, 0=no boot - 0x00, //nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse - 0x00, //iInterface: Index of string descriptor - //******************* Descriptor of Joystick Mouse HID ******************* - // 18 - 0x09, //bLength: HID Descriptor size - HID_DESCRIPTOR_TYPE, //bDescriptorType: HID - 0x11, //bcdHID: HID Class Spec release number - 0x01, - 0x00, //bCountryCode: Hardware target country - 0x01, //bNumDescriptors: Number of HID class descriptors to follow - 0x22, //bDescriptorType - HID_JOYSTICK_REPORT_DESC_SIZE,//wItemLength: Total length of Report descriptor - 0x00, - //******************* Descriptor of Mouse endpoint ******************* - // 27 - 0x07, //bLength: Endpoint Descriptor size - USB_DESC_TYPE_ENDPOINT, //bDescriptorType: - - HID_CUSTOM_EPIN_ADDR, //bEndpointAddress: Endpoint Address (IN) - 0x03, //bmAttributes: Interrupt endpoint - HID_CUSTOM_EPIN_SIZE, //wMaxPacketSize: 4 Byte max - 0x00, - HID_FS_BINTERVAL, //bInterval: Polling Interval +//Interface 0 + 9, //bLength (length of interface descriptor 9 bytes) + 4, //bDescriptorType (4 is interface) + 0, //bInterfaceNumber (This is interface 0) + 0, //bAlternateSetting (used to select alternate setting. notused) + 2, //bNumEndpoints (this interface has 2 endpoints) + 0xFF, //bInterfaceClass (Vendor Defined is 255) + 0x5D, //bInterfaceSubClass + 0x01, //bInterfaceProtocol + 0, //iInterface (Index of string descriptor for describing this notused) + //Some sort of common descriptor? I pulled this from Message Analyzer dumps of an actual controller + 17,33,0,1,1,37,129,20,0,0,0,0,19,2,8,0,0, + //Endpoint 1 IN + 7, //bLength (length of ep1in in descriptor 7 bytes) + 5, //bDescriptorType (5 is endpoint) + 0x81, //bEndpointAddress (0x81 is IN1) + 0x03, //bmAttributes (0x03 is interrupt no synch, usage type data) + 0x20, 0x00, //wMaxPacketSize (0x0020 is 1x32 bytes) + 4, //bInterval (polling interval in frames 4 frames) + //Endpoint 2 OUT + 7, //bLength (length of ep2out in descriptor 7 bytes) + 5, //bDescriptorType (5 is endpoint) + 0x02, //bEndpointAddress (0x02 is OUT2) + 0x03, //bmAttributes (0x03 is interrupt no synch, usage type data) + 0x20, 0x00, //wMaxPacketSize (0x0020 is 1x32 bytes) + 8, //bInterval (polling interval in frames 8 frames) +//Interface 1 + 9, //bLength (length of interface descriptor 9 bytes) + 4, //bDescriptorType (4 is interface) + 1, //bInterfaceNumber (This is interface 1) + 0, //bAlternateSetting (used to select alternate setting. notused) + 4, //bNumEndpoints (this interface has 4 endpoints) + 0xFF, //bInterfaceClass (Vendor Defined is 255) + 0x5D, //bInterfaceSubClass (93) + 0x03, //bInterfaceProtocol (3) + 0, //iInterface (Index of string descriptor for describing this notused) + //A different common descriptor? I pulled this from Message Analyzer dumps of an actual controller + 27,33,0,1,1,1,131,64,1,4,32,22,133,0,0,0,0,0,0,22,5,0,0,0,0,0,0, + //Endpoint 3 IN + 7, //bLength (length of ep3in descriptor 7 bytes) + 5, //bDescriptorType (5 is endpoint) + 0x83, //bEndpointAddress (0x83 is IN3) + 0x03, //bmAttributes (0x03 is interrupt no synch, usage type data) + 0x20, 0x00, //wMaxPacketSize (0x0020 is 1x32 bytes) + 2, //bInterval (polling interval in frames 2 frames) + //Endpoint 4 OUT + 7, //bLength (length of ep4out descriptor 7 bytes) + 5, //bDescriptorType (5 is endpoint) + 0x04, //bEndpointAddress (0x04 is OUT4) + 0x03, //bmAttributes (0x03 is interrupt no synch, usage type data) + 0x20, 0x00, //wMaxPacketSize (0x0020 is 1x32 bytes) + 4, //bInterval (polling interval in frames 4 frames) + //Endpoint 5 IN + 7, //bLength (length of ep5in descriptor 7 bytes) + 5, //bDescriptorType (5 is endpoint) + 0x85, //bEndpointAddress (0x85 is IN5) + 0x03, //bmAttributes (0x03 is interrupt no synch, usage type data) + 0x20, 0x00, //wMaxPacketSize (0x0020 is 1x32 bytes) + 64, //bInterval (polling interval in frames 64 frames) + //Endpoint 5 OUT (shares endpoint number with previous) + 7, //bLength (length of ep5out descriptor 7 bytes) + 5, //bDescriptorType (5 is endpoint) + 0x05, //bEndpointAddress (0x05 is OUT5) + 0x03, //bmAttributes (0x03 is interrupt no synch, usage type data) + 0x20, 0x00, //wMaxPacketSize (0x0020 is 1x32 bytes) + 16, //bInterval (polling interval in frames 16 frames) +//Interface 2 + 9, //bLength (length of interface descriptor 9 bytes) + 4, //bDescriptorType (4 is interface) + 2, //bInterfaceNumber (This is interface 2) + 0, //bAlternateSetting (used to select alternate setting. notused) + 1, //bNumEndpoints (this interface has 4 endpoints) + 0xFF, //bInterfaceClass (Vendor Defined is 255) + 0x5D, //bInterfaceSubClass (93) + 0x02, //bInterfaceProtocol (3) + 0, //iInterface (Index of string descriptor for describing this notused) + //Common Descriptor. Seems that these come after every interface description? + 9,33,0,1,1,34,134,7,0, + //Endpoint 6 IN + 7, //bLength (length of ep6in descriptor 7 bytes) + 5, //bDescriptorType (5 is endpoint) + 0x86, //bEndpointAddress (0x86 is IN6) + 0x03, //bmAttributes (0x03 is interrupt no synch, usage type data) + 0x20, 0x00, //wMaxPacketSize (0x0020 is 1x32 bytes) + 16, //bInterval (polling interval in frames 64 frames)+ +//Interface 3 +//This is the interface on which all the security handshaking takes place +//We don't use this but it could be used for man-in-the-middle stuff + 9, //bLength (length of interface descriptor 9 bytes) + 4, //bDescriptorType (4 is interface) + 3, //bInterfaceNumber (This is interface 3) + 0, //bAlternateSetting (used to select alternate setting. notused) + 0, //bNumEndpoints (this interface has 0 endpoints ???) + 0xFF, //bInterfaceClass (Vendor Defined is 255) + 0xFD, //bInterfaceSubClass (253) + 0x13, //bInterfaceProtocol (19) + 4, //iInterface (Computer never asks for this, but an x360 would. so include one day?) + //Another interface another Common Descriptor + 6,65,0,1,1,3 }; - +/* // USB HID device HS Configuration Descriptor __ALIGN_BEGIN uint8_t USBD_HID_CUSTOM_CfgHSDesc[USB_HID_CUSTOM_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, // bLength: Configuration Descriptor size @@ -62,7 +129,7 @@ __ALIGN_BEGIN uint8_t USBD_HID_CUSTOM_CfgHSDesc[USB_HID_CUSTOM_CONFIG_DESC_SIZ] 0xC0, //bmAttributes: bus powered and no Support Remote Wake-up 0x32, //MaxPower 100 mA: this current is used for detecting Vbus - //************* Descriptor of interface *************** + // ************* Descriptor of interface *************** // 09 0x09, //bLength: Interface Descriptor size USB_DESC_TYPE_INTERFACE,//bDescriptorType: Interface descriptor type @@ -73,7 +140,7 @@ __ALIGN_BEGIN uint8_t USBD_HID_CUSTOM_CfgHSDesc[USB_HID_CUSTOM_CONFIG_DESC_SIZ] 0x00, //bInterfaceSubClass : 1=BOOT, 0=no boot 0x00, //nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse 0x00, //iInterface: Index of string descriptor - //******************* Descriptor of Joystick Mouse HID ******************* + // ******************* Descriptor of Joystick Mouse HID ******************* // 18 0x09, //bLength: HID Descriptor size HID_DESCRIPTOR_TYPE, //bDescriptorType: HID @@ -84,7 +151,7 @@ __ALIGN_BEGIN uint8_t USBD_HID_CUSTOM_CfgHSDesc[USB_HID_CUSTOM_CONFIG_DESC_SIZ] 0x22, //bDescriptorType HID_JOYSTICK_REPORT_DESC_SIZE,//wItemLength: Total length of Report descriptor 0x00, - //******************* Descriptor of Mouse endpoint ******************* + // ******************* Descriptor of Mouse endpoint ******************* // 27 0x07, //bLength: Endpoint Descriptor size USB_DESC_TYPE_ENDPOINT, //bDescriptorType: @@ -108,7 +175,7 @@ __ALIGN_BEGIN uint8_t USBD_HID_CUSTOM_OtherSpeedCfgDesc[USB_HID_CUSTOM_CONFIG_DE 0xC0, //bmAttributes: bus powered and no Support Remote Wake-up 0x32, //MaxPower 100 mA: this current is used for detecting Vbus - //************* Descriptor of interface *************** + // ************* Descriptor of interface *************** // 09 0x09, //bLength: Interface Descriptor size USB_DESC_TYPE_INTERFACE,//bDescriptorType: Interface descriptor type @@ -119,7 +186,7 @@ __ALIGN_BEGIN uint8_t USBD_HID_CUSTOM_OtherSpeedCfgDesc[USB_HID_CUSTOM_CONFIG_DE 0x00, //bInterfaceSubClass : 1=BOOT, 0=no boot 0x00, //nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse 0x00, //iInterface: Index of string descriptor - //******************* Descriptor of Joystick Mouse HID ******************* + // ******************* Descriptor of Joystick Mouse HID ******************* // 18 0x09, //bLength: HID Descriptor size HID_DESCRIPTOR_TYPE, //bDescriptorType: HID @@ -130,7 +197,7 @@ __ALIGN_BEGIN uint8_t USBD_HID_CUSTOM_OtherSpeedCfgDesc[USB_HID_CUSTOM_CONFIG_DE 0x22, //bDescriptorType HID_JOYSTICK_REPORT_DESC_SIZE,//wItemLength: Total length of Report descriptor 0x00, - //******************* Descriptor of Mouse endpoint ******************* + // ******************* Descriptor of Mouse endpoint ******************* // 27 0x07, //bLength: Endpoint Descriptor size USB_DESC_TYPE_ENDPOINT, //bDescriptorType: @@ -168,3 +235,4 @@ __ALIGN_BEGIN uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] 0x01, 0x00, }; +*/ \ No newline at end of file diff --git a/lib/usb_device/src/usbd_hid_custom.cpp b/lib/usb_device/src/usbd_hid_custom.cpp index 4e8095b..0b4f673 100644 --- a/lib/usb_device/src/usbd_hid_custom.cpp +++ b/lib/usb_device/src/usbd_hid_custom.cpp @@ -11,10 +11,11 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef* pdev, USBD_SetupReqType static uint8_t USBD_HID_JOYSTICK_Setup(USBD_HandleTypeDef* pdev, USBD_SetupReqTypedef* req); static uint8_t* USBD_HID_GetFSCfgDesc(uint16_t* length); +/* static uint8_t* USBD_HID_GetHSCfgDesc(uint16_t* length); static uint8_t* USBD_HID_GetOtherSpeedCfgDesc(uint16_t* length); static uint8_t* USBD_HID_GetDeviceQualifierDesc(uint16_t* length); - +*/ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef* pdev, uint8_t epnum); USBD_ClassTypeDef USBD_CUSTOM_HID = { @@ -28,10 +29,10 @@ USBD_ClassTypeDef USBD_CUSTOM_HID = { NULL, //SOF NULL, NULL, - USBD_HID_GetHSCfgDesc, + NULL,//USBD_HID_GetHSCfgDesc, USBD_HID_GetFSCfgDesc, - USBD_HID_GetOtherSpeedCfgDesc, - USBD_HID_GetDeviceQualifierDesc, + NULL,//USBD_HID_GetOtherSpeedCfgDesc, + NULL,//USBD_HID_GetDeviceQualifierDesc, }; static uint8_t USBD_HID_Init(USBD_HandleTypeDef* pdev, uint8_t cfgidx) @@ -85,8 +86,11 @@ static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef* pdev, uint8_t cfgidx) return USBD_OK; } +#include + static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef* pdev, USBD_SetupReqTypedef* req) { + Serial.printf("usb req %02X %02X %02X\n", req->wIndex, req->bRequest, req->wValue); /* Check which interface is targetted by this request */ //if ((req->wIndex & 0x00FF) == HID_KEYBOARD_INTERFACE) //{ @@ -148,7 +152,7 @@ static uint8_t USBD_HID_JOYSTICK_Setup(USBD_HandleTypeDef* pdev, USBD_SetupReqTy ret = USBD_FAIL; } break; - + /* case USB_REQ_GET_DESCRIPTOR: if (req->wValue >> 8 == HID_REPORT_DESC) { @@ -168,7 +172,7 @@ static uint8_t USBD_HID_JOYSTICK_Setup(USBD_HandleTypeDef* pdev, USBD_SetupReqTy } USBD_CtlSendData(pdev, pbuf, len); break; - + */ case USB_REQ_GET_INTERFACE: if (pdev->dev_state == USBD_STATE_CONFIGURED) { @@ -251,7 +255,7 @@ static uint8_t* USBD_HID_GetFSCfgDesc(uint16_t* length) *length = sizeof(USBD_HID_CUSTOM_CfgFSDesc); return USBD_HID_CUSTOM_CfgFSDesc; } - +/* static uint8_t* USBD_HID_GetHSCfgDesc(uint16_t* length) { *length = sizeof(USBD_HID_CUSTOM_CfgHSDesc); @@ -263,11 +267,11 @@ static uint8_t* USBD_HID_GetOtherSpeedCfgDesc(uint16_t* length) *length = sizeof(USBD_HID_CUSTOM_OtherSpeedCfgDesc); return USBD_HID_CUSTOM_OtherSpeedCfgDesc; } - +*/ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef* pdev, uint8_t epnum) { - /* Ensure that the FIFO is empty before a new transfer, this condition could - be caused by a new transfer before the end of the previous transfer */ + // Ensure that the FIFO is empty before a new transfer, this condition could + // be caused by a new transfer before the end of the previous transfer //if (epnum == (HID_KEYBOARD_EPIN_ADDR & 0x7F)) //{ //((USBD_HID_HandleTypeDef *)pdev->pClassData)->Keyboardstate = HID_IDLE; @@ -278,9 +282,10 @@ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef* pdev, uint8_t epnum) //} return USBD_OK; } - +/* static uint8_t* USBD_HID_GetDeviceQualifierDesc(uint16_t* length) { *length = sizeof(USBD_HID_DeviceQualifierDesc); return USBD_HID_DeviceQualifierDesc; } +*/ \ No newline at end of file diff --git a/lib/usb_device/src/usbd_hid_custom_if.cpp b/lib/usb_device/src/usbd_hid_custom_if.cpp index 62411e9..f77ef95 100644 --- a/lib/usb_device/src/usbd_hid_custom_if.cpp +++ b/lib/usb_device/src/usbd_hid_custom_if.cpp @@ -6,8 +6,38 @@ USBD_HandleTypeDef hUSBD_Device_HID; static bool HID_custom_initialized = false; +__ALIGN_BEGIN uint8_t USBD_Custom_Class_DeviceDesc[] __ALIGN_END = { + 0x12, // bLength + USB_DESC_TYPE_DEVICE, // bDescriptorType + 0x00, // bcdUSB + 0x02, + 0xFF, // bDeviceClass + 0xFF, // bDeviceSubClass + 0xFF, // bDeviceProtocol + USB_MAX_EP0_SIZE, // bMaxPacketSize + LOBYTE(USBD_VID), // idVendor + HIBYTE(USBD_VID), // idVendor + LOBYTE(USBD_PID), // idProduct + HIBYTE(USBD_PID), // idProduct + 0x14, // bcdDevice rel. 0.00 + 0x01, + USBD_IDX_MFC_STR, // Index of manufacturer string + USBD_IDX_PRODUCT_STR, // Index of product string + USBD_IDX_SERIAL_STR, // Index of serial number string + USBD_MAX_NUM_CONFIGURATION // bNumConfigurations +}; + +uint8_t *USBD_Custom_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + UNUSED(speed); + *length = sizeof(USBD_Custom_Class_DeviceDesc); + return (uint8_t *)USBD_Custom_Class_DeviceDesc; +} + void HID_Custom_Init() { + USBD_Desc.GetDeviceDescriptor = USBD_Custom_Class_DeviceDescriptor; // reassign device descriptor to a custom one + if (USBD_Init(&hUSBD_Device_HID, &USBD_Desc, 0) == USBD_OK) { if (USBD_RegisterClass(&hUSBD_Device_HID, USBD_CUSTOM_HID_CLASS) == USBD_OK) diff --git a/lib/usb_device/src/usbd_report.cpp b/lib/usb_device/src/usbd_report.cpp index 3d15176..6b22a0a 100644 --- a/lib/usb_device/src/usbd_report.cpp +++ b/lib/usb_device/src/usbd_report.cpp @@ -25,6 +25,7 @@ __ALIGN_BEGIN uint8_t USBD_HID_CUSTOM_ReportDesc[] __ALIGN_END = { HID_END_COLLECTION(APPLICATION) }; */ +/* __ALIGN_BEGIN uint8_t USBD_HID_Joystick_ReportDesc[] __ALIGN_END = { HID_USAGE_PAGE(GENERIC_DESKTOP), HID_USAGE(GAME_PAD), @@ -86,7 +87,7 @@ __ALIGN_BEGIN uint8_t USBD_HID_Joystick_ReportDesc[] __ALIGN_END = { HID_END_COLLECTION(APPLICATION) }; - +*/ /* __ALIGN_BEGIN uint8_t USBD_HID_Joystick_ReportDesc2[] __ALIGN_END = { 0x05, 0x01, // USAGE_PAGE (Generic Desktop) diff --git a/platformio.ini b/platformio.ini index 2b11619..0afd1e4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,7 +20,7 @@ build_flags = -D USBD_USE_HID_COMPOSITE -D USBCON -D USBD_VID=0x045e - -D USBD_PID=0x1102 + -D USBD_PID=0x028e ;-D USBD_VID=0x0483 ;-D USBD_PID=0x0483 -D USB_MANUFACTURER="Goshi" @@ -30,4 +30,5 @@ build_flags = ; test [env:native] platform = native +lib_ignore = usb_device diff --git a/src/main.cpp b/src/main.cpp index cc1f8c5..c9eb416 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,9 +80,6 @@ void setup() device.begin(); - device.trigger_right(511); - device.trigger_left(511); - // Turn off LED digitalWrite(PC13, HIGH); } @@ -138,10 +135,9 @@ void loop() break; case TouchControl::CT_JOYSTICK: + //Serial.printf("%i, %i\n", ((TouchJoystick*)tcontrols[c])->getX(), ((TouchJoystick*)tcontrols[c])->getY()); device.joystick_left(((TouchJoystick*)tcontrols[c])->getX(), ((TouchJoystick*)tcontrols[c])->getY()); - //device.joystick_right(((TouchJoystick*)tcontrols[c])->getX(), ((TouchJoystick*)tcontrols[c])->getY()); - //device.trigger_left(((TouchJoystick*)tcontrols[c])->getX()); - //device.trigger_right(((TouchJoystick*)tcontrols[c])->getY()); + device.joystick_right(((TouchJoystick*)tcontrols[c])->getX(), ((TouchJoystick*)tcontrols[c])->getY()); break; case TouchControl::CT_DPAD: @@ -162,7 +158,7 @@ void loop() //device.joystick_right(30000, 30000); - //device.trigger_right(right_trigger); + device.trigger_right(right_trigger); device.button(2, right_tp_click); //buttons <<= 1; diff --git a/test/test_dpad/test_touch_dpad.cpp b/test/test_dpad/test_touch_dpad.cpp index 2fd7aeb..d3a6532 100644 --- a/test/test_dpad/test_touch_dpad.cpp +++ b/test/test_dpad/test_touch_dpad.cpp @@ -36,7 +36,7 @@ int main() int N = sizeof(t_points) / sizeof(int32_t); for (int i = 0; i < N; i += 2) { - int8_t res = tcontrol->touch(t_points[i], t_points[i + 1]); + int8_t res = tcontrol->touch(0, t_points[i], t_points[i + 1]); if (res > 0) { diff --git a/test/test_joystick/test_touch_joystick.cpp b/test/test_joystick/test_touch_joystick.cpp index efbe626..31d758e 100644 --- a/test/test_joystick/test_touch_joystick.cpp +++ b/test/test_joystick/test_touch_joystick.cpp @@ -6,25 +6,27 @@ int main() { printf("\n"); - int32_t pos_x = 150; - int32_t pos_y = 350; - int32_t pos_r = 2000; + int32_t pos_x = 2000; + int32_t pos_y = 2000; + int32_t pos_r = 1000; - int16_t usb_x = 512; - int16_t usb_y = 512; - int16_t usb_r = 512; + int16_t usb_x = 0; + int16_t usb_y = 0; + int16_t usb_r = 0x7FFF; + + float pos2usb = (float)usb_r / pos_r; TouchJoystick tjoystick(pos_x, pos_y, pos_r, usb_x, usb_y, usb_r); - int32_t touch_x = 150 + 1000; - int32_t touch_y = 350 + 20; + int32_t touch_x = 2000; + int32_t touch_y = 1000; int16_t x; int16_t y; - + TouchControl* tcontrol = &tjoystick; - int8_t res = tcontrol->touch(touch_x, touch_y); + int8_t res = tcontrol->touch(0, touch_x, touch_y); if (res > 0) { switch(tcontrol->getControlType()) @@ -38,6 +40,7 @@ int main() x = ((TouchJoystick*)tcontrol)->getX(); y = ((TouchJoystick*)tcontrol)->getY(); + printf("CT_JOYSTICK (%04X, %04X)\n", x, y); printf("CT_JOYSTICK (%i, %i)\n", x, y); break; } diff --git a/test/test_multiple_controls/test_multiple_controls.cpp b/test/test_multiple_controls/test_multiple_controls.cpp index 48adc73..eff7e58 100644 --- a/test/test_multiple_controls/test_multiple_controls.cpp +++ b/test/test_multiple_controls/test_multiple_controls.cpp @@ -47,7 +47,7 @@ int main() for (int i = 0; i < num_controls; ++i) { printf("Touch %i at (%i, %i) ", i, t_points[j], t_points[j + 1]); - int8_t res = tcontrols[i]->touch(t_points[j], t_points[j + 1]); + int8_t res = tcontrols[i]->touch(0, t_points[j], t_points[j + 1]); if (res > 0) { switch(tcontrols[i]->getControlType())