Skip to content

File usbd_core.h

FileList > fw > rbcx-coprocessor > lib > libusb_stm32 > include > usbd_core.h

Go to the source code of this file.

  • #include <stdbool.h>

Classes

Type Name
struct _usbd_device
Represents a USB device data.
struct usbd_ctlreq
Represents generic USB control request.
struct usbd_driver
Represents a hardware USB driver call table.
struct usbd_status

Public Types

Type Name
enum _usbd_respond
Reporting status results.
typedef usbd_respond(* usbd_cfg_callback
USB set configuration callback function.
typedef usbd_respond(* usbd_ctl_callback
USB control callback function.
enum usbd_ctl_state
USB device control endpoint machine state.
typedef struct _usbd_device usbd_device
typedef usbd_respond(* usbd_dsc_callback
USB get descriptor callback function.
typedef void(* usbd_evt_callback
Generic USB device event callback for events and endpoints processing.
typedef uint8_t(* usbd_hw_connect
typedef void(* usbd_hw_enable
Enables or disables USB hardware.
typedef bool(* usbd_hw_ep_config
Configures endpoint.
typedef void(* usbd_hw_ep_deconfig
De-configures, cleans and disables endpoint.
typedef bool(* usbd_hw_ep_isstalled
Checks endpoint for stalled state.
typedef int32_t(* usbd_hw_ep_read
Reads data from OUT or control endpoint.
typedef void(* usbd_hw_ep_setstall
typedef int32_t(* usbd_hw_ep_write
Writes data to IN or control endpoint.
typedef uint16_t(* usbd_hw_get_frameno
Gets frame number from usb hardware.
typedef uint16_t(* usbd_hw_get_serialno
Makes a string descriptor contains unique serial number from hardware ID's.
typedef uint32_t(* usbd_hw_getinfo
Get USB device status and capabilities.
typedef void(* usbd_hw_poll
Polls USB hardware for the events.
typedef void(* usbd_hw_setaddr
Sets USB hardware address.
enum usbd_machine_state
USB device machine states.
typedef enum _usbd_respond usbd_respond
Reporting status results.
typedef void(* usbd_rqc_callback
USB control transfer completed callback function.

Public Functions

Type Name
void usbd_poll (usbd_device * dev)
Polls USB for events.

Public Static Functions

Type Name
uint8_t usbd_connect (usbd_device * dev, bool connect)
Connects or disconnects USB hardware to/from usb host.
void usbd_enable (usbd_device * dev, bool enable)
Enables or disables USB hardware.
bool usbd_ep_config (usbd_device * dev, uint8_t ep, uint8_t eptype, uint16_t epsize)
Configure endpoint.
void usbd_ep_deconfig (usbd_device * dev, uint8_t ep)
Deconfigure endpoint.
int32_t usbd_ep_read (usbd_device * dev, uint8_t ep, void * buf, uint16_t blen)
Read data from endpoint.
void usbd_ep_stall (usbd_device * dev, uint8_t ep)
Stall endpoint.
void usbd_ep_unstall (usbd_device * dev, uint8_t ep)
Unstall endpoint.
int32_t usbd_ep_write (usbd_device * dev, uint8_t ep, void * buf, uint16_t blen)
Write data to endpoint.
uint32_t usbd_getinfo (usbd_device * dev)
Retrieves status and capabilities.
void usbd_init (usbd_device * dev, const struct usbd_driver * drv, const uint8_t ep0size, uint32_t * buffer, const uint16_t bsize)
Initializes device structure.
void usbd_reg_config (usbd_device * dev, usbd_cfg_callback callback)
Register callback for SET_CONFIG control request.
void usbd_reg_control (usbd_device * dev, usbd_ctl_callback callback)
Register callback for all control requests.
void usbd_reg_descr (usbd_device * dev, usbd_dsc_callback callback)
Register callback for GET_DESCRIPTOR control request.
void usbd_reg_endpoint (usbd_device * dev, uint8_t ep, usbd_evt_callback callback)
Register endpoint callback.
void usbd_reg_event (usbd_device * dev, uint8_t evt, usbd_evt_callback callback)
Registers event callback.

Macros

Type Name
define USBD_HW_ADDRFST (1 << 0)
Set address before STATUS_OUT.
define USBD_HW_BC (1 << 1)
Battery charging detection supported.
define USBD_HW_ENABLED (1 << 3)
USB device enabled.
define USBD_HW_ENUMSPEED (2 << 4)
USB device enumeration speed mask.
define USBD_HW_SPEED_FS (2 << 4)
Full speed.
define USBD_HW_SPEED_HS (3 << 4)
High speed.
define USBD_HW_SPEED_LS (1 << 4)
Low speed.
define USBD_HW_SPEED_NC (0 << 4)
Not connected.
define USB_EPTYPE_DBLBUF 0x04
Doublebuffered endpoint (bulk endpoint only).
define USB_REQ_CLASS (1 << 5)
Class specified request.
define USB_REQ_DEVICE (0 << 0)
Request to device.
define USB_REQ_DEVTOHOST (1 << 7)
Request direction is DEVICE to HOST.
define USB_REQ_DIRECTION (1 << 7)
Request direction mask.
define USB_REQ_ENDPOINT (2 << 0)
Request to endpoint.
define USB_REQ_HOSTTODEV (0 << 7)
Request direction is HOST to DEVICE.
define USB_REQ_INTERFACE (1 << 0)
Request to interface.
define USB_REQ_OTHER (3 << 0)
Other request.
define USB_REQ_RECIPIENT (3 << 0)
Request recipient mask.
define USB_REQ_STANDARD (0 << 5)
Standard request.
define USB_REQ_TYPE (3 << 5)
Request type mask.
define USB_REQ_VENDOR (2 << 5)
Vendor specified request.
define USND_HW_HS (1 << 2)
High speed supported.
define usbd_evt_count 8
define usbd_evt_eprx 5
Data packet received.
define usbd_evt_epsetup 6
Setup packet received.
define usbd_evt_eptx 4
Data packet transmitted.
define usbd_evt_error 7
Data error.
define usbd_evt_reset 0
Reset.
define usbd_evt_sof 1
Start of frame.
define usbd_evt_susp 2
Suspend.
define usbd_evt_wkup 3
Wakeup.
define usbd_lane_cdp 3
Lanes connected to charging downstream port.
define usbd_lane_dcp 4
Lanes connected to dedicated charging port.
define usbd_lane_dsc 1
Lanes disconnected.
define usbd_lane_sdp 2
Lanes connected to standard downstream port.
define usbd_lane_unk 0
Unknown or proprietary charger.

Public Types Documentation

enum _usbd_respond

enum _usbd_respond {
    usbd_fail,
    usbd_ack,
    usbd_nak
};

typedef usbd_cfg_callback

USB set configuration callback function.

typedef usbd_respond(* usbd_cfg_callback) (usbd_device *dev, uint8_t cfg);

called when SET_CONFIGURATION request issued

Parameters:

  • dev pointer to USB device
  • cfg configuration number.

Note:

if config is 0 device endpoints should be de-configured

Returns:

TRUE if success

typedef usbd_ctl_callback

USB control callback function.

typedef usbd_respond(* usbd_ctl_callback) (usbd_device *dev, usbd_ctlreq *req, usbd_rqc_callback *callback);

Uses for the control request processing. Some requests will be handled by core if callback don't process it (returns FALSE). If request was not processed STALL PID will be issued. * GET_CONFIGURATION * SET_CONFIGURATION (passes to usbd_cfg_callback) * GET_DESCRIPTOR (passes to usbd_dsc_callback) * GET_STATUS * SET_FEATURE, CLEAR_FEATURE (endpoints only) * SET_ADDRESS

Parameters:

  • dev points to USB device
  • req points to usb control request
  • *callback USB control transfer completion callback, default is NULL (no callback)

Returns:

usbd_respond status.

enum usbd_ctl_state

enum usbd_ctl_state {
    usbd_ctl_idle,
    usbd_ctl_rxdata,
    usbd_ctl_txdata,
    usbd_ctl_ztxdata,
    usbd_ctl_lastdata,
    usbd_ctl_statusin,
    usbd_ctl_statusout
};

typedef usbd_device

typedef struct _usbd_device usbd_device;

typedef usbd_dsc_callback

USB get descriptor callback function.

typedef usbd_respond(* usbd_dsc_callback) (usbd_ctlreq *req, void **address, uint16_t *dsize);

Called when GET_DESCRIPTOR request issued

Parameters:

  • req pointer to usb control request structure
  • address pointer to the descriptor in memory. Points to req->data by default. You can use this buffer.
  • dsize descriptor size. maximum buffer size by default.

Returns:

usbd_ack if you passed the correct descriptor, usbd_fail otherwise.

typedef usbd_evt_callback

Generic USB device event callback for events and endpoints processing.

typedef void(* usbd_evt_callback) (usbd_device *dev, uint8_t event, uint8_t ep);

Parameters:

  • dev pointer to USB device
  • event USB event
  • ep active endpoint number

Note:

endpoints with same indexes i.e. 0x01 and 0x81 shares same callback.

typedef usbd_hw_connect

typedef uint8_t(* usbd_hw_connect) (bool connect);

Connects or disconnects USB hardware to/from usb host

Parameters:

  • connect Connects USB to host if TRUE, disconnects otherwise

Returns:

lanes connection status.

typedef usbd_hw_enable

Enables or disables USB hardware.

typedef void(* usbd_hw_enable) (bool enable);

Parameters:

  • enable Enables USB when TRUE disables otherwise.

typedef usbd_hw_ep_config

Configures endpoint.

typedef bool(* usbd_hw_ep_config) (uint8_t ep, uint8_t eptype, uint16_t epsize);

Parameters:

  • ep endpoint address. Use USB_EPDIR_ macros to set endpoint direction
  • eptype endpoint type. Use USB_EPTYPE_* macros.
  • epsize endpoint size in bytes

Returns:

TRUE if success

typedef usbd_hw_ep_deconfig

De-configures, cleans and disables endpoint.

typedef void(* usbd_hw_ep_deconfig) (uint8_t ep);

Parameters:

  • ep endpoint index

Note:

if you have two one-direction single-buffered endpoints with same index (i.e. 0x02 and 0x82) both will be deconfigured.

typedef usbd_hw_ep_isstalled

Checks endpoint for stalled state.

typedef bool(* usbd_hw_ep_isstalled) (uint8_t ep);

Parameters:

  • ep endpoint address

Returns:

TRUE if endpoint is stalled

typedef usbd_hw_ep_read

Reads data from OUT or control endpoint.

typedef int32_t(* usbd_hw_ep_read) (uint8_t ep, void *buf, uint16_t blen);

Parameters:

  • ep endpoint index, should belong to OUT or CONTROL endpoint.
  • buf pointer to read buffer
  • blen size of the read buffer in bytes

Returns:

size of the actually received data, -1 on error.

typedef usbd_hw_ep_setstall

typedef void(* usbd_hw_ep_setstall) (uint8_t ep, bool stall);

Stalls and unstalls endpoint

Parameters:

  • ep endpoint address
  • stall endpoint will be stalled if TRUE and unstalled otherwise.

Note:

Has no effect on inactive endpoints.

typedef usbd_hw_ep_write

Writes data to IN or control endpoint.

typedef int32_t(* usbd_hw_ep_write) (uint8_t ep, void *buf, uint16_t blen);

Parameters:

  • ep endpoint index, hould belong to IN or CONTROL endpoint
  • buf pointer to data buffer
  • blen size of data will be written

Returns:

number of written bytes

typedef usbd_hw_get_frameno

typedef uint16_t(* usbd_hw_get_frameno) (void);

typedef usbd_hw_get_serialno

Makes a string descriptor contains unique serial number from hardware ID's.

typedef uint16_t(* usbd_hw_get_serialno) (void *buffer);

Parameters:

  • buffer pointer to buffer for the descriptor

Returns:

of the descriptor in bytes

typedef usbd_hw_getinfo

Get USB device status and capabilities.

typedef uint32_t(* usbd_hw_getinfo) (void);

Returns:

Hardware status and capabilities USBD_HW_CAPS

typedef usbd_hw_poll

Polls USB hardware for the events.

typedef void(* usbd_hw_poll) (usbd_device *dev, usbd_evt_callback callback);

Parameters:

  • dev pointer to usb device structure
  • callback callback to event processing subroutine

typedef usbd_hw_setaddr

Sets USB hardware address.

typedef void(* usbd_hw_setaddr) (uint8_t address);

Parameters:

  • address USB address

enum usbd_machine_state

enum usbd_machine_state {
    usbd_state_disabled,
    usbd_state_disconnected,
    usbd_state_default,
    usbd_state_addressed,
    usbd_state_configured
};

typedef usbd_respond

typedef enum _usbd_respond usbd_respond;

typedef usbd_rqc_callback

USB control transfer completed callback function.

typedef void(* usbd_rqc_callback) (usbd_device *dev, usbd_ctlreq *req);

Parameters:

  • dev pointer to USB device
  • req pointer to usb request structure

Note:

usbd_device->complete_callback will be set to NULL after this callback completion.

Public Functions Documentation

function usbd_poll

Polls USB for events.

void usbd_poll (
    usbd_device * dev
) 

Parameters:

  • dev Pointer to device structure

Note:

can be called as from main routine as from USB interrupt

Public Static Functions Documentation

function usbd_connect

Connects or disconnects USB hardware to/from usb host.

static inline uint8_t usbd_connect (
    usbd_device * dev,
    bool connect
) 

Parameters:

  • dev dev usb device _usbd_device
  • connect Connects USB to host if TRUE, disconnects otherwise

Returns:

lanes connection status. USB_LANES_STATUS

function usbd_enable

Enables or disables USB hardware.

static inline void usbd_enable (
    usbd_device * dev,
    bool enable
) 

Parameters:

  • dev dev usb device _usbd_device
  • enable Enables USB when TRUE disables otherwise

function usbd_ep_config

Configure endpoint.

static inline bool usbd_ep_config (
    usbd_device * dev,
    uint8_t ep,
    uint8_t eptype,
    uint16_t epsize
) 

Parameters:

  • dev dev usb device _usbd_device
  • ep endpoint address. Use USB_EPDIR_ macros to set endpoint direction
  • eptype endpoint type. Use USB_EPTYPE_* macros.
  • epsize endpoint size in bytes

Returns:

TRUE if success

function usbd_ep_deconfig

Deconfigure endpoint.

static inline void usbd_ep_deconfig (
    usbd_device * dev,
    uint8_t ep
) 

Parameters:

Note:

if you have two one-direction single-buffered endpoints with same index (i.e. 0x02 and 0x82) both will be deconfigured.

function usbd_ep_read

Read data from endpoint.

static inline int32_t usbd_ep_read (
    usbd_device * dev,
    uint8_t ep,
    void * buf,
    uint16_t blen
) 

Parameters:

  • dev dev usb device _usbd_device
  • ep endpoint index, should belong to OUT or CONTROL endpoint.
  • buf pointer to read buffer
  • blen size of the read buffer in bytes

Returns:

size of the actually received data, -1 on error.

function usbd_ep_stall

Stall endpoint.

static inline void usbd_ep_stall (
    usbd_device * dev,
    uint8_t ep
) 

Parameters:

function usbd_ep_unstall

Unstall endpoint.

static inline void usbd_ep_unstall (
    usbd_device * dev,
    uint8_t ep
) 

Parameters:

function usbd_ep_write

Write data to endpoint.

static inline int32_t usbd_ep_write (
    usbd_device * dev,
    uint8_t ep,
    void * buf,
    uint16_t blen
) 

Parameters:

  • dev dev usb device _usbd_device
  • ep endpoint index, hould belong to IN or CONTROL endpoint
  • buf pointer to data buffer
  • blen size of data will be written

Returns:

number of written bytes

function usbd_getinfo

Retrieves status and capabilities.

static inline uint32_t usbd_getinfo (
    usbd_device * dev
) 

Returns:

current HW status, enumeration speed and capabilities USBD_HW_CAPS

function usbd_init

Initializes device structure.

static inline void usbd_init (
    usbd_device * dev,
    const struct usbd_driver * drv,
    const uint8_t ep0size,
    uint32_t * buffer,
    const uint16_t bsize
) 

Parameters:

  • dev USB device that will be initialized
  • drv Pointer to hardware driver
  • ep0size Control endpoint 0 size
  • buffer Pointer to control request data buffer (32-bit aligned)
  • bsize Size of the data buffer

function usbd_reg_config

Register callback for SET_CONFIG control request.

static inline void usbd_reg_config (
    usbd_device * dev,
    usbd_cfg_callback callback
) 

Parameters:

function usbd_reg_control

Register callback for all control requests.

static inline void usbd_reg_control (
    usbd_device * dev,
    usbd_ctl_callback callback
) 

Parameters:

function usbd_reg_descr

Register callback for GET_DESCRIPTOR control request.

static inline void usbd_reg_descr (
    usbd_device * dev,
    usbd_dsc_callback callback
) 

Parameters:

function usbd_reg_endpoint

Register endpoint callback.

static inline void usbd_reg_endpoint (
    usbd_device * dev,
    uint8_t ep,
    usbd_evt_callback callback
) 

Parameters:

function usbd_reg_event

Registers event callback.

static inline void usbd_reg_event (
    usbd_device * dev,
    uint8_t evt,
    usbd_evt_callback callback
) 

Parameters:

Macro Definition Documentation

define USBD_HW_ADDRFST

#define USBD_HW_ADDRFST (1 << 0)

define USBD_HW_BC

#define USBD_HW_BC (1 << 1)

define USBD_HW_ENABLED

#define USBD_HW_ENABLED (1 << 3)

define USBD_HW_ENUMSPEED

#define USBD_HW_ENUMSPEED (2 << 4)

define USBD_HW_SPEED_FS

#define USBD_HW_SPEED_FS (2 << 4)

define USBD_HW_SPEED_HS

#define USBD_HW_SPEED_HS (3 << 4)

define USBD_HW_SPEED_LS

#define USBD_HW_SPEED_LS (1 << 4)

define USBD_HW_SPEED_NC

#define USBD_HW_SPEED_NC (0 << 4)

define USB_EPTYPE_DBLBUF

#define USB_EPTYPE_DBLBUF 0x04

define USB_REQ_CLASS

#define USB_REQ_CLASS (1 << 5)

define USB_REQ_DEVICE

#define USB_REQ_DEVICE (0 << 0)

define USB_REQ_DEVTOHOST

#define USB_REQ_DEVTOHOST (1 << 7)

define USB_REQ_DIRECTION

#define USB_REQ_DIRECTION (1 << 7)

define USB_REQ_ENDPOINT

#define USB_REQ_ENDPOINT (2 << 0)

define USB_REQ_HOSTTODEV

#define USB_REQ_HOSTTODEV (0 << 7)

define USB_REQ_INTERFACE

#define USB_REQ_INTERFACE (1 << 0)

define USB_REQ_OTHER

#define USB_REQ_OTHER (3 << 0)

define USB_REQ_RECIPIENT

#define USB_REQ_RECIPIENT (3 << 0)

define USB_REQ_STANDARD

#define USB_REQ_STANDARD (0 << 5)

define USB_REQ_TYPE

#define USB_REQ_TYPE (3 << 5)

define USB_REQ_VENDOR

#define USB_REQ_VENDOR (2 << 5)

define USND_HW_HS

#define USND_HW_HS (1 << 2)

define usbd_evt_count

#define usbd_evt_count 8

define usbd_evt_eprx

#define usbd_evt_eprx 5

define usbd_evt_epsetup

#define usbd_evt_epsetup 6

define usbd_evt_eptx

#define usbd_evt_eptx 4

define usbd_evt_error

#define usbd_evt_error 7

define usbd_evt_reset

#define usbd_evt_reset 0

define usbd_evt_sof

#define usbd_evt_sof 1

define usbd_evt_susp

#define usbd_evt_susp 2

define usbd_evt_wkup

#define usbd_evt_wkup 3

define usbd_lane_cdp

#define usbd_lane_cdp 3

define usbd_lane_dcp

#define usbd_lane_dcp 4

define usbd_lane_dsc

#define usbd_lane_dsc 1

define usbd_lane_sdp

#define usbd_lane_sdp 2

define usbd_lane_unk

#define usbd_lane_unk 0

The documentation for this class was generated from the following file fw/rbcx-coprocessor/lib/libusb_stm32/include/usbd_core.h