Skip to content

Commit 3db5c6f

Browse files
Thalleyfabiobaltieri
authored andcommitted
samples: Bluetooth: BAP: Sink: Reverse in/out terminology
In USB "in" refers to data going from device to host, and "out" refers to data going from host to device. From a BT perspective "usb_in" then refers to the data we send from the device to the host, that has been received over BT. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 146dce9 commit 3db5c6f

File tree

1 file changed

+10
-11
lines changed
  • samples/bluetooth/bap_broadcast_sink/src

1 file changed

+10
-11
lines changed

samples/bluetooth/bap_broadcast_sink/src/usb.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ LOG_MODULE_REGISTER(usb, CONFIG_LOG_DEFAULT_LEVEL);
4646
#define USB_MONO_FRAME_SIZE (USB_SAMPLE_CNT * USB_BYTES_PER_SAMPLE)
4747
#define USB_CHANNELS 2U
4848
#define USB_STEREO_FRAME_SIZE (USB_MONO_FRAME_SIZE * USB_CHANNELS)
49-
#define USB_OUT_RING_BUF_SIZE (CONFIG_BT_ISO_RX_BUF_COUNT * LC3_MAX_NUM_SAMPLES_STEREO)
50-
#define USB_IN_RING_BUF_SIZE (USB_MONO_FRAME_SIZE * USB_ENQUEUE_COUNT)
49+
#define USB_IN_RING_BUF_SIZE (CONFIG_BT_ISO_RX_BUF_COUNT * LC3_MAX_NUM_SAMPLES_STEREO)
5150

5251
#define IN_TERMINAL_ID UAC2_ENTITY_ID(DT_NODELABEL(in_terminal))
5352

@@ -60,8 +59,8 @@ struct decoded_sdu {
6059
uint32_t ts;
6160
} decoded_sdu;
6261

63-
RING_BUF_DECLARE(usb_out_ring_buf, USB_OUT_RING_BUF_SIZE);
64-
K_MEM_SLAB_DEFINE_STATIC(usb_out_buf_pool, ROUND_UP(USB_STEREO_FRAME_SIZE, UDC_BUF_GRANULARITY),
62+
RING_BUF_DECLARE(usb_in_ring_buf, USB_IN_RING_BUF_SIZE);
63+
K_MEM_SLAB_DEFINE_STATIC(usb_in_buf_pool, ROUND_UP(USB_STEREO_FRAME_SIZE, UDC_BUF_GRANULARITY),
6564
USB_ENQUEUE_COUNT, UDC_BUF_ALIGN);
6665
static volatile bool terminal_enabled;
6766

@@ -74,17 +73,17 @@ static void uac2_sof_cb(const struct device *dev, void *user_data)
7473

7574
if (!terminal_enabled) {
7675
/* Simply discard the data then */
77-
(void)ring_buf_get(&usb_out_ring_buf, NULL, USB_STEREO_FRAME_SIZE);
76+
(void)ring_buf_get(&usb_in_ring_buf, NULL, USB_STEREO_FRAME_SIZE);
7877
return;
7978
}
8079

81-
err = k_mem_slab_alloc(&usb_out_buf_pool, &pcm_buf, K_NO_WAIT);
80+
err = k_mem_slab_alloc(&usb_in_buf_pool, &pcm_buf, K_NO_WAIT);
8281
if (err != 0) {
8382
LOG_WRN("Could not allocate pcm_buf");
8483
return;
8584
}
8685

87-
size = ring_buf_get(&usb_out_ring_buf, pcm_buf, USB_STEREO_FRAME_SIZE);
86+
size = ring_buf_get(&usb_in_ring_buf, pcm_buf, USB_STEREO_FRAME_SIZE);
8887
if (size != USB_STEREO_FRAME_SIZE) {
8988
/* If we could not fill the buffer, zero-fill the rest (possibly all) */
9089
memset(((uint8_t *)pcm_buf) + size, 0, USB_STEREO_FRAME_SIZE - size);
@@ -116,14 +115,14 @@ static void uac2_sof_cb(const struct device *dev, void *user_data)
116115
}
117116
}
118117

119-
k_mem_slab_free(&usb_out_buf_pool, pcm_buf);
118+
k_mem_slab_free(&usb_in_buf_pool, pcm_buf);
120119
} /* USB owns the buffer which will be released in uac2_buf_release_cb */
121120
}
122121

123122
static void uac2_buf_release_cb(const struct device *dev, uint8_t terminal, void *buf,
124123
void *user_data)
125124
{
126-
k_mem_slab_free(&usb_out_buf_pool, buf);
125+
k_mem_slab_free(&usb_in_buf_pool, buf);
127126
}
128127

129128
static void terminal_update_cb(const struct device *dev, uint8_t terminal, bool enabled,
@@ -156,7 +155,7 @@ static void usb_send_frames_to_usb(void)
156155
uint32_t rb_size;
157156

158157
/* Not enough space to store data */
159-
if (ring_buf_space_get(&usb_out_ring_buf) < sizeof(stereo_frame)) {
158+
if (ring_buf_space_get(&usb_in_ring_buf) < sizeof(stereo_frame)) {
160159
if (CONFIG_INFO_REPORTING_INTERVAL > 0 &&
161160
(fail_cnt % CONFIG_INFO_REPORTING_INTERVAL) == 0U) {
162161
LOG_WRN("[%zu] Could not send more than %zu frames to USB",
@@ -195,7 +194,7 @@ static void usb_send_frames_to_usb(void)
195194
}
196195
}
197196

198-
rb_size = ring_buf_put(&usb_out_ring_buf, (uint8_t *)stereo_frame,
197+
rb_size = ring_buf_put(&usb_in_ring_buf, (uint8_t *)stereo_frame,
199198
sizeof(stereo_frame));
200199
if (rb_size != sizeof(stereo_frame)) {
201200
LOG_WRN("Failed to put frame on USB ring buf");

0 commit comments

Comments
 (0)