Yet Another WS2812/SK6812 Driver
Just uploaded to the ObEx: Yet Another WS2812/SK6812 driver
https://obex.parallax.com/obex/yet-another-ws2812-sk6812-driver/
This driver manages one or two strings of WS2812-like addressable RGB LEDs. It handles mapping the color layout in memory to the color output order of different type of LEDs; it handles mapping the timing requirements of the LEDs based on the system clock speed; it is fairly flexible in how it is configured and controlled.
Features:
- Controls one or two strings of LEDs
- Normal or inverted output (for use with an inverting buffer/isolator/level-shifter).
- Clock cycle accurate timings in all cases (maximum 1/2 system clock error).
- Handles either three or four color LED string (with limitations, see below).
Flexible configuration:
- Predefined configurations for:
- WS2811, WS2812, WS2812B, WS2813, WS2815
- SK6812RGB, SK6812RGBW
- SM16703
- User defined configurations:
- Should work for all LEDs that use pulse-width encoding of 0/1, with fixed time per bit.
- Timing specified in nanoseconds.
- The two strings can be different types (with a few limitations)
- The two strings can have different lengths
- The two strings can use different color byte order.
- The two strings can have normal/inverted output independently
- Flexible memory layout for colors per LED, and iteration over the memory locations for the individual LEDs in a chain.
Should work for all clock speeds from 48 MHz up for a typical RGB LED that uses a 1.25 us bit time.
- It might work at 40 MHz, which would use a bit time of 1.5 us, which is 20% too long, but might fall within the acceptable tolerance for many LED types.
Periodic refresh (e.g. 100 Hz), or on-demand refresh (refresh-and-pause)
Limitations:
- Typically requires a system clock of 48 MHz or higher.
- The two strings must have the same overall bit timing (but the zero and one times per bit may be different), e.g. 1.25 us as used by WS2812-type LEDs)
- The two strings must have the same number of colors, either 3 or 4. Four colors are used for RGBW LEDs.
- Color values of 8 bits are sent out high order bit first.
- The two strings use the same update frequency, because they are updated in parallel. The shorter string will not get "extra" channels of output.
For the most flexibility, the memory layout of the colors for each LED in the string should be in a single LONG. There is a demonstration of using three bytes for a string of RGB LEDs, but there is little
flexibility of layout, and the string myst be a multiple of 4 LEDs in length.Currently, the number and types of LEDs in the strings is fixed at initialization. That might change in the future.