1 /**
2  * @file
3  * @brief Bluetooth BAP Broadcast Sink sample USB header
4  *
5  * This files handles all the USB related functionality for the sample
6  *
7  * Copyright (c) 2025 Nordic Semiconductor ASA
8  *
9  * SPDX-License-Identifier: Apache-2.0
10  */
11 
12 #ifndef SAMPLE_BAP_BROADCAST_SINK_USB_H
13 #define SAMPLE_BAP_BROADCAST_SINK_USB_H
14 #include <stdbool.h>
15 #include <stddef.h>
16 #include <stdint.h>
17 #include <string.h>
18 
19 #include <zephyr/autoconf.h>
20 #include <zephyr/bluetooth/audio/audio.h>
21 #include <zephyr/device.h>
22 #include <zephyr/devicetree.h>
23 #include <zephyr/kernel.h>
24 #include <zephyr/logging/log.h>
25 #include <zephyr/net_buf.h>
26 #include <zephyr/shell/shell.h>
27 #include <zephyr/sys/ring_buffer.h>
28 #include <zephyr/sys/util.h>
29 #include <zephyr/sys/util_macro.h>
30 #include <zephyr/sys_clock.h>
31 #include <zephyr/toolchain.h>
32 #include <zephyr/usb/usb_device.h>
33 #include <zephyr/usb/class/usb_audio.h>
34 
35 #define USB_SAMPLE_RATE_HZ 48000U
36 
37 /**
38  * @brief Add decoded frame to the USB buffer
39  *
40  * @param chan_allocation The channel of the frame (@ref BT_AUDIO_LOCATION_FRONT_LEFT, @ref
41  *                        BT_AUDIO_LOCATION_FRONT_RIGHT or @ref BT_AUDIO_LOCATION_MONO_AUDIO)
42  * @param frame The frame
43  * @param frame_size The size of @p in octets
44  * @param ts The timestamp of the frame
45  *
46  * @retval 0 Success
47  * @retval -EINVAL Invalid channel, frame of framesize
48  * @retval -ENOEXEC Old timestamp, discarded
49  * @retval -ENOMEM No memory to enqueue
50  */
51 int usb_add_frame_to_usb(enum bt_audio_location chan_allocation, const int16_t *frame,
52 			 size_t frame_size, uint32_t ts);
53 
54 /**
55  * @brief Clear last sent SDU
56  *
57  * If only part of the SDU could be decoded, this should be called
58  */
59 void usb_clear_frames_to_usb(void);
60 
61 /**
62  * @brief Initialize the USB module
63  *
64  * This will start the USB thread if not already initialized
65  *
66  * @retval 0 Success
67  * @retval -EALREADY Already initialized
68  */
69 int usb_init(void);
70 
71 #endif /* SAMPLE_BAP_BROADCAST_SINK_USB_H */
72