Skip to content

Commit 7f2759c

Browse files
Merge branch 'master' of github.com:michaelkamprath/ShiftRegisterLEDMatrixLib
2 parents 7ed444b + 19b8768 commit 7f2759c

File tree

13 files changed

+84
-28
lines changed

13 files changed

+84
-28
lines changed

examples/conway-game-of-life-10x10/conway-game-of-life-10x10.ino

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public:
5454
);
5555

5656
void setCellStatus(unsigned int row, unsigned int column, LifeState cellStatus);
57-
LifeState getCellStatus(unsigned int row, unsigned int column) const;
57+
LifeState getCellStatus(int row, int column) const;
5858
void createRandomState();
5959

60-
bool isAlive(unsigned int row, unsigned int column) const;
61-
int countAliveNeighbors(unsigned int row, unsigned int column) const;
60+
bool isAlive(int row, int column) const;
61+
int countAliveNeighbors(int row, int column) const;
6262

6363
void drawToScreen();
6464
};
@@ -86,13 +86,13 @@ void CellUniverse::setCellStatus(unsigned int row, unsigned int column, LifeStat
8686
_cells[idx] = cellStatus;
8787
}
8888

89-
CellUniverse::LifeState CellUniverse::getCellStatus(unsigned int row, unsigned int column) const {
89+
CellUniverse::LifeState CellUniverse::getCellStatus(int row, int column) const {
9090
// this causes the matrix to be a toroidal array
9191
unsigned int r = row < 0 ? row + _leds.rows() : ( row >= _leds.rows() ? row - _leds.rows() : row );
9292
unsigned int c = column < 0 ? column + _leds.columns() : ( column >= _leds.columns() ? column - _leds.columns() : column );
9393

9494
// double check just to be sure
95-
if (r < 0 || r >= _leds.rows() || c < 0 || c >= _leds.columns()) {
95+
if (r >= _leds.rows() || c >= _leds.columns()) {
9696
return CellUniverse::DEAD;
9797
}
9898

@@ -101,15 +101,15 @@ CellUniverse::LifeState CellUniverse::getCellStatus(unsigned int row, unsigned i
101101
return _cells[idx];
102102
}
103103

104-
bool CellUniverse::isAlive(unsigned int row, unsigned int column) const {
104+
bool CellUniverse::isAlive(int row, int column) const {
105105
return (this->getCellStatus(row, column) == CellUniverse::ALIVE || this->getCellStatus(row, column) == CellUniverse::BORN);
106106
}
107107

108-
int CellUniverse::countAliveNeighbors(unsigned int row, unsigned int column) const {
108+
int CellUniverse::countAliveNeighbors(int row, int column) const {
109109
int aliveCount = 0;
110110

111-
for (unsigned int x = column - 1; x <= column+1; x++) {
112-
for (unsigned int y = row - 1; y <= row + 1; y++ ) {
111+
for (int x = column - 1; x <= column+1; x++) {
112+
for (int y = row - 1; y <= row + 1; y++ ) {
113113
if (this->isAlive(y, x) && !(x == column && y == row)) {
114114
aliveCount++;
115115
}

examples/conway-game-of-life-8x8/conway-game-of-life-8x8.ino

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public:
5454
);
5555

5656
void setCellStatus(unsigned int row, unsigned int column, LifeState cellStatus);
57-
LifeState getCellStatus(unsigned int row, unsigned int column) const;
57+
LifeState getCellStatus(int row, int column) const;
5858
void createRandomState();
5959

60-
bool isAlive(unsigned int row, unsigned int column) const;
61-
int countAliveNeighbors(unsigned int row, unsigned int column) const;
60+
bool isAlive(int row, int column) const;
61+
int countAliveNeighbors(int row, int column) const;
6262

6363
void drawToScreen();
6464
};
@@ -77,7 +77,7 @@ CellUniverse::CellUniverse(
7777
}
7878

7979
void CellUniverse::setCellStatus(unsigned int row, unsigned int column, LifeState cellStatus) {
80-
if (row < 0 || row >= _leds.rows() || column < 0 || column >= _leds.columns()) {
80+
if (row >= _leds.rows() || column >= _leds.columns()) {
8181
return;
8282
}
8383

@@ -86,13 +86,13 @@ void CellUniverse::setCellStatus(unsigned int row, unsigned int column, LifeStat
8686
_cells[idx] = cellStatus;
8787
}
8888

89-
CellUniverse::LifeState CellUniverse::getCellStatus(unsigned int row, unsigned int column) const {
89+
CellUniverse::LifeState CellUniverse::getCellStatus(int row, int column) const {
9090
// this causes the matrix to be a toroidal array
9191
unsigned int r = row < 0 ? row + _leds.rows() : ( row >= _leds.rows() ? row - _leds.rows() : row );
9292
unsigned int c = column < 0 ? column + _leds.columns() : ( column >= _leds.columns() ? column - _leds.columns() : column );
9393

9494
// double check just to be sure
95-
if (r < 0 || r >= _leds.rows() || c < 0 || c >= _leds.columns()) {
95+
if (r >= _leds.rows() || c >= _leds.columns()) {
9696
return CellUniverse::DEAD;
9797
}
9898

@@ -101,15 +101,15 @@ CellUniverse::LifeState CellUniverse::getCellStatus(unsigned int row, unsigned i
101101
return _cells[idx];
102102
}
103103

104-
bool CellUniverse::isAlive(unsigned int row, unsigned int column) const {
104+
bool CellUniverse::isAlive(int row, int column) const {
105105
return (this->getCellStatus(row, column) == CellUniverse::ALIVE || this->getCellStatus(row, column) == CellUniverse::BORN);
106106
}
107107

108-
int CellUniverse::countAliveNeighbors(unsigned int row, unsigned int column) const {
108+
int CellUniverse::countAliveNeighbors(int row, int column) const {
109109
int aliveCount = 0;
110110

111-
for (unsigned int x = column - 1; x <= column+1; x++) {
112-
for (unsigned int y = row - 1; y <= row + 1; y++ ) {
111+
for (int x = column - 1; x <= column+1; x++) {
112+
for (int y = row - 1; y <= row + 1; y++ ) {
113113
if (this->isAlive(y, x) && !(x == column && y == row)) {
114114
aliveCount++;
115115
}

examples/plasma-10x10/plasma-10x10.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ unsigned long loopCounter = 0;
8787
unsigned long timeCount = 0;
8888
bool timeIncrement = true;
8989

90-
#if (defined(__arm__)&& defined(TEENSYDUINO))
91-
// slow things down for the Teensy
90+
#if (defined(__arm__)&& defined(TEENSYDUINO))||(defined( ESP32 ))
91+
// slow things down for the Teensy and other fast microcontrollers
9292
const unsigned long loopMod = 20000;
9393
#else
94-
const unsigned long loopMod = 50;
94+
const unsigned long loopMod = 500;
9595
#endif
9696

9797
void loop() {

examples/plasma-8x8/plasma-8x8.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ unsigned long loopCounter = 0;
8787
unsigned long timeCount = 0;
8888
bool timeIncrement = true;
8989

90-
#if (defined(__arm__)&& defined(TEENSYDUINO))
91-
// slow things down for the Teensy
90+
#if (defined(__arm__)&& defined(TEENSYDUINO))||(defined( ESP32 ))
91+
// slow things down for the Teensy and other fast microcontrollers
9292
const unsigned long loopMod = 20000;
9393
#else
9494
const unsigned long loopMod = 500;

src/BaseLEDMatrix.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,53 @@ unsigned int BaseLEDMatrix::nextRowScanTimerInterval(void) const {
225225
return 100*this->baseIntervalMultiplier( _scanPass );
226226
}
227227

228+
#pragma mark ESP32 Handlers
229+
#elif defined ( ESP32 )
230+
hw_timer_t * timer = NULL;
231+
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
232+
233+
void IRAM_ATTR onTimer() {
234+
portENTER_CRITICAL_ISR(&timerMux);
235+
timerStop(timer);
236+
if (gSingleton->doInterFrameTransmitOff()) {
237+
gSingleton->shiftOutAllOff();
238+
} else {
239+
gSingleton->shiftOutCurrentRow();
240+
241+
// update scan row. Done outside of interrupt stoppage since execution time can
242+
// be inconsistent, which would lead to vary brightness in rows.
243+
gSingleton->incrementScanRow();
244+
}
245+
timerAlarmWrite(timer, gSingleton->nextRowScanTimerInterval(), true);
246+
timerRestart(timer);
247+
portEXIT_CRITICAL_ISR(&timerMux);
248+
}
249+
250+
void BaseLEDMatrix::startScanning(void) {
251+
this->setup();
252+
253+
_interFrameOffTimeInterval = _interFrameOffTimeMicros;
254+
255+
noInterrupts();
256+
257+
// this sets the timer to count every 1 micro seconds. use timer 3 for best compatibility
258+
timer = timerBegin(3, 80, true);
259+
timerAttachInterrupt(timer, &onTimer, true);
260+
timerAlarmWrite(timer, this->nextRowScanTimerInterval(), true);
261+
timerAlarmEnable(timer);
262+
263+
interrupts();
264+
}
265+
266+
void BaseLEDMatrix::stopScanning(void) {
267+
timerEnd(timer);
268+
}
269+
270+
unsigned int BaseLEDMatrix::nextRowScanTimerInterval(void) const {
271+
// this sets the interrupt to fire a multiple every 25 timer counts, or 25 microseconds
272+
return 25*this->baseIntervalMultiplier( _scanPass );
273+
}
274+
228275
#pragma mark ESP8266 Handlers
229276
#elif defined ( ESP8266 )
230277

src/BaseLEDMatrix.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ class BaseLEDMatrix : public TimerAction {
112112
bool columnControlBitOn = LOW,
113113
bool rowControlBitOn = LOW,
114114
unsigned int interFrameOffTimeMicros = 0,
115-
#if defined ( ESP8266 )
115+
#if defined( ESP8266 )
116116
int slavePin = D8
117+
#elif defined( ESP32 )
118+
int slavePin = 5
117119
#else
118120
int slavePin = 10
119121
#endif

src/Glyph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// along with Shift Register LED Matrix Project. If not, see <http://www.gnu.org/licenses/>.
1818

1919
#include <Arduino.h>
20-
#if defined ( ESP8266 )
20+
#if defined( ESP8266 ) || defined( ESP32 )
2121
#include <pgmspace.h>
2222
#else
2323
#include <avr/pgmspace.h>

src/GrayScaleLEDMatrix.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class GrayScaleLEDMatrix : public BaseLEDMatrix {
7171
unsigned int interFrameOffTimeMicros = 0,
7272
#if defined ( ESP8266 )
7373
int slavePin = D8
74+
#elif defined( ESP32 )
75+
int slavePin = 5
7476
#else
7577
int slavePin = 10
7678
#endif

src/LEDImage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#include <Arduino.h>
3333
#include <string.h>
34-
#if defined ( ESP8266 )
34+
#if defined( ESP8266 ) || defined( ESP32 )
3535
#include <pgmspace.h>
3636
#else
3737
#include <avr/pgmspace.h>

src/LEDMatrix.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class LEDMatrix : public BaseLEDMatrix {
7171
unsigned int interFrameOffTimeMicros = 0,
7272
#if defined ( ESP8266 )
7373
int slavePin = D8
74+
#elif defined( ESP32 )
75+
int slavePin = 5
7476
#else
7577
int slavePin = 10
7678
#endif

0 commit comments

Comments
 (0)