Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1e62820

Browse files
committedFeb 20, 2025·
applications: nrf5340_audio: LED module for kits with other LED setup
The LED module is currently written in a way that’s highly dependent on all of the LEDs present on the audio DK, which prevents the application from running on the nRF5340 DK. The module must be refactored so that it can still show the state of the application with a different selection of LEDs. Signed-off-by: Graham Wacey <graham.wacey@nordicsemi.no>
1 parent 3e3b689 commit 1e62820

24 files changed

+393
-221
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <dt-bindings/led/led.h>
8+
9+
/ {
10+
audioleds: audioleds {
11+
compatible = "gpio-leds";
12+
status = "okay";
13+
14+
led_device_type: led_device_type {
15+
gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>,
16+
<&gpio0 25 GPIO_ACTIVE_HIGH>,
17+
<&gpio0 26 GPIO_ACTIVE_HIGH>;
18+
label = "RGB LED 0";
19+
};
20+
rgb2: rgb-2 {
21+
gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>,
22+
<&gpio0 29 GPIO_ACTIVE_HIGH>,
23+
<&gpio0 30 GPIO_ACTIVE_HIGH>;
24+
label = "RGB LED 1";
25+
};
26+
led_conn_status: led_conn_status {
27+
gpios = <&gpio0 31 GPIO_ACTIVE_HIGH>;
28+
label = "Blue LED 0";
29+
};
30+
led_sync_status: led_sync_status {
31+
gpios = <&gpio1 0 GPIO_ACTIVE_HIGH>;
32+
label = "Green LED 0";
33+
};
34+
led_app_status: led_app_status {
35+
gpios = <&gpio1 1 GPIO_ACTIVE_HIGH>;
36+
label = "Green LED 1";
37+
};
38+
};
39+
};

