Tiny-WS2812  1.0.0
A tiny cross-platform WS2812 LED Strip driver
Classes | Typedefs | Enumerations | Functions
ws2812_common.h File Reference

Definitions required by all platform specific headers. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ws2812_rgb
 Data structure to hold RGB color values. More...
 

Typedefs

typedef struct ws2812_rgb ws2812_rgb
 Data structure to hold RGB color values. More...
 

Enumerations

enum  ws2812_order {
  rgb , rbg , brg , bgr ,
  grb , gbr
}
 Enum to specify the WS2812 device's color order. More...
 

Functions

void _ws2812_get_rgbmap (uint8_t(*rgbmap)[3], ws2812_order order)
 Initializes a rgb map for a given color order. More...
 

Detailed Description

Definitions required by all platform specific headers.

Author
Patrick Pedersen
Date
2021-04-16

The following header features platform independent definitions, such as typedefs, enums and structs, that are used across all platorm specific headers.

Definition in file ws2812_common.h.

Typedef Documentation

◆ ws2812_rgb

typedef struct ws2812_rgb ws2812_rgb

Data structure to hold RGB color values.

The RGB struct holds the red, green and blue values to define colors. It is used by the ws2812_tx() function to set the color of one or more WS2812 LEDs.

Note
It should be noted that WS2812 LEDs typically suffer from poor color accuracy. As an example, the typical RGB value for orange (255,165,0) displays a color closer to yellow on my WS2812 strip.

Enumeration Type Documentation

◆ ws2812_order

Enum to specify the WS2812 device's color order.

Unfortunately there is no clear standard on sequential color order of WS2812 LEDs, some are intuitively programmed in RGB order, however, many, if not the majority, are programmed in GRB oder. As there is automatic way to identify the correct color order, it must be manually provided in the device configuration with this enum.

Definition at line 44 of file ws2812_common.h.

44  {
45  rgb,
46  rbg,
47  brg,
48  bgr,
49  grb,
50  gbr
51 } ws2812_order;
ws2812_order
Enum to specify the WS2812 device's color order.
Definition: ws2812_common.h:44

Function Documentation

◆ _ws2812_get_rgbmap()

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.

44 {
45  switch (order) {
46  case rbg:
47  memcpy(rgbmap, ws2812_order_rbg, 3);
48  break;
49  case brg:
50  memcpy(rgbmap, ws2812_order_brg, 3);
51  break;
52  case bgr:
53  memcpy(rgbmap, ws2812_order_bgr, 3);
54  break;
55  case grb:
56  memcpy(rgbmap, ws2812_order_grb, 3);
57  break;
58  case gbr:
59  memcpy(rgbmap, ws2812_order_gbr, 3);
60  break;
61  default: // rgb
62  memcpy(rgbmap, ws2812_order_rgb, 3);
63  break;
64  }
65 }