Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for RGBW LEDs like SK6812RGBW #143

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.vscode
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var arduino = process.env.ARDUINO_PATH;

var boards = require("./firmware/boards.js");
var boardlist = Object.keys(boards).toString();

module.exports = function(grunt) {

// configure the tasks
Expand Down Expand Up @@ -128,6 +127,7 @@ module.exports = function(grunt) {

// dynamically create the compile targets for the various boards
Object.keys(boards).forEach(function(key) {

grunt.config(["exec", "firmata_" + key], {
command:function() {
return arduino + " --verify --verbose-build --board " + boards[key].package +
Expand Down
569 changes: 285 additions & 284 deletions firmware/bin/backpack/diecimila/backpack.ino.hex

Large diffs are not rendered by default.

948 changes: 474 additions & 474 deletions firmware/bin/backpack/leonardo/backpack.ino.hex

Large diffs are not rendered by default.

609 changes: 305 additions & 304 deletions firmware/bin/backpack/mega/backpack.ino.hex

Large diffs are not rendered by default.

948 changes: 474 additions & 474 deletions firmware/bin/backpack/micro/backpack.ino.hex

Large diffs are not rendered by default.

569 changes: 285 additions & 284 deletions firmware/bin/backpack/nano/backpack.ino.hex

Large diffs are not rendered by default.

569 changes: 285 additions & 284 deletions firmware/bin/backpack/pro-mini/backpack.ino.hex

Large diffs are not rendered by default.

569 changes: 285 additions & 284 deletions firmware/bin/backpack/uno/backpack.ino.hex

Large diffs are not rendered by default.

1,697 changes: 893 additions & 804 deletions firmware/bin/firmata/diecimila/node_pixel_firmata.ino.hex

Large diffs are not rendered by default.

2,164 changes: 1,149 additions & 1,015 deletions firmware/bin/firmata/leonardo/node_pixel_firmata.ino.hex

Large diffs are not rendered by default.

2,109 changes: 1,127 additions & 982 deletions firmware/bin/firmata/mega/node_pixel_firmata.ino.hex

Large diffs are not rendered by default.

2,164 changes: 1,149 additions & 1,015 deletions firmware/bin/firmata/micro/node_pixel_firmata.ino.hex

Large diffs are not rendered by default.

1,697 changes: 893 additions & 804 deletions firmware/bin/firmata/nano/node_pixel_firmata.ino.hex

Large diffs are not rendered by default.

1,697 changes: 893 additions & 804 deletions firmware/bin/firmata/pro-mini/node_pixel_firmata.ino.hex

Large diffs are not rendered by default.

1,697 changes: 893 additions & 804 deletions firmware/bin/firmata/uno/node_pixel_firmata.ino.hex

Large diffs are not rendered by default.

41 changes: 34 additions & 7 deletions firmware/build/backpack/ws2812.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ bool strip_changed[MAX_STRIPS]; // used to optimise strip writes.
uint8_t *px;
uint16_t px_count;
uint8_t strip_count = 0; // number of strips being used.
uint8_t color_depth = 3; // Bytes used to hold one pixel
uint8_t color_depth = 4; // Bytes used to hold one pixel

uint8_t offsetRed;
uint8_t offsetGreen;
uint8_t offsetBlue;
uint8_t offsetWhite;

void ws2812_initialise() {
// initialises the strip defaults.
Expand Down Expand Up @@ -77,9 +78,10 @@ uint8_t set_rgb_at(uint16_t index, uint32_t px_value) {
uint16_t tmp_pixel;
tmp_pixel = index * color_depth;

px[OFFSET_R(tmp_pixel)] = (uint8_t)(px_value >> 16);
px[OFFSET_G(tmp_pixel)] = (uint8_t)(px_value >> 8);
px[OFFSET_B(tmp_pixel)] = (uint8_t)px_value;
px[OFFSET_R(tmp_pixel)] = (uint8_t)(px_value >> 24);
px[OFFSET_G(tmp_pixel)] = (uint8_t)(px_value >> 16);
px[OFFSET_B(tmp_pixel)] = (uint8_t)(px_value >> 8);
px[OFFSET_W(tmp_pixel)] = (uint8_t)px_value;

return 0;
}
Expand Down Expand Up @@ -181,7 +183,8 @@ void process_command(byte argc, byte *argv){
uint32_t strip_colour = (uint32_t)argv[1] +
((uint32_t)argv[2]<<7) +
((uint32_t)argv[3]<<14) +
((uint32_t)argv[4] << 21);
((uint32_t)argv[4]<< 21) +
((uint32_t)argv[5] << 28);

if (! isShifting) {
if (strip_colour == 0) {
Expand All @@ -201,7 +204,7 @@ void process_command(byte argc, byte *argv){
// sets the pixel given by the index to the given colour
uint16_t index = (uint16_t)argv[1] + ((uint16_t)argv[2]<<7);
uint32_t colour = (uint32_t)argv[3] + ((uint32_t)argv[4]<<7) +
((uint32_t)argv[5]<<14) + ((uint32_t)argv[6] << 21);
((uint32_t)argv[5]<<14) + ((uint32_t)argv[6] << 21) + ((uint32_t)argv[6] << 28);

if (isShifting) {
break;
Expand Down Expand Up @@ -261,6 +264,9 @@ void process_command(byte argc, byte *argv){
case PIXEL_COLOUR_BRG:
setColorOrderBRG();
break;
case PIXEL_COLOUR_RGBW:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajfisher I have made some protections within pixel.js to make sure that by default, we send an array with length of 3. We send 4 if rgbw colors are declared at instantiation. I'm going to work on adding similar protection here I think, to make sure all is good within the firmware.I wanted your feedback on this approach so far before I get too into it. Please let me know your thoughts on what I have in the PR to this point. I will also go back and make sure all tests pass within the next few days. Thanks!

setColorOrderRGBW();
break;
}

// now get the strand length and set it
Expand Down Expand Up @@ -318,6 +324,13 @@ void setColorOrderBRG() {
offsetGreen = 2;
}

void setColorOrderRGBW() {
offsetRed = 0;
offsetGreen = 1;
offsetBlue = 2;
offsetWhite = 3;
}

#if DEBUG
void print_pixels() {
// prints out the array of pixel values
Expand All @@ -333,7 +346,9 @@ void print_pixels() {
serialport.print(px[OFFSET_G(index)]);
serialport.print(" ");
serialport.print(px[OFFSET_B(index)]);
serialport.println();
serialport.print(" ");
serialport.print(px[OFFSET_W(index)]);

}
}

Expand All @@ -343,3 +358,15 @@ int freeRam () {
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
#endif












4 changes: 4 additions & 0 deletions firmware/build/backpack/ws2812.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#define PIXEL_COLOUR_GRB 0x0
#define PIXEL_COLOUR_RGB 0x1
#define PIXEL_COLOUR_BRG 0x2
#define PIXEL_COLOUR_RGBW 0x3

#define STRIP_START_PIN 0

Expand All @@ -47,6 +48,7 @@
#define OFFSET_R(r) r+offsetRed
#define OFFSET_G(g) g+offsetGreen
#define OFFSET_B(b) b+offsetBlue
#define OFFSET_W(w) w+offsetWhite

void ws2812_initialise();
void ws2812_initialise(bool backpack);
Expand All @@ -57,6 +59,8 @@ uint8_t set_rgb_at(uint16_t index, uint32_t px_value);
void setColorOrderRGB();
void setColorOrderGRB();
void setColorOrderBRG();
void setColorOrderRGBW();


#if DEBUG
void print_pixels();
Expand Down
Loading