Skip to content

Commit fe2da75

Browse files
alexsvennordicjm
authored andcommitted
applications: nrf5340_audio: Update code to follow upmerge
- Change to nrf_gpio_pin_control_select in led.c - Fix reset bug in program.py - Add sequence number to le_audio_send in both BIS and CIS - Add location and context to all presets Signed-off-by: Alexander Svensen <alexander.svensen@nordicsemi.no>
1 parent 0342d91 commit fe2da75

File tree

10 files changed

+3917
-3791
lines changed

10 files changed

+3917
-3791
lines changed

applications/nrf5340_audio/bin/ble5-ctr-rpmsg_3296.hex renamed to applications/nrf5340_audio/bin/ble5-ctr-rpmsg_3301.hex

Lines changed: 3821 additions & 3758 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
description: LE Audio Controller Subsystem for nRF53
2-
git_revision: 640e043873fee52cf9e6d2e5625a8180ee275f92
3-
ll_subversion_number: '0x0CE0'
2+
git_revision: 722e1bbc2f69cd95f0cd13540b5754d1ddaa3e48
3+
ll_subversion_number: '0x0CE5'
44
ll_version_number: '0x0B'
5-
ll_subversion_number_decimal: '3296'
5+
ll_subversion_number_decimal: '3301'
66
ll_version_number_decimal: '11'
7-
timestamp: '2022-08-09T08:03:54Z'
7+
timestamp: '2022-08-16T14:33:02Z'

applications/nrf5340_audio/src/bluetooth/Kconfig.defaults

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ config BT_OBSERVER
180180
bool
181181
default y
182182

183+
config BT_PERIPHERAL
184+
bool
185+
default y
186+
183187
config BT_ISO_SYNC_RECEIVER
184188
bool
185189
default y
@@ -200,6 +204,14 @@ config BT_ISO_MAX_CHAN
200204
int
201205
default 2
202206

207+
config BT_SMP
208+
bool
209+
default y
210+
211+
config BT_PAC_SNK
212+
bool
213+
default y
214+
203215
endif # AUDIO_DEV = 1 (HEADSET)
204216

205217
# GATEWAY

applications/nrf5340_audio/src/bluetooth/le_audio_bis_gateway.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ BUILD_ASSERT(CONFIG_BT_AUDIO_BROADCAST_SRC_STREAM_COUNT <= 2,
2626
#define BT_AUDIO_LC3_BROADCAST_PRESET_NRF5340_AUDIO \
2727
BT_AUDIO_LC3_PRESET( \
2828
BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
29-
BT_CODEC_CONFIG_LC3_DURATION_10, \
30-
LE_AUDIO_SDU_SIZE_OCTETS(CONFIG_LC3_BITRATE), \
29+
BT_CODEC_CONFIG_LC3_DURATION_10, BT_AUDIO_LOCATION_FRONT_LEFT, \
30+
LE_AUDIO_SDU_SIZE_OCTETS(CONFIG_LC3_BITRATE), 1, \
3131
BT_AUDIO_CONTEXT_TYPE_MEDIA), \
3232
BT_CODEC_LC3_QOS_10_UNFRAMED(LE_AUDIO_SDU_SIZE_OCTETS(CONFIG_LC3_BITRATE), 4u, \
3333
20u, LE_AUDIO_PRES_DELAY_US))
@@ -53,6 +53,7 @@ static struct bt_audio_lc3_preset lc3_preset = BT_AUDIO_LC3_BROADCAST_PRESET_NRF
5353

5454
static atomic_t iso_tx_pool_alloc[CONFIG_BT_ISO_MAX_CHAN];
5555
static bool delete_broadcast_src;
56+
static uint32_t seq_num[CONFIG_BT_ISO_MAX_CHAN];
5657

