Skip to content

Commit

Permalink
Reduce duplication for ARM/AVR ws2812 RGB Matrix driver (#7180)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zvecr committed Oct 29, 2019
1 parent 1b06ea0 commit e48fdeb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 61 deletions.
33 changes: 10 additions & 23 deletions drivers/avr/ws2812.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
#include <avr/interrupt.h>
#include <avr/io.h>
#include <util/delay.h>
#include "debug.h"

#if !defined(LED_ARRAY) && defined(RGB_MATRIX_ENABLE)
// LED color buffer
LED_TYPE led[DRIVER_LED_TOTAL];
# define LED_ARRAY led
#endif
/*
* Forward declare internal functions
*
* The functions take a byte-array and send to the data output as WS2812 bitstream.
* The length is the number of bytes to send - three per LED.
*/

void ws2812_sendarray(uint8_t *array, uint16_t length);
void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask);


#ifdef RGBW_BB_TWI

Expand Down Expand Up @@ -135,23 +139,6 @@ unsigned char I2C_Write(unsigned char c) {

#endif

#ifdef RGB_MATRIX_ENABLE
// Set an led in the buffer to a color
void inline ws2812_setled(int i, uint8_t r, uint8_t g, uint8_t b) {
led[i].r = r;
led[i].g = g;
led[i].b = b;
}

void ws2812_setled_all(uint8_t r, uint8_t g, uint8_t b) {
for (int i = 0; i < sizeof(led) / sizeof(led[0]); i++) {
led[i].r = r;
led[i].g = g;
led[i].b = b;
}
}
#endif

// Setleds for standard RGB
void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
// ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin));
Expand Down
35 changes: 1 addition & 34 deletions drivers/avr/ws2812.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
* along with this program. If not, see <http:https://www.gnu.org/licenses/>.
*/

#ifndef LIGHT_WS2812_H_
#define LIGHT_WS2812_H_

#include <avr/io.h>
#include <avr/interrupt.h>
//#include "ws2812_config.h"
//#include "i2cmaster.h"
#pragma once

#include "quantum/color.h"

Expand All @@ -42,33 +36,6 @@
* - Send out the LED data
* - Wait 50�s to reset the LEDs
*/
#ifdef RGB_MATRIX_ENABLE
void ws2812_setled(int index, uint8_t r, uint8_t g, uint8_t b);
void ws2812_setled_all(uint8_t r, uint8_t g, uint8_t b);
#endif

void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
void ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask);
void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);

/*
* Old interface / Internal functions
*
* The functions take a byte-array and send to the data output as WS2812 bitstream.
* The length is the number of bytes to send - three per LED.
*/

void ws2812_sendarray(uint8_t *array, uint16_t length);
void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask);

/*
* Internal defines
*/
#ifndef CONCAT
# define CONCAT(a, b) a##b
#endif
#ifndef CONCAT_EXP
# define CONCAT_EXP(a, b) CONCAT(a, b)
#endif

#endif /* LIGHT_WS2812_H_ */
22 changes: 18 additions & 4 deletions quantum/rgb_matrix_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,33 @@ const rgb_matrix_driver_t rgb_matrix_driver = {

#elif defined(WS2812)

extern LED_TYPE led[DRIVER_LED_TOTAL];
// LED color buffer
LED_TYPE led[DRIVER_LED_TOTAL];

static void init(void) {}

static void flush(void) {
// Assumes use of RGB_DI_PIN
ws2812_setleds(led, DRIVER_LED_TOTAL);
}

static void init(void) {}
// Set an led in the buffer to a color
static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) {
led[i].r = r;
led[i].g = g;
led[i].b = b;
}

static void setled_all(uint8_t r, uint8_t g, uint8_t b) {
for (int i = 0; i < sizeof(led) / sizeof(led[0]); i++) {
setled(i, r, g, b);
}
}

const rgb_matrix_driver_t rgb_matrix_driver = {
.init = init,
.flush = flush,
.set_color = ws2812_setled,
.set_color_all = ws2812_setled_all,
.set_color = setled,
.set_color_all = setled_all,
};
#endif

0 comments on commit e48fdeb

Please sign in to comment.