Skip to content

Commit

Permalink
Boards:shield:added nrf5340 audio display
Browse files Browse the repository at this point in the history
  • Loading branch information
philipfidjeland committed Aug 14, 2023
1 parent 851f1f6 commit f6d0223
Show file tree
Hide file tree
Showing 21 changed files with 1,046 additions and 17 deletions.
2 changes: 2 additions & 0 deletions applications/nrf5340_audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ cmake_minimum_required(VERSION 3.20.0)

file(TO_CMAKE_PATH $ENV{ZEPHYR_BASE} CMAKE_STYLE_ZEPHYR)

set(SHIELD nrf5340_audio_display)

if (CONFIG_AUDIO_DFU EQUAL 1)
list(APPEND mcuboot_OVERLAY_CONFIG
"${CMAKE_CURRENT_LIST_DIR}/dfu/conf/overlay-mcuboot.conf"
Expand Down
1 change: 1 addition & 0 deletions applications/nrf5340_audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ rsource "src/drivers/Kconfig"
rsource "src/modules/Kconfig"
rsource "src/utils/Kconfig"
rsource "dfu/conf/Kconfig.dfu"
rsource "src/modules/display/Kconfig"

#----------------------------------------------------------------------------#
menu "Logging"
Expand Down
5 changes: 4 additions & 1 deletion applications/nrf5340_audio/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ config ZBUS
default y

config ZBUS_RUNTIME_OBSERVERS_POOL_SIZE
default 2
default 3

config SENSOR
default y
Expand Down Expand Up @@ -144,3 +144,6 @@ config FS_FATFS_MAX_LFN

config BT_LL_ACS_NRF53
default y
config NRF5340_AUDIO_DK_DISPLAY
default y

3 changes: 3 additions & 0 deletions applications/nrf5340_audio/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ CONFIG_DEVICE_SHELL=n
# Suppress err msg from sd_check_card_type. Because SPI_SDHC has no card presence method,
# assume card is in slot. Thus error message is always shown if card is not inserted
CONFIG_SD_LOG_LEVEL_OFF=y
CONFIG_AUDIO_SOURCE_I2S=y
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_NRF5340_AUDIO_DK_DISPLAY=y
10 changes: 9 additions & 1 deletion applications/nrf5340_audio/src/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/led.c
${CMAKE_CURRENT_SOURCE_DIR}/power_meas.c
${CMAKE_CURRENT_SOURCE_DIR}/sd_card.c
)
)

if (CONFIG_AUDIO_DFU_ENABLE)
target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/dfu_entry.c
)
endif()

if (CONFIG_DISPLAY)
target_sources(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/display/nrf5340_audio_dk_display.c
${CMAKE_CURRENT_SOURCE_DIR}/display/tab_menu.c
${CMAKE_CURRENT_SOURCE_DIR}/display/tab_log.c
)
endif()
8 changes: 6 additions & 2 deletions applications/nrf5340_audio/src/modules/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#

rsource "Kconfig.defaults"

rsource "display/Kconfig"
menu "Modules"

config BUTTON_DEBOUNCE_MS
int "Button debounce time in ms"
default 50

#----------------------------------------------------------------------------#
menu "Power measurement"

Expand Down Expand Up @@ -84,6 +84,10 @@ module = MODULE_SD_CARD
module-str = module-sd-card
source "subsys/logging/Kconfig.template.log_config"

module=NRF5340_AUDIO_DK_DISPLAYDISPLAY
module-str=nrf5340_audio_dk_display
source "subsys/logging/Kconfig.template.log_config"

endmenu # Log levels

#----------------------------------------------------------------------------#
Expand Down
26 changes: 26 additions & 0 deletions applications/nrf5340_audio/src/modules/display/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
rsource "Kconfig.defaults"

menu "NRF5340_audio_DK_display"

config NRF5340_AUDIO_DK_DISPLAY
bool "True if using display for nrf5340 audio DK"
default n

