Zephyr API Documentation  3.6.0
A Scalable Open Source RTOS
3.6.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
led.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Linaro Limited
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_DRIVERS_LED_H_
13#define ZEPHYR_INCLUDE_DRIVERS_LED_H_
14
22#include <errno.h>
23
24#include <zephyr/types.h>
25#include <zephyr/device.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
36struct led_info {
38 const char *label;
45};
46
53typedef int (*led_api_blink)(const struct device *dev, uint32_t led,
54 uint32_t delay_on, uint32_t delay_off);
55
62typedef int (*led_api_get_info)(const struct device *dev, uint32_t led,
63 const struct led_info **info);
64
71typedef int (*led_api_set_brightness)(const struct device *dev, uint32_t led,
72 uint8_t value);
79typedef int (*led_api_set_color)(const struct device *dev, uint32_t led,
80 uint8_t num_colors, const uint8_t *color);
81
88typedef int (*led_api_on)(const struct device *dev, uint32_t led);
89
96typedef int (*led_api_off)(const struct device *dev, uint32_t led);
97
104typedef int (*led_api_write_channels)(const struct device *dev,
105 uint32_t start_channel,
106 uint32_t num_channels,
107 const uint8_t *buf);
108
112__subsystem struct led_driver_api {
113 /* Mandatory callbacks. */
116 /* Optional callbacks. */
122};
123
136__syscall int led_blink(const struct device *dev, uint32_t led,
137 uint32_t delay_on, uint32_t delay_off);
138
139static inline int z_impl_led_blink(const struct device *dev, uint32_t led,
140 uint32_t delay_on, uint32_t delay_off)
141{
142 const struct led_driver_api *api =
143 (const struct led_driver_api *)dev->api;
144
145 if (api->blink == NULL) {
146 return -ENOSYS;
147 }
148 return api->blink(dev, led, delay_on, delay_off);
149}
150
161__syscall int led_get_info(const struct device *dev, uint32_t led,
162 const struct led_info **info);
163
164static inline int z_impl_led_get_info(const struct device *dev, uint32_t led,
165 const struct led_info **info)
166{
167 const struct led_driver_api *api =
168 (const struct led_driver_api *)dev->api;
169
170 if (api->get_info == NULL) {
171 *info = NULL;
172 return -ENOSYS;
173 }
174 return api->get_info(dev, led, info);
175}
176
192__syscall int led_set_brightness(const struct device *dev, uint32_t led,
193 uint8_t value);
194
195static inline int z_impl_led_set_brightness(const struct device *dev,
196 uint32_t led,
197 uint8_t value)
198{
199 const struct led_driver_api *api =
200 (const struct led_driver_api *)dev->api;
201
202 if (api->set_brightness == NULL) {
203 return -ENOSYS;
204 }
205 return api->set_brightness(dev, led, value);
206}
207
224__syscall int led_write_channels(const struct device *dev,
225 uint32_t start_channel,
226 uint32_t num_channels, const uint8_t *buf);
227
228static inline int
229z_impl_led_write_channels(const struct device *dev, uint32_t start_channel,
230 uint32_t num_channels, const uint8_t *buf)
231{
232 const struct led_driver_api *api =
233 (const struct led_driver_api *)dev->api;
234
235 if (api->write_channels == NULL) {
236 return -ENOSYS;
237 }
238 return api->write_channels(dev, start_channel, num_channels, buf);
239}
240
253__syscall int led_set_channel(const struct device *dev,
254 uint32_t channel, uint8_t value);
255
256static inline int z_impl_led_set_channel(const struct device *dev,
257 uint32_t channel, uint8_t value)
258{
259 return z_impl_led_write_channels(dev, channel, 1, &value);
260}
261
278__syscall int led_set_color(const struct device *dev, uint32_t led,
279 uint8_t num_colors, const uint8_t *color);
280
281static inline int z_impl_led_set_color(const struct device *dev, uint32_t led,
282 uint8_t num_colors, const uint8_t *color)
283{
284 const struct led_driver_api *api =
285 (const struct led_driver_api *)dev->api;
286
287 if (api->set_color == NULL) {
288 return -ENOSYS;
289 }
290 return api->set_color(dev, led, num_colors, color);
291}
292
302__syscall int led_on(const struct device *dev, uint32_t led);
303
304static inline int z_impl_led_on(const struct device *dev, uint32_t led)
305{
306 const struct led_driver_api *api =
307 (const struct led_driver_api *)dev->api;
308
309 return api->on(dev, led);
310}
311
321__syscall int led_off(const struct device *dev, uint32_t led);
322
323static inline int z_impl_led_off(const struct device *dev, uint32_t led)
324{
325 const struct led_driver_api *api =
326 (const struct led_driver_api *)dev->api;
327
328 return api->off(dev, led);
329}
330
335#ifdef __cplusplus
336}
337#endif
338
339#include <syscalls/led.h>
340
341#endif /* ZEPHYR_INCLUDE_DRIVERS_LED_H_ */
System error numbers.
int(* led_api_set_color)(const struct device *dev, uint32_t led, uint8_t num_colors, const uint8_t *color)
Optional API callback to set the colors of a LED.
Definition: led.h:79
int(* led_api_off)(const struct device *dev, uint32_t led)
Callback API for turning off an LED.
Definition: led.h:96
int led_off(const struct device *dev, uint32_t led)
Turn off an LED.
int led_write_channels(const struct device *dev, uint32_t start_channel, uint32_t num_channels, const uint8_t *buf)
Write/update a strip of LED channels.
int(* led_api_blink)(const struct device *dev, uint32_t led, uint32_t delay_on, uint32_t delay_off)
Callback API for blinking an LED.
Definition: led.h:53
int led_blink(const struct device *dev, uint32_t led, uint32_t delay_on, uint32_t delay_off)
Blink an LED.
int led_set_channel(const struct device *dev, uint32_t channel, uint8_t value)
Set a single LED channel.
int(* led_api_get_info)(const struct device *dev, uint32_t led, const struct led_info **info)
Optional API callback to get LED information.
Definition: led.h:62
int led_set_color(const struct device *dev, uint32_t led, uint8_t num_colors, const uint8_t *color)
Set LED color.
int led_get_info(const struct device *dev, uint32_t led, const struct led_info **info)
Get LED information.
int(* led_api_on)(const struct device *dev, uint32_t led)
Callback API for turning on an LED.
Definition: led.h:88
int(* led_api_set_brightness)(const struct device *dev, uint32_t led, uint8_t value)
Callback API for setting brightness of an LED.
Definition: led.h:71
int(* led_api_write_channels)(const struct device *dev, uint32_t start_channel, uint32_t num_channels, const uint8_t *buf)
Callback API for writing a strip of LED channels.
Definition: led.h:104
int led_set_brightness(const struct device *dev, uint32_t led, uint8_t value)
Set LED brightness.
int led_on(const struct device *dev, uint32_t led)
Turn on an LED.
#define ENOSYS
Function not implemented.
Definition: errno.h:83
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition: device.h:387
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:393
LED driver API.
Definition: led.h:112
led_api_off off
Definition: led.h:115
led_api_set_color set_color
Definition: led.h:120
led_api_get_info get_info
Definition: led.h:118
led_api_set_brightness set_brightness
Definition: led.h:119
led_api_on on
Definition: led.h:114
led_api_write_channels write_channels
Definition: led.h:121
led_api_blink blink
Definition: led.h:117
LED information structure.
Definition: led.h:36
const char * label
LED label.
Definition: led.h:38
uint32_t index
Number of colors per LED.
Definition: led.h:40
const uint8_t * color_mapping
Mapping of the LED colors.
Definition: led.h:44
uint8_t num_colors
Index of the LED on the controller.
Definition: led.h:42