blob: 5109000416131c8bc91b887c3281bf2d63f807ac [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
Sylvain Munautf5d7bf22020-09-14 10:23:50 +020034 /* DFU Runtime */
35 struct {
36 struct usb_intf_desc intf;
Sylvain Munaut4ea7d272020-10-29 13:17:11 +010037 struct usb_dfu_func_desc func;
Sylvain Munautf5d7bf22020-09-14 10:23:50 +020038 } __attribute__ ((packed)) dfu;
39} __attribute__ ((packed)) _app_conf_desc = {
40 .conf = {
41 .bLength = sizeof(struct usb_conf_desc),
42 .bDescriptorType = USB_DT_CONF,
43 .wTotalLength = sizeof(_app_conf_desc),
Sylvain Munautf5d7bf22020-09-14 10:23:50 +020044 .bNumInterfaces = 2,
Sylvain Munautf5d7bf22020-09-14 10:23:50 +020045 .bConfigurationValue = 1,
46 .iConfiguration = 4,
47 .bmAttributes = 0x80,
48 .bMaxPower = 0x32, /* 100 mA */
49 },
50 .e1 = {
51 .off = {
52 .intf = {
53 .bLength = sizeof(struct usb_intf_desc),
54 .bDescriptorType = USB_DT_INTF,
55 .bInterfaceNumber = 0,
56 .bAlternateSetting = 0,
57 .bNumEndpoints = 2,
58 .bInterfaceClass = 0xff,
59 .bInterfaceSubClass = 0xe1,
60 .bInterfaceProtocol = 0x00,
61 .iInterface = 5,
62 },
63 .ep_data_in0 = {
64 .bLength = sizeof(struct usb_ep_desc),
65 .bDescriptorType = USB_DT_EP,
66 .bEndpointAddress = 0x81,
67 .bmAttributes = 0x05,
68 .wMaxPacketSize = 0,
69 .bInterval = 1,
70 },
71 .ep_data_in1 = {
72 .bLength = sizeof(struct usb_ep_desc),
73 .bDescriptorType = USB_DT_EP,
74 .bEndpointAddress = 0x82,
75 .bmAttributes = 0x05,
76 .wMaxPacketSize = 0,
77 .bInterval = 1,
78 },
79 },
80 .on = {
81 .intf = {
82 .bLength = sizeof(struct usb_intf_desc),
83 .bDescriptorType = USB_DT_INTF,
84 .bInterfaceNumber = 0,
85 .bAlternateSetting = 1,
86 .bNumEndpoints = 2,
87 .bInterfaceClass = 0xff,
88 .bInterfaceSubClass = 0xe1,
89 .bInterfaceProtocol = 0x00,
90 .iInterface = 5,
91 },
92 .ep_data_in0 = {
93 .bLength = sizeof(struct usb_ep_desc),
94 .bDescriptorType = USB_DT_EP,
95 .bEndpointAddress = 0x81,
96 .bmAttributes = 0x05,
97 .wMaxPacketSize = 388,
98 .bInterval = 1,
99 },
100 .ep_data_in1 = {
101 .bLength = sizeof(struct usb_ep_desc),
102 .bDescriptorType = USB_DT_EP,
103 .bEndpointAddress = 0x82,
104 .bmAttributes = 0x05,
105 .wMaxPacketSize = 388,
106 .bInterval = 1,
107 },
108 },
109 },
Sylvain Munautf5d7bf22020-09-14 10:23:50 +0200110 .dfu = {
111 .intf = {
112 .bLength = sizeof(struct usb_intf_desc),
113 .bDescriptorType = USB_DT_INTF,
Sylvain Munautf5d7bf22020-09-14 10:23:50 +0200114 .bInterfaceNumber = 1,
Sylvain Munautf5d7bf22020-09-14 10:23:50 +0200115 .bAlternateSetting = 0,
116 .bNumEndpoints = 0,
117 .bInterfaceClass = 0xfe,
118 .bInterfaceSubClass = 0x01,
119 .bInterfaceProtocol = 0x01,
Sylvain Munautc704c072020-10-29 13:22:55 +0100120 .iInterface = 6,
Sylvain Munautf5d7bf22020-09-14 10:23:50 +0200121 },
122 .func = {
Sylvain Munaut4ea7d272020-10-29 13:17:11 +0100123 .bLength = sizeof(struct usb_dfu_func_desc),
124 .bDescriptorType = USB_DFU_DT_FUNC,
Sylvain Munautf5d7bf22020-09-14 10:23:50 +0200125 .bmAttributes = 0x0d,
126 .wDetachTimeOut = 1000,
127 .wTransferSize = 4096,
128 .bcdDFUVersion = 0x0101,
129 },
130 },
131};
132
133static const struct usb_conf_desc * const _conf_desc_array[] = {
134 &_app_conf_desc.conf,
135};
136
137static const struct usb_dev_desc _dev_desc = {
138 .bLength = sizeof(struct usb_dev_desc),
139 .bDescriptorType = USB_DT_DEV,
140 .bcdUSB = 0x0200,
141 .bDeviceClass = 0,
142 .bDeviceSubClass = 0,
143 .bDeviceProtocol = 0,
144 .bMaxPacketSize0 = 64,
145 .idVendor = 0x1d50,
146 .idProduct = 0x6151,
147 .bcdDevice = 2,
148 .iManufacturer = 2,
149 .iProduct = 3,
150 .iSerialNumber = 1,
151 .bNumConfigurations = num_elem(_conf_desc_array),
152};
153
154#include "usb_str_app.gen.h"
155
156const struct usb_stack_descriptors app_stack_desc = {
157 .dev = &_dev_desc,
158 .conf = _conf_desc_array,
159 .n_conf = num_elem(_conf_desc_array),
160 .str = _str_desc_array,
161 .n_str = num_elem(_str_desc_array),
162};