Tiny-WS2812  1.0.0
A tiny cross-platform WS2812 LED Strip driver
ws2812_avr.h
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 
28 #pragma once
29 
30 #include <stdint.h>
31 
32 #include "ws2812_common.h"
33 #include "ws2812.h"
34 
35 // General description necessary for Doxygen
36 
50 /*
51  * AVR: Data structure to configure a @ref ws2812 "WS2812 device struct" on AVR platforms.
52  *
53  * The following struct is used to initialize/configure a @ref ws2812 "WS2812 device struct"
54  * on AVR based devices. It is passed to the ws2812_config() function along
55  * with a reference to a @ref ws2812 "WS2812 device struct", and contains relevant
56  * information such as pins used to drive WS2812 devices, the device's reset time etc.,
57  * necessary for configuring the @ref ws2812 "WS2812 device struct" to drive one or multiple
58  * WS2812 devices on AVR based devices. The data structure varies for the Arduino AVR
59  * target and the barebone AVR target.
60  *
61  * WARNING: All fields of the configuration object must be defined before passing it to #ws2812_config()!
62  * Leaving a field undefined will result in undefined behaivor!
63  */
64 typedef struct ws2812_cfg {
65 
66 #ifdef WS2812_TARGET_PLATFORM_AVR
67  volatile uint8_t *port;
68  volatile uint8_t *ddr;
69  uint8_t *pins;
70 #endif
71 
72 #ifdef WS2812_TARGET_PLATFORM_ARDUINO_AVR
73  uint8_t *pins;
74 #endif
75 
76  uint8_t rst_time_us;
78  uint8_t n_dev;
79 
81 
82 // General description necessary for Doxygen
83 
96 /*
97  * STM8S: WS2812 device struct to drive one or more WS2812 devices on AVR based platforms.
98  *
99  * The following struct is used to drive one or more WS2812 devices on AVR based devices.
100  * It is initialized by the ws2812_config() function and is taken as an argument by practically
101  * every function of the TinyWS2812 library relevant to driving WS2812 devices (ex. ws2812_tx(),
102  * ws2812_prep_tx(), etc...).
103  *
104  * See ws2812_config()
105  *
106  */
107 typedef struct ws2812 {
108  volatile uint8_t *port;
109  uint8_t rst_time_us;
110  uint8_t maskhi;
111  uint8_t masklo;
112  uint8_t rgbmap[3];
ALL PLATFORMS: Data structure to configure a WS2812 device struct.
Definition: ws2812_avr.h:64
volatile uint8_t * ddr
Data Direction Register (ex. DDRB, DDRC, DDRD...)
Definition: ws2812_avr.h:68
uint8_t n_dev
Number of WS2812 device to drive.
Definition: ws2812_avr.h:78
volatile uint8_t * port
PORT Register (ex. PORTB, PORTC, PORTD...)
Definition: ws2812_avr.h:67
uint8_t rst_time_us
Time required for the WS2812 device(s) to reset in us.
Definition: ws2812_avr.h:76
ws2812_order order
CoColor order of the WS2812 device(s) (ex. rgb, grb, bgr...)
Definition: ws2812_avr.h:77
uint8_t * pins
Array of pins used to program WS2812 devices (Must share the same PORT! (ex. PB0, PB1,...
Definition: ws2812_avr.h:69
ALL PLATFORMS: WS2812 device struct to drive one or more WS2812 devices.
Definition: ws2812_avr.h:107
uint8_t rgbmap[3]
RGB map to map/convert RGB values to another color order.
Definition: ws2812_avr.h:112
uint8_t rst_time_us
Time required for WS2812 to reset in us.
Definition: ws2812_avr.h:109
uint8_t masklo
PORT masks to toggle the data pins low.
Definition: ws2812_avr.h:111
uint8_t maskhi
PORT masks to toggle the data pins high.
Definition: ws2812_avr.h:110
volatile uint8_t * port
PORT register of pins used to drive the WS2812 device(s)
Definition: ws2812_avr.h:108
Exposes the Tiny-WS2812 library interface.
struct ws2812 ws2812
ALL PLATFORMS: WS2812 device struct to drive one or more WS2812 devices.
struct ws2812_cfg ws2812_cfg
ALL PLATFORMS: Data structure to configure a WS2812 device struct.
Definitions required by all platform specific headers.
ws2812_order
Enum to specify the WS2812 device's color order.
Definition: ws2812_common.h:44