From 17ce2a19e4e05e71c860944130c1df55591df9dc Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Tue, 17 Dec 2024 10:44:36 +0100 Subject: [PATCH] samples: drivers: i2s: echo: add options to control sw0/sw1 Add options to control the behavior of sw0/sw1. These options also allow to select GPIO when needed. Signed-off-by: Gerard Marull-Paretas --- samples/drivers/i2s/echo/Kconfig | 12 ++++++++++++ samples/drivers/i2s/echo/src/main.c | 12 ++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/samples/drivers/i2s/echo/Kconfig b/samples/drivers/i2s/echo/Kconfig index 8cd630f1c66..623e2ae6318 100644 --- a/samples/drivers/i2s/echo/Kconfig +++ b/samples/drivers/i2s/echo/Kconfig @@ -5,3 +5,15 @@ source "Kconfig.zephyr" config I2C default $(dt_compat_on_bus,$(DT_COMPAT_WOLFSON_WM8731),i2c) + +config TOGGLE_ECHO_EFFECT_SW0 + bool "Toggle echo effect when pressing sw0" + depends on $(dt_alias_enabled,sw0) + select GPIO + default y + +config STOP_START_STREAMS_SW1 + bool "Start/stop I2S streams when pressing sw1" + depends on $(dt_alias_enabled,sw1) + select GPIO + default y diff --git a/samples/drivers/i2s/echo/src/main.c b/samples/drivers/i2s/echo/src/main.c index bffa794158b..d9619bf94c7 100644 --- a/samples/drivers/i2s/echo/src/main.c +++ b/samples/drivers/i2s/echo/src/main.c @@ -30,12 +30,12 @@ #define TIMEOUT 1000 #define SW0_NODE DT_ALIAS(sw0) -#if DT_NODE_HAS_STATUS_OKAY(SW0_NODE) +#ifdef CONFIG_TOGGLE_ECHO_EFFECT_SW0 static struct gpio_dt_spec sw0_spec = GPIO_DT_SPEC_GET(SW0_NODE, gpios); #endif #define SW1_NODE DT_ALIAS(sw1) -#if DT_NODE_HAS_STATUS_OKAY(SW1_NODE) +#ifdef CONFIG_STOP_START_STREAMS_SW1 static struct gpio_dt_spec sw1_spec = GPIO_DT_SPEC_GET(SW1_NODE, gpios); #endif @@ -47,7 +47,7 @@ static int16_t echo_block[SAMPLES_PER_BLOCK]; static volatile bool echo_enabled = true; static K_SEM_DEFINE(toggle_transfer, 1, 1); -#if DT_NODE_HAS_STATUS_OKAY(SW0_NODE) +#ifdef CONFIG_TOGGLE_ECHO_EFFECT_SW0 static void sw0_handler(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { @@ -58,7 +58,7 @@ static void sw0_handler(const struct device *dev, struct gpio_callback *cb, } #endif -#if DT_NODE_HAS_STATUS_OKAY(SW1_NODE) +#ifdef CONFIG_STOP_START_STREAMS_SW1 static void sw1_handler(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { @@ -70,7 +70,7 @@ static bool init_buttons(void) { int ret; -#if DT_NODE_HAS_STATUS_OKAY(SW0_NODE) +#ifdef CONFIG_TOGGLE_ECHO_EFFECT_SW0 static struct gpio_callback sw0_cb_data; if (!gpio_is_ready_dt(&sw0_spec)) { @@ -98,7 +98,7 @@ static bool init_buttons(void) printk("Press \"%s\" to toggle the echo effect\n", sw0_spec.port->name); #endif -#if DT_NODE_HAS_STATUS_OKAY(SW1_NODE) +#ifdef CONFIG_STOP_START_STREAMS_SW1 static struct gpio_callback sw1_cb_data; if (!gpio_is_ready_dt(&sw1_spec)) {