Tiny-WS2812
1.0.0
A tiny cross-platform WS2812 LED Strip driver
|
Exposes the Tiny-WS2812 library interface. More...
#include "ws2812_avr.h"
#include "ws2812_stm8s.h"
#include <stddef.h>
#include <stdint.h>
#include "ws2812_common.h"
Go to the source code of this file.
Functions | |
void | _ws2812_get_rgbmap (uint8_t(*rgbmap)[3], ws2812_order order) |
Initializes a rgb map for a given color order. More... | |
uint8_t | ws2812_config (ws2812 *dev, ws2812_cfg *cfg) |
Configures a WS2812 device struct. More... | |
void | ws2812_prep_tx (ws2812 *dev) |
Prepares the host device for data transmission. More... | |
void | ws2812_tx (ws2812 *dev, ws2812_rgb *pxls, size_t n_pxls) |
Transmits RGB values to the provided WS2812 device. More... | |
void | ws2812_wait_rst (ws2812 *dev) |
Waits for the WS2812 device to reset. More... | |
void | ws2812_close_tx (ws2812 *dev) |
Closes a WS2812 transmission. More... | |
Exposes the Tiny-WS2812 library interface.
The Tiny-WS2812 library initially derives from the driver code of an open source WS2812 LED controller that I had worked on prior, and provides a nearly barebone interface to communicate with WS2812 LED devices.
The following platforms and frameworks are currently supported:
It has been developed out of the necessity to have an extremely light weight and flexible cross-platform library that can be further abstracted and used troughout my WS2812 projects, particullary on MCUs with severe memory constraints (ex. ATTiny chips), where one cannot just define an RGB array equivalent to the number of LEDs. This libraries purpose is NOT to provide fancy abstractions and functions for color correction, brightness settings, animations etc.
To summerize, this library is inteded to:
Definition in file ws2812.h.
void _ws2812_get_rgbmap | ( | uint8_t(*) | rgbmap[3], |
ws2812_order | order | ||
) |
Initializes a rgb map for a given color order.
The following function is intended only to be used for internal library code, hence the _ prefix. It fills a 3 element byte array with the necessary offsets to map/convert RGB values to a different color order. For example, setting the order to rgb
fills the rgb map with 0, 1, 2
and bgr
fill the rgb map with 2, 1, 0
, etc.
Definition at line 43 of file ws2812_common.c.
void ws2812_close_tx | ( | ws2812 * | dev | ) |
Closes a WS2812 transmission.
The following function should be called after ending data transmission with a WS2812 device. The exact closing procedure is platform specific but will typically involve restoring stashed registers to their previous states, re-enable interrupts, wait for the WS2812 to reset by calling ws2812_wait_rst(), and potentially alter fields of the provided WS2812 device struct.
Definition at line 275 of file ws2812_avr.c.
uint8_t ws2812_config | ( | ws2812 * | dev, |
ws2812_cfg * | cfg | ||
) |
Configures a WS2812 device struct.
The following function initializes/configures a WS2812 device struct using a ws2812_cfg configuration struct.
Definition at line 126 of file ws2812_avr.c.
void ws2812_prep_tx | ( | ws2812 * | dev | ) |
Prepares the host device for data transmission.
The following function prepares the host device for data transmission. The exact preperation procedure is platform specific, but typically will involve disabling interrupts, stashing registers that may be modified when communicating to the WS2812 device and potentially preparing the passed WS2812 device struct for data transmission. For a more detailed understanding, please refer to the platform specific code of this function.
Definition at line 159 of file ws2812_avr.c.
void ws2812_tx | ( | ws2812 * | dev, |
ws2812_rgb * | pxls, | ||
size_t | n_pxls | ||
) |
Transmits RGB values to the provided WS2812 device.
The following function transmits RGB values to the provided WS2812 device. Calling this function consecutively for the same device will continue programming LEDs after the position where the last transmission has ended. In other words, calling the function consecutively for the same device will NOT program the device from the first LED, but rather take off from where it last ended. If this is not desired, call ws2812_wait_rst() after each transmission.
Definition at line 264 of file ws2812_avr.c.
void ws2812_wait_rst | ( | ws2812 * | dev | ) |
Waits for the WS2812 device to reset.
The following function waits for the WS2812 device to reset, thus allowing it to be overwritten from the first LED again. The reset time is configuredin the ws2812_cfg object used to initialize/configure the passed WS2812 device struct, and is recommended to be 50us according to the WS2812 datasheet, but may be set significantly lower for some WS2812 devices. Call this function if you wish to overwritte the WS2812 device after a previous ws2812_tx() call.
Definition at line 168 of file ws2812_avr.c.