summaryrefslogtreecommitdiff
path: root/digital/ucoolib/ucoolib/hal/usb/usb_desc.stm32.c
blob: 51e6ea13ff14d47e50d156d3210aa6382368d3da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* ucoolib - Microcontroller object oriented library. {{{
 *
 * Copyright (C) 2012 Nicolas Schodet
 *
 * APBTeam:
 *        Web: http://apbteam.org/
 *      Email: team AT apbteam DOT org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * }}} */
#include "usb_desc.stm32.h"

#include "config/hal/usb.hh"

const struct usb_device_descriptor usb_desc_dev = {
    .bLength = USB_DT_DEVICE_SIZE,
    .bDescriptorType = USB_DT_DEVICE,
    .bcdUSB = 0x0200,
    .bDeviceClass = 0xff,
    .bDeviceSubClass = 0,
    .bDeviceProtocol = 0,
    .bMaxPacketSize0 = 64,
    .idVendor = UCOO_CONFIG_HAL_USB_VENDOR_ID,
    .idProduct = UCOO_CONFIG_HAL_USB_PRODUCT_ID,
    .bcdDevice = 0x0000,
    .iManufacturer = 1,
    .iProduct = 2,
    .iSerialNumber = 0,
    .bNumConfigurations = 1,
};

static const struct usb_endpoint_descriptor usb_desc_endp_1[] = {
    {
	.bLength = USB_DT_ENDPOINT_SIZE,
	.bDescriptorType = USB_DT_ENDPOINT,
	.bEndpointAddress = 0x01,
	.bmAttributes = USB_ENDPOINT_ATTR_BULK,
	.wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
	.bInterval = 0,
    },
    {
	.bLength = USB_DT_ENDPOINT_SIZE,
	.bDescriptorType = USB_DT_ENDPOINT,
	.bEndpointAddress = 0x81,
	.bmAttributes = USB_ENDPOINT_ATTR_BULK,
	.wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
	.bInterval = 0,
    },
};

static const struct usb_interface_descriptor usb_desc_iface_1[] = {
    {
	.bLength = USB_DT_INTERFACE_SIZE,
	.bDescriptorType = USB_DT_INTERFACE,
	.bInterfaceNumber = 0,
	.bAlternateSetting = 0,
	.bNumEndpoints = 2,
	.bInterfaceClass = 0xff,
	.bInterfaceSubClass = 0,
	.bInterfaceProtocol = 0,
	.iInterface = 0,

	.endpoint = usb_desc_endp_1,
    },
};

#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 2

static const struct usb_endpoint_descriptor usb_desc_endp_2[] = {
    {
	.bLength = USB_DT_ENDPOINT_SIZE,
	.bDescriptorType = USB_DT_ENDPOINT,
	.bEndpointAddress = 0x02,
	.bmAttributes = USB_ENDPOINT_ATTR_BULK,
	.wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
	.bInterval = 0,
    },
    {
	.bLength = USB_DT_ENDPOINT_SIZE,
	.bDescriptorType = USB_DT_ENDPOINT,
	.bEndpointAddress = 0x82,
	.bmAttributes = USB_ENDPOINT_ATTR_BULK,
	.wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
	.bInterval = 0,
    },
};

static const struct usb_interface_descriptor usb_desc_iface_2[] = {
    {
	.bLength = USB_DT_INTERFACE_SIZE,
	.bDescriptorType = USB_DT_INTERFACE,
	.bInterfaceNumber = 1,
	.bAlternateSetting = 0,
	.bNumEndpoints = 2,
	.bInterfaceClass = 0xff,
	.bInterfaceSubClass = 0,
	.bInterfaceProtocol = 0,
	.iInterface = 0,

	.endpoint = usb_desc_endp_2,
    },
};

#endif /* UCOO_CONFIG_HAL_USB_STREAM_NB >= 2 */

#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 3

static const struct usb_endpoint_descriptor usb_desc_endp_3[] = {
    {
	.bLength = USB_DT_ENDPOINT_SIZE,
	.bDescriptorType = USB_DT_ENDPOINT,
	.bEndpointAddress = 0x03,
	.bmAttributes = USB_ENDPOINT_ATTR_BULK,
	.wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
	.bInterval = 0,
    },
    {
	.bLength = USB_DT_ENDPOINT_SIZE,
	.bDescriptorType = USB_DT_ENDPOINT,
	.bEndpointAddress = 0x83,
	.bmAttributes = USB_ENDPOINT_ATTR_BULK,
	.wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
	.bInterval = 0,
    },
};

static const struct usb_interface_descriptor usb_desc_iface_3[] = {
    {
	.bLength = USB_DT_INTERFACE_SIZE,
	.bDescriptorType = USB_DT_INTERFACE,
	.bInterfaceNumber = 2,
	.bAlternateSetting = 0,
	.bNumEndpoints = 2,
	.bInterfaceClass = 0xff,
	.bInterfaceSubClass = 0,
	.bInterfaceProtocol = 0,
	.iInterface = 0,

	.endpoint = usb_desc_endp_3,
    },
};

#endif /* UCOO_CONFIG_HAL_USB_STREAM_NB >= 3 */

#if UCOO_CONFIG_HAL_USB_STREAM_NB > 3
# error "too many streams requested"
#endif

static const struct usb_interface usb_desc_ifaces[] = {
    {
	.num_altsetting = 1,
	.altsetting = usb_desc_iface_1,
    },
#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 2
    {
	.num_altsetting = 1,
	.altsetting = usb_desc_iface_2,
    },
#endif
#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 3
    {
	.num_altsetting = 1,
	.altsetting = usb_desc_iface_3,
    },
#endif
};

const struct usb_config_descriptor usb_desc_config = {
    .bLength = USB_DT_CONFIGURATION_SIZE,
    .bDescriptorType = USB_DT_CONFIGURATION,
    .wTotalLength = 0,
    .bNumInterfaces = UCOO_CONFIG_HAL_USB_STREAM_NB,
    .bConfigurationValue = 1,
    .iConfiguration = 0,
    .bmAttributes = 0x80 | (UCOO_CONFIG_HAL_USB_SELF_POWERED ? 0x40 : 0),
    .bMaxPower = UCOO_CONFIG_HAL_USB_MAX_POWER / 2,

    .interface = usb_desc_ifaces,
};