Skip to content

Commit

Permalink
Applications: nrf5340_audio: Structure cleanup
Browse files Browse the repository at this point in the history
OCT-2705
Removed dependencies and cleaned up includes
Made a ZBUS only header.

Signed-off-by: Kristoffer Rist Skøien <[email protected]>
  • Loading branch information
koffes committed May 31, 2024
1 parent 270997c commit 8fc5a5f
Show file tree
Hide file tree
Showing 45 changed files with 111 additions and 139 deletions.
1 change: 0 additions & 1 deletion applications/nrf5340_audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ 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/nrf5340_audio_common.c
${CMAKE_BINARY_DIR}/fw_info_app.c
)

Expand Down
4 changes: 0 additions & 4 deletions applications/nrf5340_audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ 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
15 changes: 11 additions & 4 deletions applications/nrf5340_audio/broadcast_sink/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <zephyr/kernel.h>
#include <zephyr/zbus/zbus.h>

#include "nrf5340_audio_common.h"
#include "nrf5340_audio_dk.h"
#include "broadcast_sink.h"
#include "zbus_common.h"
#include "nrf5340_audio_dk.h"
#include "led.h"
#include "button_assignments.h"
#include "macros_common.h"
Expand All @@ -20,6 +20,7 @@
#include "bt_rendering_and_capture.h"
#include "audio_datapath.h"
#include "le_audio_rx.h"
#include "fw_info_app.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main, CONFIG_MAIN_LOG_LEVEL);
Expand Down Expand Up @@ -449,12 +450,18 @@ int main(void)
{
int ret;

LOG_DBG("nRF5340 APP core started");
LOG_DBG("Main started");

ret = nrf5340_audio_dk_init();
ERR_CHK(ret);

ret = nrf5340_audio_common_init();
ret = fw_info_app_print();
ERR_CHK(ret);

ret = bt_mgmt_init();
ERR_CHK(ret);

ret = audio_system_init();
ERR_CHK(ret);

ret = zbus_subscribers_create();
Expand Down
15 changes: 11 additions & 4 deletions applications/nrf5340_audio/broadcast_source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
#include <zephyr/kernel.h>
#include <zephyr/zbus/zbus.h>

#include "nrf5340_audio_common.h"
#include "nrf5340_audio_dk.h"
#include "broadcast_source.h"
#include "zbus_common.h"
#include "nrf5340_audio_dk.h"
#include "led.h"
#include "button_assignments.h"
#include "macros_common.h"
#include "audio_system.h"
#include "bt_mgmt.h"
#include "fw_info_app.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main, CONFIG_MAIN_LOG_LEVEL);
Expand Down Expand Up @@ -318,12 +319,18 @@ int main(void)
static const struct bt_data *ext_adv;
static const struct bt_data *per_adv;

LOG_DBG("nRF5340 APP core started");
LOG_DBG("Main started");

ret = nrf5340_audio_dk_init();
ERR_CHK(ret);

ret = nrf5340_audio_common_init();
ret = fw_info_app_print();
ERR_CHK(ret);

ret = bt_mgmt_init();
ERR_CHK(ret);

ret = audio_system_init();
ERR_CHK(ret);

size_t ext_adv_size = 0;
Expand Down
2 changes: 1 addition & 1 deletion applications/nrf5340_audio/doc/firmware_architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Since the application architecture is the same for all applications and the code
Communication between modules
=============================

Communication between modules is primarily done through Zephyr's :ref:`zephyr:zbus` to make sure that there are as few dependencies as possible. Each of the buses used by the applications has their message structures described in :file:`nrf5340_audio_common.h`.
Communication between modules is primarily done through Zephyr's :ref:`zephyr:zbus` to make sure that there are as few dependencies as possible. Each of the buses used by the applications has their message structures described in :file:`zbus_common.h`.

.. _nrf53_audio_app_overview_architecture_usb:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef _NRF5340_AUDIO_COMMON_H_
#define _NRF5340_AUDIO_COMMON_H_
#ifndef _ZBUS_COMMON_H_
#define _ZBUS_COMMON_H_

#include <zephyr/bluetooth/audio/audio.h>

Expand Down Expand Up @@ -89,11 +89,4 @@ 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_ */
#endif /* _ZBUS_COMMON_H_ */
8 changes: 4 additions & 4 deletions applications/nrf5340_audio/src/audio/audio_datapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
#include <zephyr/kernel.h>
#include <zephyr/shell/shell.h>
#include <nrfx_clock.h>
#include <contin_array.h>
#include <tone.h>
#include <pcm_mix.h>

#include "nrf5340_audio_common.h"
#include "zbus_common.h"
#include "macros_common.h"
#include "led.h"
#include "audio_i2s.h"
#include "sw_codec_select.h"
#include "audio_system.h"
#include "tone.h"
#include "contin_array.h"
#include "pcm_mix.h"
#include "streamctrl.h"
#include "sd_card_playback.h"

Expand Down
2 changes: 1 addition & 1 deletion applications/nrf5340_audio/src/audio/audio_datapath.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <zephyr/kernel.h>
#include <stdint.h>
#include <stdbool.h>
#include <data_fifo.h>

#include "data_fifo.h"
#include "sw_codec_select.h"

/**
Expand Down
8 changes: 4 additions & 4 deletions applications/nrf5340_audio/src/audio/audio_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

#include <zephyr/kernel.h>
#include <zephyr/shell/shell.h>
#include <data_fifo.h>
#include <contin_array.h>
#include <pcm_stream_channel_modifier.h>
#include <tone.h>

#include "macros_common.h"
#include "sw_codec_select.h"
#include "audio_datapath.h"
#include "audio_i2s.h"
#include "data_fifo.h"
#include "hw_codec.h"
#include "tone.h"
#include "contin_array.h"
#include "pcm_stream_channel_modifier.h"
#include "audio_usb.h"
#include "streamctrl.h"

Expand Down
5 changes: 2 additions & 3 deletions applications/nrf5340_audio/src/audio/sw_codec_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

#include <zephyr/kernel.h>
#include <errno.h>
#include <pcm_stream_channel_modifier.h>
#include <sample_rate_converter.h>

#include "channel_assignment.h"
#include "pcm_stream_channel_modifier.h"
#include "sample_rate_converter.h"
#if (CONFIG_SW_CODEC_LC3)
#include "sw_codec_lc3.h"
#endif /* (CONFIG_SW_CODEC_LC3) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <zephyr/bluetooth/uuid.h>

#include "bt_content_ctrl_media_internal.h"
#include "nrf5340_audio_common.h"
#include "zbus_common.h"
#include "macros_common.h"

#include <zephyr/logging/log.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <zephyr/bluetooth/conn.h>

#include "macros_common.h"
#include "nrf5340_audio_common.h"
#include "zbus_common.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_mgmt_adv, CONFIG_BT_MGMT_ADV_LOG_LEVEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <zephyr/sys/byteorder.h>

#include "macros_common.h"
#include "nrf5340_audio_common.h"
#include "zbus_common.h"
#include "button_handler.h"
#include "button_assignments.h"
#include "bt_mgmt_ctlr_cfg_internal.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "bt_mgmt.h"
#include "macros_common.h"
#include "nrf5340_audio_common.h"
#include "zbus_common.h"

#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(bt_mgmt_scan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "bt_vol_rend_internal.h"
#include "bt_vol_ctlr_internal.h"
#include "nrf5340_audio_common.h"
#include "zbus_common.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_r_c, CONFIG_BT_RENDERING_AND_CAPTURE_LOG_LEVEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <../subsys/bluetooth/audio/bap_endpoint.h>

#include "macros_common.h"
#include "nrf5340_audio_common.h"
#include "zbus_common.h"
#include "channel_assignment.h"

#include <zephyr/logging/log.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "macros_common.h"
#include "bt_le_audio_tx.h"
#include "le_audio.h"
#include "nrf5340_audio_common.h"
#include "zbus_common.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(broadcast_source, CONFIG_BROADCAST_SOURCE_LOG_LEVEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <zephyr/zbus/zbus.h>
#include <../subsys/bluetooth/audio/bap_stream.h>

#include "nrf5340_audio_common.h"
#include "zbus_common.h"
#include "audio_sync_timer.h"
#include "sdc_hci_vs.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <../subsys/bluetooth/audio/bap_endpoint.h>

#include "macros_common.h"
#include "nrf5340_audio_common.h"
#include "zbus_common.h"
#include "bt_le_audio_tx.h"
#include "le_audio.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <zephyr/bluetooth/audio/lc3.h>

#include "macros_common.h"
#include "nrf5340_audio_common.h"
#include "zbus_common.h"
#include "bt_le_audio_tx.h"
#include "le_audio.h"

Expand Down
2 changes: 1 addition & 1 deletion applications/nrf5340_audio/src/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/audio_i2s.c)
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/audio_usb.c)
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/button_handler.c)
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/led.c)
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/audio_sync_timer_rtc.c)
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/audio_sync_timer.c)

target_sources_ifdef(CONFIG_NRF5340_AUDIO_CS47L63_DRIVER app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/hw_codec.c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,30 @@
#include <nrfx_timer.h>
#include <nrfx_egu.h>


#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(audio_sync_timer, CONFIG_AUDIO_SYNC_TIMER_LOG_LEVEL);

#define AUDIO_SYNC_TIMER_NET_APP_IPC_EVT_CHANNEL 4
#define AUDIO_SYNC_TIMER_NET_APP_IPC_EVT NRF_IPC_EVENT_RECEIVE_4
#define AUDIO_SYNC_TIMER_NET_APP_IPC_EVT_CHANNEL 4
#define AUDIO_SYNC_TIMER_NET_APP_IPC_EVT NRF_IPC_EVENT_RECEIVE_4

#define AUDIO_SYNC_HF_TIMER_INSTANCE_NUMBER 1
#define AUDIO_SYNC_HF_TIMER_INSTANCE_NUMBER 1

#define AUDIO_SYNC_HF_TIMER_I2S_FRAME_START_EVT_CAPTURE_CHANNEL 0
#define AUDIO_SYNC_HF_TIMER_I2S_FRAME_START_EVT_CAPTURE NRF_TIMER_TASK_CAPTURE0
#define AUDIO_SYNC_HF_TIMER_CURR_TIME_CAPTURE_CHANNEL 1
#define AUDIO_SYNC_HF_TIMER_CURR_TIME_CAPTURE NRF_TIMER_TASK_CAPTURE1
#define AUDIO_SYNC_HF_TIMER_I2S_FRAME_START_EVT_CAPTURE NRF_TIMER_TASK_CAPTURE0
#define AUDIO_SYNC_HF_TIMER_CURR_TIME_CAPTURE_CHANNEL 1
#define AUDIO_SYNC_HF_TIMER_CURR_TIME_CAPTURE NRF_TIMER_TASK_CAPTURE1

static const nrfx_timer_t audio_sync_hf_timer_instance =
NRFX_TIMER_INSTANCE(AUDIO_SYNC_HF_TIMER_INSTANCE_NUMBER);

static uint8_t dppi_channel_i2s_frame_start;

#define AUDIO_SYNC_LF_TIMER_INSTANCE_NUMBER 0
#define AUDIO_SYNC_LF_TIMER_INSTANCE_NUMBER 0

#define AUDIO_SYNC_LF_TIMER_I2S_FRAME_START_EVT_CAPTURE_CHANNEL 0
#define AUDIO_SYNC_LF_TIMER_I2S_FRAME_START_EVT_CAPTURE NRF_RTC_TASK_CAPTURE_0
#define AUDIO_SYNC_LF_TIMER_CURR_TIME_CAPTURE_CHANNEL 1
#define AUDIO_SYNC_LF_TIMER_CURR_TIME_CAPTURE NRF_RTC_TASK_CAPTURE_1
#define AUDIO_SYNC_LF_TIMER_I2S_FRAME_START_EVT_CAPTURE NRF_RTC_TASK_CAPTURE_0
#define AUDIO_SYNC_LF_TIMER_CURR_TIME_CAPTURE_CHANNEL 1
#define AUDIO_SYNC_LF_TIMER_CURR_TIME_CAPTURE NRF_RTC_TASK_CAPTURE_1

static uint8_t dppi_channel_curr_time_capture;

Expand All @@ -64,8 +63,7 @@ static uint32_t timestamp_from_rtc_and_timer_get(uint32_t ticks, uint32_t remain
const uint32_t rtc_overflow_time_us = 512000000UL;

return ((ticks * rtc_ticks_in_femto_units) / 1000000000UL) +
(num_rtc_overflows * rtc_overflow_time_us) +
remainder_us;
(num_rtc_overflows * rtc_overflow_time_us) + remainder_us;
}

uint32_t audio_sync_timer_capture(void)
Expand Down Expand Up @@ -102,8 +100,8 @@ uint32_t audio_sync_timer_capture(void)
}

/* Read captured TIMER value */
uint32_t remainder_us = nrf_timer_cc_get(NRF_TIMER1,
AUDIO_SYNC_HF_TIMER_CURR_TIME_CAPTURE_CHANNEL);
uint32_t remainder_us =
nrf_timer_cc_get(NRF_TIMER1, AUDIO_SYNC_HF_TIMER_CURR_TIME_CAPTURE_CHANNEL);

return timestamp_from_rtc_and_timer_get(tick, remainder_us);
}
Expand Down
2 changes: 1 addition & 1 deletion applications/nrf5340_audio/src/modules/audio_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <zephyr/kernel.h>
#include <zephyr/usb/usb_device.h>
#include <zephyr/usb/class/usb_audio.h>
#include <data_fifo.h>

