Disable auto back-buffer switch logic.

No point changing to the back-buffer automatically, should be for advanced/manual uses of the library.
This commit is contained in:
mrfaptastic 2019-01-09 23:51:27 +00:00
parent 47a79db50f
commit c66fced326
2 changed files with 171 additions and 131 deletions

View file

@ -327,8 +327,16 @@ void RGB64x32MatrixPanel_I2S_DMA::updateMatrixDMABuffer(int16_t x_coord, int16_t
//Show our work!
i2s_parallel_flip_to_buffer(&I2S1, backbuf_id);
//swapBuffer();
if (immediateUpdate)
refreshDMAOutput();
//i2s_parallel_flip_to_buffer(&I2S1, backbuf_id);
/*
// There's no reason you'd want to do this in the draw pixel routine.
if (autoBackBufferFlip)
swapBuffer();
*/
} // updateDMABuffer
@ -416,9 +424,23 @@ void RGB64x32MatrixPanel_I2S_DMA::updateMatrixDMABuffer(uint8_t red, uint8_t gre
} // colour depth loop (8)
} // end row iteration
//Show our work!
i2s_parallel_flip_to_buffer(&I2S1, backbuf_id);
if (immediateUpdate)
refreshDMAOutput();
//i2s_parallel_flip_to_buffer(&I2S1, backbuf_id);
/*
// There's no reason you'd want to do this here either to be honest
if (autoBackBufferFlip)
swapBuffer();
*/
//Show our work!
//i2s_parallel_flip_to_buffer(&I2S1, backbuf_id);
//swapBuffer();
} // updateDMABuffer

View file

