From 4ba3f8ef44bb2b0be4fdc9231b6cc76e2dbc48d0 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Date: Sun, 9 Mar 2014 13:26:15 -0700 Subject: * Add rgb scaling and dithering support to all the SPI based chipsets * Fix some compiler warnings, and do other code cleanup * All LED chipsets are now using the PixelController object for loading, scaling, re-ordering rgb data --- fastspi_arm_k20.h | 70 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 31 deletions(-) (limited to 'fastspi_arm_k20.h') diff --git a/fastspi_arm_k20.h b/fastspi_arm_k20.h index 76f5b528..706755d2 100644 --- a/fastspi_arm_k20.h +++ b/fastspi_arm_k20.h @@ -290,32 +290,44 @@ public: // write a block of uint8_ts out in groups of three. len is the total number of uint8_ts to write out. The template // parameters indicate how many uint8_ts to skip at the beginning and/or end of each grouping - template void writeBytes3(register uint8_t *data, int len, register uint8_t scale) { + template void writeBytes3(register uint8_t *data, int len, register CRGB scale, bool advance=true, uint8_t skip=0) { // setSPIRate(); - uint8_t *end = data + len; select(); - if((SKIP & FLAG_START_BIT) == 0) { + uint8_t *end = data + len; + + // Setup the pixel controller + PixelController pixels(data, scale, true, advance, skip); + + if((FLAGS & FLAG_START_BIT) == 0) { //If no start bit stupiditiy, write out as many 16-bit blocks as we can - uint8_t *first_end = end - (len % (SPI_ADVANCE * 2)); - + uint8_t *first_end = end - (len % ((3+skip)*2)); while(data != first_end) { + // Load and write out the first two bytes if(WM == NONE) { wait1(); } - Write::writeWord(D::adjust(data[SPI_B0], scale) << 8 | D::adjust(data[SPI_B1], scale)); - Write::writeWord(D::adjust(data[SPI_B2], scale) << 8 | D::adjust(data[SPI_ADVANCE + SPI_B0], scale)); - Write::writeWord(D::adjust(data[SPI_ADVANCE + SPI_B1], scale) << 8 | D::adjust(data[SPI_ADVANCE + SPI_B2], scale)); - data += (SPI_ADVANCE + SPI_ADVANCE); + Write::writeWord(D::adjust(pixels.loadAndScale0()) << 8 | D::adjust(pixels.loadAndScale1())); + + // Load and write out the next two bytes (step dithering, advance data in between since we + // cross pixels here) + Write::writeWord(D::adjust(pixels.loadAndScale2()) << 8 | D::adjust(pixels.stepAdvanceAndLoadAndScale0())); + + // Load and write out the next two bytes + Write::writeWord(D::adjust(pixels.loadAndScale1()) << 8 | D::adjust(pixels.loadAndScale2())); + pixels.stepDithering(); + pixels.advanceData(); + + data += ((3+skip)*2); } if(data != end) { if(WM == NONE) { wait1(); } // write out the rest as alternating 16/8-bit blocks (likely to be just one) - Write::writeWord(D::adjust(data[SPI_B0], scale) << 8 | D::adjust(data[SPI_B1], scale)); - Write::writeByte(D::adjust(data[SPI_B2], scale)); + Write::writeWord(D::adjust(pixels.loadAndScale0()) << 8 | D::adjust(pixels.loadAndScale1())); + Write::writeByte(D::adjust(pixels.loadAndScale2())); } D::postBlock(len); waitFully(); - } else if(SKIP & FLAG_START_BIT) { + } else if(FLAGS & FLAG_START_BIT) { uint32_t ctar1_save = SPI0_CTAR1; // Clear out the FMSZ bits, reset them for 9 bits transferd for the start bit @@ -323,38 +335,34 @@ public: update_ctar1(ctar1); while(data != end) { - writeWord( 0x100 | D::adjust(data[SPI_B0], scale)); - writeByte(D::adjust(data[SPI_B1], scale)); - writeByte(D::adjust(data[SPI_B2], scale)); - data += SPI_ADVANCE; + writeWord( 0x100 | D::adjust(pixels.loadAndScale0())); + writeByte(D::adjust(pixels.loadAndScale1())); + writeByte(D::adjust(pixels.loadAndScale2())); + pixels.advanceData(); + pixels.stepDithering(); + data += (3+skip); } D::postBlock(len); waitFully(); // restore ctar1 update_ctar1(ctar1_save); - // } else { - // while(data != end) { - // writeByte(D::adjust(data[SPI_B0], scale); - // writeWord(D::adjust(data[SPI_B1], scale) << 8 | D::adjust(data[SPI_B2], scale)); - // data += SPI_ADVANCE; - // } - // waitFully(); } release(); } - template void writeBytes3(register uint8_t *data, int len, register uint8_t scale) { - writeBytes3(data, len, scale); + // template instantiations for writeBytes 3 + template void writeBytes3(register uint8_t *data, int len, register CRGB scale, bool advance=true, uint8_t skip=0) { + writeBytes3(data, len, scale, advance, skip); } - template void writeBytes3(register uint8_t *data, int len, register uint8_t scale) { - writeBytes3<0, D, RGB_ORDER>(data, len, scale); + template void writeBytes3(register uint8_t *data, int len, register CRGB scale, bool advance=true, uint8_t skip=0) { + writeBytes3<0, D, RGB_ORDER>(data, len, scale, advance, skip); } - template void writeBytes3(register uint8_t *data, int len, register uint8_t scale) { - writeBytes3<0, DATA_NOP, RGB_ORDER>(data, len, scale); + template void writeBytes3(register uint8_t *data, int len, register CRGB scale, bool advance=true, uint8_t skip=0) { + writeBytes3<0, DATA_NOP, RGB_ORDER>(data, len, scale, advance, skip); } - void writeBytes3(register uint8_t *data, int len, register uint8_t scale) { - writeBytes3<0, DATA_NOP, RGB>(data, len, scale); + void writeBytes3(register uint8_t *data, int len, register CRGB scale, bool advance=true, uint8_t skip=0) { + writeBytes3<0, DATA_NOP, RGB>(data, len, scale, advance, skip); } }; #endif -- cgit v1.2.3