Skip to content

Commit 5089474

Browse files
added ability to specific hardware endianness
While column 0 is meant to indicate the left most column, the hardware layout of the matrix might not make the left most column the MSB in the shift register chain. This might happen if you make a mistake in your hardware (oops). By setting the column endian value of the matrix,the high level software can still reference column 0 to mean the left most column, and the bit layout sent the shift registers will be adjusted according to where column 0 physically is in the hardware.
1 parent 205664e commit 5089474

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
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

7+
8+
## [Unreleased]
9+
10+
### Changed
11+
12+
### Added
13+
- Basic capability to specify the endian-ness of the column layout for a matrix. While column 0 is meant to indicate the left most column, the hardware layout of the matrix might not make the left most column the MSB in the shift register chain. This might happen if you make a mistake in your hardware (oops!). By setting the column endian value of the matrix,the high level software can still reference column 0 to mean the left most column, and the bit layout sent the shift registers will be adjusted according to where column 0 physically is in the hardware.
14+
715
## [1.1.0] - 2018-02-09
816

917
### Changed

src/BaseLEDMatrix.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ BaseLEDMatrix::BaseLEDMatrix(
3232
bool rowControlBitOn,
3333
unsigned int interFrameOffTimeMicros,
3434
int slavePin,
35+
DeviceBitEndian bitEndian,
3536
unsigned long maxSPISpeed
3637
) : TimerAction(UPDATE_INTERVAL),
3738
_rows(rows),
3839
_columns(columns),
3940
_columnBitWidth(columnBitWidth),
4041
_pwmCycleScanCount(pwmCycleScanCount),
4142
_interFrameOffTimeMicros(interFrameOffTimeMicros),
43+
_bitEndian(bitEndian),
4244
_columnControlBitOn(columnControlBitOn),
4345
_rowControlBitOn(rowControlBitOn),
4446
_curScreenBitFrames(NULL),
@@ -220,7 +222,7 @@ void BaseLEDMatrix::stopScanning(void) {
220222

221223
unsigned int BaseLEDMatrix::nextRowScanTimerInterval(void) const {
222224
// Calculates the microseconds for each scan
223-
return 5*this->baseIntervalMultiplier( _scanPass );
225+
return 100*this->baseIntervalMultiplier( _scanPass );
224226
}
225227

226228
#pragma mark ESP8266 Handlers

src/BaseLEDMatrix.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
#endif
3131

3232
class BaseLEDMatrix : public TimerAction {
33+
public:
34+
35+
typedef enum {
36+
// the left most column in the hardware and MSB in the shift register chain is column 0
37+
LED_BIG_ENDIAN,
38+
39+
// The columns are laid out in 8 column "bytes" with column 0 being the left most
40+
// bit in the right most byte. Column 8 would be the left most bit in the second
41+
// to the right byte.
42+
LED_LITTLE_ENDIAN_8
43+
} DeviceBitEndian;
3344

3445
private:
3546
unsigned int _rows;
@@ -38,6 +49,7 @@ class BaseLEDMatrix : public TimerAction {
3849
unsigned int _pwmCycleScanCount;
3950
unsigned int _interFrameOffTimeMicros;
4051
unsigned int _interFrameOffTimeInterval;
52+
DeviceBitEndian _bitEndian;
4153

4254
bool _columnControlBitOn;
4355
bool _rowControlBitOn;
@@ -106,6 +118,7 @@ class BaseLEDMatrix : public TimerAction {
106118
int slavePin = 10
107119
#endif
108120
,
121+
DeviceBitEndian bitEndian = LED_BIG_ENDIAN,
109122
unsigned long maxSPISpeed = 18000000
110123
);
111124
virtual ~BaseLEDMatrix();
@@ -160,6 +173,8 @@ class BaseLEDMatrix : public TimerAction {
160173
*/
161174
void stopScanning(void);
162175

176+
DeviceBitEndian bitEndian(void) const { return _bitEndian; }
177+
163178
/**
164179
* This methods are "private" to this class but have to be declared public so
165180
* the timer interrupt can access them.

src/RGBLEDMatrix.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ RGBLEDMatrix::RGBLEDMatrix(
3636
bool columnControlBitOn,
3737
bool rowControlBitOn,
3838
unsigned int interFrameOffTimeMicros,
39-
int slavePin
39+
int slavePin,
40+
DeviceBitEndian bitEndian
4041
) : BaseLEDMatrix(
4142
rows,
4243
columns,
@@ -45,7 +46,8 @@ RGBLEDMatrix::RGBLEDMatrix(
4546
columnControlBitOn,
4647
rowControlBitOn,
4748
interFrameOffTimeMicros,
48-
slavePin
49+
slavePin,
50+
bitEndian
4951
),
5052
_bitLayout(bitLayout),
5153
_screen_data(NULL)
@@ -216,8 +218,22 @@ void RGBLEDMatrix::setRowBitsForFrame(
216218
columnBitIdxIncrement = 1;
217219
}
218220
for (unsigned int col = 0; col < this->columns(); col++) {
219-
RGBColorType rgbValue = image.pixel(row, col);
221+
unsigned int endianCol = col;
222+
223+
if (this->bitEndian() == LED_LITTLE_ENDIAN_8 ) {
224+
// first get the column "byte"
225+
unsigned int colByte = col/8;
220226

227+
// now column's "but" in the byte
228+
unsigned int colBit = col%8;
229+
230+
// calculate new column location by on "byte"
231+
232+
endianCol = this->columns() - (colByte+1)*8 + colBit;
233+
}
234+
235+
236+
RGBColorType rgbValue = image.pixel(row, endianCol);
221237
// a form of Binary Code Modulation is used to control
222238
// the LED intensity at variou levels.
223239

src/RGBLEDMatrix.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class RGBLEDMatrix : public BaseLEDMatrix {
9393
#else
9494
int slavePin = 10
9595
#endif
96+
,
97+
DeviceBitEndian bitEndian = LED_BIG_ENDIAN
9698
);
9799
virtual ~RGBLEDMatrix();
98100

0 commit comments

Comments
 (0)