1 /*
2  * Copyright (c) 2021 Linaro Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <zephyr/devicetree.h>
10 #include <zephyr/drivers/gpio.h>
11 #include <zephyr/sys/printk.h>
12 
13 /* define SLEEP_TIME_MS higher than <st,counter-value> in ms */
14 #if DT_PROP(DT_NODELABEL(stm32_lp_tick_source), st_counter_value)
15 #define SLEEP_TIME_MS   (DT_PROP(DT_NODELABEL(stm32_lp_tick_source), st_counter_value) * 1400)
16 #else
17 #define SLEEP_TIME_MS   2000
18 #endif
19 
20 static const struct gpio_dt_spec led =
21 	GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
22 
main(void)23 int main(void)
24 {
25 	bool led_is_on = true;
26 
27 	__ASSERT_NO_MSG(gpio_is_ready_dt(&led));
28 
29 	printk("Device ready\n");
30 
31 	while (true) {
32 		gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
33 		gpio_pin_set(led.port, led.pin, (int)led_is_on);
34 		if (led_is_on == false) {
35 			/* Release resource to release device clock */
36 			gpio_pin_configure(led.port, led.pin, GPIO_DISCONNECTED);
37 		}
38 		k_msleep(SLEEP_TIME_MS);
39 		if (led_is_on == true) {
40 			/* Release resource to release device clock */
41 			gpio_pin_configure(led.port, led.pin, GPIO_DISCONNECTED);
42 		}
43 		led_is_on = !led_is_on;
44 	}
45 	return 0;
46 }
47