update(demo): add more descriptor init macros
Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
7
Kconfig
7
Kconfig
@@ -220,13 +220,16 @@ if CHERRYUSB
|
|||||||
config CHERRYUSB_DEVICE_TEMPLATE_WINUSBV1
|
config CHERRYUSB_DEVICE_TEMPLATE_WINUSBV1
|
||||||
bool
|
bool
|
||||||
prompt "winusbv1"
|
prompt "winusbv1"
|
||||||
|
config CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2
|
||||||
|
bool
|
||||||
|
prompt "winusbv2"
|
||||||
config CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_CDC
|
config CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_CDC
|
||||||
bool
|
bool
|
||||||
prompt "winusbv2_cdc"
|
prompt "winusbv2_cdc"
|
||||||
depends on CHERRYUSB_DEVICE_CDC_ACM
|
depends on CHERRYUSB_DEVICE_CDC_ACM
|
||||||
config CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_HID
|
config CHERRYUSB_DEVICE_TEMPLATE_WEBUSB_HID
|
||||||
bool
|
bool
|
||||||
prompt "winusbv2_hid"
|
prompt "webusb_hid"
|
||||||
depends on CHERRYUSB_DEVICE_HID
|
depends on CHERRYUSB_DEVICE_HID
|
||||||
endchoice
|
endchoice
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -230,13 +230,16 @@ if RT_USING_CHERRYUSB
|
|||||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV1
|
config RT_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV1
|
||||||
bool
|
bool
|
||||||
prompt "winusbv1"
|
prompt "winusbv1"
|
||||||
|
config RT_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2
|
||||||
|
bool
|
||||||
|
prompt "winusbv2"
|
||||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_CDC
|
config RT_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_CDC
|
||||||
bool
|
bool
|
||||||
prompt "winusbv2_cdc"
|
prompt "winusbv2_cdc"
|
||||||
depends on RT_CHERRYUSB_DEVICE_CDC_ACM
|
depends on RT_CHERRYUSB_DEVICE_CDC_ACM
|
||||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_HID
|
config RT_CHERRYUSB_DEVICE_TEMPLATE_WEBUSB_HID
|
||||||
bool
|
bool
|
||||||
prompt "winusbv2_hid"
|
prompt "webusb_hid"
|
||||||
depends on RT_CHERRYUSB_DEVICE_HID
|
depends on RT_CHERRYUSB_DEVICE_HID
|
||||||
config RT_CHERRYUSB_DEVICE_TEMPLATE_ADB
|
config RT_CHERRYUSB_DEVICE_TEMPLATE_ADB
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -229,13 +229,16 @@ if PKG_USING_CHERRYUSB
|
|||||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV1
|
config PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV1
|
||||||
bool
|
bool
|
||||||
prompt "winusbv1"
|
prompt "winusbv1"
|
||||||
|
config PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2
|
||||||
|
bool
|
||||||
|
prompt "winusbv2"
|
||||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_CDC
|
config PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_CDC
|
||||||
bool
|
bool
|
||||||
prompt "winusbv2_cdc"
|
prompt "winusbv2_cdc"
|
||||||
depends on PKG_CHERRYUSB_DEVICE_CDC_ACM
|
depends on PKG_CHERRYUSB_DEVICE_CDC_ACM
|
||||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_HID
|
config PKG_CHERRYUSB_DEVICE_TEMPLATE_WEBUSB_HID
|
||||||
bool
|
bool
|
||||||
prompt "winusbv2_hid"
|
prompt "webusb_hid"
|
||||||
depends on PKG_CHERRYUSB_DEVICE_HID
|
depends on PKG_CHERRYUSB_DEVICE_HID
|
||||||
config PKG_CHERRYUSB_DEVICE_TEMPLATE_ADB
|
config PKG_CHERRYUSB_DEVICE_TEMPLATE_ADB
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -166,10 +166,12 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
|
|||||||
src += Glob('demo/cdc_acm_hid_msc_template.c')
|
src += Glob('demo/cdc_acm_hid_msc_template.c')
|
||||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV1']):
|
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV1']):
|
||||||
src += Glob('demo/winusb1.0_template.c')
|
src += Glob('demo/winusb1.0_template.c')
|
||||||
|
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2']):
|
||||||
|
src += Glob('demo/winusb2.0_template.c')
|
||||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_CDC']):
|
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_CDC']):
|
||||||
src += Glob('demo/winusb2.0_cdc_template.c')
|
src += Glob('demo/winusb2.0_cdc_template.c')
|
||||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_WINUSBV2_HID']):
|
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_WEBUSB_HID']):
|
||||||
src += Glob('demo/winusb2.0_hid_template.c')
|
src += Glob('demo/webusb_hid_template.c')
|
||||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_ADB']):
|
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_ADB']):
|
||||||
src += Glob('demo/adb/usbd_adb_template.c')
|
src += Glob('demo/adb/usbd_adb_template.c')
|
||||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM_CHARDEV']):
|
if GetDepend(['PKG_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM_CHARDEV']):
|
||||||
|
|||||||
@@ -551,10 +551,9 @@ struct cdc_ncm_ndp16 {
|
|||||||
#define DBVAL_BE(x) ((x >> 24) & 0xFF), ((x >> 16) & 0xFF), ((x >> 8) & 0xFF), (x & 0xFF)
|
#define DBVAL_BE(x) ((x >> 24) & 0xFF), ((x >> 16) & 0xFF), ((x >> 8) & 0xFF), (x & 0xFF)
|
||||||
|
|
||||||
/*Length of template descriptor: 71 bytes*/
|
/*Length of template descriptor: 71 bytes*/
|
||||||
#define CDC_ECM_DESCRIPTOR_LEN (8 + 9 + 5 + 5 + 13 + 7 + 9 + 7 + 7)
|
#define CDC_ECM_DESCRIPTOR_LEN (8 + 9 + 5 + 5 + 13 + 7 + 9 + 7 + 7)
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#define CDC_ECM_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, wMaxPacketSize, \
|
#define CDC_ECM_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, wMaxPacketSize, str_idx) \
|
||||||
eth_statistics, wMaxSegmentSize, wNumberMCFilters, bNumberPowerFilters, str_idx) \
|
|
||||||
/* Interface Associate */ \
|
/* Interface Associate */ \
|
||||||
0x08, /* bLength */ \
|
0x08, /* bLength */ \
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \
|
USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \
|
||||||
@@ -587,10 +586,10 @@ eth_statistics, wMaxSegmentSize, wNumberMCFilters, bNumberPowerFilters, str_idx)
|
|||||||
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */\
|
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */\
|
||||||
CDC_FUNC_DESC_ETHERNET_NETWORKING, /* Ethernet Networking functional descriptor subtype */\
|
CDC_FUNC_DESC_ETHERNET_NETWORKING, /* Ethernet Networking functional descriptor subtype */\
|
||||||
str_idx, /* Device's MAC string index */\
|
str_idx, /* Device's MAC string index */\
|
||||||
DBVAL_BE(eth_statistics), /* Ethernet statistics (bitmap) */\
|
DBVAL_BE(0x00000000), /* Ethernet statistics (bitmap) */\
|
||||||
WBVAL(wMaxSegmentSize),/* wMaxSegmentSize: Ethernet Maximum Segment size, typically 1514 bytes */\
|
WBVAL(1514), /* wMaxSegmentSize: Ethernet Maximum Segment size, typically 1514 bytes */\
|
||||||
WBVAL(wNumberMCFilters), /* wNumberMCFilters: the number of multicast filters */\
|
WBVAL(0), /* wNumberMCFilters: the number of multicast filters */ \
|
||||||
bNumberPowerFilters, /* bNumberPowerFilters: the number of wakeup power filters */\
|
0, /* bNumberPowerFilters: the number of wakeup power filters */ \
|
||||||
0x07, /* bLength */ \
|
0x07, /* bLength */ \
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
|
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
|
||||||
int_ep, /* bEndpointAddress */ \
|
int_ep, /* bEndpointAddress */ \
|
||||||
@@ -621,10 +620,9 @@ eth_statistics, wMaxSegmentSize, wNumberMCFilters, bNumberPowerFilters, str_idx)
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
/*Length of template descriptor: 77 bytes*/
|
/*Length of template descriptor: 77 bytes*/
|
||||||
#define CDC_NCM_DESCRIPTOR_LEN (8 + 9 + 5 + 5 + 13 + 6 + 7 + 9 + 7 + 7)
|
#define CDC_NCM_DESCRIPTOR_LEN (8 + 9 + 5 + 5 + 13 + 6 + 7 + 9 + 7 + 7)
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#define CDC_NCM_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, wMaxPacketSize, \
|
#define CDC_NCM_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, wMaxPacketSize, str_idx) \
|
||||||
eth_statistics, wMaxSegmentSize, wNumberMCFilters, bNumberPowerFilters, str_idx) \
|
|
||||||
/* Interface Associate */ \
|
/* Interface Associate */ \
|
||||||
0x08, /* bLength */ \
|
0x08, /* bLength */ \
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \
|
USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \
|
||||||
@@ -657,10 +655,10 @@ eth_statistics, wMaxSegmentSize, wNumberMCFilters, bNumberPowerFilters, str_idx)
|
|||||||
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */\
|
CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */\
|
||||||
CDC_FUNC_DESC_ETHERNET_NETWORKING, /* Ethernet Networking functional descriptor subtype */\
|
CDC_FUNC_DESC_ETHERNET_NETWORKING, /* Ethernet Networking functional descriptor subtype */\
|
||||||
str_idx, /* Device's MAC string index */\
|
str_idx, /* Device's MAC string index */\
|
||||||
DBVAL_BE(eth_statistics), /* Ethernet statistics (bitmap) */\
|
DBVAL_BE(0x00000000), /* Ethernet statistics (bitmap) */\
|
||||||
WBVAL(wMaxPacketSize),/* wMaxSegmentSize: Ethernet Maximum Segment size, typically 1514 bytes */\
|
WBVAL(1514), /* wMaxSegmentSize: Ethernet Maximum Segment size, typically 1514 bytes */\
|
||||||
WBVAL(wNumberMCFilters), /* wNumberMCFilters: the number of multicast filters */\
|
WBVAL(0), /* wNumberMCFilters: the number of multicast filters */ \
|
||||||
bNumberPowerFilters, /* bNumberPowerFilters: the number of wakeup power filters */\
|
0, /* bNumberPowerFilters: the number of wakeup power filters */ \
|
||||||
0x06, \
|
0x06, \
|
||||||
CDC_CS_INTERFACE, \
|
CDC_CS_INTERFACE, \
|
||||||
CDC_FUNC_DESC_NCM, \
|
CDC_FUNC_DESC_NCM, \
|
||||||
|
|||||||
@@ -634,7 +634,7 @@ struct usb_hid_js_report {
|
|||||||
|
|
||||||
#define HID_CUSTOM_INOUT_DESCRIPTOR_LEN (9 + 9 + 7 + 7)
|
#define HID_CUSTOM_INOUT_DESCRIPTOR_LEN (9 + 9 + 7 + 7)
|
||||||
|
|
||||||
#define HID_CUSTOM_INOUT_DESCRIPTOR_INIT(bInterfaceNumber, bInterfaceSubClass, wItemLength, in_ep, out_ep,wMaxPacketSize, bInterval) \
|
#define HID_CUSTOM_INOUT_DESCRIPTOR_INIT(bInterfaceNumber, bInterfaceSubClass, wItemLength, out_ep, in_ep, wMaxPacketSize, bInterval) \
|
||||||
0x09, /* bLength: Interface Descriptor size */ \
|
0x09, /* bLength: Interface Descriptor size */ \
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */ \
|
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */ \
|
||||||
bInterfaceNumber, /* bInterfaceNumber: Number of Interface */ \
|
bInterfaceNumber, /* bInterfaceNumber: Number of Interface */ \
|
||||||
@@ -654,13 +654,13 @@ struct usb_hid_js_report {
|
|||||||
WBVAL(wItemLength), /* wItemLength: Total length of Report descriptor */ \
|
WBVAL(wItemLength), /* wItemLength: Total length of Report descriptor */ \
|
||||||
0x07, /* bLength: Endpoint Descriptor size */ \
|
0x07, /* bLength: Endpoint Descriptor size */ \
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */ \
|
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */ \
|
||||||
in_ep, /* bEndpointAddress: Endpoint Address (IN) */ \
|
out_ep, /* bEndpointAddress: Endpoint Address (OUT) */ \
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */ \
|
0x03, /* bmAttributes: Interrupt endpoint */ \
|
||||||
WBVAL(wMaxPacketSize), /* wMaxPacketSize: x Byte max */ \
|
WBVAL(wMaxPacketSize), /* wMaxPacketSize: x Byte max */ \
|
||||||
bInterval, /* bInterval: Polling Interval */ \
|
bInterval, /* bInterval: Polling Interval */ \
|
||||||
0x07, /* bLength: Endpoint Descriptor size */ \
|
0x07, /* bLength: Endpoint Descriptor size */ \
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */ \
|
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */ \
|
||||||
out_ep, /* bEndpointAddress: Endpoint Address (IN) */ \
|
in_ep, /* bEndpointAddress: Endpoint Address (IN) */ \
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */ \
|
0x03, /* bmAttributes: Interrupt endpoint */ \
|
||||||
WBVAL(wMaxPacketSize), /* wMaxPacketSize: x Byte max */ \
|
WBVAL(wMaxPacketSize), /* wMaxPacketSize: x Byte max */ \
|
||||||
bInterval /* bInterval: Polling Interval */
|
bInterval /* bInterval: Polling Interval */
|
||||||
|
|||||||
187
common/usb_def.h
187
common/usb_def.h
@@ -556,7 +556,7 @@ struct usb_bos_header_descriptor {
|
|||||||
} __PACKED;
|
} __PACKED;
|
||||||
|
|
||||||
/* BOS Capability platform Descriptor */
|
/* BOS Capability platform Descriptor */
|
||||||
struct usb_bos_capability_platform_descriptor {
|
struct usb_bos_capability_platform_common_descriptor {
|
||||||
uint8_t bLength;
|
uint8_t bLength;
|
||||||
uint8_t bDescriptorType;
|
uint8_t bDescriptorType;
|
||||||
uint8_t bDevCapabilityType;
|
uint8_t bDevCapabilityType;
|
||||||
@@ -564,16 +564,26 @@ struct usb_bos_capability_platform_descriptor {
|
|||||||
uint8_t PlatformCapabilityUUID[16];
|
uint8_t PlatformCapabilityUUID[16];
|
||||||
} __PACKED;
|
} __PACKED;
|
||||||
|
|
||||||
/* BOS Capability MS OS Descriptors version 2 */
|
/* Microsoft OS 2.0 Platform Capability Descriptor
|
||||||
struct usb_bos_capability_msosv2_descriptor {
|
* See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/
|
||||||
|
* microsoft-defined-usb-descriptors
|
||||||
|
* Adapted from the source:
|
||||||
|
* https://github.com/sowbug/weblight/blob/master/firmware/webusb.c
|
||||||
|
* (BSD-2) Thanks http://janaxelson.com/files/ms_os_20_descriptors.c
|
||||||
|
*/
|
||||||
|
struct usb_bos_capability_platform_winusb_descriptor {
|
||||||
|
struct usb_bos_capability_platform_common_descriptor common;
|
||||||
uint32_t dwWindowsVersion;
|
uint32_t dwWindowsVersion;
|
||||||
uint16_t wMSOSDescriptorSetTotalLength;
|
uint16_t wMSOSDescriptorSetTotalLength;
|
||||||
uint8_t bVendorCode;
|
uint8_t bVendorCode;
|
||||||
uint8_t bAltEnumCode;
|
uint8_t bAltEnumCode;
|
||||||
} __PACKED;
|
} __PACKED;
|
||||||
|
|
||||||
/* BOS Capability webusb */
|
/* WebUSB Platform Capability Descriptor:
|
||||||
struct usb_bos_capability_webusb_descriptor {
|
* https://wicg.github.io/webusb/#webusb-platform-capability-descriptor
|
||||||
|
*/
|
||||||
|
struct usb_bos_capability_platform_webusb_descriptor {
|
||||||
|
struct usb_bos_capability_platform_common_descriptor common;
|
||||||
uint16_t bcdVersion;
|
uint16_t bcdVersion;
|
||||||
uint8_t bVendorCode;
|
uint8_t bVendorCode;
|
||||||
uint8_t iLandingPage;
|
uint8_t iLandingPage;
|
||||||
@@ -587,26 +597,6 @@ struct usb_bos_capability_extension_descriptor {
|
|||||||
uint32_t bmAttributes;
|
uint32_t bmAttributes;
|
||||||
} __PACKED;
|
} __PACKED;
|
||||||
|
|
||||||
/* Microsoft OS 2.0 Platform Capability Descriptor
|
|
||||||
* See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/
|
|
||||||
* microsoft-defined-usb-descriptors
|
|
||||||
* Adapted from the source:
|
|
||||||
* https://github.com/sowbug/weblight/blob/master/firmware/webusb.c
|
|
||||||
* (BSD-2) Thanks http://janaxelson.com/files/ms_os_20_descriptors.c
|
|
||||||
*/
|
|
||||||
struct usb_bos_capability_platform_msosv2_descriptor {
|
|
||||||
struct usb_bos_capability_platform_descriptor platform_msos;
|
|
||||||
struct usb_bos_capability_msosv2_descriptor data_msosv2;
|
|
||||||
} __PACKED;
|
|
||||||
|
|
||||||
/* WebUSB Platform Capability Descriptor:
|
|
||||||
* https://wicg.github.io/webusb/#webusb-platform-capability-descriptor
|
|
||||||
*/
|
|
||||||
struct usb_bos_capability_platform_webusb_descriptor {
|
|
||||||
struct usb_bos_capability_platform_descriptor platform_webusb;
|
|
||||||
struct usb_bos_capability_webusb_descriptor data_webusb;
|
|
||||||
} __PACKED;
|
|
||||||
|
|
||||||
struct usb_webusb_url_descriptor {
|
struct usb_webusb_url_descriptor {
|
||||||
uint8_t bLength;
|
uint8_t bLength;
|
||||||
uint8_t bDescriptorType;
|
uint8_t bDescriptorType;
|
||||||
@@ -625,18 +615,12 @@ struct usb_bos_descriptor {
|
|||||||
uint32_t string_len;
|
uint32_t string_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* USB Device Capability Descriptor */
|
|
||||||
struct usb_device_capability_descriptor {
|
|
||||||
uint8_t bLength;
|
|
||||||
uint8_t bDescriptorType;
|
|
||||||
uint8_t bDevCapabilityType;
|
|
||||||
} __PACKED;
|
|
||||||
|
|
||||||
/** USB descriptor header */
|
/** USB descriptor header */
|
||||||
struct usb_desc_header {
|
struct usb_desc_header {
|
||||||
uint8_t bLength; /**< descriptor length */
|
uint8_t bLength; /**< descriptor length */
|
||||||
uint8_t bDescriptorType; /**< descriptor type */
|
uint8_t bDescriptorType; /**< descriptor type */
|
||||||
};
|
};
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#define USB_DEVICE_DESCRIPTOR_INIT(bcdUSB, bDeviceClass, bDeviceSubClass, bDeviceProtocol, idVendor, idProduct, bcdDevice, bNumConfigurations) \
|
#define USB_DEVICE_DESCRIPTOR_INIT(bcdUSB, bDeviceClass, bDeviceSubClass, bDeviceProtocol, idVendor, idProduct, bcdDevice, bNumConfigurations) \
|
||||||
0x12, /* bLength */ \
|
0x12, /* bLength */ \
|
||||||
@@ -705,7 +689,7 @@ struct usb_desc_header {
|
|||||||
WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \
|
WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \
|
||||||
bInterval /* bInterval */
|
bInterval /* bInterval */
|
||||||
|
|
||||||
#define USB_IAD_INIT(bFirstInterface, bInterfaceCount, bFunctionClass, bFunctionSubClass, bFunctionProtocol) \
|
#define USB_IAD_DESCRIPTOR_INIT(bFirstInterface, bInterfaceCount, bFunctionClass, bFunctionSubClass, bFunctionProtocol) \
|
||||||
0x08, /* bLength */ \
|
0x08, /* bLength */ \
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \
|
USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \
|
||||||
bFirstInterface, /* bFirstInterface */ \
|
bFirstInterface, /* bFirstInterface */ \
|
||||||
@@ -716,9 +700,144 @@ struct usb_desc_header {
|
|||||||
0x00 /* iFunction */
|
0x00 /* iFunction */
|
||||||
|
|
||||||
#define USB_LANGID_INIT(id) \
|
#define USB_LANGID_INIT(id) \
|
||||||
0x04, /* bLength */ \
|
0x04, /* bLength */ \
|
||||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ \
|
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ \
|
||||||
WBVAL(id) /* wLangID0 */
|
WBVAL(id) /* wLangID0 */
|
||||||
|
|
||||||
|
#define USB_BOS_HEADER_DESCRIPTOR_INIT(wTotalLength, bNumDeviceCaps) \
|
||||||
|
0x05, /* bLength */ \
|
||||||
|
USB_DESCRIPTOR_TYPE_BINARY_OBJECT_STORE, /* bDescriptorType */\
|
||||||
|
WBVAL(wTotalLength), /* wTotalLength */ \
|
||||||
|
bNumDeviceCaps /* bNumDeviceCaps */
|
||||||
|
|
||||||
|
#define USB_BOS_CAP_PLATFORM_WEBUSB_DESCRIPTOR_INIT(bVendorCode, iLandingPage) \
|
||||||
|
0x18, /* bLength */ \
|
||||||
|
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, /* bDescriptorType */ \
|
||||||
|
USB_DEVICE_CAPABILITY_PLATFORM, /* bDevCapabilityType */ \
|
||||||
|
0x00, /* bReserved */ \
|
||||||
|
0x38, 0xB6, 0x08, 0x34, 0xA9, 0x09, 0xA0, 0x47, /* PlatformCapabilityUUID */ \
|
||||||
|
0x8B, 0xFD, 0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65, \
|
||||||
|
WBVAL(0x0100), /* bcdVersion */ \
|
||||||
|
bVendorCode, /* bVendorCode */ \
|
||||||
|
iLandingPage /* iLandingPage */
|
||||||
|
|
||||||
|
#define USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_INIT(bVendorCode, wMSOSDescriptorSetTotalLength) \
|
||||||
|
0x1C, /* bLength */ \
|
||||||
|
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, /* bDescriptorType */ \
|
||||||
|
USB_DEVICE_CAPABILITY_PLATFORM, /* bDevCapabilityType */ \
|
||||||
|
0x00, /* bReserved */ \
|
||||||
|
0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, /* PlatformCapabilityUUID */ \
|
||||||
|
0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F, \
|
||||||
|
DBVAL(0x06030000), /* dwWindowsVersion */ \
|
||||||
|
WBVAL(wMSOSDescriptorSetTotalLength), /* wMSOSDescriptorSetTotalLength */ \
|
||||||
|
bVendorCode, /* bVendorCode */ \
|
||||||
|
0x00 /* bAltEnumCode */
|
||||||
|
|
||||||
|
#define USB_BOS_CAP_PLATFORM_WEBUSB_DESCRIPTOR_LEN 24
|
||||||
|
#define USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_LEN 28
|
||||||
|
|
||||||
|
#define USB_MSOSV1_STRING_DESCRIPTOR_INIT(vendor_code) \
|
||||||
|
0x12, /* bLength */ \
|
||||||
|
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */ \
|
||||||
|
'M', 0, /* bString[0] */ \
|
||||||
|
'S', 0, /* bString[1] */ \
|
||||||
|
'F', 0, /* bString[2] */ \
|
||||||
|
'T', 0, /* bString[3] */ \
|
||||||
|
'1', 0, /* bString[4] */ \
|
||||||
|
'0', 0, /* bString[5] */ \
|
||||||
|
vendor_code, /* bMS_VendorCode */ \
|
||||||
|
0x00 /* bPad */
|
||||||
|
|
||||||
|
#define USB_MSOSV1_COMP_ID_HEADER_DESCRIPTOR_INIT(bCount) \
|
||||||
|
DBVAL((sizeof(struct usb_msosv1_compat_id_header_descriptor) + sizeof(struct usb_msosv1_comp_id_function_descriptor) * bCount)), /* dwLength */ \
|
||||||
|
WBVAL(0x0100), /* bcdVersion */ \
|
||||||
|
WBVAL(0x0004), /* wIndex */ \
|
||||||
|
bCount, /* bCount */ \
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved[7] */
|
||||||
|
|
||||||
|
#define USB_MSOSV1_COMP_ID_FUNCTION_WINUSB_DESCRIPTOR_INIT(bFirstInterfaceNumber) \
|
||||||
|
bFirstInterfaceNumber, /* bFirstInterfaceNumber */\
|
||||||
|
0x01, /* reserved1 */ \
|
||||||
|
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, /* compatibleID[8] */ \
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* subCompatibleID[8] */ \
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved2[6] */
|
||||||
|
|
||||||
|
#define USB_MSOSV1_COMP_ID_FUNCTION_MTP_DESCRIPTOR_INIT(bFirstInterfaceNumber)\
|
||||||
|
bFirstInterfaceNumber, /* bFirstInterfaceNumber */\
|
||||||
|
0x01, /* reserved1 */ \
|
||||||
|
'M', 'T', 'P', 'U', 'S', 'B', 0x00, 0x00, /* compatibleID[8] */ \
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* subCompatibleID[8] */ \
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved2[6] */
|
||||||
|
|
||||||
|
#define USB_MSOSV1_COMP_ID_FUNCTION_ADB_DESCRIPTOR_INIT(bFirstInterfaceNumber)\
|
||||||
|
bFirstInterfaceNumber, * bFirstInterfaceNumber */\
|
||||||
|
0x01, /* reserved1 */ \
|
||||||
|
'A', 'D', 'B', 0x00, 0x00, 0x00, 0x00, 0x00, /* compatibleID[8] */ \
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* subCompatibleID[8] */ \
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved2[6] */
|
||||||
|
|
||||||
|
#define USB_MSOSV1_COMP_ID_DESCRIPTOR_LEN(bCount) \
|
||||||
|
(sizeof(struct usb_msosv1_compat_id_header_descriptor) + sizeof(struct usb_msosv1_comp_id_function_descriptor) * (bCount))
|
||||||
|
|
||||||
|
#define USB_MSOSV2_COMP_ID_SET_HEADER_DESCRIPTOR_INIT(wDescriptorSetTotalLength) \
|
||||||
|
WBVAL(WINUSB_DESCRIPTOR_SET_HEADER_SIZE), /* wLength */ \
|
||||||
|
WBVAL(WINUSB_SET_HEADER_DESCRIPTOR_TYPE), /* wDescriptorType */ \
|
||||||
|
DBVAL(0x06030000), /* dwWindowsVersion */ \
|
||||||
|
WBVAL(wDescriptorSetTotalLength) /* wDescriptorSetTotalLength */
|
||||||
|
|
||||||
|
#define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_SINGLE_DESCRIPTOR_INIT() \
|
||||||
|
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_SIZE), /* wLength */ \
|
||||||
|
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_TYPE), /* wDescriptorType */ \
|
||||||
|
'W', 'I', 'N', 'U', 'S', 'B', 0, 0, /* CompatibleId*/ \
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, /* SubCompatibleId*/ \
|
||||||
|
WBVAL(132), /* wLength */ \
|
||||||
|
WBVAL(WINUSB_FEATURE_REG_PROPERTY_TYPE), /* wDescriptorType */ \
|
||||||
|
WBVAL(WINUSB_PROP_DATA_TYPE_REG_SZ), /* wPropertyDataType */ \
|
||||||
|
WBVAL(42), /* wPropertyNameLength bPropertyName: "DeviceInterfaceGUID" */ \
|
||||||
|
'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, \
|
||||||
|
'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, \
|
||||||
|
'G', 0, 'U', 0, 'I', 0, 'D', 0, 's', 0, 0, 0, \
|
||||||
|
WBVAL(80), /* wPropertyDataLength */ \
|
||||||
|
'{', 0, \
|
||||||
|
'C', 0, 'D', 0, 'B', 0, '3', 0, 'B', 0, '5', 0, 'A', 0, 'D', 0, '-', 0, \
|
||||||
|
'2', 0, '9', 0, '3', 0, 'B', 0, '-', 0, \
|
||||||
|
'4', 0, '6', 0, '6', 0, '3', 0, '-', 0, \
|
||||||
|
'A', 0, 'A', 0, '3', 0, '6', 0, '-', \
|
||||||
|
0, '1', 0, 'A', 0, 'A', 0, 'E', 0, '4', 0, '6', 0, '4', 0, '6', 0, '3', 0, '7', 0, '7', 0, '6', 0, \
|
||||||
|
'}', 0, 0, 0, 0, 0
|
||||||
|
|
||||||
|
#define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_SINGLE_DESCRIPTOR_LEN \
|
||||||
|
(WINUSB_FEATURE_COMPATIBLE_ID_SIZE + 132)
|
||||||
|
|
||||||
|
#define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_INIT(bFirstInterfaceNumber) \
|
||||||
|
WBVAL(WINUSB_FUNCTION_SUBSET_HEADER_SIZE), /* wLength */ \
|
||||||
|
WBVAL(WINUSB_SUBSET_HEADER_FUNCTION_TYPE), /* wDescriptorType */ \
|
||||||
|
bFirstInterfaceNumber, /* bFirstInterface*/ \
|
||||||
|
0, /* bReserved */ \
|
||||||
|
WBVAL((WINUSB_FUNCTION_SUBSET_HEADER_SIZE + WINUSB_FEATURE_COMPATIBLE_ID_SIZE + 132)), /* wSubsetLength */\
|
||||||
|
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_SIZE), /* wLength */ \
|
||||||
|
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_TYPE), /* wDescriptorType */ \
|
||||||
|
'W', 'I', 'N', 'U', 'S', 'B', 0, 0, /* CompatibleId*/ \
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, /* SubCompatibleId*/ \
|
||||||
|
WBVAL(132), /* wLength */ \
|
||||||
|
WBVAL(WINUSB_FEATURE_REG_PROPERTY_TYPE), /* wDescriptorType */ \
|
||||||
|
WBVAL(WINUSB_PROP_DATA_TYPE_REG_MULTI_SZ), /* wPropertyDataType */ \
|
||||||
|
WBVAL(42), /* wPropertyNameLength bPropertyName: "DeviceInterfaceGUID" */ \
|
||||||
|
'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, \
|
||||||
|
'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, \
|
||||||
|
'G', 0, 'U', 0, 'I', 0, 'D', 0, 's', 0, 0, 0, \
|
||||||
|
WBVAL(80), /* wPropertyDataLength */ \
|
||||||
|
'{', 0, \
|
||||||
|
'C', 0, 'D', 0, 'B', 0, '3', 0, 'B', 0, '5', 0, 'A', 0, 'D', 0, '-', 0, \
|
||||||
|
'2', 0, '9', 0, '3', 0, 'B', 0, '-', 0, \
|
||||||
|
'4', 0, '6', 0, '6', 0, '3', 0, '-', 0, \
|
||||||
|
'A', 0, 'A', 0, '3', 0, '6', 0, '-', \
|
||||||
|
0, '1', 0, 'A', 0, 'A', 0, 'E', 0, '4', 0, '6', 0, '4', 0, '6', 0, '3', 0, '7', 0, '7', 0, '6', 0, \
|
||||||
|
'}', 0, 0, 0, 0, 0
|
||||||
|
|
||||||
|
#define USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_LEN \
|
||||||
|
(WINUSB_FUNCTION_SUBSET_HEADER_SIZE + WINUSB_FEATURE_COMPATIBLE_ID_SIZE + 132)
|
||||||
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
#endif /* USB_DEF_H */
|
#endif /* USB_DEF_H */
|
||||||
|
|||||||
@@ -185,8 +185,8 @@
|
|||||||
(field)[3] = (uint8_t)((value) >> 0); \
|
(field)[3] = (uint8_t)((value) >> 0); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define WBVAL(x) (x & 0xFF), ((x >> 8) & 0xFF)
|
#define WBVAL(x) ((x) & 0xFF), (((x) >> 8) & 0xFF)
|
||||||
#define DBVAL(x) (x & 0xFF), ((x >> 8) & 0xFF), ((x >> 16) & 0xFF), ((x >> 24) & 0xFF)
|
#define DBVAL(x) ((x) & 0xFF), (((x) >> 8) & 0xFF), (((x) >> 16) & 0xFF), (((x) >> 24) & 0xFF)
|
||||||
|
|
||||||
#define PP_NARG(...) \
|
#define PP_NARG(...) \
|
||||||
PP_NARG_(__VA_ARGS__, PP_RSEQ_N())
|
PP_NARG_(__VA_ARGS__, PP_RSEQ_N())
|
||||||
|
|||||||
@@ -29,14 +29,9 @@
|
|||||||
#define CDC_MAX_MPS 64
|
#define CDC_MAX_MPS 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CDC_ECM_ETH_STATISTICS_BITMAP 0x00000000
|
|
||||||
|
|
||||||
/* str idx = 4 is for mac address: aa:bb:cc:dd:ee:ff*/
|
/* str idx = 4 is for mac address: aa:bb:cc:dd:ee:ff*/
|
||||||
#define CDC_ECM_MAC_STRING_INDEX 4
|
#define CDC_ECM_MAC_STRING_INDEX 4
|
||||||
|
|
||||||
/* Ethernet Maximum Segment size, typically 1514 bytes */
|
|
||||||
#define CONFIG_CDC_ECM_ETH_MAX_SEGSZE 1514U
|
|
||||||
|
|
||||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
static const uint8_t device_descriptor[] = {
|
static const uint8_t device_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01)
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01)
|
||||||
@@ -44,7 +39,7 @@ static const uint8_t device_descriptor[] = {
|
|||||||
|
|
||||||
static const uint8_t config_descriptor[] = {
|
static const uint8_t config_descriptor[] = {
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
CDC_ECM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, CDC_MAX_MPS, CDC_ECM_ETH_STATISTICS_BITMAP, CONFIG_CDC_ECM_ETH_MAX_SEGSZE, 0, 0, CDC_ECM_MAC_STRING_INDEX)
|
CDC_ECM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, CDC_MAX_MPS, CDC_ECM_MAC_STRING_INDEX)
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t device_quality_descriptor[] = {
|
static const uint8_t device_quality_descriptor[] = {
|
||||||
@@ -105,7 +100,7 @@ const struct usb_descriptor cdc_ecm_descriptor = {
|
|||||||
static const uint8_t cdc_ecm_descriptor[] = {
|
static const uint8_t cdc_ecm_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
CDC_ECM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, CDC_MAX_MPS, CDC_ECM_ETH_STATISTICS_BITMAP, CONFIG_CDC_ECM_ETH_MAX_SEGSZE, 0, 0, CDC_ECM_MAC_STRING_INDEX),
|
CDC_ECM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, CDC_MAX_MPS, CDC_ECM_MAC_STRING_INDEX),
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
/// string0 descriptor
|
/// string0 descriptor
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
|||||||
@@ -8,25 +8,8 @@
|
|||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
#include "usbd_hid.h"
|
#include "usbd_hid.h"
|
||||||
|
|
||||||
|
#define HIDRAW_IN_EP 0x81
|
||||||
/*!< hidraw in endpoint */
|
#define HIDRAW_OUT_EP 0x02
|
||||||
#define HIDRAW_IN_EP 0x81
|
|
||||||
#ifdef CONFIG_USB_HS
|
|
||||||
#define HIDRAW_IN_EP_SIZE 1024
|
|
||||||
#define HIDRAW_IN_INTERVAL 4
|
|
||||||
#else
|
|
||||||
#define HIDRAW_IN_EP_SIZE 64
|
|
||||||
#define HIDRAW_IN_INTERVAL 10
|
|
||||||
#endif
|
|
||||||
/*!< hidraw out endpoint */
|
|
||||||
#define HIDRAW_OUT_EP 0x02
|
|
||||||
#ifdef CONFIG_USB_HS
|
|
||||||
#define HIDRAW_OUT_EP_SIZE 1024
|
|
||||||
#define HIDRAW_OUT_EP_INTERVAL 4
|
|
||||||
#else
|
|
||||||
#define HIDRAW_OUT_EP_SIZE 64
|
|
||||||
#define HIDRAW_OUT_EP_INTERVAL 10
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define USBD_VID 0xffff
|
#define USBD_VID 0xffff
|
||||||
#define USBD_PID 0xffff
|
#define USBD_PID 0xffff
|
||||||
@@ -34,53 +17,27 @@
|
|||||||
#define USBD_LANGID_STRING 1033
|
#define USBD_LANGID_STRING 1033
|
||||||
|
|
||||||
/*!< config descriptor size */
|
/*!< config descriptor size */
|
||||||
#define USB_HID_CONFIG_DESC_SIZ (9 + 9 + 9 + 7 + 7)
|
#define USB_CONFIG_SIZE (9 + 9 + 9 + 7 + 7)
|
||||||
|
|
||||||
/*!< custom hid report descriptor size */
|
/*!< custom hid report descriptor size */
|
||||||
#define HID_CUSTOM_REPORT_DESC_SIZE 38
|
#define HID_CUSTOM_REPORT_DESC_SIZE 38
|
||||||
|
|
||||||
|
#ifdef CONFIG_USB_HS
|
||||||
|
#define HID_MAX_MPS 1024
|
||||||
|
#define HIDRAW_IN_INTERVAL 1
|
||||||
|
#else
|
||||||
|
#define HID_MAX_MPS 64
|
||||||
|
#define HIDRAW_IN_INTERVAL 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
static const uint8_t device_descriptor[] = {
|
static const uint8_t device_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01)
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01)
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t config_descriptor[] = {
|
static const uint8_t config_descriptor[] = {
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
/************** Descriptor of Custom interface *****************/
|
HID_CUSTOM_INOUT_DESCRIPTOR_INIT(0x00, 0x01, HID_CUSTOM_REPORT_DESC_SIZE, HIDRAW_OUT_EP, HIDRAW_IN_EP, HID_MAX_MPS, HIDRAW_IN_INTERVAL),
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Custom HID ********************/
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE_HID, /* 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_CUSTOM_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Custom in endpoint ********************/
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HIDRAW_IN_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
WBVAL(HIDRAW_IN_EP_SIZE), /* wMaxPacketSize: 4 Byte max */
|
|
||||||
HIDRAW_IN_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/******************** Descriptor of Custom out endpoint ********************/
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HIDRAW_OUT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
WBVAL(HIDRAW_OUT_EP_SIZE), /* wMaxPacketSize: 4 Byte max */
|
|
||||||
HIDRAW_OUT_EP_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 73 */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t device_quality_descriptor[] = {
|
static const uint8_t device_quality_descriptor[] = {
|
||||||
@@ -139,42 +96,8 @@ const struct usb_descriptor hid_descriptor = {
|
|||||||
/*!< global descriptor */
|
/*!< global descriptor */
|
||||||
static const uint8_t hid_descriptor[] = {
|
static const uint8_t hid_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
/************** Descriptor of Custom interface *****************/
|
HID_CUSTOM_INOUT_DESCRIPTOR_INIT(0x00, 0x01, HID_CUSTOM_REPORT_DESC_SIZE, HIDRAW_OUT_EP, HIDRAW_IN_EP, HID_MAX_MPS, HIDRAW_IN_INTERVAL),
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Custom HID ********************/
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE_HID, /* 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_CUSTOM_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Custom in endpoint ********************/
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HIDRAW_IN_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
WBVAL(HIDRAW_IN_EP_SIZE), /* wMaxPacketSize: 4 Byte max */
|
|
||||||
HIDRAW_IN_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/******************** Descriptor of Custom out endpoint ********************/
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HIDRAW_OUT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
WBVAL(HIDRAW_OUT_EP_SIZE), /* wMaxPacketSize: 4 Byte max */
|
|
||||||
HIDRAW_OUT_EP_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 73 */
|
|
||||||
/*
|
/*
|
||||||
* string0 descriptor
|
* string0 descriptor
|
||||||
*/
|
*/
|
||||||
@@ -261,16 +184,16 @@ static const uint8_t hid_custom_report_desc[HID_CUSTOM_REPORT_DESC_SIZE] = {
|
|||||||
0x09, 0x02, /* USAGE (Vendor Usage 1) */
|
0x09, 0x02, /* USAGE (Vendor Usage 1) */
|
||||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||||
0x25, 0xff, /*LOGICAL_MAXIMUM (255) */
|
0x25, 0xff, /*LOGICAL_MAXIMUM (255) */
|
||||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||||
0x96, 0xff, 0x03, /* REPORT_COUNT (63) */
|
0x96, 0xff, 0x03, /* REPORT_COUNT (63) */
|
||||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */
|
0x81, 0x02, /* INPUT (Data,Var,Abs) */
|
||||||
/* <___________________________________________________> */
|
/* <___________________________________________________> */
|
||||||
0x85, 0x01, /* REPORT ID (0x01) */
|
0x85, 0x01, /* REPORT ID (0x01) */
|
||||||
0x09, 0x03, /* USAGE (Vendor Usage 1) */
|
0x09, 0x03, /* USAGE (Vendor Usage 1) */
|
||||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
|
||||||
0x25, 0xff, /* LOGICAL_MAXIMUM (255) */
|
0x25, 0xff, /* LOGICAL_MAXIMUM (255) */
|
||||||
0x75, 0x08, /* REPORT_SIZE (8) */
|
0x75, 0x08, /* REPORT_SIZE (8) */
|
||||||
0x96, 0xff, 0x03, /* REPORT_COUNT (63) */
|
0x96, 0xff, 0x03, /* REPORT_COUNT (63) */
|
||||||
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
|
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
0xC0 /* END_COLLECTION */
|
0xC0 /* END_COLLECTION */
|
||||||
@@ -299,8 +222,8 @@ static const uint8_t hid_custom_report_desc[HID_CUSTOM_REPORT_DESC_SIZE] = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[HIDRAW_OUT_EP_SIZE];
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[HID_MAX_MPS];
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t send_buffer[HIDRAW_IN_EP_SIZE];
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t send_buffer[HID_MAX_MPS];
|
||||||
|
|
||||||
#define HID_STATE_IDLE 0
|
#define HID_STATE_IDLE 0
|
||||||
#define HID_STATE_BUSY 1
|
#define HID_STATE_BUSY 1
|
||||||
@@ -311,27 +234,27 @@ static volatile uint8_t custom_state;
|
|||||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||||
{
|
{
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case USBD_EVENT_RESET:
|
case USBD_EVENT_RESET:
|
||||||
break;
|
break;
|
||||||
case USBD_EVENT_CONNECTED:
|
case USBD_EVENT_CONNECTED:
|
||||||
break;
|
break;
|
||||||
case USBD_EVENT_DISCONNECTED:
|
case USBD_EVENT_DISCONNECTED:
|
||||||
break;
|
break;
|
||||||
case USBD_EVENT_RESUME:
|
case USBD_EVENT_RESUME:
|
||||||
break;
|
break;
|
||||||
case USBD_EVENT_SUSPEND:
|
case USBD_EVENT_SUSPEND:
|
||||||
break;
|
break;
|
||||||
case USBD_EVENT_CONFIGURED:
|
case USBD_EVENT_CONFIGURED:
|
||||||
/* setup first out ep read transfer */
|
/* setup first out ep read transfer */
|
||||||
usbd_ep_start_read(busid, HIDRAW_OUT_EP, read_buffer, HIDRAW_OUT_EP_SIZE);
|
usbd_ep_start_read(busid, HIDRAW_OUT_EP, read_buffer, HID_MAX_MPS);
|
||||||
break;
|
break;
|
||||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||||
break;
|
break;
|
||||||
case USBD_EVENT_CLR_REMOTE_WAKEUP:
|
case USBD_EVENT_CLR_REMOTE_WAKEUP:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,7 +269,7 @@ static void usbd_hid_custom_in_callback(uint8_t busid, uint8_t ep, uint32_t nbyt
|
|||||||
static void usbd_hid_custom_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
static void usbd_hid_custom_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||||
{
|
{
|
||||||
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
||||||
usbd_ep_start_read(busid, ep, read_buffer, HIDRAW_IN_EP_SIZE);
|
usbd_ep_start_read(busid, ep, read_buffer, HID_MAX_MPS);
|
||||||
read_buffer[0] = 0x02; /* IN: report id */
|
read_buffer[0] = 0x02; /* IN: report id */
|
||||||
usbd_ep_start_write(busid, HIDRAW_IN_EP, read_buffer, nbytes);
|
usbd_ep_start_write(busid, HIDRAW_IN_EP, read_buffer, nbytes);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#define HID_INT_EP_SIZE 8
|
#define HID_INT_EP_SIZE 8
|
||||||
#define HID_INT_EP_INTERVAL 10
|
#define HID_INT_EP_INTERVAL 10
|
||||||
|
|
||||||
#define USB_HID_CONFIG_DESC_SIZ 34
|
#define USB_CONFIG_SIZE 34
|
||||||
#define HID_KEYBOARD_REPORT_DESC_SIZE 63
|
#define HID_KEYBOARD_REPORT_DESC_SIZE 63
|
||||||
|
|
||||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
@@ -24,40 +24,8 @@ static const uint8_t device_descriptor[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t config_descriptor[] = {
|
static const uint8_t config_descriptor[] = {
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
|
HID_KEYBOARD_DESCRIPTOR_INIT(0x00, 0x01, HID_KEYBOARD_REPORT_DESC_SIZE, HID_INT_EP, HID_INT_EP_SIZE, HID_INT_EP_INTERVAL),
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x01, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE_HID, /* 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_KEYBOARD_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
|
||||||
0x00,
|
|
||||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 34 */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t device_quality_descriptor[] = {
|
static const uint8_t device_quality_descriptor[] = {
|
||||||
@@ -115,40 +83,8 @@ const struct usb_descriptor hid_descriptor = {
|
|||||||
#else
|
#else
|
||||||
static const uint8_t hid_descriptor[] = {
|
static const uint8_t hid_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
|
HID_KEYBOARD_DESCRIPTOR_INIT(0x00, 0x01, HID_KEYBOARD_REPORT_DESC_SIZE, HID_INT_EP, HID_INT_EP_SIZE, HID_INT_EP_INTERVAL),
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x01, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE_HID, /* 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_KEYBOARD_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
|
||||||
0x00,
|
|
||||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 34 */
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
/// string0 descriptor
|
/// string0 descriptor
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#define USBD_LANGID_STRING 1033
|
#define USBD_LANGID_STRING 1033
|
||||||
|
|
||||||
/*!< config descriptor size */
|
/*!< config descriptor size */
|
||||||
#define USB_HID_CONFIG_DESC_SIZ 34
|
#define USB_CONFIG_SIZE 34
|
||||||
/*!< report descriptor size */
|
/*!< report descriptor size */
|
||||||
#define HID_MOUSE_REPORT_DESC_SIZE 74
|
#define HID_MOUSE_REPORT_DESC_SIZE 74
|
||||||
|
|
||||||
@@ -27,40 +27,8 @@ static const uint8_t device_descriptor[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t config_descriptor[] = {
|
static const uint8_t config_descriptor[] = {
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
|
HID_MOUSE_DESCRIPTOR_INIT(0x00, 0x01, HID_MOUSE_REPORT_DESC_SIZE, HID_INT_EP, HID_INT_EP_SIZE, HID_INT_EP_INTERVAL),
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE_HID, /* 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_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
|
||||||
0x00,
|
|
||||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 34 */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t device_quality_descriptor[] = {
|
static const uint8_t device_quality_descriptor[] = {
|
||||||
@@ -119,40 +87,8 @@ const struct usb_descriptor hid_descriptor = {
|
|||||||
/*!< global descriptor */
|
/*!< global descriptor */
|
||||||
const uint8_t hid_descriptor[] = {
|
const uint8_t hid_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
|
HID_MOUSE_DESCRIPTOR_INIT(0x00, 0x01, HID_MOUSE_REPORT_DESC_SIZE, HID_INT_EP, HID_INT_EP_SIZE, HID_INT_EP_INTERVAL),
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE_HID, /* 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_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
|
||||||
0x00,
|
|
||||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 34 */
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
/// string0 descriptor
|
/// string0 descriptor
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
|||||||
@@ -6,6 +6,52 @@
|
|||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
#include "usbd_hid.h"
|
#include "usbd_hid.h"
|
||||||
|
|
||||||
|
#define WEBUSB_VENDOR_CODE (0x22)
|
||||||
|
#define WINUSB_VENDOR_CODE (0x21)
|
||||||
|
|
||||||
|
#define URL_DESCRIPTOR_LENGTH (3 + 36)
|
||||||
|
|
||||||
|
#define WEBUSB_INTF_NUM 0x01
|
||||||
|
|
||||||
|
#define WEBUSB_URL_STRINGS \
|
||||||
|
'g', 'i', 't', 'h', 'u', 'b', '.', 'c', 'o', 'm', '/', \
|
||||||
|
'c', 'h', 'e', 'r', 'r', 'y', '-', 'e', 'm', 'b', 'e', 'd', 'd', 'e', 'd', '/', 'C', 'h', 'e', 'r', 'r', 'y', 'U', 'S', 'B',
|
||||||
|
|
||||||
|
const uint8_t USBD_WebUSBURLDescriptor[URL_DESCRIPTOR_LENGTH] = {
|
||||||
|
URL_DESCRIPTOR_LENGTH,
|
||||||
|
WEBUSB_URL_TYPE,
|
||||||
|
WEBUSB_URL_SCHEME_HTTPS,
|
||||||
|
WEBUSB_URL_STRINGS
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint8_t WINUSB_WCIDDescriptor[] = {
|
||||||
|
USB_MSOSV2_COMP_ID_SET_HEADER_DESCRIPTOR_INIT(10 + USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_LEN),
|
||||||
|
USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_INIT(WEBUSB_INTF_NUM),
|
||||||
|
};
|
||||||
|
|
||||||
|
__ALIGN_BEGIN const uint8_t USBD_BinaryObjectStoreDescriptor[] = {
|
||||||
|
USB_BOS_HEADER_DESCRIPTOR_INIT(5 + USB_BOS_CAP_PLATFORM_WEBUSB_DESCRIPTOR_LEN + USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_LEN, 2),
|
||||||
|
USB_BOS_CAP_PLATFORM_WEBUSB_DESCRIPTOR_INIT(WEBUSB_VENDOR_CODE, 0x01),
|
||||||
|
USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_INIT(WINUSB_VENDOR_CODE, sizeof(WINUSB_WCIDDescriptor)),
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usb_webusb_descriptor webusb_url_desc = {
|
||||||
|
.vendor_code = WEBUSB_VENDOR_CODE,
|
||||||
|
.string = USBD_WebUSBURLDescriptor,
|
||||||
|
.string_len = URL_DESCRIPTOR_LENGTH
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usb_msosv2_descriptor msosv2_desc = {
|
||||||
|
.vendor_code = WINUSB_VENDOR_CODE,
|
||||||
|
.compat_id = WINUSB_WCIDDescriptor,
|
||||||
|
.compat_id_len = sizeof(WINUSB_WCIDDescriptor),
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usb_bos_descriptor bos_desc = {
|
||||||
|
.string = USBD_BinaryObjectStoreDescriptor,
|
||||||
|
.string_len = sizeof(USBD_BinaryObjectStoreDescriptor)
|
||||||
|
};
|
||||||
|
|
||||||
#define USBD_VID 0xffff
|
#define USBD_VID 0xffff
|
||||||
#define USBD_PID 0xffff
|
#define USBD_PID 0xffff
|
||||||
#define USBD_MAX_POWER 100
|
#define USBD_MAX_POWER 100
|
||||||
@@ -15,181 +61,18 @@
|
|||||||
#define HID_INT_EP_SIZE 8
|
#define HID_INT_EP_SIZE 8
|
||||||
#define HID_INT_EP_INTERVAL 10
|
#define HID_INT_EP_INTERVAL 10
|
||||||
|
|
||||||
#define USB_HID_CONFIG_DESC_SIZ (34 + 9)
|
#define USB_CONFIG_SIZE (34 + 9)
|
||||||
#define HID_KEYBOARD_REPORT_DESC_SIZE 63
|
#define HID_KEYBOARD_REPORT_DESC_SIZE 63
|
||||||
|
|
||||||
#define USBD_WEBUSB_VENDOR_CODE (0x22)
|
|
||||||
#define USBD_WINUSB_VENDOR_CODE (0x21)
|
|
||||||
|
|
||||||
#define USBD_WINUSB_DESC_SET_LEN (0xB2)
|
|
||||||
#define URL_DESCRIPTOR_LENGTH (3 + 36)
|
|
||||||
|
|
||||||
#define USBD_WEBUSB_INTF_NUM 0x01
|
|
||||||
|
|
||||||
#define WEBUSB_URL_STRINGS \
|
|
||||||
'g', 'i', 't', 'h', 'u', 'b', '.', 'c', 'o', 'm', '/', \
|
|
||||||
'c', 'h', 'e', 'r', 'r', 'y', '-', 'e', 'm', 'b', 'e', 'd', 'd', 'e', 'd', '/', 'C', 'h', 'e', 'r', 'r', 'y', 'U', 'S', 'B',
|
|
||||||
|
|
||||||
const uint8_t USBD_WinUSBDescriptorSetDescriptor[USBD_WINUSB_DESC_SET_LEN] = {
|
|
||||||
// Microsoft OS 2.0 描述符集标头
|
|
||||||
0x0A, 0x00, // Descriptor size (10 bytes)
|
|
||||||
0x00, 0x00, // MS OS 2.0 descriptor set header
|
|
||||||
0x00, 0x00, 0x03, 0x06, // Windows version (8.1) (0x06030000)
|
|
||||||
USBD_WINUSB_DESC_SET_LEN, 0x00, // Size, MS OS 2.0 descriptor set
|
|
||||||
|
|
||||||
// Microsoft OS 2.0 配置子集标头
|
|
||||||
0x08, 0x00, // wLength
|
|
||||||
0x01, 0x00, // wDescriptorType
|
|
||||||
0x00, // 适用于配置 1
|
|
||||||
0x00, // bReserved
|
|
||||||
0XA8, 0X00, // Size, MS OS 2.0 configuration subset
|
|
||||||
|
|
||||||
// Microsoft OS 2.0 功能子集头
|
|
||||||
0x08, 0x00, // Descriptor size (8 bytes)
|
|
||||||
0x02, 0x00, // MS OS 2.0 function subset header
|
|
||||||
USBD_WEBUSB_INTF_NUM, // bFirstInterface
|
|
||||||
0x00, // 必须设置为 0
|
|
||||||
0xA0, 0x00,
|
|
||||||
|
|
||||||
// Microsoft OS 2.0 兼容 ID 描述符
|
|
||||||
// 兼容 ID 描述符告诉 Windows 此设备与 WinUSB 驱动程序兼容
|
|
||||||
0x14, 0x00, // wLength 20
|
|
||||||
0x03, 0x00, // MS_OS_20_FEATURE_COMPATIBLE_ID
|
|
||||||
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
|
|
||||||
// Microsoft OS 2.0 注册表属性描述符
|
|
||||||
// 注册表属性分配设备接口 GUID
|
|
||||||
0x84, 0x00, //wLength: 132
|
|
||||||
0x04, 0x00, // wDescriptorType: MS_OS_20_FEATURE_REG_PROPERTY: 0x04 (Table 9)
|
|
||||||
0x07, 0x00, //wPropertyDataType: REG_MULTI_SZ (Table 15)
|
|
||||||
0x2a, 0x00, //wPropertyNameLength:
|
|
||||||
//bPropertyName: “DeviceInterfaceGUID”
|
|
||||||
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00,
|
|
||||||
'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00,
|
|
||||||
0x00, 0x00,
|
|
||||||
0x50, 0x00, // wPropertyDataLength
|
|
||||||
//bPropertyData: “{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}”.
|
|
||||||
'{', 0x00, '9', 0x00, 'd', 0x00, '7', 0x00, 'd', 0x00, 'e', 0x00, 'b', 0x00, 'b', 0x00, 'c', 0x00, '-', 0x00,
|
|
||||||
'c', 0x00, '8', 0x00, '5', 0x00, 'd', 0x00, '-', 0x00, '1', 0x00, '1', 0x00, 'd', 0x00, '1', 0x00, '-', 0x00,
|
|
||||||
'9', 0x00, 'e', 0x00, 'b', 0x00, '4', 0x00, '-', 0x00, '0', 0x00, '0', 0x00, '6', 0x00, '0', 0x00, '0', 0x00,
|
|
||||||
'8', 0x00, 'c', 0x00, '3', 0x00, 'a', 0x00, '1', 0x00, '9', 0x00, 'a', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00
|
|
||||||
};
|
|
||||||
|
|
||||||
const uint8_t USBD_WebUSBURLDescriptor[URL_DESCRIPTOR_LENGTH] = {
|
|
||||||
URL_DESCRIPTOR_LENGTH,
|
|
||||||
WEBUSB_URL_TYPE,
|
|
||||||
WEBUSB_URL_SCHEME_HTTPS,
|
|
||||||
WEBUSB_URL_STRINGS
|
|
||||||
};
|
|
||||||
|
|
||||||
#define USBD_BOS_WTOTALLENGTH 0x39
|
|
||||||
|
|
||||||
#define LANDING_PAGE 0x01
|
|
||||||
uint8_t USBD_BinaryObjectStoreDescriptor[USBD_BOS_WTOTALLENGTH] = {
|
|
||||||
// BOS描述符
|
|
||||||
0x05, // bLength 固长为5
|
|
||||||
0x0F, // bDescriptorType 固定为15
|
|
||||||
USBD_BOS_WTOTALLENGTH, 0x00, // wTotalLength BOS描述符的总大小
|
|
||||||
0x02, // bNumDeviceCaps BOS描述符中独立设备功能特性描述符的数量
|
|
||||||
|
|
||||||
// WebUSB 平台功能描述符
|
|
||||||
0x18, // Descriptor size (24 bytes)
|
|
||||||
0x10, // Descriptor type (Device Capability) 设备功能描述符
|
|
||||||
0x05, // Capability type (Platform) 平台描述符
|
|
||||||
0x00, // Reserved
|
|
||||||
|
|
||||||
// WebUSB Platform Capability ID (3408b638-09a9-47a0-8bfd-a0768815b665)
|
|
||||||
// 平台功能 UUID 将此标识为WebUSB 平台功能描述符,它提供有关设备的基本信息
|
|
||||||
0x38, 0xB6, 0x08, 0x34,
|
|
||||||
0xA9, 0x09,
|
|
||||||
0xA0, 0x47,
|
|
||||||
0x8B, 0xFD,
|
|
||||||
0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65,
|
|
||||||
|
|
||||||
0x00, 0x01, // WebUSB version 1.0
|
|
||||||
USBD_WEBUSB_VENDOR_CODE, // Vendor-assigned WebUSB request code
|
|
||||||
LANDING_PAGE, // Landing page
|
|
||||||
|
|
||||||
// Microsoft 平台功能描述符
|
|
||||||
// 标头
|
|
||||||
0x1C, // Descriptor size (28 bytes)
|
|
||||||
0x10, // Descriptor type (Device Capability)
|
|
||||||
0x05, // Capability type (Platform)
|
|
||||||
0x00, // Reserved
|
|
||||||
|
|
||||||
0xDF, 0x60, 0xDD, 0xD8, /* PlatformCapabilityUUID */
|
|
||||||
0x89, 0x45, 0xC7, 0x4C,
|
|
||||||
0x9C, 0xD2, 0x65, 0x9D,
|
|
||||||
0x9E, 0x64, 0x8A, 0x9F,
|
|
||||||
|
|
||||||
// 描述符集信息结构
|
|
||||||
0x00, 0x00, 0x03, 0x06, /* >= Win 8.1 * dwWindowsVersion 最低兼容 Windows 版本 */
|
|
||||||
|
|
||||||
USBD_WINUSB_DESC_SET_LEN, 0X00, /* wDescriptorSetTotalLength */
|
|
||||||
|
|
||||||
USBD_WINUSB_VENDOR_CODE, /* bVendorCode */
|
|
||||||
0X00 /* bAltEnumCode */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct usb_webusb_descriptor webusb_url_desc = {
|
|
||||||
.vendor_code = USBD_WEBUSB_VENDOR_CODE,
|
|
||||||
.string = USBD_WebUSBURLDescriptor,
|
|
||||||
.string_len = URL_DESCRIPTOR_LENGTH
|
|
||||||
};
|
|
||||||
|
|
||||||
struct usb_msosv2_descriptor msosv2_desc = {
|
|
||||||
.vendor_code = USBD_WINUSB_VENDOR_CODE,
|
|
||||||
.compat_id = USBD_WinUSBDescriptorSetDescriptor,
|
|
||||||
.compat_id_len = USBD_WINUSB_DESC_SET_LEN,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct usb_bos_descriptor bos_desc = {
|
|
||||||
.string = USBD_BinaryObjectStoreDescriptor,
|
|
||||||
.string_len = USBD_BOS_WTOTALLENGTH
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
static const uint8_t device_descriptor[] = {
|
static const uint8_t device_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01)
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01)
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t config_descriptor[] = {
|
static const uint8_t config_descriptor[] = {
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
|
HID_KEYBOARD_DESCRIPTOR_INIT(0x00, 0x01, HID_KEYBOARD_REPORT_DESC_SIZE, HID_INT_EP, HID_INT_EP_SIZE, HID_INT_EP_INTERVAL),
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
USB_INTERFACE_DESCRIPTOR_INIT(WEBUSB_INTF_NUM, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00)
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x01, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE_HID, /* 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_KEYBOARD_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
|
||||||
0x00,
|
|
||||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 34 */
|
|
||||||
USB_INTERFACE_DESCRIPTOR_INIT(USBD_WEBUSB_INTF_NUM, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t device_quality_descriptor[] = {
|
static const uint8_t device_quality_descriptor[] = {
|
||||||
@@ -250,41 +133,9 @@ const struct usb_descriptor webusb_hid_descriptor = {
|
|||||||
#else
|
#else
|
||||||
static const uint8_t webusb_hid_descriptor[] = {
|
static const uint8_t webusb_hid_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0002, 0x01),
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_HID_CONFIG_DESC_SIZ, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x02, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
|
HID_KEYBOARD_DESCRIPTOR_INIT(0x00, 0x01, HID_KEYBOARD_REPORT_DESC_SIZE, HID_INT_EP, HID_INT_EP_SIZE, HID_INT_EP_INTERVAL),
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
USB_INTERFACE_DESCRIPTOR_INIT(WEBUSB_INTF_NUM, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00),
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x01, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE_HID, /* 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_KEYBOARD_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
|
||||||
0x00,
|
|
||||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 34 */
|
|
||||||
USB_INTERFACE_DESCRIPTOR_INIT(USBD_WEBUSB_INTF_NUM, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00),
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
/// string0 descriptor
|
/// string0 descriptor
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
@@ -480,7 +331,7 @@ void hid_keyboard_test(uint8_t busid)
|
|||||||
{
|
{
|
||||||
const uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
const uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
if(usb_device_is_configured(busid) == false) {
|
if (usb_device_is_configured(busid) == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,161 +4,106 @@
|
|||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
#include "usbd_cdc_acm.h"
|
|
||||||
|
|
||||||
#define WCID_VENDOR_CODE 0x17
|
#define WINUSB_VENDOR_CODE 0x17
|
||||||
|
|
||||||
#define DOUBLE_WINUSB 0
|
#define WINUSB_NUM 1
|
||||||
|
|
||||||
__ALIGN_BEGIN const uint8_t WCID_StringDescriptor_MSOS[18] __ALIGN_END = {
|
const uint8_t WCID_StringDescriptor_MSOS[18] = {
|
||||||
///////////////////////////////////////
|
USB_MSOSV1_STRING_DESCRIPTOR_INIT(WINUSB_VENDOR_CODE)
|
||||||
/// MS OS string descriptor
|
|
||||||
///////////////////////////////////////
|
|
||||||
0x12, /* bLength */
|
|
||||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
|
||||||
/* MSFT100 */
|
|
||||||
'M', 0x00, 'S', 0x00, 'F', 0x00, 'T', 0x00, /* wcChar_7 */
|
|
||||||
'1', 0x00, '0', 0x00, '0', 0x00, /* wcChar_7 */
|
|
||||||
WCID_VENDOR_CODE, /* bVendorCode */
|
|
||||||
0x00, /* bReserved */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#if DOUBLE_WINUSB == 0
|
const uint8_t WINUSB_WCIDDescriptor[] = {
|
||||||
__ALIGN_BEGIN const uint8_t WINUSB_WCIDDescriptor[40] __ALIGN_END = {
|
USB_MSOSV1_COMP_ID_HEADER_DESCRIPTOR_INIT(WINUSB_NUM),
|
||||||
///////////////////////////////////////
|
USB_MSOSV1_COMP_ID_FUNCTION_WINUSB_DESCRIPTOR_INIT(0),
|
||||||
/// WCID descriptor
|
#if WINUSB_NUM == 2
|
||||||
///////////////////////////////////////
|
USB_MSOSV1_COMP_ID_FUNCTION_WINUSB_DESCRIPTOR_INIT(1),
|
||||||
0x28, 0x00, 0x00, 0x00, /* dwLength */
|
#endif
|
||||||
0x00, 0x01, /* bcdVersion */
|
|
||||||
0x04, 0x00, /* wIndex */
|
|
||||||
0x01, /* bCount */
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* bReserved_7 */
|
|
||||||
|
|
||||||
///////////////////////////////////////
|
|
||||||
/// WCID function descriptor
|
|
||||||
///////////////////////////////////////
|
|
||||||
0x00, /* bFirstInterfaceNumber */
|
|
||||||
0x01, /* bReserved */
|
|
||||||
/* WINUSB */
|
|
||||||
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, /* cCID_8 */
|
|
||||||
/* */
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* cSubCID_8 */
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* bReserved_6 */
|
|
||||||
};
|
};
|
||||||
#else
|
|
||||||
__ALIGN_BEGIN const uint8_t WINUSB_WCIDDescriptor[64] __ALIGN_END = {
|
const uint8_t WINUSB_IF0_WCIDProperties[142] = {
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
/// WCID descriptor
|
/// WCID property descriptor
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
0x40, 0x00, 0x00, 0x00, /* dwLength */
|
0x8e, 0x00, 0x00, 0x00, /* dwLength */
|
||||||
0x00, 0x01, /* bcdVersion */
|
0x00, 0x01, /* bcdVersion */
|
||||||
0x04, 0x00, /* wIndex */
|
0x05, 0x00, /* wIndex */
|
||||||
0x02, /* bCount */
|
0x01, 0x00, /* wCount */
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* bReserved_7 */
|
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
/// WCID function descriptor
|
/// registry propter descriptor
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
0x00, /* bFirstInterfaceNumber */
|
0x84, 0x00, 0x00, 0x00, /* dwSize */
|
||||||
0x01, /* bReserved */
|
0x01, 0x00, 0x00, 0x00, /* dwPropertyDataType */
|
||||||
/* WINUSB */
|
0x28, 0x00, /* wPropertyNameLength */
|
||||||
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, /* cCID_8 */
|
/* DeviceInterfaceGUID */
|
||||||
/* */
|
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, /* wcName_20 */
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* cSubCID_8 */
|
'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, /* wcName_20 */
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* bReserved_6 */
|
't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00, /* wcName_20 */
|
||||||
|
'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, /* wcName_20 */
|
||||||
|
'U', 0x00, 'I', 0x00, 'D', 0x00, 0x00, 0x00, /* wcName_20 */
|
||||||
|
0x4e, 0x00, 0x00, 0x00, /* dwPropertyDataLength */
|
||||||
|
/* {1D4B2365-4749-48EA-B38A-7C6FDDDD7E26} */
|
||||||
|
'{', 0x00, '1', 0x00, 'D', 0x00, '4', 0x00, /* wcData_39 */
|
||||||
|
'B', 0x00, '2', 0x00, '3', 0x00, '6', 0x00, /* wcData_39 */
|
||||||
|
'5', 0x00, '-', 0x00, '4', 0x00, '7', 0x00, /* wcData_39 */
|
||||||
|
'4', 0x00, '9', 0x00, '-', 0x00, '4', 0x00, /* wcData_39 */
|
||||||
|
'8', 0x00, 'E', 0x00, 'A', 0x00, '-', 0x00, /* wcData_39 */
|
||||||
|
'B', 0x00, '3', 0x00, '8', 0x00, 'A', 0x00, /* wcData_39 */
|
||||||
|
'-', 0x00, '7', 0x00, 'C', 0x00, '6', 0x00, /* wcData_39 */
|
||||||
|
'F', 0x00, 'D', 0x00, 'D', 0x00, 'D', 0x00, /* wcData_39 */
|
||||||
|
'D', 0x00, '7', 0x00, 'E', 0x00, '2', 0x00, /* wcData_39 */
|
||||||
|
'6', 0x00, '}', 0x00, 0x00, 0x00, /* wcData_39 */
|
||||||
|
};
|
||||||
|
|
||||||
|
#if WINUSB_NUM == 2
|
||||||
|
#define WINUSB_IF1_WCID_PROPERTIES_SIZE (142)
|
||||||
|
const uint8_t WINUSB_IF1_WCIDProperties[142] = {
|
||||||
|
///////////////////////////////////////
|
||||||
|
/// WCID property descriptor
|
||||||
|
///////////////////////////////////////
|
||||||
|
0x8e, 0x00, 0x00, 0x00, /* dwLength */
|
||||||
|
0x00, 0x01, /* bcdVersion */
|
||||||
|
0x05, 0x00, /* wIndex */
|
||||||
|
0x01, 0x00, /* wCount */
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
/// WCID function descriptor
|
/// registry propter descriptor
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
0x01, /* bFirstInterfaceNumber */
|
0x84, 0x00, 0x00, 0x00, /* dwSize */
|
||||||
0x01, /* bReserved */
|
0x01, 0x00, 0x00, 0x00, /* dwPropertyDataType */
|
||||||
/* WINUSB */
|
0x28, 0x00, /* wPropertyNameLength */
|
||||||
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, /* cCID_8 */
|
/* DeviceInterfaceGUID */
|
||||||
/* */
|
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, /* wcName_20 */
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* cSubCID_8 */
|
'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, /* wcName_20 */
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* bReserved_6 */
|
't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00, /* wcName_20 */
|
||||||
|
'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, /* wcName_20 */
|
||||||
|
'U', 0x00, 'I', 0x00, 'D', 0x00, 0x00, 0x00, /* wcName_20 */
|
||||||
|
0x4e, 0x00, 0x00, 0x00, /* dwPropertyDataLength */
|
||||||
|
/* {1D4B2365-4749-48EA-B38A-7C6FDDDD7E26} */
|
||||||
|
'{', 0x00, '1', 0x00, 'D', 0x00, '4', 0x00, /* wcData_39 */
|
||||||
|
'B', 0x00, '2', 0x00, '3', 0x00, '6', 0x00, /* wcData_39 */
|
||||||
|
'5', 0x00, '-', 0x00, '4', 0x00, '7', 0x00, /* wcData_39 */
|
||||||
|
'4', 0x00, '9', 0x00, '-', 0x00, '4', 0x00, /* wcData_39 */
|
||||||
|
'8', 0x00, 'E', 0x00, 'A', 0x00, '-', 0x00, /* wcData_39 */
|
||||||
|
'B', 0x00, '3', 0x00, '8', 0x00, 'A', 0x00, /* wcData_39 */
|
||||||
|
'-', 0x00, '7', 0x00, 'C', 0x00, '6', 0x00, /* wcData_39 */
|
||||||
|
'F', 0x00, 'D', 0x00, 'D', 0x00, 'D', 0x00, /* wcData_39 */
|
||||||
|
'D', 0x00, '7', 0x00, 'E', 0x00, '2', 0x00, /* wcData_39 */
|
||||||
|
'6', 0x00, '}', 0x00, 0x00, 0x00, /* wcData_39 */
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
__ALIGN_BEGIN const uint8_t WINUSB_IF0_WCIDProperties [142] __ALIGN_END = {
|
|
||||||
///////////////////////////////////////
|
|
||||||
/// WCID property descriptor
|
|
||||||
///////////////////////////////////////
|
|
||||||
0x8e, 0x00, 0x00, 0x00, /* dwLength */
|
|
||||||
0x00, 0x01, /* bcdVersion */
|
|
||||||
0x05, 0x00, /* wIndex */
|
|
||||||
0x01, 0x00, /* wCount */
|
|
||||||
|
|
||||||
///////////////////////////////////////
|
|
||||||
/// registry propter descriptor
|
|
||||||
///////////////////////////////////////
|
|
||||||
0x84, 0x00, 0x00, 0x00, /* dwSize */
|
|
||||||
0x01, 0x00, 0x00, 0x00, /* dwPropertyDataType */
|
|
||||||
0x28, 0x00, /* wPropertyNameLength */
|
|
||||||
/* DeviceInterfaceGUID */
|
|
||||||
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, /* wcName_20 */
|
|
||||||
'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, /* wcName_20 */
|
|
||||||
't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00, /* wcName_20 */
|
|
||||||
'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, /* wcName_20 */
|
|
||||||
'U', 0x00, 'I', 0x00, 'D', 0x00, 0x00, 0x00, /* wcName_20 */
|
|
||||||
0x4e, 0x00, 0x00, 0x00, /* dwPropertyDataLength */
|
|
||||||
/* {1D4B2365-4749-48EA-B38A-7C6FDDDD7E26} */
|
|
||||||
'{', 0x00, '1', 0x00, 'D', 0x00, '4', 0x00, /* wcData_39 */
|
|
||||||
'B', 0x00, '2', 0x00, '3', 0x00, '6', 0x00, /* wcData_39 */
|
|
||||||
'5', 0x00, '-', 0x00, '4', 0x00, '7', 0x00, /* wcData_39 */
|
|
||||||
'4', 0x00, '9', 0x00, '-', 0x00, '4', 0x00, /* wcData_39 */
|
|
||||||
'8', 0x00, 'E', 0x00, 'A', 0x00, '-', 0x00, /* wcData_39 */
|
|
||||||
'B', 0x00, '3', 0x00, '8', 0x00, 'A', 0x00, /* wcData_39 */
|
|
||||||
'-', 0x00, '7', 0x00, 'C', 0x00, '6', 0x00, /* wcData_39 */
|
|
||||||
'F', 0x00, 'D', 0x00, 'D', 0x00, 'D', 0x00, /* wcData_39 */
|
|
||||||
'D', 0x00, '7', 0x00, 'E', 0x00, '2', 0x00, /* wcData_39 */
|
|
||||||
'6', 0x00, '}', 0x00, 0x00, 0x00, /* wcData_39 */
|
|
||||||
};
|
|
||||||
#define WINUSB_IF1_WCID_PROPERTIES_SIZE (142)
|
|
||||||
__ALIGN_BEGIN const uint8_t WINUSB_IF1_WCIDProperties [142] __ALIGN_END = {
|
|
||||||
///////////////////////////////////////
|
|
||||||
/// WCID property descriptor
|
|
||||||
///////////////////////////////////////
|
|
||||||
0x8e, 0x00, 0x00, 0x00, /* dwLength */
|
|
||||||
0x00, 0x01, /* bcdVersion */
|
|
||||||
0x05, 0x00, /* wIndex */
|
|
||||||
0x01, 0x00, /* wCount */
|
|
||||||
|
|
||||||
///////////////////////////////////////
|
|
||||||
/// registry propter descriptor
|
|
||||||
///////////////////////////////////////
|
|
||||||
0x84, 0x00, 0x00, 0x00, /* dwSize */
|
|
||||||
0x01, 0x00, 0x00, 0x00, /* dwPropertyDataType */
|
|
||||||
0x28, 0x00, /* wPropertyNameLength */
|
|
||||||
/* DeviceInterfaceGUID */
|
|
||||||
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, /* wcName_20 */
|
|
||||||
'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, /* wcName_20 */
|
|
||||||
't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00, /* wcName_20 */
|
|
||||||
'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, /* wcName_20 */
|
|
||||||
'U', 0x00, 'I', 0x00, 'D', 0x00, 0x00, 0x00, /* wcName_20 */
|
|
||||||
0x4e, 0x00, 0x00, 0x00, /* dwPropertyDataLength */
|
|
||||||
/* {1D4B2365-4749-48EA-B38A-7C6FDDDD7E26} */
|
|
||||||
'{', 0x00, '1', 0x00, 'D', 0x00, '4', 0x00, /* wcData_39 */
|
|
||||||
'B', 0x00, '2', 0x00, '3', 0x00, '6', 0x00, /* wcData_39 */
|
|
||||||
'5', 0x00, '-', 0x00, '4', 0x00, '7', 0x00, /* wcData_39 */
|
|
||||||
'4', 0x00, '9', 0x00, '-', 0x00, '4', 0x00, /* wcData_39 */
|
|
||||||
'8', 0x00, 'E', 0x00, 'A', 0x00, '-', 0x00, /* wcData_39 */
|
|
||||||
'B', 0x00, '3', 0x00, '8', 0x00, 'A', 0x00, /* wcData_39 */
|
|
||||||
'-', 0x00, '7', 0x00, 'C', 0x00, '6', 0x00, /* wcData_39 */
|
|
||||||
'F', 0x00, 'D', 0x00, 'D', 0x00, 'D', 0x00, /* wcData_39 */
|
|
||||||
'D', 0x00, '7', 0x00, 'E', 0x00, '2', 0x00, /* wcData_39 */
|
|
||||||
'6', 0x00, '}', 0x00, 0x00, 0x00, /* wcData_39 */
|
|
||||||
};
|
|
||||||
|
|
||||||
const uint8_t *WINUSB_IFx_WCIDProperties[] = {
|
const uint8_t *WINUSB_IFx_WCIDProperties[] = {
|
||||||
WINUSB_IF0_WCIDProperties,
|
WINUSB_IF0_WCIDProperties,
|
||||||
#if DOUBLE_WINUSB == 1
|
#if WINUSB_NUM == 2
|
||||||
WINUSB_IF1_WCIDProperties,
|
WINUSB_IF1_WCIDProperties,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct usb_msosv1_descriptor msosv1_desc = {
|
struct usb_msosv1_descriptor msosv1_desc = {
|
||||||
.string = WCID_StringDescriptor_MSOS,
|
.string = WCID_StringDescriptor_MSOS,
|
||||||
.vendor_code = WCID_VENDOR_CODE,
|
.vendor_code = WINUSB_VENDOR_CODE,
|
||||||
.compat_id = WINUSB_WCIDDescriptor,
|
.compat_id = WINUSB_WCIDDescriptor,
|
||||||
.comp_id_property = WINUSB_IFx_WCIDProperties,
|
.comp_id_property = WINUSB_IFx_WCIDProperties,
|
||||||
};
|
};
|
||||||
@@ -166,20 +111,20 @@ struct usb_msosv1_descriptor msosv1_desc = {
|
|||||||
#define WINUSB_IN_EP 0x81
|
#define WINUSB_IN_EP 0x81
|
||||||
#define WINUSB_OUT_EP 0x02
|
#define WINUSB_OUT_EP 0x02
|
||||||
|
|
||||||
#define USBD_VID 0xefff
|
#define USBD_VID 0xFFFE
|
||||||
#define USBD_PID 0xffff
|
#define USBD_PID 0xffff
|
||||||
#define USBD_MAX_POWER 100
|
#define USBD_MAX_POWER 100
|
||||||
#define USBD_LANGID_STRING 1033
|
#define USBD_LANGID_STRING 1033
|
||||||
|
|
||||||
#if DOUBLE_WINUSB == 0
|
#if WINUSB_NUM == 1
|
||||||
#define USB_CONFIG_SIZE (9 + 9 + 7 + 7)
|
#define USB_CONFIG_SIZE (9 + 9 + 7 + 7)
|
||||||
#define INTF_NUM 1
|
#define INTF_NUM 1
|
||||||
#else
|
#else
|
||||||
#define WINUSB_IN_EP2 0x83
|
#define WINUSB_IN_EP2 0x83
|
||||||
#define WINUSB_OUT_EP2 0x04
|
#define WINUSB_OUT_EP2 0x04
|
||||||
|
|
||||||
#define USB_CONFIG_SIZE (9 + 9 + 7 + 7 + 9 + 7 + 7)
|
#define USB_CONFIG_SIZE (9 + 9 + 7 + 7 + 9 + 7 + 7)
|
||||||
#define INTF_NUM 2
|
#define INTF_NUM 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_USB_HS
|
#ifdef CONFIG_USB_HS
|
||||||
@@ -198,7 +143,7 @@ static const uint8_t config_descriptor[] = {
|
|||||||
USB_INTERFACE_DESCRIPTOR_INIT(0x00, 0x00, 0x02, 0xff, 0xff, 0x00, 0x04),
|
USB_INTERFACE_DESCRIPTOR_INIT(0x00, 0x00, 0x02, 0xff, 0xff, 0x00, 0x04),
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
#if DOUBLE_WINUSB == 1
|
#if WINUSB_NUM == 2
|
||||||
USB_INTERFACE_DESCRIPTOR_INIT(0x01, 0x00, 0x02, 0xff, 0xff, 0x00, 0x05),
|
USB_INTERFACE_DESCRIPTOR_INIT(0x01, 0x00, 0x02, 0xff, 0xff, 0x00, 0x05),
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
@@ -253,7 +198,7 @@ static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
|||||||
return string_descriptors[index];
|
return string_descriptors[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct usb_descriptor winusb_descriptor = {
|
const struct usb_descriptor winusbv1_descriptor = {
|
||||||
.device_descriptor_callback = device_descriptor_callback,
|
.device_descriptor_callback = device_descriptor_callback,
|
||||||
.config_descriptor_callback = config_descriptor_callback,
|
.config_descriptor_callback = config_descriptor_callback,
|
||||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||||
@@ -261,13 +206,13 @@ const struct usb_descriptor winusb_descriptor = {
|
|||||||
.msosv1_descriptor = &msosv1_desc
|
.msosv1_descriptor = &msosv1_desc
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
const uint8_t winusb_descriptor[] = {
|
const uint8_t winusbv1_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01),
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01),
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, INTF_NUM, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, INTF_NUM, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
USB_INTERFACE_DESCRIPTOR_INIT(0x00, 0x00, 0x02, 0xff, 0xff, 0x00, 0x04),
|
USB_INTERFACE_DESCRIPTOR_INIT(0x00, 0x00, 0x02, 0xff, 0xff, 0x00, 0x04),
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
#if DOUBLE_WINUSB == 1
|
#if WINUSB_NUM == 2
|
||||||
USB_INTERFACE_DESCRIPTOR_INIT(0x01, 0x00, 0x02, 0xff, 0xff, 0x00, 0x05),
|
USB_INTERFACE_DESCRIPTOR_INIT(0x01, 0x00, 0x02, 0xff, 0xff, 0x00, 0x05),
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
@@ -428,7 +373,7 @@ static void usbd_event_handler(uint8_t busid, uint8_t event)
|
|||||||
ep_tx_busy_flag = false;
|
ep_tx_busy_flag = false;
|
||||||
/* setup first out ep read transfer */
|
/* setup first out ep read transfer */
|
||||||
usbd_ep_start_read(busid, WINUSB_OUT_EP, read_buffer, 2048);
|
usbd_ep_start_read(busid, WINUSB_OUT_EP, read_buffer, 2048);
|
||||||
#if DOUBLE_WINUSB == 1
|
#if WINUSB_NUM == 2
|
||||||
usbd_ep_start_read(busid, WINUSB_OUT_EP2, read_buffer, 2048);
|
usbd_ep_start_read(busid, WINUSB_OUT_EP2, read_buffer, 2048);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
@@ -478,7 +423,7 @@ struct usbd_endpoint winusb_in_ep1 = {
|
|||||||
|
|
||||||
struct usbd_interface intf0;
|
struct usbd_interface intf0;
|
||||||
|
|
||||||
#if DOUBLE_WINUSB == 1
|
#if WINUSB_NUM == 2
|
||||||
|
|
||||||
void usbd_winusb_out2(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
void usbd_winusb_out2(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||||
{
|
{
|
||||||
@@ -518,12 +463,12 @@ struct usbd_interface intf1;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void winusb_init(uint8_t busid, uintptr_t reg_base)
|
void winusbv1_init(uint8_t busid, uintptr_t reg_base)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
usbd_desc_register(busid, &winusb_descriptor);
|
usbd_desc_register(busid, &winusbv1_descriptor);
|
||||||
#else
|
#else
|
||||||
usbd_desc_register(busid, winusb_descriptor);
|
usbd_desc_register(busid, winusbv1_descriptor);
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONFIG_USBDEV_ADVANCE_DESC
|
#ifndef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
usbd_msosv1_desc_register(busid, &msosv1_desc);
|
usbd_msosv1_desc_register(busid, &msosv1_desc);
|
||||||
@@ -531,7 +476,7 @@ void winusb_init(uint8_t busid, uintptr_t reg_base)
|
|||||||
usbd_add_interface(busid, &intf0);
|
usbd_add_interface(busid, &intf0);
|
||||||
usbd_add_endpoint(busid, &winusb_out_ep1);
|
usbd_add_endpoint(busid, &winusb_out_ep1);
|
||||||
usbd_add_endpoint(busid, &winusb_in_ep1);
|
usbd_add_endpoint(busid, &winusb_in_ep1);
|
||||||
#if DOUBLE_WINUSB == 1
|
#if WINUSB_NUM == 2
|
||||||
usbd_add_interface(busid, &intf1);
|
usbd_add_interface(busid, &intf1);
|
||||||
usbd_add_endpoint(busid, &winusb_out_ep2);
|
usbd_add_endpoint(busid, &winusb_out_ep2);
|
||||||
usbd_add_endpoint(busid, &winusb_in_ep2);
|
usbd_add_endpoint(busid, &winusb_in_ep2);
|
||||||
|
|||||||
@@ -6,6 +6,29 @@
|
|||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
#include "usbd_cdc_acm.h"
|
#include "usbd_cdc_acm.h"
|
||||||
|
|
||||||
|
#define WINUSB_VENDOR_CODE 0x17
|
||||||
|
|
||||||
|
const uint8_t WINUSB_WCIDDescriptor[] = {
|
||||||
|
USB_MSOSV2_COMP_ID_SET_HEADER_DESCRIPTOR_INIT(10 + USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_LEN),
|
||||||
|
USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_INIT(0x00),
|
||||||
|
};
|
||||||
|
|
||||||
|
__ALIGN_BEGIN const uint8_t USBD_BinaryObjectStoreDescriptor[] = {
|
||||||
|
USB_BOS_HEADER_DESCRIPTOR_INIT(5 + USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_LEN, 1),
|
||||||
|
USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_INIT(WINUSB_VENDOR_CODE, sizeof(WINUSB_WCIDDescriptor)),
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct usb_msosv2_descriptor msosv2_desc = {
|
||||||
|
.vendor_code = WINUSB_VENDOR_CODE,
|
||||||
|
.compat_id = WINUSB_WCIDDescriptor,
|
||||||
|
.compat_id_len = sizeof(WINUSB_WCIDDescriptor),
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct usb_bos_descriptor bos_desc = {
|
||||||
|
.string = USBD_BinaryObjectStoreDescriptor,
|
||||||
|
.string_len = sizeof(USBD_BinaryObjectStoreDescriptor),
|
||||||
|
};
|
||||||
|
|
||||||
#define WINUSB_IN_EP 0x81
|
#define WINUSB_IN_EP 0x81
|
||||||
#define WINUSB_OUT_EP 0x02
|
#define WINUSB_OUT_EP 0x02
|
||||||
|
|
||||||
@@ -27,135 +50,6 @@
|
|||||||
#define WINUSB_EP_MPS 64
|
#define WINUSB_EP_MPS 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define USBD_WINUSB_VENDOR_CODE 0x20
|
|
||||||
|
|
||||||
#define USBD_WEBUSB_ENABLE 0
|
|
||||||
#define USBD_BULK_ENABLE 1
|
|
||||||
#define USBD_WINUSB_ENABLE 1
|
|
||||||
|
|
||||||
/* WinUSB Microsoft OS 2.0 descriptor sizes */
|
|
||||||
#define WINUSB_DESCRIPTOR_SET_HEADER_SIZE 10
|
|
||||||
#define WINUSB_FUNCTION_SUBSET_HEADER_SIZE 8
|
|
||||||
#define WINUSB_FEATURE_COMPATIBLE_ID_SIZE 20
|
|
||||||
|
|
||||||
#define FUNCTION_SUBSET_LEN 160
|
|
||||||
#define DEVICE_INTERFACE_GUIDS_FEATURE_LEN 132
|
|
||||||
|
|
||||||
#define USBD_WINUSB_DESC_SET_LEN (WINUSB_DESCRIPTOR_SET_HEADER_SIZE + USBD_WEBUSB_ENABLE * FUNCTION_SUBSET_LEN + USBD_BULK_ENABLE * FUNCTION_SUBSET_LEN)
|
|
||||||
|
|
||||||
__ALIGN_BEGIN const uint8_t USBD_WinUSBDescriptorSetDescriptor[] = {
|
|
||||||
WBVAL(WINUSB_DESCRIPTOR_SET_HEADER_SIZE), /* wLength */
|
|
||||||
WBVAL(WINUSB_SET_HEADER_DESCRIPTOR_TYPE), /* wDescriptorType */
|
|
||||||
0x00, 0x00, 0x03, 0x06, /* >= Win 8.1 */ /* dwWindowsVersion*/
|
|
||||||
WBVAL(USBD_WINUSB_DESC_SET_LEN), /* wDescriptorSetTotalLength */
|
|
||||||
#if (USBD_WEBUSB_ENABLE)
|
|
||||||
WBVAL(WINUSB_FUNCTION_SUBSET_HEADER_SIZE), // wLength
|
|
||||||
WBVAL(WINUSB_SUBSET_HEADER_FUNCTION_TYPE), // wDescriptorType
|
|
||||||
0, // bFirstInterface USBD_WINUSB_IF_NUM
|
|
||||||
0, // bReserved
|
|
||||||
WBVAL(FUNCTION_SUBSET_LEN), // wSubsetLength
|
|
||||||
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_SIZE), // wLength
|
|
||||||
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_TYPE), // wDescriptorType
|
|
||||||
'W', 'I', 'N', 'U', 'S', 'B', 0, 0, // CompatibleId
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, // SubCompatibleId
|
|
||||||
WBVAL(DEVICE_INTERFACE_GUIDS_FEATURE_LEN), // wLength
|
|
||||||
WBVAL(WINUSB_FEATURE_REG_PROPERTY_TYPE), // wDescriptorType
|
|
||||||
WBVAL(WINUSB_PROP_DATA_TYPE_REG_MULTI_SZ), // wPropertyDataType
|
|
||||||
WBVAL(42), // wPropertyNameLength
|
|
||||||
'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0,
|
|
||||||
'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0,
|
|
||||||
'G', 0, 'U', 0, 'I', 0, 'D', 0, 's', 0, 0, 0,
|
|
||||||
WBVAL(80), // wPropertyDataLength
|
|
||||||
'{', 0,
|
|
||||||
'9', 0, '2', 0, 'C', 0, 'E', 0, '6', 0, '4', 0, '6', 0, '2', 0, '-', 0,
|
|
||||||
'9', 0, 'C', 0, '7', 0, '7', 0, '-', 0,
|
|
||||||
'4', 0, '6', 0, 'F', 0, 'E', 0, '-', 0,
|
|
||||||
'9', 0, '3', 0, '3', 0, 'B', 0, '-',
|
|
||||||
0, '3', 0, '1', 0, 'C', 0, 'B', 0, '9', 0, 'C', 0, '5', 0, 'A', 0, 'A', 0, '3', 0, 'B', 0, '9', 0,
|
|
||||||
'}', 0, 0, 0, 0, 0
|
|
||||||
#endif
|
|
||||||
#if USBD_BULK_ENABLE
|
|
||||||
WBVAL(WINUSB_FUNCTION_SUBSET_HEADER_SIZE), /* wLength */
|
|
||||||
WBVAL(WINUSB_SUBSET_HEADER_FUNCTION_TYPE), /* wDescriptorType */
|
|
||||||
0, /* bFirstInterface USBD_BULK_IF_NUM*/
|
|
||||||
0, /* bReserved */
|
|
||||||
WBVAL(FUNCTION_SUBSET_LEN), /* wSubsetLength */
|
|
||||||
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_SIZE), /* wLength */
|
|
||||||
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_TYPE), /* wDescriptorType */
|
|
||||||
'W', 'I', 'N', 'U', 'S', 'B', 0, 0, /* CompatibleId*/
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, /* SubCompatibleId*/
|
|
||||||
WBVAL(DEVICE_INTERFACE_GUIDS_FEATURE_LEN), /* wLength */
|
|
||||||
WBVAL(WINUSB_FEATURE_REG_PROPERTY_TYPE), /* wDescriptorType */
|
|
||||||
WBVAL(WINUSB_PROP_DATA_TYPE_REG_MULTI_SZ), /* wPropertyDataType */
|
|
||||||
WBVAL(42), /* wPropertyNameLength */
|
|
||||||
'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0,
|
|
||||||
'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0,
|
|
||||||
'G', 0, 'U', 0, 'I', 0, 'D', 0, 's', 0, 0, 0,
|
|
||||||
WBVAL(80), /* wPropertyDataLength */
|
|
||||||
'{', 0,
|
|
||||||
'C', 0, 'D', 0, 'B', 0, '3', 0, 'B', 0, '5', 0, 'A', 0, 'D', 0, '-', 0,
|
|
||||||
'2', 0, '9', 0, '3', 0, 'B', 0, '-', 0,
|
|
||||||
'4', 0, '6', 0, '6', 0, '3', 0, '-', 0,
|
|
||||||
'A', 0, 'A', 0, '3', 0, '6', 0, '-',
|
|
||||||
0, '1', 0, 'A', 0, 'A', 0, 'E', 0, '4', 0, '6', 0, '4', 0, '6', 0, '3', 0, '7', 0, '7', 0, '6', 0,
|
|
||||||
'}', 0, 0, 0, 0, 0
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
#define USBD_NUM_DEV_CAPABILITIES (USBD_WEBUSB_ENABLE + USBD_WINUSB_ENABLE)
|
|
||||||
|
|
||||||
#define USBD_WEBUSB_DESC_LEN 24
|
|
||||||
#define USBD_WINUSB_DESC_LEN 28
|
|
||||||
|
|
||||||
#define USBD_BOS_WTOTALLENGTH (0x05 + \
|
|
||||||
USBD_WEBUSB_DESC_LEN * USBD_WEBUSB_ENABLE + \
|
|
||||||
USBD_WINUSB_DESC_LEN * USBD_WINUSB_ENABLE)
|
|
||||||
|
|
||||||
__ALIGN_BEGIN const uint8_t USBD_BinaryObjectStoreDescriptor[] = {
|
|
||||||
0x05, /* bLength */
|
|
||||||
0x0f, /* bDescriptorType */
|
|
||||||
WBVAL(USBD_BOS_WTOTALLENGTH), /* wTotalLength */
|
|
||||||
USBD_NUM_DEV_CAPABILITIES, /* bNumDeviceCaps */
|
|
||||||
#if (USBD_WEBUSB_ENABLE)
|
|
||||||
USBD_WEBUSB_DESC_LEN, /* bLength */
|
|
||||||
0x10, /* bDescriptorType */
|
|
||||||
USB_DEVICE_CAPABILITY_PLATFORM, /* bDevCapabilityType */
|
|
||||||
0x00, /* bReserved */
|
|
||||||
0x38, 0xB6, 0x08, 0x34, /* PlatformCapabilityUUID */
|
|
||||||
0xA9, 0x09, 0xA0, 0x47,
|
|
||||||
0x8B, 0xFD, 0xA0, 0x76,
|
|
||||||
0x88, 0x15, 0xB6, 0x65,
|
|
||||||
WBVAL(0x0100), /* 1.00 */ /* bcdVersion */
|
|
||||||
USBD_WINUSB_VENDOR_CODE, /* bVendorCode */
|
|
||||||
0, /* iLandingPage */
|
|
||||||
#endif
|
|
||||||
#if (USBD_WINUSB_ENABLE)
|
|
||||||
USBD_WINUSB_DESC_LEN, /* bLength */
|
|
||||||
0x10, /* bDescriptorType */
|
|
||||||
USB_DEVICE_CAPABILITY_PLATFORM, /* bDevCapabilityType */
|
|
||||||
0x00, /* bReserved */
|
|
||||||
0xDF, 0x60, 0xDD, 0xD8, /* PlatformCapabilityUUID */
|
|
||||||
0x89, 0x45, 0xC7, 0x4C,
|
|
||||||
0x9C, 0xD2, 0x65, 0x9D,
|
|
||||||
0x9E, 0x64, 0x8A, 0x9F,
|
|
||||||
0x00, 0x00, 0x03, 0x06, /* >= Win 8.1 */ /* dwWindowsVersion*/
|
|
||||||
WBVAL(USBD_WINUSB_DESC_SET_LEN), /* wDescriptorSetTotalLength */
|
|
||||||
USBD_WINUSB_VENDOR_CODE, /* bVendorCode */
|
|
||||||
0, /* bAltEnumCode */
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
struct usb_msosv2_descriptor msosv2_desc = {
|
|
||||||
.vendor_code = USBD_WINUSB_VENDOR_CODE,
|
|
||||||
.compat_id = USBD_WinUSBDescriptorSetDescriptor,
|
|
||||||
.compat_id_len = USBD_WINUSB_DESC_SET_LEN,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct usb_bos_descriptor bos_desc = {
|
|
||||||
.string = USBD_BinaryObjectStoreDescriptor,
|
|
||||||
.string_len = USBD_BOS_WTOTALLENGTH
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
static const uint8_t device_descriptor[] = {
|
static const uint8_t device_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01)
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01)
|
||||||
@@ -219,7 +113,7 @@ static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
|||||||
return string_descriptors[index];
|
return string_descriptors[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct usb_descriptor winusbv2_descriptor = {
|
const struct usb_descriptor winusbv2_cdc_descriptor = {
|
||||||
.device_descriptor_callback = device_descriptor_callback,
|
.device_descriptor_callback = device_descriptor_callback,
|
||||||
.config_descriptor_callback = config_descriptor_callback,
|
.config_descriptor_callback = config_descriptor_callback,
|
||||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||||
@@ -228,7 +122,7 @@ const struct usb_descriptor winusbv2_descriptor = {
|
|||||||
.bos_descriptor = &bos_desc
|
.bos_descriptor = &bos_desc
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
const uint8_t winusbv2_descriptor[] = {
|
const uint8_t winusbv2_cdc_descriptor[] = {
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
|
||||||
/* Configuration 0 */
|
/* Configuration 0 */
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, INTF_NUM, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, INTF_NUM, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
@@ -418,12 +312,12 @@ struct usbd_interface winusb_intf;
|
|||||||
struct usbd_interface intf1;
|
struct usbd_interface intf1;
|
||||||
struct usbd_interface intf2;
|
struct usbd_interface intf2;
|
||||||
|
|
||||||
void winusbv2_init(uint8_t busid, uintptr_t reg_base)
|
void winusbv2_cdc_init(uint8_t busid, uintptr_t reg_base)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
usbd_desc_register(busid, &winusbv2_descriptor);
|
usbd_desc_register(busid, &winusbv2_cdc_descriptor);
|
||||||
#else
|
#else
|
||||||
usbd_desc_register(busid, winusbv2_descriptor);
|
usbd_desc_register(busid, winusbv2_cdc_descriptor);
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONFIG_USBDEV_ADVANCE_DESC
|
#ifndef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
usbd_bos_desc_register(busid, &bos_desc);
|
usbd_bos_desc_register(busid, &bos_desc);
|
||||||
|
|||||||
@@ -1,550 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2024, sakumisu
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
#include "usbd_core.h"
|
|
||||||
#include "usbd_hid.h"
|
|
||||||
|
|
||||||
#define WINUSB_IN_EP 0x81
|
|
||||||
#define WINUSB_OUT_EP 0x02
|
|
||||||
|
|
||||||
/*!< endpoint address */
|
|
||||||
#define HID_INT_EP 0x83
|
|
||||||
#define HID_INT_EP_SIZE 4
|
|
||||||
#define HID_INT_EP_INTERVAL 10
|
|
||||||
|
|
||||||
#define USBD_VID 0xFFFE
|
|
||||||
#define USBD_PID 0xFFFF
|
|
||||||
#define USBD_MAX_POWER 500
|
|
||||||
#define USBD_LANGID_STRING 1033
|
|
||||||
|
|
||||||
#define USB_CONFIG_SIZE (9 + 9 + 7 + 7 + 9 + 9 + 7)
|
|
||||||
#define INTF_NUM 2
|
|
||||||
|
|
||||||
/*!< config descriptor size */
|
|
||||||
#define USB_HID_CONFIG_DESC_SIZ 34
|
|
||||||
/*!< report descriptor size */
|
|
||||||
#define HID_MOUSE_REPORT_DESC_SIZE 74
|
|
||||||
|
|
||||||
#ifdef CONFIG_USB_HS
|
|
||||||
#define WINUSB_EP_MPS 512
|
|
||||||
#else
|
|
||||||
#define WINUSB_EP_MPS 64
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define USBD_WINUSB_VENDOR_CODE 0x20
|
|
||||||
|
|
||||||
#define USBD_WEBUSB_ENABLE 0
|
|
||||||
#define USBD_BULK_ENABLE 1
|
|
||||||
#define USBD_WINUSB_ENABLE 1
|
|
||||||
|
|
||||||
/* WinUSB Microsoft OS 2.0 descriptor sizes */
|
|
||||||
#define WINUSB_DESCRIPTOR_SET_HEADER_SIZE 10
|
|
||||||
#define WINUSB_FUNCTION_SUBSET_HEADER_SIZE 8
|
|
||||||
#define WINUSB_FEATURE_COMPATIBLE_ID_SIZE 20
|
|
||||||
|
|
||||||
#define FUNCTION_SUBSET_LEN 160
|
|
||||||
#define DEVICE_INTERFACE_GUIDS_FEATURE_LEN 132
|
|
||||||
|
|
||||||
#define USBD_WINUSB_DESC_SET_LEN (WINUSB_DESCRIPTOR_SET_HEADER_SIZE + USBD_WEBUSB_ENABLE * FUNCTION_SUBSET_LEN + USBD_BULK_ENABLE * FUNCTION_SUBSET_LEN)
|
|
||||||
|
|
||||||
__ALIGN_BEGIN const uint8_t USBD_WinUSBDescriptorSetDescriptor[] = {
|
|
||||||
WBVAL(WINUSB_DESCRIPTOR_SET_HEADER_SIZE), /* wLength */
|
|
||||||
WBVAL(WINUSB_SET_HEADER_DESCRIPTOR_TYPE), /* wDescriptorType */
|
|
||||||
0x00, 0x00, 0x03, 0x06, /* >= Win 8.1 */ /* dwWindowsVersion*/
|
|
||||||
WBVAL(USBD_WINUSB_DESC_SET_LEN), /* wDescriptorSetTotalLength */
|
|
||||||
#if (USBD_WEBUSB_ENABLE)
|
|
||||||
WBVAL(WINUSB_FUNCTION_SUBSET_HEADER_SIZE), // wLength
|
|
||||||
WBVAL(WINUSB_SUBSET_HEADER_FUNCTION_TYPE), // wDescriptorType
|
|
||||||
0, // bFirstInterface USBD_WINUSB_IF_NUM
|
|
||||||
0, // bReserved
|
|
||||||
WBVAL(FUNCTION_SUBSET_LEN), // wSubsetLength
|
|
||||||
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_SIZE), // wLength
|
|
||||||
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_TYPE), // wDescriptorType
|
|
||||||
'W', 'I', 'N', 'U', 'S', 'B', 0, 0, // CompatibleId
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, // SubCompatibleId
|
|
||||||
WBVAL(DEVICE_INTERFACE_GUIDS_FEATURE_LEN), // wLength
|
|
||||||
WBVAL(WINUSB_FEATURE_REG_PROPERTY_TYPE), // wDescriptorType
|
|
||||||
WBVAL(WINUSB_PROP_DATA_TYPE_REG_MULTI_SZ), // wPropertyDataType
|
|
||||||
WBVAL(42), // wPropertyNameLength
|
|
||||||
'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0,
|
|
||||||
'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0,
|
|
||||||
'G', 0, 'U', 0, 'I', 0, 'D', 0, 's', 0, 0, 0,
|
|
||||||
WBVAL(80), // wPropertyDataLength
|
|
||||||
'{', 0,
|
|
||||||
'9', 0, '2', 0, 'C', 0, 'E', 0, '6', 0, '4', 0, '6', 0, '2', 0, '-', 0,
|
|
||||||
'9', 0, 'C', 0, '7', 0, '7', 0, '-', 0,
|
|
||||||
'4', 0, '6', 0, 'F', 0, 'E', 0, '-', 0,
|
|
||||||
'9', 0, '3', 0, '3', 0, 'B', 0, '-',
|
|
||||||
0, '3', 0, '1', 0, 'C', 0, 'B', 0, '9', 0, 'C', 0, '5', 0, 'A', 0, 'A', 0, '3', 0, 'B', 0, '9', 0,
|
|
||||||
'}', 0, 0, 0, 0, 0
|
|
||||||
#endif
|
|
||||||
#if USBD_BULK_ENABLE
|
|
||||||
WBVAL(WINUSB_FUNCTION_SUBSET_HEADER_SIZE), /* wLength */
|
|
||||||
WBVAL(WINUSB_SUBSET_HEADER_FUNCTION_TYPE), /* wDescriptorType */
|
|
||||||
0, /* bFirstInterface USBD_BULK_IF_NUM*/
|
|
||||||
0, /* bReserved */
|
|
||||||
WBVAL(FUNCTION_SUBSET_LEN), /* wSubsetLength */
|
|
||||||
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_SIZE), /* wLength */
|
|
||||||
WBVAL(WINUSB_FEATURE_COMPATIBLE_ID_TYPE), /* wDescriptorType */
|
|
||||||
'W', 'I', 'N', 'U', 'S', 'B', 0, 0, /* CompatibleId*/
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, /* SubCompatibleId*/
|
|
||||||
WBVAL(DEVICE_INTERFACE_GUIDS_FEATURE_LEN), /* wLength */
|
|
||||||
WBVAL(WINUSB_FEATURE_REG_PROPERTY_TYPE), /* wDescriptorType */
|
|
||||||
WBVAL(WINUSB_PROP_DATA_TYPE_REG_MULTI_SZ), /* wPropertyDataType */
|
|
||||||
WBVAL(42), /* wPropertyNameLength */
|
|
||||||
'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0,
|
|
||||||
'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0,
|
|
||||||
'G', 0, 'U', 0, 'I', 0, 'D', 0, 's', 0, 0, 0,
|
|
||||||
WBVAL(80), /* wPropertyDataLength */
|
|
||||||
'{', 0,
|
|
||||||
'C', 0, 'D', 0, 'B', 0, '3', 0, 'B', 0, '5', 0, 'A', 0, 'D', 0, '-', 0,
|
|
||||||
'2', 0, '9', 0, '3', 0, 'B', 0, '-', 0,
|
|
||||||
'4', 0, '6', 0, '6', 0, '3', 0, '-', 0,
|
|
||||||
'A', 0, 'A', 0, '3', 0, '6', 0, '-',
|
|
||||||
0, '1', 0, 'A', 0, 'A', 0, 'E', 0, '4', 0, '6', 0, '4', 0, '6', 0, '3', 0, '7', 0, '7', 0, '6', 0,
|
|
||||||
'}', 0, 0, 0, 0, 0
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
#define USBD_NUM_DEV_CAPABILITIES (USBD_WEBUSB_ENABLE + USBD_WINUSB_ENABLE)
|
|
||||||
|
|
||||||
#define USBD_WEBUSB_DESC_LEN 24
|
|
||||||
#define USBD_WINUSB_DESC_LEN 28
|
|
||||||
|
|
||||||
#define USBD_BOS_WTOTALLENGTH (0x05 + \
|
|
||||||
USBD_WEBUSB_DESC_LEN * USBD_WEBUSB_ENABLE + \
|
|
||||||
USBD_WINUSB_DESC_LEN * USBD_WINUSB_ENABLE)
|
|
||||||
|
|
||||||
__ALIGN_BEGIN const uint8_t USBD_BinaryObjectStoreDescriptor[] = {
|
|
||||||
0x05, /* bLength */
|
|
||||||
0x0f, /* bDescriptorType */
|
|
||||||
WBVAL(USBD_BOS_WTOTALLENGTH), /* wTotalLength */
|
|
||||||
USBD_NUM_DEV_CAPABILITIES, /* bNumDeviceCaps */
|
|
||||||
#if (USBD_WEBUSB_ENABLE)
|
|
||||||
USBD_WEBUSB_DESC_LEN, /* bLength */
|
|
||||||
0x10, /* bDescriptorType */
|
|
||||||
USB_DEVICE_CAPABILITY_PLATFORM, /* bDevCapabilityType */
|
|
||||||
0x00, /* bReserved */
|
|
||||||
0x38, 0xB6, 0x08, 0x34, /* PlatformCapabilityUUID */
|
|
||||||
0xA9, 0x09, 0xA0, 0x47,
|
|
||||||
0x8B, 0xFD, 0xA0, 0x76,
|
|
||||||
0x88, 0x15, 0xB6, 0x65,
|
|
||||||
WBVAL(0x0100), /* 1.00 */ /* bcdVersion */
|
|
||||||
USBD_WINUSB_VENDOR_CODE, /* bVendorCode */
|
|
||||||
0, /* iLandingPage */
|
|
||||||
#endif
|
|
||||||
#if (USBD_WINUSB_ENABLE)
|
|
||||||
USBD_WINUSB_DESC_LEN, /* bLength */
|
|
||||||
0x10, /* bDescriptorType */
|
|
||||||
USB_DEVICE_CAPABILITY_PLATFORM, /* bDevCapabilityType */
|
|
||||||
0x00, /* bReserved */
|
|
||||||
0xDF, 0x60, 0xDD, 0xD8, /* PlatformCapabilityUUID */
|
|
||||||
0x89, 0x45, 0xC7, 0x4C,
|
|
||||||
0x9C, 0xD2, 0x65, 0x9D,
|
|
||||||
0x9E, 0x64, 0x8A, 0x9F,
|
|
||||||
0x00, 0x00, 0x03, 0x06, /* >= Win 8.1 */ /* dwWindowsVersion*/
|
|
||||||
WBVAL(USBD_WINUSB_DESC_SET_LEN), /* wDescriptorSetTotalLength */
|
|
||||||
USBD_WINUSB_VENDOR_CODE, /* bVendorCode */
|
|
||||||
0, /* bAltEnumCode */
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
struct usb_msosv2_descriptor msosv2_desc = {
|
|
||||||
.vendor_code = USBD_WINUSB_VENDOR_CODE,
|
|
||||||
.compat_id = USBD_WinUSBDescriptorSetDescriptor,
|
|
||||||
.compat_id_len = USBD_WINUSB_DESC_SET_LEN,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct usb_bos_descriptor bos_desc = {
|
|
||||||
.string = USBD_BinaryObjectStoreDescriptor,
|
|
||||||
.string_len = USBD_BOS_WTOTALLENGTH
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
|
||||||
static const uint8_t device_descriptor[] = {
|
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01)
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint8_t config_descriptor[] = {
|
|
||||||
/* Configuration 0 */
|
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, INTF_NUM, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
|
||||||
/* Interface 0 */
|
|
||||||
USB_INTERFACE_DESCRIPTOR_INIT(0x00, 0x00, 0x02, 0xFF, 0x00, 0x00, 0x02),
|
|
||||||
/* Endpoint OUT 2 */
|
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP, USB_ENDPOINT_TYPE_BULK, WINUSB_EP_MPS, 0x00),
|
|
||||||
/* Endpoint IN 1 */
|
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP, USB_ENDPOINT_TYPE_BULK, WINUSB_EP_MPS, 0x00),
|
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x01, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE_HID, /* 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_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
|
||||||
0x00,
|
|
||||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint8_t device_quality_descriptor[] = {
|
|
||||||
///////////////////////////////////////
|
|
||||||
/// device qualifier descriptor
|
|
||||||
///////////////////////////////////////
|
|
||||||
0x0a,
|
|
||||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
|
||||||
0x10,
|
|
||||||
0x02,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x40,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char *string_descriptors[] = {
|
|
||||||
(const char[]){ 0x09, 0x04 }, /* Langid */
|
|
||||||
"CherryUSB", /* Manufacturer */
|
|
||||||
"CherryUSB WINUSB DEMO", /* Product */
|
|
||||||
"2022123456", /* Serial Number */
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
|
||||||
{
|
|
||||||
return device_descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
|
||||||
{
|
|
||||||
return config_descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
|
||||||
{
|
|
||||||
return device_quality_descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
|
||||||
{
|
|
||||||
if (index > 3) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return string_descriptors[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct usb_descriptor winusbv2_descriptor = {
|
|
||||||
.device_descriptor_callback = device_descriptor_callback,
|
|
||||||
.config_descriptor_callback = config_descriptor_callback,
|
|
||||||
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
|
||||||
.string_descriptor_callback = string_descriptor_callback,
|
|
||||||
.msosv2_descriptor = &msosv2_desc,
|
|
||||||
.bos_descriptor = &bos_desc
|
|
||||||
};
|
|
||||||
#else
|
|
||||||
const uint8_t winusbv2_descriptor[] = {
|
|
||||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0xEF, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
|
|
||||||
/* Configuration 0 */
|
|
||||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, INTF_NUM, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
|
||||||
/* Interface 0 */
|
|
||||||
USB_INTERFACE_DESCRIPTOR_INIT(0x00, 0x00, 0x02, 0xFF, 0x00, 0x00, 0x02),
|
|
||||||
/* Endpoint OUT 2 */
|
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP, USB_ENDPOINT_TYPE_BULK, WINUSB_EP_MPS, 0x00),
|
|
||||||
/* Endpoint IN 1 */
|
|
||||||
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP, USB_ENDPOINT_TYPE_BULK, WINUSB_EP_MPS, 0x00),
|
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x01, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE_HID, /* 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_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
HID_INT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
|
|
||||||
0x00,
|
|
||||||
HID_INT_EP_INTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* String 0 (LANGID) */
|
|
||||||
USB_LANGID_INIT(USBD_LANGID_STRING),
|
|
||||||
/* String 1 (Manufacturer) */
|
|
||||||
0x14, /* bLength */
|
|
||||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
|
||||||
'C', 0x00, /* wcChar0 */
|
|
||||||
'h', 0x00, /* wcChar1 */
|
|
||||||
'e', 0x00, /* wcChar2 */
|
|
||||||
'r', 0x00, /* wcChar3 */
|
|
||||||
'r', 0x00, /* wcChar4 */
|
|
||||||
'y', 0x00, /* wcChar5 */
|
|
||||||
'U', 0x00, /* wcChar6 */
|
|
||||||
'S', 0x00, /* wcChar7 */
|
|
||||||
'B', 0x00, /* wcChar8 */
|
|
||||||
///////////////////////////////////////
|
|
||||||
/// string2 descriptor
|
|
||||||
///////////////////////////////////////
|
|
||||||
0x2C, /* bLength */
|
|
||||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
|
||||||
'C', 0x00, /* wcChar0 */
|
|
||||||
'h', 0x00, /* wcChar1 */
|
|
||||||
'e', 0x00, /* wcChar2 */
|
|
||||||
'r', 0x00, /* wcChar3 */
|
|
||||||
'r', 0x00, /* wcChar4 */
|
|
||||||
'y', 0x00, /* wcChar5 */
|
|
||||||
'U', 0x00, /* wcChar6 */
|
|
||||||
'S', 0x00, /* wcChar7 */
|
|
||||||
'B', 0x00, /* wcChar8 */
|
|
||||||
' ', 0x00, /* wcChar9 */
|
|
||||||
'W', 0x00, /* wcChar10 */
|
|
||||||
'I', 0x00, /* wcChar11 */
|
|
||||||
'N', 0x00, /* wcChar12 */
|
|
||||||
'U', 0x00, /* wcChar13 */
|
|
||||||
'S', 0x00, /* wcChar14 */
|
|
||||||
'B', 0x00, /* wcChar15 */
|
|
||||||
' ', 0x00, /* wcChar16 */
|
|
||||||
'D', 0x00, /* wcChar17 */
|
|
||||||
'E', 0x00, /* wcChar18 */
|
|
||||||
'M', 0x00, /* wcChar19 */
|
|
||||||
'O', 0x00, /* wcChar20 */
|
|
||||||
///////////////////////////////////////
|
|
||||||
/// string3 descriptor
|
|
||||||
///////////////////////////////////////
|
|
||||||
0x16, /* bLength */
|
|
||||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
|
||||||
'2', 0x00, /* wcChar0 */
|
|
||||||
'0', 0x00, /* wcChar1 */
|
|
||||||
'2', 0x00, /* wcChar2 */
|
|
||||||
'2', 0x00, /* wcChar3 */
|
|
||||||
'1', 0x00, /* wcChar4 */
|
|
||||||
'2', 0x00, /* wcChar5 */
|
|
||||||
'3', 0x00, /* wcChar6 */
|
|
||||||
'4', 0x00, /* wcChar7 */
|
|
||||||
'5', 0x00, /* wcChar8 */
|
|
||||||
'6', 0x00, /* wcChar9 */
|
|
||||||
#ifdef CONFIG_USB_HS
|
|
||||||
/* Device Qualifier */
|
|
||||||
0x0a,
|
|
||||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
|
||||||
0x10,
|
|
||||||
0x02,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x40,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
#endif
|
|
||||||
/* End */
|
|
||||||
0x00
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[2048];
|
|
||||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[2048];
|
|
||||||
|
|
||||||
volatile bool ep_tx_busy_flag = false;
|
|
||||||
|
|
||||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
|
||||||
{
|
|
||||||
switch (event) {
|
|
||||||
case USBD_EVENT_RESET:
|
|
||||||
break;
|
|
||||||
case USBD_EVENT_CONNECTED:
|
|
||||||
break;
|
|
||||||
case USBD_EVENT_DISCONNECTED:
|
|
||||||
break;
|
|
||||||
case USBD_EVENT_RESUME:
|
|
||||||
break;
|
|
||||||
case USBD_EVENT_SUSPEND:
|
|
||||||
break;
|
|
||||||
case USBD_EVENT_CONFIGURED:
|
|
||||||
ep_tx_busy_flag = false;
|
|
||||||
/* setup first out ep read transfer */
|
|
||||||
usbd_ep_start_read(busid, WINUSB_OUT_EP, read_buffer, 2048);
|
|
||||||
break;
|
|
||||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
|
||||||
break;
|
|
||||||
case USBD_EVENT_CLR_REMOTE_WAKEUP:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void usbd_winusb_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
|
||||||
{
|
|
||||||
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
|
||||||
// for (int i = 0; i < 100; i++) {
|
|
||||||
// printf("%02x ", read_buffer[i]);
|
|
||||||
// }
|
|
||||||
// printf("\r\n");
|
|
||||||
usbd_ep_start_write(busid, WINUSB_IN_EP, read_buffer, nbytes);
|
|
||||||
/* setup next out ep read transfer */
|
|
||||||
usbd_ep_start_read(busid, WINUSB_OUT_EP, read_buffer, 2048);
|
|
||||||
}
|
|
||||||
|
|
||||||
void usbd_winusb_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
|
||||||
{
|
|
||||||
USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
|
|
||||||
|
|
||||||
if ((nbytes % usbd_get_ep_mps(busid, ep)) == 0 && nbytes) {
|
|
||||||
/* send zlp */
|
|
||||||
usbd_ep_start_write(busid, WINUSB_IN_EP, NULL, 0);
|
|
||||||
} else {
|
|
||||||
ep_tx_busy_flag = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct usbd_endpoint winusb_out_ep1 = {
|
|
||||||
.ep_addr = WINUSB_OUT_EP,
|
|
||||||
.ep_cb = usbd_winusb_out
|
|
||||||
};
|
|
||||||
|
|
||||||
struct usbd_endpoint winusb_in_ep1 = {
|
|
||||||
.ep_addr = WINUSB_IN_EP,
|
|
||||||
.ep_cb = usbd_winusb_in
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!< hid mouse report descriptor */
|
|
||||||
static const uint8_t hid_mouse_report_desc[HID_MOUSE_REPORT_DESC_SIZE] = {
|
|
||||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
|
||||||
0x09, 0x02, // USAGE (Mouse)
|
|
||||||
0xA1, 0x01, // COLLECTION (Application)
|
|
||||||
0x09, 0x01, // USAGE (Pointer)
|
|
||||||
|
|
||||||
0xA1, 0x00, // COLLECTION (Physical)
|
|
||||||
0x05, 0x09, // USAGE_PAGE (Button)
|
|
||||||
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
|
||||||
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
|
|
||||||
|
|
||||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
|
||||||
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
|
||||||
0x95, 0x03, // REPORT_COUNT (3)
|
|
||||||
0x75, 0x01, // REPORT_SIZE (1)
|
|
||||||
|
|
||||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
|
||||||
0x95, 0x01, // REPORT_COUNT (1)
|
|
||||||
0x75, 0x05, // REPORT_SIZE (5)
|
|
||||||
0x81, 0x01, // INPUT (Cnst,Var,Abs)
|
|
||||||
|
|
||||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
|
||||||
0x09, 0x30, // USAGE (X)
|
|
||||||
0x09, 0x31, // USAGE (Y)
|
|
||||||
0x09, 0x38,
|
|
||||||
|
|
||||||
0x15, 0x81, // LOGICAL_MINIMUM (-127)
|
|
||||||
0x25, 0x7F, // LOGICAL_MAXIMUM (127)
|
|
||||||
0x75, 0x08, // REPORT_SIZE (8)
|
|
||||||
0x95, 0x03, // REPORT_COUNT (2)
|
|
||||||
|
|
||||||
0x81, 0x06, // INPUT (Data,Var,Rel)
|
|
||||||
0xC0, 0x09,
|
|
||||||
0x3c, 0x05,
|
|
||||||
0xff, 0x09,
|
|
||||||
|
|
||||||
0x01, 0x15,
|
|
||||||
0x00, 0x25,
|
|
||||||
0x01, 0x75,
|
|
||||||
0x01, 0x95,
|
|
||||||
|
|
||||||
0x02, 0xb1,
|
|
||||||
0x22, 0x75,
|
|
||||||
0x06, 0x95,
|
|
||||||
0x01, 0xb1,
|
|
||||||
|
|
||||||
0x01, 0xc0 // END_COLLECTION
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!< mouse report struct */
|
|
||||||
struct hid_mouse {
|
|
||||||
uint8_t buttons;
|
|
||||||
int8_t x;
|
|
||||||
int8_t y;
|
|
||||||
int8_t wheel;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!< mouse report */
|
|
||||||
static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX struct hid_mouse mouse_cfg;
|
|
||||||
|
|
||||||
#define HID_STATE_IDLE 0
|
|
||||||
#define HID_STATE_BUSY 1
|
|
||||||
|
|
||||||
/*!< hid state ! Data can be sent only when state is idle */
|
|
||||||
static volatile uint8_t hid_state = HID_STATE_IDLE;
|
|
||||||
|
|
||||||
/* function ------------------------------------------------------------------*/
|
|
||||||
static void usbd_hid_int_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
|
||||||
{
|
|
||||||
hid_state = HID_STATE_IDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!< endpoint call back */
|
|
||||||
static struct usbd_endpoint hid_in_ep = {
|
|
||||||
.ep_cb = usbd_hid_int_callback,
|
|
||||||
.ep_addr = HID_INT_EP
|
|
||||||
};
|
|
||||||
|
|
||||||
struct usbd_interface winusb_intf;
|
|
||||||
struct usbd_interface intf1;
|
|
||||||
|
|
||||||
void winusbv2_init(uint8_t busid, uintptr_t reg_base)
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
|
||||||
usbd_desc_register(busid, &winusbv2_descriptor);
|
|
||||||
#else
|
|
||||||
usbd_desc_register(busid, winusbv2_descriptor);
|
|
||||||
#endif
|
|
||||||
#ifndef CONFIG_USBDEV_ADVANCE_DESC
|
|
||||||
usbd_bos_desc_register(busid, &bos_desc);
|
|
||||||
usbd_msosv2_desc_register(busid, &msosv2_desc);
|
|
||||||
#endif
|
|
||||||
/*!< winusb */
|
|
||||||
usbd_add_interface(busid, &winusb_intf);
|
|
||||||
usbd_add_endpoint(busid, &winusb_out_ep1);
|
|
||||||
usbd_add_endpoint(busid, &winusb_in_ep1);
|
|
||||||
|
|
||||||
usbd_add_interface(busid, usbd_hid_init_intf(busid, &intf1, hid_mouse_report_desc, HID_MOUSE_REPORT_DESC_SIZE));
|
|
||||||
usbd_add_endpoint(busid, &hid_in_ep);
|
|
||||||
|
|
||||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
|
||||||
}
|
|
||||||
416
demo/winusb2.0_template.c
Normal file
416
demo/winusb2.0_template.c
Normal file
@@ -0,0 +1,416 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, sakumisu
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#include "usbd_core.h"
|
||||||
|
|
||||||
|
#define WINUSB_VENDOR_CODE 0x17
|
||||||
|
|
||||||
|
#define WINUSB_NUM 1
|
||||||
|
|
||||||
|
// note that if device is composite device, you should use USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_INIT
|
||||||
|
const uint8_t WINUSB_WCIDDescriptor[] = {
|
||||||
|
#if WINUSB_NUM == 1
|
||||||
|
USB_MSOSV2_COMP_ID_SET_HEADER_DESCRIPTOR_INIT(10 + USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_SINGLE_DESCRIPTOR_LEN),
|
||||||
|
USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_SINGLE_DESCRIPTOR_INIT(),
|
||||||
|
#else
|
||||||
|
USB_MSOSV2_COMP_ID_SET_HEADER_DESCRIPTOR_INIT(10 + WINUSB_NUM * USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_LEN),
|
||||||
|
USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_INIT(0x00),
|
||||||
|
USB_MSOSV2_COMP_ID_FUNCTION_WINUSB_MULTI_DESCRIPTOR_INIT(0x01),
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint8_t USBD_BinaryObjectStoreDescriptor[] = {
|
||||||
|
USB_BOS_HEADER_DESCRIPTOR_INIT(5 + USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_LEN, 1),
|
||||||
|
USB_BOS_CAP_PLATFORM_WINUSB_DESCRIPTOR_INIT(WINUSB_VENDOR_CODE, sizeof(WINUSB_WCIDDescriptor)),
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct usb_msosv2_descriptor msosv2_desc = {
|
||||||
|
.vendor_code = WINUSB_VENDOR_CODE,
|
||||||
|
.compat_id = WINUSB_WCIDDescriptor,
|
||||||
|
.compat_id_len = sizeof(WINUSB_WCIDDescriptor),
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct usb_bos_descriptor bos_desc = {
|
||||||
|
.string = USBD_BinaryObjectStoreDescriptor,
|
||||||
|
.string_len = sizeof(USBD_BinaryObjectStoreDescriptor),
|
||||||
|
};
|
||||||
|
|
||||||
|
#define WINUSB_IN_EP 0x81
|
||||||
|
#define WINUSB_OUT_EP 0x02
|
||||||
|
|
||||||
|
#define USBD_VID 0xFFFE
|
||||||
|
#define USBD_PID 0xffff
|
||||||
|
#define USBD_MAX_POWER 100
|
||||||
|
#define USBD_LANGID_STRING 1033
|
||||||
|
|
||||||
|
#if WINUSB_NUM == 1
|
||||||
|
#define USB_CONFIG_SIZE (9 + 9 + 7 + 7)
|
||||||
|
#define INTF_NUM 1
|
||||||
|
#else
|
||||||
|
#define WINUSB_IN_EP2 0x83
|
||||||
|
#define WINUSB_OUT_EP2 0x04
|
||||||
|
|
||||||
|
#define USB_CONFIG_SIZE (9 + 9 + 7 + 7 + 9 + 7 + 7)
|
||||||
|
#define INTF_NUM 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_USB_HS
|
||||||
|
#define WINUSB_EP_MPS 512
|
||||||
|
#else
|
||||||
|
#define WINUSB_EP_MPS 64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
|
static const uint8_t device_descriptor[] = {
|
||||||
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01)
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t config_descriptor[] = {
|
||||||
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, INTF_NUM, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
|
USB_INTERFACE_DESCRIPTOR_INIT(0x00, 0x00, 0x02, 0xff, 0xff, 0x00, 0x04),
|
||||||
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
|
#if WINUSB_NUM == 2
|
||||||
|
USB_INTERFACE_DESCRIPTOR_INIT(0x01, 0x00, 0x02, 0xff, 0xff, 0x00, 0x05),
|
||||||
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t device_quality_descriptor[] = {
|
||||||
|
///////////////////////////////////////
|
||||||
|
/// device qualifier descriptor
|
||||||
|
///////////////////////////////////////
|
||||||
|
0x0a,
|
||||||
|
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||||
|
0x00,
|
||||||
|
0x02,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x40,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *string_descriptors[] = {
|
||||||
|
(const char[]){ 0x09, 0x04 }, /* Langid */
|
||||||
|
"CherryUSB", /* Manufacturer */
|
||||||
|
"CherryUSB WINUSB DEMO", /* Product */
|
||||||
|
"2022123456", /* Serial Number */
|
||||||
|
"CherryUSB WINUSB DEMO 1", /* STRING4 */
|
||||||
|
"CherryUSB WINUSB DEMO 2", /* STRING5 */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t *device_descriptor_callback(uint8_t speed)
|
||||||
|
{
|
||||||
|
return device_descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const uint8_t *config_descriptor_callback(uint8_t speed)
|
||||||
|
{
|
||||||
|
return config_descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const uint8_t *device_quality_descriptor_callback(uint8_t speed)
|
||||||
|
{
|
||||||
|
return device_quality_descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *string_descriptor_callback(uint8_t speed, uint8_t index)
|
||||||
|
{
|
||||||
|
if (index > 5) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return string_descriptors[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct usb_descriptor winusbv2_descriptor = {
|
||||||
|
.device_descriptor_callback = device_descriptor_callback,
|
||||||
|
.config_descriptor_callback = config_descriptor_callback,
|
||||||
|
.device_quality_descriptor_callback = device_quality_descriptor_callback,
|
||||||
|
.string_descriptor_callback = string_descriptor_callback,
|
||||||
|
.msosv2_descriptor = &msosv2_desc,
|
||||||
|
.bos_descriptor = &bos_desc,
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
const uint8_t winusbv2_descriptor[] = {
|
||||||
|
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0001, 0x01),
|
||||||
|
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, INTF_NUM, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||||
|
USB_INTERFACE_DESCRIPTOR_INIT(0x00, 0x00, 0x02, 0xff, 0xff, 0x00, 0x04),
|
||||||
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
|
#if WINUSB_NUM == 2
|
||||||
|
USB_INTERFACE_DESCRIPTOR_INIT(0x01, 0x00, 0x02, 0xff, 0xff, 0x00, 0x05),
|
||||||
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_IN_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
|
USB_ENDPOINT_DESCRIPTOR_INIT(WINUSB_OUT_EP2, 0x02, WINUSB_EP_MPS, 0x00),
|
||||||
|
#endif
|
||||||
|
///////////////////////////////////////
|
||||||
|
/// string0 descriptor
|
||||||
|
///////////////////////////////////////
|
||||||
|
USB_LANGID_INIT(USBD_LANGID_STRING),
|
||||||
|
///////////////////////////////////////
|
||||||
|
/// string1 descriptor
|
||||||
|
///////////////////////////////////////
|
||||||
|
0x14, /* bLength */
|
||||||
|
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||||
|
'C', 0x00, /* wcChar0 */
|
||||||
|
'h', 0x00, /* wcChar1 */
|
||||||
|
'e', 0x00, /* wcChar2 */
|
||||||
|
'r', 0x00, /* wcChar3 */
|
||||||
|
'r', 0x00, /* wcChar4 */
|
||||||
|
'y', 0x00, /* wcChar5 */
|
||||||
|
'U', 0x00, /* wcChar6 */
|
||||||
|
'S', 0x00, /* wcChar7 */
|
||||||
|
'B', 0x00, /* wcChar8 */
|
||||||
|
///////////////////////////////////////
|
||||||
|
/// string2 descriptor
|
||||||
|
///////////////////////////////////////
|
||||||
|
0x2C, /* bLength */
|
||||||
|
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||||
|
'C', 0x00, /* wcChar0 */
|
||||||
|
'h', 0x00, /* wcChar1 */
|
||||||
|
'e', 0x00, /* wcChar2 */
|
||||||
|
'r', 0x00, /* wcChar3 */
|
||||||
|
'r', 0x00, /* wcChar4 */
|
||||||
|
'y', 0x00, /* wcChar5 */
|
||||||
|
'U', 0x00, /* wcChar6 */
|
||||||
|
'S', 0x00, /* wcChar7 */
|
||||||
|
'B', 0x00, /* wcChar8 */
|
||||||
|
' ', 0x00, /* wcChar9 */
|
||||||
|
'W', 0x00, /* wcChar10 */
|
||||||
|
'I', 0x00, /* wcChar11 */
|
||||||
|
'N', 0x00, /* wcChar12 */
|
||||||
|
'U', 0x00, /* wcChar13 */
|
||||||
|
'S', 0x00, /* wcChar14 */
|
||||||
|
'B', 0x00, /* wcChar15 */
|
||||||
|
' ', 0x00, /* wcChar16 */
|
||||||
|
'D', 0x00, /* wcChar17 */
|
||||||
|
'E', 0x00, /* wcChar18 */
|
||||||
|
'M', 0x00, /* wcChar19 */
|
||||||
|
'O', 0x00, /* wcChar20 */
|
||||||
|
///////////////////////////////////////
|
||||||
|
/// string3 descriptor
|
||||||
|
///////////////////////////////////////
|
||||||
|
0x16, /* bLength */
|
||||||
|
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||||
|
'2', 0x00, /* wcChar0 */
|
||||||
|
'0', 0x00, /* wcChar1 */
|
||||||
|
'2', 0x00, /* wcChar2 */
|
||||||
|
'1', 0x00, /* wcChar3 */
|
||||||
|
'1', 0x00, /* wcChar4 */
|
||||||
|
'2', 0x00, /* wcChar5 */
|
||||||
|
'3', 0x00, /* wcChar6 */
|
||||||
|
'4', 0x00, /* wcChar7 */
|
||||||
|
'5', 0x00, /* wcChar8 */
|
||||||
|
'6', 0x00, /* wcChar9 */
|
||||||
|
///////////////////////////////////////
|
||||||
|
/// string4 descriptor
|
||||||
|
///////////////////////////////////////
|
||||||
|
0x30, /* bLength */
|
||||||
|
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||||
|
'C', 0x00, /* wcChar0 */
|
||||||
|
'h', 0x00, /* wcChar1 */
|
||||||
|
'e', 0x00, /* wcChar2 */
|
||||||
|
'r', 0x00, /* wcChar3 */
|
||||||
|
'r', 0x00, /* wcChar4 */
|
||||||
|
'y', 0x00, /* wcChar5 */
|
||||||
|
'U', 0x00, /* wcChar6 */
|
||||||
|
'S', 0x00, /* wcChar7 */
|
||||||
|
'B', 0x00, /* wcChar8 */
|
||||||
|
' ', 0x00, /* wcChar9 */
|
||||||
|
'W', 0x00, /* wcChar10 */
|
||||||
|
'I', 0x00, /* wcChar11 */
|
||||||
|
'N', 0x00, /* wcChar12 */
|
||||||
|
'U', 0x00, /* wcChar13 */
|
||||||
|
'S', 0x00, /* wcChar14 */
|
||||||
|
'B', 0x00, /* wcChar15 */
|
||||||
|
' ', 0x00, /* wcChar16 */
|
||||||
|
'D', 0x00, /* wcChar17 */
|
||||||
|
'E', 0x00, /* wcChar18 */
|
||||||
|
'M', 0x00, /* wcChar19 */
|
||||||
|
'O', 0x00, /* wcChar20 */
|
||||||
|
' ', 0x00, /* wcChar16 */
|
||||||
|
'1', 0x00, /* wcChar21 */
|
||||||
|
///////////////////////////////////////
|
||||||
|
/// string5 descriptor
|
||||||
|
///////////////////////////////////////
|
||||||
|
0x30, /* bLength */
|
||||||
|
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||||
|
'C', 0x00, /* wcChar0 */
|
||||||
|
'h', 0x00, /* wcChar1 */
|
||||||
|
'e', 0x00, /* wcChar2 */
|
||||||
|
'r', 0x00, /* wcChar3 */
|
||||||
|
'r', 0x00, /* wcChar4 */
|
||||||
|
'y', 0x00, /* wcChar5 */
|
||||||
|
'U', 0x00, /* wcChar6 */
|
||||||
|
'S', 0x00, /* wcChar7 */
|
||||||
|
'B', 0x00, /* wcChar8 */
|
||||||
|
' ', 0x00, /* wcChar9 */
|
||||||
|
'W', 0x00, /* wcChar10 */
|
||||||
|
'I', 0x00, /* wcChar11 */
|
||||||
|
'N', 0x00, /* wcChar12 */
|
||||||
|
'U', 0x00, /* wcChar13 */
|
||||||
|
'S', 0x00, /* wcChar14 */
|
||||||
|
'B', 0x00, /* wcChar15 */
|
||||||
|
' ', 0x00, /* wcChar16 */
|
||||||
|
'D', 0x00, /* wcChar17 */
|
||||||
|
'E', 0x00, /* wcChar18 */
|
||||||
|
'M', 0x00, /* wcChar19 */
|
||||||
|
'O', 0x00, /* wcChar20 */
|
||||||
|
' ', 0x00, /* wcChar16 */
|
||||||
|
'2', 0x00, /* wcChar21 */
|
||||||
|
#ifdef CONFIG_USB_HS
|
||||||
|
///////////////////////////////////////
|
||||||
|
/// device qualifier descriptor
|
||||||
|
///////////////////////////////////////
|
||||||
|
0x0a,
|
||||||
|
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||||
|
0x00,
|
||||||
|
0x02,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x40,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
#endif
|
||||||
|
0x00
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[2048];
|
||||||
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[2048];
|
||||||
|
|
||||||
|
volatile bool ep_tx_busy_flag = false;
|
||||||
|
|
||||||
|
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||||
|
{
|
||||||
|
switch (event) {
|
||||||
|
case USBD_EVENT_RESET:
|
||||||
|
break;
|
||||||
|
case USBD_EVENT_CONNECTED:
|
||||||
|
break;
|
||||||
|
case USBD_EVENT_DISCONNECTED:
|
||||||
|
break;
|
||||||
|
case USBD_EVENT_RESUME:
|
||||||
|
break;
|
||||||
|
case USBD_EVENT_SUSPEND:
|
||||||
|
break;
|
||||||
|
case USBD_EVENT_CONFIGURED:
|
||||||
|
ep_tx_busy_flag = false;
|
||||||
|
/* setup first out ep read transfer */
|
||||||
|
usbd_ep_start_read(busid, WINUSB_OUT_EP, read_buffer, 2048);
|
||||||
|
#if WINUSB_NUM == 2
|
||||||
|
usbd_ep_start_read(busid, WINUSB_OUT_EP2, read_buffer, 2048);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||||
|
break;
|
||||||
|
case USBD_EVENT_CLR_REMOTE_WAKEUP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void usbd_winusb_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||||
|
{
|
||||||
|
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
||||||
|
// for (int i = 0; i < 100; i++) {
|
||||||
|
// printf("%02x ", read_buffer[i]);
|
||||||
|
// }
|
||||||
|
// printf("\r\n");
|
||||||
|
usbd_ep_start_write(busid, WINUSB_IN_EP, read_buffer, nbytes);
|
||||||
|
/* setup next out ep read transfer */
|
||||||
|
usbd_ep_start_read(busid, WINUSB_OUT_EP, read_buffer, 2048);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usbd_winusb_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||||
|
{
|
||||||
|
USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
|
||||||
|
|
||||||
|
if ((nbytes % WINUSB_EP_MPS) == 0 && nbytes) {
|
||||||
|
/* send zlp */
|
||||||
|
usbd_ep_start_write(busid, WINUSB_IN_EP, NULL, 0);
|
||||||
|
} else {
|
||||||
|
ep_tx_busy_flag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct usbd_endpoint winusb_out_ep1 = {
|
||||||
|
.ep_addr = WINUSB_OUT_EP,
|
||||||
|
.ep_cb = usbd_winusb_out
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usbd_endpoint winusb_in_ep1 = {
|
||||||
|
.ep_addr = WINUSB_IN_EP,
|
||||||
|
.ep_cb = usbd_winusb_in
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usbd_interface intf0;
|
||||||
|
|
||||||
|
#if WINUSB_NUM == 2
|
||||||
|
|
||||||
|
void usbd_winusb_out2(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||||
|
{
|
||||||
|
USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes);
|
||||||
|
// for (int i = 0; i < 100; i++) {
|
||||||
|
// printf("%02x ", read_buffer[i]);
|
||||||
|
// }
|
||||||
|
// printf("\r\n");
|
||||||
|
usbd_ep_start_write(busid, WINUSB_IN_EP2, read_buffer, nbytes);
|
||||||
|
/* setup next out ep read transfer */
|
||||||
|
usbd_ep_start_read(busid, WINUSB_OUT_EP2, read_buffer, 2048);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usbd_winusb_in2(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||||
|
{
|
||||||
|
USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes);
|
||||||
|
|
||||||
|
if ((nbytes % usbd_get_ep_mps(busid, ep)) == 0 && nbytes) {
|
||||||
|
/* send zlp */
|
||||||
|
usbd_ep_start_write(busid, WINUSB_IN_EP2, NULL, 0);
|
||||||
|
} else {
|
||||||
|
ep_tx_busy_flag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct usbd_endpoint winusb_out_ep2 = {
|
||||||
|
.ep_addr = WINUSB_OUT_EP2,
|
||||||
|
.ep_cb = usbd_winusb_out2
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usbd_endpoint winusb_in_ep2 = {
|
||||||
|
.ep_addr = WINUSB_IN_EP2,
|
||||||
|
.ep_cb = usbd_winusb_in2
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usbd_interface intf1;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void winusbv2_init(uint8_t busid, uintptr_t reg_base)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
|
usbd_desc_register(busid, &winusbv2_descriptor);
|
||||||
|
#else
|
||||||
|
usbd_desc_register(busid, winusbv2_descriptor);
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_USBDEV_ADVANCE_DESC
|
||||||
|
usbd_bos_desc_register(busid, &bos_desc);
|
||||||
|
usbd_msosv2_desc_register(busid, &msosv2_desc);
|
||||||
|
#endif
|
||||||
|
usbd_add_interface(busid, &intf0);
|
||||||
|
usbd_add_endpoint(busid, &winusb_out_ep1);
|
||||||
|
usbd_add_endpoint(busid, &winusb_in_ep1);
|
||||||
|
#if WINUSB_NUM == 2
|
||||||
|
usbd_add_interface(busid, &intf1);
|
||||||
|
usbd_add_endpoint(busid, &winusb_out_ep2);
|
||||||
|
usbd_add_endpoint(busid, &winusb_in_ep2);
|
||||||
|
#endif
|
||||||
|
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user