ChibiOS/HAL 9.0.0
USB Driver

Generic USB Driver. More...

Detailed Description

Generic USB Driver.

This module implements a generic USB (Universal Serial Bus) driver supporting device-mode operations.

Precondition
In order to use the USB driver the HAL_USE_USB option must be enabled in halconf.h.

Driver State Machine

The driver implements a state machine internally, not all the driver functionalities can be used in any moment, any transition not explicitly shown in the following diagram has to be considered an error and shall be captured by an assertion (if enabled).

dot_inline_dotgraph_18.png

USB Operations

The USB driver is quite complex and USB is complex in itself, it is recommended to study the USB specification before trying to use the driver.

USB Implementation

The USB driver abstracts the inner details of the underlying USB hardware. The driver works asynchronously and communicates with the application using callbacks. The application is responsible of the descriptors and strings required by the USB device class to be implemented and of the handling of the specific messages sent over the endpoint zero. Standard messages are handled internally to the driver. The application can use hooks in order to handle custom messages or override the handling of the default handling of standard messages.

USB Endpoints

USB endpoints are the objects that the application uses to exchange data with the host. There are two kind of endpoints:

  • IN endpoints are used by the application to transmit data to the host.
  • OUT endpoints are used by the application to receive data from the host.

The driver invokes a callback after finishing an IN or OUT transaction. States diagram for OUT endpoints in transaction mode:

dot_inline_dotgraph_19.png



States diagram for IN endpoints in transaction mode:

dot_inline_dotgraph_20.png



USB Callbacks

The USB driver uses callbacks in order to interact with the application. There are several kinds of callbacks to be handled:

  • Driver events callback. As example errors, suspend event, reset event etc.
  • Messages Hook callback. This hook allows the application to implement handling of custom messages or to override the default handling of standard messages on endpoint zero.
  • Descriptor Requested callback. When the driver endpoint zero handler receives a GET DESCRIPTOR message and needs to send a descriptor to the host it queries the application using this callback.
  • Start of Frame callback. This callback is invoked each time a SOF packet is received.
  • Endpoint callbacks. Each endpoint informs the application about I/O conditions using those callbacks.
Collaboration diagram for USB Driver:

Helper macros for USB descriptors

#define USB_DESC_INDEX(i)
 Helper macro for index values into descriptor strings.
#define USB_DESC_BYTE(b)
 Helper macro for byte values into descriptor strings.
#define USB_DESC_WORD(w)
 Helper macro for word values into descriptor strings.
#define USB_DESC_BCD(bcd)
 Helper macro for BCD values into descriptor strings.
#define USB_DESC_DEVICE_SIZE   18U
#define USB_DESC_DEVICE(bcdUSB, bDeviceClass, bDeviceSubClass, bDeviceProtocol, bMaxPacketSize, idVendor, idProduct, bcdDevice, iManufacturer, iProduct, iSerialNumber, bNumConfigurations)
 Device Descriptor helper macro.
#define USB_DESC_CONFIGURATION_SIZE   9U
 Configuration Descriptor size.
#define USB_DESC_CONFIGURATION(wTotalLength, bNumInterfaces, bConfigurationValue, iConfiguration, bmAttributes, bMaxPower)
 Configuration Descriptor helper macro.
#define USB_DESC_INTERFACE_SIZE   9U
 Interface Descriptor size.
#define USB_DESC_INTERFACE(bInterfaceNumber, bAlternateSetting, bNumEndpoints, bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol, iInterface)
 Interface Descriptor helper macro.
#define USB_DESC_INTERFACE_ASSOCIATION_SIZE   8U
 Interface Association Descriptor size.
#define USB_DESC_INTERFACE_ASSOCIATION(bFirstInterface, bInterfaceCount, bFunctionClass, bFunctionSubClass, bFunctionProcotol, iInterface)
 Interface Association Descriptor helper macro.
#define USB_DESC_ENDPOINT_SIZE   7U
 Endpoint Descriptor size.
#define USB_DESC_ENDPOINT(bEndpointAddress, bmAttributes, wMaxPacketSize, bInterval)
 Endpoint Descriptor helper macro.

Endpoint types and settings

#define USB_EP_MODE_TYPE   0x0003U
#define USB_EP_MODE_TYPE_CTRL   0x0000U
#define USB_EP_MODE_TYPE_ISOC   0x0001U
#define USB_EP_MODE_TYPE_BULK   0x0002U
#define USB_EP_MODE_TYPE_INTR   0x0003U

Macro Functions

#define usbGetDriverStateI(usbp)
 Returns the driver state.
#define usbConnectBus(usbp)
 Connects the USB device.
#define usbDisconnectBus(usbp)
 Disconnect the USB device.
#define usbGetFrameNumberX(usbp)
 Returns the current frame number.
#define usbGetTransmitStatusI(usbp, ep)
 Returns the status of an IN endpoint.
#define usbGetReceiveStatusI(usbp, ep)
 Returns the status of an OUT endpoint.
#define usbGetReceiveTransactionSizeX(usbp, ep)
 Returns the exact size of a receive transaction.
#define usbSetupTransfer(usbp, buf, n, endcb)
 Request transfer setup.
#define usbReadSetup(usbp, ep, buf)
 Reads a setup packet from the dedicated packet buffer.

Low level driver helper macros

#define _usb_isr_invoke_event_cb(usbp, evt)
 Common ISR code, usb event callback.
#define _usb_isr_invoke_sof_cb(usbp)
 Common ISR code, SOF callback.
#define _usb_isr_invoke_setup_cb(usbp, ep)
 Common ISR code, setup packet callback.
#define _usb_isr_invoke_in_cb(usbp, ep)
 Common ISR code, IN endpoint callback.
#define _usb_isr_invoke_out_cb(usbp, ep)
 Common ISR code, OUT endpoint event.

PLATFORM configuration options

#define PLATFORM_USB_USE_USB1   FALSE
 USB driver enable switch.

Data Structures

struct  USBDescriptor
 Type of an USB descriptor. More...
struct  USBInEndpointState
 Type of an IN endpoint state structure. More...
struct  USBOutEndpointState
 Type of an OUT endpoint state structure. More...
struct  USBEndpointConfig
 Type of an USB endpoint configuration structure. More...
struct  USBConfig
 Type of an USB driver configuration structure. More...
struct  USBDriver
 Structure representing an USB driver. More...

Macros

#define USB_ENDPOINT_OUT(ep)
#define USB_ENDPOINT_IN(ep)
#define USB_RTYPE_DIR_MASK   0x80U
#define USB_RTYPE_DIR_HOST2DEV   0x00U
#define USB_RTYPE_DIR_DEV2HOST   0x80U
#define USB_RTYPE_TYPE_MASK   0x60U
#define USB_RTYPE_TYPE_STD   0x00U
#define USB_RTYPE_TYPE_CLASS   0x20U
#define USB_RTYPE_TYPE_VENDOR   0x40U
#define USB_RTYPE_TYPE_RESERVED   0x60U
#define USB_RTYPE_RECIPIENT_MASK   0x1FU
#define USB_RTYPE_RECIPIENT_DEVICE   0x00U
#define USB_RTYPE_RECIPIENT_INTERFACE   0x01U
#define USB_RTYPE_RECIPIENT_ENDPOINT   0x02U
#define USB_RTYPE_RECIPIENT_OTHER   0x03U
#define USB_REQ_GET_STATUS   0U
#define USB_REQ_CLEAR_FEATURE   1U
#define USB_REQ_SET_FEATURE   3U
#define USB_REQ_SET_ADDRESS   5U
#define USB_REQ_GET_DESCRIPTOR   6U
#define USB_REQ_SET_DESCRIPTOR   7U
#define USB_REQ_GET_CONFIGURATION   8U
#define USB_REQ_SET_CONFIGURATION   9U
#define USB_REQ_GET_INTERFACE   10U
#define USB_REQ_SET_INTERFACE   11U
#define USB_REQ_SYNCH_FRAME   12U
#define USB_DESCRIPTOR_DEVICE   1U
#define USB_DESCRIPTOR_CONFIGURATION   2U
#define USB_DESCRIPTOR_STRING   3U
#define USB_DESCRIPTOR_INTERFACE   4U
#define USB_DESCRIPTOR_ENDPOINT   5U
#define USB_DESCRIPTOR_DEVICE_QUALIFIER   6U
#define USB_DESCRIPTOR_OTHER_SPEED_CFG   7U
#define USB_DESCRIPTOR_INTERFACE_POWER   8U
#define USB_DESCRIPTOR_INTERFACE_ASSOCIATION   11U
#define USB_FEATURE_ENDPOINT_HALT   0U
#define USB_FEATURE_DEVICE_REMOTE_WAKEUP   1U
#define USB_FEATURE_TEST_MODE   2U
#define USB_EARLY_SET_ADDRESS   0
#define USB_LATE_SET_ADDRESS   1
#define USB_EP0_STATUS_STAGE_SW   0
#define USB_EP0_STATUS_STAGE_HW   1
#define USB_SET_ADDRESS_ACK_SW   0
#define USB_SET_ADDRESS_ACK_HW   1
#define USB_IN_STATE   0x08U
#define USB_OUT_STATE   0x10U
#define USB_USE_WAIT   FALSE
 Enables synchronous APIs.
#define USB_MAX_ENDPOINTS   4
 Maximum endpoint address.
#define USB_EP0_STATUS_STAGE   USB_EP0_STATUS_STAGE_SW
 Status stage handling method.
#define USB_SET_ADDRESS_MODE   USB_LATE_SET_ADDRESS
 The address can be changed immediately upon packet reception.
#define USB_SET_ADDRESS_ACK_HANDLING   USB_SET_ADDRESS_ACK_SW
 Method for set address acknowledge.
#define usb_lld_get_frame_number(usbp)
 Returns the current frame number.
#define usb_lld_get_transaction_size(usbp, ep)
 Returns the exact size of a receive transaction.
#define usb_lld_connect_bus(usbp)
 Connects the USB device.
#define usb_lld_disconnect_bus(usbp)
 Disconnect the USB device.
#define usb_lld_wakeup_host(usbp)
 Start of host wake-up procedure.

Typedefs

typedef struct USBDriver USBDriver
 Type of a structure representing an USB driver.
typedef uint8_t usbep_t
 Type of an endpoint identifier.
typedef void(* usbcallback_t) (USBDriver *usbp)
 Type of an USB generic notification callback.
typedef void(* usbepcallback_t) (USBDriver *usbp, usbep_t ep)
 Type of an USB endpoint callback.
typedef void(* usbeventcb_t) (USBDriver *usbp, usbevent_t event)
 Type of an USB event notification callback.
typedef bool(* usbreqhandler_t) (USBDriver *usbp)
 Type of a requests handler callback.
typedef const USBDescriptor *(* usbgetdescriptor_t) (USBDriver *usbp, uint8_t dtype, uint8_t dindex, uint16_t lang)
 Type of an USB descriptor-retrieving callback.

Enumerations

enum  usbstate_t {
  USB_UNINIT = 0 , USB_STOP = 1 , USB_READY = 2 , USB_SELECTED = 3 ,
  USB_ACTIVE = 4 , USB_SUSPENDED = 5
}
 Type of a driver state machine possible states. More...
enum  usbepstatus_t { EP_STATUS_DISABLED = 0 , EP_STATUS_STALLED = 1 , EP_STATUS_ACTIVE = 2 }
 Type of an endpoint status. More...
enum  usbep0state_t {
  USB_EP0_STP_WAITING = 0U , USB_EP0_IN_TX = USB_IN_STATE | 1U , USB_EP0_IN_WAITING_TX0 = USB_IN_STATE | 2U , USB_EP0_IN_SENDING_STS = USB_IN_STATE | 3U ,
  USB_EP0_OUT_WAITING_STS = USB_OUT_STATE | 4U , USB_EP0_OUT_RX = USB_OUT_STATE | 5U , USB_EP0_ERROR = 6U
}
 Type of an endpoint zero state machine states. More...
enum  usbevent_t {
  USB_EVENT_RESET = 0 , USB_EVENT_ADDRESS = 1 , USB_EVENT_CONFIGURED = 2 , USB_EVENT_UNCONFIGURED = 3 ,
  USB_EVENT_SUSPEND = 4 , USB_EVENT_WAKEUP = 5 , USB_EVENT_STALLED = 6
}
 Type of an enumeration of the possible USB events. More...

Functions

static uint16_t get_hword (uint8_t *p)
static void set_address (USBDriver *usbp)
 SET ADDRESS transaction callback.
static bool default_handler (USBDriver *usbp)
 Standard requests handler.
void usbInit (void)
 USB Driver initialization.
void usbObjectInit (USBDriver *usbp)
 Initializes the standard part of a USBDriver structure.
msg_t usbStart (USBDriver *usbp, const USBConfig *config)
 Configures and activates the USB peripheral.
void usbStop (USBDriver *usbp)
 Deactivates the USB peripheral.
void usbInitEndpointI (USBDriver *usbp, usbep_t ep, const USBEndpointConfig *epcp)
 Enables an endpoint.
void usbDisableEndpointsI (USBDriver *usbp)
 Disables all the active endpoints.
void usbStartReceiveI (USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n)
 Starts a receive transaction on an OUT endpoint.
void usbStartTransmitI (USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n)
 Starts a transmit transaction on 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.
msg_t usbTransmit (USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n)
 Performs a transmit transaction on an IN endpoint.
bool usbStallReceiveI (USBDriver *usbp, usbep_t ep)
 Stalls an OUT endpoint.
bool usbStallTransmitI (USBDriver *usbp, usbep_t ep)
 Stalls an IN endpoint.
void usbWakeupHost (USBDriver *usbp)
 Host wake-up procedure.
void _usb_reset (USBDriver *usbp)
 USB reset routine.
void _usb_suspend (USBDriver *usbp)
 USB suspend routine.
void _usb_wakeup (USBDriver *usbp)
 USB wake-up routine.
void _usb_ep0setup (USBDriver *usbp, usbep_t ep)
 Default EP0 SETUP callback.
void _usb_ep0in (USBDriver *usbp, usbep_t ep)
 Default EP0 IN callback.
void _usb_ep0out (USBDriver *usbp, usbep_t ep)
 Default EP0 OUT callback.
void usbReadSetupI (USBDriver *usbp, usbep_t ep, uint8_t *buf)
void usb_lld_init (void)
 Low level USB driver initialization.
void usb_lld_start (USBDriver *usbp)
 Configures and activates the USB peripheral.
void usb_lld_stop (USBDriver *usbp)
 Deactivates the USB peripheral.
void usb_lld_reset (USBDriver *usbp)
 USB low level reset routine.
void usb_lld_set_address (USBDriver *usbp)
 Sets the USB address.
void usb_lld_init_endpoint (USBDriver *usbp, usbep_t ep)
 Enables an endpoint.
void usb_lld_disable_endpoints (USBDriver *usbp)
 Disables all the active endpoints except the endpoint zero.
usbepstatus_t usb_lld_get_status_out (USBDriver *usbp, usbep_t ep)
 Returns the status of an OUT endpoint.
usbepstatus_t usb_lld_get_status_in (USBDriver *usbp, usbep_t ep)
 Returns the status of 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_lld_prepare_receive (USBDriver *usbp, usbep_t ep)
 Prepares for a receive operation.
void usb_lld_prepare_transmit (USBDriver *usbp, usbep_t ep)
 Prepares for a transmit operation.
void usb_lld_start_out (USBDriver *usbp, usbep_t ep)
 Starts a receive operation on an OUT endpoint.
void usb_lld_start_in (USBDriver *usbp, usbep_t ep)
 Starts a transmit operation on an IN endpoint.
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 usb_lld_clear_out (USBDriver *usbp, usbep_t ep)
 Brings an OUT endpoint in the active state.
void usb_lld_clear_in (USBDriver *usbp, usbep_t ep)
 Brings an IN endpoint in the active state.

Variables

static const uint8_t zero_status [] = {0x00, 0x00}
static const uint8_t active_status [] = {0x00, 0x00}
static const uint8_t halted_status [] = {0x01, 0x00}
USBDriver USBD1
 USB1 driver identifier.
union { 
   USBInEndpointState   in 
 IN EP0 state. More...
   USBOutEndpointState   out 
 OUT EP0 state. More...
ep0_state
 EP0 state.
static const USBEndpointConfig ep0config
 EP0 initialization structure.

Macro Definition Documentation

◆ USB_ENDPOINT_OUT

#define USB_ENDPOINT_OUT ( ep)
Value:
(ep)

Definition at line 34 of file hal_usb.h.

◆ USB_ENDPOINT_IN

#define USB_ENDPOINT_IN ( ep)
Value:
((ep) | 0x80U)

Definition at line 35 of file hal_usb.h.

◆ USB_RTYPE_DIR_MASK

#define USB_RTYPE_DIR_MASK   0x80U

Definition at line 37 of file hal_usb.h.

Referenced by _usb_ep0setup().

◆ USB_RTYPE_DIR_HOST2DEV

#define USB_RTYPE_DIR_HOST2DEV   0x00U

Definition at line 38 of file hal_usb.h.

◆ USB_RTYPE_DIR_DEV2HOST

#define USB_RTYPE_DIR_DEV2HOST   0x80U

Definition at line 39 of file hal_usb.h.

Referenced by _usb_ep0setup().

◆ USB_RTYPE_TYPE_MASK

#define USB_RTYPE_TYPE_MASK   0x60U

Definition at line 40 of file hal_usb.h.

Referenced by _usb_ep0setup(), default_handler(), and sduRequestsHook().

◆ USB_RTYPE_TYPE_STD

#define USB_RTYPE_TYPE_STD   0x00U

Definition at line 41 of file hal_usb.h.

Referenced by _usb_ep0setup().

◆ USB_RTYPE_TYPE_CLASS

#define USB_RTYPE_TYPE_CLASS   0x20U

Definition at line 42 of file hal_usb.h.

Referenced by sduRequestsHook().

◆ USB_RTYPE_TYPE_VENDOR

#define USB_RTYPE_TYPE_VENDOR   0x40U

Definition at line 43 of file hal_usb.h.

◆ USB_RTYPE_TYPE_RESERVED

#define USB_RTYPE_TYPE_RESERVED   0x60U

Definition at line 44 of file hal_usb.h.

◆ USB_RTYPE_RECIPIENT_MASK

#define USB_RTYPE_RECIPIENT_MASK   0x1FU

Definition at line 45 of file hal_usb.h.

Referenced by default_handler().

◆ USB_RTYPE_RECIPIENT_DEVICE

#define USB_RTYPE_RECIPIENT_DEVICE   0x00U

Definition at line 46 of file hal_usb.h.

Referenced by default_handler().

◆ USB_RTYPE_RECIPIENT_INTERFACE

#define USB_RTYPE_RECIPIENT_INTERFACE   0x01U

Definition at line 47 of file hal_usb.h.

Referenced by default_handler().

◆ USB_RTYPE_RECIPIENT_ENDPOINT

#define USB_RTYPE_RECIPIENT_ENDPOINT   0x02U

Definition at line 48 of file hal_usb.h.

Referenced by default_handler().

◆ USB_RTYPE_RECIPIENT_OTHER

#define USB_RTYPE_RECIPIENT_OTHER   0x03U

Definition at line 49 of file hal_usb.h.

◆ USB_REQ_GET_STATUS

#define USB_REQ_GET_STATUS   0U

Definition at line 51 of file hal_usb.h.

Referenced by default_handler().

◆ USB_REQ_CLEAR_FEATURE

#define USB_REQ_CLEAR_FEATURE   1U

Definition at line 52 of file hal_usb.h.

Referenced by default_handler().

◆ USB_REQ_SET_FEATURE

#define USB_REQ_SET_FEATURE   3U

Definition at line 53 of file hal_usb.h.

Referenced by default_handler().

◆ USB_REQ_SET_ADDRESS

#define USB_REQ_SET_ADDRESS   5U

Definition at line 54 of file hal_usb.h.

Referenced by _usb_ep0setup(), and default_handler().

◆ USB_REQ_GET_DESCRIPTOR

#define USB_REQ_GET_DESCRIPTOR   6U

Definition at line 55 of file hal_usb.h.

Referenced by default_handler().

◆ USB_REQ_SET_DESCRIPTOR

#define USB_REQ_SET_DESCRIPTOR   7U

Definition at line 56 of file hal_usb.h.

Referenced by default_handler().

◆ USB_REQ_GET_CONFIGURATION

#define USB_REQ_GET_CONFIGURATION   8U

Definition at line 57 of file hal_usb.h.

Referenced by default_handler().

◆ USB_REQ_SET_CONFIGURATION

#define USB_REQ_SET_CONFIGURATION   9U

Definition at line 58 of file hal_usb.h.

Referenced by default_handler().

◆ USB_REQ_GET_INTERFACE

#define USB_REQ_GET_INTERFACE   10U

Definition at line 59 of file hal_usb.h.

Referenced by default_handler().

◆ USB_REQ_SET_INTERFACE

#define USB_REQ_SET_INTERFACE   11U

Definition at line 60 of file hal_usb.h.

Referenced by default_handler().

◆ USB_REQ_SYNCH_FRAME

#define USB_REQ_SYNCH_FRAME   12U

Definition at line 61 of file hal_usb.h.

Referenced by default_handler().

◆ USB_DESCRIPTOR_DEVICE

#define USB_DESCRIPTOR_DEVICE   1U

Definition at line 63 of file hal_usb.h.

◆ USB_DESCRIPTOR_CONFIGURATION

#define USB_DESCRIPTOR_CONFIGURATION   2U

Definition at line 64 of file hal_usb.h.

◆ USB_DESCRIPTOR_STRING

#define USB_DESCRIPTOR_STRING   3U

Definition at line 65 of file hal_usb.h.

◆ USB_DESCRIPTOR_INTERFACE

#define USB_DESCRIPTOR_INTERFACE   4U

Definition at line 66 of file hal_usb.h.

◆ USB_DESCRIPTOR_ENDPOINT

#define USB_DESCRIPTOR_ENDPOINT   5U

Definition at line 67 of file hal_usb.h.

◆ USB_DESCRIPTOR_DEVICE_QUALIFIER

#define USB_DESCRIPTOR_DEVICE_QUALIFIER   6U

Definition at line 68 of file hal_usb.h.

◆ USB_DESCRIPTOR_OTHER_SPEED_CFG

#define USB_DESCRIPTOR_OTHER_SPEED_CFG   7U

Definition at line 69 of file hal_usb.h.

◆ USB_DESCRIPTOR_INTERFACE_POWER

#define USB_DESCRIPTOR_INTERFACE_POWER   8U

Definition at line 70 of file hal_usb.h.

◆ USB_DESCRIPTOR_INTERFACE_ASSOCIATION

#define USB_DESCRIPTOR_INTERFACE_ASSOCIATION   11U

Definition at line 71 of file hal_usb.h.

◆ USB_FEATURE_ENDPOINT_HALT

#define USB_FEATURE_ENDPOINT_HALT   0U

Definition at line 73 of file hal_usb.h.

Referenced by default_handler().

◆ USB_FEATURE_DEVICE_REMOTE_WAKEUP

#define USB_FEATURE_DEVICE_REMOTE_WAKEUP   1U

Definition at line 74 of file hal_usb.h.

Referenced by default_handler().

◆ USB_FEATURE_TEST_MODE

#define USB_FEATURE_TEST_MODE   2U

Definition at line 75 of file hal_usb.h.

◆ USB_EARLY_SET_ADDRESS

#define USB_EARLY_SET_ADDRESS   0

Definition at line 77 of file hal_usb.h.

◆ USB_LATE_SET_ADDRESS

#define USB_LATE_SET_ADDRESS   1

Definition at line 78 of file hal_usb.h.

◆ USB_EP0_STATUS_STAGE_SW

#define USB_EP0_STATUS_STAGE_SW   0

Definition at line 80 of file hal_usb.h.

◆ USB_EP0_STATUS_STAGE_HW

#define USB_EP0_STATUS_STAGE_HW   1

Definition at line 81 of file hal_usb.h.

◆ USB_SET_ADDRESS_ACK_SW

#define USB_SET_ADDRESS_ACK_SW   0

Definition at line 83 of file hal_usb.h.

◆ USB_SET_ADDRESS_ACK_HW

#define USB_SET_ADDRESS_ACK_HW   1

Definition at line 84 of file hal_usb.h.

◆ USB_DESC_INDEX

#define USB_DESC_INDEX ( i)
Value:
((uint8_t)(i))

Helper macro for index values into descriptor strings.

Definition at line 93 of file hal_usb.h.

◆ USB_DESC_BYTE

#define USB_DESC_BYTE ( b)
Value:
((uint8_t)(b))

Helper macro for byte values into descriptor strings.

Definition at line 98 of file hal_usb.h.

◆ USB_DESC_WORD

#define USB_DESC_WORD ( w)
Value:
(uint8_t)((w) & 255U), \
(uint8_t)(((w) >> 8) & 255U)

Helper macro for word values into descriptor strings.

Definition at line 103 of file hal_usb.h.

◆ USB_DESC_BCD

#define USB_DESC_BCD ( bcd)
Value:
(uint8_t)((bcd) & 255U), \
(uint8_t)(((bcd) >> 8) & 255)

Helper macro for BCD values into descriptor strings.

Definition at line 110 of file hal_usb.h.

◆ USB_DESC_DEVICE_SIZE

#define USB_DESC_DEVICE_SIZE   18U

Definition at line 117 of file hal_usb.h.

◆ USB_DESC_DEVICE

#define USB_DESC_DEVICE ( bcdUSB,
bDeviceClass,
bDeviceSubClass,
bDeviceProtocol,
bMaxPacketSize,
idVendor,
idProduct,
bcdDevice,
iManufacturer,
iProduct,
iSerialNumber,
bNumConfigurations )
Value:
USB_DESC_BYTE(USB_DESCRIPTOR_DEVICE), \
USB_DESC_BCD(bcdUSB), \
USB_DESC_BYTE(bDeviceClass), \
USB_DESC_BYTE(bDeviceSubClass), \
USB_DESC_BYTE(bDeviceProtocol), \
USB_DESC_BYTE(bMaxPacketSize), \
USB_DESC_WORD(idVendor), \
USB_DESC_WORD(idProduct), \
USB_DESC_BCD(bcdDevice), \
USB_DESC_INDEX(iManufacturer), \
USB_DESC_INDEX(iProduct), \
USB_DESC_INDEX(iSerialNumber), \
USB_DESC_BYTE(bNumConfigurations)
#define USB_DESC_DEVICE_SIZE
Definition hal_usb.h:117
#define USB_DESCRIPTOR_DEVICE
Definition hal_usb.h:63
#define USB_DESC_BYTE(b)
Helper macro for byte values into descriptor strings.
Definition hal_usb.h:98

