Skip to content

File syn_usb_host.h

FileList > drivers > syn_usb_host.h

Go to the source code of this file

Zero-Heap USB 2.0 Host Core Protocol Engine. More...

  • #include "syntropic/common/syn_defs.h"
  • #include "syntropic/drivers/syn_usb.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>
  • #include "syntropic/pt/syn_pt.h"

Classes

Type Name
struct SYN_USB_Host
struct SYN_USB_HostClassDriver
struct SYN_USB_HostDevInfo

Public Functions

Type Name
const SYN_USB_HostDevInfo * syn_usb_host_get_dev_info (const SYN_USB_Host * host)
Get cached device information from last enumeration.
SYN_Status syn_usb_host_init (SYN_USB_Host * host)
Initialize USB Host Core.
bool syn_usb_host_is_ready (const SYN_USB_Host * host)
Check if USB Host has a device enumerated and ready.
SYN_Status syn_usb_host_process (SYN_USB_Host * host)
Process USB Host state machine (call each scheduler tick).
SYN_Status syn_usb_host_register_class (SYN_USB_Host * host, const SYN_USB_HostClassDriver * cls)
Register a host class driver for interface matching.

Macros

Type Name
define PT_USB_HOST_WAIT_READY (pt, host) [**PT\_WAIT\_UNTIL**](syn__pt_8h.md#define-pt_wait_until)(pt, [**syn\_usb\_host\_is\_ready**](syn__usb__host_8c.md#function-syn_usb_host_is_ready)(host))
Block a protothread coroutine until a USB device is enumerated and ready.
define SYN_USB_HOST_ENUM_BUF_SIZE 256U
define SYN_USB_HOST_ENUM_CLASS_PROBE 5U
define SYN_USB_HOST_ENUM_DONE 6U
define SYN_USB_HOST_ENUM_GET_CFG 3U
define SYN_USB_HOST_ENUM_GET_DEV8 0U
define SYN_USB_HOST_ENUM_GET_DEV_FULL 2U
define SYN_USB_HOST_ENUM_SET_ADDR 1U
define SYN_USB_HOST_ENUM_SET_CFG 4U
define SYN_USB_HOST_MAX_CLASSES 4U
define SYN_USB_HOST_MAX_PIPES 4U
define SYN_USB_HOST_STATE_ATTACHED 1U
define SYN_USB_HOST_STATE_DISCONNECTED 0U
define SYN_USB_HOST_STATE_ENUMERATING 3U
define SYN_USB_HOST_STATE_ERROR 5U
define SYN_USB_HOST_STATE_READY 4U
define SYN_USB_HOST_STATE_RESET 2U

Detailed Description

Manages device attach/detach detection, bus reset, standard enumeration (GET_DESCRIPTOR, SET_ADDRESS, SET_CONFIGURATION), and dispatches matched interfaces to registered host class drivers.

Public Functions Documentation

function syn_usb_host_get_dev_info

Get cached device information from last enumeration.

const SYN_USB_HostDevInfo * syn_usb_host_get_dev_info (
    const SYN_USB_Host * host
) 

Parameters:

  • host Pointer to USB Host instance.

Returns:

Pointer to device info struct, or NULL if no device.


function syn_usb_host_init

Initialize USB Host Core.

SYN_Status syn_usb_host_init (
    SYN_USB_Host * host
) 

Parameters:

  • host Pointer to USB Host instance.

Returns:

SYN_OK on success.


function syn_usb_host_is_ready

Check if USB Host has a device enumerated and ready.

bool syn_usb_host_is_ready (
    const SYN_USB_Host * host
) 

Parameters:

  • host Pointer to USB Host instance.

Returns:

true if host state is READY.


function syn_usb_host_process

Process USB Host state machine (call each scheduler tick).

SYN_Status syn_usb_host_process (
    SYN_USB_Host * host
) 

Drives attach detection, bus reset, enumeration, class probing, and detach handling. Non-blocking.

Parameters:

  • host Pointer to USB Host instance.

Returns:

SYN_OK on success, SYN_BUSY if transfer pending.


function syn_usb_host_register_class

Register a host class driver for interface matching.

SYN_Status syn_usb_host_register_class (
    SYN_USB_Host * host,
    const SYN_USB_HostClassDriver * cls
) 

Parameters:

  • host Pointer to USB Host instance.
  • cls Host class driver vtable.

Returns:

SYN_OK on success.


Macro Definition Documentation

define PT_USB_HOST_WAIT_READY

Block a protothread coroutine until a USB device is enumerated and ready.

#define PT_USB_HOST_WAIT_READY (
    pt,
    host
) `PT_WAIT_UNTIL (pt, syn_usb_host_is_ready (host))`

Parameters:

  • pt Protothread context.
  • host Pointer to USB Host instance.

define SYN_USB_HOST_ENUM_BUF_SIZE

#define SYN_USB_HOST_ENUM_BUF_SIZE `256U`

Enumeration descriptor scratch buffer


define SYN_USB_HOST_ENUM_CLASS_PROBE

#define SYN_USB_HOST_ENUM_CLASS_PROBE `5U`

Match & probe class drivers


define SYN_USB_HOST_ENUM_DONE

#define SYN_USB_HOST_ENUM_DONE `6U`

Enumeration complete


define SYN_USB_HOST_ENUM_GET_CFG

#define SYN_USB_HOST_ENUM_GET_CFG `3U`

Read Configuration Descriptor


define SYN_USB_HOST_ENUM_GET_DEV8

#define SYN_USB_HOST_ENUM_GET_DEV8 `0U`

Enumeration sub-steps (internal to ENUMERATING state) Read first 8 bytes of Device Desc


define SYN_USB_HOST_ENUM_GET_DEV_FULL

#define SYN_USB_HOST_ENUM_GET_DEV_FULL `2U`

Read full 18-byte Device Desc


define SYN_USB_HOST_ENUM_SET_ADDR

#define SYN_USB_HOST_ENUM_SET_ADDR `1U`

Assign bus address


define SYN_USB_HOST_ENUM_SET_CFG

#define SYN_USB_HOST_ENUM_SET_CFG `4U`

Issue SET_CONFIGURATION


define SYN_USB_HOST_MAX_CLASSES

#define SYN_USB_HOST_MAX_CLASSES `4U`

Maximum registered host class drivers


define SYN_USB_HOST_MAX_PIPES

#define SYN_USB_HOST_MAX_PIPES `4U`

Maximum host pipes (EP0 + data pipes)


define SYN_USB_HOST_STATE_ATTACHED

#define SYN_USB_HOST_STATE_ATTACHED `1U`

Device physically present


define SYN_USB_HOST_STATE_DISCONNECTED

#define SYN_USB_HOST_STATE_DISCONNECTED `0U`

USB Host States No device attached


define SYN_USB_HOST_STATE_ENUMERATING

#define SYN_USB_HOST_STATE_ENUMERATING `3U`

Reading descriptors & assigning address


define SYN_USB_HOST_STATE_ERROR

#define SYN_USB_HOST_STATE_ERROR `5U`

Enumeration or transfer error


define SYN_USB_HOST_STATE_READY

#define SYN_USB_HOST_STATE_READY `4U`

Device enumerated and class active


define SYN_USB_HOST_STATE_RESET

#define SYN_USB_HOST_STATE_RESET `2U`

Bus reset in progress



The documentation for this class was generated from the following file src/syntropic/drivers/syn_usb_host.h