5758
static bool is_iso_buffer_full(uint8_t idx)
5859
{
@@ -243,7 +244,7 @@ int le_audio_send(uint8_t const *const data, size_t size)
243244

244245
atomic_inc(&iso_tx_pool_alloc[i]);
245246

246-
ret = bt_audio_stream_send(&streams[i], buf);
247+
ret = bt_audio_stream_send(&streams[i], buf, seq_num[i]++, BT_ISO_TIMESTAMP_NONE);
247248
if (ret < 0) {
248249
LOG_WRN("Failed to send audio data: %d", ret);
249250
net_buf_unref(buf);

applications/nrf5340_audio/src/bluetooth/le_audio_bis_headset.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <bluetooth/bluetooth.h>
1010
#include <bluetooth/audio/audio.h>
11+
#include <bluetooth/audio/capabilities.h>
12+
1113
/* TODO: Remove when a get_info function is implemented in host */
1214
#include <../subsys/bluetooth/audio/endpoint.h>
1315

@@ -27,7 +29,9 @@ static struct bt_audio_broadcast_sink *broadcast_sink;
2729
static struct bt_audio_stream streams[CONFIG_LC3_DEC_CHAN_MAX];
2830
static struct bt_audio_stream *streams_p[ARRAY_SIZE(streams)];
2931

30-
static struct bt_audio_lc3_preset lc3_preset = BT_AUDIO_LC3_BROADCAST_PRESET_48_4_1;
32+
/* We need to set a location as a pre-compile, this changed in initialize */
33+
static struct bt_codec codec =
34+
BT_CODEC_LC3_CONFIG_48_4(BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_MEDIA);
3135

3236
/* Create a mask for the maximum BIS we can sync to using the number of streams
3337
* broadcasted. We add an additional 1 since the bis indexes start from 1 and not
@@ -128,7 +132,8 @@ static struct bt_audio_stream_ops stream_ops = { .started = stream_started_cb,
128132
.stopped = stream_stopped_cb,
129133
.recv = stream_recv_cb };
130134

131-
static bool scan_recv_cb(const struct bt_le_scan_recv_info *info, uint32_t broadcast_id)
135+
static bool scan_recv_cb(const struct bt_le_scan_recv_info *info, struct net_buf_simple *ad,
136+
uint32_t broadcast_id)
132137
{
133138
LOG_DBG("Broadcast source found, waiting for PA sync");
134139

@@ -256,8 +261,7 @@ static void syncable_cb(struct bt_audio_broadcast_sink *sink, bool encrypted)
256261

257262
LOG_INF("Syncing to broadcast");
258263

259-
ret = bt_audio_broadcast_sink_sync(broadcast_sink, bis_index_bitfield, streams_p,
260-
&lc3_preset.codec, NULL);
264+
ret = bt_audio_broadcast_sink_sync(broadcast_sink, bis_index_bitfield, streams_p, NULL);
261265
if (ret) {
262266
LOG_ERR("Unable to sync to broadcast source");
263267
return;
@@ -273,13 +277,42 @@ static struct bt_audio_broadcast_sink_cb broadcast_sink_cbs = { .scan_recv = sca
273277
.base_recv = base_recv_cb,
274278
.syncable = syncable_cb };
275279

280+
static struct bt_audio_capability capabilities = {
281+
.dir = BT_AUDIO_DIR_SINK,
282+
.codec = &codec,
283+
};
284+
276285
static void initialize(le_audio_receive_cb recv_cb)
277286
{
287+
int ret;
278288
static bool initialized;
289+
enum audio_channel channel;
279290

280291
if (!initialized) {
281292
receive_cb = recv_cb;
282293

294+
ret = channel_assignment_get(&channel);
295+
if (ret) {
296+
/* Channel is not assigned yet: use default */
297+
channel = AUDIO_CHANNEL_DEFAULT;
298+
}
299+
if (channel == AUDIO_CH_L) {
300+
ret = bt_audio_capability_set_location(BT_AUDIO_DIR_SINK,
301+
BT_AUDIO_LOCATION_FRONT_LEFT);
302+
} else {
303+
ret = bt_audio_capability_set_location(BT_AUDIO_DIR_SINK,
304+
BT_AUDIO_LOCATION_FRONT_RIGHT);
305+
}
306+
if (ret) {
307+
LOG_ERR("Location set failed");
308+
}
309+
310+
ret = bt_audio_capability_register(&capabilities);
311+
if (ret) {
312+
LOG_ERR("Capability register failed (ret %d)", ret);
313+
ERR_CHK(ret);
314+
}
315+
283316
bt_audio_broadcast_sink_register_cb(&broadcast_sink_cbs);
284317

285318
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {

applications/nrf5340_audio/src/bluetooth/le_audio_cis_gateway.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ LOG_MODULE_REGISTER(cis_gateway, CONFIG_LOG_BLE_LEVEL);
2222
#define BT_AUDIO_LC3_UNICAST_PRESET_NRF5340_AUDIO \
2323
BT_AUDIO_LC3_PRESET( \
2424
BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
25-
BT_CODEC_CONFIG_LC3_DURATION_10, \
26-
LE_AUDIO_SDU_SIZE_OCTETS(CONFIG_LC3_BITRATE), \
25+
BT_CODEC_CONFIG_LC3_DURATION_10, BT_AUDIO_LOCATION_FRONT_LEFT, \
26+
LE_AUDIO_SDU_SIZE_OCTETS(CONFIG_LC3_BITRATE), 1, \
2727
BT_AUDIO_CONTEXT_TYPE_MEDIA), \
2828
BT_CODEC_LC3_QOS_10_UNFRAMED(LE_AUDIO_SDU_SIZE_OCTETS(CONFIG_LC3_BITRATE), 2u, \
2929
20u, LE_AUDIO_PRES_DELAY_US))
@@ -44,8 +44,12 @@ static struct bt_conn *headset_conn[CONFIG_BT_MAX_CONN];
4444
static struct bt_audio_stream audio_streams[CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SNK_COUNT];
4545
static struct bt_audio_unicast_group *unicast_group;
4646
static struct bt_codec *remote_codecs[CONFIG_BT_AUDIO_UNICAST_CLIENT_PAC_COUNT];
47-
static struct bt_audio_ep *sinks[CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SNK_COUNT];
4847
static struct bt_audio_discover_params audio_discover_param[CONFIG_BT_MAX_CONN];
48+
49+
static struct bt_audio_sink {
50+
struct bt_audio_ep *ep;
51+
uint32_t seq_num;
52+
} sinks[CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SNK_COUNT];
4953
/* clang-format off */
5054
static struct net_buf_pool *iso_tx_pools[] = { LISTIFY(CONFIG_BT_ISO_MAX_CHAN,
5155
NET_BUF_POOL_PTR_ITERATE, (,)) };
@@ -111,6 +115,19 @@ static int headset_conn_index_get(struct bt_conn *conn, uint8_t *index)
111115
return -EINVAL;
112116
}
113117

