Go to the documentation of this file.
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
71 #if !IS_ACTIVE(KCONFIG_MODULE_USBUS)
72 #define CONFIG_USBUS_AUTO_ATTACH 1
83 #if IS_ACTIVE(CONFIG_USBUS_EP0_SIZE_8)
84 #define CONFIG_USBUS_EP0_SIZE 8
85 #elif IS_ACTIVE(CONFIG_USBUS_EP0_SIZE_16)
86 #define CONFIG_USBUS_EP0_SIZE 16
87 #elif IS_ACTIVE(CONFIG_USBUS_EP0_SIZE_32)
88 #define CONFIG_USBUS_EP0_SIZE 32
89 #elif IS_ACTIVE(CONFIG_USBUS_EP0_SIZE_64)
90 #define CONFIG_USBUS_EP0_SIZE 64
93 #ifndef CONFIG_USBUS_EP0_SIZE
94 #define CONFIG_USBUS_EP0_SIZE 64
101 #define USBUS_TNAME "usbus"
110 #define USBUS_THREAD_FLAG_USBDEV (0x02)
111 #define USBUS_THREAD_FLAG_USBDEV_EP (0x04)
120 #define USBUS_HANDLER_FLAG_RESET (0x0001)
121 #define USBUS_HANDLER_FLAG_SOF (0x0002)
122 #define USBUS_HANDLER_FLAG_SUSPEND (0x0004)
123 #define USBUS_HANDLER_FLAG_RESUME (0x0008)
124 #define USBUS_HANDLER_FLAG_TR_FAIL (0x0010)
125 #define USBUS_HANDLER_FLAG_TR_STALL (0x0020)
527 void usbus_create(
char *stack,
int stacksize,
char priority,
563 handler->
flags |= flag;
575 handler->
flags &= ~flag;
589 return handler->
flags & flag;
usb_ep_dir_t
USB endpoint directions.
struct usbus_interface_alt * next
Next alternative setting.
int16_t kernel_pid_t
Unique process identifier.
static void usbus_event_post(usbus_t *usbus, event_t *event)
Submit an event to the usbus thread.
bool active
If the endpoint should be activated after reset.
usbus_endpoint_t ep_out[USBDEV_NUM_ENDPOINTS]
USBUS OUT endpoints
#define USBDEV_NUM_ENDPOINTS
Number of USB IN and OUT endpoints allocated.
usbus_endpoint_t * ep
List of associated endpoints for this alternative setting.
uint8_t subclass
USB interface subclass
struct usbus_interface_alt usbus_interface_alt_t
USBUS interface alternative setting.
usbus_handler_t * control
Ptr to the control endpoint handler
usbus_event_transfer_t
USB endpoint transfer status events.
Common macros and compiler attributes/pragmas configuration.
@ USBUS_DESCR_LEN_FUNC
Descriptor length is calculated by a function.
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.
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.
@ USBUS_CONTROL_REQUEST_STATE_INACK
Expecting a zero-length ack IN request from the host.
USBUS interface alternative setting.
struct usbus_interface usbus_interface_t
USBUS interface.
const usbus_handler_driver_t * driver
driver for this handler
void(* transfer_handler)(usbus_t *usbus, struct usbus_handler *handler, usbdev_ep_t *ep, usbus_event_transfer_t event)
transfer handler function
@ USBUS_EVENT_TRANSFER_FAIL
Transfer nack replied by peripheral.
@ USBUS_EVENT_USB_SOF
USB start of frame received
Definitions low-level USB driver interface.
@ USBUS_EVENT_USB_RESUME
USB resume condition detected
usb_ep_type_t
USB endpoint types.
struct usbus_descr_gen * next
ptr to the next descriptor generator
struct usbus_interface_alt * alts
List of alt settings
static void usbus_handler_remove_flag(usbus_handler_t *handler, uint32_t flag)
disable a specific handler flag
usbus_string_t product
Product string
usbus_endpoint_t ep_in[USBDEV_NUM_ENDPOINTS]
USBUS IN endpoints
Messaging API for inter process communication.
static void usbus_disable_endpoint(usbus_endpoint_t *ep)
Disable an endpoint.
@ USBUS_CONTROL_REQUEST_STATE_READY
Ready for new control request.
Scheduler API definition.
static void usbus_enable_endpoint(usbus_endpoint_t *ep)
Enable an endpoint.
usbus_descr_gen_t * descr_gen
Linked list of optional additional descriptor generators.
usbus_string_t manuf
Manufacturer string
usbus_string_t * descr
Descriptor string
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.
uint8_t addr
Address of the USB peripheral
@ USBUS_STATE_SUSPEND
Peripheral is suspended by the host.
struct usbus_endpoint * next
Next endpoint in the usbus_interface_t list of endpoints.
USBUS descriptor generator function pointers.
@ USBUS_CONTROL_REQUEST_STATE_OUTDATA
Data OUT expected.
struct usbus_string * next
Ptr to the next registered string.
USB setup packet (USB 2.0 spec table 9-2)
usbus_control_request_state_t
USBUS control request state machine.
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.
usbus_string_t config
Configuration string
void usbus_register_event_handler(usbus_t *usbus, usbus_handler_t *handler)
Add an event handler to the USBUS context.
uint8_t protocol
USB interface protocol
uint16_t idx
USB string index
uint32_t flags
Report flags.
static void usbus_handler_set_flag(usbus_handler_t *handler, uint32_t flag)
enable a specific handler flag
usbus_descr_gen_t * descr_gen
Linked list of optional additional descriptor generators.
usbus_interface_t * iface
List of USB interfaces
@ USBUS_EVENT_USB_RESET
USB reset event
struct usbus_endpoint usbus_endpoint_t
USBUS endpoint context.
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.
@ USBUS_EVENT_TRANSFER_STALL
Transfer stall replied by peripheral.
void(* event_handler)(usbus_t *usbus, struct usbus_handler *handler, usbus_event_usb_t event)
event handler function
@ USBUS_CONTROL_REQUEST_STATE_INDATA
Request received with expected DATA IN stage.
struct usbus_handler * next
List of handlers (to be used by usbus_t)
usbdev endpoint descriptor
usbus_descr_len_type_t len_type
Either USBUS_DESCR_LEN_FIXED or USBUS_DESCR_LEN_FUNC.
usbus_endpoint_t * ep
Linked list of endpoints belonging to this interface
usbus_interface_t * iface
Interface this handler belongs to.
@ USBUS_EVENT_USB_SUSPEND
USB suspend condition detected.
usbdev_ep_t * ep
ptr to the matching usbdev endpoint
Definition of global compile time configuration options.
void(* init)(usbus_t *usbus, struct usbus_handler *handler)
Initialize the event handler.
uint32_t ep_events
bitflags with endpoint event state
void event_post(event_queue_t *queue, event_t *event)
Queue an event.
uint16_t maxpacketsize
Max packet size of this endpoint.
uint8_t interval
Poll interval for interrupt endpoints.
usbdev_t * dev
usb phy device of the usb manager
usbus_descr_gen_t * descr_gen
Linked list of optional additional descriptor generators.
usbus_state_t state
Current state
@ USBUS_STATE_DISCONNECT
Device is disconnected from the host.
struct usbus_handler_driver usbus_handler_driver_t
USBUS event handler function pointers.
USBUS descriptor generator.
uint16_t idx
Interface index, (set by USBUS during registration
@ USBUS_STATE_ADDR
Address configured.
kernel_pid_t pid
PID of the usb manager's thread
size_t fixed_len
Fixed total length of the generated descriptors.
usbus_descr_gen_t * descr_gen
Linked list of top level descriptor generators
const char * str
C string to use as content
usbus_string_t * strings
List of descriptor strings
const usbus_descr_gen_funcs_t * funcs
Function pointers.
uint16_t str_idx
Number of strings registered
struct usbus_descr_gen usbus_descr_gen_t
USBUS descriptor generator.
void * arg
Extra context argument for the descriptor functions.
void usbus_init(usbus_t *usbus, usbdev_t *usbdev)
Initialize an USBUS context.
usbus_descr_len_type_t
descriptor length types for USB descriptor generators
USBUS event handler function pointers.
usbus_handler_t * handler
Handlers for this interface
usbus_handler_t * handlers
List of event callback handlers
@ USBUS_STATE_CONFIGURED
Peripheral is configured.
event_queue_t queue
Event queue
usbus_state_t pstate
state to recover to from suspend
@ USBUS_EVENT_TRANSFER_COMPLETE
Transfer successfully completed.
@ USBUS_CONTROL_REQUEST_STATE_OUTACK
Expecting a zero-length ack OUT request from the host.
struct usbus_string usbus_string_t
USBUS string type.
@ USBUS_DESCR_LEN_FIXED
Descriptor always generates a fixed length.
usbus_state_t
state machine states for the global USBUS thread
int(* control_handler)(usbus_t *usbus, struct usbus_handler *handler, usbus_control_request_state_t state, usb_setup_t *request)
control request handler function
@ USBUS_STATE_RESET
Reset condition received.
struct usbus_interface * next
Next interface (set by USBUS during registration)
static bool usbus_handler_isset_flag(usbus_handler_t *handler, uint32_t flag)
check if a specific handler flag is set
Definitions for USB protocol messages.
void usbus_create(char *stack, int stacksize, char priority, const char *name, usbus_t *usbus)
Create and start the USBUS thread.