ws2812 Drivers

This driver allows control of any smart pixels that use the ws2812 protocol. It supports pixel chains that use normal RGB pixels or newer RGBW pixels.

The current driver does not support mixed RGB and RGBW pixels in a single chain.

The NuttX ws2812 driver is split into two parts:

  1. An “upper half”, generic driver that provides the common interface to application level code, and

  2. A “lower half”, platform-specific driver that implements the low-level formatting and output.

Files supporting ws2812 can be found in the following locations:

  • Interface Definition. The header file for the NuttX ws2812 driver reside at include/nuttx/leds/ws2812.h. This header file includes both the application level interface to the ws2812 driver as well as the interface between the “upper half” and “lower half” drivers. The ws2812 module uses a standard character driver framework.

  • “Upper Half” Driver. The generic, “upper half” ws2812 driver resides at drivers/leds/ws2812.c.

  • “Lower Half” Drivers. Platform-specific ws2812 drivers reside in arch/<architecture>/src/<hardware> directory for the specific processor <architecture> and for the specific <chip> ws2812 peripheral devices.

Configuration

Upper half configuration resides in Device Drivers ‣ LED support ‣ WS2812 LED driver . Some of the configuration options are described here - mostly for the purpose of helping with implementation of lower half drivers and board code.

Number of ws2812s connected

These LEDs are designed to be chained and this configuration option allows the user to specify how many LEDs are in the chain.

Do note though that this is only a suggestion for other code - for example for default board configuration. The value set here may be ignored by the lower half and it is not used by the upper half either. The upper half reads the LED count from nleds element of struct ws2812_dev_s

ws2812s have white LED

Some variants of these LEDs have a white component byte. Lower half can disable support for such devices if this configuration option is not set.

Add byte order transformation functions

According to datasheets, these LEDs expect RGB data in green-red-blue order on the wire. Data provided by the user space are formatted as 32bit pixels in RGB order (ie. 0x00RRGGBB.) The lower half driver therefore needs to reorder bytes received from the user space through the upper half to transmit them in the order the LED expects.

However, there are variants of these LEDs available on the market which expect the RGB data in red-green-blue order. This configuration option adds byte order transformation functions (currently one) to the upper half driver. If requested by struct ws2812_dev_s member byte_order_transformation, chosen transformation function is called on data received from user space before passing them to the lower half when writing. For reads, reverse transformation is applied.

Do note that choosing - and making use - of this option requires a buffer allocated by lower half for every driver instance that needs this feature.