Skip to content

Commit f6c5421

Browse files
authored
Merge pull request #215 from ironsheep/master
Upgrade to v0.2.0 Ironsheep LED Matrix Driver
2 parents b6e0e21 + 51e17dc commit f6c5421

11 files changed

+1511
-549
lines changed

libraries/community/p2/All/isp_hub75_matrix/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ Language: Spin2 / Pasm2
66

77
Created: 03-DEC-2020
88

9+
Upadted: 19-FEB-2021
10+
911
Category: display
1012

1113
Description:
1214
Driver for HUB75 controlled RGB LED Matrix Panels
1315

1416
Related:
1517

16-
- See Docs, Setup Instructions at [HUB75 LED Matrix Driver Github Repository](https://github.com/ironsheep/p2-HUB75-LED-Matrix-Driver)
17-
- Watch for P2 Eval HUB75 Driver Board soon to be for sale at [Parallax Shop](https://www.parallax.com/product-category/propeller-2/)
18+
- See Docs, Setup Instructions at [HUB75 LED Matrix Driver Github Repository](https://github.com/ironsheep/p2-LED-Matrix-Driver)
19+
- Buy P2 Eval HUB75 Driver Board at [Parallax Online Store](https://www.parallax.com/product/p2-eval-hub75-adapter-board/)
20+
- See Morphing Digits software add-on at the [P2 LED-Matrix Morphing Digits Repository](https://github.com/ironsheep/P2-LED-Matrix-Morphing-Digits)
1821

1922
License: MIT (see end of source code)

libraries/community/p2/All/isp_hub75_matrix/isp_hub75_color.spin2

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,27 @@ CON { test colorset }
3333
cOrange = $FFA500
3434
cBlueViolet = $8A2BE2
3535

36+
cFullRed = $FF0000
37+
cFullGreen = $00FF00
38+
cFullBlue = $0000FF
39+
3640
' SPECIAL non-colors - invoke alforithm to gerate actual color used'
3741
cRedWhtBlu = $deadf0
3842
cRainbow = $deadf1
3943

4044
#0, LED_UNKNOWN, LED_RED, LED_GREEN, LED_BLUE
4145

46+
' our 3-bit colors
47+
BASE_BLACK = $00
48+
BASE_RED = $01
49+
BASE_GREEN = $02
50+
BASE_YELLOW = $03
51+
BASE_BLUE = $04
52+
BASE_MAGENTA = $05
53+
BASE_CYAN = $06
54+
BASE_WHITE = $07
55+
56+
4257
OBJ
4358

4459
screen : "isp_hub75_screenAccess"
@@ -152,14 +167,19 @@ PUB dutyCycleForIntensity(hex8bit) : pwmBits
152167
'' CALCULATE: proper duty cycle for intensity of 0-255
153168
' --- VERSION 1 - Bits spread throughout ---
154169
if hex8bit == 255
155-
pwmBits := $ff
170+
pwmBits := screen.MAX_PWM_FRAMES
156171
else
157172
pwmBits := hex8bit / screen.MAX_PWM_FRAMES
158-
159-
173+
{
174+
if not didShow[hex8bit]
175+
debug("clr:dcyc ", uhex_byte(hex8bit), uhex_byte(pwmBits))
176+
didShow[hex8bit] := TRUE
177+
'}
160178

161179
DAT { tables, default values }
162180

181+
didShow byte FALSE[256]
182+
163183
defaultBrightness word 256 '256 ' 205 = 80% [0-255,256] where 256 is NO brightness adjustment
164184

165185
' Gamma curve (lookup table)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:fcf16fb8c4209b3584c09cdffb433716f7f96805538cd870f4507af46e26512b
3-
size 18997
2+
oid sha256:088163fc8a12bf2ac9731d0475a485f16a0fe252b35aa2995c3865d092427751
3+
size 17320

libraries/community/p2/All/isp_hub75_matrix/isp_hub75_display.spin2

Lines changed: 85 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ SCROLL_FOREVER = scroller.SCROLL_FOREVER
3434
SCROLL_ONCE = scroller.SCROLL_ONCE
3535
SCROLL_ONCE_TO_CLEAR = scroller.SCROLL_ONCE_TO_CLEAR
3636

37+
' FIXME: UNDONE make this user configurable
3738
MAX_SCROLLING_REGIONS = 3
3839

3940
DAT { one or more screens of pixels of 24bit color }
@@ -66,18 +67,31 @@ VAR { Object Instance Variables }
6667
byte horizontalGapInPix
6768
byte verticalGapInPix
6869
byte hBitmapOffsetInPix
70+
byte bScan_1_4
71+
byte bSwapRB
6972

70-
PUB start() : ok | scrollerIndex
73+
PUB start() : ok | scrollerIndex, dvrConfig, driverConfigRaw
7174
'' Start the underlying driver(s)
7275

76+
ok := cog := -1 ' mark as failed, initially
77+
7378
'debug("`term temp size 80 50 textsize 10")
79+
if screen.MAX_PANELS_PER_COLUMN * screen.MAX_PANELS_PER_ROW <> screen.MAX_PANELS
80+
debug("dsp:Geometry BAD in isp_hub75_hwGeometry.spin2!")
81+
abort
82+
7483

75-
debug("- TEXT: start()")
84+
debug("dsp:start()")
7685
ok := cog := panel.start() ' send buffer to driver
7786
if ok == -1
78-
debug("- TEXT: underlying drivers failed!")
87+
debug("dsp:underlying drivers failed!")
7988
abort
8089

90+
dvrConfig, driverConfigRaw := screen.getDriverFlags()
91+
bScan_1_4 := (dvrConfig & screen.SCAN_4) > 0 ? True : False
92+
bSwapRB := (dvrConfig & screen.RB_SWAP) > 0 ? True : False
93+
94+
8195
' tell all about location of screen buffer
8296
screen.setScreen(@screen0)
8397

@@ -104,18 +118,23 @@ PUB clearScreen()
104118

105119
PUB fillScreen(rgbColor) | row, column
106120
'' Fill the display with 24-bit color value
107-
repeat row from 0 to screen.MAX_DISPLAY_ROWS - 1
108-
repeat column from 0 to screen.MAX_DISPLAY_COLUMNS - 1
121+
repeat row from 0 to screen.MAX_PHYSICAL_ROWS - 1
122+
repeat column from 0 to screen.MAX_PHYSICAL_COLUMNS - 1
109123
pixels.drawPixelAtRC(row, column, rgbColor)
110124

111125
PUB fillPanel(threeBitColor)
112126
'' Fill screen but without PWM (for testing underlying driver)
113127
panel.fillPanel(threeBitColor)
114128

115129
PUB commitScreenToPanel()
116-
'' Write sceen to panel driver
117-
'debug("- DISP: commit!")
118-
panel.convertScreen2PWM(@screen0)
130+
'' Write sceen to panel driver PWM frames (while alternating PWM frame sets)
131+
'debug("dsp: commit!")
132+
133+
if bScan_1_4
134+
panel.convertScreen2PWM_14(@screen0, bSwapRB)
135+
'panel.convertScreen2PWM_14_spin(@screen0, bSwapRB)
136+
else
137+
panel.convertScreen2PWM(@screen0, bSwapRB)
119138

120139

121140
{ -------------- Text Handling -------------- }
@@ -185,7 +204,7 @@ PUB setTextFont(newFont) | scrollerIndex, hUnusedPix, vUnusedPix
185204

186205
selectedTextFont := newFont
187206

188-
debug("dsp:font ", udec(charHeightInPix), udec(charWidthInPix), udec(maxTextLines), udec(maxTextColumns), udec(verticalGapInPix), udec(horizontalGapInPix), udec(topOffsetInPix), udec(leftOffsetInPix))
207+
'debug("dsp:font ", udec(charHeightInPix), udec(charWidthInPix), udec(maxTextLines), udec(maxTextColumns), udec(verticalGapInPix), udec(horizontalGapInPix), udec(topOffsetInPix), udec(leftOffsetInPix))
189208

190209
' configure our scrollers for font choice
191210
repeat scrollerIndex from 0 to MAX_SCROLLING_REGIONS - 1
@@ -310,7 +329,7 @@ PRI nextFreeScroller() : scrollerIndexToUse | scrollerIndex
310329
if scrollerIndexToUse == NOT_FOUND
311330
debug("Failed to locate free scroller!")
312331
abort
313-
debug("dsp:nextFreeScroller() ", udec(scrollerIndexToUse))
332+
'debug("dsp:nextFreeScroller() ", udec(scrollerIndexToUse))
314333

315334
{ -------------- Basic Graphics -------------- }
316335

@@ -324,25 +343,25 @@ PUB drawBoxOfColor(topRow, leftColumn, width, height, filled, rgbColor) | rightC
324343
bottomRow := topRow + height - 1
325344
if filled == TRUE
326345
repeat rowIndex from 0 to height - 1
327-
drawLineOfColor(topRow + rowIndex, leftColumn, topRow + rowIndex, rightColumn, currTextColor) ' horiz row
346+
drawLineOfColor(topRow + rowIndex, leftColumn, topRow + rowIndex, rightColumn, rgbColor) ' horiz row
328347
else
329-
drawLineOfColor(topRow, leftColumn, topRow, rightColumn, currTextColor) ' horiz top
330-
drawLineOfColor(topRow, rightColumn, bottomRow, rightColumn, currTextColor) ' vert right
331-
drawLineOfColor(bottomRow, leftColumn, bottomRow, rightColumn, currTextColor) ' horiz bottom
332-
drawLineOfColor(topRow, leftColumn, bottomRow, leftColumn, currTextColor) ' vert left
348+
drawLineOfColor(topRow, leftColumn, topRow, rightColumn, rgbColor) ' horiz top
349+
drawLineOfColor(topRow, rightColumn, bottomRow, rightColumn, rgbColor) ' vert right
350+
drawLineOfColor(bottomRow, leftColumn, bottomRow, rightColumn, rgbColor) ' horiz bottom
351+
drawLineOfColor(topRow, leftColumn, bottomRow, leftColumn, rgbColor) ' vert left
333352

334353

335354
PUB drawLine(fmRow, fmColumn, toRow, toColumn)
336355
'' Draw line fromRC -> toRC using current text color (currently limited to horzontal/vertical lines)
337356
drawLineOfColor(fmRow, fmColumn, toRow, toColumn, currTextColor)
338357

339-
PUB drawLineOfColor(fmRow, fmColumn, toRow, toColumn, rgbColor) | row, column, dx, dy, ctr, incr
358+
PUB drawLineOfColor(fmRow, fmColumn, toRow, toColumn, rgbColor) | row, column, dx, dy, ctr, incr, intD
340359
'' Draw line fromRC -> toRC using rgbColor (currently limited to horzontal/vertical lines)
360+
fmRow := 0 #> fmRow <# screen.MAX_PHYSICAL_ROWS - 1
361+
fmColumn := 0 #> fmColumn <# screen.MAX_PHYSICAL_COLUMNS - 1
362+
toRow := 0 #> toRow <# screen.MAX_PHYSICAL_ROWS - 1
363+
toColumn := 0 #> toColumn <# screen.MAX_PHYSICAL_COLUMNS - 1
341364
'debug("seg:drwLn fmRC=(", udec_(fmRow), ",", udec_(fmColumn), "), toRC=(", udec_(toRow), ",", udec_(toColumn), "), RGB=(", uhex_long(rgbColor), ")")
342-
fmRow := 0 #> fmRow <# screen.MAX_DISPLAY_ROWS - 1
343-
fmColumn := 0 #> fmColumn <# screen.MAX_DISPLAY_COLUMNS - 1
344-
toRow := 0 #> toRow <# screen.MAX_DISPLAY_ROWS - 1
345-
toColumn := 0 #> toColumn <# screen.MAX_DISPLAY_COLUMNS - 1
346365
if fmRow == toRow
347366
' draw Horizontal Line
348367
repeat column from fmColumn to toColumn
@@ -352,22 +371,53 @@ PUB drawLineOfColor(fmRow, fmColumn, toRow, toColumn, rgbColor) | row, column, d
352371
repeat row from fmRow to toRow
353372
pixels.drawPixelAtRC(row, fmColumn, rgbColor)
354373
else
355-
dx := (toColumn - fmColumn)
356-
dy := (toRow - fmRow)
357-
if (abs(dx) >= abs(dy))
358-
incr := abs(dx)
374+
if abs(toRow - fmRow) < abs(toColumn - fmColumn)
375+
if fmColumn > toColumn
376+
plotLineLow(toColumn, toRow, fmColumn, fmRow, rgbColor)
377+
else
378+
plotLineLow(fmColumn, fmRow, toColumn, toRow, rgbColor)
359379
else
360-
incr := abs(dy)
361-
dx := dx / incr
362-
dy := dy / incr
363-
column := fmColumn
364-
row := fmRow
365-
ctr := 1
366-
repeat while (ctr <= incr)
367-
pixels.drawPixelAtRC(row, column, rgbColor)
368-
column += dx
369-
row += dy
370-
ctr += 1
380+
if fmRow > toRow
381+
plotLineHigh(toColumn, toRow, fmColumn, fmRow, rgbColor)
382+
else
383+
plotLineHigh(fmColumn, fmRow, toColumn, toRow, rgbColor)
384+
385+
386+
PRI plotLineLow(x0, y0, x1, y1, rgbColor) | row, column, dy, dx, D, yi
387+
dx := x1 - x0
388+
dy := y1 - y0
389+
yi := 1
390+
if dy < 0
391+
yi := -1
392+
dy := -dy
393+
D := (2 * dy) - dx
394+
row := y0
395+
396+
repeat column from x0 to x1
397+
pixels.drawPixelAtRC(row, column, rgbColor)
398+
if D > 0
399+
row := row + yi
400+
D := D + (2 * (dy - dx))
401+
else
402+
D := D + 2 * dy
403+
404+
PRI plotLineHigh(x0, y0, x1, y1, rgbColor) | row, column, dy, dx, D, xi
405+
dx := x1 - x0
406+
dy := y1 - y0
407+
xi := 1
408+
if dx < 0
409+
xi := -1
410+
dx := -dx
411+
D := (2 * dx) - dy
412+
column := x0
413+
414+
repeat row from y0 to y1
415+
pixels.drawPixelAtRC(row, column, rgbColor)
416+
if D > 0
417+
column := column + xi
418+
D := D + (2 * (dx - dy))
419+
else
420+
D := D + 2*dx
371421

372422
{ -------------- Misc Helpers -------------- }
373423

libraries/community/p2/All/isp_hub75_matrix/isp_hub75_display_bmp.spin2

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ PRI loadBitmap(pBitmapFile) | nPanelCol, nPanelRow, blue, green, red, haveError,
4444
abort
4545

4646
' fill screen buffer
47-
repeat nPanelRow from 0 to screen.MAX_PANEL_ROWS - 1
48-
repeat nPanelCol from 0 to screen.MAX_PANEL_COLUMNS - 1
47+
repeat nPanelRow from 0 to screen.MAX_PHYSICAL_ROWS - 1
48+
repeat nPanelCol from 0 to screen.MAX_PHYSICAL_COLUMNS - 1
4949
'debug("loadBitmap() - RC=(", udec_(nPanelRow), ", ", udec_(nPanelCol), ")")
5050
showDebug := FALSE
5151
if isDebugLocn(nPanelRow, nPanelCol)
@@ -101,7 +101,7 @@ PRI validateBmpFile(pBmpFileImage) : bValidStatus | pFileHeader, i, iStart, iEnd
101101
' XYZZYpnl debug(" - Img-start @0x", uhex_(iStart))
102102
' XYZZYpnl debug(" - Img-end @0x", uhex_(iEnd))
103103

104-
if biWidth <> screen.MAX_PANEL_COLUMNS or biHeight <> screen.MAX_PANEL_ROWS
104+
if biWidth <> screen.MAX_PHYSICAL_COLUMNS or biHeight <> screen.MAX_PHYSICAL_ROWS
105105
' XYZZYpnl debug(" !! invalid BMP size! [NOT 64x32]")
106106
bValidStatus := FALSE
107107

@@ -118,16 +118,16 @@ PRI validateBmpFile(pBmpFileImage) : bValidStatus | pFileHeader, i, iStart, iEnd
118118
'else
119119
' XYZZYpnl debug("-good BMP size! [64x32]")
120120

121-
'dbgMemDump(@fileHeaderMsg, pBmpFileImage, bfOffBits)
122-
'dbgMemDump(@fileStartMsg, iStart, 32)
123-
'dbgMemDump(@fileEndMsg, iEnd-32-1, 32)
121+
'screen.dbgMemDump(@fileHeaderMsg, pBmpFileImage, bfOffBits)
122+
'screen.dbgMemDump(@fileStartMsg, iStart, 32)
123+
'screen.dbgMemDump(@fileEndMsg, iEnd-32-1, 32)
124124

125125
PRI get24BitBMPColorForRC(nRow, nColumn) : red, green, blue | pixColorAddr
126-
if(nRow > screen.MAX_PANEL_ROWS - 1)
127-
debug("- ERROR bad nRow value [", udec_(nRow), " > ", udec_(screen.MAX_PANEL_ROWS - 1), "]")
126+
if(nRow > screen.MAX_PHYSICAL_ROWS - 1)
127+
debug("- ERROR bad nRow value [", udec_(nRow), " > ", udec_(screen.MAX_PHYSICAL_ROWS - 1), "]")
128128

129-
if(nColumn > screen.MAX_PANEL_COLUMNS - 1)
130-
debug("- ERROR bad nColumn value [", udec_(nColumn), " > ", udec_(screen.MAX_PANEL_COLUMNS - 1), "]")
129+
if(nColumn > screen.MAX_PHYSICAL_COLUMNS - 1)
130+
debug("- ERROR bad nColumn value [", udec_(nColumn), " > ", udec_(screen.MAX_PHYSICAL_COLUMNS - 1), "]")
131131

132132
pixColorAddr := getPixelAddressForBMPRowColumn(nRow, nColumn)
133133
' our intername .bmp file byte order is BGR!
@@ -137,7 +137,7 @@ PRI get24BitBMPColorForRC(nRow, nColumn) : red, green, blue | pixColorAddr
137137

138138
PRI getPixelAddressForBMPRowColumn(nRow, nColumn) : pixColorAddr | rowIndex, columnIndex, nOffset, fileBitsBase, showDebug
139139
' Row is inverted in .BMP file...
140-
rowIndex := (screen.MAX_PANEL_ROWS - 1) - nRow
140+
rowIndex := (screen.MAX_PHYSICAL_ROWS - 1) - nRow
141141

142142
' Column is normal in file...
143143
columnIndex := nColumn
@@ -148,7 +148,7 @@ PRI getPixelAddressForBMPRowColumn(nRow, nColumn) : pixColorAddr | rowIndex, col
148148
showDebug := TRUE ' FALSE ' turn off debug
149149

150150
' now offset is simple (just multiply by 3! [bytes of color])
151-
nOffset := ((rowIndex * screen.MAX_PANEL_COLUMNS) + columnIndex) * screen.DISPLAY_BYTES_PER_COLOR
151+
nOffset := ((rowIndex * screen.MAX_PHYSICAL_COLUMNS) + columnIndex) * screen.DISPLAY_BYTES_PER_COLOR
152152

153153
fileBitsBase := @byte[pBitmapFileInMemory][bfOffBits] ' get base of image in file (skip header)
154154
pixColorAddr := @byte[fileBitsBase][nOffset] ' add in offset to 24-bit color

0 commit comments

Comments
 (0)