Skip to content

File syn_usb_cdc.h

FileList > drivers > syn_usb_cdc.h

Go to the source code of this file

Zero-Heap USB 2.0 CDC ACM Virtual COM Port Class Driver. 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_CDC
struct SYN_USB_CDC_LineCoding

Public Functions

Type Name
SYN_Status syn_usb_cdc_handle_setup (SYN_USB_CDC * cdc, const SYN_USB_SetupPacket * setup, uint8_t * resp, size_t * rlen)
Handle Control Setup Request from host (EP0).
SYN_Status syn_usb_cdc_init (SYN_USB_CDC * cdc)
Initialize USB CDC Class instance with defaults (115200 baud, 8N1).
SYN_Status syn_usb_cdc_read (SYN_USB_CDC * cdc, void * buf, size_t max_len, size_t * out_len)
Read bytes from USB CDC Bulk OUT receive buffer.
SYN_Status syn_usb_cdc_register (SYN_USB_Device * dev, SYN_USB_CDC * cdc)
Register USB CDC ACM class driver with USB device core.
bool syn_usb_cdc_rx_available (const SYN_USB_CDC * cdc)
Check if receive data is available.
bool syn_usb_cdc_tx_ready (const SYN_USB_CDC * cdc)
Check if transmit buffer is ready.
SYN_Status syn_usb_cdc_write (SYN_USB_CDC * cdc, const void * data, size_t len)
Write bytes to USB CDC Bulk IN transmit buffer.

Macros

Type Name
define PT_USB_CDC_WAIT_RX (pt, cdc) [**PT\_WAIT\_UNTIL**](syn__pt_8h.md#define-pt_wait_until)(pt, [**syn\_usb\_cdc\_rx\_available**](syn__usb__cdc_8c.md#function-syn_usb_cdc_rx_available)(cdc))
Block a protothread coroutine until CDC RX data is available.
define PT_USB_CDC_WAIT_TX_READY (pt, cdc) [**PT\_WAIT\_UNTIL**](syn__pt_8h.md#define-pt_wait_until)(pt, [**syn\_usb\_cdc\_tx\_ready**](syn__usb__cdc_8c.md#function-syn_usb_cdc_tx_ready)(cdc))
Block a protothread coroutine until CDC TX buffer is ready.
define SYN_USB_CDC_GET_LINE_CODING 0x21U
define SYN_USB_CDC_SET_CONTROL_LINE_STATE 0x22U
define SYN_USB_CDC_SET_LINE_CODING 0x20U

Detailed Description

USB CDC specifications: * Interface 0: CDC Communication Class (Interrupt EP 0x82 / 8B). * Interface 1: CDC Data Class (Bulk IN EP 0x81 / 64B, Bulk OUT EP 0x01 / 64B).

Public Functions Documentation

function syn_usb_cdc_handle_setup

Handle Control Setup Request from host (EP0).

SYN_Status syn_usb_cdc_handle_setup (
    SYN_USB_CDC * cdc,
    const SYN_USB_SetupPacket * setup,
    uint8_t * resp,
    size_t * rlen
) 

Parameters:

  • cdc Pointer to USB CDC instance.
  • setup Pointer to setup packet.
  • resp Pointer to response buffer.
  • rlen Pointer to receive response length.

Returns:

SYN_OK on success.


function syn_usb_cdc_init

Initialize USB CDC Class instance with defaults (115200 baud, 8N1).

SYN_Status syn_usb_cdc_init (
    SYN_USB_CDC * cdc
) 

Parameters:

  • cdc Pointer to USB CDC instance.

Returns:

SYN_OK on success.


function syn_usb_cdc_read

Read bytes from USB CDC Bulk OUT receive buffer.

SYN_Status syn_usb_cdc_read (
    SYN_USB_CDC * cdc,
    void * buf,
    size_t max_len,
    size_t * out_len
) 

Parameters:

  • cdc Pointer to USB CDC instance.
  • buf Pointer to destination buffer.
  • max_len Max capacity.
  • out_len Pointer to receive read byte count.

Returns:

SYN_OK on success.


function syn_usb_cdc_register

Register USB CDC ACM class driver with USB device core.

SYN_Status syn_usb_cdc_register (
    SYN_USB_Device * dev,
    SYN_USB_CDC * cdc
) 

Parameters:

  • dev Pointer to USB device core context.
  • cdc Pointer to USB CDC instance.

Returns:

SYN_OK on success.


function syn_usb_cdc_rx_available

Check if receive data is available.

bool syn_usb_cdc_rx_available (
    const SYN_USB_CDC * cdc
) 

Parameters:

  • cdc Pointer to USB CDC instance.

Returns:

true if unread data is present in rx_buf.


function syn_usb_cdc_tx_ready

Check if transmit buffer is ready.

bool syn_usb_cdc_tx_ready (
    const SYN_USB_CDC * cdc
) 

Parameters:

  • cdc Pointer to USB CDC instance.

Returns:

true if transmit buffer is available.


function syn_usb_cdc_write

Write bytes to USB CDC Bulk IN transmit buffer.

SYN_Status syn_usb_cdc_write (
    SYN_USB_CDC * cdc,
    const void * data,
    size_t len
) 

Parameters:

  • cdc Pointer to USB CDC instance.
  • data Pointer to data bytes.
  • len Byte length.

Returns:

SYN_OK on success.


Macro Definition Documentation

define PT_USB_CDC_WAIT_RX

Block a protothread coroutine until CDC RX data is available.

#define PT_USB_CDC_WAIT_RX (
    pt,
    cdc
) `PT_WAIT_UNTIL (pt, syn_usb_cdc_rx_available (cdc))`

Parameters:

  • pt Protothread context.
  • cdc Pointer to USB CDC instance.

define PT_USB_CDC_WAIT_TX_READY

Block a protothread coroutine until CDC TX buffer is ready.

#define PT_USB_CDC_WAIT_TX_READY (
    pt,
    cdc
) `PT_WAIT_UNTIL (pt, syn_usb_cdc_tx_ready (cdc))`

Parameters:

  • pt Protothread context.
  • cdc Pointer to USB CDC instance.

define SYN_USB_CDC_GET_LINE_CODING

#define SYN_USB_CDC_GET_LINE_CODING `0x21U`

CDC Request Get Line Coding (0x21)


define SYN_USB_CDC_SET_CONTROL_LINE_STATE

#define SYN_USB_CDC_SET_CONTROL_LINE_STATE `0x22U`

CDC Request Set Control Line State (0x22)


define SYN_USB_CDC_SET_LINE_CODING

#define SYN_USB_CDC_SET_LINE_CODING `0x20U`

CDC Request Set Line Coding (0x20)



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