PebbleOS v4.47.0-757-g12b6c531f
Loading...
Searching...
No Matches
USB device controller

The device side of a USB controller, which the USB device stack drives. More...

Data Structures

struct  pbl_udc_callbacks
 What the stack does with what a controller reports, from its interrupt. More...
 
struct  pbl_udc_ops
 Driver operations. More...
 
struct  pbl_udc
 USB device controller. More...
 

Macros

#define PBL_UDC_EP_IN   0x80U
 Direction bit of an IN endpoint address.
 
#define PBL_UDC_STATE_DEFINE(sym)
 Define the runtime state of a controller.
 
#define PBL_UDC_INIT(sym, _name, _parent, _ops, _num_eps, _max_speed)
 Initializer of a controller.
 

Enumerations

enum  pbl_udc_ep_type { PBL_UDC_EP_CONTROL = 0 , PBL_UDC_EP_ISOCHRONOUS = 1 , PBL_UDC_EP_BULK = 2 , PBL_UDC_EP_INTERRUPT = 3 }
 Endpoint transfer types, as the endpoint descriptor gives them. More...
 
enum  pbl_udc_speed { PBL_UDC_SPEED_FULL , PBL_UDC_SPEED_HIGH }
 Bus speeds. More...
 
enum  pbl_udc_event {
  PBL_UDC_EVENT_RESET , PBL_UDC_EVENT_ENUMERATED , PBL_UDC_EVENT_SUSPEND , PBL_UDC_EVENT_RESUME ,
  PBL_UDC_EVENT_SETUP
}
 Bus events. More...
 

Functions

void pbl_udc_register (const struct pbl_udc *udc, const struct pbl_udc_callbacks *cb, void *arg)
 Take what the controller reports.
 
int pbl_udc_enable (const struct pbl_udc *udc)
 Connect to the bus.
 
int pbl_udc_disable (const struct pbl_udc *udc)
 Disconnect from the bus.
 
enum pbl_udc_speed pbl_udc_speed (const struct pbl_udc *udc)
 The speed the bus runs at, once enumerated.
 
int pbl_udc_set_address (const struct pbl_udc *udc, uint8_t addr)
 Take the address the host gave, before the status stage of its request.
 
int pbl_udc_ep_enable (const struct pbl_udc *udc, uint8_t ep, enum pbl_udc_ep_type type, uint16_t mps)
 Set an endpoint up.
 
int pbl_udc_ep_disable (const struct pbl_udc *udc, uint8_t ep)
 Shut an endpoint down.
 
int pbl_udc_ep_set_halt (const struct pbl_udc *udc, uint8_t ep, bool halt)
 Stall an endpoint, or clear its stall.
 
int pbl_udc_ep_queue (const struct pbl_udc *udc, uint8_t ep, void *buf, size_t len)
 Start a transfer.
 
void pbl_udc_event (const struct pbl_udc *udc, enum pbl_udc_event evt, const uint8_t *setup)
 Report a bus event, from the controller's interrupt.
 
void pbl_udc_xfer_done (const struct pbl_udc *udc, uint8_t ep, int ret)
 Report the end of a transfer, from the controller's interrupt.
 

Variables

const struct pbl_udc *const UDC
 The device controller of the board, for the USB device stack.
 

Detailed Description

The device side of a USB controller, which the USB device stack drives.

Endpoints are named by their address: the number, with PBL_UDC_EP_IN for the IN direction. Endpoint 0 is set up by the driver; the stack runs control transfers on it as a pair, 0x00 and 0x80.

Transfers are queued one at a time per endpoint with pbl_udc_ep_queue(). An IN transfer sends its bytes, a zero-length packet when it has none; an OUT transfer ends with a short packet or once its buffer is full. The driver reports the end of each with pbl_udc_xfer_done(), and bus events, setup packets among them, with pbl_udc_event(), both from its interrupt: the stack's callbacks run there.

The driver takes the address as soon as the stack sets it, before the status stage of the SET_ADDRESS request, as controllers that apply it in hardware need.


Data Structure Documentation

◆ pbl_udc

struct pbl_udc

USB device controller.

Data Fields
struct pbl_device dev Device.
enum pbl_udc_speed max_speed Fastest speed the controller and its PHY run at.
uint8_t num_eps Number of endpoints in each direction, endpoint 0 included.
const struct pbl_udc_ops * ops Driver operations.
struct pbl_udc_state * state Runtime state.

Macro Definition Documentation

◆ PBL_UDC_EP_IN

#define PBL_UDC_EP_IN   0x80U

Direction bit of an IN endpoint address.

◆ PBL_UDC_INIT

#define PBL_UDC_INIT (   sym,
  _name,
  _parent,
  _ops,
  _num_eps,
  _max_speed 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, pbl_udc_dev_init, _parent, &pbl_udc_class), \
.ops = (_ops), \
.state = &sym##_udc_state, \
.num_eps = (_num_eps), \
.max_speed = (_max_speed), \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:153

Initializer of a controller.

