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