Skip to content

Commit

Permalink
reduce object include hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsheep committed Mar 26, 2024
1 parent 64cd440 commit 7f80102
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion driver/demo_hub75_7seg.spin2
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ OBJ
digit[MAX_DIGITS] : "isp_hub75_7seg"
hub75Bffrs : "isp_hub75_hwBufferAccess"
user : "isp_hub75_hwPanelConfig" ' hardware config common to all demos
scrnBuffers : "isp_hub75_hwBuffers" ' the large buffers storing pixel data
scrnBuffers : "isp_hub75_hwBuffers" ' the large buffers storing pixel data

PUB start() : ok | blockX, blockY, subrow, subcol, row, col, red, green, blue, builtPtr, color3bit, color24bit, pPixColor, colorOffset, byteOffset, hours24
'' Start underlying drivers and run demo
Expand Down
60 changes: 5 additions & 55 deletions driver/isp_hub75_colorUtils.spin2
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
'' -- see below for terms of use
'' E-mail..... [email protected]
'' Started.... Nov 2022
'' Updated.... 15 Jan 2024
'' Updated.... 26 Mar 2024
''
'' =================================================================================================

CON

#0, LED_UNKNOWN, LED_RED, LED_GREEN, LED_BLUE

OBJ

hub75Bffrs : "isp_hub75_hwBufferAccess"

DAT { driver controls for testing }

Expand All @@ -42,14 +39,6 @@ PUB getBrightness() : brightness
'' Return the global brightness value
brightness := defaultBrightness

PUB correctedColor(nChainIdx, color) : adjustedColor
'' Correct a color using generic gamma
adjustedColor := color
'return
'adjustedColor := byte[@gamma][adjustedColor]
'adjustedColor := ((adjustedColor * defaultBrightness) >> 8) & $ff
adjustedColor := colorAtDesiredBitWidth(nChainIdx, adjustedColor)

PUB gammaPeek(color) : adjustedColor | gammmaIndex, lowColor, highColor
'' Return index of nearest matching value in gamma table
if bGammaEnable
Expand All @@ -73,9 +62,8 @@ PUB gammaPeek(color) : adjustedColor | gammmaIndex, lowColor, highColor
else
adjustedColor := color

PUB correctedSingleColor(nChainIdx, led, colorValue) : adjustedColor | pGammaTable
'' Correct the color for a specific LED (R, G, or B)
adjustedColor := colorValue
PUB gammaCorrectedSingleColor(led, colorValue) : adjustedColor | pGammaTable
'' Gamma-Correct the color for a specific LED (R, G, or B)
case led
LED_RED:
pGammaTable := @gamma
Expand All @@ -85,11 +73,9 @@ PUB correctedSingleColor(nChainIdx, led, colorValue) : adjustedColor | pGammaTab
pGammaTable := @gamma
other:
abort

adjustedColor := ((adjustedColor * defaultBrightness) >> 8) & $ff
adjustedColor := ((colorValue * defaultBrightness) >> 8) & $ff
if bGammaEnable
adjustedColor := byte[pGammaTable][adjustedColor]
adjustedColor := colorAtDesiredBitWidth(nChainIdx, adjustedColor)
adjustedColor := byte[@gamma][adjustedColor]

PUB rgbColorFromDegrees(degrees) : rcbColor | offset60, fract60, red, green, blue
'' CONVERT: 0-355 degrees to color
Expand Down Expand Up @@ -145,45 +131,9 @@ PUB gammaPtrs(): pGammaRed, pGammaGreen, pGammaBlue
pGammaGreen := @gamma
pGammaBlue := @gamma

PUB colorAtDesiredBitWidth(nChainIdx, hex8bit) : pwmBits
'' CALCULATE: proper duty cycle for intensity of 0-255
shiftLtValue := 8 - hub75Bffrs.colorDepth(nChainIdx)
nbrPwmFrames := hub75Bffrs.pwmFrameCount(nChainIdx)
'debug("- color CFG: ", udec_long(shiftLtValue), udec_long(nbrPwmFrames))
'
' (map 8-bit color depth to {compiled}-bit color depth)
' map 0-255 to compiled color depth 0-7,15,31,63,127,255
'
' REF: https://www.arduino.cc/reference/en/language/functions/math/map
'
' Re-maps a number from one range to another. That is, a value of fromLow would get mapped to toLow,
' a value of fromHigh to toHigh, values in-between to values in-between, etc.
'
' y = map(x, 1, 50, 50, 1);
'
' PRI map(inValue, inMin, inMax, outMin, outMax) : outValue
' outValue := (inValue - inMin) * (outMax - outMin) / (inMax - inMin) + outMin
' outValue := (inValue - 0) * (outMax - 0) / (inMax - 0) + 0
' outValue := inValue * outMax / inMax
'
' shiftLtValue 5, 4, 3, 2, 1, 0
' map(hex8bit, 0, 255, 0, 7) 7=3-bit, 15=4-bit, 31=5-bit, 63=6-bit, 127=7-bit, 255=8-bit
' outValue := (hex8bit - 0) * (7 - 0) / (255 - 0) + 0
' outValue := hex8bit * 7 / 255

pwmBits := (hex8bit * nbrPwmFrames) / 255 ' map our value
pwmBits <<= shiftLtValue ' shift value into our upper COLOR_DEPTH bits
{
if not didShow[hex8bit]
debug("clr:dcyc ", uhex_byte(hex8bit), uhex_byte(pwmBits))
didShow[hex8bit] := TRUE
'}

DAT { tables, default values }

shiftLtValue long 0 ' set by init()
nbrPwmFrames long 0 ' set by init()

didShow byte FALSE[256]

defaultBrightness word 256 '256 ' 205 = 80% [0-255,256] where 256 is NO brightness adjustment
Expand Down
52 changes: 51 additions & 1 deletion driver/isp_hub75_hwBufferAccess.spin2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'' -- see below for terms of use
'' E-mail..... [email protected]
'' Started.... Nov 2022
'' Updated.... 15 Jan 2024
'' Updated.... 26 Mar 2024
''
'' =================================================================================================
'
Expand Down Expand Up @@ -51,6 +51,7 @@ OBJ

hwEnum : "isp_hub75_hwEnums" ' hub75 attachment, set up constants
user : "isp_hub75_hwPanelConfig" ' user's panels configuration constants
colorUtils : "isp_hub75_colorUtils" ' color utilities

CON { internal constants }
' -------------------------------------------------------------------
Expand Down Expand Up @@ -357,6 +358,55 @@ PUB getDriverFlags(nChainIdx) : desiredFlags, eChipType
debug("- have unknown CHIP ", ubin_word(desiredFlags))
abort

PUB correctedColor(nChainIdx, color) : adjustedColor
'' Correct a color using generic gamma
adjustedColor := color
'return
'adjustedColor := byte[@gamma][adjustedColor]
'adjustedColor := ((adjustedColor * defaultBrightness) >> 8) & $ff
adjustedColor := colorAtDesiredBitWidth(nChainIdx, adjustedColor)

PUB correctedSingleColor(nChainIdx, led, colorValue) : adjustedColor | pGammaTable
'' Correct the color for a specific LED (R, G, or B)
adjustedColor := ((colorValue * colorUtils.getBrightness()) >> 8) & $ff
if colorUtils.isGammaEnabled()
adjustedColor := colorUtils.gammaCorrectedSingleColor(led, colorValue)
adjustedColor := colorAtDesiredBitWidth(nChainIdx, adjustedColor)

PUB colorAtDesiredBitWidth(nChainIdx, hex8bit) : pwmBits | shiftLtValue, nbrPwmFrames
'' CALCULATE: proper duty cycle for intensity of 0-255
shiftLtValue := 8 - colorDepth(nChainIdx)
nbrPwmFrames := pwmFrameCount(nChainIdx)
'debug("- color CFG: ", udec_long(shiftLtValue), udec_long(nbrPwmFrames))
'
' (map 8-bit color depth to {compiled}-bit color depth)
' map 0-255 to compiled color depth 0-7,15,31,63,127,255
'
' REF: https://www.arduino.cc/reference/en/language/functions/math/map
'
' Re-maps a number from one range to another. That is, a value of fromLow would get mapped to toLow,
' a value of fromHigh to toHigh, values in-between to values in-between, etc.
'
' y = map(x, 1, 50, 50, 1);
'
' PRI map(inValue, inMin, inMax, outMin, outMax) : outValue
' outValue := (inValue - inMin) * (outMax - outMin) / (inMax - inMin) + outMin
' outValue := (inValue - 0) * (outMax - 0) / (inMax - 0) + 0
' outValue := inValue * outMax / inMax
'
' shiftLtValue 5, 4, 3, 2, 1, 0
' map(hex8bit, 0, 255, 0, 7) 7=3-bit, 15=4-bit, 31=5-bit, 63=6-bit, 127=7-bit, 255=8-bit
' outValue := (hex8bit - 0) * (7 - 0) / (255 - 0) + 0
' outValue := hex8bit * 7 / 255

pwmBits := (hex8bit * nbrPwmFrames) / 255 ' map our value
pwmBits <<= shiftLtValue ' shift value into our upper COLOR_DEPTH bits
{
if not didShow[hex8bit]
debug("clr:dcyc ", uhex_byte(hex8bit), uhex_byte(pwmBits))
didShow[hex8bit] := TRUE
'}

PUB dbgMemDump(pMessage, pBytes, lenBytes) | bytBffr, colIdx, rowIdx, maxCol, maxRow, dispLen
'' Dump bytes in hex format to debug() terminal
debug("`temp '", zstr_(pMessage), ": bffr=", uhex_long_(pBytes), "(", udec_(lenBytes), ")' 13")
Expand Down
8 changes: 4 additions & 4 deletions driver/isp_hub75_screenUtils.spin2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'' -- see below for terms of use
'' E-mail..... [email protected]
'' Started.... Nov 2020
'' Updated.... 5 Nov 2022
'' Updated.... 26 Mar 2024
''
'' =================================================================================================

Expand Down Expand Up @@ -65,9 +65,9 @@ PUB drawPixelAtRCwithRGB(nChainIdx, row, column, red, green, blue) | rowIndex, c
'if isDebugLocn(rowIndex, columnIndex)
'if column // 16 == 0
'debug("- Screen RC=(", udec_(rowIndex), ", ", udec_(columnIndex), "), ofs=", udec_(colorOffset), ", RGB=(", uhex_(red), uhex_(green), uhex_(blue), ")")
byte[pColor][0] := colorUtils.correctedSingleColor(nChainIdx, colorUtils.LED_RED, red)
byte[pColor][1] := colorUtils.correctedSingleColor(nChainIdx, colorUtils.LED_GREEN, green)
byte[pColor][2] := colorUtils.correctedSingleColor(nChainIdx, colorUtils.LED_BLUE, blue)
byte[pColor][0] := hub75Bffrs.correctedSingleColor(nChainIdx, colorUtils.LED_RED, red)
byte[pColor][1] := hub75Bffrs.correctedSingleColor(nChainIdx, colorUtils.LED_GREEN, green)
byte[pColor][2] := hub75Bffrs.correctedSingleColor(nChainIdx, colorUtils.LED_BLUE, blue)

CON { license }

Expand Down

0 comments on commit 7f80102

Please sign in to comment.