16
16
#include <zephyr/device.h>
17
17
#include <zephyr/kernel.h>
18
18
19
+ #include "led_blink.h"
20
+
19
21
#include <zephyr/logging/log.h>
20
22
LOG_MODULE_REGISTER (led_gpio , CONFIG_LED_LOG_LEVEL );
21
23
@@ -24,9 +26,28 @@ struct led_gpio_config {
24
26
const struct gpio_dt_spec * led ;
25
27
};
26
28
27
- static int led_gpio_set_brightness (const struct device * dev , uint32_t led , uint8_t value )
29
+ struct led_gpio_data {
30
+ #ifdef CONFIG_LED_BLINK_SOFTWARE
31
+ struct led_blink_software_data * blink_data ;
32
+ #endif
33
+ };
34
+
35
+ #ifdef CONFIG_LED_BLINK_SOFTWARE
36
+ struct led_blink_software_data * led_gpio_blink_data (const struct device * dev , uint32_t led )
28
37
{
38
+ const struct led_gpio_config * config = dev -> config ;
39
+ struct led_gpio_data * data = dev -> data ;
40
+
41
+ if (led >= config -> num_leds ) {
42
+ return NULL ;
43
+ }
44
+
45
+ return & data -> blink_data [led ];
46
+ }
47
+ #endif
29
48
49
+ static int led_gpio_set_brightness (const struct device * dev , uint32_t led , uint8_t value )
50
+ {
30
51
const struct led_gpio_config * config = dev -> config ;
31
52
const struct gpio_dt_spec * led_gpio ;
32
53
@@ -69,6 +90,9 @@ static int led_gpio_init(const struct device *dev)
69
90
70
91
static DEVICE_API (led , led_gpio_api ) = {
71
92
.set_brightness = led_gpio_set_brightness ,
93
+ #ifdef CONFIG_LED_BLINK_SOFTWARE
94
+ .get_blink_data = led_gpio_blink_data ,
95
+ #endif
72
96
};
73
97
74
98
#define LED_GPIO_DEVICE (i ) \
@@ -78,12 +102,17 @@ static const struct gpio_dt_spec gpio_dt_spec_##i[] = { \
78
102
}; \
79
103
\
80
104
static const struct led_gpio_config led_gpio_config_##i = { \
81
- .num_leds = ARRAY_SIZE(gpio_dt_spec_##i), \
105
+ .num_leds = ARRAY_SIZE(gpio_dt_spec_##i), \
82
106
.led = gpio_dt_spec_##i, \
83
107
}; \
84
108
\
109
+ static struct led_gpio_data led_gpio_data_##i = { \
110
+ LED_BLINK_SOFTWARE_DATA(i, blink_data) \
111
+ }; \
112
+ \
85
113
DEVICE_DT_INST_DEFINE(i, &led_gpio_init, NULL, \
86
- NULL, &led_gpio_config_##i, \
114
+ (&led_gpio_data_##i), \
115
+ &led_gpio_config_##i, \
87
116
POST_KERNEL, CONFIG_LED_INIT_PRIORITY, \
88
117
&led_gpio_api);
89
118
0 commit comments