USBUS (Universal Serial Bus Unified Stack), USB device management interface. More...
USBUS (Universal Serial Bus Unified Stack), USB device management interface.
Modules | |
USBUS compile time configurations | |
USBUS descriptor formatter functions | |
Files | |
file | usbus.h |
USBUS basic interface. | |
file | control.h |
USBUS control endpoint module. | |
Data Structures | |
struct | usbus_string |
USBUS string type. More... | |
struct | usbus_descr_gen_funcs_t |
USBUS descriptor generator function pointers. More... | |
struct | usbus_descr_gen |
USBUS descriptor generator. More... | |
struct | usbus_endpoint |
USBUS endpoint context. More... | |
struct | usbus_urb |
USBUS USB request/response block. More... | |
struct | usbus_interface_alt |
USBUS interface alternative setting. More... | |
struct | usbus_interface |
USBUS interface. More... | |
struct | usbus_handler_driver |
USBUS event handler function pointers. More... | |
struct | usbus_handler |
USBUS handler struct. More... | |
struct | usbus |
USBUS context struct. More... | |
Macros | |
#define | USBUS_TNAME "usbus" |
USBUS thread name. | |
Typedefs | |
typedef struct usbus_string | usbus_string_t |
USBUS string type. | |
typedef struct usbus | usbus_t |
USBUS context forward declaration. | |
typedef struct usbus_handler | usbus_handler_t |
USBUS event handler forward declaration. | |
typedef struct usbus_descr_gen | usbus_descr_gen_t |
USBUS descriptor generator. | |
typedef struct usbus_endpoint | usbus_endpoint_t |
USBUS endpoint context. | |
typedef struct usbus_urb | usbus_urb_t |
USBUS USB request/response block. | |
typedef struct usbus_interface_alt | usbus_interface_alt_t |
USBUS interface alternative setting. | |
typedef struct usbus_interface | usbus_interface_t |
USBUS interface. | |
typedef struct usbus_handler_driver | usbus_handler_driver_t |
USBUS event handler function pointers. | |
Enumerations | |
enum | usbus_event_usb_t { USBUS_EVENT_USB_RESET , USBUS_EVENT_USB_SOF , USBUS_EVENT_USB_SUSPEND , USBUS_EVENT_USB_RESUME } |
USB handler events. More... | |
enum | usbus_event_transfer_t { USBUS_EVENT_TRANSFER_COMPLETE , USBUS_EVENT_TRANSFER_FAIL , USBUS_EVENT_TRANSFER_STALL } |
USB endpoint transfer status events. More... | |
enum | usbus_state_t { USBUS_STATE_DISCONNECT , USBUS_STATE_RESET , USBUS_STATE_ADDR , USBUS_STATE_CONFIGURED , USBUS_STATE_SUSPEND } |
state machine states for the global USBUS thread More... | |
enum | usbus_control_request_state_t { USBUS_CONTROL_REQUEST_STATE_READY , USBUS_CONTROL_REQUEST_STATE_INDATA , USBUS_CONTROL_REQUEST_STATE_OUTACK , USBUS_CONTROL_REQUEST_STATE_OUTDATA , USBUS_CONTROL_REQUEST_STATE_INACK } |
USBUS control request state machine. More... | |
enum | usbus_descr_len_type_t { USBUS_DESCR_LEN_FIXED , USBUS_DESCR_LEN_FUNC } |
descriptor length types for USB descriptor generators More... | |
Functions | |
static void | usbus_event_post (usbus_t *usbus, event_t *event) |
Submit an event to 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. | |
uint16_t | usbus_add_interface (usbus_t *usbus, usbus_interface_t *iface) |
Add an interface to the USBUS thread context. | |
void | usbus_add_interface_alt (usbus_interface_t *iface, usbus_interface_alt_t *alt) |
Add alternate settings to a given interface. | |
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_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_add_conf_descriptor (usbus_t *usbus, usbus_descr_gen_t *descr_gen) |
Add a generator for generating additional top level USB descriptor content. | |
void | usbus_register_event_handler (usbus_t *usbus, usbus_handler_t *handler) |
Add an event handler to the USBUS context. | |
void | usbus_init (usbus_t *usbus, usbdev_t *usbdev) |
Initialize an USBUS context. | |
size_t | usbus_max_bulk_endpoint_size (usbus_t *usbus) |
Get the maximum supported bulk endpoint transfer size based on the enumeration speed. | |
size_t | usbus_max_interrupt_endpoint_size (usbus_t *usbus) |
Get the maximum supported interrupt endpoint transfer size based on the enumeration speed. | |
void | usbus_create (char *stack, int stacksize, char priority, const char *name, usbus_t *usbus) |
Create and start the USBUS thread. | |
static void | usbus_urb_init (usbus_urb_t *urb, uint8_t *buf, size_t len, uint32_t flags) |
Initialize a new URB. | |
void | usbus_urb_submit (usbus_t *usbus, usbus_endpoint_t *endpoint, usbus_urb_t *urb) |
Submit an URB to an endpoint. | |
int | usbus_urb_cancel (usbus_t *usbus, usbus_endpoint_t *endpoint, usbus_urb_t *urb) |
Cancel and already queued URB. | |
void | usbus_endpoint_halt (usbus_endpoint_t *ep) |
Set the halt condition on an endpoint. | |
void | usbus_endpoint_clear_halt (usbus_endpoint_t *ep) |
Clear the halt condition on an endpoint. | |
static void | usbus_enable_endpoint (usbus_endpoint_t *ep) |
Enable an endpoint. | |
static void | usbus_disable_endpoint (usbus_endpoint_t *ep) |
Disable an endpoint. | |
static void | usbus_handler_set_flag (usbus_handler_t *handler, uint32_t flag) |
enable a specific handler flag | |
static void | usbus_handler_remove_flag (usbus_handler_t *handler, uint32_t flag) |
disable a specific handler flag | |
static bool | usbus_handler_isset_flag (usbus_handler_t *handler, uint32_t flag) |
check if a specific handler flag is set | |
static void | usbus_urb_set_flag (usbus_urb_t *urb, uint32_t flag) |
enable an URB flag | |
static void | usbus_urb_remove_flag (usbus_urb_t *urb, uint32_t flag) |
disable an URB flag | |
static bool | usbus_urb_isset_flag (usbus_urb_t *urb, uint32_t flag) |
check if an URB flag is set | |
USBUS thread flags | |
Thread flags used by the USBUS thread. THREAD_FLAG_EVENT is also used, but defined elsewhere | |
#define | USBUS_THREAD_FLAG_USBDEV (0x02) |
usbdev esr needs handling | |
#define | USBUS_THREAD_FLAG_USBDEV_EP (0x04) |
One or more endpoints requires servicing. | |
USBUS handler subscription flags | |
#define | USBUS_HANDLER_FLAG_RESET (0x0001) |
Report reset event. | |
#define | USBUS_HANDLER_FLAG_SOF (0x0002) |
Report SOF events. | |
#define | USBUS_HANDLER_FLAG_SUSPEND (0x0004) |
Report suspend events. | |
#define | USBUS_HANDLER_FLAG_RESUME (0x0008) |
Report resume from suspend. | |
#define | USBUS_HANDLER_FLAG_TR_STALL (0x0020) |
Report transfer stall complete. | |
USBUS URB flags | |
#define | USBUS_URB_FLAG_AUTO_ZLP (0x0001) |
End the URB with a zero length packet if the URB is a full number of USB transfers in length. | |
#define | USBUS_URB_FLAG_NEEDS_ZLP (0x1000) |
URB needs a zero length packet and it is requested. | |
#define | USBUS_URB_FLAG_CANCELLED (0x2000) |
URB must be cancelled after the next finished xmit. | |
#define USBUS_HANDLER_FLAG_RESET (0x0001) |
#define USBUS_HANDLER_FLAG_RESUME (0x0008) |
#define USBUS_HANDLER_FLAG_SUSPEND (0x0004) |
#define USBUS_HANDLER_FLAG_TR_STALL (0x0020) |
#define USBUS_THREAD_FLAG_USBDEV (0x02) |
#define USBUS_THREAD_FLAG_USBDEV_EP (0x04) |
#define USBUS_URB_FLAG_AUTO_ZLP (0x0001) |
#define USBUS_URB_FLAG_CANCELLED (0x2000) |
#define USBUS_URB_FLAG_NEEDS_ZLP (0x1000) |
typedef struct usbus_descr_gen usbus_descr_gen_t |
USBUS descriptor generator.
The functions are called to allow custom modules to define their own descriptors in addition to the USB descriptor. The top level (usbus_t), the interface (usbus_interface_t), interface alternative settings (usbus_interface_alt_t) and endpoints (usbus_endpoint_t) allow for generating additional descriptors
typedef struct usbus_handler usbus_handler_t |
typedef struct usbus_interface_alt usbus_interface_alt_t |
USBUS interface alternative setting.
Used for specifying alternative interfaces for an usbus_interface_t
USBUS control request state machine.
enum usbus_event_usb_t |
enum usbus_state_t |
state machine states for the global USBUS thread
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.
[in] | usbus | USBUS context |
[in] | descr_gen | descriptor generator to add |
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.
An usbdev_ep_t is requested from the low level peripheral matching the type, direction and buffer length.
[in] | usbus | USBUS context |
[in] | iface | USB interface to add the endpoint to |
[in] | type | USB endpoint type |
[in] | dir | USB endpoint direction |
[in] | len | Buffer space for the endpoint to allocate |
uint16_t usbus_add_interface | ( | usbus_t * | usbus, |
usbus_interface_t * | iface | ||
) |
Add an interface to the USBUS thread context.
[in] | usbus | USBUS context |
[in] | iface | USB interface to add |
void usbus_add_interface_alt | ( | usbus_interface_t * | iface, |
usbus_interface_alt_t * | alt | ||
) |
Add alternate settings to a given interface.
[in] | iface | USB interface |
[in] | alt | alternate settings interface to add |
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.
[in] | usbus | USBUS context |
[in] | desc | string descriptor context |
[in] | str | C string to use |
void usbus_create | ( | char * | stack, |
int | stacksize, | ||
char | priority, | ||
const char * | name, | ||
usbus_t * | usbus | ||
) |
Create and start the USBUS thread.
[in] | stack | The stack for the USBUS thread. |
[in] | stacksize | Size of stack . |
[in] | priority | Priority for the USBUS thread. |
[in] | name | Name for the USBUS thread May be NULL. |
[in] | usbus | context to start the thread for |
|
inlinestatic |
|
inlinestatic |
void usbus_endpoint_clear_halt | ( | usbus_endpoint_t * | ep | ) |
Clear the halt condition on an endpoint.
void usbus_endpoint_halt | ( | usbus_endpoint_t * | ep | ) |
Set the halt condition on an endpoint.
The endpoint will respond with stall to all packets and must explicitly be cleared by the host by clearing the halt condition or switching interfaces
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Initialize an USBUS context.
[in] | usbus | context to initialize |
[in] | usbdev | usbdev peripheral to use by USBUS |
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.
This iterates over the endpoints in an interface and will return the first endpoint from the interface matching the type
and dir
. It will return NULL when no matching endpoint is found.
[in] | interface | interface to look in |
[in] | type | endpoint type to match |
[in] | dir | endpoint direction to match |
size_t usbus_max_bulk_endpoint_size | ( | usbus_t * | usbus | ) |
Get the maximum supported bulk endpoint transfer size based on the enumeration speed.
Should only be called after enumeration has finished by the peripheral. Calling this in response to the USBUS_EVENT_USB_RESET is valid
size_t usbus_max_interrupt_endpoint_size | ( | usbus_t * | usbus | ) |
Get the maximum supported interrupt endpoint transfer size based on the enumeration speed.
Should only be called after enumeration has finished by the peripheral. Calling this in response to the USBUS_EVENT_USB_RESET is valid
void usbus_register_event_handler | ( | usbus_t * | usbus, |
usbus_handler_t * | handler | ||
) |
Add an event handler to the USBUS context.
The handler must also belong to an interface (usbus_interface_t::handler must point to handler
) for transfer event callbacks to work.
[in] | usbus | USBUS context |
[in] | handler | event handler to register |
int usbus_urb_cancel | ( | usbus_t * | usbus, |
usbus_endpoint_t * | endpoint, | ||
usbus_urb_t * | urb | ||
) |
Cancel and already queued URB.
The URB will be cancelled after the next transmission if the URB is already partially completed. It is up to the handler code to gracefully handle the partially aborted transfer on the endpoint pipe.
The callback will be called if the URB was already started and cancelled while (partially) transferred
usbus_urb
module.[in] | usbus | USBUS context |
[in] | endpoint | USBUS endpoint the URB is queued to |
[in] | urb | URB to cancel |
|
inlinestatic |
Initialize a new URB.
Must be called before submitting an URB to an endpoint.
len
argument must allow for a whole number of max length transfers.usbus_urb
module.[in] | urb | URB to submit |
[in] | buf | Buffer to store or transmit the data from |
[in] | len | Length of buf in bytes |
[in] | flags | Flags to set for the URB such as USBUS_URB_FLAG_AUTO_ZLP |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
void usbus_urb_submit | ( | usbus_t * | usbus, |
usbus_endpoint_t * | endpoint, | ||
usbus_urb_t * | urb | ||
) |
Submit an URB to an endpoint.
usbus_urb
module.[in] | usbus | USBUS context |
[in] | endpoint | USBUS endpoint the URB is queued to |
[in] | urb | URB to submit |