diff --git a/applications/nrf5340_audio/CMakeLists.txt b/applications/nrf5340_audio/CMakeLists.txt index c75af4ee3b9e..135f01e99945 100644 --- a/applications/nrf5340_audio/CMakeLists.txt +++ b/applications/nrf5340_audio/CMakeLists.txt @@ -8,6 +8,9 @@ cmake_minimum_required(VERSION 3.20.0) file(TO_CMAKE_PATH $ENV{ZEPHYR_BASE} CMAKE_STYLE_ZEPHYR) + +set(SHIELD adafruit_2_8_tft_touch_v2) + if (CONFIG_AUDIO_DFU EQUAL 1) list(APPEND mcuboot_OVERLAY_CONFIG "${CMAKE_CURRENT_LIST_DIR}/dfu/conf/overlay-mcuboot.conf" diff --git a/applications/nrf5340_audio/prj.conf b/applications/nrf5340_audio/prj.conf index 162cc1ffdb96..617f86b142c9 100644 --- a/applications/nrf5340_audio/prj.conf +++ b/applications/nrf5340_audio/prj.conf @@ -58,3 +58,7 @@ 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_NRF5340AUDIODK_DISPLAY=y + +CONFIG_MAIN_STACK_SIZE=2048 +CONFIG_LV_Z_MEM_POOL_NUMBER_BLOCKS=8 diff --git a/applications/nrf5340_audio/src/main.c b/applications/nrf5340_audio/src/main.c index 864ac4750f48..3df0e23dc911 100644 --- a/applications/nrf5340_audio/src/main.c +++ b/applications/nrf5340_audio/src/main.c @@ -25,6 +25,7 @@ #include "audio_system.h" #include "channel_assignment.h" #include "streamctrl.h" +#include #if defined(CONFIG_AUDIO_DFU_ENABLE) #include "dfu_entry.h" @@ -227,4 +228,5 @@ int main(void) ret = streamctrl_start(); ERR_CHK(ret); + display_init(); } diff --git a/applications/nrf5340_audio/tools/buildprog/nrf5340_audio_dk_devices.json b/applications/nrf5340_audio/tools/buildprog/nrf5340_audio_dk_devices.json index 0a42fe365d5b..4487f1df7e91 100644 --- a/applications/nrf5340_audio/tools/buildprog/nrf5340_audio_dk_devices.json +++ b/applications/nrf5340_audio/tools/buildprog/nrf5340_audio_dk_devices.json @@ -1,16 +1,16 @@ [ { - "nrf5340_audio_dk_snr": 1000, + "nrf5340_audio_dk_snr": 1050163097, "nrf5340_audio_dk_dev": "headset", "channel": "left" }, { - "nrf5340_audio_dk_snr": 1000, + "nrf5340_audio_dk_snr": 1050156006, "nrf5340_audio_dk_dev": "gateway", "channel": "NA" }, { - "nrf5340_audio_dk_snr": 1000, + "nrf5340_audio_dk_snr": 1050129901, "nrf5340_audio_dk_dev": "headset", "channel": "right" } diff --git a/include/nrf5340audiodk_display/nrf5340audiodk_display.h b/include/nrf5340audiodk_display/nrf5340audiodk_display.h new file mode 100644 index 000000000000..7977b5f16c34 --- /dev/null +++ b/include/nrf5340audiodk_display/nrf5340audiodk_display.h @@ -0,0 +1,5 @@ +#ifndef NRF5340AUDIODK_DISPLAY_H +#define NRF5340AUDIODK_DISPLAY_H + +void display_init(); +#endif \ No newline at end of file diff --git a/subsys/CMakeLists.txt b/subsys/CMakeLists.txt index f05176d31b20..f508b96b62a5 100644 --- a/subsys/CMakeLists.txt +++ b/subsys/CMakeLists.txt @@ -70,3 +70,4 @@ add_subdirectory_ifdef(CONFIG_NRF_RPC nrf_rpc) add_subdirectory_ifdef(CONFIG_NRF_802154_RADIO_DRIVER ieee802154) add_subdirectory_ifdef(CONFIG_NRF_DM dm) add_subdirectory_ifdef(CONFIG_EMDS emds) +add_subdirectory_ifdef(CONFIG_NRF5340AUDIODK_DISPLAY nrf5340audiodk_display) \ No newline at end of file diff --git a/subsys/Kconfig b/subsys/Kconfig index e03eb0a9b7af..4d91b5f6a96d 100644 --- a/subsys/Kconfig +++ b/subsys/Kconfig @@ -55,4 +55,6 @@ rsource "ieee802154/Kconfig" rsource "dm/Kconfig" +rsource "nrf5340audiodk_display/Kconfig" + rsource "nrf_security/Kconfig" diff --git a/subsys/mgmt/fmfu/Kconfig b/subsys/mgmt/fmfu/Kconfig index 10d60a983beb..bb89934ecd7d 100644 --- a/subsys/mgmt/fmfu/Kconfig +++ b/subsys/mgmt/fmfu/Kconfig @@ -16,4 +16,4 @@ module=MGMT_FMFU module-dep=LOG module-str=FMFU source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config" -endmenu +endmenu \ No newline at end of file diff --git a/subsys/nrf5340audiodk_display/CMakeLists.txt b/subsys/nrf5340audiodk_display/CMakeLists.txt new file mode 100644 index 000000000000..fa7eac7d5bd8 --- /dev/null +++ b/subsys/nrf5340audiodk_display/CMakeLists.txt @@ -0,0 +1,11 @@ +# +# Copyright (c) 2021 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# +zephyr_library() + +zephyr_library_sources( + src/nrf5340audiodk_display.c + src/button_tab.c + ) diff --git a/subsys/nrf5340audiodk_display/Kconfig b/subsys/nrf5340audiodk_display/Kconfig new file mode 100644 index 000000000000..4df3cd3a812d --- /dev/null +++ b/subsys/nrf5340audiodk_display/Kconfig @@ -0,0 +1,21 @@ +config NRF5340AUDIODK_DISPLAY + bool "Need this string for config to work" + select DISPLAY + select LOG + select LVGL + select LV_MEM_CUSTOM + select LV_USE_LOG + select LV_USE_LABEL + select LV_USE_BTN + select LV_USE_IMG + select LV_FONT_MONTSERRAT_14 + select CONFIG_LOG + select CONFIG_LOG_MODE_MINIMAL + select CONFIG_DISPLAY + select CONFIG_LVGL + select CONFIG_LV_MEM_CUSTOM + select CONFIG_LV_USE_LOG + select CONFIG_LV_USE_LABEL + select CONFIG_LV_USE_BTN + select CONFIG_LV_USE_IMG + select CONFIG_LV_FONT_MONTSERRAT_14 \ No newline at end of file diff --git a/subsys/nrf5340audiodk_display/src/button_tab.c b/subsys/nrf5340audiodk_display/src/button_tab.c new file mode 100644 index 000000000000..1be64eeff1b3 --- /dev/null +++ b/subsys/nrf5340audiodk_display/src/button_tab.c @@ -0,0 +1,203 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL +#include +#include +#include "nrf5340audiodk_display_internal.h" + +enum button_action { + BUTTON_PRESS, + BUTTON_ACTION_NUM, +}; +struct button_msg { + uint32_t button_pin; + enum button_action button_action; +}; + +ZBUS_CHAN_DECLARE(button_chan); + +static void event_cb_play_pause_button(lv_event_t *e) +{ + struct button_msg msg; + + msg.button_action = BUTTON_PRESS; + msg.button_pin = BUTTON_PLAY_PAUSE; + + int ret; + ret = zbus_chan_pub(&button_chan, &msg, K_NO_WAIT); + /* if (ret) { + LOG_ERR("Failed to publish button msg, ret: %d", ret); + } */ +} + +static void event_cb_volume_up_button(lv_event_t *e) +{ + struct button_msg msg; + + msg.button_action = BUTTON_PRESS; + msg.button_pin = BUTTON_VOLUME_UP; + + int ret; + ret = zbus_chan_pub(&button_chan, &msg, K_NO_WAIT); + /* if (ret) { + LOG_ERR("Failed to publish button msg, ret: %d", ret); +} */ +} + +static void event_cb_volume_down_button(lv_event_t *e) +{ + struct button_msg msg; + + msg.button_action = BUTTON_PRESS; + msg.button_pin = BUTTON_VOLUME_DOWN; + + int ret; + ret = zbus_chan_pub(&button_chan, &msg, K_NO_WAIT); + /* if (ret) { + LOG_ERR("Failed to publish button msg, ret: %d", ret); + } */ +} +static void event_cb_btn4_button(lv_event_t *e) +{ + struct button_msg msg; + + msg.button_action = BUTTON_PRESS; + msg.button_pin = BUTTON_4; + + int ret; + ret = zbus_chan_pub(&button_chan, &msg, K_NO_WAIT); + /* if (ret) { + LOG_ERR("Failed to publish button msg, ret: %d", ret); + } */ +} + +static void event_cb_btn5_button(lv_event_t *e) +{ + struct button_msg msg; + + msg.button_action = BUTTON_PRESS; + msg.button_pin = BUTTON_5; + + int ret; + ret = zbus_chan_pub(&button_chan, &msg, K_NO_WAIT); + /* if (ret) { + LOG_ERR("Failed to publish button msg, ret: %d", ret); + } */ +} + +void create_play_pause_button(lv_obj_t *current_screen) +{ + lv_obj_t *play_pause_button; + lv_obj_t *play_pause_label; + + play_pause_button = lv_btn_create(current_screen); + lv_obj_align(play_pause_button, LV_ALIGN_CENTER, 0, 0); + play_pause_label = lv_label_create(play_pause_button); + lv_label_set_text(play_pause_label, "Play/Pause"); + lv_obj_align(play_pause_label, LV_ALIGN_CENTER, 0, 0); + lv_obj_add_event_cb(play_pause_button, event_cb_play_pause_button, LV_EVENT_CLICKED, NULL); +} + +void create_volume_buttons(lv_obj_t *current_screen) +{ + lv_obj_t *volume_up_button; + lv_obj_t *volume_down_button; + + lv_obj_t *volume_up_label; + lv_obj_t *volume_down_label; + lv_obj_t *volume_level_label; + + volume_up_button = lv_btn_create(current_screen); + volume_down_button = lv_btn_create(current_screen); + + volume_up_label = lv_label_create(volume_up_button); + volume_down_label = lv_label_create(volume_down_button); + volume_level_label = lv_label_create(current_screen); + + lv_label_set_text(volume_up_label, "Vol+"); + lv_label_set_text(volume_down_label, "Vol-"); + lv_label_set_text(volume_level_label, "Volume"); + + lv_obj_align(volume_up_button, LV_ALIGN_TOP_RIGHT, 0, 0); + lv_obj_align(volume_down_button, LV_ALIGN_BOTTOM_RIGHT, 0, 0); + + lv_obj_align(volume_up_label, LV_ALIGN_TOP_RIGHT, 0, 0); + lv_obj_align(volume_down_label, LV_ALIGN_CENTER, 0, 0); + lv_obj_align(volume_level_label, LV_ALIGN_TOP_RIGHT, 0, 40); + lv_obj_add_event_cb(volume_up_button, event_cb_volume_up_button, LV_EVENT_CLICKED, NULL); + lv_obj_add_event_cb(volume_down_button, event_cb_volume_down_button, LV_EVENT_CLICKED, + NULL); +} + +void create_btn4_gateway_button(lv_obj_t *current_screen) +{ + lv_obj_t *btn4_button; + lv_obj_t *btn4_label; + + btn4_button = lv_btn_create(current_screen); + lv_obj_align(btn4_button, LV_ALIGN_TOP_LEFT, 0, 0); + btn4_label = lv_label_create(btn4_button); + lv_label_set_text(btn4_label, "Test tone"); + lv_obj_align(btn4_label, LV_ALIGN_TOP_LEFT, 0, 0); + lv_obj_add_event_cb(btn4_button, event_cb_btn4_button, LV_EVENT_CLICKED, NULL); +} +void create_btn4_headset_button(lv_obj_t *current_screen) +{ + lv_obj_t *btn4_button; + lv_obj_t *btn4_label; + + btn4_button = lv_btn_create(current_screen); + lv_obj_align(btn4_button, LV_ALIGN_TOP_LEFT, 0, 0); + btn4_label = lv_label_create(btn4_button); + lv_label_set_text(btn4_label, "Change audio stream"); + lv_obj_align(btn4_label, LV_ALIGN_TOP_LEFT, 0, 0); + lv_obj_add_event_cb(btn4_button, event_cb_btn4_button, LV_EVENT_CLICKED, NULL); +} +void create_btn5_button(lv_obj_t *current_screen) +{ + lv_obj_t *btn5_button; + lv_obj_t *btn5_label; + + btn5_button = lv_btn_create(current_screen); + lv_obj_align(btn5_button, LV_ALIGN_BOTTOM_LEFT, 0, 0); + btn5_label = lv_label_create(btn5_button); + lv_label_set_text(btn5_label, "Mute"); + lv_obj_align(btn5_label, LV_ALIGN_BOTTOM_LEFT, 0, 0); + lv_obj_add_event_cb(btn5_button, event_cb_btn5_button, LV_EVENT_CLICKED, NULL); +} +void create_devicetype_label(lv_obj_t *current_screen) +{ + char what_dev_am_i[8]; + +#if (CONFIG_AUDIO_DEV == 1) + strcpy(what_dev_am_i, "Headset"); +#endif +#if (CONFIG_AUDIO_DEV == 2) + strcpy(what_dev_am_i, "Gateway"); +#endif + lv_obj_t *what_dev_am_i_label; + what_dev_am_i_label = lv_label_create(current_screen); + lv_label_set_text(what_dev_am_i_label, what_dev_am_i); + lv_obj_align(what_dev_am_i_label, LV_ALIGN_BOTTOM_MID, 0, 0); +} +void create_button_tab(lv_obj_t *screen) +{ +#if (CONFIG_AUDIO_DEV == 1) + create_btn4_headset_button(screen); +#endif +#if (CONFIG_AUDIO_DEV == 2) + create_btn4_gateway_button(screen); +#endif + create_play_pause_button(screen); + create_volume_buttons(screen); + create_btn5_button(screen); + create_devicetype_label(screen); +} \ No newline at end of file diff --git a/subsys/nrf5340audiodk_display/src/nrf5340audiodk_display.c b/subsys/nrf5340audiodk_display/src/nrf5340audiodk_display.c new file mode 100644 index 000000000000..6daad2de1fb2 --- /dev/null +++ b/subsys/nrf5340audiodk_display/src/nrf5340audiodk_display.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL +#include +#include +#include "nrf5340audiodk_display_internal.h" +LOG_MODULE_REGISTER(app); + +int test; +enum button_action { + BUTTON_PRESS, + BUTTON_ACTION_NUM, +}; +struct button_msg { + uint32_t button_pin; + enum button_action button_action; +}; + +ZBUS_CHAN_DECLARE(button_chan); + +void create_timestamp_label(lv_obj_t *current_screen) +{ + static uint32_t count; + char count_str[11] = {0}; + lv_obj_t *count_label; + count_label = lv_label_create(current_screen); + lv_obj_align(count_label, LV_ALIGN_BOTTOM_MID, 0, 0); + while (1) { + if ((count % 100) == 0U) { + sprintf(count_str, "%d", count / 100U); + lv_label_set_text(count_label, count_str); + } + lv_task_handler(); + ++count; + k_sleep(K_MSEC(10)); + } +} + +void display_init() +{ + lv_obj_t *tabview; + tabview = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 50); + + lv_obj_t *button_tab = lv_tabview_add_tab(tabview, "Button Tab"); + lv_obj_t *log_tab = lv_tabview_add_tab(tabview, "Log Tab"); + lv_obj_t *state_tab = lv_tabview_add_tab(tabview, "State Tab"); + + const struct device *display_dev; + display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display)); + + if (!device_is_ready(display_dev)) { + LOG_ERR("Device not ready, aborting test"); + return; + } + create_button_tab(button_tab); + + display_blanking_off(display_dev); + + while (1) { + lv_task_handler(); + k_sleep(K_MSEC(16)); + } +} \ No newline at end of file diff --git a/subsys/nrf5340audiodk_display/src/nrf5340audiodk_display_internal.h b/subsys/nrf5340audiodk_display/src/nrf5340audiodk_display_internal.h new file mode 100644 index 000000000000..df3e2f0e0c69 --- /dev/null +++ b/subsys/nrf5340audiodk_display/src/nrf5340audiodk_display_internal.h @@ -0,0 +1,11 @@ +enum button_pin_names { + BUTTON_VOLUME_DOWN = DT_GPIO_PIN(DT_ALIAS(sw0), gpios), + BUTTON_VOLUME_UP = DT_GPIO_PIN(DT_ALIAS(sw1), gpios), + BUTTON_PLAY_PAUSE = DT_GPIO_PIN(DT_ALIAS(sw2), gpios), + BUTTON_4 = DT_GPIO_PIN(DT_ALIAS(sw3), gpios), + BUTTON_5 = DT_GPIO_PIN(DT_ALIAS(sw4), gpios), +}; + + + +void create_button_tab(lv_obj_t *screen); \ No newline at end of file