‎applications/nrf5340_audio/boards/nrf5340_audio_dk_nrf5340_cpuapp_fota.overlay

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "nrf5340_audio_dk_nrf5340_cpuapp.overlay"
2+
13
/ {
24
chosen {
35
nordic,pm-ext-flash = &mx25r64;
@@ -9,7 +11,9 @@
911
};
1012

1113
&spi4 {
12-
cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>, <&gpio0 11 GPIO_ACTIVE_LOW>, <&gpio0 17 GPIO_ACTIVE_LOW>;
14+
cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>,
15+
<&gpio0 11 GPIO_ACTIVE_LOW>,
16+
<&gpio0 17 GPIO_ACTIVE_LOW>;
1317
status = "okay";
1418
mx25r64: mx25r6435f@0 {
1519

@@ -34,6 +38,6 @@
3438

3539
&gpio_fwd {
3640
uart {
37-
gpios = < &gpio1 0x9 0x0 >, < &gpio1 0x8 0x0 >, < &gpio1 0xb 0x0 >;
41+
gpios = <&gpio1 0x9 0x0>, <&gpio1 0x8 0x0>, <&gpio1 0xb 0x0>;
3842
};
3943
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
CONFIG_NRF5340_AUDIO_CS47L63_DRIVER=n
8+
CONFIG_NRF5340_AUDIO_POWER_MEASUREMENT=n
9+
CONFIG_NRF5340_AUDIO_SD_CARD_MODULE=n

‎applications/nrf5340_audio/boards/nrf5340dk_nrf5340_cpuapp.overlay

+35
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,38 @@
1616
hp-channel-r;
1717
};
1818
};
19+
20+
&pinctrl {
21+
i2s0_default: i2s0_default {
22+
group1 {
23+
psels = <NRF_PSEL(I2S_MCK, 0, 12)>;
24+
nordic,drive-mode = <NRF_DRIVE_H0H1>;
25+
};
26+
group2 {
27+
28+
psels = <NRF_PSEL(I2S_SCK_M, 0, 14)>,
29+
<NRF_PSEL(I2S_LRCK_M, 0, 16)>,
30+
<NRF_PSEL(I2S_SDOUT, 0, 13)>,
31+
<NRF_PSEL(I2S_SDIN, 0, 15)>;
32+
};
33+
};
34+
35+
i2s0_sleep: i2s0_sleep {
36+
group1 {
37+
psels = <NRF_PSEL(I2S_MCK, 0, 12)>,
38+
<NRF_PSEL(I2S_SCK_M, 0, 14)>,
39+
<NRF_PSEL(I2S_LRCK_M, 0, 16)>,
40+
<NRF_PSEL(I2S_SDOUT, 0, 13)>,
41+
<NRF_PSEL(I2S_SDIN, 0, 15)>;
42+
low-power-enable;
43+
};
44+
};
45+
};
46+
47+
&i2s0 {
48+
compatible = "nordic,nrf-i2s";
49+
status = "okay";
50+
pinctrl-0 = <&i2s0_default>;
51+
pinctrl-1 = <&i2s0_sleep>;
52+
pinctrl-names = "default", "sleep";
53+
};

‎applications/nrf5340_audio/broadcast_sink/main.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
#include "broadcast_sink.h"
1313
#include "zbus_common.h"
14-
#include "nrf5340_audio_dk.h"
14+
#include "board_init.h"
15+
#include "led_assignments.h"
1516
#include "led.h"
1617
#include "button_assignments.h"
1718
#include "macros_common.h"
@@ -208,7 +209,7 @@ static void le_audio_msg_sub_thread(void)
208209

209210
audio_system_start();
210211
stream_state_set(STATE_STREAMING);
211-
ret = led_blink(LED_APP_1_BLUE);
212+
ret = led_blink(LED_AUDIO_CONN_STATUS);
212213
ERR_CHK(ret);
213214

214215
break;
@@ -223,7 +224,7 @@ static void le_audio_msg_sub_thread(void)
223224

224225
stream_state_set(STATE_PAUSED);
225226
audio_system_stop();
226-
ret = led_on(LED_APP_1_BLUE);
227+
ret = led_on(LED_AUDIO_CONN_STATUS);
227228
ERR_CHK(ret);
228229

229230
break;
@@ -265,7 +266,7 @@ static void le_audio_msg_sub_thread(void)
265266
if (strm_state == STATE_STREAMING) {
266267
stream_state_set(STATE_PAUSED);
267268
audio_system_stop();
268-
ret = led_on(LED_APP_1_BLUE);
269+
ret = led_on(LED_AUDIO_CONN_STATUS);
269270
ERR_CHK(ret);
270271
}
271272

@@ -566,7 +567,7 @@ int main(void)
566567

567568
LOG_DBG("Main started");
568569

569-
ret = nrf5340_audio_dk_init();
570+
ret = board_init();
570571
ERR_CHK(ret);
571572

572573
ret = fw_info_app_print();

‎applications/nrf5340_audio/broadcast_source/main.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
#include "broadcast_source.h"
1515
#include "zbus_common.h"
16-
#include "nrf5340_audio_dk.h"
16+
#include "board_init.h"
17+
#include "led_assignments.h"
1718
#include "led.h"
1819
#include "button_assignments.h"
1920
#include "macros_common.h"
@@ -206,7 +207,7 @@ static void le_audio_msg_sub_thread(void)
206207

207208
audio_system_start();
208209
stream_state_set(STATE_STREAMING);
209-
ret = led_blink(LED_APP_1_BLUE);
210+
ret = led_blink(LED_AUDIO_CONN_STATUS);
210211
ERR_CHK(ret);
211212

212213
break;
@@ -223,7 +224,7 @@ static void le_audio_msg_sub_thread(void)
223224

224225
stream_state_set(STATE_PAUSED);
225226
audio_system_stop();
226-
ret = led_on(LED_APP_1_BLUE);
227+
ret = led_on(LED_AUDIO_CONN_STATUS);
227228
ERR_CHK(ret);
228229

229230
break;
@@ -558,7 +559,7 @@ int main(void)
558559
size_t ext_adv_buf_cnt = 0;
559560
size_t per_adv_buf_cnt = 0;
560561

561-
ret = nrf5340_audio_dk_init();
562+
ret = board_init();
562563
ERR_CHK(ret);
563564

564565
ret = fw_info_app_print();

‎applications/nrf5340_audio/sample.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ sample:
44
common:
55
integration_platforms:
66
- nrf5340_audio_dk/nrf5340/cpuapp
7-
platform_allow: nrf5340_audio_dk/nrf5340/cpuapp
7+
- nrf5340dk/nrf5340/cpuapp
8+
platform_allow:
9+
- nrf5340_audio_dk/nrf5340/cpuapp
10+
- nrf5340dk/nrf5340/cpuapp
811
sysbuild: true
912
build_only: true
1013
tags:

‎applications/nrf5340_audio/src/audio/audio_datapath.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "zbus_common.h"
2121
#include "macros_common.h"
22+
#include "led_assignments.h"
2223
#include "led.h"
2324
#include "audio_i2s.h"
2425
#include "sw_codec_select.h"
@@ -354,9 +355,9 @@ static void pres_comp_state_set(enum pres_comp_state new_state)
354355
/* NOTE: The string below is used by the Nordic CI system */
355356
LOG_INF("Pres comp state: %s", pres_comp_state_names[new_state]);
356357
if (new_state == PRES_STATE_LOCKED) {
357-
ret = led_on(LED_APP_2_GREEN);
358+
ret = led_on(LED_AUDIO_SYNC_STATUS);
358359
} else {
359-
ret = led_off(LED_APP_2_GREEN);
360+
ret = led_off(LED_AUDIO_SYNC_STATUS);
360361
}
361362
ERR_CHK(ret);
362363
}

‎applications/nrf5340_audio/src/audio/audio_system.c

+15-8
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,10 @@ void audio_system_start(void)
408408
ret = audio_usb_start(&fifo_tx, &fifo_rx);
409409
ERR_CHK(ret);
410410
#else
411-
ret = hw_codec_default_conf_enable();
412-
ERR_CHK(ret);
411+
if (IS_ENABLED(CONFIG_BOARD_NRF5340_AUDIO_DK_NRF5340_CPUAPP)) {
412+
ret = hw_codec_default_conf_enable();
413+
ERR_CHK(ret);
414+
}
413415

414416
ret = audio_datapath_start(&fifo_rx);
415417
ERR_CHK(ret);
@@ -430,8 +432,10 @@ void audio_system_stop(void)
430432
#if ((CONFIG_AUDIO_DEV == GATEWAY) && CONFIG_AUDIO_SOURCE_USB)
431433
audio_usb_stop();
432434
#else
433-
ret = hw_codec_soft_reset();
434-
ERR_CHK(ret);
435+
if (IS_ENABLED(CONFIG_BOARD_NRF5340_AUDIO_DK_NRF5340_CPUAPP)) {
436+
ret = hw_codec_soft_reset();
437+
ERR_CHK(ret);
438+
}
435439

436440
ret = audio_datapath_stop();
437441
ERR_CHK(ret);
@@ -485,12 +489,15 @@ int audio_system_init(void)
485489
return ret;
486490
}
487491

