Tiny-WS2812
1.0.0
A tiny cross-platform WS2812 LED Strip driver
|
Driver code for AVR chips. More...
#include <stdint.h>
#include <stdbool.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <util/delay.h>
#include <ws2812.h>
#include <Arduino.h>
Go to the source code of this file.
Functions | |
void | delay_us (uint8_t us) |
Halts the program for a given ammount of microseconds. 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_wait_rst (ws2812 *dev) |
Waits for the WS2812 device to reset. More... | |
void | ws2812_tx_byte (ws2812 *dev, uint8_t byte) |
Transmits a byte of data to the WS2812 device. More... | |
void | ws2812_tx (ws2812 *dev, ws2812_rgb *leds, size_t n_leds) |
Transmits RGB values to the provided WS2812 device. More... | |
void | ws2812_close_tx (ws2812 *dev) |
Closes a WS2812 transmission. More... | |
Driver code for AVR chips.
The following file holds the Tiny-WS2812 library code to drive WS2812 devices on AVR chips.
Definition in file ws2812_avr.c.
void delay_us | ( | uint8_t | us | ) |
Halts the program for a given ammount of microseconds.
The following function temporarily disables interrupts and pauses the program code for a provided ammount of microseconds (max 255).
Definition at line 116 of file ws2812_avr.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_tx_byte | ( | ws2812 * | dev, |
uint8_t | byte | ||
) |
Transmits a byte of data to the WS2812 device.
The following function transmits a single byte of data to the provided WS2812 device. It is primarily based on the driver code of cpldcpu's light_ws2812 library and achieves precisely timed communication with the WS2812 device through inline AVR assembly code.
Definition at line 192 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.