Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Garcia <danielgarcia@gmail.com>2014-03-10 00:26:15 +0400
committerDaniel Garcia <danielgarcia@gmail.com>2014-03-10 00:26:15 +0400
commit4ba3f8ef44bb2b0be4fdc9231b6cc76e2dbc48d0 (patch)
tree3e12a4e9a32b28db9541191a4fa332aeba7ecc16 /fastspi_arm_k20.h
parentd1535918f9a0023d1c3a6c1c89615bc3c8d0c3e0 (diff)
* 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
Diffstat (limited to 'fastspi_arm_k20.h')
-rw-r--r--fastspi_arm_k20.h70
1 files changed, 39 insertions, 31 deletions
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 <uint8_t SKIP, class D, EOrder RGB_ORDER> void writeBytes3(register uint8_t *data, int len, register uint8_t scale) {
+ template <uint8_t FLAGS, class D, EOrder RGB_ORDER> 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<RGB_ORDER> 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<CM, WM, NOTLAST>::writeWord(D::adjust(data[SPI_B0], scale) << 8 | D::adjust(data[SPI_B1], scale));
- Write<CM, WM, NOTLAST>::writeWord(D::adjust(data[SPI_B2], scale) << 8 | D::adjust(data[SPI_ADVANCE + SPI_B0], scale));
- Write<CM, WM, NOTLAST>::writeWord(D::adjust(data[SPI_ADVANCE + SPI_B1], scale) << 8 | D::adjust(data[SPI_ADVANCE + SPI_B2], scale));
- data += (SPI_ADVANCE + SPI_ADVANCE);
+ Write<CM, WM, NOTLAST>::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<CM, WM, NOTLAST>::writeWord(D::adjust(pixels.loadAndScale2()) << 8 | D::adjust(pixels.stepAdvanceAndLoadAndScale0()));
+
+ // Load and write out the next two bytes
+ Write<CM, WM, NOTLAST>::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<CM, WM, NOTLAST>::writeWord(D::adjust(data[SPI_B0], scale) << 8 | D::adjust(data[SPI_B1], scale));
- Write<CM, WM, NOTLAST>::writeByte(D::adjust(data[SPI_B2], scale));
+ Write<CM, WM, NOTLAST>::writeWord(D::adjust(pixels.loadAndScale0()) << 8 | D::adjust(pixels.loadAndScale1()));
+ Write<CM, WM, NOTLAST>::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 <uint8_t SKIP, EOrder RGB_ORDER> void writeBytes3(register uint8_t *data, int len, register uint8_t scale) {
- writeBytes3<SKIP, DATA_NOP, RGB_ORDER>(data, len, scale);
+ // template instantiations for writeBytes 3
+ template <uint8_t FLAGS, EOrder RGB_ORDER> void writeBytes3(register uint8_t *data, int len, register CRGB scale, bool advance=true, uint8_t skip=0) {
+ writeBytes3<FLAGS, DATA_NOP, RGB_ORDER>(data, len, scale, advance, skip);
}
- template <class D, EOrder RGB_ORDER> void writeBytes3(register uint8_t *data, int len, register uint8_t scale) {
- writeBytes3<0, D, RGB_ORDER>(data, len, scale);
+ template <class D, EOrder RGB_ORDER> 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 <EOrder RGB_ORDER> void writeBytes3(register uint8_t *data, int len, register uint8_t scale) {
- writeBytes3<0, DATA_NOP, RGB_ORDER>(data, len, scale);
+ template <EOrder RGB_ORDER> 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