# Radio front panel: Linux port report Status as of 2026-11-09. All code is in `linux/`. The LPC1114 firmware in the repository root is unchanged. **Update 2026-11-10:** the panel now runs on real hardware through i2c-dev (`radio-ui i2c --pattern geometry|gray` over a USB I²C bridge at 400 kHz): 240×160, 2 bpp and pixel polarity confirmed. The control lines were remapped to the actual board (see `linux/README.md`), and the review in `linux/s1d13700-recommendations.md` was applied to the core and the DRM driver. The DRM driver, keys and device tree overlay are still untested on hardware. **Later on 2026-11-10:** the full UI ran on the real panel (`radio-ui i2c --host`), which led to three fixes: - **Cursor block.** A memory write turns the controller's cursor on even when the DISP ON attributes say off (REG[0Ah] note in the hardware spec), leaving a block at the last write position. The core now re-sends DISP ON after any update that wrote VRAM while the display is on (12 I²C bytes). The simulator models the behaviour and the tests check that the cursor stays off and that an update while blanked does not switch the display back on. - **Text.** Gray glyph edges looked smeared at 2 bpp, so text is now drawn in plain black and white with full hinting (`TEXT_ANTIALIAS` in `radio/render.py` overrides this). The small and log fonts became Verdana and Andale Mono (Microsoft core fonts), with Liberation as the fallback. The log has 7 rows of 10 px, leaving room for Polish accents. - **DRM backlight.** The driver now registers a `radio-backlight` backlight device for the expander's P1.0 pin, driven from the flush worker, so the frontend's default sysfs path works. Still compiled only. **Update 2026-11-11:** the application is now Python (`linux/radio/`, run as `linux/radio-ui sim|i2c|drm`), written for Python 3.7.3 (Debian buster, on the target) through 3.14. The panel core stays in C, since the kernel driver shares it, and is loaded through ctypes from `build/libradiopanel.so` (`make lib`). The `sim` window's LCD area matched the C window pixel for pixel, apart from one pixel of progress bar caused by timing. New: a test mode (`--window-keys`) that drives the real panel and a real MPD but takes keys from a window on the PC's X display. The Python DRM frontend ran on the real panel with the driver loaded, against the fake MPD. The command names below were updated: `radio-gtk` → `radio-ui sim`, `radio-i2c` → `radio-ui i2c`, `radio-drm` → `radio-ui drm`. **Update 2026-11-13:** keys over I²C. U2 sits at **0x76** (A1 high, A0 low), and its keys are **active high with pull-downs**, wired P0.3-P0.7 Next, Left, Down, Up, Right and P1.0-P1.7 Esc, OK, Menu, List, Play, Pause, Stop, Prev (P0.0-P0.2 unused). `INT` is not connected on the USB test board, so `radio/keypad.py` polls the expander through i2c-dev every 20 ms, with debouncing, gpio-keys-style autorepeat, and protection against stuck keys and bus faults. `radio-ui i2c` uses it by default; `radio-ui drm --keys-bus N` can too, and falls back to it on its own when there is no `radio-keys` evdev device. `radio-ui keytest` shows the keys on the panel, and `tests/hw_test.sh` runs it, the patterns or the full UI on the rig. It can also set up the panel and U2 and leave them on (`init`, over i2c-dev), or bind the DRM driver to 0x74 and leave it active (`drm`, undone by `release`). Both ran on the rig: the driver bound as card1, and `radio-ui drm` with no options found U2 on i2c-11. On the rig, the expander answers, setup reads back (config `ffff`, polarity `0000`) and all keys read up. No key has been pressed yet. The overlay was moved to 0x76 with the new pins and active-high flags, and its stale `gpio-backlight` node on U2 P1.5 (now Pause) was dropped: the backlight is U1 P1.0. ## 1. Summary The LPC1114 is replaced by software on the Linux board, with the S1D13700 LCD and the keys attached through two TCA9539 I²C expanders. **Works today, without hardware:** the full UI runs in a desktop window against the real MPD on `radio.lo`, with on-screen buttons and keyboard shortcuts. Every frame takes the real path down to individual TCA9539 bytes, and a simulator of the expander and LCD controller decodes those bytes to produce the picture. **Runs on the USB test rig:** the panel through i2c-dev and through the DRM driver, the full UI on both, and the key expander U2: all 13 keys read correctly on the key screen. **Not yet run:** the device tree overlay, the application on the target board and its Python 3.7.3, and key autorepeat on real presses. What is still unconfirmed about the hardware is in section 7. ## 2. Decisions and how they changed | Topic | Original plan | Now | Reason | |---|---|---|---| | Keys | 4×4 matrix, `gpio-matrix-keypad` | 13 keys sensed directly: `gpio-keys` with the overlay, polled over i2c-dev until `INT` is wired | 13 of U2's 16 pins, no scanning; the backlight is on U1 P1.0 | | UI toolkit | LVGL | Cairo + Pango on GLib | LVGL was not installed; Pango handles Polish text directly | | Development | USB adapter first | Window + simulator first | Most of the logic needs no hardware | | MPD | Local | Host is an option; default `radio.lo` in the window, `localhost` on the panel frontends | Remote development | | Kernel | DRM driver only | DRM driver **and** an i2c-dev frontend | The i2c-dev path needs no kernel changes, so it works on 4.19 | **The stock `gpio-pca953x` driver is used for U2 only.** U1 needs one continuous I²C write alternating both ports, which the GPIO API cannot express; going through `gpiod` would cost roughly 2.5-3× more bus time per LCD byte. An I²C address binds to one driver, which is another reason for a separate expander. ## 3. Architecture MPD (mpd.py, idle events) ───────┐ /dev/kmsg (optional) ────────────┤ keys (evdev, U2 polled, window) ─┤ ▼ app.py + render.py (Cairo/Pango) Python │ XRGB8888 frame + changed rows ┌───────────────────────┼─────────────────────────┐ ▼ ▼ ▼ radio-ui sim radio-ui i2c radio-ui drm │ │ dumb buffer + DIRTYFB ▼ ▼ ▼ libpanel.c (ctypes) libpanel.c (ctypes) s1d13700_drm.c ▼ ▼ ▼ ┌───────────────── s1d13700_core.c ──────────────────────┐ │ XRGB→2 bpp · byte diff against shadow · write planner │ │ · TCA9539 stream encoder │ └────────────────────────────────────────────────────────┘ │ │ │ s1d13700_sim.c /dev/i2c-N (I2C_RDWR) i2c_master_send() The core has no OS dependency, so the code tested on the desktop is the code that drives the panel. ## 4. Components ### Panel core (`linux/driver/s1d13700_core.*`) - **Stream encoder.** One write message starts with command byte `0x02`, then alternates P0 (data) and P1 (control). Each LCD cycle is `data, WR=0, data, WR=1`. A0 changes get their own P0/P1 pair with WR# high, because A0 needs setup time before the WR# edge and shares a port with it. A cycle is never split across messages, so WR# is not left low when the bus is released. - **Init.** Programs expander outputs before directions, holds reset 20 ms, then configures the controller. Based on the AVR project's sequence, with changes from the datasheet: `FX=7` and `HDOT=0` (required above 1 bpp), `CM=1` (required in graphics mode; the AVR code had 0), grayscale value 1 (the LPC's 3 is reserved). VRAM is cleared before the display is turned on. - **Planner.** Compares each frame with a shadow of VRAM at byte level, so even a client that redraws everything costs only what changed. Rows with changes form bands, and each band is written horizontally or vertically (`CSRDIR` down), whichever is cheaper. Unchanged gaps up to 6 bytes (the cost of a seek) are rewritten rather than skipped. - **Error handling.** A transport error makes the next update rewrite the frame. ### Simulator (`linux/sim/`) Models the TCA9539 register pairs and the S1D13700 indirect interface, seeing only the I²C bytes. It counts faults: A0 changing with a WR# edge, parameters with no command or too many of them, unknown commands, bad registers, messages ending between P0 and P1, inconsistent SYSTEM SET, and writes during reset. The window frontend exits with an error code if any occurred. ### Application (`linux/radio/`) Python 3.7.3 to 3.14, with PyGObject (GLib, Pango, PangoCairo), pycairo and python3-gi-cairo; GTK 3 only for the window and the test mode, libdrm only for `drm`. The MPD protocol is implemented directly, so no MPD library is needed. | File | Role | |---|---| | `app.py` | Render scheduling, changed-rows detection, keys, backlight timeout, log batching, kernel log | | `render.py` | Screen layout: title, state icon, track, time, progress, options, volume, link warning, log | | `mpd.py` | Event-driven MPD connection; reconnects every 3 s | | `panel.py`, `libpanel.c` | The C panel core and simulator behind a handle, through ctypes | | `sim.py` | `sim`: window with simulated panel, buttons, shortcuts and a live traffic readout | | `gtkkeys.py` | Key table and buttons, and the test mode's key window | | `drm.py` | `drm`: the panel through the DRM driver (libdrm 2.4.97 calls, dumb buffer by ioctl) | | `platform.py` | evdev keys, sysfs backlight, i2c bus check, signal handling | | `keypad.py` | U2 over i2c-dev: setup, 20 ms polling, debounce, autorepeat, stuck-key and bus-fault guards | | `keytest.py` | `keytest`: the key screen for hardware tests | | `__main__.py` | Command line, `i2c` and `keytest` frontends, `--pattern geometry` / `gray` | Behaviour kept from the firmware: 300 ms key lockout, 30 s backlight, the same command for each key, no title while stopped. New: event-driven updates instead of 2 s polling, proper Polish characters, a progress bar, volume display. Log redraws are batched to at most one per second. Key mapping in the window and the test mode's key window: `Z X C V B` prev/play/pause/stop/next, arrows (Up/Down = volume), `Enter` OK, `Esc` refresh, `M` menu, `L` list, `Space` pause; also the media and volume keys of a multimedia keyboard. OK, Menu, List, Left and Right wake the backlight only, as in the firmware. ### DRM driver (`linux/driver/s1d13700_drm.c`) Atomic KMS driver modelled on the in-tree `st7571-i2c`, built against 6.18. Plane updates convert damage into a pending frame; a worker sends it, merging anything that arrives meanwhile. Messages are capped at 1025 bytes (about 23 ms) so other devices on the bus get a turn, and the adapter's `max_write_len` is honoured. Offers XRGB8888 and fbdev emulation, with counters in debugfs, and a `radio-backlight` backlight device for P1.0. Size, depth and TC/R are module parameters. ### Device tree (`linux/dts/radio-panel.dts`) Binds U1 to the driver, U2 (0x76) to `gpio-pca953x`, and defines `radio-keys`; the backlight comes from the driver. Numeric constants are used so it works with `armbian-add-overlay`. Wiring tables are in `linux/README.md`. ## 5. Bus cost | Update (240×160, 2 bpp, 400 kHz) | I²C bytes | Bus time | Source | |---|---|---|---| | One 8×13 digit | 169 | 3.8 ms | test suite | | Full frame | 38 474 (38 messages) | 867 ms | test suite | | Stopped screen from blank | 2 779 | 63 ms | window, real MPD | | Typical small update | 113-177 | 2.6-4.0 ms | window, fake MPD | These are calculated from the bytes sent, assuming an ideal 400 kHz bus. Real timing will be slower. Every update that writes VRAM includes 12 bytes for re-sending DISP ON (the cursor fix); the last two rows predate it. ## 6. Verification performed | Check | Result | |---|---| | Panel tests: init values, invalid configs, no-change = no traffic, direction choice, gap merging, 2000 random update rounds at 1/2/4 bpp and message sizes 7/61/1025, error recovery, pixel conversion | Pass, also under ASan and UBSan | | The simulator's fault detector fires on bad streams | Pass | | All frontends, the overlay and the module compile; module with `W=1` | No warnings shown | | Python UI tests (`make pytest`, 26 tests): MPD parsing, commands, push and reconnect against the fake server; rendering through the simulator with no faults; key lockout; patterns; bus refusal; evdev codes and U2 pins against the overlay; U2 setup, debounce, autorepeat, keys held at start, bus faults, poller error recovery; key screen | Pass on 3.14.7 | | `radio-ui sim` against the C window, same fake server | LCD area identical except one progress bar pixel (timing) | | `radio-ui drm` on the real panel (driver loaded), fake MPD | Runs, no errors from the frontend or the kernel | | Test mode key window: every shortcut, media key and window close, injected as GDK events | All 13 keys mapped; closing the window quits | | DRM ctypes structures and ioctl numbers against the C headers | Identical | | Window buttons against a fake MPD: Next, Up, Down, Pause, Prev, Stop, Play, Esc, Menu | The seven MPD commands sent correctly; Menu sends none | | Every key on the key screen (`tests/hw_test.sh`), USB rig | All 13 read correctly after swapping Play (P1.6) and Stop (P1.4) | | Real MPD on `radio.lo` (0.21.4), read-only | Connects and displays correctly; player state not changed | | MPD pushing a change | Triggers a refresh (fake server) | | Server lost, then back | Warning shown, reconnects automatically (fake server) | | `radio-i2c` (C) on PIIX4, AMDGPU I²C and AUX buses; Python bus check with mocked names | All refused, no traffic | Python 3.7.3 was not run here (no interpreter or container available): the code was parsed with `ast.parse(feature_version=(3, 7))` and avoids newer library calls, but needs a run on the target. Real X keyboard delivery to the key window was not exercised (no input injection tool), nor real MPD with key presses, to avoid changing playback. The Python i2c-dev path drove the panel on the rig (`tests/hw_test.sh init`); the full `radio-ui i2c` UI has not run there since the port. ## 7. Not verified These can only be settled with hardware. - ~~**TCA9539 write behaviour.**~~ Writes toggle within the register pair: the panel works, so the stream is sound. - ~~**Panel geometry.**~~ Confirmed 240×160 on 2026-11-10. - **TC/R and frame rate.** 162 is taken from the AVR's working 2 bpp setup. - ~~**Pixel polarity.**~~ Confirmed. Gray levels show, but text looks better without them (see the update at the top). - **Flicker.** The datasheet recommends display memory access during blanking, which can't be synchronised over I²C. The existing firmware doesn't either. - **A0 timing margin.** The conservative extra cycle may be removable, saving about a third of the seek cost. - **Key autorepeat.** All 13 keys read correctly on the key screen (Play and Stop were swapped and are fixed), but the repeat timing on held keys is unconfirmed. - **`radio-keys` device name.** Assumed from the node name; `--input` overrides it. - **DRM driver and frontend behaviour at runtime.** Also `/dev/kmsg` on the target. ## 8. Kernel: 4.19.62-sunxi or upgrade | | Stay on 4.19 | Upgrade to current | |---|---|---| | Panel | `radio-ui i2c` | `radio-ui drm` + driver, or `radio-ui i2c` | | Kernel changes | Overlay only | Overlay + module | | Standard graphics tools | No | Yes (DRM, fbdev emulation) | The driver cannot build on 4.19: it depends on damage tracking, shmem and client helpers from much later kernels. There is no 4.19 tree here to measure the gap. **Recommendation:** bring up on 4.19 with `radio-ui i2c`, which gets a working panel with no kernel risk. Upgrade only if standard graphics tools turn out to be wanted, since the application does not need DRM. **Allwinner I²C:** the `i2c-mv64xxx` driver has no FIFO handling, so it takes about one interrupt per byte, up to 44 000 per second during a long update. Short updates make this brief, but a full frame lasts most of a second. Measure the CPU cost on the board. ## 9. Remaining work **Phase 0: bring-up (needs an adapter or the SoC)** - [x] Wire U1 and the LCD (USB I²C bridge on the dev PC) - [ ] Capture one write on a logic analyzer: pair toggling, WR#/A0 order - [x] `--pattern geometry`: 240×160 confirmed - [x] `--pattern gray`: polarity confirmed - [ ] Tune `--tcr` (flicker, frame rate) - [ ] Decide whether the A0 extra cycle can go **Phase 1: keys and backlight** - [x] Rewire the keypad for direct sensing: active high, pull-downs, U2 at 0x76 - [x] Key expander answers on the rig, idle reading clean - [x] Press every key on `tests/hw_test.sh` (key screen): Play/Stop were swapped - [ ] Check repeat on Up/Down - [ ] Full UI with I²C keys against the fake MPD (`tests/hw_test.sh ui`) - [ ] Set the real root `compatible`, I²C bus and INT pin in the overlay - [ ] Check with `evtest`: all 13 keys, no bus traffic while idle - [ ] Check the backlight through sysfs **Phase 2: application on the board** - [ ] Install python3-gi, python3-gi-cairo, gir1.2-pango-1.0 and fonts (DejaVu); `make lib` on the SoC - [ ] Run `make pytest` on the target's Python 3.7.3 - [ ] Add a systemd unit with restart and `WatchdogSec` (the firmware had a watchdog; the app has no `sd_notify` yet) - [ ] Measure CPU load and real update times - [ ] Decide on volume control (section 11) - [ ] Tune font sizes and layout on the real panel (started: fonts, no antialiasing, log rows) - [ ] Install the Microsoft core fonts (Verdana, Andale Mono) or accept the Liberation fallback **Phase 3: DRM (only if upgrading)** - [ ] Upgrade the kernel; build the module for the target - [ ] Test with `modetest` and `radio-ui drm` (the frontend has run on the dev PC) - [ ] Add R1/R2 formats and a blank/power-save path if useful - [ ] Keep fbcon off this panel: a blinking cursor means constant I²C traffic **Phase 4: cutover** - [ ] Remove the firmware, serial autologin and `utils/` - [ ] Update the top-level README **Possible later improvements** - Hardware log scrolling via the controller's split screen (about 10× less traffic per scroll; needs a private interface in the driver) - Optional XOR pulse circuit for WR#, doubling throughput - Features for the unassigned keys - Connect to MPD without blocking the UI: a dead host currently stalls it for up to 2 s per attempt ## 10. Known limitations - MPD connection and DNS lookup block the main loop (up to 2 s per retry). - Only XRGB8888 is exposed by the driver; gray conversion is a plain threshold with no dithering. - The layout assumes 240×160; other sizes need its constants changed. - `SLEEP` power save is not used; blanking is display-off only. - Keys over i2c-dev are polled (50 reads/s) until `INT` is wired; the final board can use the overlay's `gpio-keys` instead. - The window's log pane shows only application messages unless `--kmsg` is given, and then shows the desktop's log rather than the radio's. ## 11. Open questions 1. ~~**Is the keypad a physical matrix?**~~ Settled: rewired for direct sensing, active high with pull-downs, U2 at 0x76. 2. **Volume.** `radio.lo` reports `volume: n/a`, and the old scripts used `amixer set DAC` directly. Without a working MPD mixer the Up/Down keys do nothing. The default hardware mixer looks for `PCM`, which the H3 codec lacks; `linux/README.md` gives the `mixer_control "DAC"` setting for `/etc/mpd.conf`; not yet confirmed on the board. 3. **Which SoC exactly?** The overlay's `compatible`, bus and INT pin are placeholders. 4. **Are other devices on the chosen I²C bus?** A dedicated bus is preferable. ## 12. Safety note for the development machine The development PC is an AMD BC-250. Its `I2C_HEADER1` and possibly its PIIX4 SMBus ports reach the voltage regulators (ISL69247, ISL95712). Do not attach the expanders there, and do not run `i2cdetect` scans on buses 6-10. `radio-ui i2c` refuses those buses by name. Use a dedicated USB adapter: the rig uses an ATmega8U2 running i2c-tiny-usb (load it with `delay=1` for 400 kHz). ## 13. References - [S1D13700F01 hardware specification, Rev. 4.07](https://global-origin.epson.com/products_and_drivers/semicon/pdf/id003161.pdf) - [TCA9539 datasheet (SCPS202C)](https://www.ti.com/lit/ds/symlink/tca9539.pdf) - [BC-250 pinouts](https://elektricm.github.io/amd-bc250-docs/hardware/pinouts) - In-tree template: `drivers/gpu/drm/sitronix/st7571-i2c.c` - AVR graphics driver: `~/avr-svn/zdalny_termometr_odb/common/`