Device Descriptor helper macro.

Definition at line 122 of file hal_usb.h.

◆ USB_DESC_CONFIGURATION_SIZE

#define USB_DESC_CONFIGURATION_SIZE   9U

Configuration Descriptor size.

Definition at line 144 of file hal_usb.h.

◆ USB_DESC_CONFIGURATION

#define USB_DESC_CONFIGURATION ( wTotalLength,
bNumInterfaces,
bConfigurationValue,
iConfiguration,
bmAttributes,
bMaxPower )
Value:
USB_DESC_BYTE(USB_DESCRIPTOR_CONFIGURATION), \
USB_DESC_WORD(wTotalLength), \
USB_DESC_BYTE(bNumInterfaces), \
USB_DESC_BYTE(bConfigurationValue), \
USB_DESC_INDEX(iConfiguration), \
USB_DESC_BYTE(bmAttributes), \
USB_DESC_BYTE(bMaxPower)
#define USB_DESC_CONFIGURATION_SIZE
Configuration Descriptor size.
Definition hal_usb.h:144
#define USB_DESCRIPTOR_CONFIGURATION
Definition hal_usb.h:64

Configuration Descriptor helper macro.

Definition at line 149 of file hal_usb.h.

◆ USB_DESC_INTERFACE_SIZE

#define USB_DESC_INTERFACE_SIZE   9U

Interface Descriptor size.

Definition at line 164 of file hal_usb.h.

◆ USB_DESC_INTERFACE

#define USB_DESC_INTERFACE ( bInterfaceNumber,
bAlternateSetting,
bNumEndpoints,
bInterfaceClass,
bInterfaceSubClass,
bInterfaceProtocol,
iInterface )
Value:
USB_DESC_BYTE(USB_DESCRIPTOR_INTERFACE), \
USB_DESC_BYTE(bInterfaceNumber), \
USB_DESC_BYTE(bAlternateSetting), \
USB_DESC_BYTE(bNumEndpoints), \
USB_DESC_BYTE(bInterfaceClass), \
USB_DESC_BYTE(bInterfaceSubClass), \
USB_DESC_BYTE(bInterfaceProtocol), \
USB_DESC_INDEX(iInterface)
#define USB_DESCRIPTOR_INTERFACE
Definition hal_usb.h:66
#define USB_DESC_INTERFACE_SIZE
Interface Descriptor size.
Definition hal_usb.h:164

Interface Descriptor helper macro.

Definition at line 169 of file hal_usb.h.

◆ USB_DESC_INTERFACE_ASSOCIATION_SIZE

#define USB_DESC_INTERFACE_ASSOCIATION_SIZE   8U

Interface Association Descriptor size.

Definition at line 186 of file hal_usb.h.

◆ USB_DESC_INTERFACE_ASSOCIATION

#define USB_DESC_INTERFACE_ASSOCIATION ( bFirstInterface,
bInterfaceCount,
bFunctionClass,
bFunctionSubClass,
bFunctionProcotol,
iInterface )
Value:
USB_DESC_BYTE(bFirstInterface), \
USB_DESC_BYTE(bInterfaceCount), \
USB_DESC_BYTE(bFunctionClass), \
USB_DESC_BYTE(bFunctionSubClass), \
USB_DESC_BYTE(bFunctionProcotol), \
USB_DESC_INDEX(iInterface)
#define USB_DESCRIPTOR_INTERFACE_ASSOCIATION
Definition hal_usb.h:71
#define USB_DESC_INTERFACE_ASSOCIATION_SIZE
Interface Association Descriptor size.
Definition hal_usb.h:186

Interface Association Descriptor helper macro.

Definition at line 191 of file hal_usb.h.

◆ USB_DESC_ENDPOINT_SIZE

#define USB_DESC_ENDPOINT_SIZE   7U

Endpoint Descriptor size.

Definition at line 207 of file hal_usb.h.

◆ USB_DESC_ENDPOINT

#define USB_DESC_ENDPOINT ( bEndpointAddress,
bmAttributes,
wMaxPacketSize,
bInterval )
Value:
USB_DESC_BYTE(USB_DESCRIPTOR_ENDPOINT), \
USB_DESC_BYTE(bEndpointAddress), \
USB_DESC_BYTE(bmAttributes), \
USB_DESC_WORD(wMaxPacketSize), \
USB_DESC_BYTE(bInterval)
#define USB_DESC_ENDPOINT_SIZE
Endpoint Descriptor size.
Definition hal_usb.h:207
#define USB_DESCRIPTOR_ENDPOINT
Definition hal_usb.h:67

Endpoint Descriptor helper macro.

Definition at line 212 of file hal_usb.h.

◆ USB_EP_MODE_TYPE

#define USB_EP_MODE_TYPE   0x0003U

Endpoint type mask.

Definition at line 226 of file hal_usb.h.

◆ USB_EP_MODE_TYPE_CTRL

#define USB_EP_MODE_TYPE_CTRL   0x0000U

Control endpoint.

Definition at line 227 of file hal_usb.h.

◆ USB_EP_MODE_TYPE_ISOC

#define USB_EP_MODE_TYPE_ISOC   0x0001U

Isochronous endpoint.

Definition at line 228 of file hal_usb.h.

◆ USB_EP_MODE_TYPE_BULK

#define USB_EP_MODE_TYPE_BULK   0x0002U

Bulk endpoint.

Definition at line 229 of file hal_usb.h.

◆ USB_EP_MODE_TYPE_INTR

#define USB_EP_MODE_TYPE_INTR   0x0003U

Interrupt endpoint.

Definition at line 230 of file hal_usb.h.

◆ USB_IN_STATE

#define USB_IN_STATE   0x08U

Definition at line 233 of file hal_usb.h.

◆ USB_OUT_STATE

#define USB_OUT_STATE   0x10U

Definition at line 234 of file hal_usb.h.

◆ USB_USE_WAIT

#define USB_USE_WAIT   FALSE

Enables synchronous APIs.

Note
Disabling this option saves both code and data space.

Definition at line 245 of file hal_usb.h.

◆ usbGetDriverStateI

#define usbGetDriverStateI ( usbp)
Value:
((usbp)->state)

Returns the driver state.

Parameters
[in]usbppointer to the USBDriver object
Returns
The driver state.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 391 of file hal_usb.h.

Referenced by obnotify(), sdu_start_receive(), sduSOFHookI(), usbReceive(), and usbTransmit().

◆ usbConnectBus

#define usbConnectBus ( usbp)
Value:
#define usb_lld_connect_bus(usbp)
Connects the USB device.

Connects the USB device.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 400 of file hal_usb.h.

◆ usbDisconnectBus

#define usbDisconnectBus ( usbp)
Value:
#define usb_lld_disconnect_bus(usbp)
Disconnect the USB device.

Disconnect the USB device.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 409 of file hal_usb.h.

◆ usbGetFrameNumberX

#define usbGetFrameNumberX ( usbp)
Value:
#define usb_lld_get_frame_number(usbp)
Returns the current frame number.

Returns the current frame number.

Parameters
[in]usbppointer to the USBDriver object
Returns
The current frame number.
Function Class:
This is an X-Class API, this function can be invoked from any context.

Definition at line 419 of file hal_usb.h.

◆ usbGetTransmitStatusI

#define usbGetTransmitStatusI ( usbp,
ep )
Value:
(((usbp)->transmitting & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U)

Returns the status of an IN endpoint.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Returns
The operation status.
Return values
falseEndpoint ready.
trueEndpoint transmitting.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 432 of file hal_usb.h.

Referenced by obnotify(), sduSOFHookI(), usbStallTransmitI(), and usbStartTransmitI().

◆ usbGetReceiveStatusI

#define usbGetReceiveStatusI ( usbp,
ep )
Value:
(((usbp)->receiving & (uint16_t)((unsigned)1U << (unsigned)(ep))) != 0U)

Returns the status of an OUT endpoint.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Returns
The operation status.
Return values
falseEndpoint ready.
trueEndpoint receiving.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 446 of file hal_usb.h.

Referenced by sdu_start_receive(), usbStallReceiveI(), and usbStartReceiveI().

◆ usbGetReceiveTransactionSizeX

#define usbGetReceiveTransactionSizeX ( usbp,
ep )
Value:
#define usb_lld_get_transaction_size(usbp, ep)
Returns the exact size of a receive transaction.

Returns the exact size of a receive transaction.

The received size can be different from the size specified in usbStartReceiveI() because the last packet could have a size different from the expected one.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Returns
Received data size.
Function Class:
This is an X-Class API, this function can be invoked from any context.