488-
ret = hw_codec_init();
489-
if (ret) {
490-
LOG_ERR("Failed to initialize HW codec: %d", ret);
491-
return ret;
492+
if (IS_ENABLED(CONFIG_BOARD_NRF5340_AUDIO_DK_NRF5340_CPUAPP)) {
493+
ret = hw_codec_init();
494+
if (ret) {
495+
LOG_ERR("Failed to initialize HW codec: %d", ret);
496+
return ret;
497+
}
492498
}
493499
#endif
500+
494501
k_poll_signal_init(&encoder_sig);
495502

496503
return 0;

‎applications/nrf5340_audio/src/bluetooth/bt_management/bt_mgmt.c

-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
#include "bt_mgmt_ctlr_cfg_internal.h"
2121
#include "bt_mgmt_adv_internal.h"
2222
#include "bt_mgmt_dfu_internal.h"
23-
#if CONFIG_BOARD_NRF5340_AUDIO_DK_NRF5340_CPUAPP
2423
#include "button_assignments.h"
25-
#endif
2624

2725
#include <zephyr/logging/log.h>
2826
LOG_MODULE_REGISTER(bt_mgmt, CONFIG_BT_MGMT_LOG_LEVEL);
@@ -213,7 +211,6 @@ static void bt_enabled_cb(int err)
213211

214212
static int bonding_clear_check(void)
215213
{
216-
#if CONFIG_BOARD_NRF5340_AUDIO_DK_NRF5340_CPUAPP
217214
int ret;
218215
bool pressed;
219216

@@ -227,7 +224,6 @@ static int bonding_clear_check(void)
227224
return ret;
228225
}
229226

230-
#endif
231227
return 0;
232228
}
233229

