Skip to content

Commit

Permalink
applications: nrf5340_audio: Split generic applications into separate…
Browse files Browse the repository at this point in the history
… mains

- Create samples folder containing:
  - broadcast_sink
  - broadcast_source
  - unicast_client
  - unicast_server
- Move relevant configs to respective folders
- Move common init functions into separate file

Signed-off-by: Alexander Svensen <[email protected]>
  • Loading branch information
alexsven authored and rlubos committed Jan 17, 2024
1 parent 5f79077 commit 56a9c81
Show file tree
Hide file tree
Showing 32 changed files with 510 additions and 381 deletions.
19 changes: 18 additions & 1 deletion applications/nrf5340_audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,27 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/utils/fw_info_app.c.in"

# Target sources below are specific to the nRF5340 Audio DK HW
target_sources(app PRIVATE
src/main.c
src/nrf5340_audio_common.c
${CMAKE_BINARY_DIR}/fw_info_app.c
)

if (CONFIG_BT_BAP_BROADCAST_SINK)
add_subdirectory(broadcast_sink)
endif()

if (CONFIG_BT_BAP_BROADCAST_SOURCE)
add_subdirectory(broadcast_source)
endif()

if (CONFIG_BT_BAP_UNICAST_CLIENT)
add_subdirectory(unicast_client)
endif()

if (CONFIG_BT_BAP_UNICAST_SERVER)
add_subdirectory(unicast_server)
endif()


# Include application events and configuration headers
zephyr_library_include_directories(
include
Expand Down
22 changes: 22 additions & 0 deletions applications/nrf5340_audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ config TRANSPORT_CIS
endchoice

#----------------------------------------------------------------------------#
if (TRANSPORT_BIS && AUDIO_DEV = 1)
rsource "broadcast_sink/Kconfig.defaults"
endif # TRANSPORT_BIS && AUDIO_DEV = 1

if (TRANSPORT_BIS && AUDIO_DEV = 2)
rsource "broadcast_source/Kconfig.defaults"
endif # TRANSPORT_BIS && AUDIO_DEV = 2

if (TRANSPORT_CIS && AUDIO_DEV = 1)
rsource "unicast_server/Kconfig.defaults"
endif # TRANSPORT_CIS && AUDIO_DEV = 1

if (TRANSPORT_CIS && AUDIO_DEV = 2)
rsource "unicast_client/Kconfig.defaults"
endif # TRANSPORT_CIS && AUDIO_DEV = 2



rsource "Kconfig.defaults"
rsource "src/audio/Kconfig"
rsource "src/bluetooth/Kconfig"
Expand All @@ -48,6 +66,10 @@ module = MAIN
module-str = main
source "subsys/logging/Kconfig.template.log_config"

module = NRF5340_AUDIO_COMMON
module-str = nrf5340_audio_common
source "subsys/logging/Kconfig.template.log_config"

config PRINT_STACK_USAGE_MS
depends on THREAD_ANALYZER && INIT_STACKS
int "Print stack usage every x milliseconds"
Expand Down
3 changes: 0 additions & 3 deletions applications/nrf5340_audio/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ config NRFX_I2S0
config PCM_MIX
default y

config TONE
default y

config PSCM
default y

Expand Down
8 changes: 8 additions & 0 deletions applications/nrf5340_audio/broadcast_sink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/main.c)
64 changes: 64 additions & 0 deletions applications/nrf5340_audio/broadcast_sink/Kconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

## ACL related configs ##
config BT_OBSERVER
default y

config BT_PERIPHERAL
default y

# Generic Audio Sink - 0x0840
config BT_DEVICE_APPEARANCE
default 2112

config BT_PER_ADV_SYNC_MAX
default 2

config BT_SMP
default y


## ISO related configs ##
config BT_ISO_SYNC_RECEIVER
default y

config BT_BAP_BROADCAST_SINK
default y

config BT_BAP_SCAN_DELEGATOR
default y

config BT_BAP_BROADCAST_SNK_STREAM_COUNT
default 2

config BT_BAP_BROADCAST_SNK_COUNT
default 2

config BT_ISO_MAX_CHAN
default 2

config BT_ISO_MAX_BIG
default 2

config BT_PAC_SNK
default y

config BT_AUDIO_RX
default y


## Audio related configs ##
config AUDIO_MUTE
default n

config AUDIO_TEST_TONE
default n


## LC3 related configs ##
config LC3_DEC_CHAN_MAX
default 1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zephyr/zbus/zbus.h>

#include "nrf5340_audio_common.h"
#include "nrf5340_audio_dk.h"
#include "broadcast_sink.h"
#include "led.h"
#include "button_assignments.h"
Expand All @@ -21,7 +22,7 @@
#include "le_audio_rx.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(streamctrl_broadcast_sink, CONFIG_STREAMCTRL_LOG_LEVEL);
LOG_MODULE_REGISTER(main, CONFIG_MAIN_LOG_LEVEL);

struct ble_iso_data {
uint8_t data[CONFIG_BT_ISO_RX_MTU];
Expand Down Expand Up @@ -436,18 +437,17 @@ void streamctrl_send(void const *const data, size_t size, uint8_t num_ch)
LOG_WRN("Sending is not possible for broadcast sink");
}

