|
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
7 | | -#include <zephyr.h> |
8 | | -#include <device.h> |
9 | | -#include <devicetree.h> |
10 | | -#include <drivers/gpio.h> |
| 7 | +#include <zephyr/kernel.h> |
| 8 | +#include <zephyr/drivers/gpio.h> |
11 | 9 |
|
12 | 10 | /* 1000 msec = 1 sec */ |
13 | | -#define SLEEP_TIME_MS 1000 |
| 11 | +#define SLEEP_TIME_MS 300 |
14 | 12 |
|
15 | 13 | /* The devicetree node identifier for the "led0" alias. */ |
16 | 14 | #define LED0_NODE DT_ALIAS(led0) |
17 | 15 |
|
18 | | -#if DT_NODE_HAS_STATUS(LED0_NODE, okay) |
19 | | -#define LED0 DT_GPIO_LABEL(LED0_NODE, gpios) |
20 | | -#define PIN DT_GPIO_PIN(LED0_NODE, gpios) |
21 | | -#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios) |
22 | | -#else |
23 | | -/* A build error here means your board isn't set up to blink an LED. */ |
24 | | -#error "Unsupported board: led0 devicetree alias is not defined" |
25 | | -#define LED0 "" |
26 | | -#define PIN 0 |
27 | | -#define FLAGS 0 |
28 | | -#endif |
| 16 | +/* |
| 17 | + * A build error on this line means your board is unsupported. |
| 18 | + * See the sample documentation for information on how to fix this. |
| 19 | + */ |
| 20 | +static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); |
29 | 21 |
|
30 | 22 | void main(void) |
31 | 23 | { |
32 | | - const struct device *dev; |
33 | | - bool led_is_on = true; |
34 | 24 | int ret; |
35 | 25 |
|
36 | | - dev = device_get_binding(LED0); |
37 | | - if (dev == NULL) { |
| 26 | + if (!gpio_is_ready_dt(&led)) |
| 27 | + { |
38 | 28 | return; |
39 | 29 | } |
40 | 30 |
|
41 | | - ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS); |
42 | | - if (ret < 0) { |
| 31 | + ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); |
| 32 | + if (ret < 0) |
| 33 | + { |
43 | 34 | return; |
44 | 35 | } |
45 | 36 |
|
46 | | - while (1) { |
47 | | - gpio_pin_set(dev, PIN, (int)led_is_on); |
48 | | - led_is_on = !led_is_on; |
| 37 | + while (1) |
| 38 | + { |
| 39 | + ret = gpio_pin_toggle_dt(&led); |
| 40 | + if (ret < 0) |
| 41 | + { |
| 42 | + return; |
| 43 | + } |
49 | 44 | k_msleep(SLEEP_TIME_MS); |
50 | 45 | } |
51 | 46 | } |
0 commit comments