Parameters
symSymbol of the controller.
_nameName.
_parentParent device, or NULL.
_opsDriver operations.
_num_epsNumber of endpoints in each direction.
_max_speedFastest speed, one of pbl_udc_speed.

◆ PBL_UDC_STATE_DEFINE

#define PBL_UDC_STATE_DEFINE (   sym)
Value:
static struct pbl_udc_state sym##_udc_state
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:132

Define the runtime state of a controller.

Parameters
symSymbol of the controller.

Enumeration Type Documentation

◆ pbl_udc_ep_type

Endpoint transfer types, as the endpoint descriptor gives them.

Enumerator
PBL_UDC_EP_CONTROL 

Control.

PBL_UDC_EP_ISOCHRONOUS 

Isochronous.

PBL_UDC_EP_BULK 

Bulk.

PBL_UDC_EP_INTERRUPT 

Interrupt.

◆ pbl_udc_event

Bus events.

Enumerator
PBL_UDC_EVENT_RESET 

The host reset the bus: the device is back to its default state, at address 0.

PBL_UDC_EVENT_ENUMERATED 

The bus speed is known, after a reset.

PBL_UDC_EVENT_SUSPEND 

The bus went idle.

PBL_UDC_EVENT_RESUME 

The bus is active again.

PBL_UDC_EVENT_SETUP 

A setup packet arrived on endpoint 0.

◆ pbl_udc_speed

Bus speeds.

Enumerator
PBL_UDC_SPEED_FULL 

Full speed, 12 Mb/s.

PBL_UDC_SPEED_HIGH 

High speed, 480 Mb/s.

Function Documentation

◆ pbl_udc_disable()

int pbl_udc_disable ( const struct pbl_udc *  udc)

Disconnect from the bus.

Parameters
udcController.
Returns
0 or a negative errno.

◆ pbl_udc_enable()

int pbl_udc_enable ( const struct pbl_udc *  udc)

Connect to the bus.

Parameters
udcController.
Returns
0, -ENODEV if the controller is not ready, or another negative errno.

◆ pbl_udc_ep_disable()

int pbl_udc_ep_disable ( const struct pbl_udc *  udc,
uint8_t  ep 
)

Shut an endpoint down.

Parameters
udcController.
epEndpoint address.
Returns
0 or a negative errno.

◆ pbl_udc_ep_enable()

int pbl_udc_ep_enable ( const struct pbl_udc *  udc,
uint8_t  ep,
enum pbl_udc_ep_type  type,
uint16_t  mps 
)

Set an endpoint up.

Parameters
udcController.
epEndpoint address.
typeTransfer type.
mpsMaximum packet size.
Returns
0, -EINVAL for an endpoint the controller lacks, or another negative errno.

◆ pbl_udc_ep_queue()

int pbl_udc_ep_queue ( const struct pbl_udc *  udc,
uint8_t  ep,
void *  buf,
size_t  len 
)

Start a transfer.

Parameters
udcController.
epEndpoint address.
bufData to send, or room for what arrives, until the transfer ends.
lenIts length, in bytes.
Returns
0, -EBUSY if a transfer is under way on the endpoint, or another negative errno.

◆ pbl_udc_ep_set_halt()

int pbl_udc_ep_set_halt ( const struct pbl_udc *  udc,
uint8_t  ep,
bool  halt 
)

Stall an endpoint, or clear its stall.

Parameters
udcController.
epEndpoint address.
haltWhether to stall it.
Returns
0 or a negative errno.

◆ pbl_udc_event()

void pbl_udc_event ( const struct pbl_udc *  udc,
enum pbl_udc_event  evt,
const uint8_t *  setup 
)

Report a bus event, from the controller's interrupt.

Parameters
udcController.
evtEvent.
setupFor PBL_UDC_EVENT_SETUP, the 8 bytes of the setup packet.

◆ pbl_udc_register()

void pbl_udc_register ( const struct pbl_udc *  udc,
const struct pbl_udc_callbacks *  cb,
void *  arg 
)

Take what the controller reports.

Parameters
udcController.
cbCallbacks, which run from the controller's interrupt.
argArgument of the callbacks.

◆ pbl_udc_set_address()

int pbl_udc_set_address ( const struct pbl_udc *  udc,
uint8_t  addr 
)

Take the address the host gave, before the status stage of its request.

Parameters
udcController.
addrAddress.
Returns
0 or a negative errno.

◆ pbl_udc_speed()

enum pbl_udc_speed pbl_udc_speed ( const struct pbl_udc *  udc)

The speed the bus runs at, once enumerated.

Parameters
udcController.
Returns
Speed.

◆ pbl_udc_xfer_done()

void pbl_udc_xfer_done ( const struct pbl_udc *  udc,
uint8_t  ep,
int  ret 
)

Report the end of a transfer, from the controller's interrupt.

Parameters
udcController.
epEndpoint address.
retBytes moved, or a negative errno.

Variable Documentation

◆ UDC

const struct pbl_udc* const UDC
extern

The device controller of the board, for the USB device stack.