Skip to content

Commit 3cf7a9a

Browse files
committed
add 32x64 support
1 parent 5f718bd commit 3cf7a9a

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

RGBmatrixPanel.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ static RGBmatrixPanel *activePanel = NULL;
8787

8888
// Code common to both the 16x32 and 32x32 constructors:
8989
void RGBmatrixPanel::init(uint8_t rows, uint8_t a, uint8_t b, uint8_t c,
90-
uint8_t sclk, uint8_t latch, uint8_t oe, boolean dbuf) {
90+
uint8_t sclk, uint8_t latch, uint8_t oe, boolean dbuf, uint8_t width) {
9191

9292
nRows = rows; // Number of multiplexed rows; actual height is 2X this
9393

9494
// Allocate and initialize matrix buffer:
95-
int buffsize = 32 * nRows * 3, // x3 = 3 bytes holds 4 planes "packed"
95+
int buffsize = width * nRows * 3, // x3 = 3 bytes holds 4 planes "packed"
9696
allocsize = (dbuf == true) ? (buffsize * 2) : buffsize;
9797
if(NULL == (matrixbuff[0] = (uint8_t *)malloc(allocsize))) return;
9898
memset(matrixbuff[0], 0, allocsize);
@@ -132,16 +132,16 @@ RGBmatrixPanel::RGBmatrixPanel(
132132
uint8_t sclk, uint8_t latch, uint8_t oe, boolean dbuf) :
133133
Adafruit_GFX(32, 16) {
134134

135-
init(8, a, b, c, sclk, latch, oe, dbuf);
135+
init(8, a, b, c, sclk, latch, oe, dbuf, 32);
136136
}
137137

138-
// Constructor for 32x32 panel:
138+
// Constructor for 32x32 or 32x64 panel:
139139
RGBmatrixPanel::RGBmatrixPanel(
140140
uint8_t a, uint8_t b, uint8_t c, uint8_t d,
141-
uint8_t sclk, uint8_t latch, uint8_t oe, boolean dbuf) :
142-
Adafruit_GFX(32, 32) {
141+
uint8_t sclk, uint8_t latch, uint8_t oe, boolean dbuf, uint8_t width) :
142+
Adafruit_GFX(width, 32) {
143143

144-
init(16, a, b, c, sclk, latch, oe, dbuf);
144+
init(16, a, b, c, sclk, latch, oe, dbuf, width);
145145

146146
// Init a few extra 32x32-specific elements:
147147
_d = d;
@@ -303,11 +303,11 @@ void RGBmatrixPanel::drawPixel(int16_t x, int16_t y, uint16_t c) {
303303
ptr = &matrixbuff[backindex][y * WIDTH * (nPlanes - 1) + x]; // Base addr
304304
// Plane 0 is a tricky case -- its data is spread about,
305305
// stored in least two bits not used by the other planes.
306-
ptr[64] &= ~B00000011; // Plane 0 R,G mask out in one op
307-
if(r & 1) ptr[64] |= B00000001; // Plane 0 R: 64 bytes ahead, bit 0
308-
if(g & 1) ptr[64] |= B00000010; // Plane 0 G: 64 bytes ahead, bit 1
309-
if(b & 1) ptr[32] |= B00000001; // Plane 0 B: 32 bytes ahead, bit 0
310-
else ptr[32] &= ~B00000001; // Plane 0 B unset; mask out
306+
ptr[_width*2] &= ~B00000011; // Plane 0 R,G mask out in one op
307+
if(r & 1) ptr[_width*2] |= B00000001; // Plane 0 R: 64 bytes ahead, bit 0
308+
if(g & 1) ptr[_width*2] |= B00000010; // Plane 0 G: 64 bytes ahead, bit 1
309+
if(b & 1) ptr[_width] |= B00000001; // Plane 0 B: 32 bytes ahead, bit 0
310+
else ptr[_width] &= ~B00000001; // Plane 0 B unset; mask out
311311
// The remaining three image planes are more normal-ish.
312312
// Data is stored in the high 6 bits so it can be quickly
313313
// copied to the DATAPORT register w/6 output lines.
@@ -323,8 +323,8 @@ void RGBmatrixPanel::drawPixel(int16_t x, int16_t y, uint16_t c) {
323323
// bits, except for the plane 0 stuff, using 2 least bits.
324324
ptr = &matrixbuff[backindex][(y - nRows) * WIDTH * (nPlanes - 1) + x];
325325
*ptr &= ~B00000011; // Plane 0 G,B mask out in one op
326-
if(r & 1) ptr[32] |= B00000010; // Plane 0 R: 32 bytes ahead, bit 1
327-
else ptr[32] &= ~B00000010; // Plane 0 R unset; mask out
326+
if(r & 1) ptr[_width] |= B00000010; // Plane 0 R: 32 bytes ahead, bit 1
327+
else ptr[_width] &= ~B00000010; // Plane 0 R unset; mask out
328328
if(g & 1) *ptr |= B00000001; // Plane 0 G: bit 0
329329
if(b & 1) *ptr |= B00000010; // Plane 0 B: bit 0
330330
for(; bit < limit; bit <<= 1) {
@@ -342,7 +342,7 @@ void RGBmatrixPanel::fillScreen(uint16_t c) {
342342
// For black or white, all bits in frame buffer will be identically
343343
// set or unset (regardless of weird bit packing), so it's OK to just
344344
// quickly memset the whole thing:
345-
memset(matrixbuff[backindex], c, 32 * nRows * 3);
345+
memset(matrixbuff[backindex], c, _width * nRows * 3);
346346
} else {
347347
// Otherwise, need to handle it the long way:
348348
Adafruit_GFX::fillScreen(c);
@@ -367,7 +367,7 @@ void RGBmatrixPanel::swapBuffers(boolean copy) {
367367
swapflag = true; // Set flag here, then...
368368
while(swapflag == true) delay(1); // wait for interrupt to clear it
369369
if(copy == true)
370-
memcpy(matrixbuff[backindex], matrixbuff[1-backindex], 32 * nRows * 3);
370+
memcpy(matrixbuff[backindex], matrixbuff[1-backindex], _width * nRows * 3);
371371
}
372372
}
373373

@@ -378,7 +378,7 @@ void RGBmatrixPanel::swapBuffers(boolean copy) {
378378
// back into the display using a pgm_read_byte() loop.
379379
void RGBmatrixPanel::dumpMatrix(void) {
380380

381-
int i, buffsize = 32 * nRows * 3;
381+
int i, buffsize = _width * nRows * 3;
382382

383383
Serial.print("\n\n"
384384
"#include <avr/pgmspace.h>\n\n"
@@ -543,7 +543,14 @@ void RGBmatrixPanel::updateDisplay(void) {
543543
pew pew pew pew pew pew pew pew
544544
pew pew pew pew pew pew pew pew
545545

546-
buffptr += 32;
546+
if (_width == 64) {
547+
pew pew pew pew pew pew pew pew
548+
pew pew pew pew pew pew pew pew
549+
pew pew pew pew pew pew pew pew
550+
pew pew pew pew pew pew pew pew
551+
}
552+
553+
buffptr = ptr; //+= 32;
547554

548555
} else { // 920 ticks from TCNT1=0 (above) to end of function
549556

@@ -556,11 +563,11 @@ void RGBmatrixPanel::updateDisplay(void) {
556563
// output for plane 0 is handled while plane 3 is being displayed...
557564
// because binary coded modulation is used (not PWM), that plane
558565
// has the longest display interval, so the extra work fits.
559-
for(i=0; i<32; i++) {
566+
for(i=0; i<_width; i++) {
560567
DATAPORT =
561568
( ptr[i] << 6) |
562-
((ptr[i+32] << 4) & 0x30) |
563-
((ptr[i+64] << 2) & 0x0C);
569+
((ptr[i+_width] << 4) & 0x30) |
570+
((ptr[i+_width*2] << 2) & 0x0C);
564571
SCLKPORT = tick; // Clock lo
565572
SCLKPORT = tock; // Clock hi
566573
}

RGBmatrixPanel.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class RGBmatrixPanel : public Adafruit_GFX {
1616

1717
// Constructor for 32x32 panel (adds 'd' pin):
1818
RGBmatrixPanel(uint8_t a, uint8_t b, uint8_t c, uint8_t d,
19-
uint8_t sclk, uint8_t latch, uint8_t oe, boolean dbuf);
19+
uint8_t sclk, uint8_t latch, uint8_t oe, boolean dbuf, uint8_t width=32);
2020

2121
void
2222
begin(void),
@@ -43,7 +43,8 @@ class RGBmatrixPanel : public Adafruit_GFX {
4343

4444
// Init/alloc code common to both constructors:
4545
void init(uint8_t rows, uint8_t a, uint8_t b, uint8_t c,
46-
uint8_t sclk, uint8_t latch, uint8_t oe, boolean dbuf);
46+
uint8_t sclk, uint8_t latch, uint8_t oe, boolean dbuf,
47+
uint8_t width);
4748

4849
// PORT register pointers, pin bitmasks, pin numbers:
4950
volatile uint8_t

0 commit comments

Comments
 (0)