-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathusb.h
247 lines (221 loc) · 6.42 KB
/
usb.h
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
* Copyright (C) 2018 Koen Zandberg <koen@bergzand.net>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for
* more details.
*/
/**
* @defgroup usb USB
* @ingroup sys
* @brief Configuration defines for USB peripheral devices.
* @{
*
* @file
* @brief Definition of global compile time configuration options
*
* @author Koen Zandberg <koen@bergzand.net>
*/
#ifndef USB_H
#define USB_H
#ifdef __cplusplus
extern "C" {
#endif
#include "board.h"
/**
* @defgroup usb_conf USB peripheral compile time configurations
* @ingroup config
* @{
*/
/* These can be overridden by boards that should come up with their board
* supplier VID/PID pair. Boards should only override this if the RIOT built-in
* peripherals are compatible with whatever is usually shipped with that pair
* */
#ifndef INTERNAL_PERIPHERAL_VID
/** Reserved for RIOT standard peripherals as per http://pid.codes/1209/7D00/ */
#define INTERNAL_PERIPHERAL_VID (0x1209)
#endif
#ifndef INTERNAL_PERIPHERAL_PID
/** Reserved for RIOT standard peripherals as per http://pid.codes/1209/7D00/ */
#define INTERNAL_PERIPHERAL_PID (0x7D00)
#endif
#if !(defined(CONFIG_USB_VID) && defined(CONFIG_USB_PID))
#ifdef USB_H_USER_IS_RIOT_INTERNAL
#define CONFIG_USB_VID INTERNAL_PERIPHERAL_VID
#define CONFIG_USB_PID INTERNAL_PERIPHERAL_PID
#else
#error Please configure your vendor and product IDs. For development, you may \
set USB_VID=${USB_VID_TESTING} USB_PID=${USB_PID_TESTING}.
#endif
#endif
/**
* @brief USB peripheral device vendor ID
*
* @note You must provide your own VID/PID combination when manufacturing a
* device with USB.
*/
#ifdef DOXYGEN
#define CONFIG_USB_VID
#endif
/**
* @brief USB peripheral device product ID
*
* @note You must provide your own VID/PID combination when manufacturing a
* device with USB.
*/
#ifdef DOXYGEN
#define CONFIG_USB_PID
#endif
/**
* @brief USB peripheral manufacturer string
*/
#ifndef CONFIG_USB_MANUF_STR
#define CONFIG_USB_MANUF_STR "RIOT-os.org"
#endif
/**
* @brief USB peripheral product string
*/
#ifndef CONFIG_USB_PRODUCT_STR
#define CONFIG_USB_PRODUCT_STR RIOT_BOARD
#endif
/**
* @brief USB peripheral configuration string
*/
#ifndef CONFIG_USB_CONFIGURATION_STR
#define CONFIG_USB_CONFIGURATION_STR "USB config"
#endif
/**
* @brief USB peripheral serial string
*
* Compile-time value to override the serial string with. An LUID-based hex
* string is generated when this value is not used.
*
* This string does not have to be a number, but it must be unique between
* devices with identical VID:PID combination.
*/
#ifdef DOXYGEN
#define CONFIG_USB_SERIAL_STR "RIOT-12345"
#endif
/**
* @brief USB peripheral serial string length
*
* Maximum value is 63. Sensible values are between 8 to 32 depending on the
* number of expected devices.
*
* The length here is in bytes. The generated hex string is twice as many chars
* in length due to conversion from bytes to hex chars.
*/
#if !defined(CONFIG_USB_SERIAL_STR) && !defined(CONFIG_USB_SERIAL_BYTE_LENGTH)
#define CONFIG_USB_SERIAL_BYTE_LENGTH 8
#endif
/**
* @brief USB peripheral device version
*
* This is the version number of this peripheral
* @note Not to be be confused with the USB version number
*/
#ifndef CONFIG_USB_PRODUCT_BCDVERSION
#define CONFIG_USB_PRODUCT_BCDVERSION 0x0100
#endif
/**
* @brief USB specification version
*/
#ifndef CONFIG_USB_SPEC_BCDVERSION
#if defined(CONFIG_USB_SPEC_BCDVERSION_1_1)
#define CONFIG_USB_SPEC_BCDVERSION 0x0110
#elif defined(CONFIG_USB_SPEC_BCDVERSION_2_0)
#define CONFIG_USB_SPEC_BCDVERSION 0x0200
#else
#define CONFIG_USB_SPEC_BCDVERSION 0x0200
#endif
#endif
/**
* @brief USB peripheral setting to indicate self powered devices.
*/
#ifndef CONFIG_USB_SELF_POWERED
#define CONFIG_USB_SELF_POWERED (0)
#endif
/**
* @brief USB peripheral setting to indicate remote wakeup capability.
*/
#ifndef CONFIG_USB_REM_WAKEUP
#define CONFIG_USB_REM_WAKEUP (0)
#endif
/**
* @brief USB device max power draw in mA, between 0 and 500mA
*/
#ifndef CONFIG_USB_MAX_POWER
#define CONFIG_USB_MAX_POWER (100)
#endif
/**
* @brief Default LANG ID reported to the host
*/
#ifndef CONFIG_USB_DEFAULT_LANGID
#define CONFIG_USB_DEFAULT_LANGID 0x0409 /* EN-US */
#endif
/** @} */
/**
* @brief RIOT-internal USB peripheral clearance indicator
*
* This define must only be set in compilation units that are RIOT internal,
* and only when they implement peripherals that can be considered default RIOT
* peripherals.
*
* When this is defined in all uses of `usb.h`, the board can use the
* 0x1209/0x7D00 VID/PID pair unless explicit configuration using @ref
* CONFIG_USB_VID and @ref CONFIG_USB_PID say otherwise.
*
* There is no sharp characterization of what consititutes an internal
* peripheral; a good check is this: If an application can, just by switching
* between boards, can have a feature provided by either RIOT's USB stack or a
* different mechanism, the USB version is a default RIOT peripheral.
*
* Examples are stdio access (is provided by most boards using a UART and an
* external USB UART adapter), Ethernet (is provided by other boards using
* ethos) and firmware upload and reset (is provided by other boards using an
* on-board programmer).
*
* See http://pid.codes/1209/7D00/ for the allocation of that code.
* @{
*/
#ifdef DOXYGEN
#define USB_H_USER_IS_RIOT_INTERNAL
#endif
/** @} */
/**
* @brief USB version definitions
*/
typedef enum {
USB_VERSION_1x, /* USB 1.0 or 1.1 device */
USB_VERSION_20, /* USB 2.0 device */
} usb_version_t;
/**
* @brief USB speed definitions
*/
typedef enum {
USB_SPEED_LOW, /* Low speed (1.5Mbit/s) */
USB_SPEED_FULL, /* Full speed (12Mbit/s) */
USB_SPEED_HIGH, /* High speed (480Mbit/s) */
} usb_speed_t;
/**
* @brief USB endpoint types
*/
typedef enum {
USB_EP_TYPE_NONE = 0, /**< Unused endpoint */
USB_EP_TYPE_CONTROL, /**< Control type */
USB_EP_TYPE_INTERRUPT, /**< Interrupt type */
USB_EP_TYPE_BULK, /**< Bulk type */
USB_EP_TYPE_ISOCHRONOUS, /**< Isochronous type */
} usb_ep_type_t;
/**
* @brief USB endpoint directions
*/
typedef enum {
USB_EP_DIR_OUT, /**< Host out, device in */
USB_EP_DIR_IN, /**< Host in, device out */
} usb_ep_dir_t;
#ifdef __cplusplus
}
#endif
#endif /* USB_H */
/** @} */