Zephyr API Documentation 4.4.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
led_strip.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Linaro Limited
3 * Copyright (c) 2024 Jamie McCrae
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
16
17#ifndef ZEPHYR_INCLUDE_DRIVERS_LED_STRIP_H_
18#define ZEPHYR_INCLUDE_DRIVERS_LED_STRIP_H_
19
31
32#include <errno.h>
33#include <zephyr/types.h>
34#include <zephyr/device.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
46struct led_rgb {
47#ifdef CONFIG_LED_STRIP_RGB_SCRATCH
48 /*
49 * Pad/scratch space needed by some drivers. Users should
50 * ignore.
51 */
52 uint8_t scratch;
53#endif
60};
61
66
72typedef int (*led_api_update_rgb)(const struct device *dev,
73 struct led_rgb *pixels,
74 size_t num_pixels);
75
81typedef int (*led_api_update_channels)(const struct device *dev,
82 uint8_t *channels,
83 size_t num_channels);
84
90typedef size_t (*led_api_length)(const struct device *dev);
91
109
112
125static inline int led_strip_update_rgb(const struct device *dev,
126 struct led_rgb *pixels,
127 size_t num_pixels)
128{
129 const struct led_strip_driver_api *api =
130 (const struct led_strip_driver_api *)dev->api;
131
132 /* Allow for out-of-tree drivers that do not have this function for 2 Zephyr releases
133 * until making it mandatory, function added after Zephyr 3.6
134 */
135 if (api->length != NULL) {
136 /* Ensure supplied pixel size is valid for this device */
137 if (api->length(dev) < num_pixels) {
138 return -ERANGE;
139 }
140 }
141
142 return api->update_rgb(dev, pixels, num_pixels);
143}
144
160static inline int led_strip_update_channels(const struct device *dev,
161 uint8_t *channels,
162 size_t num_channels)
163{
164 const struct led_strip_driver_api *api =
165 (const struct led_strip_driver_api *)dev->api;
166
167 if (api->update_channels == NULL) {
168 return -ENOSYS;
169 }
170
171 return api->update_channels(dev, channels, num_channels);
172}
173
181static inline size_t led_strip_length(const struct device *dev)
182{
183 const struct led_strip_driver_api *api =
184 (const struct led_strip_driver_api *)dev->api;
185
186 return api->length(dev);
187}
188
189#ifdef __cplusplus
190}
191#endif
192
196
197#endif /* ZEPHYR_INCLUDE_DRIVERS_LED_STRIP_H_ */
System error numbers.
size_t(* led_api_length)(const struct device *dev)
Callback API for getting length of an LED strip.
Definition led_strip.h:90
int(* led_api_update_rgb)(const struct device *dev, struct led_rgb *pixels, size_t num_pixels)
Callback API for updating an RGB LED strip.
Definition led_strip.h:72
int(* led_api_update_channels)(const struct device *dev, uint8_t *channels, size_t num_channels)
Callback API for updating channels without an RGB interpretation.
Definition led_strip.h:81
static int led_strip_update_rgb(const struct device *dev, struct led_rgb *pixels, size_t num_pixels)
Update an LED strip with the given RGB array.
Definition led_strip.h:125
static size_t led_strip_length(const struct device *dev)
Get chain length (in pixels) of an LED strip device.
Definition led_strip.h:181
static int led_strip_update_channels(const struct device *dev, uint8_t *channels, size_t num_channels)
Update an LED strip with the given channel array.
Definition led_strip.h:160
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define ERANGE
Result too large.
Definition errno.h:72
#define NULL
Definition iar_missing_defs.h:20
Size of off_t must be equal or less than size of size_t
Definition retained_mem.h:29
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
Color value for a single RGB LED.
Definition led_strip.h:46
uint8_t r
Red channel.
Definition led_strip.h:55
uint8_t g
Green channel.
Definition led_strip.h:57
uint8_t b
Blue channel.
Definition led_strip.h:59
<span class="mlabel">Driver Operations</span> LED Strip driver operations
Definition led_strip.h:95
led_api_length length
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition led_strip.h:103
led_api_update_channels update_channels
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition led_strip.h:107
led_api_update_rgb update_rgb
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition led_strip.h:99