2 #include "stm32f1xx_hal.h"
9 #define DESC_U16(x) ((x) & 0xff), ((x) >> 8)
13 DESC_STR_MANUFACTURER,
16 DESC_STR_CONFIGURATION,
20 static const byte desc_device[] = {
22 USB_DESC_TYPE_DEVICE, // bDescriptorType
23 DESC_U16(0x0200), // bcdUSB
25 0x00, // bDeviceSubClass
26 0x00, // bDeviceProtocol
27 USB_MAX_EP0_SIZE, // bMaxPacketSize
28 DESC_U16(0x4242), // idVendor
29 DESC_U16(0x0001), // idProduct
30 DESC_U16(0x0200), // bcdDevice
31 DESC_STR_MANUFACTURER, // iManufacturer
32 DESC_STR_PRODUCT, // iProduct
33 DESC_STR_SERIAL, // iSerialNumber
34 USB_NUM_CONFIGURATIONS, // bNumConfigurations
37 static const byte desc_config[] = {
38 // Configuration descriptor
40 USB_DESC_TYPE_CONFIGURATION, // bDescriptorType
43 0x01, // bNumInterfaces
44 0x01, // bConfigurationValue
45 DESC_STR_CONFIGURATION, // iConfiguration
46 0xc0, // bmAttributes: bus-powered, supports remote wakeup
47 0x32, // Max power: 100 mA
48 // Interface descriptor
50 USB_DESC_TYPE_INTERFACE, // bDescriptorType
51 0x00, // bInterfaceNumber
52 0x00, // bAlternateSetting
53 0x02, // bNumEndpoints
54 0xff, // bInterfaceClass: vendor-defined
55 0x00, // bInterfaceSubClass
56 0x00, // nInterfaceProtocol
57 DESC_STR_INTERFACE, // iInterface
58 // End-point descriptor
60 USB_DESC_TYPE_ENDPOINT, // bDescriptorType
61 0x01, // bEndpointAddress
62 USB_EP_TYPE_BULK, // bmAttributes
63 0x40, 0x00, // wMaxPacketSize
64 0x00, // bInterval: unused
65 // End-point descriptor
67 USB_DESC_TYPE_ENDPOINT, // bDescriptorType
68 0x81, // bEndpointAddress
69 USB_EP_TYPE_BULK, // bmAttributes
70 0x40, 0x00, // wMaxPacketSize
71 0x00, // bInterval: unused
74 static const char * const desc_string[] = {
75 NULL, // DESC_STR_NONE
76 "United Computer Wizards", // DESC_STR_MANUFACTURER
77 "Mysterious Gadget", // DESC_STR_PRODUCT
78 "00000042", // DESC_STR_SERIAL
79 "Default Configuration", // DESC_STR_CONFIGURATION
80 "Default Interface", // DESC_STR_INTERFACE
83 static const byte desc_languages[] = {
85 USB_DESC_TYPE_STRING, // bDescriptorType
86 DESC_U16(1033), // English
91 void usb_dev_reset(struct usb *usb)
93 usb->desc_device = desc_device;
94 usb->desc_device_len = sizeof(desc_device);
95 usb->desc_config = desc_config;
96 usb->desc_config_len = sizeof(desc_config);
97 usb->desc_string = desc_string;
98 usb->desc_string_items = sizeof(desc_string) / sizeof(desc_string[0]);
99 usb->desc_languages = desc_languages;
100 usb->desc_languages_len = sizeof(desc_languages);
103 void usb_dev_configure(struct usb *usb)
107 void usb_dev_unconfigure(struct usb *usb)
111 bool usb_dev_setup_hook(struct usb *usb, struct setup_request *setup)
116 void usb_dev_ctl_recv_done(struct usb *usb)
120 void usb_dev_ctl_send_done(struct usb *usb)
124 void usb_dev_recv_done(struct usb *usb, byte epnum)
128 void usb_dev_send_done(struct usb *usb, byte epnum)