github mrcodetastic/ESP32-HUB75-MatrixPanel-DMA 3.1.1

one hour ago

What's Changed

  • Refactor VirtualMatrixPanel_T (compatibility breaking changes) by @mrcodetastic in #989 - Refer to table below
  • Add VirtualDMAConfig and auto-derived VirtualMatrixPanel_T constructors by @mrcodetastic in #990
  • S3 gdma fix by @mrcodetastic in #981 - Refer to explain below
  • Port to arduino-esp32 4.0.0-RC1 / ESP-IDF 6.1 (pioarduino 61.04.00-RC1) by @robertlipe in #972
  • Add FOUR_SCAN_64PX_HIGH_16S for 64x64 1/16-scan (16S) panels by @sezabart in #976
  • Add get_lsbMsbTransitionBit() by @marcmerlin in #978
  • Build CIE 1931 brightness LUT at runtime from active color depth by @mrcodetastic in #987
  • Fix HZ_10M value and allow a real 8MHz clock on ESP32/S2 by @RichardD012 in #984
  • Fix backward compatibility across ESP-IDF 4.x/5.x/6.x and bump to 3.1.1 (fixes #986, #983) by @mrcodetastic in #988

Panel Compatibility & Issues Closed via VirtualMatrixPanel_T (PR #989 / PR #990)

This is the result of the cumulative help that @board707 has provided over the years to people with panels with differing scan types and pixel mapping arrangements. This was used to produce a refactored VirtualMatrixPanel_T with template policies (TwoScanMapping, FourScanMapping<PxBase, Flags>, FourScan64pxBitSwapMapping, EightScanMapping<PxBase, Flags>, custom ScanPolicyTraits), automatic VirtualDisplay::makeDMAConfig() geometry folding, and the interactive Pixel_Mapping_Test workflow was able to close 67 issues (plus 7 stale/support not planned issues redirected to built-in policies and doc/NonStandardPanels.md).

Thank you @board707 for your help to others.

Standard Sketch Pattern (master after PR #990)

#include <ESP32-HUB75-VirtualMatrixPanel_T.hpp>

using PanelScan      = FourScanMapping<8, FOUR_SCAN_SWAP_BLOCKS>; // pick policy from table below
using VirtualDisplay = VirtualMatrixPanel_T<CHAIN_NONE, PanelScan>; // or CHAIN_* for 2D grids

auto mxconfig    = VirtualDisplay::makeDMAConfig(PANEL_W, PANEL_H /*, ROWS, COLS*/);
// apply extra mxconfig fields (clkphase, line_decoder, driver, etc.) before dma_display->begin()
auto *virtualDisp = new VirtualDisplay(*dma_display, mxconfig);

(For custom padded DMA widths like #608 / #719 where DMA shift width differs from logical panel width, pass explicit dimensions: new VirtualDisplay(*dma_display, 1, 1, PANEL_W, PANEL_H).)


Closed Issues Resolved (completed — 67 Issues)

Issue List: #967, #966, #955, #949, #944, #942, #937, #930, #925, #914, #908, #905, #871, #850, #848, #840, #836, #833, #823, #806, #805, #801, #799, #797, #793, #781, #771, #769, #765, #754, #737, #727, #723, #719, #712, #711, #702, #700, #698, #686, #677, #666, #645, #643, #637, #627, #624, #608, #591, #580, #545, #540, #516, #500, #480, #468, #453, #429, #386, #350, #345, #323, #321, #311, #204, #57, #47

Issue Category Panel Type / Specs (Drivers & Mux) VirtualMatrixPanel_T Usage (PanelScan / Constructor) Extra mxconfig & Notes
#967 8-Scan 32x16 1/2S (SM16208SJ, direct row mux; titled 1/8) EightScan32x16_SM16208 line_decoder = TYPE_DIRECT, clkphase = false, latch_blanking = 4 (verified by reporter)
#966 4-Scan Chain 64x32 1/8S (1x2 A/B/C-only outdoor panels, 74HC245 skew) FourScanMapping<> (makeDMAConfig(64, 32, 1, 2)) clkphase = false fixes hold-time corruption on 2nd chained panel
#955 4-Scan YS-P5-320X160(PRO)-8S-1921-GYGY-V1 (64x32 1/8S, FM6124HJ + 595) FourScanMapping<1> driver = FM6124, line_decoder = TYPE595, clkphase = false
#949 4-Scan P5-08S-1921 (64x32 1/8S, MBI5124 + SM5166) FourScanMapping<16> driver = MBI5124
#944 2-Scan P4-320X160-2121-20S-PV1 (80x40 1/20S, DP5125F + DP32019B) TwoScanMapping Ensure gpio.e is connected (>16 row addresses); clkphase = false
#942 4-Scan P4 80x40 1/10S (SM16208 + SM5368) FourScanMapping<4, FOUR_SCAN_XOR_SEGMENTS> line_decoder = TYPE595, clkphase = false (DP3364 / ICND2046AP / SM16169SH cataloged incompatible)
#937 8-Scan Custom P6(3535)-32X32-4S-72SB-22F (32x32 1/4S, MBI5124GP) Custom ScanPolicyTraits<4, 4> (4*W x H/4 DMA folding) clkphase = false; sketch-local band/slot policy (makeDMAConfig(32, 32))
#930 4-Scan SzLightall P10 320x160 1/4 scan V1.1 (32x16 1/4S, SM16208 + SM74HC138D) FourScanMapping<8, FOUR_SCAN_SWAP_BLOCKS> clkphase = false
#925 Custom Stride 78x78 1/26S (SM5368PS / RU5958DSP mux) Custom 3-row folding ScanPolicy (makeDMAConfig(78, 78)) line_decoder = TYPE595, latch_blanking = 4, clkphase = false
#914 Single-Scan EICEG-P2.5-64X32-32s-v1.3 (64x32 1/32S, FM6124) TwoScanMapping with makeDMAConfig(64, 64) Double DMA height (64) + E pin + driver = FM6124; draw within y = 0..31
#908 4-Scan GKGD P4-8040-10S-V2.3 (80x40 1/10S, ICN2037 + ICN2012) FourScanMapping<16> driver = FM6124 (or ICN2038S/SHIFTREG), latch_blanking = 4, clkphase = false
#905 4-Scan P8 32x16 1/4S (SM16206S + MP7128GF / TC5020, no 138/595) FourScanMapping<8> line_decoder = TYPE_DIRECT, clkphase = false
#871 4-Scan P4 80x40 1/10S (SM5368 mux) FourScanMapping<> line_decoder = TYPE595, clkphase = false
#850 8-Scan 32x16 1/2S (SM16208SJ + 4953 MOSFET direct mux) EightScan32x16_819 (or EightScan32x16_SM16208) line_decoder = TYPE_DIRECT, clkphase = false
#848 Double-Buffer Outdoor 4-scan (64x32 1/8S) FourScanMapping<> double_buff = true + flipDMABuffer() (drawPixel & drawPixelRGB888 both use ScanPolicy)
#840 4-Scan P5-3232-3528-8S-A2 (32x32 1/8S, DP5020B + DP74HC138D) FourScanMapping<0, FOUR_SCAN_SWAP_BLOCKS> clkphase = false
#836 4-Scan (x3) (1) P8 40x20 1/5S (DP5125D+RUC7258D)
(2) P8 40x20 1/5S (FM6047+RUC7258D)
(3) QiangLi P6.67 48x24 1/6S (DP5135+DP32020)
(1) FourScanP8_40x20
(2) FourScanMapping<8, FOUR_SCAN_ZIGZAG_SM16208>
(3) FourScanMapping<> (48x24)
clkphase = false; line_decoder = TYPE595 on 48x24 (LS9936 variant cataloged incompatible)
#833 4-Scan Chain P10 32x16 1/4S 2x2 grid recommendation VirtualMatrixPanel_T<CHAIN_TOP_RIGHT_DOWN, FourScanMapping<8, FOUR_SCAN_SWAP_BLOCKS>> Or FourScanMapping<8>; makeDMAConfig(32, 16, 2, 2), clkphase = false
#823 8-Scan 32x16 1/2S (SM16208S, direct row mux; titled 1/4) EightScan32x16_819 / EightScan32x16_SM16208 line_decoder = TYPE_DIRECT, clkphase = false
#806 4-Scan P4 80x40 1/10S (SM16208 + TC7559 mux) FourScanMapping<> driver = SHIFTREG, line_decoder = TYPE595, clkphase = false
#805 2-Scan + 595 32x32 1/16S (MBI5124 + ICND2018 mux) TwoScanMapping driver = MBI5124, line_decoder = TYPE595
#801 4-Scan P8 32x16 1/4S (TC5020AP + DP4953 direct MOSFET mux) FourScanMapping<8> line_decoder = TYPE_DIRECT, clkphase = false
#799 4-Scan P10(3535)32x16-4S (32x16 1/4S) FourScanMapping<8, FOUR_SCAN_SWAP_BLOCKS> clkphase = false
#797 2-Scan Checklist K716-128x64-32S-V3.3 (128x64 1/32S, SM16208SF + SM5166PS) TwoScanMapping Hardware triage documented (driver = SHIFTREG, gpio.e, clkphase = false)
#793 2-Scan Tuning P5(2121)-3264-16S-M5 (64x32 1/16S, RUL6024 + RUC7258D) TwoScanMapping driver = SHIFTREG, clkphase = false, latch_blanking = 1
#781 4-Scan P5 64x32 1/8S (SM16208SJ + SM5368PS mux) FourScanMapping<4, FOUR_SCAN_SWAP_BLOCKS | FOUR_SCAN_XOR_SEGMENTS> line_decoder = TYPE595, clkphase = false
#771 2-Scan Silkscreen 64x64 1/32S (ICN2037BP + RUC7258D) TwoScanMapping HUB75E pin 12 mislabeled GND on PCB is D; connect D & E, clkphase = false
#769 2-Scan P4 80x40 1/20S indoor (FM6124D + CNCC29/TC7262) TwoScanMapping driver = FM6124, gpio.e connected, clkphase = false
#765 4-Scan Chain P5 Outdoor 64x32 1/8S vertical/2D grid VirtualMatrixPanel_T<CHAIN_TOP_RIGHT_DOWN, FourScanMapping<>> Or <32> / <16>; makeDMAConfig(64, 32, 2, 1), clkphase = false
#754 4-Scan 80x40 1/10S (DP5125D + DP32020A mux) FourScanMapping<4, FOUR_SCAN_SWAP_BLOCKS> line_decoder = TYPE595, clkphase = false
#737 4-Scan P5 64x32 1/8S (ICN2038S + ICN2012) FourScanMapping<32> driver = ICN2038S, clkphase = false
#727 Single-Scan 64x32 1/32S (scan == panel_res_y) TwoScanMapping with makeDMAConfig(64, 64) Double DMA height (64) + A..E pins; draw within y = 0..31
#723 2-Scan + 595 PH2-128*64-32S-V1.0 (128x64 1/32S, FM6126A + D5958SS) TwoScanMapping driver = FM6126A, line_decoder = TYPE595, latch_blanking = 3, clkphase = false, gpio.e
#719 Custom Column-Skip P2.5-10452-26S-V2.0 (104x52 1/26S, ICN2037BP, dummy col every 16th) Custom ColumnSkip16Mapping : ScanPolicyTraits<1, 1> Custom makeDMAConfig width 110; construct (*dma_display, 1, 1, 104, 52) + gpio.e
#712 Docs / Guide P10 32x16 1/8S & 1/4S FourScanMapping / TwoScanMapping Documented in doc/VirtualMatrixPanel_T.md & doc/NonStandardPanels.md
#711 4-Scan P5 Outdoor 64x32 1/8S (ICN2038S + ICN2012) FourScanMapping<32> driver = ICN2038S, clkphase = false
#702 Mixed (x3) (1) 80x40 1/20S (DP5125D+3018SDP)
(2) P4 80x40 1/10S (ICN2037BP+RUC7258D)
(3) P5 64x32 1/8S (SM16208SJ+RUL5158C)
(1) TwoScanMapping
(2) FourScanMapping<16>
(3) FourScanMapping<32>
line_decoder = TYPE595 on (1), clkphase = false (LS9930CS cataloged incompatible)
#700 Single-Scan P3 48x16 1/16S (MBI5124, scan == panel_res_y) TwoScanMapping with makeDMAConfig(48, 32) Double DMA height (32) + driver = MBI5124; draw within y = 0..15
#698 4-Scan P5-1921-64*32-8S-S2 / HRLOP-P5-1921/V2.0 (64x32 1/8S) FourScanMapping<4> clkphase = false
#686 4-Scan Docs 1/4-scan (32x16 1/4S) FourScanMapping<8> (or FourScanMapping<>) Setup automated via makeDMAConfig(32, 16) + doc/VirtualMatrixPanel_T.md
#677 4-Scan P10 32x16 1/4S 1x2 chain (SM16208SJ + DP74HC138B + MW245B + MW4953F) FourScanMapping<1> (makeDMAConfig(32, 16, 1, 2)) clkphase = false
#666 2-Scan Tuning 64x64 1/32S (FM6126A) TwoScanMapping driver = FM6126A, clkphase = false, gpio.e, plus commit 5d495d3 init delay
#645 Mixed DP5125D (x4) (1) Q3 64x64 1/32S (DP32020A)
(2) 64x64 1/32S (VB5628)
(3) Q5 64x32 1/8S (DP32020A)
(4) P10 32x16 1/4S (74HC138B)
(1)-(2) TwoScanMapping
(3) FourScanMapping<32>
(4) FourScanMapping<8, FOUR_SCAN_SWAP_BLOCKS>
line_decoder = TYPE595 on (1) & (3); pin-12 D/GND silkscreen note on (2); clkphase = false
#643 2-Scan Tuning P10-2727-8S-32X16-A (32x16 1/8S, DP5125D + RUC7258D) TwoScanMapping i2sspeed = HZ_8M (true 8 MHz fix), latch_blanking = 4, clkphase = false
#637 4-Scan (x2) (1) P8(3535)-20X40-5S-V1.2 (40x20 1/5S, ZigZag8)
(2) 40x20 1/5S (4-px checkerboard)
(1) FourScanMapping<8, FOUR_SCAN_ZIGZAG_SM16208>
(2) FourScanP8_40x20
clkphase = false
#627 4-Scan P4 Outdoor 80x40 1/10S (ICN2038S) FourScanMapping<16> driver = ICN2038S, clkphase = false
#624 4-Scan Chain 64x32 1/8S 2x2 grid (P4-1921-64x32-8s-s1 & ICN2037BP + SM5166PC) VirtualMatrixPanel_T<CHAIN_TOP_RIGHT_DOWN, FourScanMapping<>> Or FourScanMapping<32>; multi-row 4-scan chaining (makeDMAConfig(64, 32, 2, 2))
#608 Custom Column-Skip P3 104x52 1/26S (7x 16-ch ICs, 112 clocks, 8 skipped at x=56..63) Custom SkipMiddle8Mapping : ScanPolicyTraits<1, 1> Custom makeDMAConfig width 112; construct (*dma_display, 1, 1, 104, 52) + gpio.e
#591 4-Scan P6(3535) 32x32-8S-V1.6 (32x32 1/8S, ICN5020B) FourScanMapping<16, FOUR_SCAN_SWAP_BLOCKS> clkphase = false
#580 4-Scan 64x32 1/8S (pxbase = 16) FourScanMapping<16> clkphase = false
#545 2-Scan Checklist 64x64 1/32S (SM16208SJ + SM5166PS) TwoScanMapping Pre-Mapping Checklist: i2sspeed = HZ_8M, latch_blanking = 4, clkphase = false, gpio.e
#540 Single-Scan P4 64x32 1/32S (scan == panel_res_y) TwoScanMapping with makeDMAConfig(64, 64) Double DMA height (64) + E pin; draw within y = 0..31
#516 Single-Scan / 595 (1) 64x32 1/32S single-scan
(2) P3 64x64 1/32S (DP5125D + SM5368PF)
TwoScanMapping (makeDMAConfig(64, 64) for both) (1) draw in y = 0..31 + E pin; (2) line_decoder = TYPE595
#500 4-Scan HRLOP-P5-1921 (64x32 1/8S, SM16208S/ICN2038S + ICN2012) FourScanMapping<4> clkphase = false
#480 4-Scan P4-6432-8S-V2.0 (64x32 1/8S, ICN2037BP + RUC7258D, A/B/C only) FourScanMapping<> clkphase = false
#468 4-Scan Chain 64x64 1/16S 2x3 grid (SM16208SJ/ICN2037BP + RUC7258D) VirtualMatrixPanel_T<CHAIN_TOP_RIGHT_DOWN, FourScan64pxBitSwapMapping<>> Multi-panel chaining for 8-row bit-swapped panels (FM6124/SHIFTREG, clkphase = false)
#453 4-Scan / 2-Scan (1) P4 80x40 1/20S (ICN2038S + SM5166P/ICN2012)
(2) P4-80*40-10S-V2.0 (80x40 1/10S, ZigZag8)
(1) TwoScanMapping
(2) FourScan80x40_ZigZag8
(1) driver = ICN2038S + E pin; (2) clkphase = false
#429 2-Scan + 595 128x64 1/32S (ICN2037BP + RUL5158C A/B/C mux) TwoScanMapping line_decoder = TYPE595, clkphase = false, gpio.e
#386 2-Scan Standard 32x16 1/8S indoor TwoScanMapping Standard two-scan (no 4-scan folding needed)
#350 Custom Mirror 64x32 horizontal mirroring Custom MirrorHorizontalPolicy : ScanPolicyTraits<1, 1> Sketch-local ScanPolicy example (geom.virtual_res_x - 1 - coords.x)
#345 4-Scan (1) 64x32 1/8S (ICN2037BP)
(2) 64x64 1/16S outdoor (ICN2037BP)
(1) FourScanMapping<>
(2) FourScan64pxBitSwapMapping<>
clkphase = false
#323 2-Scan Silkscreen P3-6464-32S-V2.0 (64x64 1/32S, ICN2037BP) TwoScanMapping Pin 12 mislabeled GND on PCB is D; connect D & E, clkphase = false
#321 4-Scan 64x64 1/16S (MBI5124) FourScan64_16S (FourScanMapping<0, FOUR_SCAN_NONE, 64>) driver = MBI5124 (PR #976 / doc/FourScan_64x64_16S.md)
#311 4-Scan 32x32 1/8S (TC5020AP) FourScanMapping<> (or FourScanMapping<16>) clkphase = false
#204 Meta Tracking 1/4 and 1/8 scan tracking thread (32x16 1/4S, 64x32 1/8S, etc.) FourScanMapping<PxBase, Flags> & EightScanMapping<PxBase, Flags> Superseded custom getCoords() overrides; added Pixel_Mapping_Test & docs
#57 4-Scan 32x16 1/4S P10 outdoor (historical thread) FourScanMapping<> / FourScanMapping<8> clkphase = false
#47 Grid Chaining 2x2 grid of 64x32 panels VirtualMatrixPanel_T<CHAIN_TOP_RIGHT_DOWN, TwoScanMapping> makeDMAConfig(64, 32, 2, 2), clkphase = false

ESP32-S3 PSRAM (SPIRAM_DMA_BUFFER) Stability, Cache Coherency & Watchdog Recovery

This release resolves several long-standing ESP32-S3 Octal-PSRAM issues (including permanent black screens during Wi-Fi/TLS traffic, NVS/LittleFS writes, OTA Update.write(), and multi-panel chains).

Root Cause: Two Independent Failure Modes on ESP32-S3

Testing and community reports (e.g., #786, #910, #926, #974) revealed two separate root causes behind ESP32-S3 PSRAM display failures:

  1. Cache Coherency & Multi-Core Arbitration Races (CPU / D-Cache Side):

    • Previously, the library used the ESP32-S3 mask-ROM function Cache_WriteBack_Addr() per pixel and per color bitplane inside updateMatrixDMABuffer().
    • Because the ROM function does not acquire ESP-IDF's internal cache spinlock, calling it continuously from the render task while Wi-Fi, BLE, or TLS ran on the other core could race on the cache controller and lock up the SoC. Calling it on every pixel/bitplane (tens of thousands of times per frame) also severely impacted frame rate and added heavy PSRAM bus pressure.
  2. Physical MSPI Bus Starvation & LCD_CAM FIFO Underflow (Hardware Peripheral Side):

    • On ESP32-S3 silicon, internal Flash and external Octal PSRAM share a single physical SPI/MSPI bus arbiter.
    • Whenever an application writes or erases flash—such as OTA updates (Update.write()), NVS/Preferences commits, or LittleFS writes—the flash controller disables caches and stalls external PSRAM reads for milliseconds.
    • While the MSPI bus is blocked (or saturated by simultaneous setBrightness() buffer rewrites), GDMA cannot feed payload words from PSRAM into LCD_CAM's asynchronous TX FIFO (lcd_afifo) fast enough.
    • Even with proper esp_cache_msync() cache synchronization and batched flushes in place, once an LCD_CAM TX FIFO underflow occurs in continuous lcd_always_out_en = 1 loop mode, LCD_CAM and GDMA do not self-recover—leaving the display permanently black until a hardware reset.

S3 PSRAM Fix - What Was Implemented

1. Spinlock-Safe esp_cache_msync() & Batched Cache Writebacks

  • Thread-safe cache writebacks: Unified DMA_CACHE_WRITEBACK across ESP32-P4, ESP32-S31, and ESP32-S3 SPIRAM_DMA_BUFFER to use ESP-IDF's spinlock-synchronized, 64-byte-aligned esp_cache_msync(..., ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_TYPE_DATA) on ESP-IDF 5.2+ (with automatic fallback to Cache_WriteBack_Addr() on older IDF versions).
  • Zero per-pixel flushes when double-buffered: Added MatrixPanel_I2S_DMA::flushFrameBufferCache(). When double_buff is enabled, draw calls (drawPixel, fillScreen, clearScreen, hlineDMA, vlineDMA) modify the cached back buffer at full speed and flipDMABuffer() flushes each row once right before handing the buffer to GDMA.
  • Hoisted single-buffer flushes: When double_buff is disabled, cache flushes are hoisted out of the inner bitplane and pixel loops in updateMatrixDMABuffer(), hlineDMA(), and setBrightnessOE(), cutting cache sync calls by up to ~1,000× on full-screen operations.

2. ESP32-S3 PSRAM GDMA Starvation Recovery Watchdog (gdma_lcd_parallel16)

  • Per-frame heartbeat & fault detection: Enabled isr_cache_safe = 1, eof_till_data_popped = true, and GDMA on_tx_eof / on_tx_descr_err callbacks so interrupts remain serviceable during flash/cache operations and reflect real FIFO output flow.
  • Automatic LCD_CAM + GDMA recovery: When SPIRAM_DMA_BUFFER is active, a lightweight FreeRTOS watchdog task (hub75_dma_wd) monitors the frame EOF heartbeat every 20 ms. If a descriptor fault occurs or no frame completes within 160 ms (tuned to tolerate large, lower-FPS PSRAM panel chains without false triggers), dma_recover() safely quiesces and resets both GDMA and the LCD_CAM state machine (lcd_reset + lcd_afifo_reset) and resumes scanning the active buffer—preventing both permanent black screens and flipDMABuffer() stalls.
  • Optional compile-time flag (-DNO_S3_PSRAM_WATCHDOG): Internal SRAM builds incur zero watchdog task/RAM overhead. For SPIRAM_DMA_BUFFER builds, the watchdog is enabled by default and can be compiled out with -DNO_S3_PSRAM_WATCHDOG (or explicitly enabled without SPIRAM_DMA_BUFFER via -DS3_PSRAM_WATCHDOG); see doc/BuildOptions.md.

3. Exact-Multiple DMA Descriptor & Synchronized Buffer Flip Fixes

  • Fixed buildDmaDescriptorLinks() for panel chains whose row size is an exact multiple of DMA_MAX (e.g., 4-panel configurations), preventing 0-byte DMA descriptors from faulting GDMA.
  • Synchronized set_dma_output_buffer() so flipDMABuffer() waits for GDMA EOF on the target descriptor chain before releasing the previous framebuffer back to the CPU for drawing.

New Contributors

Full Changelog: 3.1.0...3.1.1

Don't miss a new ESP32-HUB75-MatrixPanel-DMA release

NewReleases is sending notifications on new releases.