28#if (HAL_USE_USB == TRUE) || defined(__DOXYGEN__)
34#define USB_ENDPOINT_OUT(ep) (ep)
35#define USB_ENDPOINT_IN(ep) ((ep) | 0x80U)
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
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
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
73#define USB_FEATURE_ENDPOINT_HALT 0U
74#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1U
75#define USB_FEATURE_TEST_MODE 2U
77#define USB_EARLY_SET_ADDRESS 0
78#define USB_LATE_SET_ADDRESS 1
80#define USB_EP0_STATUS_STAGE_SW 0
81#define USB_EP0_STATUS_STAGE_HW 1
83#define USB_SET_ADDRESS_ACK_SW 0
84#define USB_SET_ADDRESS_ACK_HW 1
93#define USB_DESC_INDEX(i) ((uint8_t)(i))
98#define USB_DESC_BYTE(b) ((uint8_t)(b))
103#define USB_DESC_WORD(w) \
104 (uint8_t)((w) & 255U), \
105 (uint8_t)(((w) >> 8) & 255U)
110#define USB_DESC_BCD(bcd) \
111 (uint8_t)((bcd) & 255U), \
112 (uint8_t)(((bcd) >> 8) & 255)
117#define USB_DESC_DEVICE_SIZE 18U
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)
144#define USB_DESC_CONFIGURATION_SIZE 9U
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)
164#define USB_DESC_INTERFACE_SIZE 9U
169#define USB_DESC_INTERFACE(bInterfaceNumber, bAlternateSetting, \
170 bNumEndpoints, bInterfaceClass, \
171 bInterfaceSubClass, bInterfaceProtocol, \
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)
186#define USB_DESC_INTERFACE_ASSOCIATION_SIZE 8U
191#define USB_DESC_INTERFACE_ASSOCIATION(bFirstInterface, \
192 bInterfaceCount, bFunctionClass, \
193 bFunctionSubClass, bFunctionProcotol, \
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)
207#define USB_DESC_ENDPOINT_SIZE 7U
212#define USB_DESC_ENDPOINT(bEndpointAddress, bmAttributes, wMaxPacketSize, \
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)
226#define USB_EP_MODE_TYPE 0x0003U
227#define USB_EP_MODE_TYPE_CTRL 0x0000U
228#define USB_EP_MODE_TYPE_ISOC 0x0001U
229#define USB_EP_MODE_TYPE_BULK 0x0002U
230#define USB_EP_MODE_TYPE_INTR 0x0003U
233#define USB_IN_STATE 0x08U
234#define USB_OUT_STATE 0x10U
244#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)
245#define USB_USE_WAIT FALSE
391#define usbGetDriverStateI(usbp) ((usbp)->state)
400#define usbConnectBus(usbp) usb_lld_connect_bus(usbp)
409#define usbDisconnectBus(usbp) usb_lld_disconnect_bus(usbp)
419#define usbGetFrameNumberX(usbp) usb_lld_get_frame_number(usbp)
432#define usbGetTransmitStatusI(usbp, ep) \
433 (((usbp)->transmitting & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U)
446#define usbGetReceiveStatusI(usbp, ep) \
447 (((usbp)->receiving & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U)
461#define usbGetReceiveTransactionSizeX(usbp, ep) \
462 usb_lld_get_transaction_size(usbp, ep)
476#define usbSetupTransfer(usbp, buf, n, endcb) { \
477 (usbp)->ep0next = (buf); \
478 (usbp)->ep0n = (n); \
479 (usbp)->ep0endcb = (endcb); \
496#define usbReadSetup(usbp, ep, buf) usb_lld_read_setup(usbp, ep, buf)
511#define _usb_isr_invoke_event_cb(usbp, evt) { \
512 if (((usbp)->config->event_cb) != NULL) { \
513 (usbp)->config->event_cb(usbp, evt); \
524#define _usb_isr_invoke_sof_cb(usbp) { \
525 if (((usbp)->config->sof_cb) != NULL) { \
526 (usbp)->config->sof_cb(usbp); \
538#define _usb_isr_invoke_setup_cb(usbp, ep) { \
539 (usbp)->epc[ep]->setup_cb(usbp, ep); \
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); \
556 osalSysLockFromISR(); \
557 osalThreadResumeI(&(usbp)->epc[ep]->in_state->thread, MSG_OK); \
558 osalSysUnlockFromISR(); \
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); \
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); \
583 osalSysLockFromISR(); \
584 osalThreadResumeI(&(usbp)->epc[ep]->out_state->thread, \
585 usbGetReceiveTransactionSizeX(usbp, ep)); \
586 osalSysUnlockFromISR(); \
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); \
614 uint8_t *buf,
size_t n);
616 const uint8_t *buf,
size_t n);
617#if USB_USE_WAIT == TRUE
int32_t msg_t
Type of a message.
uint8_t usbep_t
Type of an endpoint identifier.
void _usb_suspend(USBDriver *usbp)
USB suspend routine.
usbepstatus_t
Type of an endpoint status.
void usbDisableEndpointsI(USBDriver *usbp)
Disables all the active endpoints.
bool(* usbreqhandler_t)(USBDriver *usbp)
Type of a requests handler callback.
msg_t usbTransmit(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n)
Performs a transmit transaction on an IN endpoint.
void usbStartReceiveI(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n)
Starts a receive transaction on an OUT endpoint.
void _usb_wakeup(USBDriver *usbp)
USB wake-up routine.
void usbInit(void)
USB Driver initialization.
bool usbStallTransmitI(USBDriver *usbp, usbep_t ep)
Stalls an IN endpoint.
msg_t usbReceive(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n)
Performs a receive transaction on an OUT endpoint.
usbep0state_t
Type of an endpoint zero state machine states.
void(* usbepcallback_t)(USBDriver *usbp, usbep_t ep)
Type of an USB endpoint callback.
void _usb_ep0setup(USBDriver *usbp, usbep_t ep)
Default EP0 SETUP callback.
void usbStartTransmitI(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n)
Starts a transmit transaction on an IN endpoint.
msg_t usbStart(USBDriver *usbp, const USBConfig *config)
Configures and activates the USB peripheral.
void usbInitEndpointI(USBDriver *usbp, usbep_t ep, const USBEndpointConfig *epcp)
Enables an endpoint.
void(* usbeventcb_t)(USBDriver *usbp, usbevent_t event)
Type of an USB event notification callback.
void usbStop(USBDriver *usbp)
Deactivates the USB peripheral.
void _usb_ep0in(USBDriver *usbp, usbep_t ep)
Default EP0 IN callback.
void _usb_reset(USBDriver *usbp)
USB reset routine.
void(* usbcallback_t)(USBDriver *usbp)
Type of an USB generic notification callback.
void usbWakeupHost(USBDriver *usbp)
Host wake-up procedure.
usbevent_t
Type of an enumeration of the possible USB events.
void usbObjectInit(USBDriver *usbp)
Initializes the standard part of a USBDriver structure.
void usbReadSetupI(USBDriver *usbp, usbep_t ep, uint8_t *buf)
usbstate_t
Type of a driver state machine possible states.
bool usbStallReceiveI(USBDriver *usbp, usbep_t ep)
Stalls an OUT endpoint.
void _usb_ep0out(USBDriver *usbp, usbep_t ep)
Default EP0 OUT callback.
@ USB_EP0_OUT_WAITING_STS
PLATFORM USB subsystem low level driver header.
Type of an USB driver configuration structure.
Type of an USB descriptor.
const uint8_t * ud_string
Pointer to the descriptor.
size_t ud_size
Descriptor size in unicode characters.
Structure representing an USB driver.
Type of an USB endpoint configuration structure.