1 /*
2  * Copyright (c) 2016 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdio.h>
8 #include <zephyr/kernel.h>
9 #include <zephyr/drivers/gpio.h>
10 
11 /* 1000 msec = 1 sec */
12 #define SLEEP_TIME_MS   1000
13 
14 /* The devicetree node identifier for the "led0" alias. */
15 #define LED0_NODE DT_ALIAS(led0)
16 
17 /*
18  * A build error on this line means your board is unsupported.
19  * See the sample documentation for information on how to fix this.
20  */
21 static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
22 
main(void)23 int main(void)
24 {
25 	int ret;
26 	bool led_state = true;
27 
28 	if (!gpio_is_ready_dt(&led)) {
29 		return 0;
30 	}
31 
32 	ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
33 	if (ret < 0) {
34 		return 0;
35 	}
36 
37 	while (1) {
38 		ret = gpio_pin_toggle_dt(&led);
39 		if (ret < 0) {
40 			return 0;
41 		}
42 
43 		led_state = !led_state;
44 		printf("LED state: %s\n", led_state ? "ON" : "OFF");
45 		k_msleep(SLEEP_TIME_MS);
46 	}
47 	return 0;
48 }
49