Definition at line 461 of file hal_usb.h.

Referenced by _usb_ep0out(), and sduDataReceived().

◆ usbSetupTransfer

#define usbSetupTransfer ( usbp,
buf,
n,
endcb )
Value:
{ \
(usbp)->ep0next = (buf); \
(usbp)->ep0n = (n); \
(usbp)->ep0endcb = (endcb); \
}

Request transfer setup.

This macro is used by the request handling callbacks in order to prepare a transaction over the endpoint zero.

Parameters
[in]usbppointer to the USBDriver object
[in]bufpointer to a buffer for the transaction data
[in]nnumber of bytes to be transferred
[in]endcbcallback to be invoked after the transfer or NULL
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 476 of file hal_usb.h.

Referenced by default_handler(), and sduRequestsHook().

◆ usbReadSetup

#define usbReadSetup ( usbp,
ep,
buf )
Value:
usb_lld_read_setup(usbp, ep, buf)
void usb_lld_read_setup(USBDriver *usbp, usbep_t ep, uint8_t *buf)
Reads a setup packet from the dedicated packet buffer.

Reads a setup packet from the dedicated packet buffer.

This function must be invoked in the context of the setup_cb callback in order to read the received setup packet.

Precondition
In order to use this function the endpoint must have been initialized as a control endpoint.
Note
This function can be invoked both in thread and IRQ context.
Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
[out]bufbuffer where to copy the packet data
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 496 of file hal_usb.h.

Referenced by _usb_ep0setup().

◆ _usb_isr_invoke_event_cb

#define _usb_isr_invoke_event_cb ( usbp,
evt )
Value:
{ \
if (((usbp)->config->event_cb) != NULL) { \
(usbp)->config->event_cb(usbp, evt); \
} \
}

Common ISR code, usb event callback.

Parameters
[in]usbppointer to the USBDriver object
[in]evtUSB event code
Function Class:
Not an API, this function is for internal use only.

Definition at line 511 of file hal_usb.h.

Referenced by _usb_ep0in(), _usb_ep0out(), _usb_ep0setup(), _usb_reset(), _usb_suspend(), _usb_wakeup(), default_handler(), and set_address().

◆ _usb_isr_invoke_sof_cb

#define _usb_isr_invoke_sof_cb ( usbp)
Value:
{ \
if (((usbp)->config->sof_cb) != NULL) { \
(usbp)->config->sof_cb(usbp); \
} \
}

Common ISR code, SOF callback.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 524 of file hal_usb.h.

◆ _usb_isr_invoke_setup_cb

#define _usb_isr_invoke_setup_cb ( usbp,
ep )
Value:
{ \
(usbp)->epc[ep]->setup_cb(usbp, ep); \
}

Common ISR code, setup packet callback.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 538 of file hal_usb.h.

◆ _usb_isr_invoke_in_cb

#define _usb_isr_invoke_in_cb ( usbp,
ep )
Value:
{ \
(usbp)->transmitting &= ~(1 << (ep)); \
if ((usbp)->epc[ep]->in_cb != NULL) { \
(usbp)->epc[ep]->in_cb(usbp, ep); \
} \
osalSysLockFromISR(); \
osalThreadResumeI(&(usbp)->epc[ep]->in_state->thread, MSG_OK); \
osalSysUnlockFromISR(); \
}
#define MSG_OK
Definition osal.h:56

Common ISR code, IN endpoint callback.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 551 of file hal_usb.h.

◆ _usb_isr_invoke_out_cb

#define _usb_isr_invoke_out_cb ( usbp,
ep )
Value:
{ \
(usbp)->receiving &= ~(1 << (ep)); \
if ((usbp)->epc[ep]->out_cb != NULL) { \
(usbp)->epc[ep]->out_cb(usbp, ep); \
} \
osalSysLockFromISR(); \
osalThreadResumeI(&(usbp)->epc[ep]->out_state->thread, \
osalSysUnlockFromISR(); \
}
#define usbGetReceiveTransactionSizeX(usbp, ep)
Returns the exact size of a receive transaction.
Definition hal_usb.h:461

Common ISR code, OUT endpoint event.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 578 of file hal_usb.h.

◆ USB_MAX_ENDPOINTS

#define USB_MAX_ENDPOINTS   4

Maximum endpoint address.

Definition at line 37 of file hal_usb_lld.h.

Referenced by _usb_reset(), _usb_suspend(), usbDisableEndpointsI(), usbObjectInit(), usbStart(), usbStartReceiveI(), usbStartTransmitI(), and usbStop().

◆ USB_EP0_STATUS_STAGE

#define USB_EP0_STATUS_STAGE   USB_EP0_STATUS_STAGE_SW

Status stage handling method.

Definition at line 42 of file hal_usb_lld.h.

◆ USB_SET_ADDRESS_MODE

#define USB_SET_ADDRESS_MODE   USB_LATE_SET_ADDRESS

The address can be changed immediately upon packet reception.

Definition at line 47 of file hal_usb_lld.h.

◆ USB_SET_ADDRESS_ACK_HANDLING

#define USB_SET_ADDRESS_ACK_HANDLING   USB_SET_ADDRESS_ACK_SW

Method for set address acknowledge.

Definition at line 52 of file hal_usb_lld.h.

◆ PLATFORM_USB_USE_USB1

#define PLATFORM_USB_USE_USB1   FALSE

USB driver enable switch.

If set to TRUE the support for USB1 is included.

Note
The default is FALSE.

Definition at line 68 of file hal_usb_lld.h.

◆ usb_lld_get_frame_number

#define usb_lld_get_frame_number ( usbp)
Value:
0

Returns the current frame number.

Parameters
[in]usbppointer to the USBDriver object
Returns
The current frame number.
Function Class:
Not an API, this function is for internal use only.

Definition at line 306 of file hal_usb_lld.h.

◆ usb_lld_get_transaction_size

#define usb_lld_get_transaction_size ( usbp,
ep )
Value:
((usbp)->epc[ep]->out_state->rxcnt)

Returns the exact size of a receive transaction.

The received size can be different from the size specified in usbStartReceiveI() because the last packet could have a size different from the expected one.

Precondition
The OUT endpoint must have been configured in transaction mode in order to use this function.
Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Returns
Received data size.
Function Class:
Not an API, this function is for internal use only.

Definition at line 322 of file hal_usb_lld.h.

◆ usb_lld_connect_bus

#define usb_lld_connect_bus ( usbp)

Connects the USB device.

Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 330 of file hal_usb_lld.h.

◆ usb_lld_disconnect_bus

#define usb_lld_disconnect_bus ( usbp)

Disconnect the USB device.

Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 337 of file hal_usb_lld.h.

◆ usb_lld_wakeup_host

#define usb_lld_wakeup_host ( usbp)

Start of host wake-up procedure.

Function Class:
Not an API, this function is for internal use only.

Definition at line 344 of file hal_usb_lld.h.

Referenced by usbWakeupHost().

Typedef Documentation

◆ USBDriver

typedef struct USBDriver USBDriver

Type of a structure representing an USB driver.

Definition at line 259 of file hal_usb.h.

◆ usbep_t

typedef uint8_t usbep_t

Type of an endpoint identifier.

Definition at line 264 of file hal_usb.h.

◆ usbcallback_t

typedef void(* usbcallback_t) (USBDriver *usbp)

Type of an USB generic notification callback.

Parameters
[in]usbppointer to the USBDriver object triggering the callback

Definition at line 333 of file hal_usb.h.

◆ usbepcallback_t

typedef void(* usbepcallback_t) (USBDriver *usbp, usbep_t ep)

Type of an USB endpoint callback.

Parameters
[in]usbppointer to the USBDriver object triggering the callback
[in]ependpoint number

Definition at line 342 of file hal_usb.h.

◆ usbeventcb_t

typedef void(* usbeventcb_t) (USBDriver *usbp, usbevent_t event)

Type of an USB event notification callback.

Parameters
[in]usbppointer to the USBDriver object triggering the callback
[in]eventevent type

Definition at line 351 of file hal_usb.h.

◆ usbreqhandler_t

typedef bool(* usbreqhandler_t) (USBDriver *usbp)

Type of a requests handler callback.

The request is encoded in the usb_setup buffer.

Parameters
[in]usbppointer to the USBDriver object triggering the callback
Returns
The request handling exit code.
Return values
falseRequest not recognized by the handler.
trueRequest handled.

Definition at line 363 of file hal_usb.h.

◆ usbgetdescriptor_t

typedef const USBDescriptor *(* usbgetdescriptor_t) (USBDriver *usbp, uint8_t dtype, uint8_t dindex, uint16_t lang)

Type of an USB descriptor-retrieving callback.

Definition at line 368 of file hal_usb.h.

Enumeration Type Documentation

◆ usbstate_t

enum usbstate_t

Type of a driver state machine possible states.

Enumerator
USB_UNINIT 

Not initialized.

USB_STOP 

Stopped.