#include "macros_common.h"
#include "data_fifo.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(audio_usb, CONFIG_MODULE_AUDIO_USB_LOG_LEVEL);
Expand Down
2 changes: 1 addition & 1 deletion applications/nrf5340_audio/src/modules/audio_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef _AUDIO_USB_H_
#define _AUDIO_USB_H_

#include "data_fifo.h"
#include <data_fifo.h>

#if (CONFIG_AUDIO_SOURCE_USB && !CONFIG_AUDIO_SAMPLE_RATE_48000_HZ)
/* Only 48kHz is supported when using USB */
Expand Down
2 changes: 1 addition & 1 deletion applications/nrf5340_audio/src/modules/button_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <ctype.h>

#include "macros_common.h"
#include "nrf5340_audio_common.h"
#include "zbus_common.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(button_handler, CONFIG_MODULE_BUTTON_HANDLER_LOG_LEVEL);
Expand Down
2 changes: 1 addition & 1 deletion applications/nrf5340_audio/src/modules/hw_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <zephyr/zbus/zbus.h>

#include "macros_common.h"
#include "nrf5340_audio_common.h"
#include "zbus_common.h"
#include "cs47l63.h"
#include "cs47l63_spec.h"
#include "cs47l63_reg_conf.h"
Expand Down
Loading

0 comments on commit 8fc5a5f

Please sign in to comment.