From de0c79f819d7e2e904f51db634b9d6554b2b0527 Mon Sep 17 00:00:00 2001 From: Arkadiusz Balys Date: Tue, 30 Jan 2024 10:08:12 +0100 Subject: [PATCH] Added shell command for gain --- applications/nrf5340_audio/prj.conf | 4 +-- .../nrf5340_audio/src/modules/hw_codec.c | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/applications/nrf5340_audio/prj.conf b/applications/nrf5340_audio/prj.conf index 7c6f0c406624..afec9f547dc1 100644 --- a/applications/nrf5340_audio/prj.conf +++ b/applications/nrf5340_audio/prj.conf @@ -37,8 +37,8 @@ CONFIG_KERNEL_SHELL=y CONFIG_USE_SEGGER_RTT=y ## Disable logs on RTT CONFIG_SHELL_RTT_INIT_LOG_LEVEL_NONE=y -CONFIG_SHELL_BACKEND_RTT=y -CONFIG_SHELL_BACKEND_SERIAL=n +CONFIG_SHELL_BACKEND_RTT=n +CONFIG_SHELL_BACKEND_SERIAL=y CONFIG_SHELL_VT100_COLORS=y CONFIG_SHELL_STACK_SIZE=1024 CONFIG_SHELL_CMD_BUFF_SIZE=128 diff --git a/applications/nrf5340_audio/src/modules/hw_codec.c b/applications/nrf5340_audio/src/modules/hw_codec.c index 2d4781fb9b71..1135dcc485f2 100644 --- a/applications/nrf5340_audio/src/modules/hw_codec.c +++ b/applications/nrf5340_audio/src/modules/hw_codec.c @@ -478,10 +478,37 @@ static int cmd_input(const struct shell *shell, size_t argc, char **argv) return 0; } +static int cmd_gain(const struct shell *shell, size_t argc, char **argv) +{ + uint8_t gain = 0; + + if (argc == 1) { + shell_print(shell, "Current gain %u dB", gain); + return 0; + } + + if (argc != 2) { + shell_error(shell, "Only one argument required, provided: %d", argc); + return -EINVAL; + } + + if (!isdigit((int)argv[1][0])) { + shell_error(shell, "Supplied argument is not numeric"); + return -EINVAL; + } + + gain = strtoul(argv[1], NULL, BASE_10); + + shell_print(shell, "Selected gain: %u dB", gain); + + return 0; +} + SHELL_STATIC_SUBCMD_SET_CREATE(hw_codec_cmd, SHELL_COND_CMD(CONFIG_SHELL, input, NULL, " Select input\n\t0: LINE_IN\n\t\t1: PDM_MIC", cmd_input), + SHELL_COND_CMD(CONFIG_SHELL, gain, NULL, " Set gain [dB]", cmd_gain), SHELL_SUBCMD_SET_END); SHELL_CMD_REGISTER(hw_codec, &hw_codec_cmd, "Change settings on HW codec", NULL);