Explorar o código

Make radio-ui a standalone repository, with the panel core as a submodule

k4be hai 2 semanas
pai
achega
d27eeca8d7
Modificáronse 9 ficheiros con 104 adicións e 89 borrados
  1. 0 6
      .gitignore
  2. 3 0
      .gitmodules
  3. 29 44
      Makefile
  4. 46 22
      README.md
  5. 18 13
      docs/REPORT.md
  6. 1 0
      panel
  7. 1 1
      radio/panel.py
  8. 1 1
      tests/hw_test.sh
  9. 5 2
      tests/test_ui.py

+ 0 - 6
.gitignore

@@ -1,8 +1,2 @@
 build/
-driver/*.mod
-driver/*.mod.c
-driver/.*.cmd
-driver/Module.symvers
-driver/modules.order
-driver/.tmp_versions/
 __pycache__/

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "panel"]
+	path = panel
+	url = ../s1d13700-tca

+ 29 - 44
Makefile

@@ -1,62 +1,47 @@
-# Linux port: run from this directory.
-#   make test        panel core tests (no hardware, no libraries)
-#   make lib         panel core library for the Python UI (./radio-ui)
-#   make pytest      UI tests: MPD client, rendering, simulated panel
-#   make dtbo        device tree overlay
-#   make module      DRM driver, against KDIR (default: running kernel source)
-
-BUILD   := build
-CC      ?= gcc
-CFLAGS  ?= -O2 -g
-CFLAGS  += -std=gnu11 -Wall -Wextra -MMD -MP
-CFLAGS  += -Idriver -Isim
-KDIR    ?= /usr/src/linux
-
-CORE     := driver/s1d13700_core.c
-SIM      := sim/s1d13700_sim.c
-PYTHON   ?= python3
+# radio-ui: run from this directory.
+#   make lib         panel core library for the application (./radio-ui)
+#   make test        application tests: MPD client, rendering, simulated panel
+#   make panel-test  the panel core's own tests (in $(PANEL_DIR))
+#   make module      the DRM driver, against KDIR (for tests/hw_test.sh drm)
+#
+# PANEL_DIR is the s1d13700-tca repository: the submodule by default.
+
+BUILD     := build
+CC        ?= gcc
+CFLAGS    ?= -O2 -g
+CFLAGS    += -std=gnu11 -Wall -Wextra -MMD -MP
+PANEL_DIR ?= panel
+CFLAGS    += -I$(PANEL_DIR)/driver -I$(PANEL_DIR)/sim
+PYTHON    ?= python3
 PANEL_LIB := $(BUILD)/libradiopanel.so
 
-.PHONY: all test asan lib pytest dtbo module clean
-all: test lib
+CORE := $(PANEL_DIR)/driver/s1d13700_core.c
+SIM  := $(PANEL_DIR)/sim/s1d13700_sim.c
 
-# ---- tests -----------------------------------------------------------------
-$(BUILD)/test_panel: tests/test_panel.c $(CORE) $(SIM)
-	@mkdir -p $(dir $@)
-	$(CC) $(CFLAGS) -o $@ $^
-
-$(BUILD)/test_panel_asan: tests/test_panel.c $(CORE) $(SIM)
-	@mkdir -p $(dir $@)
-	$(CC) $(CFLAGS) -fsanitize=address,undefined -fno-sanitize-recover=all -o $@ $^
-
-test: $(BUILD)/test_panel
-	$<
+export PANEL_DIR
 
-asan: $(BUILD)/test_panel_asan
-	$<
+.PHONY: all lib test pytest panel-test module clean
+all: lib
 
-# ---- Python UI -------------------------------------------------------------
 lib: $(PANEL_LIB)
 
+$(CORE) $(SIM):
+	@echo "$@ missing: run 'git submodule update --init' or set PANEL_DIR" >&2; exit 1
+
 $(PANEL_LIB): radio/libpanel.c $(CORE) $(SIM)
 	@mkdir -p $(dir $@)
-	$(CC) $(CFLAGS) -fPIC -shared -o $@ $^
+	$(CC) $(CFLAGS) -fPIC -shared -o $@ radio/libpanel.c $(CORE) $(SIM)
 
-pytest: $(PANEL_LIB)
+test pytest: $(PANEL_LIB)
 	$(PYTHON) -W 'ignore::DeprecationWarning:gi.events' -m unittest discover -s tests -p 'test_*.py' -v
 
-# ---- device tree and kernel module -----------------------------------------
-dtbo: $(BUILD)/radio-panel.dtbo
-
-$(BUILD)/radio-panel.dtbo: dts/radio-panel.dts
-	@mkdir -p $(dir $@)
-	dtc -@ -I dts -O dtb -o $@ $<
+panel-test:
+	$(MAKE) -C $(PANEL_DIR) test
 
 module:
-	$(MAKE) -C $(KDIR) M=$(CURDIR)/driver modules
+	$(MAKE) -C $(PANEL_DIR) module
 
 clean:
 	rm -rf $(BUILD)
-	-$(MAKE) -C $(KDIR) M=$(CURDIR)/driver clean
 
--include $(shell find $(BUILD) -name '*.d' 2>/dev/null)
+-include $(wildcard $(BUILD)/*.d)

+ 46 - 22
README.md

@@ -1,28 +1,39 @@
-# Linux port
+# radio-ui: MPD front panel on an S1D13700 LCD
 
-Replaces the LPC1114 firmware: the panel and keys hang off I²C expanders on the
-Linux board. The panel runs on real hardware through `radio-ui i2c` and
-`radio-ui drm`. All 13 keys read correctly through the key expander on the test
-rig. The overlay has not run.
+The front panel of an internet radio: an MPD client that shows the current
+song, time, volume and playlist on a 240×160 S1D13700 graphic LCD and takes 13
+keys. The LCD and the keys hang off two TCA9539 I²C expanders on the Linux
+board (an Orange Pi Zero); this replaces an earlier LPC1114 microcontroller
+firmware. It runs on the radio, through the DRM driver or i2c-dev, and on a
+PC with a USB I²C bridge or a simulated panel in a window.
+
+The panel core (C), its simulator and the DRM driver are a separate
+repository, [s1d13700-tca](../s1d13700-tca), included here as the git
+submodule `panel/`.
 
 | Path | What |
 |---|---|
-| `driver/s1d13700_core.*` | Panel core, used by everything: init, 2 bpp conversion, write planner, TCA9539 stream |
-| `driver/s1d13700_drm.c` | DRM driver (6.x kernels) |
-| `sim/` | Model of the TCA9539 and S1D13700: decodes the I²C bytes and flags bus faults |
 | `radio/` | The application, in Python: UI, MPD client, I²C key polling and the `sim`, `i2c`, `drm` and `keytest` frontends |
 | `radio/libpanel.c` | The panel core and simulator as a library for the application |
 | `radio-ui` | Starts the application |
-| `dts/radio-panel.dts` | Overlay for the keys, backlight and panel |
-| `tests/` | Panel core tests, application tests, a fake MPD server and `hw_test.sh` |
+| `tests/` | Application tests, a fake MPD server and `hw_test.sh` |
+| `panel/` | Submodule: s1d13700-tca (panel core, simulator, DRM driver, device tree overlay) |
+| `docs/REPORT.md` | The port from the LPC1114 firmware: decisions, verification, history |
 
 ## Building
 
-    make test          # panel core tests, no hardware or libraries
+    git clone --recurse-submodules <url>/radio-ui.git
+    # or, in an existing clone:  git submodule update --init
+
     make lib           # build/libradiopanel.so, needed by the application
-    make pytest        # application tests, no hardware or display
-    make dtbo
-    make module KDIR=/path/to/kernel
+    make test          # application tests, no hardware or display
+    make panel-test    # the panel core's tests (in panel/)
+    make module KDIR=/path/to/kernel   # the DRM driver, in panel/driver/
+
+`PANEL_DIR=/path/to/s1d13700-tca` uses another checkout of the panel
+repository instead of the submodule (`make`, `tests/hw_test.sh` and the tests
+all read it). The key tests check `radio/keypad.py` and `radio/platform.py`
+against its `dts/radio-panel.dts`.
 
 The application runs on Python 3.7.3 (Debian buster) to 3.14 and needs
 PyGObject with GLib, Pango and PangoCairo, pycairo and its PyGObject bridge;
@@ -156,12 +167,12 @@ whatever `--input` names. On the PC without the U2 keypad:
 
 ## Wiring
 
-**U1, TCA9539 at 0x74** (A1=L, A0=L), raw I²C client of the panel code
+**U1, TCA9539 at 0x74** (A1=L, A0=L), driven by the panel core (`panel/README.md`)
 
 | Pin | Signal | Module pin |
 |---|---|---|
 | P0.0-7 | D0-D7 | D0-D7 |
-| P1.0 | Backlight enable (active high, assumed) | |
+| P1.0 | Backlight enable (active high) | |
 | P1.1 | RES# | RST |
 | P1.2 | A0 | A15 |
 | P1.3 | WR# | WE |
@@ -170,11 +181,11 @@ whatever `--input` names. On the PC without the U2 keypad:
 | P1.6-7 | spare | |
 
 **U2, TCA9539 at 0x76** (A1=H, A0=L): polled by `radio-ui i2c`, or stock
-`gpio-pca953x` with the overlay
+`gpio-pca953x` with the device tree (`panel/dts/`)
 
 Keys are active high: each pin has a pull-down (the TCA9539 has no internal
 ones) and its key connects it to the supply. `INT` is not connected on the USB
-test board, so the keys are polled; the final board wires it to a host GPIO.
+test board, so the keys are polled there; on the Orange Pi Zero it is on PA6.
 
 | Pin | Key | Pin | Key |
 |---|---|---|---|
@@ -187,8 +198,21 @@ test board, so the keys are polled; the final board wires it to a host GPIO.
 | | | P1.6 | Play |
 | | | P1.7 | Prev |
 
-## To confirm on hardware
+## On the Orange Pi Zero
+
+The radio's kernel, U-Boot and board device tree are built by the OPi0
+project (`build-kernel.sh`), which copies the driver from the s1d13700-tca
+repository and builds it in, together with `gpio-pca953x` and `gpio-keys`
+for U2. There `radio-ui drm` finds the panel and the `radio-keys` input
+device by itself. The backlight and input device permissions (udev rule,
+`video` and `input` groups) are described in `panel/README.md` and the OPi0
+README.
+
+On a kernel without the driver (Armbian 4.19), use `radio-ui i2c --bus 1`;
+set the bus to 400 kHz (`clock-frequency` on i2c1), the mv64xxx default of
+100 kHz makes a playlist redraw take about half a second.
+
+## Not settled
 
-- TC/R (`--tcr`) for frame rate; 162 comes from the AVR project's 2 bpp setup
-- Key autorepeat on Up/Down; then the overlay (`evtest`)
-- The application on the target's Python 3.7.3
+- TC/R (`--tcr`) for the frame rate; 162 comes from the AVR project's 2 bpp setup
+- Key autorepeat timing on held keys

+ 18 - 13
docs/REPORT.md

@@ -1,13 +1,18 @@
 # 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.
+This is the record of the port from the LPC1114 firmware, kept as it was
+written; only the paths were changed to the split repositories (this one,
+radio-ui, and s1d13700-tca for the panel core, simulator, driver and device
+tree). Current usage is in the READMEs.
+
+Status as of 2026-11-09. At the time all code was in `linux/` of
+the LPC1114 firmware repository.
 
 **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
+actual board (see `README.md`), and the review in
+`s1d13700-tca/docs/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.
 
@@ -29,8 +34,8 @@ which led to three fixes:
   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
+**Update 2026-11-11:** the application is now Python (`radio/`, run as
+`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
@@ -119,7 +124,7 @@ that drives the panel.
 
 ## 4. Components
 
-### Panel core (`linux/driver/s1d13700_core.*`)
+### Panel core (`s1d13700-tca/driver/s1d13700_core.*`)
 
 - **Stream encoder.** One write message starts with command byte `0x02`, then
   alternates P0 (data) and P1 (control). Each LCD cycle is
@@ -139,7 +144,7 @@ that drives the panel.
   rewritten rather than skipped.
 - **Error handling.** A transport error makes the next update rewrite the frame.
 
-### Simulator (`linux/sim/`)
+### Simulator (`s1d13700-tca/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
@@ -147,7 +152,7 @@ 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/`)
+### Application (`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
@@ -177,7 +182,7 @@ Key mapping in the window and the test mode's key window: `Z X C V B` prev/play/
 multimedia keyboard.
 OK, Menu, List, Left and Right wake the backlight only, as in the firmware.
 
-### DRM driver (`linux/driver/s1d13700_drm.c`)
+### DRM driver (`s1d13700-tca/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
@@ -187,11 +192,11 @@ 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`)
+### Device tree (`s1d13700-tca/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`.
+`armbian-add-overlay`. Wiring tables are in `README.md`.
 
 ## 5. Bus cost
 
@@ -331,7 +336,7 @@ cost on the board.
 ## 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.
+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; `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.
 

+ 1 - 0
panel

@@ -0,0 +1 @@
+Subproject commit b3e7f6625a10d88b3217d580d25036a127e869a4

+ 1 - 1
radio/panel.py

@@ -1,4 +1,4 @@
-"""The C panel core (driver/s1d13700_core.c) and simulator, through ctypes.
+"""The C panel core and simulator (from s1d13700-tca), through ctypes.
 
 The core is shared with the kernel driver, so it stays in C; build it with
 `make lib`. RADIO_PANEL_LIB overrides where the library is looked for.

+ 1 - 1
tests/hw_test.sh

@@ -45,7 +45,7 @@ fi
 echo "bus i2c-$bus: $(cat /sys/class/i2c-dev/i2c-"$bus"/name)"
 
 DRV=s1d13700-tca
-KO=driver/$DRV.ko
+KO=${PANEL_DIR:-panel}/driver/$DRV.ko
 dev74=/sys/bus/i2c/devices/$bus-0074
 
 as_root() { if [ "$(id -u)" = 0 ]; then "$@"; else sudo "$@"; fi; }

+ 5 - 2
tests/test_ui.py

@@ -14,6 +14,9 @@ from unittest import mock
 
 HERE = os.path.dirname(os.path.abspath(__file__))
 sys.path.insert(0, os.path.join(HERE, ".."))
+# the overlay in the s1d13700-tca repository: the submodule or PANEL_DIR
+PANEL_DIR = os.environ.get("PANEL_DIR", os.path.join(HERE, "..", "panel"))
+OVERLAY = os.path.join(PANEL_DIR, "dts", "radio-panel.dts")
 
 from gi.repository import GLib  # noqa: E402
 
@@ -278,7 +281,7 @@ class TestPlatform(unittest.TestCase):
             os_open.assert_not_called()
 
     def test_evdev_keys_match_overlay(self):
-        with open(os.path.join(HERE, "..", "dts", "radio-panel.dts")) as f:
+        with open(OVERLAY) as f:
             dts = f.read()
         import re
         found = dict((label, int(code)) for label, code in re.findall(
@@ -482,7 +485,7 @@ class FakeExpander(object):
 
 class TestKeypad(unittest.TestCase):
     def test_pins_match_overlay(self):
-        with open(os.path.join(HERE, "..", "dts", "radio-panel.dts")) as f:
+        with open(OVERLAY) as f:
             dts = f.read()
         import re
         found = dict((int(pin), label) for label, pin in re.findall(