Skip to content

fix(minui): add TrimUI Smart Pro input mapping on MinUI#253

Open
jellydn wants to merge 7 commits into
rommapp:mainfrom
jellydn:fix/tsp-min
Open

fix(minui): add TrimUI Smart Pro input mapping on MinUI#253
jellydn wants to merge 7 commits into
rommapp:mainfrom
jellydn:fix/tsp-min

Conversation

@jellydn

@jellydn jellydn commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What

Fixes two issues on the TrimUI Smart Pro running MinUI (#252):

  1. Key bindings not mappedDetectDevice() fell through to DeviceGeneric for tg5040, and GetInputMappingBytes() had no DeviceTrimui case, so no input mapping was loaded.
  2. Screen rotation stays vertical — the initial fix applied OrientationRotate90 for DeviceTrimui, but this was incorrect. The TSP kernel framebuffer is already 1280x720 landscape (confirmed via SSH/fbset), so no rotation is needed.

Why

On the TrimUI Smart Pro, MinUI sets MINUI_DEVICE=tg5040. The detectDeviceByEnv() function correctly mapped this to DeviceTrimui, but DetectDevice() did not include DeviceTrimui in its switch statement — it fell through to DeviceGeneric. This meant no input mapping was loaded (buttons unmapped).

The screen rotation issue was mistakenly attributed to needing OrientationRotate90, but the TSP kernel already handles this — the framebuffer reports 1280x720 natively.

How

Code fixes

  • cfw/minui/input_mappings.go: Added DeviceTrimui to the DetectDevice() switch so it returns the correct device type. Added a DeviceTrimui case to GetInputMappingBytes() to load trimui.json. Extracted devicetree paths into package-level variables for testability. Added DeviceTrimuiBrick device type detected via device-tree model string.
  • cfw/minui/input_mappings/trimui.json (new): SDL button mappings for the TrimUI Smart Pro, based on the proven muOS trimui-smart-pro.json mapping (same hardware, same SDL2 stack).
  • app/setup.go: No screen rotation is applied for DeviceTrimui — the kernel framebuffer is already correctly oriented. Rotation is only applied for DeviceZero28 (which actually needs it).

Tests

  • cfw/minui/input_mappings_test.go (new): Unit tests for detectDeviceByEnv(), DetectDevice(), and GetInputMappingBytes():
    • All env var values (tg5040, zero28, my355, unknown, empty)
    • Devicetree-based detection for Anbernic (h616), Zero28 (a133), and TrimUI Smart Pro / Brick
    • Regression test for issue MinUI on Trim Smart Pro: key bindings not mapped and screen rotation stays vertical #252 verifying TrimUI Smart Pro returns DeviceTrimui
    • Embedded mapping loading for trimui, anbernic, zero28, and nil returns for miyoo_flip/generic
    • Structural validation of trimui.json

Documentation

  • docs/getting-started/install-minui.md: Added note about TrimUI Smart Pro & Brick input mapping support.

Test Build

A test build is available for easy testing on real hardware:

⬇ Download Grout-MinUI.zip (57 MB)

  1. Download and unzip Grout-MinUI.zip
  2. Place the Grout.pak directory into SD_ROOT/Tools/tg5040/ on your SD card
  3. Launch Grout from the Tools menu

Notes

  • The tg5040 platform identifier in MinUI covers both the TrimUI Smart Pro and TrimUI Brick. The Brick is distinguished via device-tree model string.
  • No screen rotation is applied — the kernel already handles display orientation on these devices.
  • The input mapping is based on muOS trimui-smart-pro.json since both run SDL2 on identical hardware.

Checklist

  • Tests added or updated
  • Documentation updated
  • Test build attached for hardware testing
  • No breaking changes

jellydn added 4 commits July 8, 2026 21:01
…nFixes rommapp#252\n\n- Detect DeviceTrimui in DetectDevice() instead of falling through to DeviceGeneric\n- Add trimui.json input mapping based on muOS trimui-smart-pro.json\n- Apply OrientationRotate90 for DeviceTrimui (same Allwinner A133 SoC as Zero28)\n- Cache DetectDevice() result in initFramework to avoid redundant calls\n- Extract devicetreeCompatiblePath as package-level var for testability\n- Add unit tests for detectDeviceByEnv, DetectDevice, and GetInputMappingBytes\n- Update install-minui.md docs with TrimUI Smart Pro support note
The TrimUI Brick shares the tg5040 platform with the Smart Pro/Pro S in MinUI
but has a portrait panel (480x800) that does not need rotation. Distinguish them
via /sys/firmware/devicetree/base/model — if 'brick' is found in the model string,
return DeviceTrimuiBrick (same input mapping, no rotation).
The TSP framebuffer is already 1280x720 landscape at the kernel level
(confirmed via SSH/fbset). Applying OrientationRotate90 on top of that
breaks the display. Remove DeviceTrimui from the rotation check.
@jellydn jellydn changed the title fix(minui): add TrimUI Smart Pro input mapping and screen rotation fix(minui): add TrimUI Smart Pro input mapping on MinUI Jul 8, 2026
The TSP SDL button indices appear swapped from the standard assignment.
Match the gabagool default controller mapping where SDL A(0)→B and SDL B(1)→A.
@jellydn jellydn marked this pull request as ready for review July 8, 2026 14:21
@jellydn

jellydn commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

🔬 Code Quality Review (Thermo-Nuclear)

Overview

Reviewed the 379-line changeset across 6 files. The implementation is correct and functionally complete, with solid test coverage of the TrimUI Smart Pro and Brick detection paths. Below are structural findings with a plan to address them in follow-up PRs.


Finding 1 (Medium-High): DetectDevice() tangled fall-through

What: The function reads the device-tree compatible file at the top, uses it
to short-circuit for Anbernic and Zero28, then falls through to a switch that
reads the model file for the Trimui case. This wastes I/O on every call
(compatible file read is only useful for 2 of 5 paths) and has a subtle
shared-err pattern that is hard to follow.

Fix (deferred): Refactor to a flat, table-driven approach — read both
device-tree files once into a devicetreeInfo struct, then resolve the device
via a linear decision chain:

func DetectDevice() Device {
    if runtime.GOARCH == "arm" { return DeviceMiyoo }
    dt := readDevicetree()
    if strings.Contains(dt.compatible, "allwinner,h616") { return DeviceAnbernic }
    env := os.Getenv(DeviceType)
    if env == "zero28" && strings.Contains(dt.compatible, "allwinner,a133") { return DeviceZero28 }
    if env == "tg5040" && strings.Contains(dt.model, "brick") { return DeviceTrimuiBrick }
    if env == "tg5040" { return DeviceTrimui }
    if env == "my355" { return DeviceMiyooFlip }
    return DeviceGeneric
}

This eliminates wasted I/O, removes the shared-err subtlety, and makes the
resolution order explicit.


Finding 2 (Medium): initFramework growing CFW ladder

What: initFramework in app/setup.go has a growing chain of conditional
blocks for Spruce rotation, MinUI rotation, MiyooFlip input disable, etc. Each
new device adds another if/else clause, centralizing device-specific knowledge
in the main file.

Fix (deferred): Push display requirements into each CFW package via a
GetDisplayRequirements() function. Then initFramework becomes a simple
dispatcher with no device-specific knowledge.


Finding 3 (Medium): Package-level mutable IO vars for testing

What: devicetreeCompatiblePath and devicetreeModelPath are package-level
mutable globals, which requires withFakeDevicetree/withFakeDevicetreeModel
helpers and temp files in tests. The test file is 302 lines for 113 lines of
implementation.

Fix (deferred): Accept a DevicetreeReader struct instead of mutating
globals. This would eliminate all the test infrastructure helpers.


Plan

These findings are structural improvements that go beyond the scope of this PR.
They are tracked for follow-up cleanup and will not block merging this fix.

@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds TrimUI MinUI device support and mapping coverage. The main changes are:

  • Detects tg5040 as TrimUI instead of generic.
  • Adds a shared TrimUI Smart Pro and Brick input mapping.
  • Keeps TrimUI display orientation normal while preserving Zero28 rotation.
  • Adds MinUI detection and mapping tests.
  • Updates the changelog and MinUI install docs.

Confidence Score: 5/5

This looks safe to merge after confirming the Brick input event layout.

  • No blocking issues found in the changed code.
  • The only follow-up is to verify that Brick reports the same SDL button layout as the Smart Pro.

cfw/minui/input_mappings.go and cfw/minui/input_mappings/trimui.json

Important Files Changed

Filename Overview
cfw/minui/input_mappings.go Adds TrimUI and TrimUI Brick detection plus embedded mapping selection.
cfw/minui/input_mappings/trimui.json Adds the TrimUI input mapping used by both Smart Pro and Brick.
app/setup.go Limits MinUI rotation to Zero28 and reuses the detected MinUI device for input-source setup.
cfw/minui/input_mappings_test.go Adds tests for MinUI environment detection, device-tree detection, and embedded mapping loading.
docs/getting-started/install-minui.md Documents TrimUI Smart Pro and Brick input mapping support on MinUI.
.github/CHANGELOG.md Adds an unreleased changelog entry for the TrimUI MinUI fix.

Fix All in Claude Code

Reviews (1): Last reviewed commit: "fix(minui): swap A/B and X/Y in TSP inpu..." | Re-trigger Greptile

Comment on lines +104 to +105
case DeviceTrimui, DeviceTrimuiBrick:
filename = "input_mappings/trimui.json"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Brick Shares Smart Pro Mapping

When DetectDevice() returns DeviceTrimuiBrick, this branch loads the Smart Pro mapping unconditionally. If the Brick reports its dpad or triggers through SDL hat or axis events instead of the Smart Pro controller-button layout, those inputs stay unmapped even though the docs now list Brick support.

Fix in Claude Code

The Brick has a 1024×768 IPS display (confirmed from product page specs),
not a portrait panel. Update the install guide note and CHANGELOG entry.
@jellydn

jellydn commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Testing Status

  • TrimUI Smart Pro — tested and confirmed working (button mappings, no rotation)
  • MagicX Zero28 — tested and confirmed working
  • Other devices (Anbernic, Miyoo Flip, etc.) — need help testing to verify no regressions

Request for Review

This PR is now ready for review. Please test on your MinUI device if possible and report any issues. Key changes:

  1. Added DeviceTrimui case to DetectDevice() switch so input mappings load for tg5040 devices
  2. Removed incorrect screen rotation for TrimUI devices (kernel framebuffer is already landscape)
  3. Added DeviceTrimuiBrick detection via device-tree model (1024×768 IPS panel, same mapping, no rotation)
  4. Fixed A/B, X/Y button mapping to match TSP hardware layout

Test build available: https://github.com/jellydn/grout/releases/tag/v4.9.1.0-minui-tsp-fix

CC @jellydn

The Brick has a 1024x768 IPS display (confirmed from product page), not
a 480x800 portrait panel. Fix both the variable doc and the DetectDevice()
switch comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant