Skip to content

Commit 7434ca5

Browse files
added some documentation
1 parent e5805f0 commit 7434ca5

File tree

6 files changed

+127
-12
lines changed

6 files changed

+127
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ When constructing a matrix driver, you need to tell it a few details:
5656
* The matrix's size in rows and columns
5757
* Whether the shift registers used for controlling columns should be set to `HIGH` or `LOW` to turn on the column.
5858
* Whether the shift registers used for controlling rows should be set to `HIGH` or `LOW` to turn on the row
59-
* The pin which will be used to send the latch signle.
59+
* The pin which will be used to send the latch signal.
6060

6161
#### LEDMatrix
6262
The `LEDMatrix` driver is used for matrices of single color LEDs. This drive uses a `MutableGlyph` as its image buffer.

src/BaseLEDMatrix.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
#define ICACHE_RAM_ATTR
2222
#endif
2323

24-
#define SPICACHEPADBITS(rows,cols) (rows*3 + cols)%8 ? 8 - (rows*3 + cols)%8 : 0
25-
#define SPICACHESIZE(rows,cols) 1+((rows*3 + cols)-1)/8
26-
2724
const unsigned long UPDATE_INTERVAL = 2000;
2825

2926
static BaseLEDMatrix* gSingleton = NULL;
@@ -110,7 +107,7 @@ void BaseLEDMatrix::action() {
110107
}
111108
}
112109

