Skip to content

Commit 90ac761

Browse files
committed
Merge remote-tracking branch 'adafruit/master'
2 parents 5f718bd + 8570b7a commit 90ac761

File tree

3 files changed

+152
-23
lines changed

3 files changed

+152
-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
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// testshapes demo for RGBmatrixPanel library.
2+
// Demonstrates the drawing abilities of the RGBmatrixPanel library.
3+
// For 32x32 RGB LED matrix.
4+
5+
// NOTE THIS CAN ONLY BE USED ON A MEGA! NOT ENOUGH RAM ON UNO!
6+
7+
#include <Adafruit_GFX.h> // Core graphics library
8+
#include <RGBmatrixPanel.h> // Hardware-specific library
9+
10+
// If your 32x32 matrix has the SINGLE HEADER input,
11+
// use this pinout:
12+
#define CLK 12 // MUST be on PORTB!
13+
#define OE 13
14+
#define LAT A0
15+
16+
#define A 10
17+
#define B A2
18+
#define C 11
19+
#define D A1
20+
21+
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);
22+
23+
void setup() {
24+
25+
matrix.begin();
26+
27+
// draw a pixel in solid white
28+
matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
29+
delay(500);
30+
31+
// fix the screen with green
32+
matrix.fillRect(0, 0, matrix.width(), matrix.height(), matrix.Color333(0, 7, 0));
33+
delay(500);
34+
35+
// draw a box in yellow
36+
matrix.drawRect(0, 0, matrix.width(), matrix.height(), matrix.Color333(7, 7, 0));
37+
delay(500);
38+
39+
// draw an 'X' in red
40+
matrix.drawLine(0, 0, matrix.width()-1, matrix.height()-1, matrix.Color333(7, 0, 0));
41+
matrix.drawLine(matrix.width()-1, 0, 0, matrix.height()-1, matrix.Color333(7, 0, 0));
42+
delay(500);
43+
44+
// draw a blue circle
45+
matrix.drawCircle(10, 10, 10, matrix.Color333(0, 0, 7));
46+
delay(500);
47+
48+
// fill a violet circle
49+
matrix.fillCircle(40, 21, 10, matrix.Color333(7, 0, 7));
50+
delay(500);
51+
52+
// fill the screen with 'black'
53+
matrix.fillScreen(matrix.Color333(0, 0, 0));
54+
55+
// draw some text!
56+
matrix.setTextSize(1); // size 1 == 8 pixels high
57+
matrix.setTextWrap(false); // Don't wrap at end of line - will do ourselves
58+
59+
matrix.setCursor(8, 0); // start at top left, with 8 pixel of spacing
60+
uint8_t w = 0;
61+
char *str = "AdafruitIndustries";
62+
for (w=0; w<8; w++) {
63+
matrix.setTextColor(Wheel(w));
64+
matrix.print(str[w]);
65+
}
66+
matrix.setCursor(2, 8); // next line
67+
for (w=8; w<18; w++) {
68+
matrix.setTextColor(Wheel(w));
69+
matrix.print(str[w]);
70+
}
71+
matrix.println();
72+
//matrix.setTextColor(matrix.Color333(4,4,4));
73+
//matrix.println("Industries");
74+
matrix.setTextColor(matrix.Color333(7,7,7));
75+
matrix.println("LED MATRIX!");
76+
77+
// print each letter with a rainbow color
78+
matrix.setTextColor(matrix.Color333(7,0,0));
79+
matrix.print('3');
80+
matrix.setTextColor(matrix.Color333(7,4,0));
81+
matrix.print('2');
82+
matrix.setTextColor(matrix.Color333(7,7,0));
83+
matrix.print('x');
84+
matrix.setTextColor(matrix.Color333(4,7,0));
85+
matrix.print('6');
86+
matrix.setTextColor(matrix.Color333(0,7,0));
87+
matrix.print('4');
88+
matrix.setCursor(34, 24);
89+
matrix.setTextColor(matrix.Color333(0,7,7));
90+
matrix.print("*");
91+
matrix.setTextColor(matrix.Color333(0,4,7));
92+
matrix.print('R');
93+
matrix.setTextColor(matrix.Color333(0,0,7));
94+
matrix.print('G');
95+
matrix.setTextColor(matrix.Color333(4,0,7));
96+
matrix.print("B");
97+
matrix.setTextColor(matrix.Color333(7,0,4));
98+
matrix.println("*");
99+
100+
101+
// whew!
102+
}
103+
104+
void loop() {
105+
// do nothing
106+
}
107+
108+
109+
// Input a value 0 to 24 to get a color value.
110+
// The colours are a transition r - g - b - back to r.
111+
uint16_t Wheel(byte WheelPos) {
112+
if(WheelPos < 8) {
113+
return matrix.Color333(7 - WheelPos, WheelPos, 0);
114+
} else if(WheelPos < 16) {
115+
WheelPos -= 8;
116+
return matrix.Color333(0, 7-WheelPos, WheelPos);
117+
} else {
118+
WheelPos -= 16;
119+
return matrix.Color333(0, WheelPos, 7 - WheelPos);
120+
}
121+
}

0 commit comments

Comments
 (0)