Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button tab #11622

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions applications/nrf5340_audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions applications/nrf5340_audio/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions applications/nrf5340_audio/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "audio_system.h"
#include "channel_assignment.h"
#include "streamctrl.h"
#include <nrf5340audiodk_display/nrf5340audiodk_display.h>

#if defined(CONFIG_AUDIO_DFU_ENABLE)
#include "dfu_entry.h"
Expand Down Expand Up @@ -227,4 +228,5 @@ int main(void)

ret = streamctrl_start();
ERR_CHK(ret);
display_init();
}
Original file line number Diff line number Diff line change
@@ -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"
}
Expand Down
5 changes: 5 additions & 0 deletions include/nrf5340audiodk_display/nrf5340audiodk_display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef NRF5340AUDIODK_DISPLAY_H
#define NRF5340AUDIODK_DISPLAY_H

void display_init();
#endif
1 change: 1 addition & 0 deletions subsys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions subsys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ rsource "ieee802154/Kconfig"

rsource "dm/Kconfig"

rsource "nrf5340audiodk_display/Kconfig"

rsource "nrf_security/Kconfig"
2 changes: 1 addition & 1 deletion subsys/mgmt/fmfu/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ module=MGMT_FMFU
module-dep=LOG
module-str=FMFU
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
endmenu
endmenu
11 changes: 11 additions & 0 deletions subsys/nrf5340audiodk_display/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
21 changes: 21 additions & 0 deletions subsys/nrf5340audiodk_display/Kconfig
Original file line number Diff line number Diff line change
@@ -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
203 changes: 203 additions & 0 deletions subsys/nrf5340audiodk_display/src/button_tab.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
#include <nrf5340audiodk_display/nrf5340audiodk_display.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/display.h>
#include <zephyr/drivers/gpio.h>
#include <lvgl.h>
#include <stdio.h>
#include <string.h>
#include <zephyr/kernel.h>
#include <zephyr/zbus/zbus.h>
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include <zephyr/logging/log.h>
#include <stdint.h>
#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);
}
71 changes: 71 additions & 0 deletions subsys/nrf5340audiodk_display/src/nrf5340audiodk_display.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <nrf5340audiodk_display/nrf5340audiodk_display.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/display.h>
#include <zephyr/drivers/gpio.h>
#include <lvgl.h>
#include <stdio.h>
#include <string.h>
#include <zephyr/kernel.h>
#include <zephyr/zbus/zbus.h>
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include <zephyr/logging/log.h>
#include <stdint.h>
#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));
}
}
Loading