ChibiOS/HAL  6.1.0
hal_usb.h
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.h
19  * @brief USB Driver macros and structures.
20  *
21  * @addtogroup USB
22  * @{
23  */
24 
25 #ifndef HAL_USB_H
26 #define HAL_USB_H
27 
28 #if (HAL_USE_USB == TRUE) || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 #define USB_ENDPOINT_OUT(ep) (ep)
35 #define USB_ENDPOINT_IN(ep) ((ep) | 0x80U)
36 
37 #define USB_RTYPE_DIR_MASK 0x80U
38 #define USB_RTYPE_DIR_HOST2DEV 0x00U
39 #define USB_RTYPE_DIR_DEV2HOST 0x80U
40 #define USB_RTYPE_TYPE_MASK 0x60U
41 #define USB_RTYPE_TYPE_STD 0x00U
42 #define USB_RTYPE_TYPE_CLASS 0x20U
43 #define USB_RTYPE_TYPE_VENDOR 0x40U
44 #define USB_RTYPE_TYPE_RESERVED 0x60U
45 #define USB_RTYPE_RECIPIENT_MASK 0x1FU
46 #define USB_RTYPE_RECIPIENT_DEVICE 0x00U
47 #define USB_RTYPE_RECIPIENT_INTERFACE 0x01U
48 #define USB_RTYPE_RECIPIENT_ENDPOINT 0x02U
49 #define USB_RTYPE_RECIPIENT_OTHER 0x03U
50 
51 #define USB_REQ_GET_STATUS 0U
52 #define USB_REQ_CLEAR_FEATURE 1U
53 #define USB_REQ_SET_FEATURE 3U
54 #define USB_REQ_SET_ADDRESS 5U
55 #define USB_REQ_GET_DESCRIPTOR 6U
56 #define USB_REQ_SET_DESCRIPTOR 7U
57 #define USB_REQ_GET_CONFIGURATION 8U
58 #define USB_REQ_SET_CONFIGURATION 9U
59 #define USB_REQ_GET_INTERFACE 10U
60 #define USB_REQ_SET_INTERFACE 11U
61 #define USB_REQ_SYNCH_FRAME 12U
62 
63 #define USB_DESCRIPTOR_DEVICE 1U
64 #define USB_DESCRIPTOR_CONFIGURATION 2U
65 #define USB_DESCRIPTOR_STRING 3U
66 #define USB_DESCRIPTOR_INTERFACE 4U
67 #define USB_DESCRIPTOR_ENDPOINT 5U
68 #define USB_DESCRIPTOR_DEVICE_QUALIFIER 6U
69 #define USB_DESCRIPTOR_OTHER_SPEED_CFG 7U
70 #define USB_DESCRIPTOR_INTERFACE_POWER 8U
71 #define USB_DESCRIPTOR_INTERFACE_ASSOCIATION 11U
72 
73 #define USB_FEATURE_ENDPOINT_HALT 0U
74 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1U
75 #define USB_FEATURE_TEST_MODE 2U
76 
77 #define USB_EARLY_SET_ADDRESS 0
78 #define USB_LATE_SET_ADDRESS 1
79 
80 #define USB_EP0_STATUS_STAGE_SW 0
81 #define USB_EP0_STATUS_STAGE_HW 1
82 
83 #define USB_SET_ADDRESS_ACK_SW 0
84 #define USB_SET_ADDRESS_ACK_HW 1
85 
86 /**
87  * @name Helper macros for USB descriptors
88  * @{
89  */
90 /**
91  * @brief Helper macro for index values into descriptor strings.
92  */
93 #define USB_DESC_INDEX(i) ((uint8_t)(i))
94 
95 /**
96  * @brief Helper macro for byte values into descriptor strings.
97  */
98 #define USB_DESC_BYTE(b) ((uint8_t)(b))
99 
100 /**
101  * @brief Helper macro for word values into descriptor strings.
102  */
103 #define USB_DESC_WORD(w) \
104  (uint8_t)((w) & 255U), \
105  (uint8_t)(((w) >> 8) & 255U)
106 
107 /**
108  * @brief Helper macro for BCD values into descriptor strings.
109  */
110 #define USB_DESC_BCD(bcd) \
111  (uint8_t)((bcd) & 255U), \
112  (uint8_t)(((bcd) >> 8) & 255)
113 
114 /*
115  * @define Device Descriptor size.
116  */
117 #define USB_DESC_DEVICE_SIZE 18U
118 
119 /**
120  * @brief Device Descriptor helper macro.
121  */
122 #define USB_DESC_DEVICE(bcdUSB, bDeviceClass, bDeviceSubClass, \
123  bDeviceProtocol, bMaxPacketSize, idVendor, \
124  idProduct, bcdDevice, iManufacturer, \
125  iProduct, iSerialNumber, bNumConfigurations) \
126  USB_DESC_BYTE(USB_DESC_DEVICE_SIZE), \
127  USB_DESC_BYTE(USB_DESCRIPTOR_DEVICE), \
128  USB_DESC_BCD(bcdUSB), \
129  USB_DESC_BYTE(bDeviceClass), \
130  USB_DESC_BYTE(bDeviceSubClass), \
131  USB_DESC_BYTE(bDeviceProtocol), \
132  USB_DESC_BYTE(bMaxPacketSize), \
133  USB_DESC_WORD(idVendor), \
134  USB_DESC_WORD(idProduct), \
135  USB_DESC_BCD(bcdDevice), \
136  USB_DESC_INDEX(iManufacturer), \
137  USB_DESC_INDEX(iProduct), \
138  USB_DESC_INDEX(iSerialNumber), \
139  USB_DESC_BYTE(bNumConfigurations)
140 
141 /**
142  * @brief Configuration Descriptor size.
143  */
144 #define USB_DESC_CONFIGURATION_SIZE 9U
145 
146 /**
147  * @brief Configuration Descriptor helper macro.
148  */
149 #define USB_DESC_CONFIGURATION(wTotalLength, bNumInterfaces, \
150  bConfigurationValue, iConfiguration, \
151  bmAttributes, bMaxPower) \
152  USB_DESC_BYTE(USB_DESC_CONFIGURATION_SIZE), \
153  USB_DESC_BYTE(USB_DESCRIPTOR_CONFIGURATION), \
154  USB_DESC_WORD(wTotalLength), \
155  USB_DESC_BYTE(bNumInterfaces), \
156  USB_DESC_BYTE(bConfigurationValue), \
157  USB_DESC_INDEX(iConfiguration), \
158  USB_DESC_BYTE(bmAttributes), \
159  USB_DESC_BYTE(bMaxPower)
160 
161 /**
162  * @brief Interface Descriptor size.
163  */
164 #define USB_DESC_INTERFACE_SIZE 9U
165 
166 /**
167  * @brief Interface Descriptor helper macro.
168  */
169 #define USB_DESC_INTERFACE(bInterfaceNumber, bAlternateSetting, \
170  bNumEndpoints, bInterfaceClass, \
171  bInterfaceSubClass, bInterfaceProtocol, \
172  iInterface) \
173  USB_DESC_BYTE(USB_DESC_INTERFACE_SIZE), \
174  USB_DESC_BYTE(USB_DESCRIPTOR_INTERFACE), \
175  USB_DESC_BYTE(bInterfaceNumber), \
176  USB_DESC_BYTE(bAlternateSetting), \
177  USB_DESC_BYTE(bNumEndpoints), \
178  USB_DESC_BYTE(bInterfaceClass), \
179  USB_DESC_BYTE(bInterfaceSubClass), \
180  USB_DESC_BYTE(bInterfaceProtocol), \
181  USB_DESC_INDEX(iInterface)
182 
183 /**
184  * @brief Interface Association Descriptor size.
185  */
186 #define USB_DESC_INTERFACE_ASSOCIATION_SIZE 8U
187 
188 /**
189  * @brief Interface Association Descriptor helper macro.
190  */
191 #define USB_DESC_INTERFACE_ASSOCIATION(bFirstInterface, \
192  bInterfaceCount, bFunctionClass, \
193  bFunctionSubClass, bFunctionProcotol, \
194  iInterface) \
195  USB_DESC_BYTE(USB_DESC_INTERFACE_ASSOCIATION_SIZE), \
196  USB_DESC_BYTE(USB_DESCRIPTOR_INTERFACE_ASSOCIATION), \
197  USB_DESC_BYTE(bFirstInterface), \
198  USB_DESC_BYTE(bInterfaceCount), \
199  USB_DESC_BYTE(bFunctionClass), \
200  USB_DESC_BYTE(bFunctionSubClass), \
201  USB_DESC_BYTE(bFunctionProcotol), \
202  USB_DESC_INDEX(iInterface)
203 
204 /**
205  * @brief Endpoint Descriptor size.
206  */
207 #define USB_DESC_ENDPOINT_SIZE 7U
208 
209 /**
210  * @brief Endpoint Descriptor helper macro.
211  */
212 #define USB_DESC_ENDPOINT(bEndpointAddress, bmAttributes, wMaxPacketSize, \
213  bInterval) \
214  USB_DESC_BYTE(USB_DESC_ENDPOINT_SIZE), \
215  USB_DESC_BYTE(USB_DESCRIPTOR_ENDPOINT), \
216  USB_DESC_BYTE(bEndpointAddress), \
217  USB_DESC_BYTE(bmAttributes), \
218  USB_DESC_WORD(wMaxPacketSize), \
219  USB_DESC_BYTE(bInterval)
220 /** @} */
221 
222 /**
223  * @name Endpoint types and settings
224  * @{
225  */
226 #define USB_EP_MODE_TYPE 0x0003U /**< Endpoint type mask. */
227 #define USB_EP_MODE_TYPE_CTRL 0x0000U /**< Control endpoint. */
228 #define USB_EP_MODE_TYPE_ISOC 0x0001U /**< Isochronous endpoint. */
229 #define USB_EP_MODE_TYPE_BULK 0x0002U /**< Bulk endpoint. */
230 #define USB_EP_MODE_TYPE_INTR 0x0003U /**< Interrupt endpoint. */
231 /** @} */
232 
233 #define USB_IN_STATE 0x08U
234 #define USB_OUT_STATE 0x10U
235 
236 /*===========================================================================*/
237 /* Driver pre-compile time settings. */
238 /*===========================================================================*/
239 
240 /**
241  * @brief Enables synchronous APIs.
242  * @note Disabling this option saves both code and data space.
243  */
244 #if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)
245 #define USB_USE_WAIT FALSE
246 #endif
247 
248 /*===========================================================================*/
249 /* Derived constants and error checks. */
250 /*===========================================================================*/
251 
252 /*===========================================================================*/
253 /* Driver data structures and types. */
254 /*===========================================================================*/
255 
256 /**
257  * @brief Type of a structure representing an USB driver.
258  */
259 typedef struct USBDriver USBDriver;
260 
261 /**
262  * @brief Type of an endpoint identifier.
263  */
264 typedef uint8_t usbep_t;
265 
266 /**
267  * @brief Type of a driver state machine possible states.
268  */
269 typedef enum {
270  USB_UNINIT = 0, /**< Not initialized. */
271  USB_STOP = 1, /**< Stopped. */
272  USB_READY = 2, /**< Ready, after bus reset. */
273  USB_SELECTED = 3, /**< Address assigned. */
274  USB_ACTIVE = 4, /**< Active, configuration selected.*/
275  USB_SUSPENDED = 5 /**< Suspended, low power mode. */
276 } usbstate_t;
277 
278 /**
279  * @brief Type of an endpoint status.
280  */
281 typedef enum {
282  EP_STATUS_DISABLED = 0, /**< Endpoint not active. */
283  EP_STATUS_STALLED = 1, /**< Endpoint opened but stalled. */
284  EP_STATUS_ACTIVE = 2 /**< Active endpoint. */
285 } usbepstatus_t;
286 
287 /**
288  * @brief Type of an endpoint zero state machine states.
289  */
290 typedef enum {
291  USB_EP0_STP_WAITING = 0U, /**< Waiting for SETUP data.*/
292  USB_EP0_IN_TX = USB_IN_STATE | 1U, /**< Transmitting. */
293  USB_EP0_IN_WAITING_TX0 = USB_IN_STATE | 2U, /**< Waiting transmit 0. */
294  USB_EP0_IN_SENDING_STS = USB_IN_STATE | 3U, /**< Sending status. */
295  USB_EP0_OUT_WAITING_STS = USB_OUT_STATE | 4U, /**< Waiting status. */
296  USB_EP0_OUT_RX = USB_OUT_STATE | 5U, /**< Receiving. */
297  USB_EP0_ERROR = 6U /**< Error, EP0 stalled. */
298 } usbep0state_t;
299 
300 /**
301  * @brief Type of an enumeration of the possible USB events.
302  */
303 typedef enum {
304  USB_EVENT_RESET = 0, /**< Driver has been reset by host. */
305  USB_EVENT_ADDRESS = 1, /**< Address assigned. */
306  USB_EVENT_CONFIGURED = 2, /**< Configuration selected. */
307  USB_EVENT_UNCONFIGURED = 3, /**< Configuration removed. */
308  USB_EVENT_SUSPEND = 4, /**< Entering suspend mode. */
309  USB_EVENT_WAKEUP = 5, /**< Leaving suspend mode. */
310  USB_EVENT_STALLED = 6 /**< Endpoint 0 error, stalled. */
311 } usbevent_t;
312 
313 /**
314  * @brief Type of an USB descriptor.
315  */
316 typedef struct {
317  /**
318  * @brief Descriptor size in unicode characters.
319  */
320  size_t ud_size;
321  /**
322  * @brief Pointer to the descriptor.
323  */
324  const uint8_t *ud_string;
325 } USBDescriptor;
326 
327 /**
328  * @brief Type of an USB generic notification callback.
329  *
330  * @param[in] usbp pointer to the @p USBDriver object triggering the
331  * callback
332  */
333 typedef void (*usbcallback_t)(USBDriver *usbp);
334 
335 /**
336  * @brief Type of an USB endpoint callback.
337  *
338  * @param[in] usbp pointer to the @p USBDriver object triggering the
339  * callback
340  * @param[in] ep endpoint number
341  */
342 typedef void (*usbepcallback_t)(USBDriver *usbp, usbep_t ep);
343 
344 /**
345  * @brief Type of an USB event notification callback.
346  *
347  * @param[in] usbp pointer to the @p USBDriver object triggering the
348  * callback
349  * @param[in] event event type
350  */
351 typedef void (*usbeventcb_t)(USBDriver *usbp, usbevent_t event);
352 
353 /**
354  * @brief Type of a requests handler callback.
355  * @details The request is encoded in the @p usb_setup buffer.
356  *
357  * @param[in] usbp pointer to the @p USBDriver object triggering the
358  * callback
359  * @return The request handling exit code.
360  * @retval false Request not recognized by the handler.
361  * @retval true Request handled.
362  */
363 typedef bool (*usbreqhandler_t)(USBDriver *usbp);
364 
365 /**
366  * @brief Type of an USB descriptor-retrieving callback.
367  */
368 typedef const USBDescriptor * (*usbgetdescriptor_t)(USBDriver *usbp,
369  uint8_t dtype,
370  uint8_t dindex,
371  uint16_t lang);
372 
373 #include "hal_usb_lld.h"
374 
375 /*===========================================================================*/
376 /* Driver macros. */
377 /*===========================================================================*/
378 
379 /**
380  * @name Macro Functions
381  * @{
382  */
383 /**
384  * @brief Returns the driver state.
385  *
386  * @param[in] usbp pointer to the @p USBDriver object
387  * @return The driver state.
388  *
389  * @iclass
390  */
391 #define usbGetDriverStateI(usbp) ((usbp)->state)
392 
393 /**
394  * @brief Connects the USB device.
395  *
396  * @param[in] usbp pointer to the @p USBDriver object
397  *
398  * @api
399  */
400 #define usbConnectBus(usbp) usb_lld_connect_bus(usbp)
401 
402 /**
403  * @brief Disconnect the USB device.
404  *
405  * @param[in] usbp pointer to the @p USBDriver object
406  *
407  * @api
408  */
409 #define usbDisconnectBus(usbp) usb_lld_disconnect_bus(usbp)
410 
411 /**
412  * @brief Returns the current frame number.
413  *
414  * @param[in] usbp pointer to the @p USBDriver object
415  * @return The current frame number.
416  *
417  * @xclass
418  */
419 #define usbGetFrameNumberX(usbp) usb_lld_get_frame_number(usbp)
420 
421 /**
422  * @brief Returns the status of an IN endpoint.
423  *
424  * @param[in] usbp pointer to the @p USBDriver object
425  * @param[in] ep endpoint number
426  * @return The operation status.
427  * @retval false Endpoint ready.
428  * @retval true Endpoint transmitting.
429  *
430  * @iclass
431  */
432 #define usbGetTransmitStatusI(usbp, ep) \
433  (((usbp)->transmitting & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U)
434 
435 /**
436  * @brief Returns the status of an OUT endpoint.
437  *
438  * @param[in] usbp pointer to the @p USBDriver object
439  * @param[in] ep endpoint number
440  * @return The operation status.
441  * @retval false Endpoint ready.
442  * @retval true Endpoint receiving.
443  *
444  * @iclass
445  */
446 #define usbGetReceiveStatusI(usbp, ep) \
447  (((usbp)->receiving & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U)
448 
449 /**
450  * @brief Returns the exact size of a receive transaction.
451  * @details The received size can be different from the size specified in
452  * @p usbStartReceiveI() because the last packet could have a size
453  * different from the expected one.
454  *
455  * @param[in] usbp pointer to the @p USBDriver object
456  * @param[in] ep endpoint number
457  * @return Received data size.
458  *
459  * @xclass
460  */
461 #define usbGetReceiveTransactionSizeX(usbp, ep) \
462  usb_lld_get_transaction_size(usbp, ep)
463 
464 /**
465  * @brief Request transfer setup.
466  * @details This macro is used by the request handling callbacks in order to
467  * prepare a transaction over the endpoint zero.
468  *
469  * @param[in] usbp pointer to the @p USBDriver object
470  * @param[in] buf pointer to a buffer for the transaction data
471  * @param[in] n number of bytes to be transferred
472  * @param[in] endcb callback to be invoked after the transfer or @p NULL
473  *
474  * @special
475  */
476 #define usbSetupTransfer(usbp, buf, n, endcb) { \
477  (usbp)->ep0next = (buf); \
478  (usbp)->ep0n = (n); \
479  (usbp)->ep0endcb = (endcb); \
480 }
481 
482 /**
483  * @brief Reads a setup packet from the dedicated packet buffer.
484  * @details This function must be invoked in the context of the @p setup_cb
485  * callback in order to read the received setup packet.
486  * @pre In order to use this function the endpoint must have been
487  * initialized as a control endpoint.
488  * @note This function can be invoked both in thread and IRQ context.
489  *
490  * @param[in] usbp pointer to the @p USBDriver object
491  * @param[in] ep endpoint number
492  * @param[out] buf buffer where to copy the packet data
493  *
494  * @special
495  */
496 #define usbReadSetup(usbp, ep, buf) usb_lld_read_setup(usbp, ep, buf)
497 /** @} */
498 
499 /**
500  * @name Low level driver helper macros
501  * @{
502  */
503 /**
504  * @brief Common ISR code, usb event callback.
505  *
506  * @param[in] usbp pointer to the @p USBDriver object
507  * @param[in] evt USB event code
508  *
509  * @notapi
510  */
511 #define _usb_isr_invoke_event_cb(usbp, evt) { \
512  if (((usbp)->config->event_cb) != NULL) { \
513  (usbp)->config->event_cb(usbp, evt); \
514  } \
515 }
516 
517 /**
518  * @brief Common ISR code, SOF callback.
519  *
520  * @param[in] usbp pointer to the @p USBDriver object
521  *
522  * @notapi
523  */
524 #define _usb_isr_invoke_sof_cb(usbp) { \
525  if (((usbp)->config->sof_cb) != NULL) { \
526  (usbp)->config->sof_cb(usbp); \
527  } \
528 }
529 
530 /**
531  * @brief Common ISR code, setup packet callback.
532  *
533  * @param[in] usbp pointer to the @p USBDriver object
534  * @param[in] ep endpoint number
535  *
536  * @notapi
537  */
538 #define _usb_isr_invoke_setup_cb(usbp, ep) { \
539  (usbp)->epc[ep]->setup_cb(usbp, ep); \
540 }
541 
542 /**
543  * @brief Common ISR code, IN endpoint callback.
544  *
545  * @param[in] usbp pointer to the @p USBDriver object
546  * @param[in] ep endpoint number
547  *
548  * @notapi
549  */
550 #if (USB_USE_WAIT == TRUE) || defined(__DOXYGEN__)
551 #define _usb_isr_invoke_in_cb(usbp, ep) { \
552  (usbp)->transmitting &= ~(1 << (ep)); \
553  if ((usbp)->epc[ep]->in_cb != NULL) { \
554  (usbp)->epc[ep]->in_cb(usbp, ep); \
555  } \
556  osalSysLockFromISR(); \
557  osalThreadResumeI(&(usbp)->epc[ep]->in_state->thread, MSG_OK); \
558  osalSysUnlockFromISR(); \
559 }
560 #else
561 #define _usb_isr_invoke_in_cb(usbp, ep) { \
562  (usbp)->transmitting &= ~(1 << (ep)); \
563  if ((usbp)->epc[ep]->in_cb != NULL) { \
564  (usbp)->epc[ep]->in_cb(usbp, ep); \
565  } \
566 }
567 #endif
568 
569 /**
570  * @brief Common ISR code, OUT endpoint event.
571  *
572  * @param[in] usbp pointer to the @p USBDriver object
573  * @param[in] ep endpoint number
574  *
575  * @notapi
576  */
577 #if (USB_USE_WAIT == TRUE) || defined(__DOXYGEN__)
578 #define _usb_isr_invoke_out_cb(usbp, ep) { \
579  (usbp)->receiving &= ~(1 << (ep)); \
580  if ((usbp)->epc[ep]->out_cb != NULL) { \
581  (usbp)->epc[ep]->out_cb(usbp, ep); \
582  } \
583  osalSysLockFromISR(); \
584  osalThreadResumeI(&(usbp)->epc[ep]->out_state->thread, \
585  usbGetReceiveTransactionSizeX(usbp, ep)); \
586  osalSysUnlockFromISR(); \
587 }
588 #else
589 #define _usb_isr_invoke_out_cb(usbp, ep) { \
590  (usbp)->receiving &= ~(1 << (ep)); \
591  if ((usbp)->epc[ep]->out_cb != NULL) { \
592  (usbp)->epc[ep]->out_cb(usbp, ep); \
593  } \
594 }
595 #endif
596 /** @} */
597 
598 /*===========================================================================*/
599 /* External declarations. */
600 /*===========================================================================*/
601 
602 #ifdef __cplusplus
603 extern "C" {
604 #endif
605  void usbInit(void);
606  void usbObjectInit(USBDriver *usbp);
607  void usbStart(USBDriver *usbp, const USBConfig *config);
608  void usbStop(USBDriver *usbp);
609  void usbInitEndpointI(USBDriver *usbp, usbep_t ep,
610  const USBEndpointConfig *epcp);
611  void usbDisableEndpointsI(USBDriver *usbp);
612  void usbReadSetupI(USBDriver *usbp, usbep_t ep, uint8_t *buf);
613  void usbStartReceiveI(USBDriver *usbp, usbep_t ep,
614  uint8_t *buf, size_t n);
615  void usbStartTransmitI(USBDriver *usbp, usbep_t ep,
616  const uint8_t *buf, size_t n);
617 #if USB_USE_WAIT == TRUE
618  msg_t usbReceive(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n);
619  msg_t usbTransmit(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n);
620 #endif
621  bool usbStallReceiveI(USBDriver *usbp, usbep_t ep);
622  bool usbStallTransmitI(USBDriver *usbp, usbep_t ep);
623  void usbWakeupHost(USBDriver *usbp);
624  void _usb_reset(USBDriver *usbp);
625  void _usb_suspend(USBDriver *usbp);
626  void _usb_wakeup(USBDriver *usbp);
627  void _usb_ep0setup(USBDriver *usbp, usbep_t ep);
628  void _usb_ep0in(USBDriver *usbp, usbep_t ep);
629  void _usb_ep0out(USBDriver *usbp, usbep_t ep);
630 #ifdef __cplusplus
631 }
632 #endif
633 
634 #endif /* HAL_USE_USB == TRUE */
635 
636 #endif /* HAL_USB_H */
637 
638 /** @} */
void usbDisableEndpointsI(USBDriver *usbp)
Disables all the active endpoints.
Definition: hal_usb.c:410
void _usb_suspend(USBDriver *usbp)
USB suspend routine.
Definition: hal_usb.c:713
void _usb_ep0setup(USBDriver *usbp, usbep_t ep)
Default EP0 SETUP callback.
Definition: hal_usb.c:772
void usbWakeupHost(USBDriver *usbp)
Host wake-up procedure.
Definition: hal_usb.c:646
size_t ud_size
Descriptor size in unicode characters.
Definition: hal_usb.h:320
PLATFORM USB subsystem low level driver header.
usbstate_t
Type of a driver state machine possible states.
Definition: hal_usb.h:269
const USBConfig * config
Current configuration data.
Definition: hal_usb_lld.h:225
Structure representing an USB driver.
Definition: hal_usb_lld.h:217
int32_t msg_t
Type of a message.
Definition: osal.h:160
void(* usbcallback_t)(USBDriver *usbp)
Type of an USB generic notification callback.
Definition: hal_usb.h:333
void(* usbeventcb_t)(USBDriver *usbp, usbevent_t event)
Type of an USB event notification callback.
Definition: hal_usb.h:351
msg_t usbTransmit(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n)
Performs a transmit transaction on an IN endpoint.
Definition: hal_usb.c:569
void usbInit(void)
USB Driver initialization.
Definition: hal_usb.c:270
void usbStartReceiveI(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n)
Starts a receive transaction on an OUT endpoint.
Definition: hal_usb.c:453
usbep0state_t
Type of an endpoint zero state machine states.
Definition: hal_usb.h:290
void _usb_ep0in(USBDriver *usbp, usbep_t ep)
Default EP0 IN callback.
Definition: hal_usb.c:880
void _usb_wakeup(USBDriver *usbp)
USB wake-up routine.
Definition: hal_usb.c:753
bool(* usbreqhandler_t)(USBDriver *usbp)
Type of a requests handler callback.
Definition: hal_usb.h:363
void _usb_ep0out(USBDriver *usbp, usbep_t ep)
Default EP0 OUT callback.
Definition: hal_usb.c:947
void usbStop(USBDriver *usbp)
Deactivates the USB peripheral.
Definition: hal_usb.c:327
const uint8_t * ud_string
Pointer to the descriptor.
Definition: hal_usb.h:324
bool usbStallTransmitI(USBDriver *usbp, usbep_t ep)
Stalls an IN endpoint.
Definition: hal_usb.c:624
void usbInitEndpointI(USBDriver *usbp, usbep_t ep, const USBEndpointConfig *epcp)
Enables an endpoint.
Definition: hal_usb.c:375
void _usb_reset(USBDriver *usbp)
USB reset routine.
Definition: hal_usb.c:663
void usbStart(USBDriver *usbp, const USBConfig *config)
Configures and activates the USB peripheral.
Definition: hal_usb.c:303
void(* usbepcallback_t)(USBDriver *usbp, usbep_t ep)
Type of an USB endpoint callback.
Definition: hal_usb.h:342
bool usbStallReceiveI(USBDriver *usbp, usbep_t ep)
Stalls an OUT endpoint.
Definition: hal_usb.c:599
Type of an USB descriptor.
Definition: hal_usb.h:316
uint8_t usbep_t
Type of an endpoint identifier.
Definition: hal_usb.h:264
Type of an USB driver configuration structure.
Definition: hal_usb_lld.h:190
usbevent_t
Type of an enumeration of the possible USB events.
Definition: hal_usb.h:303
void usbStartTransmitI(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n)
Starts a transmit transaction on an IN endpoint.
Definition: hal_usb.c:492
msg_t usbReceive(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n)
Performs a receive transaction on an OUT endpoint.
Definition: hal_usb.c:536
Type of an USB endpoint configuration structure.
Definition: hal_usb_lld.h:134
void usbObjectInit(USBDriver *usbp)
Initializes the standard part of a USBDriver structure.
Definition: hal_usb.c:282
usbepstatus_t
Type of an endpoint status.
Definition: hal_usb.h:281