Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.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
41struct led_info {
42 const char *label;
46};
47
54typedef int (*led_api_blink)(const struct device *dev, uint32_t led,
55 uint32_t delay_on, uint32_t delay_off);
56
63typedef int (*led_api_get_info)(const struct device *dev, uint32_t led,
64 const struct led_info **info);
65
72typedef int (*led_api_set_brightness)(const struct device *dev, uint32_t led,
73 uint8_t value);
80typedef int (*led_api_set_color)(const struct device *dev, uint32_t led,
81 uint8_t num_colors, const uint8_t *color);
82
89typedef int (*led_api_on)(const struct device *dev, uint32_t led);
90
97typedef int (*led_api_off)(const struct device *dev, uint32_t led);
98
105typedef int (*led_api_write_channels)(const struct device *dev,
106 uint32_t start_channel,
107 uint32_t num_channels,
108 const uint8_t *buf);
109
113__subsystem struct led_driver_api {
114 /* Mandatory callbacks. */
117 /* Optional callbacks. */
123};
124
137__syscall int led_blink(const struct device *dev, uint32_t led,
138 uint32_t delay_on, uint32_t delay_off);
139
140static inline int z_impl_led_blink(const struct device *dev, uint32_t led,
141 uint32_t delay_on, uint32_t delay_off)
142{
143 const struct led_driver_api *api =
144 (const struct led_driver_api *)dev->api;
145
146 if (api->blink == NULL) {
147 return -ENOSYS;
148 }
149 return api->blink(dev, led, delay_on, delay_off);
150}
151
162__syscall int led_get_info(const struct device *dev, uint32_t led,
163 const struct led_info **info);
164
165static inline int z_impl_led_get_info(const struct device *dev, uint32_t led,
166 const struct led_info **info)
167{
168 const struct led_driver_api *api =
169 (const struct led_driver_api *)dev->api;
170
171 if (api->get_info == NULL) {
172 *info = NULL;
173 return -ENOSYS;
174 }
175 return api->get_info(dev, led, info);
176}
177
193__syscall int led_set_brightness(const struct device *dev, uint32_t led,
194 uint8_t value);
195
196static inline int z_impl_led_set_brightness(const struct device *dev,
197 uint32_t led,
198 uint8_t value)
199{
200 const struct led_driver_api *api =
201 (const struct led_driver_api *)dev->api;
202
203 if (api->set_brightness == NULL) {
204 return -ENOSYS;
205 }
206 return api->set_brightness(dev, led, value);
207}
208
225__syscall int led_write_channels(const struct device *dev,
226 uint32_t start_channel,
227 uint32_t num_channels, const uint8_t *buf);
228
229static inline int
230z_impl_led_write_channels(const struct device *dev, uint32_t start_channel,
231 uint32_t num_channels, const uint8_t *buf)
232{
233 const struct led_driver_api *api =
234 (const struct led_driver_api *)dev->api;
235
236 if (api->write_channels == NULL) {
237 return -ENOSYS;
238 }
239 return api->write_channels(dev, start_channel, num_channels, buf);
240}
241
254__syscall int led_set_channel(const struct device *dev,
255 uint32_t channel, uint8_t value);
256
257static inline int z_impl_led_set_channel(const struct device *dev,
258 uint32_t channel, uint8_t value)
259{
260 return z_impl_led_write_channels(dev, channel, 1, &value);
261}
262
279__syscall int led_set_color(const struct device *dev, uint32_t led,
280 uint8_t num_colors, const uint8_t *color);
281
282static inline int z_impl_led_set_color(const struct device *dev, uint32_t led,
283 uint8_t num_colors, const uint8_t *color)
284{
285 const struct led_driver_api *api =
286 (const struct led_driver_api *)dev->api;
287
288 if (api->set_color == NULL) {
289 return -ENOSYS;
290 }
291 return api->set_color(dev, led, num_colors, color);
292}
293
303__syscall int led_on(const struct device *dev, uint32_t led);
304
305static inline int z_impl_led_on(const struct device *dev, uint32_t led)
306{
307 const struct led_driver_api *api =
308 (const struct led_driver_api *)dev->api;
309
310 return api->on(dev, led);
311}
312
322__syscall int led_off(const struct device *dev, uint32_t led);
323
324static inline int z_impl_led_off(const struct device *dev, uint32_t led)
325{
326 const struct led_driver_api *api =
327 (const struct led_driver_api *)dev->api;
328
329 return api->off(dev, led);
330}
331
336#ifdef __cplusplus
337}
338#endif
339
340#include <syscalls/led.h>
341
342#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:80
int(* led_api_off)(const struct device *dev, uint32_t led)
Callback API for turning off an LED.
Definition: led.h:97
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:54
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:63
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:89
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:72
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:105
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:381
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:387
LED driver API.
Definition: led.h:113
led_api_off off
Definition: led.h:116
led_api_set_color set_color
Definition: led.h:121
led_api_get_info get_info
Definition: led.h:119
led_api_set_brightness set_brightness
Definition: led.h:120
led_api_on on
Definition: led.h:115
led_api_write_channels write_channels
Definition: led.h:122
led_api_blink blink
Definition: led.h:118
LED information structure.
Definition: led.h:41
const char * label
Definition: led.h:42
uint32_t index
Definition: led.h:43
const uint8_t * color_mapping
Definition: led.h:45
uint8_t num_colors
Definition: led.h:44