blob: 96996ed3a783fc510fa6b886042d004550f250c0 [file] [log] [blame]
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Sample app for Audio class
*/
#include <zephyr.h>
#include <logging/log.h>
#include <usb/usb_device.h>
#include <usb/class/usb_audio.h>
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
static void data_received(const struct device *dev,
struct net_buf *buffer,
size_t size)
{
int ret;
if (!buffer || !size) {
/* This should never happen */
return;
}
LOG_DBG("Received %d data, buffer %p", size, buffer);
/* Check if the device OUT buffer can be used for input */
if (size == usb_audio_get_in_frame_size(dev)) {
ret = usb_audio_send(dev, buffer, size);
if (ret) {
net_buf_unref(buffer);
}
} else {
net_buf_unref(buffer);
}
}
static void feature_update(const struct device *dev,
const struct usb_audio_fu_evt *evt)
{
LOG_DBG("Control selector %d for channel %d updated",
evt->cs, evt->channel);
switch (evt->cs) {
case USB_AUDIO_FU_MUTE_CONTROL:
default:
break;
}
}
static const struct usb_audio_ops ops = {
.data_received_cb = data_received,
.feature_update_cb = feature_update,
};
void main(void)
{
const struct device *hs_dev;
int ret;
LOG_INF("Entered %s", __func__);
hs_dev = device_get_binding("HEADSET");
if (!hs_dev) {
LOG_ERR("Can not get USB Headset Device");
return;
}
LOG_INF("Found USB Headset Device");
usb_audio_register(hs_dev, &ops);
ret = usb_enable(NULL);
if (ret != 0) {
LOG_ERR("Failed to enable USB");
return;
}
LOG_INF("USB enabled");
}