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 <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
cf4fb7a560
commit
17ce2a19e4
2 changed files with 18 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue