From 45652d0d5266bbe000166cdbd76e7750fe9fb11b Mon Sep 17 00:00:00 2001 From: mrfaptastic Date: Wed, 2 Jan 2019 23:09:32 +0000 Subject: [PATCH] Addition of faster fillScreen function Addition of a function to wipe the entire DMA buffer / screen with a single color in a quicker manner. --- ESP32-RGB64x32MatrixPanel-I2S-DMA.cpp | 106 +++++++++++++++++++++++++- ESP32-RGB64x32MatrixPanel-I2S-DMA.h | 25 ++++-- 2 files changed, 125 insertions(+), 6 deletions(-) diff --git a/ESP32-RGB64x32MatrixPanel-I2S-DMA.cpp b/ESP32-RGB64x32MatrixPanel-I2S-DMA.cpp index 6aab3bb..02f8148 100644 --- a/ESP32-RGB64x32MatrixPanel-I2S-DMA.cpp +++ b/ESP32-RGB64x32MatrixPanel-I2S-DMA.cpp @@ -169,6 +169,7 @@ void RGB64x32MatrixPanel_I2S_DMA::configureDMA() } // end initMatrixDMABuff +/* Update a specific co-ordinate in the DMA buffer */ void RGB64x32MatrixPanel_I2S_DMA::updateMatrixDMABuffer(int16_t x_coord, int16_t y_coord, uint8_t red, uint8_t green, uint8_t blue) { @@ -312,9 +313,112 @@ void RGB64x32MatrixPanel_I2S_DMA::updateMatrixDMABuffer(int16_t x_coord, int16_t i2s_parallel_flip_to_buffer(&I2S1, backbuf_id); //swapBuffer(); - } // updateDMABuffer + +/* Update the entire buffer with a single specific colour - quicker */ +void RGB64x32MatrixPanel_I2S_DMA::updateMatrixDMABuffer(uint8_t red, uint8_t green, uint8_t blue) +{ + + for (unsigned int y_coord = 0; y_coord < ROWS_PER_FRAME; y_coord++) // half height - 16 iterations + { + for(int color_depth_idx=0; color_depth_idx lsbMsbTransitionBit || !color_depth_idx) && ((x_coord) >= brightness)) v|=BIT_OE; // For Brightness + + // special case for the bits *after* LSB through (lsbMsbTransitionBit) - OE is output after data is shifted, so need to set OE to fractional brightness + if(color_depth_idx && color_depth_idx <= lsbMsbTransitionBit) { + // divide brightness in half for each bit below lsbMsbTransitionBit + int lsbBrightness = brightness >> (lsbMsbTransitionBit - color_depth_idx + 1); + if((x_coord) >= lsbBrightness) v|=BIT_OE; // For Brightness + } + + // need to turn off OE one clock before latch, otherwise can get ghosting + if((x_coord)==PIXELS_PER_LATCH-1) v|=BIT_OE; + + + // Top half colours + if (green & mask) + v|=BIT_G1; + if (blue & mask) + v|=BIT_B1; + if (red & mask) + v|=BIT_R1; + + // Bottom half colours + if (red & mask) + v|=BIT_R2; + if (green & mask) + v|=BIT_G2; + if (blue & mask) + v|=BIT_B2; + + + // 16 bit parallel mode + //Save the calculated value to the bitplane memory in reverse order to account for I2S Tx FIFO mode1 ordering + if(x_coord%2) + { + p->data[(x_coord)-1] = v; + } else { + p->data[(x_coord)+1] = v; + } // end reordering + + } // end x_coord iteration + } // colour depth loop (8) + } // end row iteration + + //Show our work! + i2s_parallel_flip_to_buffer(&I2S1, backbuf_id); + swapBuffer(); + +} // updateDMABuffer + + + + + + + + + + + + + + + /* // WORK IN PROGRESS void RGB64x32MatrixPanel_I2S_DMA::writeRGB24Frame2DMABuffer(rgb_24 *framedata, int16_t frame_width = MATRIX_WIDTH, int16_t frame_height = MATRIX_HEIGHT) diff --git a/ESP32-RGB64x32MatrixPanel-I2S-DMA.h b/ESP32-RGB64x32MatrixPanel-I2S-DMA.h index e6975b3..2e28f8c 100644 --- a/ESP32-RGB64x32MatrixPanel-I2S-DMA.h +++ b/ESP32-RGB64x32MatrixPanel-I2S-DMA.h @@ -171,7 +171,7 @@ class RGB64x32MatrixPanel_I2S_DMA : public Adafruit_GFX { allocateDMAbuffers(); backbuf_id = 0; - brightness = 64; // default to max brightness, wear sunglasses when looking directly at panel. + brightness = 32; // default to max brightness, wear sunglasses when looking directly at panel. } @@ -184,10 +184,14 @@ class RGB64x32MatrixPanel_I2S_DMA : public Adafruit_GFX { flushDMAbuffer(); swapBuffer(); } + + // TODO: Disable/Enable auto buffer flipping (useful for lots of drawPixel usage)... // Draw pixels - virtual void drawPixel(int16_t x, int16_t y, uint16_t color); // adafruit implementation + virtual void drawPixel(int16_t x, int16_t y, uint16_t color); // overwrite adafruit implementation + virtual void fillScreen(uint16_t color); // overwrite adafruit implementation + void clearScreen() { fillScreen(0); } inline void drawPixelRGB565(int16_t x, int16_t y, uint16_t color); inline void drawPixelRGB888(int16_t x, int16_t y, uint8_t r, uint8_t g, uint8_t b); inline void drawPixelRGB24(int16_t x, int16_t y, rgb_24 color); @@ -236,9 +240,11 @@ class RGB64x32MatrixPanel_I2S_DMA : public Adafruit_GFX { void configureDMA(); // Get everything setup. Refer to the .c file - // Paint a pixel to the DMA buffer directly + // Update a specific pixel in the DMA buffer a colour void updateMatrixDMABuffer(int16_t x, int16_t y, uint8_t red, uint8_t green, uint8_t blue); - + + // Update the entire DMA buffer a certain colour (wipe the screen basically) + void updateMatrixDMABuffer(uint8_t red, uint8_t green, uint8_t blue); // Internal variables bool dma_configuration_success; @@ -257,11 +263,20 @@ class RGB64x32MatrixPanel_I2S_DMA : public Adafruit_GFX { /***************************************************************************************/ -inline void RGB64x32MatrixPanel_I2S_DMA::drawPixel(int16_t x, int16_t y, uint16_t color) +inline void RGB64x32MatrixPanel_I2S_DMA::drawPixel(int16_t x, int16_t y, uint16_t color) // adafruit virtual void override { drawPixelRGB565( x, y, color); } +inline void RGB64x32MatrixPanel_I2S_DMA::fillScreen(uint16_t color) // adafruit virtual void override +{ + uint8_t r = ((((color >> 11) & 0x1F) * 527) + 23) >> 6; + uint8_t g = ((((color >> 5) & 0x3F) * 259) + 33) >> 6; + uint8_t b = (((color & 0x1F) * 527) + 23) >> 6; + + updateMatrixDMABuffer(r, g, b); // the RGB only (no pixel coordinate) version of 'updateMatrixDMABuffer' +} + // For adafruit inline void RGB64x32MatrixPanel_I2S_DMA::drawPixelRGB565(int16_t x, int16_t y, uint16_t color) {