29 #if (HAL_USE_USB == TRUE) || defined(__DOXYGEN__) 43 static const uint8_t zero_status[] = {0x00, 0x00};
44 static const uint8_t active_status[] ={0x00, 0x00};
45 static const uint8_t halted_status[] = {0x01, 0x00};
51 static uint16_t get_hword(uint8_t *p) {
55 hw |= (uint16_t)*p << 8U;
88 switch ((((uint32_t)usbp->
setup[0] & (USB_RTYPE_RECIPIENT_MASK |
89 USB_RTYPE_TYPE_MASK)) |
90 ((uint32_t)usbp->
setup[1] << 8U))) {
91 case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_GET_STATUS << 8):
95 case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_CLEAR_FEATURE << 8):
98 if (usbp->
setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) {
104 case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_FEATURE << 8):
107 if (usbp->
setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) {
113 case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_ADDRESS << 8):
117 #if USB_SET_ADDRESS_MODE == USB_EARLY_SET_ADDRESS 118 if ((usbp->
setup[0] == USB_RTYPE_RECIPIENT_DEVICE) &&
119 (usbp->
setup[1] == USB_REQ_SET_ADDRESS)) {
127 case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_GET_DESCRIPTOR << 8):
128 case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_GET_DESCRIPTOR << 8):
132 get_hword(&usbp->
setup[4]));
140 case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_GET_CONFIGURATION << 8):
144 case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_CONFIGURATION << 8):
145 #if defined(USB_SET_CONFIGURATION_OLD_BEHAVIOR) 162 if (usbp->
setup[2] != 0U) {
171 case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_GET_STATUS << 8):
172 case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_SYNCH_FRAME << 8):
179 case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_GET_STATUS << 8):
181 if ((usbp->
setup[4] & 0x80U) != 0U) {
215 case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_CLEAR_FEATURE << 8):
217 if (usbp->
setup[2] != USB_FEATURE_ENDPOINT_HALT) {
221 if ((usbp->
setup[4] & 0x0FU) != 0U) {
222 if ((usbp->
setup[4] & 0x80U) != 0U) {
231 case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_SET_FEATURE << 8):
233 if (usbp->
setup[2] != USB_FEATURE_ENDPOINT_HALT) {
237 if ((usbp->
setup[4] & 0x0FU) != 0U) {
238 if ((usbp->
setup[4] & 0x80U) != 0U) {
247 case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_DESCRIPTOR << 8):
248 case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_CLEAR_FEATURE << 8):
249 case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_SET_FEATURE << 8):
250 case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_GET_INTERFACE << 8):
251 case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_SET_INTERFACE << 8):
345 #if USB_USE_WAIT == TRUE 346 if (usbp->
epc[i] != NULL) {
385 usbp->
epc[ep] = epcp;
421 #if USB_USE_WAIT == TRUE 423 if (usbp->
epc[i] != NULL) {
454 uint8_t *buf,
size_t n) {
462 usbp->
receiving |= (uint16_t)((
unsigned)1U << (unsigned)ep);
471 #if USB_USE_WAIT == TRUE 493 const uint8_t *buf,
size_t n) {
501 usbp->
transmitting |= (uint16_t)((
unsigned)1U << (unsigned)ep);
510 #if USB_USE_WAIT == TRUE 518 #if (USB_USE_WAIT == TRUE) || defined(__DOXYGEN__) 678 #if USB_USE_WAIT == TRUE 680 if (usbp->
epc[i] != NULL) {
724 #if USB_USE_WAIT == TRUE 729 if (usbp->
epc[i] != NULL) {
797 if (((usbp->
setup[0] & USB_RTYPE_TYPE_MASK) != USB_RTYPE_TYPE_STD) ||
810 #if (USB_SET_ADDRESS_ACK_HANDLING == USB_SET_ADDRESS_ACK_HW) 811 if (usbp->
setup[1] == USB_REQ_SET_ADDRESS) {
819 max = (size_t)get_hword(&usbp->
setup[6]);
821 if (usbp->
ep0n > max) {
824 if ((usbp->
setup[0] & USB_RTYPE_DIR_MASK) == USB_RTYPE_DIR_DEV2HOST) {
826 if (usbp->
ep0n != 0U) {
837 #if (USB_EP0_STATUS_STAGE == USB_EP0_STATUS_STAGE_SW) 842 usb_lld_end_setup(usbp, ep);
848 if (usbp->
ep0n != 0U) {
859 #if (USB_EP0_STATUS_STAGE == USB_EP0_STATUS_STAGE_SW) 864 usb_lld_end_setup(usbp, ep);
886 max = (size_t)get_hword(&usbp->
setup[6]);
890 if ((usbp->
ep0n < max) &&
902 #if (USB_EP0_STATUS_STAGE == USB_EP0_STATUS_STAGE_SW) 907 usb_lld_end_setup(usbp, ep);
954 #if (USB_EP0_STATUS_STAGE == USB_EP0_STATUS_STAGE_SW) 959 usb_lld_end_setup(usbp, ep);
965 #if (USB_EP0_STATUS_STAGE == USB_EP0_STATUS_STAGE_SW) USBOutEndpointState * out_state
USBEndpointState associated to the OUT endpoint.
static void set_address(USBDriver *usbp)
SET ADDRESS transaction callback.
uint16_t in_maxsize
IN endpoint maximum packet size.
void usbDisableEndpointsI(USBDriver *usbp)
Disables all the active endpoints.
void _usb_suspend(USBDriver *usbp)
USB suspend routine.
void _usb_ep0setup(USBDriver *usbp, usbep_t ep)
Default EP0 SETUP callback.
Type of an OUT endpoint state structure.
msg_t osalThreadSuspendS(thread_reference_t *trp)
Sends the current thread sleeping and sets a reference variable.
void usbWakeupHost(USBDriver *usbp)
Host wake-up procedure.
void usb_lld_init(void)
Low level USB driver initialization.
usbstate_t state
Driver state.
size_t rxcnt
Received bytes so far.
const USBEndpointConfig * epc[USB_MAX_ENDPOINTS+1]
Active endpoints configurations.
uint8_t setup[8]
Setup packet buffer.
void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep)
Enables an endpoint.
void usb_lld_clear_out(USBDriver *usbp, usbep_t ep)
Brings an OUT endpoint in the active state.
size_t txsize
Requested transmit transfer size.
#define usb_lld_wakeup_host(usbp)
Start of host wake-up procedure.
size_t ud_size
Descriptor size in unicode characters.
void usb_lld_clear_in(USBDriver *usbp, usbep_t ep)
Brings an IN endpoint in the active state.
#define usbGetReceiveStatusI(usbp, ep)
Returns the status of an OUT endpoint.
void usb_lld_start(USBDriver *usbp)
Configures and activates the USB peripheral.
#define osalDbgCheckClassI()
I-Class state check.
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.
static void osalSysLockFromISR(void)
Enters a critical zone from ISR context.
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
void usb_lld_stall_in(USBDriver *usbp, usbep_t ep)
Brings an IN endpoint in the stalled state.
void osalOsRescheduleS(void)
Checks if a reschedule is required and performs it.
uint8_t configuration
Current USB device configuration.
void usb_lld_start_in(USBDriver *usbp, usbep_t ep)
Starts a transmit operation on an IN endpoint.
const USBConfig * config
Current configuration data.
Structure representing an USB driver.
uint8_t address
Assigned USB address.
void * out_params[USB_MAX_ENDPOINTS]
Fields available to user, it can be used to associate an application-defined handler to an OUT endpoi...
size_t ep0n
Number of bytes yet to be transferred through endpoint 0.
int32_t msg_t
Type of a message.
void usb_lld_stall_out(USBDriver *usbp, usbep_t ep)
Brings an OUT endpoint in the stalled state.
uint16_t receiving
Bit map of the receiving OUT endpoints.
#define usbGetDriverStateI(usbp)
Returns the driver state.
msg_t usbTransmit(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n)
Performs a transmit transaction on an IN endpoint.
thread_reference_t thread
Waiting thread.
const uint8_t * txbuf
Pointer to the transmission linear buffer.
#define usbGetTransmitStatusI(usbp, ep)
Returns the status of an IN endpoint.
void usbInit(void)
USB Driver initialization.
usbreqhandler_t requests_hook_cb
Requests hook callback.
uint8_t * rxbuf
Pointer to the receive linear buffer.
void usbStartReceiveI(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n)
Starts a receive transaction on an OUT endpoint.
#define _usb_isr_invoke_event_cb(usbp, evt)
Common ISR code, usb event callback.
void _usb_ep0in(USBDriver *usbp, usbep_t ep)
Default EP0 IN callback.
size_t txcnt
Transmitted bytes so far.
void _usb_wakeup(USBDriver *usbp)
USB wake-up routine.
#define osalDbgCheck(c)
Function parameters check.
void usb_lld_reset(USBDriver *usbp)
USB low level reset routine.
size_t rxsize
Requested receive transfer size.
static void osalSysUnlockFromISR(void)
Leaves a critical zone from ISR context.
void _usb_ep0out(USBDriver *usbp, usbep_t ep)
Default EP0 OUT callback.
uint16_t transmitting
Bit map of the transmitting IN endpoints.
void usbStop(USBDriver *usbp)
Deactivates the USB peripheral.
const uint8_t * ud_string
Pointer to the descriptor.
bool usbStallTransmitI(USBDriver *usbp, usbep_t ep)
Stalls an IN endpoint.
void usbInitEndpointI(USBDriver *usbp, usbep_t ep, const USBEndpointConfig *epcp)
Enables an endpoint.
usbepstatus_t usb_lld_get_status_out(USBDriver *usbp, usbep_t ep)
Returns the status of an OUT endpoint.
void * in_params[USB_MAX_ENDPOINTS]
Fields available to user, it can be used to associate an application-defined handler to an IN endpoin...
uint16_t status
Current USB device status.
#define usbReadSetup(usbp, ep, buf)
Reads a setup packet from the dedicated packet buffer.
void _usb_reset(USBDriver *usbp)
USB reset routine.
void usbStart(USBDriver *usbp, const USBConfig *config)
Configures and activates the USB peripheral.
Type of an IN endpoint state structure.
static void osalSysLock(void)
Enters a critical zone from thread context.
static bool default_handler(USBDriver *usbp)
Standard requests handler.
uint8_t * ep0next
Next position in the buffer to be transferred through endpoint 0.
usbgetdescriptor_t get_descriptor_cb
Device GET_DESCRIPTOR request callback.
usbcallback_t ep0endcb
Endpoint 0 end transaction callback.
usbepstatus_t usb_lld_get_status_in(USBDriver *usbp, usbep_t ep)
Returns the status of an IN endpoint.
bool usbStallReceiveI(USBDriver *usbp, usbep_t ep)
Stalls an OUT endpoint.
#define osalDbgAssert(c, remark)
Condition assertion.
Type of an USB descriptor.
uint8_t usbep_t
Type of an endpoint identifier.
Type of an USB driver configuration structure.
void osalThreadResumeI(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
void usbStartTransmitI(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n)
Starts a transmit transaction on an IN endpoint.
void usb_lld_stop(USBDriver *usbp)
Deactivates the USB peripheral.
msg_t usbReceive(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n)
Performs a receive transaction on an OUT endpoint.
Type of an USB endpoint configuration structure.
void usbObjectInit(USBDriver *usbp)
Initializes the standard part of a USBDriver structure.
#define usbSetupTransfer(usbp, buf, n, endcb)
Request transfer setup.
usbstate_t saved_state
State of the driver when a suspend happened.
USBInEndpointState * in_state
USBEndpointState associated to the IN endpoint.
thread_reference_t thread
Waiting thread.
void usb_lld_set_address(USBDriver *usbp)
Sets the USB address.
usbep0state_t ep0state
Endpoint 0 state.
#define usbGetReceiveTransactionSizeX(usbp, ep)
Returns the exact size of a receive transaction.
#define USB_MAX_ENDPOINTS
Maximum endpoint address.