‎applications/nrf5340_audio/src/modules/button_assignments.h

+7
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616

1717
#include <zephyr/drivers/gpio.h>
1818

19+
#define BUTTON_NOT_ASSIGNED 0xFF
20+
1921
/** @brief List of buttons and associated metadata
2022
*/
2123
enum button_pin_names {
2224
BUTTON_VOLUME_DOWN = DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
2325
BUTTON_VOLUME_UP = DT_GPIO_PIN(DT_ALIAS(sw1), gpios),
2426
BUTTON_PLAY_PAUSE = DT_GPIO_PIN(DT_ALIAS(sw2), gpios),
27+
#if defined(CONFIG_BOARD_NRF5340_AUDIO_DK_NRF5340_CPUAPP)
2528
BUTTON_4 = DT_GPIO_PIN(DT_ALIAS(sw3), gpios),
2629
BUTTON_5 = DT_GPIO_PIN(DT_ALIAS(sw4), gpios),
30+
#else
31+
BUTTON_5 = DT_GPIO_PIN(DT_ALIAS(sw3), gpios),
32+
BUTTON_4 = BUTTON_NOT_ASSIGNED,
33+
#endif /* CONFIG_BOARD_NRF5340_AUDIO_DK_NRF5340_CPUAPP */
2734
};
2835

2936
#endif /* _BUTTON_ASSIGNMENTS_H_ */

‎applications/nrf5340_audio/src/modules/button_handler.c

+16
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const static struct btn_config btn_cfg[] = {
5252
.btn_pin = BUTTON_PLAY_PAUSE,
5353
.btn_cfg_mask = DT_GPIO_FLAGS(DT_ALIAS(sw2), gpios),
5454
},
55+
#if defined(CONFIG_BOARD_NRF5340_AUDIO_DK_NRF5340_CPUAPP)
5556
{
5657
.btn_name = STRINGIFY(BUTTON_4),
5758
.btn_pin = BUTTON_4,
@@ -62,6 +63,17 @@ const static struct btn_config btn_cfg[] = {
6263
.btn_pin = BUTTON_5,
6364
.btn_cfg_mask = DT_GPIO_FLAGS(DT_ALIAS(sw4), gpios),
6465
}
66+
#else
67+
{
68+
.btn_name = STRINGIFY(BUTTON_4),
69+
.btn_pin = BUTTON_4,
70+
},
71+
{
72+
.btn_name = STRINGIFY(BUTTON_5),
73+
.btn_pin = BUTTON_5,
74+
.btn_cfg_mask = DT_GPIO_FLAGS(DT_ALIAS(sw3), gpios),
75+
}
76+
#endif /* CONFIG_BOARD_NRF5340_AUDIO_DK_NRF5340_CPUAPP */
6577
};
6678
/* clang-format on */
6779

@@ -220,6 +232,10 @@ int button_handler_init(void)
220232
}
221233

222234
for (uint8_t i = 0; i < ARRAY_SIZE(btn_cfg); i++) {
235+
if (btn_cfg[i].btn_pin == BUTTON_NOT_ASSIGNED) {
236+
continue;
237+
}
238+
223239
ret = gpio_pin_configure(gpio_53_dev, btn_cfg[i].btn_pin,
224240
GPIO_INPUT | btn_cfg[i].btn_cfg_mask);
225241
if (ret) {

0 commit comments

Comments
 (0)
Please sign in to comment.