Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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 <zephyr/types.h>
23#include <device.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
39struct led_info {
40 const char *label;
44};
45
52typedef int (*led_api_blink)(const struct device *dev, uint32_t led,
53 uint32_t delay_on, uint32_t delay_off);
54
61typedef int (*led_api_get_info)(const struct device *dev, uint32_t led,
62 const struct led_info **info);
63
70typedef int (*led_api_set_brightness)(const struct device *dev, uint32_t led,
71 uint8_t value);
78typedef int (*led_api_set_color)(const struct device *dev, uint32_t led,
79 uint8_t num_colors, const uint8_t *color);
80
87typedef int (*led_api_on)(const struct device *dev, uint32_t led);
88
95typedef int (*led_api_off)(const struct device *dev, uint32_t led);
96
103typedef int (*led_api_write_channels)(const struct device *dev,
104 uint32_t start_channel,
105 uint32_t num_channels,
106 const uint8_t *buf);
107
111__subsystem struct led_driver_api {
112 /* Mandatory callbacks. */
115 /* Optional callbacks. */
121};
122
135__syscall int led_blink(const struct device *dev, uint32_t led,
136 uint32_t delay_on, uint32_t delay_off);
137
138static inline int z_impl_led_blink(const struct device *dev, uint32_t led,
139 uint32_t delay_on, uint32_t delay_off)
140{
141 const struct led_driver_api *api =
142 (const struct led_driver_api *)dev->api;
143
144 if (api->blink == NULL) {
145 return -ENOSYS;
146 }
147 return api->blink(dev, led, delay_on, delay_off);
148}
149
160__syscall int led_get_info(const struct device *dev, uint32_t led,
161 const struct led_info **info);
162
163static inline int z_impl_led_get_info(const struct device *dev, uint32_t led,
164 const struct led_info **info)
165{
166 const struct led_driver_api *api =
167 (const struct led_driver_api *)dev->api;
168
169 if (api->get_info == NULL) {
170 *info = NULL;
171 return -ENOSYS;
172 }
173 return api->get_info(dev, led, info);
174}
175
191__syscall int led_set_brightness(const struct device *dev, uint32_t led,
192 uint8_t value);
193
194static inline int z_impl_led_set_brightness(const struct device *dev,
195 uint32_t led,
196 uint8_t value)
197{
198 const struct led_driver_api *api =
199 (const struct led_driver_api *)dev->api;
200
201 if (api->set_brightness == NULL) {
202 return -ENOSYS;
203 }
204 return api->set_brightness(dev, led, value);
205}
206
223__syscall int led_write_channels(const struct device *dev,
224 uint32_t start_channel,
225 uint32_t num_channels, const uint8_t *buf);
226
227static inline int
228z_impl_led_write_channels(const struct device *dev, uint32_t start_channel,
229 uint32_t num_channels, const uint8_t *buf)
230{
231 const struct led_driver_api *api =
232 (const struct led_driver_api *)dev->api;
233
234 if (api->write_channels == NULL) {
235 return -ENOSYS;
236 }
237 return api->write_channels(dev, start_channel, num_channels, buf);
238}
239
252__syscall int led_set_channel(const struct device *dev,
253 uint32_t channel, uint8_t value);
254
255static inline int z_impl_led_set_channel(const struct device *dev,
256 uint32_t channel, uint8_t value)
257{
258 return z_impl_led_write_channels(dev, channel, 1, &value);
259}
260
277__syscall int led_set_color(const struct device *dev, uint32_t led,
278 uint8_t num_colors, const uint8_t *color);
279
280static inline int z_impl_led_set_color(const struct device *dev, uint32_t led,
281 uint8_t num_colors, const uint8_t *color)
282{
283 const struct led_driver_api *api =
284 (const struct led_driver_api *)dev->api;
285
286 if (api->set_color == NULL) {
287 return -ENOSYS;
288 }
289 return api->set_color(dev, led, num_colors, color);
290}
291
301__syscall int led_on(const struct device *dev, uint32_t led);
302
303static inline int z_impl_led_on(const struct device *dev, uint32_t led)
304{
305 const struct led_driver_api *api =
306 (const struct led_driver_api *)dev->api;
307
308 return api->on(dev, led);
309}
310
320__syscall int led_off(const struct device *dev, uint32_t led);
321
322static inline int z_impl_led_off(const struct device *dev, uint32_t led)
323{
324 const struct led_driver_api *api =
325 (const struct led_driver_api *)dev->api;
326
327 return api->off(dev, led);
328}
329
334#ifdef __cplusplus
335}
336#endif
337
338#include <syscalls/led.h>
339
340#endif /* ZEPHYR_INCLUDE_DRIVERS_LED_H_ */
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:78
int(* led_api_off)(const struct device *dev, uint32_t led)
Callback API for turning off an LED.
Definition: led.h:95
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:52
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:61
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:87
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:70
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:103
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
Definition: errno.h:83
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
LED driver API.
Definition: led.h:111
led_api_off off
Definition: led.h:114
led_api_set_color set_color
Definition: led.h:119
led_api_get_info get_info
Definition: led.h:117
led_api_set_brightness set_brightness
Definition: led.h:118
led_api_on on
Definition: led.h:113
led_api_write_channels write_channels
Definition: led.h:120
led_api_blink blink
Definition: led.h:116
LED information structure.
Definition: led.h:39
const char * label
Definition: led.h:40
uint32_t index
Definition: led.h:41
const uint8_t * color_mapping
Definition: led.h:43
uint8_t num_colors
Definition: led.h:42