USB_READY 

Ready, after bus reset.

USB_SELECTED 

Address assigned.

USB_ACTIVE 

Active, configuration selected.

USB_SUSPENDED 

Suspended, low power mode.

Definition at line 269 of file hal_usb.h.

◆ usbepstatus_t

Type of an endpoint status.

Enumerator
EP_STATUS_DISABLED 

Endpoint not active.

EP_STATUS_STALLED 

Endpoint opened but stalled.

EP_STATUS_ACTIVE 

Active endpoint.

Definition at line 281 of file hal_usb.h.

◆ usbep0state_t

Type of an endpoint zero state machine states.

Enumerator
USB_EP0_STP_WAITING 

Waiting for SETUP data.

USB_EP0_IN_TX 

Transmitting.

USB_EP0_IN_WAITING_TX0 

Waiting transmit 0.

USB_EP0_IN_SENDING_STS 

Sending status.

USB_EP0_OUT_WAITING_STS 

Waiting status.

USB_EP0_OUT_RX 

Receiving.

USB_EP0_ERROR 

Error, EP0 stalled.

Definition at line 290 of file hal_usb.h.

◆ usbevent_t

enum usbevent_t

Type of an enumeration of the possible USB events.

Enumerator
USB_EVENT_RESET 

Driver has been reset by host.

USB_EVENT_ADDRESS 

Address assigned.

USB_EVENT_CONFIGURED 

Configuration selected.

USB_EVENT_UNCONFIGURED 

Configuration removed.

USB_EVENT_SUSPEND 

Entering suspend mode.

USB_EVENT_WAKEUP 

Leaving suspend mode.

USB_EVENT_STALLED 

Endpoint 0 error, stalled.

Definition at line 303 of file hal_usb.h.

Function Documentation

◆ get_hword()

uint16_t get_hword ( uint8_t * p)
static

Definition at line 51 of file hal_usb.c.

Referenced by _usb_ep0in(), _usb_ep0setup(), and default_handler().

◆ set_address()

void set_address ( USBDriver * usbp)
static

SET ADDRESS transaction callback.

Parameters
[in]usbppointer to the USBDriver object

Definition at line 64 of file hal_usb.c.

References _usb_isr_invoke_event_cb, USBDriver::address, USBDriver::setup, USBDriver::state, USB_EVENT_ADDRESS, usb_lld_set_address(), and USB_SELECTED.

Referenced by default_handler().

Here is the call graph for this function:

◆ default_handler()

bool default_handler ( USBDriver * usbp)
static

Standard requests handler.

This is the standard requests default handler, most standard requests are handled here, the user can override the standard handling using the requests_hook_cb hook in the USBConfig structure.

Parameters
[in]usbppointer to the USBDriver object
Returns
The request handling exit code.
Return values
falseRequest not recognized by the handler or error.
trueRequest handled.

Definition at line 84 of file hal_usb.c.

References _usb_isr_invoke_event_cb, active_status, USBDriver::config, USBDriver::configuration, EP_STATUS_ACTIVE, EP_STATUS_DISABLED, EP_STATUS_STALLED, USBConfig::get_descriptor_cb, get_hword(), halted_status, osalSysLockFromISR(), osalSysUnlockFromISR(), set_address(), USBDriver::setup, USBDriver::state, USBDriver::status, USBDescriptor::ud_size, USBDescriptor::ud_string, USB_ACTIVE, USB_EVENT_CONFIGURED, USB_EVENT_UNCONFIGURED, USB_FEATURE_DEVICE_REMOTE_WAKEUP, USB_FEATURE_ENDPOINT_HALT, usb_lld_clear_in(), usb_lld_clear_out(), usb_lld_get_status_in(), usb_lld_get_status_out(), usb_lld_stall_in(), usb_lld_stall_out(), USB_REQ_CLEAR_FEATURE, USB_REQ_GET_CONFIGURATION, USB_REQ_GET_DESCRIPTOR, USB_REQ_GET_INTERFACE, USB_REQ_GET_STATUS, USB_REQ_SET_ADDRESS, USB_REQ_SET_CONFIGURATION, USB_REQ_SET_DESCRIPTOR, USB_REQ_SET_FEATURE, USB_REQ_SET_INTERFACE, USB_REQ_SYNCH_FRAME, USB_RTYPE_RECIPIENT_DEVICE, USB_RTYPE_RECIPIENT_ENDPOINT, USB_RTYPE_RECIPIENT_INTERFACE, USB_RTYPE_RECIPIENT_MASK, USB_RTYPE_TYPE_MASK, USB_SELECTED, usbDisableEndpointsI(), usbSetupTransfer, and zero_status.

Referenced by _usb_ep0setup().

Here is the call graph for this function:

◆ usbInit()

void usbInit ( void )

USB Driver initialization.

Note
This function is implicitly invoked by halInit(), there is no need to explicitly initialize the driver.
Function Class:
Object or module nitializer function.

Definition at line 270 of file hal_usb.c.

References usb_lld_init().

Referenced by halInit().

Here is the call graph for this function:

◆ usbObjectInit()

void usbObjectInit ( USBDriver * usbp)

Initializes the standard part of a USBDriver structure.

Parameters
[out]usbppointer to the USBDriver object
Function Class:
Object or module nitializer function.

Definition at line 282 of file hal_usb.c.

References USBDriver::config, USBDriver::in_params, USBDriver::out_params, USBDriver::receiving, USBDriver::state, USBDriver::transmitting, USB_MAX_ENDPOINTS, and USB_STOP.

Referenced by usb_lld_init().

◆ usbStart()

msg_t usbStart ( USBDriver * usbp,
const USBConfig * config )

Configures and activates the USB peripheral.

Parameters
[in]usbppointer to the USBDriver object
[in]configpointer to the USBConfig object
Returns
The operation status.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 304 of file hal_usb.c.

References USBDriver::config, USBDriver::epc, HAL_RET_SUCCESS, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), USBDriver::state, usb_lld_start(), USB_MAX_ENDPOINTS, USB_READY, and USB_STOP.

Here is the call graph for this function:

◆ usbStop()

void usbStop ( USBDriver * usbp)

Deactivates the USB peripheral.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 345 of file hal_usb.c.

References USBDriver::config, USBDriver::epc, USBEndpointConfig::in_state, MSG_RESET, osalDbgAssert, osalDbgCheck, osalOsRescheduleS(), osalSysLock(), osalSysUnlock(), osalThreadResumeI(), USBEndpointConfig::out_state, USBDriver::state, USBInEndpointState::thread, USBOutEndpointState::thread, USB_ACTIVE, usb_lld_stop(), USB_MAX_ENDPOINTS, USB_READY, USB_SELECTED, USB_STOP, and USB_SUSPENDED.

Here is the call graph for this function:

◆ usbInitEndpointI()

void usbInitEndpointI ( USBDriver * usbp,
usbep_t ep,
const USBEndpointConfig * epcp )

Enables an endpoint.

This function enables an endpoint, both IN and/or OUT directions depending on the configuration structure.

Note
This function must be invoked in response of a SET_CONFIGURATION or SET_INTERFACE message.
Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
[in]epcpthe endpoint configuration
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 393 of file hal_usb.c.

References USBDriver::epc, USBEndpointConfig::in_state, osalDbgAssert, osalDbgCheck, osalDbgCheckClassI, USBEndpointConfig::out_state, USBDriver::state, USB_ACTIVE, and usb_lld_init_endpoint().

Here is the call graph for this function:

◆ usbDisableEndpointsI()

void usbDisableEndpointsI ( USBDriver * usbp)

Disables all the active endpoints.

This function disables all the active endpoints except the endpoint zero.

Note
This function must be invoked in response of a SET_CONFIGURATION message with configuration number zero.
Parameters
[in]usbppointer to the USBDriver object
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 428 of file hal_usb.c.

References USBDriver::epc, USBEndpointConfig::in_state, MSG_RESET, osalDbgAssert, osalDbgCheck, osalDbgCheckClassI, osalThreadResumeI(), USBEndpointConfig::out_state, USBDriver::receiving, USBDriver::state, USBInEndpointState::thread, USBOutEndpointState::thread, USBDriver::transmitting, USB_ACTIVE, usb_lld_disable_endpoints(), and USB_MAX_ENDPOINTS.

Referenced by default_handler().

Here is the call graph for this function:

◆ usbStartReceiveI()

void usbStartReceiveI ( USBDriver * usbp,
usbep_t ep,
uint8_t * buf,
size_t n )

Starts a receive transaction on an OUT endpoint.

Note
This function is meant to be called from ISR context outside critical zones because there is a potentially slow operation inside.
The transaction terminates when one of the following conditions has been met:
  • The specified amount of data has been received.
  • A short packet has been received.
  • A zero-lenght packet has been received.
  • The USB has been reset by host or the driver went into USB_SUSPENDED state.
Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
[out]bufbuffer where to copy the received data
[in]ntransaction size. It is recommended a multiple of the packet size because the excess is discarded.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 479 of file hal_usb.c.

