Skip to content

Commit 53034d7

Browse files
added support for ATmega1284 mcu
1 parent e8fab32 commit 53034d7

File tree

7 files changed

+44
-36
lines changed

7 files changed

+44
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
### Added
1313
- Added support for the Arduino Zero and Due boards (and related)
1414
- Added support for older ATmega8535, ATmega16 and ATmega32 microcontrollers
15+
- Added support for ATmega1284 and ATmega1284P microcontrollers
1516
- Added method to LEDImage for drawing circles
1617
- Added a Red-Blue-Green bit layout mode for the RGB matrix object
1718

src/BaseLEDMatrix.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ ICACHE_RAM_ATTR void BaseLEDMatrix::incrementScanRow( void ) {
129129
}
130130

131131
// Number of 5 microsecond units
132-
ICACHE_RAM_ATTR unsigned int BaseLEDMatrix::multiplier5microseconds( size_t frame ) const {
132+
ICACHE_RAM_ATTR unsigned int BaseLEDMatrix::baseIntervalMultiplier( size_t frame ) const {
133133
// base case does nothing interesting
134134
return 1;
135135
}
@@ -182,7 +182,7 @@ void BaseLEDMatrix::stopScanning(void) {
182182

183183
unsigned int BaseLEDMatrix::nextTimerInterval(void) const {
184184
// Calculates the microseconds for each scan
185-
return 5*this->multiplier5microseconds( _scanPass );
185+
return 5*this->baseIntervalMultiplier( _scanPass );
186186
}
187187

188188
#pragma mark ESP8266 Handlers
@@ -227,7 +227,7 @@ void BaseLEDMatrix::stopScanning(void) {
227227

228228
ICACHE_RAM_ATTR unsigned int BaseLEDMatrix::nextTimerInterval(void) const {
229229
// Calculates the microseconds for each scan
230-
return 5*this->multiplier5microseconds( _scanPass );
230+
return 5*this->baseIntervalMultiplier( _scanPass );
231231
}
232232

233233
#pragma mark Arduino Due Handlers
@@ -259,7 +259,7 @@ unsigned int BaseLEDMatrix::nextTimerInterval(void) const {
259259
// Calculates the microseconds for each scan
260260
// The base interval is set to 55, which for the
261261
// 10.5MHz CLOCK2 yields a ~5 micro second interval.
262-
return 55*this->multiplier5microseconds( _scanPass );
262+
return 55*this->baseIntervalMultiplier( _scanPass );
263263
}
264264

265265
void BaseLEDMatrix::stopScanning(void) {
@@ -325,7 +325,7 @@ unsigned int BaseLEDMatrix::nextTimerInterval(void) const {
325325
// Calculates the microseconds for each scan
326326
// The base interval is set to 59, which with a /4
327327
// prescaler should yield a 5 ms interval.
328-
return 59*this->multiplier5microseconds( _scanPass );
328+
return 59*this->baseIntervalMultiplier( _scanPass );
329329
}
330330

331331
void BaseLEDMatrix::stopScanning(void) {
@@ -372,20 +372,19 @@ void BaseLEDMatrix::startScanning(void) {
372372
this->setup();
373373

374374
noInterrupts(); // disable all interrupts
375-
376-
TIMSK2 &= ~(1<<TOIE2); // disable timer overflow interupt
375+
376+
TIMSK2 &= ~(1<<TOIE2); // disable timer overflow interupt
377377

378378
// SET timer2 to count up mode
379379
TCCR2A &= ~((1<<WGM21) | (1<<WGM20));
380380
TCCR2B &= ~(1<<WGM22);
381-
382381
// set clock to I/O clock
383-
ASSR &= ~(1<<AS2);
384-
385-
// overflow only mode
386-
TIMSK2 &= ~(1<<OCIE2A);
387-
388-
// configure to fire about every 5 micro-second
382+
ASSR &= ~(1<<AS2);
383+
384+
// overflow only mode
385+
TIMSK2 &= ~(1<<OCIE2A);
386+
387+
// configure to fire about every 5 micro-second
389388
TCCR2B |= (1<<CS22) ;
390389
TCCR2B &= ~(1<<CS20);
391390
TCCR2B &= ~(1<<CS21);
@@ -402,19 +401,21 @@ void BaseLEDMatrix::stopScanning(void) {
402401
}
403402

404403
unsigned int BaseLEDMatrix::nextTimerInterval(void) const {
405-
return max(257 - this->multiplier5microseconds( _scanPass )*BASE_SCAN_TIMER_INTERVALS, 0 );
404+
return max(257 - this->baseIntervalMultiplier( _scanPass )*BASE_SCAN_TIMER_INTERVALS, 0 );
406405
}
407406

408-
409407
ISR(TIMER2_OVF_vect) {
410-
noInterrupts();
408+
noInterrupts(); // disable all interrupts
409+
411410
// shift out next row
412411
gSingleton->shiftOutCurrentRow();
412+
413413
// reload the timer
414-
TCNT2 = gSingleton->nextTimerInterval();
415-
interrupts();
416-
// update scan row. Done outside of interrupt stoppage since execution time can
417-
// be inconsistent, which would lead to vary brightness in rows.
418-
gSingleton->incrementScanRow();
414+
TCNT2 = gSingleton->nextTimerInterval();
415+
interrupts(); // enable all interrupts
416+
417+
// update scan row. Done outside of interrupt stoppage since execution time can
418+
// be inconsistent, which would lead to vary brightness in rows.
419+
gSingleton->incrementScanRow();
419420
}
420421
#endif

src/BaseLEDMatrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class BaseLEDMatrix : public TimerAction {
5454
virtual bool matrixNeedsUpdate(void) const = 0;
5555
virtual void matrixHasBeenUpdated(void) = 0;
5656

57-
virtual unsigned int multiplier5microseconds( size_t frame ) const;
57+
virtual unsigned int baseIntervalMultiplier( size_t frame ) const;
5858
public:
5959

6060
/**

src/LEDImage.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ template <class PixelType>
8484
const PixelType LEDImageBase<PixelType>::pixel( int row, int column ) const {
8585
if (this->isProgMem()) {
8686
switch (sizeof(PixelType)) {
87-
case 4:
87+
case 2:
8888
return (PixelType)pgm_read_word_near( this->data() + row*this->columns() + column );
8989
break;
90-
default:
91-
case 2:
90+
case 1:
9291
return (PixelType)pgm_read_byte_near( this->data() + row*this->columns() + column );
9392
break;
9493
}

src/RGBColor.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#ifndef TWELVE_BIT_COLOR
2323
#define TWELVE_BIT_COLOR (defined(__arm__)&& defined(TEENSYDUINO)) \
2424
||defined(__AVR_ATmega2560__) \
25-
||defined ( ESP8266 ) \
25+
||defined(__AVR_ATmega1284__) \
26+
||defined(__AVR_ATmega1284P__) \
27+
||defined( ESP8266 ) \
2628
||defined(ARDUINO_SAMD_ZERO) \
2729
||defined(_SAM3XA_)
2830
#endif
@@ -45,7 +47,7 @@ The bits of the byte are laid out as follows in a 2-byte integer:
4547
4648
*/
4749

48-
typedef unsigned int RGBColorType;
50+
typedef uint16_t RGBColorType;
4951

5052

5153
const RGBColorType AQUA_COLOR = 0x00FF;

src/RGBLEDMatrix.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,25 @@ void RGBLEDMatrix::setRowBitsForFrame(
248248

249249

250250
// Number of 5 microsecond units
251-
unsigned int RGBLEDMatrix::multiplier5microseconds( size_t frame ) const {
252-
unsigned int mulitplier = 1;
251+
unsigned int RGBLEDMatrix::baseIntervalMultiplier( size_t frame ) const {
253252
#if TWELVE_BIT_COLOR
254-
mulitplier = frame/4+1;
253+
#if defined(__AVR_ATmega2560__)||defined(__AVR_ATmega1284__)||defined(__AVR_ATmega1284P__)
254+
unsigned int multiplier = frame/8 + 1;
255255
#else
256+
unsigned int multiplier = frame/4 + 1;
257+
#endif
258+
259+
#else
260+
unsigned int multiplier = 1;
256261
switch (frame) {
257262
case 2:
258-
mulitplier = 3;
263+
multiplier = 3;
259264
break;
260265
case 3:
261-
mulitplier = 8;
266+
multiplier = 8;
262267
break;
263268
}
264269
#endif
265-
266-
return mulitplier;
270+
271+
return multiplier;
267272
}

src/RGBLEDMatrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class RGBLEDMatrix : public BaseLEDMatrix {
5656
virtual void generateFrameBits(LEDMatrixBits& frameBits, size_t frame ) const;
5757
virtual bool matrixNeedsUpdate(void) const;
5858
virtual void matrixHasBeenUpdated(void);
59-
virtual unsigned int multiplier5microseconds( size_t frame ) const;
59+
virtual unsigned int baseIntervalMultiplier( size_t frame ) const;
6060
public:
6161

6262
/**

0 commit comments

Comments
 (0)