blob: 98f2830a0a695be0cc9016643454f6acbf2e1427 [file] [log] [blame]
Sylvain Munautbc9f5c42020-09-14 10:22:29 +02001/*
2 * usb_desc_app.c
3 *
4 * Copyright (C) 2019-2020 Sylvain Munaut <tnt@246tNt.com>
5 * SPDX-License-Identifier: GPL-3.0-or-later
6 */
7
8#include <no2usb/usb_proto.h>
9#include <no2usb/usb.h>
10
11#define NULL ((void*)0)
12#define num_elem(a) (sizeof(a) / sizeof(a[0]))
13
14
15static const struct {
16 /* Configuration */
17 struct usb_conf_desc conf;
18
19 /* E1 */
20 struct {
21 struct {
22 struct usb_intf_desc intf;
23 struct usb_ep_desc ep_data_in;
24 struct usb_ep_desc ep_data_out;
25 struct usb_ep_desc ep_fb;
26 } __attribute__ ((packed)) off;
27 struct {
28 struct usb_intf_desc intf;
29 struct usb_ep_desc ep_data_in;
30 struct usb_ep_desc ep_data_out;
31 struct usb_ep_desc ep_fb;
32 } __attribute__ ((packed)) on;
33 } __attribute__ ((packed)) e1;
34
35 /* CDC */
36#if 0
37 struct {
38 struct usb_intf_desc intf_ctl;
39 struct usb_cs_intf_hdr_desc cs_intf_hdr;
40 struct usb_cs_intf_acm_desc cs_intf_acm;
41 struct usb_cs_intf_union_desc cs_intf_union;
42 uint8_t cs_intf_union_slave;
43 struct usb_ep_desc ep_ctl;
44 struct usb_intf_desc intf_data;
45 struct usb_ep_desc ep_data_out;
46 struct usb_ep_desc ep_data_in;
47 } __attribute__ ((packed)) cdc;
48#endif
49
50 /* DFU Runtime */
51 struct {
52 struct usb_intf_desc intf;
53 struct usb_dfu_desc func;
54 } __attribute__ ((packed)) dfu;
55} __attribute__ ((packed)) _app_conf_desc = {
56 .conf = {
57 .bLength = sizeof(struct usb_conf_desc),
58 .bDescriptorType = USB_DT_CONF,
59 .wTotalLength = sizeof(_app_conf_desc),
60#if 0
61 .bNumInterfaces = 4,
62#else
63 .bNumInterfaces = 2,
64#endif
65 .bConfigurationValue = 1,
66 .iConfiguration = 4,
67 .bmAttributes = 0x80,
68 .bMaxPower = 0x32, /* 100 mA */
69 },
70 .e1 = {
71 .off = {
72 .intf = {
73 .bLength = sizeof(struct usb_intf_desc),
74 .bDescriptorType = USB_DT_INTF,
75 .bInterfaceNumber = 0,
76 .bAlternateSetting = 0,
77 .bNumEndpoints = 3,
78 .bInterfaceClass = 0xff,
79 .bInterfaceSubClass = 0xe1,
80 .bInterfaceProtocol = 0x00,
81 .iInterface = 5,
82 },
83 .ep_data_in = {
84 .bLength = sizeof(struct usb_ep_desc),
85 .bDescriptorType = USB_DT_EP,
86 .bEndpointAddress = 0x82,
87 .bmAttributes = 0x05,
88 .wMaxPacketSize = 0,
89 .bInterval = 1,
90 },
91 .ep_data_out = {
92 .bLength = sizeof(struct usb_ep_desc),
93 .bDescriptorType = USB_DT_EP,
94 .bEndpointAddress = 0x01,
95 .bmAttributes = 0x05,
96 .wMaxPacketSize = 0,
97 .bInterval = 1,
98 },
99 .ep_fb = {
100 .bLength = sizeof(struct usb_ep_desc),
101 .bDescriptorType = USB_DT_EP,
102 .bEndpointAddress = 0x81,
103 .bmAttributes = 0x11,
104 .wMaxPacketSize = 0,
105 .bInterval = 3,
106 },
107 },
108 .on = {
109 .intf = {
110 .bLength = sizeof(struct usb_intf_desc),
111 .bDescriptorType = USB_DT_INTF,
112 .bInterfaceNumber = 0,
113 .bAlternateSetting = 1,
114 .bNumEndpoints = 3,
115 .bInterfaceClass = 0xff,
116 .bInterfaceSubClass = 0xe1,
117 .bInterfaceProtocol = 0x00,
118 .iInterface = 5,
119 },
120 .ep_data_in = {
121 .bLength = sizeof(struct usb_ep_desc),
122 .bDescriptorType = USB_DT_EP,
123 .bEndpointAddress = 0x82,
124 .bmAttributes = 0x05,
125 .wMaxPacketSize = 388,
126 .bInterval = 1,
127 },
128 .ep_data_out = {
129 .bLength = sizeof(struct usb_ep_desc),
130 .bDescriptorType = USB_DT_EP,
131 .bEndpointAddress = 0x01,
132 .bmAttributes = 0x05,
133 .wMaxPacketSize = 388,
134 .bInterval = 1,
135 },
136 .ep_fb = {
137 .bLength = sizeof(struct usb_ep_desc),
138 .bDescriptorType = USB_DT_EP,
139 .bEndpointAddress = 0x81,
140 .bmAttributes = 0x11,
141 .wMaxPacketSize = 8,
142 .bInterval = 3,
143 },
144 },
145 },
146#if 0
147 .cdc = {
148 .intf_ctl = {
149 .bLength = sizeof(struct usb_intf_desc),
150 .bDescriptorType = USB_DT_INTF,
151 .bInterfaceNumber = 1,
152 .bAlternateSetting = 0,
153 .bNumEndpoints = 1,
154 .bInterfaceClass = 0x02,
155 .bInterfaceSubClass = 0x02,
156 .bInterfaceProtocol = 0x00,
157 .iInterface = 6,
158 },
159 .cs_intf_hdr = {
160 .bLength = sizeof(struct usb_cs_intf_hdr_desc),
161 .bDescriptorType = USB_DT_CS_INTF,
162 .bDescriptorsubtype = 0x00,
163 .bcdCDC = 0x0110,
164 },
165 .cs_intf_acm = {
166 .bLength = sizeof(struct usb_cs_intf_acm_desc),
167 .bDescriptorType = USB_DT_CS_INTF,
168 .bDescriptorsubtype = 0x02,
169 .bmCapabilities = 0x02,
170 },
171 .cs_intf_union = {
172 .bLength = sizeof(struct usb_cs_intf_union_desc) + 1,
173 .bDescriptorType = USB_DT_CS_INTF,
174 .bDescriptorsubtype = 0x06,
175 .bMasterInterface = 1,
176 },
177 .cs_intf_union_slave = 2,
178 .ep_ctl = {
179 .bLength = sizeof(struct usb_ep_desc),
180 .bDescriptorType = USB_DT_EP,
181 .bEndpointAddress = 0x84,
182 .bmAttributes = 0x03,
183 .wMaxPacketSize = 64,
184 .bInterval = 0x40,
185 },
186 .intf_data = {
187 .bLength = sizeof(struct usb_intf_desc),
188 .bDescriptorType = USB_DT_INTF,
189 .bInterfaceNumber = 2,
190 .bAlternateSetting = 0,
191 .bNumEndpoints = 2,
192 .bInterfaceClass = 0x0a,
193 .bInterfaceSubClass = 0x00,
194 .bInterfaceProtocol = 0x00,
195 .iInterface = 7,
196 },
197 .ep_data_out = {
198 .bLength = sizeof(struct usb_ep_desc),
199 .bDescriptorType = USB_DT_EP,
200 .bEndpointAddress = 0x05,
201 .bmAttributes = 0x02,
202 .wMaxPacketSize = 64,
203 .bInterval = 0x00,
204 },
205 .ep_data_in = {
206 .bLength = sizeof(struct usb_ep_desc),
207 .bDescriptorType = USB_DT_EP,
208 .bEndpointAddress = 0x85,
209 .bmAttributes = 0x02,
210 .wMaxPacketSize = 64,
211 .bInterval = 0x00,
212 },
213 },
214#endif
215 .dfu = {
216 .intf = {
217 .bLength = sizeof(struct usb_intf_desc),
218 .bDescriptorType = USB_DT_INTF,
219#if 0
220 .bInterfaceNumber = 3,
221#else
222 .bInterfaceNumber = 1,
223#endif
224 .bAlternateSetting = 0,
225 .bNumEndpoints = 0,
226 .bInterfaceClass = 0xfe,
227 .bInterfaceSubClass = 0x01,
228 .bInterfaceProtocol = 0x01,
229 .iInterface = 8,
230 },
231 .func = {
232 .bLength = sizeof(struct usb_dfu_desc),
233 .bDescriptorType = USB_DT_DFU,
234 .bmAttributes = 0x0d,
235 .wDetachTimeOut = 1000,
236 .wTransferSize = 4096,
237 .bcdDFUVersion = 0x0101,
238 },
239 },
240};
241
242static const struct usb_conf_desc * const _conf_desc_array[] = {
243 &_app_conf_desc.conf,
244};
245
246static const struct usb_dev_desc _dev_desc = {
247 .bLength = sizeof(struct usb_dev_desc),
248 .bDescriptorType = USB_DT_DEV,
249 .bcdUSB = 0x0200,
250 .bDeviceClass = 0,
251 .bDeviceSubClass = 0,
252 .bDeviceProtocol = 0,
253 .bMaxPacketSize0 = 64,
254 .idVendor = 0x1d50,
255 .idProduct = 0x6145,
256 .bcdDevice = 0x0003, /* v0.3 */
257 .iManufacturer = 2,
258 .iProduct = 3,
259 .iSerialNumber = 1,
260 .bNumConfigurations = num_elem(_conf_desc_array),
261};
262
263#include "usb_str_app.gen.h"
264
265const struct usb_stack_descriptors app_stack_desc = {
266 .dev = &_dev_desc,
267 .conf = _conf_desc_array,
268 .n_conf = num_elem(_conf_desc_array),
269 .str = _str_desc_array,
270 .n_str = num_elem(_str_desc_array),
271};