Commit | Line | Data |
---|---|---|
0a40654b YL |
1 | /* |
2 | * light weight WS2812 lib include | |
3 | * | |
4 | * Version 2.3 - Nev 29th 2015 | |
5 | * Author: Tim (cpldcpu@gmail.com) | |
6 | * | |
7 | * Please do not change this file! All configuration is handled in "ws2812_config.h" | |
8 | * | |
9 | * License: GNU GPL v2 (see License.txt) | |
10 | + | |
11 | */ | |
12 | ||
13 | #ifndef LIGHT_WS2812_H_ | |
14 | #define LIGHT_WS2812_H_ | |
15 | ||
16 | #include <avr/io.h> | |
17 | #include <avr/interrupt.h> | |
18 | //#include "ws2812_config.h" | |
664c0a03 | 19 | //#include "i2cmaster.h" |
5f91fb41 JH |
20 | |
21 | #define LIGHT_I2C 1 | |
22 | #define LIGHT_I2C_ADDR 0x84 | |
23 | #define LIGHT_I2C_ADDR_WRITE ( (LIGHT_I2C_ADDR<<1) | I2C_WRITE ) | |
24 | #define LIGHT_I2C_ADDR_READ ( (LIGHT_I2C_ADDR<<1) | I2C_READ ) | |
25 | ||
e9f74875 JH |
26 | #define RGBW 1 |
27 | ||
28 | #ifdef RGBW | |
29 | #define LED_TYPE struct cRGBW | |
30 | #else | |
31 | #define LED_TYPE struct cRGB | |
32 | #endif | |
33 | ||
0a40654b YL |
34 | |
35 | /* | |
36 | * Structure of the LED array | |
37 | * | |
38 | * cRGB: RGB for WS2812S/B/C/D, SK6812, SK6812Mini, SK6812WWA, APA104, APA106 | |
39 | * cRGBW: RGBW for SK6812RGBW | |
40 | */ | |
41 | ||
42 | struct cRGB { uint8_t g; uint8_t r; uint8_t b; }; | |
43 | struct cRGBW { uint8_t g; uint8_t r; uint8_t b; uint8_t w;}; | |
44 | ||
45 | ||
46 | ||
47 | /* User Interface | |
48 | * | |
49 | * Input: | |
50 | * ledarray: An array of GRB data describing the LED colors | |
51 | * number_of_leds: The number of LEDs to write | |
52 | * pinmask (optional): Bitmask describing the output bin. e.g. _BV(PB0) | |
53 | * | |
54 | * The functions will perform the following actions: | |
55 | * - Set the data-out pin as output | |
56 | * - Send out the LED data | |
57 | * - Wait 50�s to reset the LEDs | |
58 | */ | |
59 | ||
e9f74875 JH |
60 | void ws2812_setleds (LED_TYPE *ledarray, uint16_t number_of_leds); |
61 | void ws2812_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask); | |
62 | void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds); | |
0a40654b YL |
63 | |
64 | /* | |
65 | * Old interface / Internal functions | |
66 | * | |
67 | * The functions take a byte-array and send to the data output as WS2812 bitstream. | |
68 | * The length is the number of bytes to send - three per LED. | |
69 | */ | |
70 | ||
71 | void ws2812_sendarray (uint8_t *array,uint16_t length); | |
72 | void ws2812_sendarray_mask(uint8_t *array,uint16_t length, uint8_t pinmask); | |
73 | ||
74 | ||
75 | /* | |
76 | * Internal defines | |
77 | */ | |
78 | #ifndef CONCAT | |
79 | #define CONCAT(a, b) a ## b | |
80 | #endif | |
81 | #ifndef CONCAT_EXP | |
82 | #define CONCAT_EXP(a, b) CONCAT(a, b) | |
83 | #endif | |
84 | ||
85 | // #define ws2812_PORTREG CONCAT_EXP(PORT,ws2812_port) | |
86 | // #define ws2812_DDRREG CONCAT_EXP(DDR,ws2812_port) | |
87 | ||
88 | #endif /* LIGHT_WS2812_H_ */ |