References USBDriver::epc, osalDbgAssert, osalDbgCheck, osalDbgCheckClassI, USBEndpointConfig::out_state, USBDriver::receiving, USBOutEndpointState::rxbuf, USBOutEndpointState::rxcnt, USBOutEndpointState::rxsize, USBOutEndpointState::thread, usb_lld_start_out(), USB_MAX_ENDPOINTS, and usbGetReceiveStatusI.

Referenced by _usb_ep0in(), _usb_ep0setup(), sdu_start_receive(), and usbReceive().

Here is the call graph for this function:

◆ usbStartTransmitI()

void usbStartTransmitI ( USBDriver * usbp,
usbep_t ep,
const uint8_t * buf,
size_t n )

Starts a transmit transaction on an IN endpoint.

Note
This function is meant to be called from ISR context outside critical zones because there is a potentially slow operation inside.
Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
[in]bufbuffer where to fetch the data to be transmitted
[in]ntransaction size
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 518 of file hal_usb.c.

References USBDriver::epc, USBEndpointConfig::in_state, osalDbgAssert, osalDbgCheck, osalDbgCheckClassI, USBInEndpointState::thread, USBDriver::transmitting, USBInEndpointState::txbuf, USBInEndpointState::txcnt, USBInEndpointState::txsize, usb_lld_start_in(), USB_MAX_ENDPOINTS, and usbGetTransmitStatusI.

Referenced by _usb_ep0in(), _usb_ep0out(), _usb_ep0setup(), obnotify(), sduDataTransmitted(), sduSOFHookI(), and usbTransmit().

Here is the call graph for this function:

◆ usbReceive()

msg_t usbReceive ( USBDriver * usbp,
usbep_t ep,
uint8_t * buf,
size_t n )

Performs a receive transaction on an OUT endpoint.

Note
The transaction terminates when one of the following conditions has been met:
  • The specified amount of data has been received.
  • A short packet has been received.
  • A zero-lenght packet has been received.
  • The USB has been reset by host or the driver went into USB_SUSPENDED state.
Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
[out]bufbuffer where to copy the received data
[in]ntransaction size. It is recommended a multiple of the packet size because the excess is discarded.
Returns
The received effective data size, it can be less than the amount specified.
Return values
MSG_RESETdriver not in USB_ACTIVE state or the operation has been aborted by an USB reset or a transition to the USB_SUSPENDED state.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 569 of file hal_usb.c.

References USBDriver::epc, MSG_RESET, osalSysLock(), osalSysUnlock(), osalThreadSuspendS(), USBEndpointConfig::out_state, USBOutEndpointState::thread, USB_ACTIVE, usbGetDriverStateI, and usbStartReceiveI().

Here is the call graph for this function:

◆ usbTransmit()

msg_t usbTransmit ( USBDriver * usbp,
usbep_t ep,
const uint8_t * buf,
size_t n )

Performs a transmit transaction on an IN endpoint.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
[in]bufbuffer where to fetch the data to be transmitted
[in]ntransaction size
Returns
The operation status.
Return values
MSG_OKoperation performed successfully.
MSG_RESETdriver not in USB_ACTIVE state or the operation has been aborted by an USB reset or a transition to the USB_SUSPENDED state.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 602 of file hal_usb.c.

References USBDriver::epc, USBEndpointConfig::in_state, MSG_RESET, osalSysLock(), osalSysUnlock(), osalThreadSuspendS(), USBInEndpointState::thread, USB_ACTIVE, usbGetDriverStateI, and usbStartTransmitI().

Here is the call graph for this function:

◆ usbStallReceiveI()

bool usbStallReceiveI ( USBDriver * usbp,
usbep_t ep )

Stalls an OUT endpoint.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Returns
The operation status.
Return values
falseEndpoint stalled.
trueEndpoint busy, not stalled.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 632 of file hal_usb.c.

References osalDbgCheck, osalDbgCheckClassI, usb_lld_stall_out(), and usbGetReceiveStatusI.

Here is the call graph for this function:

◆ usbStallTransmitI()

bool usbStallTransmitI ( USBDriver * usbp,
usbep_t ep )

Stalls an IN endpoint.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Returns
The operation status.
Return values
falseEndpoint stalled.
trueEndpoint busy, not stalled.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 657 of file hal_usb.c.

References osalDbgCheck, osalDbgCheckClassI, usb_lld_stall_in(), and usbGetTransmitStatusI.

Here is the call graph for this function:

◆ usbWakeupHost()

void usbWakeupHost ( USBDriver * usbp)

Host wake-up procedure.

Note
It is silently ignored if the USB device is not in the USB_SUSPENDED state.
Parameters
[in]usbppointer to the USBDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 679 of file hal_usb.c.

References USBDriver::state, usb_lld_wakeup_host, and USB_SUSPENDED.

◆ _usb_reset()

void _usb_reset ( USBDriver * usbp)

USB reset routine.

This function must be invoked when an USB bus reset condition is detected.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 696 of file hal_usb.c.

References _usb_isr_invoke_event_cb, USBDriver::address, USBDriver::configuration, USBDriver::ep0state, USBDriver::epc, USBEndpointConfig::in_state, MSG_RESET, osalSysLockFromISR(), osalSysUnlockFromISR(), osalThreadResumeI(), USBEndpointConfig::out_state, USBDriver::receiving, USBDriver::state, USBDriver::status, USBInEndpointState::thread, USBOutEndpointState::thread, USBDriver::transmitting, USB_EP0_STP_WAITING, USB_EVENT_RESET, usb_lld_reset(), USB_MAX_ENDPOINTS, and USB_READY.

Here is the call graph for this function:

◆ _usb_suspend()

void _usb_suspend ( USBDriver * usbp)

USB suspend routine.

This function must be invoked when an USB bus suspend condition is detected.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 746 of file hal_usb.c.

References _usb_isr_invoke_event_cb, USBDriver::epc, USBEndpointConfig::in_state, MSG_RESET, osalSysLockFromISR(), osalSysUnlockFromISR(), osalThreadResumeI(), USBEndpointConfig::out_state, USBDriver::receiving, USBDriver::saved_state, USBDriver::state, USBInEndpointState::thread, USBOutEndpointState::thread, USBDriver::transmitting, USB_EVENT_SUSPEND, USB_MAX_ENDPOINTS, and USB_SUSPENDED.

Here is the call graph for this function:

◆ _usb_wakeup()

void _usb_wakeup ( USBDriver * usbp)

USB wake-up routine.

This function must be invoked when an USB bus wake-up condition is detected.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 793 of file hal_usb.c.

References _usb_isr_invoke_event_cb, USBDriver::saved_state, USBDriver::state, USB_EVENT_WAKEUP, and USB_SUSPENDED.

◆ _usb_ep0setup()

void _usb_ep0setup ( USBDriver * usbp,
usbep_t ep )

Default EP0 SETUP callback.

This function is used by the low level driver as default handler for EP0 SETUP events.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number, always zero
Function Class:
Not an API, this function is for internal use only.

Definition at line 816 of file hal_usb.c.

References _usb_isr_invoke_event_cb, USBDriver::config, default_handler(), USBDriver::ep0n, USBDriver::ep0next, USBDriver::ep0state, get_hword(), osalSysLockFromISR(), osalSysUnlockFromISR(), USBConfig::requests_hook_cb, USBDriver::setup, USB_EP0_ERROR, USB_EP0_IN_SENDING_STS, USB_EP0_IN_TX, USB_EP0_OUT_RX, USB_EP0_OUT_WAITING_STS, USB_EP0_STP_WAITING, USB_EVENT_STALLED, usb_lld_stall_in(), usb_lld_stall_out(), USB_REQ_SET_ADDRESS, USB_RTYPE_DIR_DEV2HOST, USB_RTYPE_DIR_MASK, USB_RTYPE_TYPE_MASK, USB_RTYPE_TYPE_STD, usbReadSetup, usbStartReceiveI(), and usbStartTransmitI().

Here is the call graph for this function:

◆ _usb_ep0in()

void _usb_ep0in ( USBDriver * usbp,
usbep_t ep )

Default EP0 IN callback.

This function is used by the low level driver as default handler for EP0 IN events.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number, always zero
Function Class:
Not an API, this function is for internal use only.

Definition at line 924 of file hal_usb.c.

References _usb_isr_invoke_event_cb, USBDriver::ep0endcb, USBDriver::ep0n, USBDriver::ep0state, USBDriver::epc, get_hword(), USBEndpointConfig::in_maxsize, osalDbgAssert, osalSysLockFromISR(), osalSysUnlockFromISR(), USBDriver::setup, USB_EP0_ERROR, USB_EP0_IN_SENDING_STS, USB_EP0_IN_TX, USB_EP0_IN_WAITING_TX0, USB_EP0_OUT_RX, USB_EP0_OUT_WAITING_STS, USB_EP0_STP_WAITING, USB_EVENT_STALLED, usb_lld_stall_in(), usb_lld_stall_out(), usbStartReceiveI(), and usbStartTransmitI().

