Loading...
Searching...
No Matches
ws281x.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Marian Buschsieweke
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
84
85#include <stdint.h>
86
87#include "color.h"
88#include "periph/gpio.h"
89#include "ws281x_backend.h"
90#include "ws281x_constants.h"
91
92#ifdef __cplusplus
93extern "C" {
94#endif
95
96#ifndef WS281X_BYTES_PER_DEVICE
100# define WS281X_BYTES_PER_DEVICE (3U)
101#endif
102
106#if WS281X_BYTES_PER_DEVICE == 4
108#else
110#endif
111
115typedef struct {
121 uint8_t *buf;
122 uint16_t numof;
123 gpio_t pin;
125
129typedef struct {
131} ws281x_t;
132
143int ws281x_init(ws281x_t *dev, const ws281x_params_t *params);
144
173void ws281x_write_buffer(ws281x_t *dev, const void *buf, size_t size);
174
181
191
202void ws281x_set_buffer(void *dest, uint16_t index, ws281x_pixel_t color);
203
214static inline void ws281x_set(ws281x_t *dev, uint16_t index, ws281x_pixel_t color)
215{
216 ws281x_set_buffer(dev->params.buf, index, color);
217}
218
227static inline void ws281x_write(ws281x_t *dev)
228{
231 (size_t)dev->params.numof * WS281X_BYTES_PER_DEVICE);
233}
234
235#ifdef __cplusplus
236}
237#endif
238
Headers for the color handling module.
Low-level GPIO peripheral driver interface definitions.
static void ws281x_write(ws281x_t *dev)
Writes the internal buffer to the LED chain.
Definition ws281x.h:227
void ws281x_set_buffer(void *dest, uint16_t index, ws281x_pixel_t color)
Sets the color of an LED in the given data buffer.
#define WS281X_BYTES_PER_DEVICE
The number of bytes to allocate in the data buffer per LED.
Definition ws281x.h:100
void ws281x_end_transmission(ws281x_t *dev)
Ends the transmission to the WS2812/SK6812 LED chain.
int ws281x_init(ws281x_t *dev, const ws281x_params_t *params)
Initialize an WS281x RGB LED chain.
color_rgb_t ws281x_pixel_t
Pixel type representing a single LED.
Definition ws281x.h:109
static void ws281x_set(ws281x_t *dev, uint16_t index, ws281x_pixel_t color)
Sets the color of an LED in the chain in the internal buffer.
Definition ws281x.h:214
void ws281x_prepare_transmission(ws281x_t *dev)
Sets up everything needed to write data to the WS281X LED chain.
void ws281x_write_buffer(ws281x_t *dev, const void *buf, size_t size)
Writes the color data of the user supplied buffer.
Data-structure describing an RGB color.
Definition color.h:34
Data-structure describing an RGBW color.
Definition color.h:43
Struct to hold initialization parameters for a WS281x RGB LED.
Definition ws281x.h:115
gpio_t pin
GPIO connected to the data pin of the first LED.
Definition ws281x.h:123
uint8_t * buf
A statically allocated data buffer storing the state of the LEDs.
Definition ws281x.h:121
uint16_t numof
Number of chained RGB LEDs.
Definition ws281x.h:122
Device descriptor of a WS281x RGB LED chain.
Definition ws281x.h:129
ws281x_params_t params
Parameters of the LED chain.
Definition ws281x.h:130
Backend configuration for WS2812/SK6812 RGB LEDs.
Constants for WS2812/SK6812 RGB LEDs.