Update ESP32-VirtualMatrixPanel-I2S-DMA.h
This commit is contained in:
parent
264d997618
commit
7d1841e355
1 changed files with 265 additions and 267 deletions
|
@ -30,7 +30,7 @@
|
|||
#include <Fonts/FreeSansBold12pt7b.h>
|
||||
#endif
|
||||
|
||||
//#include <iostream>
|
||||
// #include <iostream>
|
||||
|
||||
struct VirtualCoords
|
||||
{
|
||||
|
@ -46,7 +46,8 @@ struct VirtualCoords
|
|||
|
||||
enum PANEL_SCAN_RATE
|
||||
{
|
||||
NORMAL_TWO_SCAN, NORMAL_ONE_SIXTEEN, // treated as the same
|
||||
NORMAL_TWO_SCAN,
|
||||
NORMAL_ONE_SIXTEEN, // treated as the same
|
||||
FOUR_SCAN_32PX_HIGH,
|
||||
FOUR_SCAN_16PX_HIGH
|
||||
};
|
||||
|
@ -54,6 +55,7 @@ enum PANEL_SCAN_RATE
|
|||
// Chaining approach... From the perspective of the DISPLAY / LED side of the chain of panels.
|
||||
enum PANEL_CHAIN_TYPE
|
||||
{
|
||||
CHAIN_NONE,
|
||||
CHAIN_TOP_LEFT_DOWN,
|
||||
CHAIN_TOP_RIGHT_DOWN,
|
||||
CHAIN_BOTTOM_LEFT_UP,
|
||||
|
@ -74,8 +76,7 @@ class VirtualMatrixPanel
|
|||
{
|
||||
|
||||
public:
|
||||
|
||||
VirtualMatrixPanel(MatrixPanel_I2S_DMA &disp, int _vmodule_rows, int _vmodule_cols, int _panelResX, int _panelResY, PANEL_CHAIN_TYPE _panel_chain_type = CHAIN_TOP_RIGHT_DOWN)
|
||||
VirtualMatrixPanel(MatrixPanel_I2S_DMA &disp, int _vmodule_rows, int _vmodule_cols, int _panelResX, int _panelResY, PANEL_CHAIN_TYPE _panel_chain_type = CHAIN_NONE)
|
||||
#ifdef USE_GFX_ROOT
|
||||
: GFX(_vmodule_cols * _panelResX, _vmodule_rows * _panelResY)
|
||||
#elif !defined NO_GFX
|
||||
|
@ -121,7 +122,10 @@ public:
|
|||
void drawPixel(int16_t x, int16_t y, CRGB color);
|
||||
#endif
|
||||
|
||||
uint16_t color444(uint8_t r, uint8_t g, uint8_t b) { return display->color444(r, g, b); }
|
||||
uint16_t color444(uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
return display->color444(r, g, b);
|
||||
}
|
||||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b) { return display->color565(r, g, b); }
|
||||
uint16_t color333(uint8_t r, uint8_t g, uint8_t b) { return display->color333(r, g, b); }
|
||||
|
||||
|
@ -177,28 +181,27 @@ inline VirtualCoords VirtualMatrixPanel::getCoords(int16_t &virt_x, int16_t &vir
|
|||
}
|
||||
|
||||
int row = (virt_y / panelResY); // 0 indexed
|
||||
switch(panel_chain_type)
|
||||
switch (panel_chain_type)
|
||||
{
|
||||
case (CHAIN_TOP_RIGHT_DOWN):
|
||||
{
|
||||
if ( (row % 2) == 1 )
|
||||
if ((row % 2) == 1)
|
||||
{ // upside down panel
|
||||
|
||||
//Serial.printf("Condition 1, row %d ", row);
|
||||
// Serial.printf("Condition 1, row %d ", row);
|
||||
|
||||
// reversed for the row
|
||||
coords.x = dmaResX - virt_x - (row*virtualResX);
|
||||
coords.x = dmaResX - virt_x - (row * virtualResX);
|
||||
|
||||
// y co-ord inverted within the panel
|
||||
coords.y = panelResY - 1 - (virt_y % panelResY);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
|
||||
// Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row + 1)) * virtualResX) + virt_x;
|
||||
coords.y = virt_y % panelResY;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -207,27 +210,27 @@ inline VirtualCoords VirtualMatrixPanel::getCoords(int16_t &virt_x, int16_t &vir
|
|||
// Right side up. Starting from top right all the way down.
|
||||
// Connected in a Zig Zag manner = some long ass cables being used potentially
|
||||
|
||||
//Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
|
||||
// Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row + 1)) * virtualResX) + virt_x;
|
||||
coords.y = virt_y % panelResY;
|
||||
}
|
||||
break;
|
||||
|
||||
case (CHAIN_TOP_LEFT_DOWN): // OK -> modulus opposite of CHAIN_TOP_RIGHT_DOWN
|
||||
{
|
||||
if ( (row % 2) == 0 )
|
||||
if ((row % 2) == 0)
|
||||
{ // reversed panel
|
||||
|
||||
//Serial.printf("Condition 1, row %d ", row);
|
||||
coords.x = dmaResX - virt_x - (row*virtualResX);
|
||||
// Serial.printf("Condition 1, row %d ", row);
|
||||
coords.x = dmaResX - virt_x - (row * virtualResX);
|
||||
|
||||
// y co-ord inverted within the panel
|
||||
coords.y = panelResY - 1 - (virt_y % panelResY);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
|
||||
// Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row + 1)) * virtualResX) + virt_x;
|
||||
coords.y = virt_y % panelResY;
|
||||
}
|
||||
}
|
||||
|
@ -235,31 +238,29 @@ inline VirtualCoords VirtualMatrixPanel::getCoords(int16_t &virt_x, int16_t &vir
|
|||
|
||||
case (CHAIN_TOP_LEFT_DOWN_ZZ):
|
||||
{
|
||||
//Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
|
||||
// Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row + 1)) * virtualResX) + virt_x;
|
||||
coords.y = virt_y % panelResY;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case (CHAIN_BOTTOM_LEFT_UP): //
|
||||
{
|
||||
row = vmodule_rows - row - 1;
|
||||
|
||||
if ( (row % 2) == 1 )
|
||||
if ((row % 2) == 1)
|
||||
{
|
||||
// Serial.printf("Condition 1, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
|
||||
coords.x = ((vmodule_rows - (row + 1)) * virtualResX) + virt_x;
|
||||
coords.y = virt_y % panelResY;
|
||||
}
|
||||
else
|
||||
{ // inverted panel
|
||||
|
||||
// Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = dmaResX - (row*virtualResX) - virt_x;
|
||||
coords.x = dmaResX - (row * virtualResX) - virt_x;
|
||||
coords.y = panelResY - 1 - (virt_y % panelResY);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -267,7 +268,7 @@ inline VirtualCoords VirtualMatrixPanel::getCoords(int16_t &virt_x, int16_t &vir
|
|||
{
|
||||
row = vmodule_rows - row - 1;
|
||||
// Serial.printf("Condition 1, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
|
||||
coords.x = ((vmodule_rows - (row + 1)) * virtualResX) + virt_x;
|
||||
coords.y = virt_y % panelResY;
|
||||
}
|
||||
break;
|
||||
|
@ -276,22 +277,21 @@ inline VirtualCoords VirtualMatrixPanel::getCoords(int16_t &virt_x, int16_t &vir
|
|||
{
|
||||
row = vmodule_rows - row - 1;
|
||||
|
||||
if ( (row % 2) == 0 )
|
||||
if ((row % 2) == 0)
|
||||
{ // right side up
|
||||
|
||||
// Serial.printf("Condition 1, row %d ", row);
|
||||
// refersed for the row
|
||||
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
|
||||
coords.x = ((vmodule_rows - (row + 1)) * virtualResX) + virt_x;
|
||||
coords.y = virt_y % panelResY;
|
||||
}
|
||||
else
|
||||
{ // inverted panel
|
||||
|
||||
// Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = dmaResX - (row*virtualResX) - virt_x;
|
||||
coords.x = dmaResX - (row * virtualResX) - virt_x;
|
||||
coords.y = panelResY - 1 - (virt_y % panelResY);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -301,21 +301,20 @@ inline VirtualCoords VirtualMatrixPanel::getCoords(int16_t &virt_x, int16_t &vir
|
|||
// Connected in a Zig Zag manner = some long ass cables being used potentially
|
||||
|
||||
row = vmodule_rows - row - 1;
|
||||
//Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
|
||||
// Serial.printf("Condition 2, row %d ", row);
|
||||
coords.x = ((vmodule_rows - (row + 1)) * virtualResX) + virt_x;
|
||||
coords.y = virt_y % panelResY;
|
||||
}
|
||||
break;
|
||||
|
||||
// Q: 1 row!? Why?
|
||||
// A: In cases people are only using virtual matrix panel for panels of non-standard scan rates.
|
||||
default:
|
||||
coords.x = coords.y = -1; // By defalt use an invalid co-ordinates that will be rejected by updateMatrixDMABuffer
|
||||
return coords;
|
||||
coords.x = virt_x; coords.y = virt_y;
|
||||
break;
|
||||
|
||||
} // end switch
|
||||
|
||||
|
||||
|
||||
/* START: Pixel remapping AGAIN to convert TWO parallel scanline output that the
|
||||
* the underlying hardware library is designed for (because
|
||||
* there's only 2 x RGB pins... and convert this to 1/4 or something
|
||||
|
@ -344,7 +343,6 @@ inline VirtualCoords VirtualMatrixPanel::getCoords(int16_t &virt_x, int16_t &vir
|
|||
// Real number of DMA y rows is half reality
|
||||
// coords.y = (y / 16)*8 + (y & 0b00000111);
|
||||
coords.y = (virt_y >> 4) * 8 + (virt_y & 0b00000111);
|
||||
|
||||
}
|
||||
else if (panel_scan_rate == FOUR_SCAN_16PX_HIGH)
|
||||
{
|
||||
|
@ -439,7 +437,7 @@ inline void VirtualMatrixPanel::drawDisplayTest()
|
|||
{
|
||||
int top_left_x = (panel == 0) ? 0 : (panel * panelResX);
|
||||
this->display->drawRect(top_left_x, 0, panelResX, panelResY, this->display->color565(0, 255, 0));
|
||||
this->display->setCursor( (panel * panelResX)+2, panelResY - 4);
|
||||
this->display->setCursor((panel * panelResX) + 2, panelResY - 4);
|
||||
this->display->print((vmodule_cols * vmodule_rows) - panel);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue