Audio Class 2 device API

USB Audio Class 2 device specific API defined in include/zephyr/usb/class/usbd_uac2.h.

API Reference

group uac2_device

USB Audio Class 2 device API.

Defines

UAC2_ENTITY_ID(node)

Get entity ID.

Parameters:
  • node – node identifier

Functions

void usbd_uac2_set_ops(const struct device *dev, const struct uac2_ops *ops, void *user_data)

Register USB Audio 2 application callbacks.

Parameters:
  • dev – USB Audio 2 device instance

  • ops – USB Audio 2 callback structure

  • user_data – Opaque user data to pass to ops callbacks

int usbd_uac2_send(const struct device *dev, uint8_t terminal, void *data, uint16_t size)

Send audio data to output terminal.

Data buffer must be sufficiently aligned and otherwise suitable for use by UDC driver.

Parameters:
  • dev – USB Audio 2 device

  • terminal – Output Terminal ID linked to AudioStreaming interface

  • data – Buffer containing outgoing data

  • size – Number of bytes to send

Returns:

0 on success, negative value on error

struct uac2_ops
#include <usbd_uac2.h>

USB Audio 2 application event handlers.

Public Members

void (*sof_cb)(const struct device *dev, void *user_data)

Start of Frame callback.

Notifies application about SOF event on the bus.

Param dev:

USB Audio 2 device

Param user_data:

Opaque user data pointer

void (*terminal_update_cb)(const struct device *dev, uint8_t terminal, bool enabled, bool microframes, void *user_data)

Terminal update callback.

Notifies application that host has enabled or disabled a terminal.

Param dev:

USB Audio 2 device

Param terminal:

Terminal ID linked to AudioStreaming interface

Param enabled:

True if host enabled terminal, False otherwise

Param microframes:

True if USB connection speed uses microframes

Param user_data:

Opaque user data pointer

void *(*get_recv_buf)(const struct device *dev, uint8_t terminal, uint16_t size, void *user_data)

Get receive buffer address.

USB stack calls this function to obtain receive buffer address for AudioStreaming interface. The buffer is owned by USB stack until data_recv_cb callback is called. The buffer must be sufficiently aligned and otherwise suitable for use by UDC driver.

Param dev:

USB Audio 2 device

Param terminal:

Input Terminal ID linked to AudioStreaming interface

Param size:

Maximum number of bytes USB stack will write to buffer.

Param user_data:

Opaque user data pointer

void (*data_recv_cb)(const struct device *dev, uint8_t terminal, void *buf, uint16_t size, void *user_data)

Data received.

This function releases buffer obtained in get_recv_buf after USB has written data to the buffer and/or no longer needs it.

Param dev:

USB Audio 2 device

Param terminal:

Input Terminal ID linked to AudioStreaming interface

Param buf:

Buffer previously obtained via get_recv_buf

Param size:

Number of bytes written to buffer

Param user_data:

Opaque user data pointer

void (*buf_release_cb)(const struct device *dev, uint8_t terminal, void *buf, void *user_data)

Transmit buffer release callback.

This function releases buffer provided in usbd_uac2_send when the class no longer needs it.

Param dev:

USB Audio 2 device

Param terminal:

Output Terminal ID linked to AudioStreaming interface

Param buf:

Buffer previously provided via usbd_uac2_send

Param user_data:

Opaque user data pointer

uint32_t (*feedback_cb)(const struct device *dev, uint8_t terminal, void *user_data)

Get Explicit Feedback value.

Explicit feedback value format depends terminal connection speed. If device is High-Speed capable, it must use Q16.16 format if and only if the terminal_update_cb was called with microframes parameter set to true. On Full-Speed only devices, or if High-Speed capable device is operating at Full-Speed (microframes was false), the format is Q10.14 stored on 24 least significant bits (i.e. 8 most significant bits are ignored).

Param dev:

USB Audio 2 device

Param terminal:

Input Terminal ID whose feedback should be returned

Param user_data:

Opaque user data pointer