samples: blinky: clean up error on unsupported board
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 <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
cf2d474adf
commit
748c7757ea
1 changed files with 16 additions and 6 deletions
|
@ -12,7 +12,19 @@
|
||||||
#define SLEEP_TIME_MS 1000
|
#define SLEEP_TIME_MS 1000
|
||||||
|
|
||||||
#ifndef DT_ALIAS_LED0_GPIOS_FLAGS
|
#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
|
#endif
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
|
@ -21,20 +33,18 @@ void main(void)
|
||||||
bool led_is_on = true;
|
bool led_is_on = true;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dev = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER);
|
dev = device_get_binding(LED0);
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gpio_pin_configure(dev, DT_ALIAS_LED0_GPIOS_PIN,
|
ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
|
||||||
GPIO_OUTPUT_ACTIVE
|
|
||||||
| DT_ALIAS_LED0_GPIOS_FLAGS);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
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;
|
led_is_on = !led_is_on;
|
||||||
k_sleep(SLEEP_TIME_MS);
|
k_sleep(SLEEP_TIME_MS);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue