Skip to content

Commit e97356e

Browse files
Added support for Adafruit_GFX
1 parent bf0637b commit e97356e

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ A replacement for Arduino's LedControl library.
77
- Writing to the display is controlled by the software,
88
- Much, much faster (as it uses hardware SPI with soft SS)
99
- Can use an external memory or self-allocated buffer
10+
- (Optional) support for Adafruit_GFX library - use -DUSE_ADAFTUIT_GFX to enable.
1011

1112
## Pin selection
1213
Each segment of the display needs 16 bits and they can all be shifted in at once.

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=LEDMatrixDriver
2-
version=0.1.2
2+
version=0.2.0
33
author=Bartosz Bielawski
44
maintainer=Bartosz Bielawski, bartosz.bielawski@gmail.com
55
sentence=A replacement for Arduino's LedControl library for MAX7219

src/LEDMatrixDriver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <Arduino.h>
1010

1111
LEDMatrixDriver::LEDMatrixDriver(uint8_t N, uint8_t ssPin, uint8_t* frameBuffer_):
12+
#ifdef USE_ADAFRUIT_GFX
13+
Adafruit_GFX(N*8, N),
14+
#endif
1215
N(N),
1316
spiSettings(5000000, MSBFIRST, SPI_MODE0),
1417
frameBuffer(frameBuffer_),
@@ -175,7 +178,6 @@ uint8_t* LEDMatrixDriver::_getBufferPtr(uint16_t x, uint16_t y) const
175178
return nullptr;
176179

177180
uint16_t B = x >> 3; //byte
178-
uint16_t b = 7 - (x & 7); //bit
179181

180182
return frameBuffer + y*N + B;
181183
}
@@ -191,7 +193,6 @@ void LEDMatrixDriver::display()
191193
void LEDMatrixDriver::scroll( scrollDirection direction )
192194
{
193195
int cnt = 0;
194-
uint8_t* buf = NULL;
195196
switch( direction )
196197
{
197198
case scrollDirection::scrollUp:

src/LEDMatrixDriver.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121

2222
#include <SPI.h>
2323

24+
#ifdef ESP32
25+
#include <cstring>
26+
#endif
27+
28+
#ifdef USE_ADAFRUIT_GFX
29+
#include <Adafruit_GFX.h>
30+
class LEDMatrixDriver: public Adafruit_GFX
31+
#else
2432
class LEDMatrixDriver
33+
#endif
2534
{
2635
//commands as defined in the datasheet
2736
const static uint16_t ENABLE = 0x0C00;
@@ -42,6 +51,13 @@ class LEDMatrixDriver
4251
LEDMatrixDriver(LEDMatrixDriver&& other) = delete;
4352
LEDMatrixDriver& operator=(const LEDMatrixDriver& other) = delete;
4453

54+
#ifdef USE_ADAFRUIT_GFX
55+
virtual void writePixel(int16_t x, int16_t y, uint16_t color) {setPixel(x,y,color);}
56+
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) {setPixel(x,y,color);}
57+
virtual void endWrite(void) {if (not manualDisplayRefresh) display();}
58+
void setManualDisplayRefresh(bool enabled) {manualDisplayRefresh = enabled;}
59+
#endif
60+
4561
//all these commands work on ALL segments
4662
void setEnabled(bool enabled);
4763
void setIntensity(uint8_t level);
@@ -92,6 +108,10 @@ class LEDMatrixDriver
92108
uint8_t* frameBuffer;
93109
bool selfAllocated;
94110
uint8_t ssPin;
111+
112+
#ifdef USE_ADAFRUIT_GFX
113+
bool manualDisplayRefresh = true;
114+
#endif
95115
};
96116

97117
#endif /* LEDMATRIXDRIVER_H_ */

0 commit comments

Comments
 (0)