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