Here is the call graph for this function:

◆ _usb_ep0out()

void _usb_ep0out ( USBDriver * usbp,
usbep_t ep )

Default EP0 OUT callback.

This function is used by the low level driver as default handler for EP0 OUT events.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number, always zero
Function Class:
Not an API, this function is for internal use only.

Definition at line 991 of file hal_usb.c.

References _usb_isr_invoke_event_cb, USBDriver::ep0endcb, USBDriver::ep0state, osalDbgAssert, osalSysLockFromISR(), osalSysUnlockFromISR(), USB_EP0_ERROR, USB_EP0_IN_SENDING_STS, USB_EP0_IN_TX, USB_EP0_IN_WAITING_TX0, USB_EP0_OUT_RX, USB_EP0_OUT_WAITING_STS, USB_EP0_STP_WAITING, USB_EVENT_STALLED, usb_lld_stall_in(), usb_lld_stall_out(), usbGetReceiveTransactionSizeX, and usbStartTransmitI().

Here is the call graph for this function:

◆ usbReadSetupI()

void usbReadSetupI ( USBDriver * usbp,
usbep_t ep,
uint8_t * buf )

◆ usb_lld_init()

void usb_lld_init ( void )

Low level USB driver initialization.

Function Class:
Not an API, this function is for internal use only.

Definition at line 99 of file hal_usb_lld.c.

References USBD1, and usbObjectInit().

Referenced by usbInit().

Here is the call graph for this function:

◆ usb_lld_start()

void usb_lld_start ( USBDriver * usbp)

Configures and activates the USB peripheral.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 114 of file hal_usb_lld.c.

References USBDriver::state, USB_STOP, and USBD1.

Referenced by usbStart().

◆ usb_lld_stop()

void usb_lld_stop ( USBDriver * usbp)

Deactivates the USB peripheral.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 135 of file hal_usb_lld.c.

References USBDriver::state, USB_READY, and USBD1.

Referenced by usbStop().

◆ usb_lld_reset()

void usb_lld_reset ( USBDriver * usbp)

USB low level reset routine.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 156 of file hal_usb_lld.c.

References ep0config, USBDriver::epc, and usb_lld_init_endpoint().

Referenced by _usb_reset().

Here is the call graph for this function:

◆ usb_lld_set_address()

void usb_lld_set_address ( USBDriver * usbp)

Sets the USB address.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 172 of file hal_usb_lld.c.

Referenced by set_address().

◆ usb_lld_init_endpoint()

void usb_lld_init_endpoint ( USBDriver * usbp,
usbep_t ep )

Enables an endpoint.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 186 of file hal_usb_lld.c.

Referenced by usb_lld_reset(), and usbInitEndpointI().

◆ usb_lld_disable_endpoints()

void usb_lld_disable_endpoints ( USBDriver * usbp)

Disables all the active endpoints except the endpoint zero.

Parameters
[in]usbppointer to the USBDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 200 of file hal_usb_lld.c.

Referenced by usbDisableEndpointsI().

◆ usb_lld_get_status_out()

usbepstatus_t usb_lld_get_status_out ( USBDriver * usbp,
usbep_t ep )

Returns the status of an OUT endpoint.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Returns
The endpoint status.
Return values
EP_STATUS_DISABLEDThe endpoint is not active.
EP_STATUS_STALLEDThe endpoint is stalled.
EP_STATUS_ACTIVEThe endpoint is active.
Function Class:
Not an API, this function is for internal use only.

Definition at line 218 of file hal_usb_lld.c.

References EP_STATUS_DISABLED.

Referenced by default_handler().

◆ usb_lld_get_status_in()

usbepstatus_t usb_lld_get_status_in ( USBDriver * usbp,
usbep_t ep )

Returns the status of an IN endpoint.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Returns
The endpoint status.
Return values
EP_STATUS_DISABLEDThe endpoint is not active.
EP_STATUS_STALLEDThe endpoint is stalled.
EP_STATUS_ACTIVEThe endpoint is active.
Function Class:
Not an API, this function is for internal use only.

Definition at line 238 of file hal_usb_lld.c.

References EP_STATUS_DISABLED.

Referenced by default_handler().

◆ usb_lld_read_setup()

void usb_lld_read_setup ( USBDriver * usbp,
usbep_t ep,
uint8_t * buf )

Reads a setup packet from the dedicated packet buffer.

This function must be invoked in the context of the setup_cb callback in order to read the received setup packet.

Precondition
In order to use this function the endpoint must have been initialized as a control endpoint.
Postcondition
The endpoint is ready to accept another packet.
Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
[out]bufbuffer where to copy the packet data
Function Class:
Not an API, this function is for internal use only.

Definition at line 260 of file hal_usb_lld.c.

◆ usb_lld_prepare_receive()

void usb_lld_prepare_receive ( USBDriver * usbp,
usbep_t ep )

Prepares for a receive operation.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 276 of file hal_usb_lld.c.

◆ usb_lld_prepare_transmit()

void usb_lld_prepare_transmit ( USBDriver * usbp,
usbep_t ep )

Prepares for a transmit operation.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 291 of file hal_usb_lld.c.

◆ usb_lld_start_out()

void usb_lld_start_out ( USBDriver * usbp,
usbep_t ep )

Starts a receive operation on an OUT endpoint.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 306 of file hal_usb_lld.c.

Referenced by usbStartReceiveI().

◆ usb_lld_start_in()

void usb_lld_start_in ( USBDriver * usbp,
usbep_t ep )

Starts a transmit operation on an IN endpoint.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 321 of file hal_usb_lld.c.

Referenced by usbStartTransmitI().

◆ usb_lld_stall_out()

void usb_lld_stall_out ( USBDriver * usbp,
usbep_t ep )

Brings an OUT endpoint in the stalled state.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 336 of file hal_usb_lld.c.

Referenced by _usb_ep0in(), _usb_ep0out(), _usb_ep0setup(), default_handler(), and usbStallReceiveI().

◆ usb_lld_stall_in()

void usb_lld_stall_in ( USBDriver * usbp,
usbep_t ep )

Brings an IN endpoint in the stalled state.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 351 of file hal_usb_lld.c.

Referenced by _usb_ep0in(), _usb_ep0out(), _usb_ep0setup(), default_handler(), and usbStallTransmitI().

◆ usb_lld_clear_out()

void usb_lld_clear_out ( USBDriver * usbp,
usbep_t ep )

Brings an OUT endpoint in the active state.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 366 of file hal_usb_lld.c.

Referenced by default_handler().

◆ usb_lld_clear_in()

void usb_lld_clear_in ( USBDriver * usbp,
usbep_t ep )

Brings an IN endpoint in the active state.

Parameters
[in]usbppointer to the USBDriver object
[in]ependpoint number
Function Class:
Not an API, this function is for internal use only.

Definition at line 381 of file hal_usb_lld.c.

Referenced by default_handler().

Variable Documentation

◆ zero_status

const uint8_t zero_status[] = {0x00, 0x00}
static

Definition at line 43 of file hal_usb.c.

Referenced by default_handler().

◆ active_status

const uint8_t active_status[] = {0x00, 0x00}
static

Definition at line 44 of file hal_usb.c.

Referenced by default_handler().

◆ halted_status

const uint8_t halted_status[] = {0x01, 0x00}
static

Definition at line 45 of file hal_usb.c.

Referenced by default_handler().

◆ USBD1

USBDriver USBD1

USB1 driver identifier.

Definition at line 41 of file hal_usb_lld.c.

Referenced by usb_lld_init(), usb_lld_start(), and usb_lld_stop().

◆ [union]

union { ... } ep0_state

EP0 state.

Note
It is an union because IN and OUT endpoints are never used at the same time for EP0.

◆ []

USBInEndpointState { ... } ::in

IN EP0 state.

Definition at line 57 of file hal_usb_lld.c.

◆ []

USBOutEndpointState { ... } ::out

OUT EP0 state.

Definition at line 61 of file hal_usb_lld.c.

◆ ep0config

const USBEndpointConfig ep0config
static
Initial value:
= {
0x40,
0x40,
&ep0_state.in,
&ep0_state.out
}
void _usb_ep0setup(USBDriver *usbp, usbep_t ep)
Default EP0 SETUP callback.
Definition hal_usb.c:816
#define USB_EP_MODE_TYPE_CTRL
Definition hal_usb.h:227
void _usb_ep0in(USBDriver *usbp, usbep_t ep)
Default EP0 IN callback.
Definition hal_usb.c:924
static union @235206122270051152302000074257205070254344304236 ep0_state
EP0 state.
void _usb_ep0out(USBDriver *usbp, usbep_t ep)
Default EP0 OUT callback.
Definition hal_usb.c:991

EP0 initialization structure.

Definition at line 67 of file hal_usb_lld.c.

Referenced by usb_lld_reset().