I added initial SK9822 support to the SmartMatrix Library, it’s on GitHub now. You need to edit SmartMatrix_Impl.h and change #define LEDTYPE
at the top. Later I’ll make it able to select the LED type from the sketch using template parameters.
APA102 LEDs don’t follow their datasheet, and appear to use /32 math for GBC instead of /31. I didn’t verify that with a scope, but using /32 math got rid of the stepping. /31 math makes no sense on an embedded platform, it should be a power of two. The SK9822 engineers must have wanted to follow the APA102 datasheet to the letter, and used /31 math for GBC. I have GBC working without stepping, but the unoptimized code uses four division operations per pixel, where with the APA102 you could just use bitwise math and shifts which are much more efficient.
The SmartMatrix Library code isn’t easy to follow because it combines the overall matrix brightness value with the RGB pixel scaling calculation, I’ll have to add comments explaining the math later. This code should be easy to use in a non-SmartMatrix project (though it still doesn’t have comments):
uint16_t maxrgb = max(max(led16bit_r, led16bit_g), led16bit_b);
value = maxrgb * 0x10000 / 31;
// load pixels with 8-bit color plus 5-bit global brightness
src[spilength++] = 0xE0 | (value + 1); // Pixel start with global brightness
src[spilength++] = ((led16bit_b * 31) / (value + 1)) >> 8;
src[spilength++] = ((led16bit_g * 31) / (value + 1)) >> 8;
src[spilength++] = ((led16bit_r * 31) / (value + 1)) >> 8;
I’m not seeing the hue shift with the SK9822s. I didn’t directly trying ramping the GBC from 0x0 to 0x1f, but ran this code with the SmartMatrix Library using 48-bit math, and it should have taken care of changing the GBC in the background:
buffer = backgroundLayer.backBuffer();
for(int i=0; i<64; i++) {
buffer[i] = rgb48(20*4*i,240*4*i,70*4*i);
}
backgroundLayer.swapBuffers(true);
I get this on an 8x8 matrix diffused with a sheet of paper. It’s admittedly not a great photo, but I don’t see any dramatic hue shifts.
Here’s a SK9822 and APA102 side by side running the same sketch.
And here’s a slow motion video recording (iPhone 6) of the two with the lower speed PWM on the APA102s showing. The whole frame flickering is because I was shining a fluorescent lamp above the diffuser.