IoT-LED-Matrix/lib/led-matrix-32-16/led-matrix-32-16.cpp

84 lines
2.3 KiB
C++

#include "led-matrix-32-16.hpp"
inline VirtualCoords CustomPxBasePanel::getCoords(int16_t x, int16_t y)
{
coords = VirtualMatrixPanel::getCoords(x, y); // first call base class method to update coords for chaining approach
if (coords.x == -1 || coords.y == -1)
{ // Co-ordinates go from 0 to X-1 remember! width() and height() are out of range!
return coords;
}
uint8_t pxbase = 8; // pixel base
if ((coords.y & 4) == 0)
{
coords.x += (coords.x / pxbase) * pxbase;
}
else
{
coords.x += ((coords.x / pxbase) + 1) * pxbase;
}
coords.y = (coords.y >> 3) * 4 + (coords.y & 0b00000011);
return coords;
}
LedMetrix32x16::LedMetrix32x16(HUB75_I2S_CFG::i2s_pins _pins)
{
_pins.r1 = _pins.r1;
_pins.g1 = _pins.g1;
_pins.b1 = _pins.b1;
_pins.r2 = _pins.r2;
_pins.g2 = _pins.g2;
_pins.b2 = _pins.b2;
_pins.a = _pins.a;
_pins.b = _pins.b;
_pins.c = _pins.c;
_pins.d = _pins.d;
_pins.e = _pins.e;
_pins.lat = _pins.lat;
_pins.oe = _pins.oe;
_pins.clk = _pins.clk;
}
LedMetrix32x16::LedMetrix32x16()
{
_pins.r1 = R1_PIN_DEFAULT;
_pins.g1 = G1_PIN_DEFAULT;
_pins.b1 = B1_PIN_DEFAULT;
_pins.r2 = R2_PIN_DEFAULT;
_pins.g2 = G2_PIN_DEFAULT;
_pins.b2 = B2_PIN_DEFAULT;
_pins.a = A_PIN_DEFAULT;
_pins.b = B_PIN_DEFAULT;
_pins.c = C_PIN_DEFAULT;
_pins.d = D_PIN_DEFAULT;
_pins.e = E_PIN_DEFAULT;
_pins.lat = LAT_PIN_DEFAULT;
_pins.oe = OE_PIN_DEFAULT;
_pins.clk = CLK_PIN_DEFAULT;
}
void LedMetrix32x16::begin(int nRow, int nColl, PANEL_CHAIN_TYPE chain_type )
{
int res_x = 32;
int res_y = 16;
HUB75_I2S_CFG mxconfig (
res_x * 2, // width of a single panel
res_y / 2, // height of a single panel
nRow * nColl, // chain length - number of panels in the chain
_pins // pin mapping
); // I2S clock speed
// Create the DMA display object
mxconfig.clkphase = false; // use negative clock edge
dma_display = new MatrixPanel_I2S_DMA(mxconfig);
if (not dma_display->begin())
Serial.println("****** !KABOOM! I2S memory allocation failed ***********");
// Create the virtual display object
virtual_display = new CustomPxBasePanel(*dma_display, nRow, nColl, res_x, res_y, chain_type);
}