3.32. ws2812 — NeoPixels

Source code: src/drivers/ws2812.h, src/drivers/ws2812.c


Defines

WS2812_PIN_DEVICES_MAX 8

Functions

int ws2812_module_init(void)

Initialize the WS2812 driver module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int ws2812_init(struct ws2812_driver_t *self_p, struct pin_device_t **pin_devices_pp, int number_of_pin_devices)

Initialize given driver object from given configuration.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object to be initialized.
  • pin_devices_pp: An array of pin device(s) to use. The maximum length of the array is defined as WS2812_PIN_DEVICES_MAX.
  • number_of_pin_devices: Number of pin devices in the pin devices array.

int ws2812_write(struct ws2812_driver_t *self_p, const uint8_t *colors_p, int number_of_pixles)

Write given RGB colors to the NeoPixels.

CAUTION: Interrupts are disabled during the write to meet the strict timing requirements on the pulse train. It takes ~30 us to write to one pixel, that is, interrupts are disabled for ~30 * number_of_pixles us. Long pixel chains may cause the rest of the system to misbehave.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object.
  • colors_p: An array of GRB colors to write to the NeoPixels. All pin devices green component first, then all red, and last all blue, repeated for all NeoPixels. For example, when a single pin device is configured the array is G0, R0, B0, G1, R1, B1, ...
  • number_of_pixles: Number of GRB colors per pin device in colors_p.

struct ws2812_driver_t

Public Members

struct pin_device_t **pins_pp
int number_of_pins
uint32_t mask