From 748c7757eae38c70570036d5b363a89d7653ecb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 4 Mar 2020 10:40:05 -0800 Subject: [PATCH] samples: blinky: clean up error on unsupported board MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This sample requires led0 in the board devicetree's /aliases. Improve the error message when that is not available. Signed-off-by: Martí Bolívar --- samples/basic/blinky/src/main.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/samples/basic/blinky/src/main.c b/samples/basic/blinky/src/main.c index 94e3b876010..21f33309194 100644 --- a/samples/basic/blinky/src/main.c +++ b/samples/basic/blinky/src/main.c @@ -12,7 +12,19 @@ #define SLEEP_TIME_MS 1000 #ifndef DT_ALIAS_LED0_GPIOS_FLAGS -#define DT_ALIAS_LED0_GPIOS_FLAGS 0 +#define FLAGS 0 +#else +#define FLAGS DT_ALIAS_LED0_GPIOS_FLAGS +#endif + +/* Make sure the board's devicetree declares led0 in its /aliases. */ +#ifdef DT_ALIAS_LED0_GPIOS_CONTROLLER +#define LED0 DT_ALIAS_LED0_GPIOS_CONTROLLER +#define PIN DT_ALIAS_LED0_GPIOS_PIN +#else +#error "Unsupported board: led0 devicetree alias is not defined" +#define LED0 "" +#define PIN 0 #endif void main(void) @@ -21,20 +33,18 @@ void main(void) bool led_is_on = true; int ret; - dev = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER); + dev = device_get_binding(LED0); if (dev == NULL) { return; } - ret = gpio_pin_configure(dev, DT_ALIAS_LED0_GPIOS_PIN, - GPIO_OUTPUT_ACTIVE - | DT_ALIAS_LED0_GPIOS_FLAGS); + ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS); if (ret < 0) { return; } while (1) { - gpio_pin_set(dev, DT_ALIAS_LED0_GPIOS_PIN, (int)led_is_on); + gpio_pin_set(dev, PIN, (int)led_is_on); led_is_on = !led_is_on; k_sleep(SLEEP_TIME_MS); }