aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2019-10-29 01:00:03 +0000
committerGitHub <noreply@github.com>2019-10-29 01:00:03 +0000
commite48fdebe5a351772c4f34b201130271a42c1496d (patch)
treefae47f5c1eb817e8f36c0ae87b60ab152ea171f1
parent1b06ea0c863b493215d80400f00797ceb0eabc3d (diff)
downloadqmk_firmware-e48fdebe5a351772c4f34b201130271a42c1496d.tar.gz
qmk_firmware-e48fdebe5a351772c4f34b201130271a42c1496d.zip
Reduce duplication for ARM/AVR ws2812 RGB Matrix driver (#7180)
* Reduce duplication for ARM/AVR ws2812 rgb_matrix driver * Reduce duplication for ARM/AVR ws2812 rgb_matrix driver - Fix setled_all use of r,g,b
-rw-r--r--drivers/avr/ws2812.c33
-rw-r--r--drivers/avr/ws2812.h35
-rw-r--r--quantum/rgb_matrix_drivers.c22
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
32LED_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
36void ws2812_sendarray(uint8_t *array, uint16_t length);
37void 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
140void 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
146void 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
156void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) { 143void 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
46void ws2812_setled(int index, uint8_t r, uint8_t g, uint8_t b);
47void ws2812_setled_all(uint8_t r, uint8_t g, uint8_t b);
48#endif
49
50void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds); 39void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
51void ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask); 40void ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask);
52void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds); 41void 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
61void ws2812_sendarray(uint8_t *array, uint16_t length);
62void 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
100extern LED_TYPE led[DRIVER_LED_TOTAL]; 100// LED color buffer
101LED_TYPE led[DRIVER_LED_TOTAL];
102
103static void init(void) {}
101 104
102static void flush(void) { 105static 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
107static void init(void) {} 110// Set an led in the buffer to a color
111static 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
117static 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
109const rgb_matrix_driver_t rgb_matrix_driver = { 123const 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