Tiny-WS2812  1.0.0
A tiny cross-platform WS2812 LED Strip driver
ws2812_common.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Patrick Pedersen
3 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13 
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  *
17  */
18 
29 #include <stdio.h>
30 #include <string.h>
31 
32 #include <ws2812.h>
33 
34 // RGB maps
35 const static uint8_t ws2812_order_rgb[3] = { 0, 1, 2 };
36 const static uint8_t ws2812_order_rbg[3] = { 0, 2, 1 };
37 const static uint8_t ws2812_order_brg[3] = { 2, 0, 1 };
38 const static uint8_t ws2812_order_bgr[3] = { 2, 1, 0 };
39 const static uint8_t ws2812_order_grb[3] = { 1, 0, 2 };
40 const static uint8_t ws2812_order_gbr[3] = { 1, 2, 0 };
41 
42 // Refer to header for documentation
43 void _ws2812_get_rgbmap(uint8_t (*rgbmap)[3], ws2812_order order)
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 }
Exposes the Tiny-WS2812 library interface.
void _ws2812_get_rgbmap(uint8_t(*rgbmap)[3], ws2812_order order)
Initializes a rgb map for a given color order.
Definition: ws2812_common.c:43
ws2812_order
Enum to specify the WS2812 device's color order.
Definition: ws2812_common.h:44