Skip to content

Commit f3e4e32

Browse files
Add Support for Teensy 4.x (#14)
* addressed various compiler warnings * updated environment for platformio development * added support for teensy 4.x
1 parent 84fc5b5 commit f3e4e32

File tree

14 files changed

+188
-65
lines changed

14 files changed

+188
-65
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@
3333
artwork/
3434
test/
3535

36+
# Visual Code + PlatformIO
37+
.pio
38+
.vscode
39+
.travis.yml

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Added a `platformio.ini` file to aid in the development of this library using hte Platform IO environment. This is only useful for developing this library itself, and not at all used for using this library in your projects.
10+
- Added support for Teensy 4.x boards
811

912
## [2.0.1]
1013
### Added

examples/10x10-matrix/color_gradient-10x10/color_gradient-10x10.ino

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ RGBLEDMatrix leds(10,10);
88
void setup() {
99
leds.setup();
1010
leds.startDrawing();
11-
for (int y = 0; y < leds.rows(); y++ ) {
12-
for (int x = 0; x < leds.columns(); x++ ) {
11+
for (unsigned int y = 0; y < leds.rows(); y++ ) {
12+
for (unsigned int x = 0; x < leds.columns(); x++ ) {
1313
float dx = leds.columns() - x - 1;
1414
float dy = leds.rows()-y - 1;
15-
float dmy = leds.rows()/2.0-y;
1615

1716
float d_tl = max(1.0-sqrt(x*x + y*y)/MAX_DISTANCE, 0);
18-
float d_tr = max(1.0-sqrt(dx*dx + y*y)/MAX_DISTANCE, 0);
1917
float d_bl = max(1.0-sqrt(x*x + (leds.rows()-y)*(leds.rows()))/MAX_DISTANCE, 0);
2018
float d_br = max(1.0-sqrt(dx*dx + dy*dy)/MAX_DISTANCE, 0);
21-
float d_rm = max(1.0-sqrt(dx*dx + dmy*dmy)/(MAX_DISTANCE*3.0/4.0), 0);
2219

2320
RGBColorType c = RGBColor::fromRGB( d_tl*255, d_br*194, d_bl*255);
2421
leds.writePixel(x, y, c);

examples/10x10-matrix/dot-chaser-10x10/dot-chaser-10x10.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ private:
88
int _xVel;
99
int _yVel;
1010

11-
int _xStack[5] = {-1,-1,-1,-1,-1};
12-
int _yStack[5] = {-1,-1,-1,-1,-1};
11+
unsigned int _xStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
12+
unsigned int _yStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
1313

1414

1515
protected:
1616
virtual void action() {
1717
_screen->startDrawing();
18-
for (int x = 0; x < _screen->columns(); ++x) {
19-
for (int y = 0; y < _screen->rows(); ++y ) {
18+
for (unsigned int x = 0; x < _screen->columns(); ++x) {
19+
for (unsigned int y = 0; y < _screen->rows(); ++y ) {
2020
RGBColorType color = 0;
2121
if ( x == _xStack[4] && y == _yStack[4] ) {
2222
color = DARK_BLUE_COLOR;

examples/16x16-matrix/color_gradient-16x16-cprg/color_gradient-16x16-cprg.ino

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@ RGBLEDMatrix leds(16,16, RGBLEDMatrix::RGB_GROUPS_CPRG8, HIGH, LOW, 3);
88
void setup() {
99
leds.setup();
1010
leds.startDrawing();
11-
for (int y = 0; y < leds.rows(); y++ ) {
12-
for (int x = 0; x < leds.columns(); x++ ) {
11+
for (unsigned int y = 0; y < leds.rows(); y++ ) {
12+
for (unsigned int x = 0; x < leds.columns(); x++ ) {
1313
float dx = leds.columns() - x - 1;
1414
float dy = leds.rows()-y - 1;
15-
float dmy = leds.rows()/2.0-y;
1615

1716
float d_tl = max(1.0-sqrt(x*x + y*y)/MAX_DISTANCE, 0);
18-
float d_tr = max(1.0-sqrt(dx*dx + y*y)/MAX_DISTANCE, 0);
1917
float d_bl = max(1.0-sqrt(x*x + (leds.rows()-y)*(leds.rows()))/MAX_DISTANCE, 0);
2018
float d_br = max(1.0-sqrt(dx*dx + dy*dy)/MAX_DISTANCE, 0);
21-
float d_rm = max(1.0-sqrt(dx*dx + dmy*dmy)/(MAX_DISTANCE*3.0/4.0), 0);
22-
19+
2320
RGBColorType c = RGBColor::fromRGB( d_tl*255, d_br*194, d_bl*255);
2421
leds.writePixel(x, y, c);
2522
}

examples/16x16-matrix/conway-game-of-life-16x16-cprg/conway-game-of-life-16x16-cprg.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ void CellUniverse::setCellStatus(unsigned int row, unsigned int column, LifeStat
8383

8484
CellUniverse::LifeState CellUniverse::getCellStatus(int row, int column) const {
8585
// this causes the matrix to be a toroidal array
86-
unsigned int r = row < 0 ? row + _leds.rows() : ( row >= _leds.rows() ? row - _leds.rows() : row );
87-
unsigned int c = column < 0 ? column + _leds.columns() : ( column >= _leds.columns() ? column - _leds.columns() : column );
86+
unsigned int r = row < 0 ? row + _leds.rows() : ( row >= (int)_leds.rows() ? row - _leds.rows() : row );
87+
unsigned int c = column < 0 ? column + _leds.columns() : ( column >= (int)_leds.columns() ? column - _leds.columns() : column );
8888

8989
// double check just to be sure
9090
if (r >= _leds.rows() || c >= _leds.columns()) {

examples/16x16-matrix/dot-chaser-16x16-cprg/dot-chaser-16x16-cprg.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ private:
88
int _xVel;
99
int _yVel;
1010

11-
int _xStack[5] = {-1,-1,-1,-1,-1};
12-
int _yStack[5] = {-1,-1,-1,-1,-1};
11+
unsigned int _xStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
12+
unsigned int _yStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
1313

1414

1515
protected:
1616
virtual void action() {
1717
_screen->startDrawing();
18-
for (int x = 0; x < _screen->rows(); ++x) {
19-
for (int y = 0; y < _screen->columns(); ++y ) {
18+
for (unsigned int x = 0; x < _screen->rows(); ++x) {
19+
for (unsigned int y = 0; y < _screen->columns(); ++y ) {
2020
RGBColorType color = 0;
2121
if ( x == _xStack[4] && y == _yStack[4] ) {
2222
color = DARK_BLUE_COLOR;

examples/16x16-matrix/plasma-16x16-cprg/plasma-16x16-cprg.ino

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,42 +88,35 @@ void setup() {
8888
leds.startScanning();
8989
}
9090

91-
unsigned long loopCounter = 0;
9291
unsigned long timeCount = 0;
9392
bool timeIncrement = true;
9493

95-
#if (defined(__arm__)&& defined(TEENSYDUINO) || defined(ESP32))
96-
// slow things down for the Teensy
97-
const unsigned long loopMod = 10000;
98-
#else
99-
const unsigned long loopMod = 50;
100-
#endif
101-
10294
void loop() {
10395
leds.loop();
104-
loopCounter++;
10596

106-
if (loopCounter == loopMod) {
107-
if (timeIncrement) {
108-
timeCount++;
109-
110-
//
111-
// set a maximum to timeCount because floats only have
112-
// a max precision of 5 significant digits. Otherwise, when timeCount
113-
// gets too large, the animation will get choppy because calls to drawPlasma()
114-
// will not have a noticable change to timeCount/TIME_DILATION. for several
115-
// consecutive calls.
116-
//
117-
if (timeCount >= 1000*PI) {
118-
timeIncrement = false;
119-
}
120-
} else {
121-
timeCount--;
122-
if (timeCount == 0) {
123-
timeIncrement = true;
124-
}
97+
// update frame every 40 milleseconds. AVR chips are slow enough to not need this delay.
98+
#if !defined(ARDUINO_ARCH_AVR)
99+
delay(40);
100+
#endif
101+
102+
if (timeIncrement) {
103+
timeCount++;
104+
105+
//
106+
// set a maximum to timeCount because floats only have
107+
// a max precision of 5 significant digits. Otherwise, when timeCount
108+
// gets too large, the animation will get choppy because calls to drawPlasma()
109+
// will not have a noticable change to timeCount/TIME_DILATION. for several
110+
// consecutive calls.
111+
//
112+
if (timeCount >= 1000*PI) {
113+
timeIncrement = false;
114+
}
115+
} else {
116+
timeCount--;
117+
if (timeCount == 0) {
118+
timeIncrement = true;
125119
}
126-
drawPlasma(timeCount);
127-
loopCounter = 0;
128120
}
121+
drawPlasma(timeCount);
129122
}

examples/8x8-matrix/color_gradient-8x8/color_gradient-8x8.ino

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ RGBLEDMatrix leds(8,8);
88
void setup() {
99
leds.setup();
1010
leds.startDrawing();
11-
for (int y = 0; y < leds.rows(); y++ ) {
12-
for (int x = 0; x < leds.columns(); x++ ) {
11+
for (unsigned int y = 0; y < leds.rows(); y++ ) {
12+
for (unsigned int x = 0; x < leds.columns(); x++ ) {
1313
float dx = leds.columns() - x - 1;
1414
float dy = leds.rows()-y - 1;
15-
float dmy = leds.rows()/2.0-y;
1615

1716
float d_tl = max(1.0-sqrt(x*x + y*y)/MAX_DISTANCE, 0);
18-
float d_tr = max(1.0-sqrt(dx*dx + y*y)/MAX_DISTANCE, 0);
1917
float d_bl = max(1.0-sqrt(x*x + (leds.rows()-y)*(leds.rows()))/MAX_DISTANCE, 0);
2018
float d_br = max(1.0-sqrt(dx*dx + dy*dy)/MAX_DISTANCE, 0);
21-
float d_rm = max(1.0-sqrt(dx*dx + dmy*dmy)/(MAX_DISTANCE*3.0/4.0), 0);
2219

2320
RGBColorType c = RGBColor::fromRGB( d_tl*255, d_br*194, d_bl*255);
2421
leds.writePixel(x, y, c);

examples/8x8-matrix/dot-chaser-8x8/dot-chaser-8x8.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ private:
88
int _xVel;
99
int _yVel;
1010

11-
int _xStack[5] = {-1,-1,-1,-1,-1};
12-
int _yStack[5] = {-1,-1,-1,-1,-1};
11+
unsigned int _xStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
12+
unsigned int _yStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
1313

1414

1515
protected:
1616
virtual void action() {
1717
_screen->startDrawing();
18-
for (int x = 0; x < _screen->rows(); ++x) {
19-
for (int y = 0; y < _screen->columns(); ++y ) {
18+
for (unsigned int x = 0; x < _screen->rows(); ++x) {
19+
for (unsigned int y = 0; y < _screen->columns(); ++y ) {
2020
RGBColorType color = 0;
2121
if ( x == _xStack[4] && y == _yStack[4] ) {
2222
color = DARK_BLUE_COLOR;

platformio.ini

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
; This PlatformIO onfiguration is for development on this library only,
2+
; not for usage of this library in other projects.
3+
4+
[platformio]
5+
src_dir = examples/16x16-matrix/plasma-16x16-cprg
6+
default_envs = teensy40
7+
lib_dir = .
8+
9+
[common]
10+
lib_deps =
11+
Adafruit GFX Library
12+
SPI
13+
Wire
14+
15+
[env:teensy40]
16+
platform = teensy
17+
board = teensy40
18+
framework = arduino
19+
lib_deps =
20+
TimerThree
21+
${common.lib_deps}
22+
build_flags = -Wno-unknown-pragmas
23+
24+
[env:teensy31]
25+
platform = teensy
26+
board = teensy31
27+
framework = arduino
28+
lib_deps =
29+
TimerThree
30+
${common.lib_deps}
31+
build_flags = -Wno-unknown-pragmas
32+
33+
[env:esp8266]
34+
platform = espressif8266
35+
board = nodemcuv2
36+
framework = arduino
37+
lib_deps =
38+
${common.lib_deps}
39+
40+
[env:lolin32]
41+
platform = espressif32
42+
board = lolin32
43+
framework = arduino
44+
lib_deps =
45+
${common.lib_deps}
46+
47+
[env:MightyCore]
48+
platform = atmelavr
49+
board = ATmega1284P
50+
framework = arduino
51+
lib_deps =
52+
${common.lib_deps}
53+
54+
; Clock frequency in [Hz]
55+
board_build.f_cpu = 20000000L
56+
57+
; HARDWARE SETTINGS
58+
; Oscillator option
59+
board_hardware.oscillator = external
60+
; Hardware UART for serial upload
61+
board_hardware.uart = uart0
62+
; Brown-out detection
63+
board_hardware.bod = 2.7v
64+
; EEPROM retain
65+
board_hardware.eesave = yes
66+
67+
; UPLOAD SETTINGS
68+
board_upload.speed = 115200
69+
; Upload serial port is automatically detected by default. Override by uncommenting the line below
70+
;upload_port = /dev/cu.usbserial*
71+
72+
; BUILD OPTIONS
73+
; Current pinout
74+
board_build.variant = standard
75+
; Comment out to enable LTO (this line unflags it)
76+
build_unflags = -flto
77+
78+
; Extra build flags
79+
build_flags = -Wno-unknown-pragmas
80+
81+
82+
; Upload using programmer
83+
;upload_protocol = usbasp
84+
; Aditional upload flags
85+
;upload_flags = -Pusb
86+
87+
; SERIAL MONITOR OPTIONS
88+
; Monitor and upload port is the same by default
89+
;monitor_port =
90+
; Serial monitor baud rate
91+
monitor_speed = 9600

src/BaseLEDMatrix.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,51 @@ void BaseLEDMatrix::debugPrintFrames( void ) const {
240240
*/
241241

242242
#pragma mark Teensy Handlers
243-
#if (defined(__arm__) && defined(TEENSYDUINO))
243+
#if ((defined(__IMXRT1062__)||defined(__arm__)) && defined(TEENSYDUINO))
244+
#if defined(__IMXRT1062__)
245+
// Use IntervalTimer on Teensy 4+ to drive scan timing
246+
#include <IntervalTimer.h>
247+
248+
IntervalTimer ledMatrixTimer;
249+
250+
void timerInteruptHandler( void ) {
251+
ledMatrixTimer.end();
252+
253+
if (gSingleton->doInterFrameTransmitOff()) {
254+
gSingleton->shiftOutAllOff();
255+
256+
// reload the timer
257+
ledMatrixTimer.begin(timerInteruptHandler, gSingleton->rowOffTimerInterval());
258+
} else {
259+
gSingleton->shiftOutCurrentControlRow();
260+
261+
// reload the timer
262+
ledMatrixTimer.begin(timerInteruptHandler, gSingleton->nextRowScanTimerInterval());
263+
// update scan row. Done outside of interrupt stoppage since execution time can
264+
// be inconsistent, which would lead to vary brightness in rows.
265+
gSingleton->incrementScanRow();
266+
}
267+
}
268+
269+
void BaseLEDMatrix::startScanning(void) {
270+
this->setup();
271+
272+
_interFrameOffTimeInterval = _interFrameOffTimeMicros;
273+
274+
ledMatrixTimer.begin(timerInteruptHandler, gSingleton->nextRowScanTimerInterval());
275+
}
276+
277+
void BaseLEDMatrix::stopScanning(void) {
278+
ledMatrixTimer.end();
279+
}
280+
281+
unsigned int BaseLEDMatrix::nextRowScanTimerInterval(void) const {
282+
// Calculates the microseconds for each scan
283+
return 10*this->baseIntervalMultiplier( _scanPass );
284+
}
285+
#else
244286
//
245-
// On the Teensy ARM boards, use the TimerThree library to drive scan timing
287+
// On the Teensy 3.x boards, use the TimerThree library to drive scan timing
246288
//
247289
#include <TimerThree.h>
248290

@@ -286,6 +328,7 @@ unsigned int BaseLEDMatrix::nextRowScanTimerInterval(void) const {
286328
// Calculates the microseconds for each scan
287329
return 10*this->baseIntervalMultiplier( _scanPass );
288330
}
331+
#endif // #if defined(__IMXRT1062__)
289332

290333
#pragma mark ESP32 Handlers
291334
#elif defined ( ESP32 )

src/RGBAnimation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ ColorBitmapSequenceAnimation::ColorBitmapSequenceAnimation(
8787
}
8888

8989
void ColorBitmapSequenceAnimation::erase(RGBLEDMatrix& matrix) {
90-
int idx = this->getSequenceIndex();
91-
9290
matrix.writeFillRect(
9391
this->getOriginX() - _leftPadSize,
9492
this->getOriginY() - _topPadSize,

src/RGBLEDMatrix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool RGBLEDMatrix::allowedFrameForValue(uint16_t value, size_t frame) const {
9191
// green has a bit specific to this pass, on for that.
9292
return ( (value&0x0040) != 0 ) ||
9393
// only one for red and blue if both the prior pass and next pass are on
94-
(value&0x1800 == 0x1800) || (value&0x0003 == 0x0003);
94+
((value&0x1800) == 0x1800) || ((value&0x0003) == 0x0003);
9595
break;
9696
case 2:
9797
// red bit 2, green bit 3, blue bit 2

0 commit comments

Comments
 (0)