Skip to content

File syn_usb_hid.h

FileList > drivers > syn_usb_hid.h

Go to the source code of this file

Zero-Heap USB 2.0 Human Interface Device (HID) Class Driver.

  • #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_HID

Public Functions

Type Name
SYN_Status syn_usb_hid_init (SYN_USB_HID * hid)
Initialize USB HID Class Instance.
SYN_Status syn_usb_hid_read_report (SYN_USB_HID * hid, void * buf, size_t max_len, size_t * out_len)
Read received OUT report from host.
SYN_Status syn_usb_hid_register (SYN_USB_Device * dev, SYN_USB_HID * hid, const uint8_t * report_desc, uint16_t report_desc_len)
Register USB HID class driver with USB device core.
bool syn_usb_hid_report_available (const SYN_USB_HID * hid)
Check if OUT report is available.
SYN_Status syn_usb_hid_send_report (SYN_USB_HID * hid, const void * report, size_t len)
Queue an IN report for transmission to host.
bool syn_usb_hid_tx_ready (const SYN_USB_HID * hid)
Check if IN transmit buffer is ready.

Macros

Type Name
define PT_USB_HID_WAIT_RX (pt, hid) [**PT\_WAIT\_UNTIL**](syn__pt_8h.md#define-pt_wait_until)(pt, [**syn\_usb\_hid\_report\_available**](syn__usb__hid_8c.md#function-syn_usb_hid_report_available)(hid))
Block a protothread coroutine until an OUT report is available.
define PT_USB_HID_WAIT_TX_READY (pt, hid) [**PT\_WAIT\_UNTIL**](syn__pt_8h.md#define-pt_wait_until)(pt, [**syn\_usb\_hid\_tx\_ready**](syn__usb__hid_8c.md#function-syn_usb_hid_tx_ready)(hid))
Block a protothread coroutine until the IN report transmit buffer is ready.
define SYN_USB_HID_MAX_REPORT_SIZE 64U
define SYN_USB_HID_REQ_GET_IDLE 0x02U
define SYN_USB_HID_REQ_GET_PROTOCOL 0x03U
define SYN_USB_HID_REQ_GET_REPORT 0x01U
define SYN_USB_HID_REQ_SET_IDLE 0x0AU
define SYN_USB_HID_REQ_SET_PROTOCOL 0x0BU
define SYN_USB_HID_REQ_SET_REPORT 0x09U

Public Functions Documentation

function syn_usb_hid_init

Initialize USB HID Class Instance.

SYN_Status syn_usb_hid_init (
    SYN_USB_HID * hid
) 

Parameters:

  • hid Pointer to USB HID instance.

Returns:

SYN_OK on success.


function syn_usb_hid_read_report

Read received OUT report from host.

SYN_Status syn_usb_hid_read_report (
    SYN_USB_HID * hid,
    void * buf,
    size_t max_len,
    size_t * out_len
) 

Parameters:

  • hid Pointer to USB HID instance.
  • buf Output buffer.
  • max_len Capacity.
  • out_len Pointer to receive read byte count.

Returns:

SYN_OK on success.


function syn_usb_hid_register

Register USB HID class driver with USB device core.

SYN_Status syn_usb_hid_register (
    SYN_USB_Device * dev,
    SYN_USB_HID * hid,
    const uint8_t * report_desc,
    uint16_t report_desc_len
) 

Parameters:

  • dev Pointer to USB device core context.
  • hid Pointer to USB HID instance.
  • report_desc Pointer to static HID report descriptor.
  • report_desc_len Byte length of report descriptor.

Returns:

SYN_OK on success.


function syn_usb_hid_report_available

Check if OUT report is available.

bool syn_usb_hid_report_available (
    const SYN_USB_HID * hid
) 

Parameters:

  • hid Pointer to USB HID instance.

Returns:

true if unread report data exists.


function syn_usb_hid_send_report

Queue an IN report for transmission to host.

SYN_Status syn_usb_hid_send_report (
    SYN_USB_HID * hid,
    const void * report,
    size_t len
) 

Parameters:

  • hid Pointer to USB HID instance.
  • report Pointer to report data.
  • len Report byte length.

Returns:

SYN_OK on success.


function syn_usb_hid_tx_ready

Check if IN transmit buffer is ready.

bool syn_usb_hid_tx_ready (
    const SYN_USB_HID * hid
) 

Parameters:

  • hid Pointer to USB HID instance.

Returns:

true if transmit buffer is free.


Macro Definition Documentation

define PT_USB_HID_WAIT_RX

Block a protothread coroutine until an OUT report is available.

#define PT_USB_HID_WAIT_RX (
    pt,
    hid
) `PT_WAIT_UNTIL (pt, syn_usb_hid_report_available (hid))`

Parameters:

  • pt Protothread context.
  • hid Pointer to USB HID instance.

define PT_USB_HID_WAIT_TX_READY

Block a protothread coroutine until the IN report transmit buffer is ready.

#define PT_USB_HID_WAIT_TX_READY (
    pt,
    hid
) `PT_WAIT_UNTIL (pt, syn_usb_hid_tx_ready (hid))`

Parameters:

  • pt Protothread context.
  • hid Pointer to USB HID instance.

define SYN_USB_HID_MAX_REPORT_SIZE

#define SYN_USB_HID_MAX_REPORT_SIZE `64U`

Maximum HID report size


define SYN_USB_HID_REQ_GET_IDLE

#define SYN_USB_HID_REQ_GET_IDLE `0x02U`

HID Request Get Idle (0x02)


define SYN_USB_HID_REQ_GET_PROTOCOL

#define SYN_USB_HID_REQ_GET_PROTOCOL `0x03U`

HID Request Get Protocol (0x03)


define SYN_USB_HID_REQ_GET_REPORT

#define SYN_USB_HID_REQ_GET_REPORT `0x01U`

HID Class Specific Requests per USB HID Spec 1.11 ยง7.2 HID Request Get Report (0x01)


define SYN_USB_HID_REQ_SET_IDLE

#define SYN_USB_HID_REQ_SET_IDLE `0x0AU`

HID Request Set Idle (0x0A)


define SYN_USB_HID_REQ_SET_PROTOCOL

#define SYN_USB_HID_REQ_SET_PROTOCOL `0x0BU`

HID Request Set Protocol (0x0B)


define SYN_USB_HID_REQ_SET_REPORT

#define SYN_USB_HID_REQ_SET_REPORT `0x09U`

HID Request Set Report (0x09)



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