113-
void BaseLEDMatrix::shiftOutCurrentRow( void ) {
110+
ICACHE_RAM_ATTR void BaseLEDMatrix::shiftOutCurrentRow( void ) {
114111
this->shiftOutRow( _scanRow, _scanPass );
115112
}
116113

src/BaseLEDMatrix.h

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,23 @@ class BaseLEDMatrix : public TimerAction {
5656

5757
virtual unsigned int multiplier5microseconds( size_t frame ) const;
5858
public:
59-
6059

60+
/**
61+
* Constructs the base LED matrix controller object.
62+
*
63+
* @param rows the number of rows in the LED matrix. Rows are expected to have
64+
* shared power to the LEDs.
65+
* @param columns the number of columns in the LED matrix.
66+
* @param columnBitWidth the number of bits needed to represent one physical LED in
67+
* a column. E.g., and RGB LED needs 3 bits.
68+
* @param pwmCycleScanCount the number of row scans needed for the PWM cycle of the matrix.
69+
* @param columnControlBitOn what value a column bit should be set to to the column on.
70+
* @param rowControlBitOn what value a row bit should be set to to turn the row on.
71+
* E.g. of the row is common anode and a PNP transistor is being use
72+
* to switch power to the row, the row bit likely needs to be LOW to
73+
* cause the transistor to power the row.
74+
* @param slavePin which ard pin is used for the latch signal.
75+
*/
6176
BaseLEDMatrix(
6277
unsigned int rows,
6378
unsigned int columns,
@@ -73,18 +88,60 @@ class BaseLEDMatrix : public TimerAction {
7388
);
7489
virtual ~BaseLEDMatrix();
7590

91+
/**
92+
* Should be called before any operations against this object is performed. Child
93+
* classes implementing matrix-type specific implementation should call this parent
94+
* class implementation of setup() before doing their own setup work.
95+
*/
7696
virtual void setup();
7797

98+
/**
99+
* Increments the draw lock. While a matrix has a non-zero draw lock, any changes to
100+
* the image() buffer will not be pass through to the matrix scan buffer.
101+
*/
78102
void startDrawing(void) { _isDrawingCount++; }
103+
104+
/**
105+
* Decrements the draw lock. All calls to startDrawing() should be balanced with a
106+
* call to stopDrawing().
107+
*/
79108
void stopDrawing(void) { _isDrawingCount--; if (_isDrawingCount < 0) { _isDrawingCount = 0; }}
109+
110+
111+
/**
112+
* Returns true is a draw lock is active.
113+
*/
80114
bool isDrawing(void) const { return (_isDrawingCount > 0); }
81115

116+
/**
117+
* Returns the number of rows in this matrix.
118+
*
119+
* @return the number of rows in the matrix.
120+
*/
82121
unsigned int rows() const { return _rows; }
122+
123+
/**
124+
* Returns the number of columns in this matrix.
125+
*
126+
* @return the number of columns in the matrix.
127+
*/
83128
unsigned int columns() const { return _columns; }
84129

130+
/**
131+
* Begins the row scan timer interrupt, which in turn starts sending data through the
132+
* SPI interface to the LED matrix.
133+
*/
85134
void startScanning(void);
135+
136+
/**
137+
* Stops the LED matrix row scan timmer interrupt.
138+
*/
86139
void stopScanning(void);
87140

141+
/**
142+
* This methods are "private" to this class but have to be declared public so
143+
* the timer interrupt can access them.
144+
*/
88145
void shiftOutCurrentRow(void);
89146
unsigned int nextTimerInterval(void) const;
90147
void incrementScanRow( void );

src/LEDMatrix.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ class LEDMatrix : public BaseLEDMatrix {
4242
public:
4343

4444

45+
/**
46+
* Constructs a mono-color LED matrix controller object.
47+
*
48+
* @param rows the number of rows in the LED matrix. Rows are expected to have
49+
* shared power to the LEDs.
50+
* @param columns the number of columns in the LED matrix.
51+
* @param columnControlBitOn what value a column bit should be set to to the column on.
52+
* @param rowControlBitOn what value a row bit should be set to to turn the row on.
53+
* E.g. of the row is common anode and a PNP transistor is being use
54+
* to switch power to the row, the row bit likely needs to be LOW to
55+
* cause the transistor to power the row.
56+
* @param slavePin which ard pin is used for the latch signal.
57+
*/
4558
LEDMatrix(
4659
int rows,
4760
int columns,
@@ -55,9 +68,26 @@ class LEDMatrix : public BaseLEDMatrix {
5568
);
5669
virtual ~LEDMatrix();
5770

71+
/**
72+
* Should be called before any operations against this object is performed.
73+
*/
5874
virtual void setup();
5975

76+
/**
77+
* Returns the image buffer for this matrix object. This is the
78+
* image buffer that drawing should be done to.
79+
*
80+
* @return a MutableGlyph object reference that is the matrix's image buffer.
81+
*/
6082
MutableGlyph& image(void) { return *_screen_data; }
83+
84+
/**
85+
* Returns a const reference to the image buffer for this matrix object. This is the
86+
* image buffer that drawing should be done to, but is const here and thus should
87+
* be only read from.
88+
*
89+
* @return a const MutableGlyph object reference that is the matrix's image buffer.
90+
*/
6191
const MutableGlyph& image(void) const { return *_screen_data; }
6292
};
6393

src/RGBLEDMatrix.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,21 @@ class RGBLEDMatrix : public BaseLEDMatrix {
5353
virtual unsigned int multiplier5microseconds( size_t frame ) const;
5454
public:
5555

56-
56+
/**
57+
* Constructs an RGB LED matrix controller object.
58+
*
59+
* @param rows the number of rows in the LED matrix. Rows are expected to have
60+
* shared power to the LEDs.
61+
* @param columns the number of columns in the LED matrix.
62+
* @param bitLayout an RGBLEDBitLayout enum indicating how the RGB bits are arranged
63+
* in each row.
64+
* @param columnControlBitOn what value a column bit should be set to to the column on.
65+
* @param rowControlBitOn what value a row bit should be set to to turn the row on.
66+
* E.g. of the row is common anode and a PNP transistor is being use
67+
* to switch power to the row, the row bit likely needs to be LOW to
68+
* cause the transistor to power the row.
69+
* @param slavePin which ard pin is used for the latch signal.
70+
*/
5771
RGBLEDMatrix(
5872
int rows,
5973
int columns,
@@ -70,7 +84,21 @@ class RGBLEDMatrix : public BaseLEDMatrix {
7084

7185
virtual void setup();
7286

87+
/**
88+
* Returns the image buffer for this matrix object. This is the
89+
* image buffer that drawing should be done to.
90+
*
91+
* @return a MutableRGBImage object reference that is the matrix's image buffer.
92+
*/
7393
MutableRGBImage& image(void) { return *_screen_data; }
94+
95+
/**
96+
* Returns a const reference to the image buffer for this matrix object. This is the
97+
* image buffer that drawing should be done to, but is const here and thus should
98+
* be only read from.
99+
*
100+
* @return a const MutableRGBImage object reference that is the matrix's image buffer.
101+
*/
74102
const MutableRGBImage& image(void) const { return *_screen_data; }
75103

76104
};

src/TimerAction.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@
1919
#ifndef __TIMERACTION_H__
2020
#define __TIMERACTION_H__
2121

22+
/**
23+
* TimerAction is a class that manages the timed firing of an action. Timing is
24+
* approximate and "no sooner than" the period delay. To use, subclass this class
25+
* and override the protected action() method to implement the periodic action, then call
26+
* the loop() method to an instance of the the subclass that has been constructed with the
27+
* desired timing interval. The TimerAction class will call the action() method repeatedly
28+
* after the first call to loop once the timing interval has passed.
29+
*/
2230
class TimerAction {
2331
private:
2432
unsigned long _interval;
2533
unsigned long _lastLoopMicros;
26-
unsigned long _actionAverageMicros;
2734

2835
bool _isActive;
2936

@@ -47,7 +54,6 @@ class TimerAction {
4754
public:
4855
TimerAction(unsigned long intervalMicros)
4956
: _interval(intervalMicros),
50-
_actionAverageMicros(0),
5157
_isActive(true)
5258
{
5359
_interval = intervalMicros;
@@ -60,9 +66,6 @@ class TimerAction {
6066
if ( _interval <= delta ) {
6167
_lastLoopMicros = micros();
6268
this->action();
63-
// at this point this->timeSinceLast() is the time it took to
64-
// do the action;
65-
_actionAverageMicros = (_actionAverageMicros+this->timeSinceLast())/2;
6669
}
6770
}
6871
}

0 commit comments

Comments
 (0)