blob: 153d70ed54509e9eb8e1d25131bfd35595f7441b [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>
Sylvain Munaut4ea7d272020-10-29 13:17:11 +01009#include <no2usb/usb_dfu_proto.h>
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020010#include <no2usb/usb.h>
11
12#define NULL ((void*)0)
13#define num_elem(a) (sizeof(a) / sizeof(a[0]))
14
15
16static const struct {
17 /* Configuration */
18 struct usb_conf_desc conf;
19
20 /* E1 */
21 struct {
Harald Welte30fc5602020-12-14 15:56:28 +010022 /* Two altsettings are required, as isochronous
23 * interfaces must have a setting where they don't
24 * transceive any data. wMaxPacketSize is 0 for
25 * all endpoints in the 'off' altsetting */
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020026 struct {
27 struct usb_intf_desc intf;
28 struct usb_ep_desc ep_data_in;
29 struct usb_ep_desc ep_data_out;
30 struct usb_ep_desc ep_fb;
Harald Welte805f2cf2020-12-14 17:31:03 +010031 struct usb_ep_desc ep_interrupt;
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020032 } __attribute__ ((packed)) off;
33 struct {
34 struct usb_intf_desc intf;
35 struct usb_ep_desc ep_data_in;
36 struct usb_ep_desc ep_data_out;
37 struct usb_ep_desc ep_fb;
Harald Welte805f2cf2020-12-14 17:31:03 +010038 struct usb_ep_desc ep_interrupt;
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020039 } __attribute__ ((packed)) on;
40 } __attribute__ ((packed)) e1;
41
42 /* CDC */
43#if 0
44 struct {
45 struct usb_intf_desc intf_ctl;
46 struct usb_cs_intf_hdr_desc cs_intf_hdr;
47 struct usb_cs_intf_acm_desc cs_intf_acm;
48 struct usb_cs_intf_union_desc cs_intf_union;
49 uint8_t cs_intf_union_slave;
50 struct usb_ep_desc ep_ctl;
51 struct usb_intf_desc intf_data;
52 struct usb_ep_desc ep_data_out;
53 struct usb_ep_desc ep_data_in;
54 } __attribute__ ((packed)) cdc;
55#endif
56
57 /* DFU Runtime */
58 struct {
59 struct usb_intf_desc intf;
Sylvain Munaut4ea7d272020-10-29 13:17:11 +010060 struct usb_dfu_func_desc func;
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020061 } __attribute__ ((packed)) dfu;
62} __attribute__ ((packed)) _app_conf_desc = {
63 .conf = {
64 .bLength = sizeof(struct usb_conf_desc),
65 .bDescriptorType = USB_DT_CONF,
66 .wTotalLength = sizeof(_app_conf_desc),
67#if 0
68 .bNumInterfaces = 4,
69#else
70 .bNumInterfaces = 2,
71#endif
72 .bConfigurationValue = 1,
73 .iConfiguration = 4,
74 .bmAttributes = 0x80,
75 .bMaxPower = 0x32, /* 100 mA */
76 },
77 .e1 = {
78 .off = {
79 .intf = {
80 .bLength = sizeof(struct usb_intf_desc),
81 .bDescriptorType = USB_DT_INTF,
82 .bInterfaceNumber = 0,
83 .bAlternateSetting = 0,
Harald Welte805f2cf2020-12-14 17:31:03 +010084 .bNumEndpoints = 4,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +020085 .bInterfaceClass = 0xff,
86 .bInterfaceSubClass = 0xe1,
87 .bInterfaceProtocol = 0x00,
88 .iInterface = 5,
89 },
90 .ep_data_in = {
91 .bLength = sizeof(struct usb_ep_desc),
92 .bDescriptorType = USB_DT_EP,
93 .bEndpointAddress = 0x82,
94 .bmAttributes = 0x05,
95 .wMaxPacketSize = 0,
96 .bInterval = 1,
97 },
98 .ep_data_out = {
99 .bLength = sizeof(struct usb_ep_desc),
100 .bDescriptorType = USB_DT_EP,
101 .bEndpointAddress = 0x01,
102 .bmAttributes = 0x05,
103 .wMaxPacketSize = 0,
104 .bInterval = 1,
105 },
106 .ep_fb = {
107 .bLength = sizeof(struct usb_ep_desc),
108 .bDescriptorType = USB_DT_EP,
109 .bEndpointAddress = 0x81,
110 .bmAttributes = 0x11,
111 .wMaxPacketSize = 0,
112 .bInterval = 3,
113 },
Harald Welte805f2cf2020-12-14 17:31:03 +0100114 .ep_interrupt = {
115 .bLength = sizeof(struct usb_ep_desc),
116 .bDescriptorType = USB_DT_EP,
117 .bEndpointAddress = 0x83,
118 .bmAttributes = 0x03,
119 .wMaxPacketSize = 10,
120 .bInterval = 3,
121 },
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200122 },
123 .on = {
124 .intf = {
125 .bLength = sizeof(struct usb_intf_desc),
126 .bDescriptorType = USB_DT_INTF,
127 .bInterfaceNumber = 0,
128 .bAlternateSetting = 1,
Harald Welte805f2cf2020-12-14 17:31:03 +0100129 .bNumEndpoints = 4,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200130 .bInterfaceClass = 0xff,
131 .bInterfaceSubClass = 0xe1,
132 .bInterfaceProtocol = 0x00,
133 .iInterface = 5,
134 },
135 .ep_data_in = {
136 .bLength = sizeof(struct usb_ep_desc),
137 .bDescriptorType = USB_DT_EP,
138 .bEndpointAddress = 0x82,
139 .bmAttributes = 0x05,
140 .wMaxPacketSize = 388,
141 .bInterval = 1,
142 },
143 .ep_data_out = {
144 .bLength = sizeof(struct usb_ep_desc),
145 .bDescriptorType = USB_DT_EP,
146 .bEndpointAddress = 0x01,
147 .bmAttributes = 0x05,
148 .wMaxPacketSize = 388,
149 .bInterval = 1,
150 },
151 .ep_fb = {
152 .bLength = sizeof(struct usb_ep_desc),
153 .bDescriptorType = USB_DT_EP,
154 .bEndpointAddress = 0x81,
155 .bmAttributes = 0x11,
156 .wMaxPacketSize = 8,
157 .bInterval = 3,
158 },
Harald Welte805f2cf2020-12-14 17:31:03 +0100159 .ep_interrupt = {
160 .bLength = sizeof(struct usb_ep_desc),
161 .bDescriptorType = USB_DT_EP,
162 .bEndpointAddress = 0x83,
163 .bmAttributes = 0x03,
164 .wMaxPacketSize = 10,
165 .bInterval = 3,
166 },
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200167 },
168 },
169#if 0
170 .cdc = {
171 .intf_ctl = {
172 .bLength = sizeof(struct usb_intf_desc),
173 .bDescriptorType = USB_DT_INTF,
174 .bInterfaceNumber = 1,
175 .bAlternateSetting = 0,
176 .bNumEndpoints = 1,
177 .bInterfaceClass = 0x02,
178 .bInterfaceSubClass = 0x02,
179 .bInterfaceProtocol = 0x00,
180 .iInterface = 6,
181 },
182 .cs_intf_hdr = {
183 .bLength = sizeof(struct usb_cs_intf_hdr_desc),
184 .bDescriptorType = USB_DT_CS_INTF,
185 .bDescriptorsubtype = 0x00,
186 .bcdCDC = 0x0110,
187 },
188 .cs_intf_acm = {
189 .bLength = sizeof(struct usb_cs_intf_acm_desc),
190 .bDescriptorType = USB_DT_CS_INTF,
191 .bDescriptorsubtype = 0x02,
192 .bmCapabilities = 0x02,
193 },
194 .cs_intf_union = {
195 .bLength = sizeof(struct usb_cs_intf_union_desc) + 1,
196 .bDescriptorType = USB_DT_CS_INTF,
197 .bDescriptorsubtype = 0x06,
198 .bMasterInterface = 1,
199 },
200 .cs_intf_union_slave = 2,
201 .ep_ctl = {
202 .bLength = sizeof(struct usb_ep_desc),
203 .bDescriptorType = USB_DT_EP,
204 .bEndpointAddress = 0x84,
205 .bmAttributes = 0x03,
206 .wMaxPacketSize = 64,
207 .bInterval = 0x40,
208 },
209 .intf_data = {
210 .bLength = sizeof(struct usb_intf_desc),
211 .bDescriptorType = USB_DT_INTF,
212 .bInterfaceNumber = 2,
213 .bAlternateSetting = 0,
214 .bNumEndpoints = 2,
215 .bInterfaceClass = 0x0a,
216 .bInterfaceSubClass = 0x00,
217 .bInterfaceProtocol = 0x00,
218 .iInterface = 7,
219 },
220 .ep_data_out = {
221 .bLength = sizeof(struct usb_ep_desc),
222 .bDescriptorType = USB_DT_EP,
223 .bEndpointAddress = 0x05,
224 .bmAttributes = 0x02,
225 .wMaxPacketSize = 64,
226 .bInterval = 0x00,
227 },
228 .ep_data_in = {
229 .bLength = sizeof(struct usb_ep_desc),
230 .bDescriptorType = USB_DT_EP,
231 .bEndpointAddress = 0x85,
232 .bmAttributes = 0x02,
233 .wMaxPacketSize = 64,
234 .bInterval = 0x00,
235 },
236 },
237#endif
238 .dfu = {
239 .intf = {
240 .bLength = sizeof(struct usb_intf_desc),
241 .bDescriptorType = USB_DT_INTF,
242#if 0
243 .bInterfaceNumber = 3,
244#else
245 .bInterfaceNumber = 1,
246#endif
247 .bAlternateSetting = 0,
248 .bNumEndpoints = 0,
249 .bInterfaceClass = 0xfe,
250 .bInterfaceSubClass = 0x01,
251 .bInterfaceProtocol = 0x01,
252 .iInterface = 8,
253 },
254 .func = {
Sylvain Munaut4ea7d272020-10-29 13:17:11 +0100255 .bLength = sizeof(struct usb_dfu_func_desc),
256 .bDescriptorType = USB_DFU_DT_FUNC,
Sylvain Munautbc9f5c42020-09-14 10:22:29 +0200257 .bmAttributes = 0x0d,
258 .wDetachTimeOut = 1000,
259 .wTransferSize = 4096,
260 .bcdDFUVersion = 0x0101,
261 },
262 },
263};
264
265static const struct usb_conf_desc * const _conf_desc_array[] = {
266 &_app_conf_desc.conf,
267};
268
269static const struct usb_dev_desc _dev_desc = {
270 .bLength = sizeof(struct usb_dev_desc),
271 .bDescriptorType = USB_DT_DEV,
272 .bcdUSB = 0x0200,
273 .bDeviceClass = 0,
274 .bDeviceSubClass = 0,
275 .bDeviceProtocol = 0,
276 .bMaxPacketSize0 = 64,
277 .idVendor = 0x1d50,
278 .idProduct = 0x6145,
279 .bcdDevice = 0x0003, /* v0.3 */
280 .iManufacturer = 2,
281 .iProduct = 3,
282 .iSerialNumber = 1,
283 .bNumConfigurations = num_elem(_conf_desc_array),
284};
285
286#include "usb_str_app.gen.h"
287
288const struct usb_stack_descriptors app_stack_desc = {
289 .dev = &_dev_desc,
290 .conf = _conf_desc_array,
291 .n_conf = num_elem(_conf_desc_array),
292 .str = _str_desc_array,
293 .n_str = num_elem(_str_desc_array),
294};