diff options
| -rw-r--r-- | drivers/avr/ws2812.c | 33 | ||||
| -rw-r--r-- | drivers/avr/ws2812.h | 35 | ||||
| -rw-r--r-- | quantum/rgb_matrix_drivers.c | 22 |
3 files changed, 29 insertions, 61 deletions
diff --git a/drivers/avr/ws2812.c b/drivers/avr/ws2812.c index 0a02c6f7f..5c733c4ab 100644 --- a/drivers/avr/ws2812.c +++ b/drivers/avr/ws2812.c | |||
| @@ -25,13 +25,17 @@ | |||
| 25 | #include <avr/interrupt.h> | 25 | #include <avr/interrupt.h> |
| 26 | #include <avr/io.h> | 26 | #include <avr/io.h> |
| 27 | #include <util/delay.h> | 27 | #include <util/delay.h> |
| 28 | #include "debug.h" | ||
| 29 | 28 | ||
| 30 | #if !defined(LED_ARRAY) && defined(RGB_MATRIX_ENABLE) | 29 | /* |
| 31 | // LED color buffer | 30 | * Forward declare internal functions |
| 32 | LED_TYPE led[DRIVER_LED_TOTAL]; | 31 | * |
| 33 | # define LED_ARRAY led | 32 | * The functions take a byte-array and send to the data output as WS2812 bitstream. |
| 34 | #endif | 33 | * The length is the number of bytes to send - three per LED. |
| 34 | */ | ||
| 35 | |||
| 36 | void ws2812_sendarray(uint8_t *array, uint16_t length); | ||
| 37 | void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask); | ||
| 38 | |||
| 35 | 39 | ||
| 36 | #ifdef RGBW_BB_TWI | 40 | #ifdef RGBW_BB_TWI |
| 37 | 41 | ||
| @@ -135,23 +139,6 @@ unsigned char I2C_Write(unsigned char c) { | |||
| 135 | 139 | ||
| 136 | #endif | 140 | #endif |
| 137 | 141 | ||
| 138 | #ifdef RGB_MATRIX_ENABLE | ||
| 139 | // Set an led in the buffer to a color | ||
| 140 | void inline ws2812_setled(int i, uint8_t r, uint8_t g, uint8_t b) { | ||
| 141 | led[i].r = r; | ||
| 142 | led[i].g = g; | ||
| 143 | led[i].b = b; | ||
| 144 | } | ||
| 145 | |||
| 146 | void ws2812_setled_all(uint8_t r, uint8_t g, uint8_t b) { | ||
| 147 | for (int i = 0; i < sizeof(led) / sizeof(led[0]); i++) { | ||
| 148 | led[i].r = r; | ||
| 149 | led[i].g = g; | ||
| 150 | led[i].b = b; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | #endif | ||
| 154 | |||
| 155 | // Setleds for standard RGB | 142 | // Setleds for standard RGB |
| 156 | void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) { | 143 | void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) { |
| 157 | // ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin)); | 144 | // ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin)); |
diff --git a/drivers/avr/ws2812.h b/drivers/avr/ws2812.h index a9dd89718..9652b94bb 100644 --- a/drivers/avr/ws2812.h +++ b/drivers/avr/ws2812.h | |||
| @@ -20,13 +20,7 @@ | |||
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ | 21 | */ |
| 22 | 22 | ||
| 23 | #ifndef LIGHT_WS2812_H_ | 23 | #pragma once |
| 24 | #define LIGHT_WS2812_H_ | ||
| 25 | |||
| 26 | #include <avr/io.h> | ||
| 27 | #include <avr/interrupt.h> | ||
| 28 | //#include "ws2812_config.h" | ||
| 29 | //#include "i2cmaster.h" | ||
| 30 | 24 | ||
| 31 | #include "quantum/color.h" | 25 | #include "quantum/color.h" |
| 32 | 26 | ||
| @@ -42,33 +36,6 @@ | |||
| 42 | * - Send out the LED data | 36 | * - Send out the LED data |
| 43 | * - Wait 50�s to reset the LEDs | 37 | * - Wait 50�s to reset the LEDs |
| 44 | */ | 38 | */ |
| 45 | #ifdef RGB_MATRIX_ENABLE | ||
| 46 | void ws2812_setled(int index, uint8_t r, uint8_t g, uint8_t b); | ||
| 47 | void ws2812_setled_all(uint8_t r, uint8_t g, uint8_t b); | ||
| 48 | #endif | ||
| 49 | |||
| 50 | void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds); | 39 | void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds); |
| 51 | void ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask); | 40 | void ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask); |
| 52 | void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds); | 41 | void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds); |
| 53 | |||
| 54 | /* | ||
| 55 | * Old interface / Internal functions | ||
| 56 | * | ||
| 57 | * The functions take a byte-array and send to the data output as WS2812 bitstream. | ||
| 58 | * The length is the number of bytes to send - three per LED. | ||
| 59 | */ | ||
| 60 | |||
| 61 | void ws2812_sendarray(uint8_t *array, uint16_t length); | ||
| 62 | void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask); | ||
| 63 | |||
| 64 | /* | ||
| 65 | * Internal defines | ||
| 66 | */ | ||
| 67 | #ifndef CONCAT | ||
| 68 | # define CONCAT(a, b) a##b | ||
| 69 | #endif | ||
| 70 | #ifndef CONCAT_EXP | ||
| 71 | # define CONCAT_EXP(a, b) CONCAT(a, b) | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #endif /* LIGHT_WS2812_H_ */ | ||
diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c index 5b54bd595..503f97014 100644 --- a/quantum/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix_drivers.c | |||
| @@ -97,19 +97,33 @@ const rgb_matrix_driver_t rgb_matrix_driver = { | |||
| 97 | 97 | ||
| 98 | #elif defined(WS2812) | 98 | #elif defined(WS2812) |
| 99 | 99 | ||
| 100 | extern LED_TYPE led[DRIVER_LED_TOTAL]; | 100 | // LED color buffer |
| 101 | LED_TYPE led[DRIVER_LED_TOTAL]; | ||
| 102 | |||
| 103 | static void init(void) {} | ||
| 101 | 104 | ||
| 102 | static void flush(void) { | 105 | static void flush(void) { |
| 103 | // Assumes use of RGB_DI_PIN | 106 | // Assumes use of RGB_DI_PIN |
| 104 | ws2812_setleds(led, DRIVER_LED_TOTAL); | 107 | ws2812_setleds(led, DRIVER_LED_TOTAL); |
| 105 | } | 108 | } |
| 106 | 109 | ||
| 107 | static void init(void) {} | 110 | // Set an led in the buffer to a color |
| 111 | static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) { | ||
| 112 | led[i].r = r; | ||
| 113 | led[i].g = g; | ||
| 114 | led[i].b = b; | ||
| 115 | } | ||
| 116 | |||
| 117 | static void setled_all(uint8_t r, uint8_t g, uint8_t b) { | ||
| 118 | for (int i = 0; i < sizeof(led) / sizeof(led[0]); i++) { | ||
| 119 | setled(i, r, g, b); | ||
| 120 | } | ||
| 121 | } | ||
| 108 | 122 | ||
| 109 | const rgb_matrix_driver_t rgb_matrix_driver = { | 123 | const rgb_matrix_driver_t rgb_matrix_driver = { |
| 110 | .init = init, | 124 | .init = init, |
| 111 | .flush = flush, | 125 | .flush = flush, |
| 112 | .set_color = ws2812_setled, | 126 | .set_color = setled, |
| 113 | .set_color_all = ws2812_setled_all, | 127 | .set_color_all = setled_all, |
| 114 | }; | 128 | }; |
| 115 | #endif | 129 | #endif |
