1 /*
2  * Copyright (c) 2023 Phytec Messtechnik GmbH
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/device.h>
8 #include <zephyr/drivers/led.h>
9 #include <zephyr/kernel.h>
10 
11 #include <zephyr/logging/log.h>
12 LOG_MODULE_REGISTER(app, CONFIG_LED_LOG_LEVEL);
13 
14 #define NUM_LEDS 9
15 #define DELAY_TIME_ON		K_MSEC(1000)
16 #define DELAY_TIME_BREATHING	K_MSEC(20)
17 
main(void)18 int main(void)
19 {
20 	const struct device *const led_dev = DEVICE_DT_GET_ANY(ti_lp5569);
21 	int i, ret;
22 
23 	if (!led_dev) {
24 		LOG_ERR("No device with compatible ti,lp5569 found");
25 		return 0;
26 	} else if (!device_is_ready(led_dev)) {
27 		LOG_ERR("LED device %s not ready", led_dev->name);
28 		return 0;
29 	}
30 
31 	LOG_INF("Found LED device %s", led_dev->name);
32 
33 	/*
34 	 * Display a continuous pattern that turns on 9 LEDs at 1 s one by
35 	 * one until it reaches the end and turns off LEDs in reverse order.
36 	 */
37 
38 	LOG_INF("Testing 9 LEDs ..");
39 
40 	while (1) {
41 		/* Turn on LEDs one by one */
42 		for (i = 0; i < NUM_LEDS; i++) {
43 			ret = led_on(led_dev, i);
44 			if (ret) {
45 				return ret;
46 			}
47 
48 			k_sleep(DELAY_TIME_ON);
49 		}
50 
51 		/* Turn all LEDs off slowly to demonstrate set_brightness */
52 		for (i = 0; i <= 100; i++) {
53 			for (int j = 0; j < NUM_LEDS; j++) {
54 				ret = led_set_brightness(led_dev, j, 100 - i);
55 				if (ret) {
56 					return ret;
57 				}
58 			}
59 
60 			k_sleep(DELAY_TIME_BREATHING);
61 		}
62 	}
63 	return 0;
64 }
65