52#ifndef USBUS_STACKSIZE
53#define USBUS_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
60#define USBUS_PRIO (THREAD_PRIORITY_MAIN - 6)
70#ifndef CONFIG_USBUS_AUTO_ATTACH
72#if !IS_ACTIVE(CONFIG_MODULE_USBUS)
73#define CONFIG_USBUS_AUTO_ATTACH 1
83#ifndef CONFIG_USBUS_MSC_AUTO_MTD
84#define CONFIG_USBUS_MSC_AUTO_MTD 1
94#if IS_ACTIVE(CONFIG_USBUS_EP0_SIZE_8)
95#define CONFIG_USBUS_EP0_SIZE 8
96#elif IS_ACTIVE(CONFIG_USBUS_EP0_SIZE_16)
97#define CONFIG_USBUS_EP0_SIZE 16
98#elif IS_ACTIVE(CONFIG_USBUS_EP0_SIZE_32)
99#define CONFIG_USBUS_EP0_SIZE 32
100#elif IS_ACTIVE(CONFIG_USBUS_EP0_SIZE_64)
101#define CONFIG_USBUS_EP0_SIZE 64
104#ifndef CONFIG_USBUS_EP0_SIZE
105#define CONFIG_USBUS_EP0_SIZE 64
112#define USBUS_TNAME "usbus"
121#define USBUS_THREAD_FLAG_USBDEV (0x02)
122#define USBUS_THREAD_FLAG_USBDEV_EP (0x04)
131#define USBUS_HANDLER_FLAG_RESET (0x0001)
132#define USBUS_HANDLER_FLAG_SOF (0x0002)
133#define USBUS_HANDLER_FLAG_SUSPEND (0x0004)
134#define USBUS_HANDLER_FLAG_RESUME (0x0008)
135#define USBUS_HANDLER_FLAG_TR_STALL (0x0020)
148#define USBUS_URB_FLAG_AUTO_ZLP (0x0001)
154#define USBUS_URB_FLAG_NEEDS_ZLP (0x1000)
160#define USBUS_URB_FLAG_CANCELLED (0x2000)
315#ifdef MODULE_USBUS_URB
470#ifndef CONFIG_USB_SERIAL_STR
722 handler->
flags |= flag;
734 handler->
flags &= ~flag;
748 return handler->
flags & flag;
786 return urb->
flags & flag;
Definitions for USB protocol messages.
#define USBDEV_NUM_ENDPOINTS
Number of USB OTG FS endpoints including EP0.
int16_t kernel_pid_t
Unique process identifier.
void event_post(event_queue_t *queue, event_t *event)
Queue an event.
static void usbus_urb_remove_flag(usbus_urb_t *urb, uint32_t flag)
disable an URB flag
void usbus_add_interface_alt(usbus_interface_t *iface, usbus_interface_alt_t *alt)
Add alternate settings to a given interface.
static void usbus_handler_remove_flag(usbus_handler_t *handler, uint32_t flag)
disable a specific handler flag
struct usbus_interface_alt usbus_interface_alt_t
USBUS interface alternative setting.
usbus_event_transfer_t
USB endpoint transfer status events.
struct usbus_handler_driver usbus_handler_driver_t
USBUS event handler function pointers.
usbus_descr_len_type_t
descriptor length types for USB descriptor generators
static void usbus_urb_init(usbus_urb_t *urb, uint8_t *buf, size_t len, uint32_t flags)
Initialize a new URB.
struct usbus_string usbus_string_t
USBUS string type.
struct usbus_urb usbus_urb_t
USBUS USB request/response block.
static bool usbus_handler_isset_flag(usbus_handler_t *handler, uint32_t flag)
check if a specific handler flag is set
void usbus_init(usbus_t *usbus, usbdev_t *usbdev)
Initialize an USBUS context.
void usbus_endpoint_clear_halt(usbus_endpoint_t *ep)
Clear the halt condition on an endpoint.
int usbus_urb_cancel(usbus_t *usbus, usbus_endpoint_t *endpoint, usbus_urb_t *urb)
Cancel and already queued URB.
static void usbus_urb_set_flag(usbus_urb_t *urb, uint32_t flag)
enable an URB flag
struct usbus_endpoint usbus_endpoint_t
USBUS endpoint context.
size_t usbus_max_interrupt_endpoint_size(usbus_t *usbus)
Get the maximum supported interrupt endpoint transfer size based on the enumeration speed.
uint16_t usbus_add_interface(usbus_t *usbus, usbus_interface_t *iface)
Add an interface to the USBUS thread context.
usbus_event_usb_t
USB handler events.
static void usbus_event_post(usbus_t *usbus, event_t *event)
Submit an event to the usbus thread.
size_t usbus_max_bulk_endpoint_size(usbus_t *usbus)
Get the maximum supported bulk endpoint transfer size based on the enumeration speed.
usbus_endpoint_t * usbus_interface_find_endpoint(usbus_interface_t *interface, usb_ep_type_t type, usb_ep_dir_t dir)
Find an endpoint from an interface based on the endpoint properties.
static void usbus_handler_set_flag(usbus_handler_t *handler, uint32_t flag)
enable a specific handler flag
usbus_control_request_state_t
USBUS control request state machine.
struct usbus_descr_gen usbus_descr_gen_t
USBUS descriptor generator.
usbus_endpoint_t * usbus_add_endpoint(usbus_t *usbus, usbus_interface_t *iface, usb_ep_type_t type, usb_ep_dir_t dir, size_t len)
Add an endpoint to the specified interface.
void usbus_create(char *stack, int stacksize, char priority, const char *name, usbus_t *usbus)
Create and start the USBUS thread.
uint16_t usbus_add_string_descriptor(usbus_t *usbus, usbus_string_t *desc, const char *str)
Add a string descriptor to the USBUS thread context.
struct usbus_interface usbus_interface_t
USBUS interface.
void usbus_endpoint_halt(usbus_endpoint_t *ep)
Set the halt condition on an endpoint.
static bool usbus_urb_isset_flag(usbus_urb_t *urb, uint32_t flag)
check if an URB flag is set
static void usbus_enable_endpoint(usbus_endpoint_t *ep)
Enable an endpoint.
void usbus_add_conf_descriptor(usbus_t *usbus, usbus_descr_gen_t *descr_gen)
Add a generator for generating additional top level USB descriptor content.
usbus_state_t
state machine states for the global USBUS thread
void usbus_urb_submit(usbus_t *usbus, usbus_endpoint_t *endpoint, usbus_urb_t *urb)
Submit an URB to an endpoint.
static void usbus_disable_endpoint(usbus_endpoint_t *ep)
Disable an endpoint.
void usbus_register_event_handler(usbus_t *usbus, usbus_handler_t *handler)
Add an event handler to the USBUS context.
@ USBUS_EVENT_TRANSFER_COMPLETE
Transfer successfully completed.
@ USBUS_EVENT_TRANSFER_STALL
Transfer stall replied by peripheral.
@ USBUS_EVENT_TRANSFER_FAIL
Transfer nack replied by peripheral.
@ USBUS_DESCR_LEN_FIXED
Descriptor always generates a fixed length.
@ USBUS_DESCR_LEN_FUNC
Descriptor length is calculated by a function.
@ USBUS_EVENT_USB_SOF
USB start of frame received
@ USBUS_EVENT_USB_RESUME
USB resume condition detected
@ USBUS_EVENT_USB_RESET
USB reset event
@ USBUS_EVENT_USB_SUSPEND
USB suspend condition detected.
@ USBUS_CONTROL_REQUEST_STATE_INACK
Expecting a zero-length ack IN request from the host.
@ USBUS_CONTROL_REQUEST_STATE_OUTACK
Expecting a zero-length ack OUT request from the host.
@ USBUS_CONTROL_REQUEST_STATE_OUTDATA
Data OUT expected.
@ USBUS_CONTROL_REQUEST_STATE_INDATA
Request received with expected DATA IN stage.
@ USBUS_CONTROL_REQUEST_STATE_READY
Ready for new control request.
@ USBUS_STATE_RESET
Reset condition received.
@ USBUS_STATE_CONFIGURED
Peripheral is configured.
@ USBUS_STATE_ADDR
Address configured.
@ USBUS_STATE_DISCONNECT
Device is disconnected from the host.
@ USBUS_STATE_SUSPEND
Peripheral is suspended by the host.
usb_ep_dir_t
USB endpoint directions.
usb_ep_type_t
USB endpoint types.
Common macros and compiler attributes/pragmas configuration.
Scheduler API definition.
USB setup packet (USB 2.0 spec table 9-2)
usbdev endpoint descriptor
USBUS descriptor generator function pointers.
usbus_descr_len_type_t len_type
Either USBUS_DESCR_LEN_FIXED or USBUS_DESCR_LEN_FUNC.
size_t fixed_len
Fixed total length of the generated descriptors.
USBUS descriptor generator.
void * arg
Extra context argument for the descriptor functions.
struct usbus_descr_gen * next
ptr to the next descriptor generator
const usbus_descr_gen_funcs_t * funcs
Function pointers.
uint16_t maxpacketsize
Max packet size of this endpoint.
bool active
If the endpoint should be activated after reset.
usbdev_ep_t * ep
ptr to the matching usbdev endpoint
uint8_t interval
Poll interval for interrupt endpoints.
struct usbus_endpoint * next
Next endpoint in the usbus_interface_t list of endpoints.
usbus_descr_gen_t * descr_gen
Linked list of optional additional descriptor generators.
bool halted
Endpoint is halted.
USBUS event handler function pointers.
void(* init)(usbus_t *usbus, struct usbus_handler *handler)
Initialize the event handler.
void(* transfer_handler)(usbus_t *usbus, struct usbus_handler *handler, usbdev_ep_t *ep, usbus_event_transfer_t event)
transfer handler function
void(* event_handler)(usbus_t *usbus, struct usbus_handler *handler, usbus_event_usb_t event)
event handler function
int(* control_handler)(usbus_t *usbus, struct usbus_handler *handler, usbus_control_request_state_t state, usb_setup_t *request)
control request handler function
struct usbus_handler * next
List of handlers (to be used by usbus_t)
uint32_t flags
Report flags.
const usbus_handler_driver_t * driver
driver for this handler
usbus_interface_t * iface
Interface this handler belongs to.
USBUS interface alternative setting.
usbus_descr_gen_t * descr_gen
Linked list of optional additional descriptor generators.
struct usbus_interface_alt * next
Next alternative setting.
usbus_endpoint_t * ep
List of associated endpoints for this alternative setting.
usbus_string_t * descr
Descriptor string.
uint8_t protocol
USB interface protocol
struct usbus_interface_alt * alts
List of alt settings
uint8_t subclass
USB interface subclass
usbus_endpoint_t * ep
Linked list of endpoints belonging to this interface
struct usbus_interface * next
Next interface (set by USBUS during registration)
usbus_descr_gen_t * descr_gen
Linked list of optional additional descriptor generators.
usbus_handler_t * handler
Handlers for this interface
uint16_t idx
Interface index, (set by USBUS during registration
usbus_string_t * descr
Descriptor string
const char * str
C string to use as content
struct usbus_string * next
Ptr to the next registered string.
uint16_t idx
USB string index
USBUS USB request/response block.
uint8_t * buf
Pointer to the (aligned) buffer.
clist_node_t list
clist block in the queue
size_t len
Length of the data.
uint32_t flags
Transfer flags.
size_t transferred
amount transferred, only valid for OUT
usbus_state_t state
Current state
usbus_state_t pstate
state to recover to from suspend
usbus_endpoint_t ep_out[USBDEV_NUM_ENDPOINTS]
USBUS OUT endpoints
usbus_handler_t * handlers
List of event callback handlers
uint8_t addr
Address of the USB peripheral
bool wakeup_enabled
Remote wakeup device feature status
char serial_str[2 *CONFIG_USB_SERIAL_BYTE_LENGTH+1]
Hex representation of the device serial number.
kernel_pid_t pid
PID of the usb manager's thread
usbus_endpoint_t ep_in[USBDEV_NUM_ENDPOINTS]
USBUS IN endpoints
usbus_descr_gen_t * descr_gen
Linked list of top level descriptor generators
usbus_handler_t * control
Ptr to the control endpoint handler
usbus_string_t serial
serial string
usbus_string_t product
Product string
usbus_string_t manuf
Manufacturer string
usbus_string_t * strings
List of descriptor strings
usbdev_t * dev
usb phy device of the usb manager
uint16_t str_idx
Number of strings registered
usbus_interface_t * iface
List of USB interfaces
event_queue_t queue
Event queue
uint32_t ep_events
bitflags with endpoint event state
usbus_string_t config
Configuration string
Definition of global compile time configuration options.
Definitions low-level USB driver interface.