118+
static uint32_t get_and_incr_seq_num(const struct bt_audio_stream *stream)
119+
{
120+
for (size_t i = 0U; i < ARRAY_SIZE(sinks); i++) {
121+
if (stream->ep == sinks[i].ep) {
122+
return sinks[i].seq_num++;
123+
}
124+
}
125+
126+
LOG_WRN("Could not find endpoint from stream %p", stream);
127+
128+
return 0;
129+
}
130+
114131
static void unicast_client_location_cb(struct bt_conn *conn, enum bt_audio_dir dir,
115132
enum bt_audio_location loc)
116133
{
@@ -236,6 +253,14 @@ static void stream_started_cb(struct bt_audio_stream *stream)
236253
{
237254
int ret;
238255

256+
/* Reset sequence number for sinks */
257+
for (size_t i = 0U; i < ARRAY_SIZE(sinks); i++) {
258+
if (stream->ep == sinks[i].ep) {
259+
sinks[i].seq_num = 0U;
260+
break;
261+
}
262+
}
263+
239264
LOG_INF("Stream %p started", (void *)stream);
240265

241266
ret = ctrl_events_le_audio_event_send(LE_AUDIO_EVT_STREAMING);
@@ -295,7 +320,7 @@ static void add_remote_sink(struct bt_audio_ep *ep, uint8_t index)
295320
if (index > sizeof(sinks)) {
296321
LOG_ERR("Sink index is out of range");
297322
} else {
298-
sinks[index] = ep;
323+
sinks[index].ep = ep;
299324
}
300325
}
301326

@@ -358,7 +383,7 @@ static void discover_sink_cb(struct bt_conn *conn, struct bt_codec *codec, struc
358383
LOG_ERR("Could not do VCS discover");
359384
}
360385
#endif /* (CONFIG_BT_VCS_CLIENT) */
361-
ret = bt_audio_stream_config(conn, &audio_streams[conn_index], sinks[conn_index],
386+
ret = bt_audio_stream_config(conn, &audio_streams[conn_index], sinks[conn_index].ep,
362387
&lc3_preset_nrf5340.codec);
363388
if (ret) {
364389
LOG_ERR("Could not configure stream");
@@ -630,7 +655,9 @@ static int iso_stream_send(uint8_t const *const data, size_t size, uint8_t iso_c
630655

631656
atomic_inc(&iso_tx_pool_alloc[iso_chan_idx]);
632657

633-
ret = bt_audio_stream_send(&audio_streams[iso_chan_idx], buf);
658+
ret = bt_audio_stream_send(&audio_streams[iso_chan_idx], buf,
659+
get_and_incr_seq_num(&audio_streams[iso_chan_idx]),
660+
BT_ISO_TIMESTAMP_NONE);
634661
if (ret < 0) {
635662
LOG_WRN("Failed to send audio data: %d", ret);
636663
net_buf_unref(buf);

applications/nrf5340_audio/src/bluetooth/le_audio_cis_headset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,10 @@ static int initialize(le_audio_receive_cb recv_cb)
365365
}
366366
if (channel == AUDIO_CH_L) {
367367
ret = bt_audio_capability_set_location(BT_AUDIO_DIR_SINK,
368-
BT_AUDIO_LOCATION_SIDE_LEFT);
368+
BT_AUDIO_LOCATION_FRONT_LEFT);
369369
} else {
370370
ret = bt_audio_capability_set_location(BT_AUDIO_DIR_SINK,
371-
BT_AUDIO_LOCATION_SIDE_RIGHT);
371+
BT_AUDIO_LOCATION_FRONT_RIGHT);
372372
}
373373
if (ret) {
374374
LOG_ERR("Location set failed");

applications/nrf5340_audio/src/modules/button_handler.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ int button_handler_init(void)
198198
}
199199

200200
for (uint8_t i = 0; i < ARRAY_SIZE(btn_cfg); i++) {
201-
ret = gpio_pin_configure(gpio_53_dev, btn_cfg[i].btn_pin, btn_cfg[i].btn_cfg_mask);
201+
ret = gpio_pin_configure(gpio_53_dev, btn_cfg[i].btn_pin,
202+
GPIO_INPUT | btn_cfg[i].btn_cfg_mask);
202203
if (ret) {
203204
return ret;
204205
}

applications/nrf5340_audio/src/modules/led.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,7 @@ static int config_led_monochrome(uint8_t led_unit, uint8_t led)
105105
*/
106106
static int transfer_pin_to_net(uint8_t led)
107107
{
108-
uint8_t pin_to_transfer;
109-
110-
if (strcmp(leds[led].port->name, "GPIO_0") == 0) {
111-
pin_to_transfer = leds[led].pin;
112-
} else if (strcmp(leds[led].port->name, "GPIO_1") == 0) {
113-
pin_to_transfer = leds[led].pin + P0_PIN_NUM;
114-
} else {
115-
LOG_ERR("Invalid GPIO device");
116-
return -ENODEV;
117-
}
118-
119-
nrf_gpio_pin_mcu_select(pin_to_transfer, NRF_GPIO_PIN_MCUSEL_NETWORK);
108+
nrf_gpio_pin_control_select(leds[led].pin, NRF_GPIO_PIN_SEL_NETWORK);
120109
LOG_DBG("Pin %d transferred on device %s", leds[led].pin, leds[led].port->name);
121110
return 0;
122111
}

applications/nrf5340_audio/tools/buildprog/program.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _program_cores(dev: DeviceConf) -> int:
6464
dev.core_app_programmed = SelectFlags.FAIL
6565
return 1
6666

67-
if dev.core_net_programmed != SelectFlags.NOT and dev.core_app_programmed != SelectFlags.NOT:
67+
if dev.core_net_programmed != SelectFlags.NOT or dev.core_app_programmed != SelectFlags.NOT:
6868
print(f"Resetting {dev}")
6969
cmd = f"nrfjprog -r --snr {dev.nrf5340_audio_dk_snr}"
7070
ret_val = system(cmd)

0 commit comments

Comments
 (0)