Skip to content

HUB75: allow non-horizontal panel arrangements (e.g. vertically stacked panels) - #372

Open
atlan wants to merge 7 commits into
MoonModules:mdevfrom
atlan:feature/hub75-panel-arrangement
Open

atlan wants to merge 7 commits into
MoonModules:mdevfrom
atlan:feature/hub75-panel-arrangement

Conversation

@atlan

@atlan atlan commented Jul 31, 2026 •

Copy link
Copy Markdown

What this is trying to achieve

Allow HUB75 panels to be arranged in something other than a single horizontal row — for
example four 64x32 panels stacked vertically into a 64x128 display.

Today this is not possible. A HUB75 chain is electrically always horizontal, so N panels
always form an area of (panel width * N) x panel height. Declaring a different layout in
the 2D panel configuration only changes the logical area — BusHub75Matrix::show() still
walks the buffer using display->width():

const unsigned width = _panelWidth;      // = display->width() = physical chain width
size_t pix = 0;
for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { … pix++; }

So the same linear buffer is written with the logical width and read with the physical one,
and the image gets wrapped onto the chain. Measured on hardware: two 64x64 panels declared
as 64x128 with the upper half red showed red on the top half of both panels, instead of
red on the left panel and blue on the right.

Note the built-in preview (WebSocket live view) shows the logical area and therefore looks
correct — it is not usable as evidence for what actually reaches the panels.

How the code works

VirtualMatrixPanel from the DMA library already performs the logical-to-physical mapping,
including all the chain-type variants. WLED-MM only ever creates it for four-scan panels, and
there hard-coded as (1, chain_length, …) — always a single row.

bus_manager.cpp — a default: branch in the panel type switch now creates a
VirtualMatrixPanel for normal panel types too, as soon as rows or columns exceed 1.
rows * columns must equal the chain length; otherwise the arrangement is ignored and a
warning is printed.

bus_manager.h — the arrangement is carried in the existing bus pin field:

index meaning
[0] chain length
[1] virtual rows
[2] virtual columns
[3] PANEL_CHAIN_TYPE (0 = CHAIN_NONE, 1..4 = the plain variants, 5..8 = the ZigZag variants)

nPins for HUB75 goes from 1 to 4 and getPins() reports the arrangement back — otherwise
only the chain length survives a config save and the arrangement is silently lost.

Example for four 64x32 panels stacked vertically, chained bottom-left up in a zigzag:
pin: [4, 4, 1, 8].

Backwards compatibility: unset values are normalised to 1, so an existing pin: [2]
becomes [2, 1, 1, 0]. The arrangement stays dormant and behaviour is unchanged for every
existing configuration.

wled.cpp — safety fuse. A bad arrangement could in theory stall during panel
initialisation; the web server would never come up and a device without USB access would be
unreachable. So /vpanel_try.txt is written before beginStrip() and removed once the main
loop has been running for 20 s. If the marker is still present at boot, the arrangement is
skipped and the device boots normally. Deleting the file from the /edit page arms it again.
Both wled.cpp blocks are inside #ifdef WLED_ENABLE_HUB75MATRIX.

Testing performed

  • Builds: adafruit_matrixportal_esp32s3_tinyUF2 (HUB75 enabled) and esp32dev
    (HUB75 not enabled) both compile clean.
  • On hardware (Adafruit MatrixPortal S3, two 64x64 panels, pin: [2, 2, 1, 8]): WLED
    distributes the logical image onto the correct chain positions. The panels are physically
    mounted side by side, so this shows up as left/right — stacked it would be top/bottom.
  • Safety fuse on hardware: marker file appears about 8 s into boot and is gone by about
    21 s; a boot with the marker left in place skips the arrangement as intended.
  • Regression: an unchanged single-row configuration behaves exactly as before.

Known limitations / where I'd like a second opinion

  • The four-panel stacked case is not yet verified on hardware — that display is still
    being built. Verified so far is the two-panel case above, which exercises the same code
    path.
  • The chain types were derived by simulating the library's getCoords(), not by trying
    them on physical hardware.
    All eight stay within the area bounds (no out-of-range
    writes), but I cannot claim from measurement which one matches a given physical wiring.
    Only type 8 has actually been on a panel.
  • The arrangement is configured by hand in the pin array; there is no UI for it. I did
    not want to touch the settings pages without knowing whether you'd want it there at all,
    and if so, in what form. Happy to add it if you point me at the preferred place.
  • I kept _vRows / _vCols as uint8_t to fit the existing pin array. That caps the
    arrangement at 255 in each direction, which seems far beyond anything practical, but say
    the word if you'd rather have it typed differently.

AI assistance

Parts of this change were drafted with AI assistance. The relevant blocks are marked as such
in the code. I have gone through the result line by line, verified the behaviour on hardware
as described above, and left the surrounding existing comments untouched.

Summary by CodeRabbit

  • New Features
    • Added support for HUB75 panels arranged across multiple rows or columns.
    • Preserved panel arrangement settings, including chain length, virtual rows, columns, and chain type.
    • Added support for additional valid panel chain types and layouts.
  • Bug Fixes
    • Added validation for panel configurations, with automatic fallback to standard horizontal chaining when settings are invalid, unsupported, or unavailable.
    • Ensured outdated panel mappings are discarded when the configured arrangement changes.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Partly generated by an AI. Make sure that the contributor fully understands the code!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants