Skip to content

File syn_usb.h

FileList > drivers > syn_usb.h

Go to the source code of this file

Zero-Heap Modular USB 2.0 Device Core Protocol Engine.

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

Classes

Type Name
struct SYN_USB_ClassDriver
struct SYN_USB_Device
struct SYN_USB_SetupPacket

Public Functions

Type Name
SYN_Status syn_usb_init (SYN_USB_Device * dev, const uint8_t * device_desc)
Initialize USB Device Core with standard 18-byte Device Descriptor.
bool syn_usb_is_configured (const SYN_USB_Device * dev)
Check if USB device is in CONFIGURED state.
SYN_Status syn_usb_process_setup (SYN_USB_Device * dev, const SYN_USB_SetupPacket * pkt, uint8_t * resp, uint16_t * rlen)
Process Control Setup packet from Host (EP0).
SYN_Status syn_usb_register_class (SYN_USB_Device * dev, const SYN_USB_ClassDriver * cls, const uint8_t * iface_desc, uint16_t iface_desc_len)
Register a class driver and append its interface descriptors.
SYN_Status syn_usb_set_raw_config_desc (SYN_USB_Device * dev, const uint8_t * desc, uint16_t len)
Set raw configuration descriptor pointer (overrides auto-assembly).
SYN_Status syn_usb_set_string_desc (SYN_USB_Device * dev, uint8_t index, const uint8_t * desc)
Set string descriptor pointer for a given index.

Macros

Type Name
define PT_USB_WAIT_CONFIGURED (pt, dev) [**PT\_WAIT\_UNTIL**](syn__pt_8h.md#define-pt_wait_until)(pt, [**syn\_usb\_is\_configured**](syn__usb_8c.md#function-syn_usb_is_configured)(dev))
Block a protothread coroutine until USB device reaches CONFIGURED state.
define SYN_USB_DESC_TYPE_CONFIGURATION 0x02U
define SYN_USB_DESC_TYPE_DEVICE 0x01U
define SYN_USB_DESC_TYPE_ENDPOINT 0x05U
define SYN_USB_DESC_TYPE_INTERFACE 0x04U
define SYN_USB_DESC_TYPE_STRING 0x03U
define SYN_USB_EP0_BUF_SIZE 64U
define SYN_USB_MAX_CLASSES 4U
define SYN_USB_MAX_CONFIG_DESC 256U
define SYN_USB_MAX_STRING_DESCS 8U
define SYN_USB_REQ_CLEAR_FEATURE 0x01U
define SYN_USB_REQ_GET_CONFIGURATION 0x08U
define SYN_USB_REQ_GET_DESCRIPTOR 0x06U
define SYN_USB_REQ_GET_STATUS 0x00U
define SYN_USB_REQ_SET_ADDRESS 0x05U
define SYN_USB_REQ_SET_CONFIGURATION 0x09U
define SYN_USB_REQ_SET_DESCRIPTOR 0x07U
define SYN_USB_REQ_SET_FEATURE 0x03U
define SYN_USB_STATE_ADDRESS 1U
define SYN_USB_STATE_CONFIGURED 2U
define SYN_USB_STATE_DEFAULT 0U

Public Functions Documentation

function syn_usb_init

Initialize USB Device Core with standard 18-byte Device Descriptor.

SYN_Status syn_usb_init (
    SYN_USB_Device * dev,
    const uint8_t * device_desc
) 

Parameters:

  • dev Pointer to USB device instance.
  • device_desc Pointer to 18-byte standard USB device descriptor.

Returns:

SYN_OK on success.


function syn_usb_is_configured

Check if USB device is in CONFIGURED state.

bool syn_usb_is_configured (
    const SYN_USB_Device * dev
) 

Parameters:

  • dev Pointer to USB device context.

Returns:

true if device is configured.


function syn_usb_process_setup

Process Control Setup packet from Host (EP0).

SYN_Status syn_usb_process_setup (
    SYN_USB_Device * dev,
    const SYN_USB_SetupPacket * pkt,
    uint8_t * resp,
    uint16_t * rlen
) 

Parameters:

  • dev Pointer to USB device context.
  • pkt Pointer to received Setup Packet.
  • resp Output buffer for data stage response.
  • rlen Output pointer to receive response byte length.

Returns:

SYN_OK on success.


function syn_usb_register_class

Register a class driver and append its interface descriptors.

SYN_Status syn_usb_register_class (
    SYN_USB_Device * dev,
    const SYN_USB_ClassDriver * cls,
    const uint8_t * iface_desc,
    uint16_t iface_desc_len
) 

Parameters:

  • dev Pointer to USB device context.
  • cls Class driver vtable and binding context.
  • iface_desc Pointer to class interface descriptor payload.
  • iface_desc_len Length of interface descriptor payload.

Returns:

SYN_OK on success.


function syn_usb_set_raw_config_desc

Set raw configuration descriptor pointer (overrides auto-assembly).

SYN_Status syn_usb_set_raw_config_desc (
    SYN_USB_Device * dev,
    const uint8_t * desc,
    uint16_t len
) 

Parameters:

  • dev Pointer to USB device context.
  • desc Pointer to raw configuration descriptor.
  • len Length in bytes.

Returns:

SYN_OK on success.


function syn_usb_set_string_desc

Set string descriptor pointer for a given index.

SYN_Status syn_usb_set_string_desc (
    SYN_USB_Device * dev,
    uint8_t index,
    const uint8_t * desc
) 

Parameters:

  • dev Pointer to USB device context.
  • index String index (0=Language ID, 1=Manufacturer, 2=Product, etc).
  • desc Pointer to UNICODE string descriptor.

Returns:

SYN_OK on success.


Macro Definition Documentation

define PT_USB_WAIT_CONFIGURED

Block a protothread coroutine until USB device reaches CONFIGURED state.

#define PT_USB_WAIT_CONFIGURED (
    pt,
    dev
) `PT_WAIT_UNTIL (pt, syn_usb_is_configured (dev))`

Parameters:

  • pt Protothread context.
  • dev Pointer to USB device instance.

define SYN_USB_DESC_TYPE_CONFIGURATION

#define SYN_USB_DESC_TYPE_CONFIGURATION `0x02U`

Configuration Descriptor Type (0x02)


define SYN_USB_DESC_TYPE_DEVICE

#define SYN_USB_DESC_TYPE_DEVICE `0x01U`

Descriptor Types Device Descriptor Type (0x01)


define SYN_USB_DESC_TYPE_ENDPOINT

#define SYN_USB_DESC_TYPE_ENDPOINT `0x05U`

Endpoint Descriptor Type (0x05)


define SYN_USB_DESC_TYPE_INTERFACE

#define SYN_USB_DESC_TYPE_INTERFACE `0x04U`

Interface Descriptor Type (0x04)


define SYN_USB_DESC_TYPE_STRING

#define SYN_USB_DESC_TYPE_STRING `0x03U`

String Descriptor Type (0x03)


define SYN_USB_EP0_BUF_SIZE

#define SYN_USB_EP0_BUF_SIZE `64U`

EP0 control buffer size


define SYN_USB_MAX_CLASSES

#define SYN_USB_MAX_CLASSES `4U`

Maximum registered class drivers


define SYN_USB_MAX_CONFIG_DESC

#define SYN_USB_MAX_CONFIG_DESC `256U`

Maximum auto-assembled configuration descriptor buffer capacity


define SYN_USB_MAX_STRING_DESCS

#define SYN_USB_MAX_STRING_DESCS `8U`

Maximum string descriptor slots


define SYN_USB_REQ_CLEAR_FEATURE

#define SYN_USB_REQ_CLEAR_FEATURE `0x01U`

USB Request Clear Feature (0x01)


define SYN_USB_REQ_GET_CONFIGURATION

#define SYN_USB_REQ_GET_CONFIGURATION `0x08U`

USB Request Get Configuration (0x08)


define SYN_USB_REQ_GET_DESCRIPTOR

#define SYN_USB_REQ_GET_DESCRIPTOR `0x06U`

USB Request Get Descriptor (0x06)


define SYN_USB_REQ_GET_STATUS

#define SYN_USB_REQ_GET_STATUS `0x00U`

Standard USB Request Codes per USB 2.0 Spec Table 9-4 USB Request Get Status (0x00)


define SYN_USB_REQ_SET_ADDRESS

#define SYN_USB_REQ_SET_ADDRESS `0x05U`

USB Request Set Address (0x05)


define SYN_USB_REQ_SET_CONFIGURATION

#define SYN_USB_REQ_SET_CONFIGURATION `0x09U`

USB Request Set Configuration (0x09)


define SYN_USB_REQ_SET_DESCRIPTOR

#define SYN_USB_REQ_SET_DESCRIPTOR `0x07U`

USB Request Set Descriptor (0x07)


define SYN_USB_REQ_SET_FEATURE

#define SYN_USB_REQ_SET_FEATURE `0x03U`

USB Request Set Feature (0x03)


define SYN_USB_STATE_ADDRESS

#define SYN_USB_STATE_ADDRESS `1U`

USB Address state


define SYN_USB_STATE_CONFIGURED

#define SYN_USB_STATE_CONFIGURED `2U`

USB Configured state


define SYN_USB_STATE_DEFAULT

#define SYN_USB_STATE_DEFAULT `0U`

USB Device States per USB 2.0 Spec ยง9.1.1 USB Default state



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