ChibiOS/HAL 9.0.0
hal_usb_lld.c
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file hal_usb_lld.c
19 * @brief PLATFORM USB subsystem low level driver source.
20 *
21 * @addtogroup USB
22 * @{
23 */
24
25#include "hal.h"
26
27#if (HAL_USE_USB == TRUE) || defined(__DOXYGEN__)
28
29/*===========================================================================*/
30/* Driver local definitions. */
31/*===========================================================================*/
32
33/*===========================================================================*/
34/* Driver exported variables. */
35/*===========================================================================*/
36
37/**
38 * @brief USB1 driver identifier.
39 */
40#if (PLATFORM_USB_USE_USB1 == TRUE) || defined(__DOXYGEN__)
42#endif
43
44/*===========================================================================*/
45/* Driver local variables and types. */
46/*===========================================================================*/
47
48/**
49 * @brief EP0 state.
50 * @note It is an union because IN and OUT endpoints are never used at the
51 * same time for EP0.
52 */
53static union {
54 /**
55 * @brief IN EP0 state.
56 */
58 /**
59 * @brief OUT EP0 state.
60 */
63
64/**
65 * @brief EP0 initialization structure.
66 */
72 0x40,
73 0x40,
74 &ep0_state.in,
75 &ep0_state.out
76};
77
78/*===========================================================================*/
79/* Driver local variables and types. */
80/*===========================================================================*/
81
82/*===========================================================================*/
83/* Driver local functions. */
84/*===========================================================================*/
85
86/*===========================================================================*/
87/* Driver interrupt handlers and threads. */
88/*===========================================================================*/
89
90/*===========================================================================*/
91/* Driver exported functions. */
92/*===========================================================================*/
93
94/**
95 * @brief Low level USB driver initialization.
96 *
97 * @notapi
98 */
99void usb_lld_init(void) {
100
101#if PLATFORM_USB_USE_USB1 == TRUE
102 /* Driver initialization.*/
104#endif
105}
106
107/**
108 * @brief Configures and activates the USB peripheral.
109 *
110 * @param[in] usbp pointer to the @p USBDriver object
111 *
112 * @notapi
113 */
115
116 if (usbp->state == USB_STOP) {
117 /* Enables the peripheral.*/
118#if PLATFORM_USB_USE_USB1 == TRUE
119 if (&USBD1 == usbp) {
120
121 }
122#endif
123 }
124 /* Configures the peripheral.*/
125
126}
127
128/**
129 * @brief Deactivates the USB peripheral.
130 *
131 * @param[in] usbp pointer to the @p USBDriver object
132 *
133 * @notapi
134 */
136
137 if (usbp->state == USB_READY) {
138 /* Resets the peripheral.*/
139
140 /* Disables the peripheral.*/
141#if PLATFORM_USB_USE_USB1 == TRUE
142 if (&USBD1 == usbp) {
143
144 }
145#endif
146 }
147}
148
149/**
150 * @brief USB low level reset routine.
151 *
152 * @param[in] usbp pointer to the @p USBDriver object
153 *
154 * @notapi
155 */
157
158 /* Post reset initialization.*/
159
160 /* EP0 initialization.*/
161 usbp->epc[0] = &ep0config;
162 usb_lld_init_endpoint(usbp, 0);
163}
164
165/**
166 * @brief Sets the USB address.
167 *
168 * @param[in] usbp pointer to the @p USBDriver object
169 *
170 * @notapi
171 */
173
174 (void)usbp;
175
176}
177
178/**
179 * @brief Enables an endpoint.
180 *
181 * @param[in] usbp pointer to the @p USBDriver object
182 * @param[in] ep endpoint number
183 *
184 * @notapi
185 */
187
188 (void)usbp;
189 (void)ep;
190
191}
192
193/**
194 * @brief Disables all the active endpoints except the endpoint zero.
195 *
196 * @param[in] usbp pointer to the @p USBDriver object
197 *
198 * @notapi
199 */
201
202 (void)usbp;
203
204}
205
206/**
207 * @brief Returns the status of an OUT endpoint.
208 *
209 * @param[in] usbp pointer to the @p USBDriver object
210 * @param[in] ep endpoint number
211 * @return The endpoint status.
212 * @retval EP_STATUS_DISABLED The endpoint is not active.
213 * @retval EP_STATUS_STALLED The endpoint is stalled.
214 * @retval EP_STATUS_ACTIVE The endpoint is active.
215 *
216 * @notapi
217 */
219
220 (void)usbp;
221 (void)ep;
222
223 return EP_STATUS_DISABLED;
224}
225
226/**
227 * @brief Returns the status of an IN endpoint.
228 *
229 * @param[in] usbp pointer to the @p USBDriver object
230 * @param[in] ep endpoint number
231 * @return The endpoint status.
232 * @retval EP_STATUS_DISABLED The endpoint is not active.
233 * @retval EP_STATUS_STALLED The endpoint is stalled.
234 * @retval EP_STATUS_ACTIVE The endpoint is active.
235 *
236 * @notapi
237 */
239
240 (void)usbp;
241 (void)ep;
242
243 return EP_STATUS_DISABLED;
244}
245
246/**
247 * @brief Reads a setup packet from the dedicated packet buffer.
248 * @details This function must be invoked in the context of the @p setup_cb
249 * callback in order to read the received setup packet.
250 * @pre In order to use this function the endpoint must have been
251 * initialized as a control endpoint.
252 * @post The endpoint is ready to accept another packet.
253 *
254 * @param[in] usbp pointer to the @p USBDriver object
255 * @param[in] ep endpoint number
256 * @param[out] buf buffer where to copy the packet data
257 *
258 * @notapi
259 */
260void usb_lld_read_setup(USBDriver *usbp, usbep_t ep, uint8_t *buf) {
261
262 (void)usbp;
263 (void)ep;
264 (void)buf;
265
266}
267
268/**
269 * @brief Prepares for a receive operation.
270 *
271 * @param[in] usbp pointer to the @p USBDriver object
272 * @param[in] ep endpoint number
273 *
274 * @notapi
275 */
277
278 (void)usbp;
279 (void)ep;
280
281}
282
283/**
284 * @brief Prepares for a transmit operation.
285 *
286 * @param[in] usbp pointer to the @p USBDriver object
287 * @param[in] ep endpoint number
288 *
289 * @notapi
290 */
292
293 (void)usbp;
294 (void)ep;
295
296}
297
298/**
299 * @brief Starts a receive operation on an OUT endpoint.
300 *
301 * @param[in] usbp pointer to the @p USBDriver object
302 * @param[in] ep endpoint number
303 *
304 * @notapi
305 */
307
308 (void)usbp;
309 (void)ep;
310
311}
312
313/**
314 * @brief Starts a transmit operation on an IN endpoint.
315 *
316 * @param[in] usbp pointer to the @p USBDriver object
317 * @param[in] ep endpoint number
318 *
319 * @notapi
320 */
322
323 (void)usbp;
324 (void)ep;
325
326}
327
328/**
329 * @brief Brings an OUT endpoint in the stalled state.
330 *
331 * @param[in] usbp pointer to the @p USBDriver object
332 * @param[in] ep endpoint number
333 *
334 * @notapi
335 */
337
338 (void)usbp;
339 (void)ep;
340
341}
342
343/**
344 * @brief Brings an IN endpoint in the stalled state.
345 *
346 * @param[in] usbp pointer to the @p USBDriver object
347 * @param[in] ep endpoint number
348 *
349 * @notapi
350 */
352
353 (void)usbp;
354 (void)ep;
355
356}
357
358/**
359 * @brief Brings an OUT endpoint in the active state.
360 *
361 * @param[in] usbp pointer to the @p USBDriver object
362 * @param[in] ep endpoint number
363 *
364 * @notapi
365 */
367
368 (void)usbp;
369 (void)ep;
370
371}
372
373/**
374 * @brief Brings an IN endpoint in the active state.
375 *
376 * @param[in] usbp pointer to the @p USBDriver object
377 * @param[in] ep endpoint number
378 *
379 * @notapi
380 */
382
383 (void)usbp;
384 (void)ep;
385
386}
387
388#endif /* HAL_USE_USB == TRUE */
389
390/** @} */
void usb_lld_stop(USBDriver *usbp)
Deactivates the USB peripheral.
void usb_lld_set_address(USBDriver *usbp)
Sets the USB address.
uint8_t usbep_t
Type of an endpoint identifier.
Definition hal_usb.h:264
void usb_lld_clear_in(USBDriver *usbp, usbep_t ep)
Brings an IN endpoint in the active state.
usbepstatus_t
Type of an endpoint status.
Definition hal_usb.h:281
void usb_lld_init(void)
Low level USB driver initialization.
Definition hal_usb_lld.c:99
USBOutEndpointState out
OUT EP0 state.
Definition hal_usb_lld.c:61
void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep)
Enables an endpoint.
usbepstatus_t usb_lld_get_status_out(USBDriver *usbp, usbep_t ep)
Returns the status of an OUT endpoint.
void _usb_ep0setup(USBDriver *usbp, usbep_t ep)
Default EP0 SETUP callback.
Definition hal_usb.c:816
void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep)
Prepares for a transmit operation.
void usb_lld_reset(USBDriver *usbp)
USB low level reset routine.
usbepstatus_t usb_lld_get_status_in(USBDriver *usbp, usbep_t ep)
Returns the status of an IN endpoint.
void usb_lld_disable_endpoints(USBDriver *usbp)
Disables all the active endpoints except the endpoint zero.
void usb_lld_start_out(USBDriver *usbp, usbep_t ep)
Starts a receive operation on an OUT endpoint.
#define USB_EP_MODE_TYPE_CTRL
Definition hal_usb.h:227
static const USBEndpointConfig ep0config
EP0 initialization structure.
Definition hal_usb_lld.c:67
void usb_lld_start(USBDriver *usbp)
Configures and activates the USB peripheral.
void usb_lld_start_in(USBDriver *usbp, usbep_t ep)
Starts a transmit operation on an IN endpoint.
void usb_lld_read_setup(USBDriver *usbp, usbep_t ep, uint8_t *buf)
Reads a setup packet from the dedicated packet buffer.
void _usb_ep0in(USBDriver *usbp, usbep_t ep)
Default EP0 IN callback.
Definition hal_usb.c:924
USBDriver USBD1
USB1 driver identifier.
Definition hal_usb_lld.c:41
void usb_lld_clear_out(USBDriver *usbp, usbep_t ep)
Brings an OUT endpoint in the active state.
void usb_lld_stall_out(USBDriver *usbp, usbep_t ep)
Brings an OUT endpoint in the stalled state.
void usb_lld_stall_in(USBDriver *usbp, usbep_t ep)
Brings an IN endpoint in the stalled state.
void usbObjectInit(USBDriver *usbp)
Initializes the standard part of a USBDriver structure.
Definition hal_usb.c:282
void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep)
Prepares for a receive operation.
static union @235206122270051152302000074257205070254344304236 ep0_state
EP0 state.
void _usb_ep0out(USBDriver *usbp, usbep_t ep)
Default EP0 OUT callback.
Definition hal_usb.c:991
@ EP_STATUS_DISABLED
Definition hal_usb.h:282
@ USB_STOP
Definition hal_usb.h:271
@ USB_READY
Definition hal_usb.h:272
HAL subsystem header.
Structure representing an USB driver.
const USBEndpointConfig * epc[USB_MAX_ENDPOINTS+1]
Active endpoints configurations.
usbstate_t state
Driver state.
Type of an USB endpoint configuration structure.
Type of an IN endpoint state structure.
Definition hal_usb_lld.h:83
Type of an OUT endpoint state structure.