Loading...
Searching...
No Matches
usbus.h File Reference

USBUS basic interface. More...

Detailed Description

USBUS basic interface.

Author
Koen Zandberg koen@.nosp@m.berg.nosp@m.zand..nosp@m.net

Definition in file usbus.h.

#include <stdint.h>
#include <stdlib.h>
#include "clist.h"
#include "event.h"
#include "sched.h"
#include "modules.h"
#include "msg.h"
#include "thread.h"
#include "usb.h"
#include "periph/usbdev.h"
#include "usb/descriptor.h"
+ Include dependency graph for usbus.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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_STACKSIZE   (THREAD_STACKSIZE_DEFAULT)
 USBUS thread stack size.
 
#define USBUS_PRIO   (THREAD_PRIORITY_MAIN - 6)
 USBUS thread priority.
 
#define CONFIG_USBUS_AUTO_ATTACH   1
 USBUS auto attach setting.
 
#define CONFIG_USBUS_MSC_AUTO_MTD   1
 USBUS MSC auto MTD setting.
 
#define CONFIG_USBUS_EP0_SIZE   64
 USBUS endpoint 0 buffer size.
 
#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_tusbus_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_tusbus_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.