The device side of a USB controller, which the USB device stack drives.
More...
|
| #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.
|
| |
|
| 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.
|
| |
|
| const struct pbl_udc *const | UDC |
| | The device controller of the board, for the USB device stack.
|
| |
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.
◆ pbl_udc
| 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. |
◆ 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: { \
.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
-
| sym | Symbol of the controller. |
| _name | Name. |
| _parent | Parent device, or NULL. |
| _ops | Driver operations. |
| _num_eps | Number of endpoints in each direction. |
| _max_speed | Fastest 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
-
| sym | Symbol of the controller. |
◆ 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.
|
◆ pbl_udc_disable()
| int pbl_udc_disable |
( |
const struct pbl_udc * |
udc | ) |
|
Disconnect from the bus.
- Parameters
-
- Returns
- 0 or a negative errno.
◆ pbl_udc_enable()
| int pbl_udc_enable |
( |
const struct pbl_udc * |
udc | ) |
|
Connect to the bus.
- Parameters
-
- 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
-
| udc | Controller. |
| ep | Endpoint address. |
- Returns
- 0 or a negative errno.
◆ pbl_udc_ep_enable()
Set an endpoint up.
- Parameters
-
| udc | Controller. |
| ep | Endpoint address. |
| type | Transfer type. |
| mps | Maximum 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
-
| udc | Controller. |
| ep | Endpoint address. |
| buf | Data to send, or room for what arrives, until the transfer ends. |
| len | Its 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
-
| udc | Controller. |
| ep | Endpoint address. |
| halt | Whether to stall it. |
- Returns
- 0 or a negative errno.
◆ pbl_udc_event()
Report a bus event, from the controller's interrupt.
- Parameters
-
◆ pbl_udc_register()
Take what the controller reports.
- Parameters
-
| udc | Controller. |
| cb | Callbacks, which run from the controller's interrupt. |
| arg | Argument 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
-
- Returns
- 0 or a negative errno.
◆ pbl_udc_speed()
The speed the bus runs at, once enumerated.
- Parameters
-
- 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
-
| udc | Controller. |
| ep | Endpoint address. |
| ret | Bytes moved, or a negative errno. |
◆ UDC
The device controller of the board, for the USB device stack.