Skip to content

Group USBD_HW

Modules > USBD_HW

Contains HW driver API.

Classes

Type Name
struct usbd_driver
Represents a hardware USB driver call table.

Public Types

Type Name
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.

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 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

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

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 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