1 #include "usbd_core.h"
2 #include "usbd_mtp.h"
3
4 #define WCID_VENDOR_CODE 0x01
5
6 __ALIGN_BEGIN const uint8_t WCID_StringDescriptor_MSOS[18] __ALIGN_END = {
7 ///////////////////////////////////////
8 /// MS OS string descriptor
9 ///////////////////////////////////////
10 0x12, /* bLength */
11 USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
12 /* MSFT100 */
13 'M', 0x00, 'S', 0x00, 'F', 0x00, 'T', 0x00, /* wcChar_7 */
14 '1', 0x00, '0', 0x00, '0', 0x00, /* wcChar_7 */
15 WCID_VENDOR_CODE, /* bVendorCode */
16 0x00, /* bReserved */
17 };
18
19 __ALIGN_BEGIN const uint8_t WINUSB_WCIDDescriptor[40] __ALIGN_END = {
20 ///////////////////////////////////////
21 /// WCID descriptor
22 ///////////////////////////////////////
23 0x28, 0x00, 0x00, 0x00, /* dwLength */
24 0x00, 0x01, /* bcdVersion */
25 0x04, 0x00, /* wIndex */
26 0x01, /* bCount */
27 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* bReserved_7 */
28
29 ///////////////////////////////////////
30 /// WCID function descriptor
31 ///////////////////////////////////////
32 0x00, /* bFirstInterfaceNumber */
33 0x01, /* bReserved */
34 /* MTP */
35 'M', 'T', 'P', 0x00, 0x00, 0x00, 0x00, 0x00, /* cCID_8 */
36 /* */
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* cSubCID_8 */
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* bReserved_6 */
39 };
40
41 struct usb_msosv1_descriptor msosv1_desc = {
42 .string = (uint8_t *)WCID_StringDescriptor_MSOS,
43 .string_len = 18,
44 .vendor_code = WCID_VENDOR_CODE,
45 .compat_id = (uint8_t *)WINUSB_WCIDDescriptor,
46 .compat_id_len = sizeof(WINUSB_WCIDDescriptor),
47 .comp_id_property = NULL,
48 .comp_id_property_len = 0,
49 };
50
51 /*!< endpoint address */
52 #define CDC_IN_EP 0x81
53 #define CDC_OUT_EP 0x02
54 #define CDC_INT_EP 0x83
55
56 #define USBD_VID 0xFFFE
57 #define USBD_PID 0xFFFF
58 #define USBD_MAX_POWER 100
59 #define USBD_LANGID_STRING 1033
60
61 /*!< config descriptor size */
62 #define USB_CONFIG_SIZE (9 + MTP_DESCRIPTOR_LEN)
63
64 #ifdef CONFIG_USB_HS
65 #define MTP_MAX_MPS 512
66 #else
67 #define MTP_MAX_MPS 64
68 #endif
69
70 const uint8_t mtp_descriptor[] = {
71 USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0201, 0x01),
72 USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
73 MTP_DESCRIPTOR_INIT(0x00, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, MTP_MAX_MPS, 0x02),
74 ///////////////////////////////////////
75 /// string0 descriptor
76 ///////////////////////////////////////
77 USB_LANGID_INIT(USBD_LANGID_STRING),
78 ///////////////////////////////////////
79 /// string1 descriptor
80 ///////////////////////////////////////
81 0x14, /* bLength */
82 USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
83 'C', 0x00, /* wcChar0 */
84 'h', 0x00, /* wcChar1 */
85 'e', 0x00, /* wcChar2 */
86 'r', 0x00, /* wcChar3 */
87 'r', 0x00, /* wcChar4 */
88 'y', 0x00, /* wcChar5 */
89 'U', 0x00, /* wcChar6 */
90 'S', 0x00, /* wcChar7 */
91 'B', 0x00, /* wcChar8 */
92 ///////////////////////////////////////
93 /// string2 descriptor
94 ///////////////////////////////////////
95 0x26, /* bLength */
96 USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
97 'C', 0x00, /* wcChar0 */
98 'h', 0x00, /* wcChar1 */
99 'e', 0x00, /* wcChar2 */
100 'r', 0x00, /* wcChar3 */
101 'r', 0x00, /* wcChar4 */
102 'y', 0x00, /* wcChar5 */
103 'U', 0x00, /* wcChar6 */
104 'S', 0x00, /* wcChar7 */
105 'B', 0x00, /* wcChar8 */
106 ' ', 0x00, /* wcChar9 */
107 'M', 0x00, /* wcChar10 */
108 'T', 0x00, /* wcChar11 */
109 'P', 0x00, /* wcChar12 */
110 ' ', 0x00, /* wcChar13 */
111 'D', 0x00, /* wcChar14 */
112 'E', 0x00, /* wcChar15 */
113 'M', 0x00, /* wcChar16 */
114 'O', 0x00, /* wcChar17 */
115 ///////////////////////////////////////
116 /// string3 descriptor
117 ///////////////////////////////////////
118 0x16, /* bLength */
119 USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
120 '2', 0x00, /* wcChar0 */
121 '0', 0x00, /* wcChar1 */
122 '2', 0x00, /* wcChar2 */
123 '1', 0x00, /* wcChar3 */
124 '0', 0x00, /* wcChar4 */
125 '3', 0x00, /* wcChar5 */
126 '1', 0x00, /* wcChar6 */
127 '0', 0x00, /* wcChar7 */
128 '0', 0x00, /* wcChar8 */
129 '0', 0x00, /* wcChar9 */
130 #ifdef CONFIG_USB_HS
131 ///////////////////////////////////////
132 /// device qualifier descriptor
133 ///////////////////////////////////////
134 0x0a,
135 USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
136 0x00,
137 0x02,
138 0x02,
139 0x02,
140 0x01,
141 0x40,
142 0x01,
143 0x00,
144 #endif
145 0x00
146 };
147
148 const uint8_t bos_descriptor[] = {
149 0x05, 0x0f, 0x16, 0x00, 0x02,
150 0x07, 0x10, 0x02, 0x06, 0x00, 0x00, 0x00,
151 0x0a, 0x10, 0x03, 0x00, 0x0f, 0x00, 0x01, 0x01, 0xf4, 0x01
152 };
153
usbd_event_handler(uint8_t event)154 void usbd_event_handler(uint8_t event)
155 {
156 switch (event) {
157 case USBD_EVENT_RESET:
158 break;
159 case USBD_EVENT_CONNECTED:
160 break;
161 case USBD_EVENT_DISCONNECTED:
162 break;
163 case USBD_EVENT_RESUME:
164 break;
165 case USBD_EVENT_SUSPEND:
166 break;
167 case USBD_EVENT_CONFIGURED:
168 break;
169 case USBD_EVENT_SET_REMOTE_WAKEUP:
170 break;
171 case USBD_EVENT_CLR_REMOTE_WAKEUP:
172 break;
173
174 default:
175 break;
176 }
177 }
178
179 struct usbd_interface intf0;
180
181 struct usb_bos_descriptor bos_desc = {
182 .string = bos_descriptor,
183 .string_len = 22
184 };
185
mtp_init(void)186 void mtp_init(void)
187 {
188 usbd_desc_register(mtp_descriptor);
189 usbd_msosv1_desc_register(&msosv1_desc);
190 usbd_bos_desc_register(&bos_desc);
191 usbd_add_interface(usbd_mtp_init_intf(&intf0, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP));
192 usbd_initialize();
193 }