config DISPLAY_LOG_TAB_LOG_LEVEL
int "Log level of messages display on log tab"
default 2

config LOG_TIMESTAMP
bool "Display timestamp in us in front of log message"
default n

config LOG_TAB_MAX_LEN
int "How many log messages to be stored on the log tab"
default 10

endmenu # NRF5340_audio_DK_display
33 changes: 33 additions & 0 deletions applications/nrf5340_audio/src/modules/display/Kconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
#rsource "Kconfig.defaults"

if NRF5340_AUDIO_DK_DISPLAY

config DISPLAY
default y

config LVGL
default y

config LV_Z_MEM_POOL_NUMBER_BLOCKS
int "Number of max size blocks in memory pool"
default 8

config LV_FONT_MONTSERRAT_14
default y

config LV_FONT_MONTSERRAT_48
default y

config LV_FONT_MONTSERRAT_20
default y

config LV_Z_VDB_SIZE
int "Virtual display buffer size"
default 32

endif # NRF5340_AUDIO_DK_DISPLAY
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/display.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/kernel.h>
#include <zephyr/zbus/zbus.h>
#include <zephyr/logging/log.h>

#include <stdio.h>
#include <string.h>
#include <stdint.h>

#include <lvgl.h>
#include "tab_menu.h"
#include "tab_log.h"
#include "macros_common.h"

#define DISPLAY_THREAD_PRIORITY 5
#define DISPLAY_INIT_PRIORITY 91 /* Must have lower priority than LVGL init */
#define DISPLAY_THREAD_STACK_SIZE 4096

LOG_MODULE_REGISTER(display_log, CONFIG_DISPLAY_LOG_LEVEL);

struct k_thread display_data;
k_tid_t display_thread;
lv_obj_t *tab_log;

ZBUS_CHAN_DECLARE(button_chan);
ZBUS_CHAN_DECLARE(le_audio_chan);

ZBUS_OBS_DECLARE(le_audio_evt_sub_display);

K_THREAD_STACK_DEFINE(display_thread_STACK, DISPLAY_THREAD_STACK_SIZE);

void nrf5340_audio_dk_display_update_thread(void *arg1, void *arg2, void *arg3)
{

int update_counter = 0;
int update_counter_menu = 0;

while (1) {
update_counter++;
if (update_counter >= 10) {
update_counter_menu = tab_menu_update(update_counter_menu);
update_counter = 0;
}
uint32_t time_till_next = lv_timer_handler();

k_sleep(K_MSEC(time_till_next));
}
}

lv_obj_t *tab_log_get(void)
{
return tab_log;
}

static int nrf5340_audio_dk_display_init(void)
{
const struct device *display_dev;
int ret;
lv_obj_t *tabview;
lv_obj_t *tab_menu;

display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(display_dev)) {
LOG_ERR("Device not ready, aborting test");
return -ENODEV;
}

tabview = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 50);

tab_menu = lv_tabview_add_tab(tabview, "Menu");
tab_log = lv_tabview_add_tab(tabview, "Logging");

ret = zbus_chan_add_obs(&le_audio_chan, &le_audio_evt_sub_display, K_MSEC(200));
ERR_CHK(ret);

display_blanking_off(display_dev);

tab_menu_create(tab_menu);

tab_log_create(tab_log);

lv_obj_clear_flag(lv_tabview_get_content(tabview), LV_OBJ_FLAG_SCROLLABLE);

display_thread = k_thread_create(&display_data, display_thread_STACK,
K_THREAD_STACK_SIZEOF(display_thread_STACK),
nrf5340_audio_dk_display_update_thread, NULL, NULL, NULL,
K_PRIO_PREEMPT(DISPLAY_THREAD_PRIORITY), 0, K_NO_WAIT);
k_thread_name_set(display_thread, "Nrf5340_audio__dk display thread");

return 0;
}
SYS_INIT(nrf5340_audio_dk_display_init, APPLICATION, DISPLAY_INIT_PRIORITY);
Loading

0 comments on commit f6d0223

Please sign in to comment.