int streamctrl_start(void)
int main(void)
{
int ret;
static bool started;

if (started) {
LOG_WRN("Streamctrl already started");
return -EALREADY;
}
LOG_DBG("nRF5340 APP core started");

ret = nrf5340_audio_dk_init();
ERR_CHK(ret);

ret = audio_system_init();
ERR_CHK_MSG(ret, "Failed to initialize the audio system");
ret = nrf5340_audio_common_init();
ERR_CHK(ret);

ret = zbus_subscribers_create();
ERR_CHK_MSG(ret, "Failed to create zbus subscriber threads");
Expand All @@ -464,7 +464,5 @@ int streamctrl_start(void)
ret = bt_mgmt_scan_start(0, 0, BT_MGMT_SCAN_TYPE_BROADCAST, CONFIG_BT_AUDIO_BROADCAST_NAME);
ERR_CHK_MSG(ret, "Failed to start scanning");

started = true;

return 0;
}
8 changes: 8 additions & 0 deletions applications/nrf5340_audio/broadcast_source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/main.c)
39 changes: 39 additions & 0 deletions applications/nrf5340_audio/broadcast_source/Kconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

## ISO related configs ##
config BT_CAP_INITIATOR
default y

# Broadcasting Device - 0x0885
config BT_DEVICE_APPEARANCE
default 2181

config BT_ISO_BROADCASTER
default y

config BT_BAP_BROADCAST_SOURCE
default y

config BT_ISO_TX_BUF_COUNT
default 2

config BT_BAP_BROADCAST_SRC_STREAM_COUNT
default 2

config BT_ISO_MAX_CHAN
default 2

config BT_AUDIO_TX
default y


## LC3 related configs ##
config LC3_BITRATE
default BT_AUDIO_BITRATE_BROADCAST_SRC

config LC3_ENC_CHAN_MAX
default 2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zephyr/zbus/zbus.h>

#include "nrf5340_audio_common.h"
#include "nrf5340_audio_dk.h"
#include "broadcast_source.h"
#include "led.h"
#include "button_assignments.h"
Expand All @@ -18,7 +19,7 @@
#include "bt_mgmt.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(streamctrl_brcast_src, CONFIG_STREAMCTRL_LOG_LEVEL);
LOG_MODULE_REGISTER(main, CONFIG_MAIN_LOG_LEVEL);

ZBUS_SUBSCRIBER_DEFINE(button_evt_sub, CONFIG_BUTTON_MSG_SUB_QUEUE_SIZE);

Expand Down Expand Up @@ -306,24 +307,23 @@ void streamctrl_send(void const *const data, size_t size, uint8_t num_ch)
}
}

int streamctrl_start(void)
int main(void)
{
int ret;
static bool started;

if (started) {
LOG_WRN("Streamctrl already started");
return -EALREADY;
}
LOG_DBG("nRF5340 APP core started");

ret = nrf5340_audio_dk_init();
ERR_CHK(ret);

ret = nrf5340_audio_common_init();
ERR_CHK(ret);

size_t ext_adv_size = 0;
size_t per_adv_size = 0;
const struct bt_data *ext_adv = NULL;
const struct bt_data *per_adv = NULL;

ret = audio_system_init();
ERR_CHK_MSG(ret, "Failed to initialize the audio system");

ret = zbus_subscribers_create();
ERR_CHK_MSG(ret, "Failed to create zbus subscriber threads");

Expand All @@ -338,7 +338,5 @@ int streamctrl_start(void)
ret = bt_mgmt_adv_start(ext_adv, ext_adv_size, per_adv, per_adv_size, false);
ERR_CHK_MSG(ret, "Failed to start advertiser");

started = true;

return 0;
}
7 changes: 7 additions & 0 deletions applications/nrf5340_audio/include/nrf5340_audio_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ struct content_control_msg {
enum content_control_evt_type event;
};

/**
* @brief Initialize the software modules that are common for all the audio samples.
*
* @return 0 if successful, error otherwise.
*/
int nrf5340_audio_common_init(void);

#endif /* _NRF5340_AUDIO_COMMON_H_ */
20 changes: 0 additions & 20 deletions applications/nrf5340_audio/src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,3 @@ target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/sw_codec_select.c
${CMAKE_CURRENT_SOURCE_DIR}/le_audio_rx.c
)

if (CONFIG_BT_BAP_BROADCAST_SINK)
target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/streamctrl_broadcast_sink.c)
endif()

if (CONFIG_BT_BAP_BROADCAST_SOURCE)
target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/streamctrl_broadcast_source.c)
endif()

if (CONFIG_BT_BAP_UNICAST_CLIENT)
target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/streamctrl_unicast_client.c)
endif()

if (CONFIG_BT_BAP_UNICAST_SERVER)
target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/streamctrl_unicast_server.c)
endif()
1 change: 1 addition & 0 deletions applications/nrf5340_audio/src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ endchoice

config AUDIO_TEST_TONE
bool "Test tone instead of doing user defined action"
select TONE
default y
help
Use button 4 to set a test tone
Expand Down
Loading

0 comments on commit 56a9c81

Please sign in to comment.