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