Skip to content

Commit 279e4a0

Browse files
alexsvenrlubos
authored andcommitted
applications: nrf5340_audio: Store channel_assignment in RAM
- Move channel assignment to RAM to be able to change on boot - Hold button VOL+ for right device - Hold button VOL- for left device Signed-off-by: Alexander Svensen <[email protected]>
1 parent 1e63104 commit 279e4a0

File tree

8 files changed

+69
-93
lines changed

8 files changed

+69
-93
lines changed

applications/nrf5340_audio/src/bluetooth/le_audio_bis_headset.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,8 @@ static void base_recv_cb(struct bt_audio_broadcast_sink *sink, const struct bt_a
220220
return;
221221
}
222222

223-
ret = channel_assignment_get(&channel);
224-
if (ret) {
225-
/* Channel is not assigned yet: use default */
226-
channel = AUDIO_CHANNEL_DEFAULT;
227-
}
223+
channel_assignment_get(&channel);
224+
228225
channel = BIT(channel);
229226

230227
LOG_DBG("Received BASE with %d subgroup(s) from broadcast sink", base->subgroup_count);
@@ -308,11 +305,8 @@ static void initialize(le_audio_receive_cb recv_cb)
308305
if (!initialized) {
309306
receive_cb = recv_cb;
310307

311-
ret = channel_assignment_get(&channel);
312-
if (ret) {
313-
/* Channel is not assigned yet: use default */
314-
channel = AUDIO_CHANNEL_DEFAULT;
315-
}
308+
channel_assignment_get(&channel);
309+
316310
if (channel == AUDIO_CH_L) {
317311
ret = bt_audio_capability_set_location(BT_AUDIO_DIR_SINK,
318312
BT_AUDIO_LOCATION_FRONT_LEFT);

applications/nrf5340_audio/src/bluetooth/le_audio_cis_headset.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,7 @@ static int initialize(le_audio_receive_cb recv_cb)
423423
#endif /* (CONFIG_BT_VCS) */
424424

425425
receive_cb = recv_cb;
426-
ret = channel_assignment_get(&channel);
427-
if (ret) {
428-
/* Channel is not assigned yet: use default */
429-
channel = AUDIO_CHANNEL_DEFAULT;
430-
}
426+
channel_assignment_get(&channel);
431427

432428
for (int i = 0; i < ARRAY_SIZE(caps); i++) {
433429
ret = bt_audio_capability_register(&caps[i]);

applications/nrf5340_audio/src/main.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ static int leds_set(void)
7373
#if (CONFIG_AUDIO_DEV == HEADSET)
7474
enum audio_channel channel;
7575

76-
ret = channel_assignment_get(&channel);
77-
if (ret) {
78-
/* Channel is not assigned yet: use default */
79-
channel = AUDIO_CHANNEL_DEFAULT;
80-
}
76+
channel_assignment_get(&channel);
8177

8278
if (channel == AUDIO_CH_L) {
8379
ret = led_on(LED_APP_RGB, LED_COLOR_BLUE);
@@ -120,11 +116,6 @@ static int bonding_clear_check(void)
120116
static int channel_assign_check(void)
121117
{
122118
#if (CONFIG_AUDIO_DEV == HEADSET) && CONFIG_AUDIO_HEADSET_CHANNEL_RUNTIME
123-
if (!channel_assignment_get(&(enum audio_channel){ AUDIO_CH_L })) {
124-
/* Channel already assigned */
125-
return 0;
126-
}
127-
128119
int ret;
129120
bool pressed;
130121

@@ -134,7 +125,8 @@ static int channel_assign_check(void)
134125
}
135126

136127
if (pressed) {
137-
return channel_assignment_set(AUDIO_CH_L);
128+
channel_assignment_set(AUDIO_CH_L);
129+
return 0;
138130
}
139131

140132
ret = button_pressed(BUTTON_VOLUME_UP, &pressed);
@@ -143,7 +135,8 @@ static int channel_assign_check(void)
143135
}
144136

145137
if (pressed) {
146-
return channel_assignment_set(AUDIO_CH_R);
138+
channel_assignment_set(AUDIO_CH_R);
139+
return 0;
147140
}
148141
#endif
149142

@@ -180,6 +173,8 @@ void main(void)
180173
ret = button_handler_init();
181174
ERR_CHK(ret);
182175

176+
channel_assignment_init();
177+
183178
ret = channel_assign_check();
184179
ERR_CHK(ret);
185180

applications/nrf5340_audio/src/modules/dfu_entry.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,26 @@ LOG_MODULE_REGISTER(dfu, CONFIG_LOG_DFU_ENTRY_LEVEL);
4242
static struct bt_le_adv_param adv_param;
4343
static const struct bt_data ad_peer[] = {
4444
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
45-
BT_DATA_BYTES(BT_DATA_UUID128_ALL,
46-
0x84, 0xaa, 0x60, 0x74, 0x52, 0x8a, 0x8b, 0x86,
47-
0xd3, 0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d),
45+
BT_DATA_BYTES(BT_DATA_UUID128_ALL, 0x84, 0xaa, 0x60, 0x74, 0x52, 0x8a, 0x8b, 0x86, 0xd3,
46+
0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d),
4847
};
4948

5049
/* MCUMGR related functions */
5150
static void mcumgr_register(void)
5251
{
53-
/* Enable MCUMGR */
54-
#ifdef CONFIG_MCUMGR_CMD_OS_MGMT
55-
os_mgmt_register_group();
56-
#endif
57-
#ifdef CONFIG_MCUMGR_CMD_IMG_MGMT
58-
img_mgmt_register_group();
59-
#endif
60-
#ifdef CONFIG_MCUMGR_CMD_STAT_MGMT
61-
stat_mgmt_register_group();
62-
#endif
63-
#ifdef CONFIG_MCUMGR_SMP_BT
64-
smp_bt_register();
65-
#endif
52+
/* Enable MCUMGR */
53+
#ifdef CONFIG_MCUMGR_CMD_OS_MGMT
54+
os_mgmt_register_group();
55+
#endif
56+
#ifdef CONFIG_MCUMGR_CMD_IMG_MGMT
57+
img_mgmt_register_group();
58+
#endif
59+
#ifdef CONFIG_MCUMGR_CMD_STAT_MGMT
60+
stat_mgmt_register_group();
61+
#endif
62+
#ifdef CONFIG_MCUMGR_SMP_BT
63+
smp_bt_register();
64+
#endif
6665
}
6766

6867
static void smp_adv(void)
@@ -96,7 +95,7 @@ static struct bt_conn_cb dfu_conn_callbacks = {
9695

9796
static void dfu_set_bt_name(void)
9897
{
99-
char name[CONFIG_BT_DEVICE_NAME_MAX] = {0};
98+
char name[CONFIG_BT_DEVICE_NAME_MAX] = { 0 };
10099

101100
strlcpy(name, CONFIG_BT_DEVICE_NAME, CONFIG_BT_DEVICE_NAME_MAX);
102101
strlcat(name, "_", CONFIG_BT_DEVICE_NAME_MAX);
@@ -106,11 +105,7 @@ static void dfu_set_bt_name(void)
106105
int ret;
107106
enum audio_channel channel;
108107

109-
ret = channel_assignment_get(&channel);
110-
if (ret) {
111-
/* Channel is not assigned yet: use default */
112-
channel = AUDIO_CHANNEL_DEFAULT;
113-
}
108+
channel_assignment_get(&channel);
114109

115110
if (channel == AUDIO_CH_L) {
116111
strlcat(name, CH_L_TAG, CONFIG_BT_DEVICE_NAME_MAX);

applications/nrf5340_audio/src/utils/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,9 @@ config LOG_CS47L63_LEVEL
4848
int "Log level for CS47L63"
4949
default 2
5050

51+
config LOG_CHANNEL_ASSIGNMENT_LEVEL
52+
int "Log level for channel assignment"
53+
default 3
54+
5155
endmenu # Log levels
5256
endmenu # Utils

applications/nrf5340_audio/src/utils/channel_assignment.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,41 @@
1010

1111
#include "uicr.h"
1212

13-
int channel_assignment_get(enum audio_channel *channel)
14-
{
15-
#if CONFIG_AUDIO_HEADSET_CHANNEL_RUNTIME
16-
uint8_t channel_value;
13+
#include <zephyr/logging/log.h>
14+
LOG_MODULE_REGISTER(channel_assignment, CONFIG_LOG_CHANNEL_ASSIGNMENT_LEVEL);
1715

18-
channel_value = uicr_channel_get();
19-
20-
if (channel_value >= AUDIO_CH_NUM) {
21-
return -EIO;
22-
}
16+
static uint8_t channel_value;
2317

18+
void channel_assignment_get(enum audio_channel *channel)
19+
{
2420
*channel = (enum audio_channel)channel_value;
25-
#else
26-
*channel = (enum audio_channel)CONFIG_AUDIO_HEADSET_CHANNEL;
27-
#endif /* CONFIG_AUDIO_HEADSET_CHANNEL_RUNTIME */
28-
29-
return 0;
3021
}
3122

3223
#if CONFIG_AUDIO_HEADSET_CHANNEL_RUNTIME
33-
/**
34-
* @brief Assign audio channel.
35-
*
36-
* @param[out] channel Channel value
37-
*
38-
* @return 0 if successful
39-
* @return -EROFS if different channel is already written
40-
* @return -EIO if channel is not assigned.
41-
*/
42-
int channel_assignment_set(enum audio_channel channel)
24+
void channel_assignment_set(enum audio_channel channel)
4325
{
44-
return uicr_channel_set(channel);
26+
int ret;
27+
28+
channel_value = channel;
29+
30+
/* Try to write the channel value to UICR */
31+
ret = uicr_channel_set(channel);
32+
if (ret) {
33+
LOG_DBG("Unable to write channel value to UICR");
34+
}
4535
}
36+
#endif /* CONFIG_AUDIO_HEADSET_CHANNEL_RUNTIME */
37+
38+
void channel_assignment_init(void)
39+
{
40+
#if CONFIG_AUDIO_HEADSET_CHANNEL_RUNTIME
41+
channel_value = uicr_channel_get();
4642

43+
if (channel_value >= AUDIO_CH_NUM) {
44+
/* Invalid value in UICR if UICR is not written */
45+
channel_value = AUDIO_CHANNEL_DEFAULT;
46+
}
47+
#else
48+
channel_value = CONFIG_AUDIO_HEADSET_CHANNEL;
4749
#endif /* CONFIG_AUDIO_HEADSET_CHANNEL_RUNTIME */
50+
}

applications/nrf5340_audio/src/utils/channel_assignment.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,21 @@ enum audio_channel {
3333
* @brief Get assigned audio channel.
3434
*
3535
* @param[out] channel Channel value
36-
*
37-
* @return 0 if successful
38-
* @return -EIO if channel is not assigned.
3936
*/
40-
int channel_assignment_get(enum audio_channel *channel);
37+
void channel_assignment_get(enum audio_channel *channel);
4138

4239
#if CONFIG_AUDIO_HEADSET_CHANNEL_RUNTIME
4340
/**
4441
* @brief Assign audio channel.
4542
*
4643
* @param[out] channel Channel value
47-
*
48-
* @return 0 if successful
49-
* @return -EROFS if different channel is already written
50-
* @return -EIO if channel is not assigned.
5144
*/
52-
int channel_assignment_set(enum audio_channel channel);
45+
void channel_assignment_set(enum audio_channel channel);
5346
#endif /* AUDIO_HEADSET_CHANNEL_RUNTIME */
5447

48+
/**
49+
* @brief Initialize the channel assignment
50+
*/
51+
void channel_assignment_init(void);
52+
5553
#endif /* _CHANNEL_ASSIGNMENT_H_ */

applications/nrf5340_audio/src/utils/fw_info_app.c.in

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,7 @@ int fw_info_app_print(void)
3535
#if (CONFIG_AUDIO_DEV == HEADSET)
3636
enum audio_channel channel;
3737

38-
ret = channel_assignment_get(&channel);
39-
if (ret) {
40-
channel = AUDIO_CHANNEL_DEFAULT;
41-
ret = log_set_tag(CH_L_TAG);
42-
if (ret) {
43-
return ret;
44-
}
45-
LOG_INF(COLOR_CYAN "HEADSET <no ch selected> defaulting to " STRINGIFY(
46-
AUDIO_CHANNEL_DEFAULT) " " COLOR_RESET);
47-
}
38+
channel_assignment_get(&channel);
4839
if (channel == AUDIO_CH_L) {
4940
ret = log_set_tag(CH_L_TAG);
5041
if (ret) {

0 commit comments

Comments
 (0)