From 7f80102c6f7244d23f4637d8e070206c7dc1ac32 Mon Sep 17 00:00:00 2001 From: Stephen M Moraco Date: Tue, 26 Mar 2024 12:55:11 -0600 Subject: [PATCH] reduce object include hierarchy --- driver/demo_hub75_7seg.spin2 | 2 +- driver/isp_hub75_colorUtils.spin2 | 60 +++------------------------ driver/isp_hub75_hwBufferAccess.spin2 | 52 ++++++++++++++++++++++- driver/isp_hub75_screenUtils.spin2 | 8 ++-- 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/driver/demo_hub75_7seg.spin2 b/driver/demo_hub75_7seg.spin2 index 62a83b1..0b6512e 100644 --- a/driver/demo_hub75_7seg.spin2 +++ b/driver/demo_hub75_7seg.spin2 @@ -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 diff --git a/driver/isp_hub75_colorUtils.spin2 b/driver/isp_hub75_colorUtils.spin2 index 2ed8c87..9d10b59 100644 --- a/driver/isp_hub75_colorUtils.spin2 +++ b/driver/isp_hub75_colorUtils.spin2 @@ -7,7 +7,7 @@ '' -- see below for terms of use '' E-mail..... stephen@ironsheep.biz '' Started.... Nov 2022 -'' Updated.... 15 Jan 2024 +'' Updated.... 26 Mar 2024 '' '' ================================================================================================= @@ -15,9 +15,6 @@ CON #0, LED_UNKNOWN, LED_RED, LED_GREEN, LED_BLUE -OBJ - - hub75Bffrs : "isp_hub75_hwBufferAccess" DAT { driver controls for testing } @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/driver/isp_hub75_hwBufferAccess.spin2 b/driver/isp_hub75_hwBufferAccess.spin2 index 961a20e..f59c9ef 100644 --- a/driver/isp_hub75_hwBufferAccess.spin2 +++ b/driver/isp_hub75_hwBufferAccess.spin2 @@ -7,7 +7,7 @@ '' -- see below for terms of use '' E-mail..... stephen@ironsheep.biz '' Started.... Nov 2022 -'' Updated.... 15 Jan 2024 +'' Updated.... 26 Mar 2024 '' '' ================================================================================================= ' @@ -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 } ' ------------------------------------------------------------------- @@ -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") diff --git a/driver/isp_hub75_screenUtils.spin2 b/driver/isp_hub75_screenUtils.spin2 index 20032d2..5579821 100644 --- a/driver/isp_hub75_screenUtils.spin2 +++ b/driver/isp_hub75_screenUtils.spin2 @@ -7,7 +7,7 @@ '' -- see below for terms of use '' E-mail..... stephen@ironsheep.biz '' Started.... Nov 2020 -'' Updated.... 5 Nov 2022 +'' Updated.... 26 Mar 2024 '' '' ================================================================================================= @@ -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 }