@ -50,7 +50,6 @@
subframes. We have 15 pixels: if we show subframe 3 for 8 of them, subframe 2 for 4 of them, subframe 1 for 2 of them and subframe 1 for 1 of
them, this 'automatically' happens. (We also distribute the subframes evenly over the ticks, which reduces flicker.)
In this code, we use the I2S peripheral in parallel mode to achieve this. Essentially, first we allocate memory for all subframes. This memory
contains a sequence of all the signals (2xRGB, line select, latch enable, output enable) that need to be sent to the display for that subframe.
Then we ask the I2S-parallel driver to set up a DMA chain so the subframes are sent out in a sequence that satisfies the requirement that
@ -59,13 +58,25 @@
We use a frontbuffer/backbuffer technique here to make sure the display is refreshed in one go and drawing artifacts do not reach the display.
In practice, for small displays this is not really necessarily.
Finally, the binary code modulated intensity of a LED does not correspond to the intensity as seen by human eyes. To correct for that, a
luminance correction is used. See val2pwm.c for more info.
Note: Because every subframe contains one bit of grayscale information, they are also referred to as 'bitplanes' by the code below.
*/
/***************************************************************************************/
/* HUB75 RGB pixel WIDTH and HEIGHT.
*
* This library has only been tested with a 64 pixel (wide) and 32 (high) RGB panel.
* Theoretically, if you want to chain two of these horizontally to make a 128x32 panel
* you can do so with the cable and then set the MATRIX_WIDTH to '128'.
*
* Also, if you use a 64x64 panel, then set the MATRIX_HEIGHT to '64', and it might work.
*
* All of this is memory permitting of course (dependant on your sketch etc.) ...
*
*/
#define MATRIX_HEIGHT 32
#define MATRIX_WIDTH 64
#define MATRIX_ROWS_IN_PARALLEL 2
/***************************************************************************************/
/* ESP32 Pin Definition. You can change this, but best if you keep it as is... */
@ -88,11 +99,7 @@
#define CLK_PIN_DEFAULT 16
/***************************************************************************************/
/* HUB75 RGB Panel definitions and DMA Config. It's best you don't change any of this. */
#define MATRIX_HEIGHT 32
#define MATRIX_WIDTH 64
#define MATRIX_ROWS_IN_PARALLEL 2
/* Don't change this stuff unless you know what you are doing */
// Panel Upper half RGB (numbering according to order in DMA gpio_bus configuration)
#define BIT_R1 (1<<0)
@ -135,6 +142,7 @@
/***************************************************************************************/
// note: sizeof(data) must be multiple of 32 bits, as ESP32 DMA linked list buffer address pointer must be word-aligned.
struct rowBitStruct {
MATRIX_DATA_STORAGE_TYPE data[((MATRIX_WIDTH * MATRIX_HEIGHT) / MATRIX_HEIGHT) + CLKS_DURING_LATCH];
@ -162,12 +170,13 @@ typedef struct rgb_24 {
uint8_t blue;
} rgb_24;
/***************************************************************************************/
class RGB64x32MatrixPanel_I2S_DMA : public Adafruit_GFX {
// ------- PUBLIC -------
public:
RGB64x32MatrixPanel_I2S_DMA(bool _doubleBuffer = false) // doublebuffer always enabled, option makes no difference
: Adafruit_GFX(MATRIX_WIDTH, MATRIX_HEIGHT), doubleBuffer(_doubleBuffer) {
RGB64x32MatrixPanel_I2S_DMA(bool _immediateUpdate = true, bool _autoBackBufferFlip = false) // Refer to commentary in the private: section
: Adafruit_GFX(MATRIX_WIDTH, MATRIX_HEIGHT), immediateUpdate(_immediateUpdate), autoBackBufferFlip(_autoBackBufferFlip) {
backbuf_id = 0;
brightness = 32; // default to max brightness, wear sunglasses when looking directly at panel.
@ -217,9 +226,9 @@ class RGB64x32MatrixPanel_I2S_DMA : public Adafruit_GFX {
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);
void drawPixelRGB565(int16_t x, int16_t y, uint16_t color);
void drawPixelRGB888(int16_t x, int16_t y, uint8_t r, uint8_t g, uint8_t b);
void drawPixelRGB24(int16_t x, int16_t y, rgb_24 color);
// TODO: Draw a frame! Oooh.
//void writeRGB24Frame2DMABuffer(rgb_24 *framedata, int16_t frame_width, int16_t frame_height);
@ -236,6 +245,11 @@ class RGB64x32MatrixPanel_I2S_DMA : public Adafruit_GFX {
backbuf_id ^=1;
}
void refreshDMAOutput()
{
i2s_parallel_flip_to_buffer(&I2S1, backbuf_id);
}
void setBrightness(int _brightness)
{
// Change to set the brightness of the display, range of 1 to matrixWidth (i.e. 1 - 64)
@ -268,15 +282,18 @@ class RGB64x32MatrixPanel_I2S_DMA : public Adafruit_GFX {
void configureDMA(int r1_pin, int g1_pin, int b1_pin, int r2_pin, int g2_pin, int b2_pin, int a_pin, int b_pin, int c_pin, int d_pin, int e_pin, int lat_pin, int oe_pin, int clk_pin); // Get everything setup. Refer to the .c file
// Update a specific pixel in the DMA buffer a colour
// Update a specific pixel in the DMA buffer to 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)
// Update the entire DMA buffer (aka. The RGB Panel) a certain colour (wipe the screen basically)
void updateMatrixDMABuffer(uint8_t red, uint8_t green, uint8_t blue);
// Internal variables
bool immediateUpdate; // Purpose: as per the variable name says, the minute we change a pixel, tell the ESP32 to use this for the I2S DMA Output
bool autoBackBufferFlip; // (Note: currently not used) Purpose: do we use the other buffer automatically after an update, or change to the 2nd buffer manually? Only use this if you know what you're doing. Otherwise for example, calling drawPixel three times (i.e. you're updating 3 pixels), will update pixel 1 on buffer 0, pixel on buffer 1, and pixel 3 on buffer 0 again - so you'll get weird output.
// Setup
bool dma_configuration_success;
bool doubleBuffer;
// Pixel data is organized from LSB to MSB sequentially by row, from row 0 to row matrixHeight/matrixRowsInParallel (two rows of pixels are refreshed in parallel)
frameStruct *matrixUpdateFrames;
@ -290,7 +307,8 @@ class RGB64x32MatrixPanel_I2S_DMA : public Adafruit_GFX {
}; // end Class header
/***************************************************************************************/
// https://stackoverflow.com/questions/5057021/why-are-c-inline-functions-in-the-header
/* 2. functions declared in the header must be marked inline because otherwise, every translation unit which includes the header will contain a definition of the function, and the linker will complain about multiple definitions (a violation of the One Definition Rule). The inline keyword suppresses this, allowing multiple translation units to contain (identical) definitions. */
inline void RGB64x32MatrixPanel_I2S_DMA::drawPixel(int16_t x, int16_t y, uint16_t color) // adafruit virtual void override
{
drawPixelRGB565( x, y, color);