samples: bluetooth: periodic_sync: add option to control led0
Add a new option to control led0 behavior. If enabled, led0 will be used for blinking. This option also allows to select GPIO when needed. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
ecdb4ffaf1
commit
75154a6443
2 changed files with 13 additions and 8 deletions
|
|
@ -12,4 +12,10 @@ config PER_ADV_NAME
|
|||
help
|
||||
Name of target advertising for Periodic Advertising Synchronization.
|
||||
|
||||
config PER_BLINK_LED0
|
||||
bool "Blink led0"
|
||||
depends on $(dt_alias_enabled,led0)
|
||||
select GPIO
|
||||
default y
|
||||
|
||||
source "Kconfig.zephyr"
|
||||
|
|
|
|||
|
|
@ -27,8 +27,7 @@ static K_SEM_DEFINE(sem_per_sync_lost, 0, 1);
|
|||
/* The devicetree node identifier for the "led0" alias. */
|
||||
#define LED0_NODE DT_ALIAS(led0)
|
||||
|
||||
#if DT_NODE_HAS_STATUS_OKAY(LED0_NODE)
|
||||
#define HAS_LED 1
|
||||
#ifdef CONFIG_PER_BLINK_LED0
|
||||
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
|
||||
#define BLINK_ONOFF K_MSEC(500)
|
||||
|
||||
|
|
@ -186,7 +185,7 @@ int main(void)
|
|||
|
||||
printk("Starting Periodic Advertising Synchronization Demo\n");
|
||||
|
||||
#if defined(HAS_LED)
|
||||
#ifdef CONFIG_PER_BLINK_LED0
|
||||
printk("Checking LED device...");
|
||||
if (!gpio_is_ready_dt(&led)) {
|
||||
printk("failed.\n");
|
||||
|
|
@ -203,7 +202,7 @@ int main(void)
|
|||
printk("done.\n");
|
||||
|
||||
k_work_init_delayable(&blink_work, blink_timeout);
|
||||
#endif /* HAS_LED */
|
||||
#endif /* CONFIG_PER_BLINK_LED0 */
|
||||
|
||||
/* Initialize the Bluetooth Subsystem */
|
||||
err = bt_enable(NULL);
|
||||
|
|
@ -229,14 +228,14 @@ int main(void)
|
|||
printk("success.\n");
|
||||
|
||||
do {
|
||||
#if defined(HAS_LED)
|
||||
#ifdef CONFIG_PER_BLINK_LED0
|
||||
struct k_work_sync work_sync;
|
||||
|
||||
printk("Start blinking LED...\n");
|
||||
led_is_on = false;
|
||||
gpio_pin_set(led.port, led.pin, (int)led_is_on);
|
||||
k_work_schedule(&blink_work, BLINK_ONOFF);
|
||||
#endif /* HAS_LED */
|
||||
#endif /* CONFIG_PER_BLINK_LED0 */
|
||||
|
||||
printk("Waiting for periodic advertising...\n");
|
||||
per_adv_found = false;
|
||||
|
|
@ -275,14 +274,14 @@ int main(void)
|
|||
}
|
||||
printk("Periodic sync established.\n");
|
||||
|
||||
#if defined(HAS_LED)
|
||||
#ifdef CONFIG_PER_BLINK_LED0
|
||||
printk("Stop blinking LED.\n");
|
||||
k_work_cancel_delayable_sync(&blink_work, &work_sync);
|
||||
|
||||
/* Keep LED on */
|
||||
led_is_on = true;
|
||||
gpio_pin_set(led.port, led.pin, (int)led_is_on);
|
||||
#endif /* HAS_LED */
|
||||
#endif /* CONFIG_PER_BLINK_LED0 */
|
||||
|
||||
printk("Waiting for periodic sync lost...\n");
|
||||
err = k_sem_take(&sem_per_sync_lost, K_FOREVER);
|
||||
|
|
|
|||
Loading…
Reference in a new issue