Explorar el Código

Hide the S1D13700 cursor, sharpen text, add DRM backlight

A memory write turns the controller's cursor on regardless of the DISP ON
attributes, leaving a block at the last write position on the panel. Re-send
DISP ON after any update that wrote VRAM while the display is on, model the
behaviour in the simulator and test it.

Draw text without antialiasing, since gray edges smear at 2 bpp, and use
Verdana and Andale Mono with Liberation fallbacks. Give the log 10 px lines
for Polish accents, 7 rows.

Register a radio-backlight device in the DRM driver for the P1.0 pin,
driven from the flush worker.

Update the report and README after the first runs on the real panel,
including the test rig and ways to simulate keys.
k4be hace 2 semanas
padre
commit
e6fc6acdfb
Se han modificado 4 ficheros con 97 adiciones y 25 borrados
  1. 39 4
      README.md
  2. 1 1
      app/app.h
  3. 18 6
      app/ui_render.c
  4. 39 14
      docs/REPORT.md

+ 39 - 4
README.md

@@ -1,7 +1,8 @@
 # Linux port
 
 Replaces the LPC1114 firmware: the panel and keys hang off I²C expanders on the
-Linux board. Nothing here has run on real hardware yet.
+Linux board. The panel runs on real hardware through `radio-i2c`; the DRM
+driver, keys and overlay have not run yet.
 
 | Path | What |
 |---|---|
@@ -39,6 +40,42 @@ Real panel through i2c-dev, for bring-up or on a kernel too old for the driver:
 `--bus` must name a known adapter; motherboard and display buses are always
 refused. Only use the bus number of the adapter the panel is wired to.
 
+Text uses Verdana and Andale Mono (Microsoft core fonts) if installed, otherwise
+Liberation Sans and Mono, drawn without antialiasing.
+
+### Test rig on the development PC
+
+The panel hangs off an ATmega8U2 i2c-tiny-usb bridge. Load the driver for
+400 kHz (its default, `delay=10`, is only 50 kHz), then find the bus number:
+
+    sudo modprobe -r i2c_tiny_usb; sudo modprobe i2c_tiny_usb delay=1
+    grep -l i2c-tiny-usb /sys/bus/i2c/devices/i2c-*/name
+
+To try the keys without touching the real player, run the fake MPD and point
+the panel at it:
+
+    tests/fake_mpd.py 6601 build/mpd-commands.log 5 &
+    build/radio-i2c --bus 11 --host localhost --port 6601
+
+Never scan or use the other buses on this PC: some reach the CPU regulators.
+
+### Simulating keys
+
+The panel frontends read keys from evdev only: the device named `radio-keys`,
+or whatever `--input` names. On the PC without the U2 keypad:
+
+- **PC keyboard:** `--input /dev/input/by-id/<keyboard>-event-kbd` (needs read
+  access, group `input`). Arrows and Esc map directly; the media keys of a
+  multimedia keyboard map to Prev/Next/Stop if they send `KEY_PREVIOUSSONG`,
+  `KEY_NEXTSONG`, `KEY_STOPCD`. Play, Pause, OK, Menu and List have no
+  ordinary key. The keyboard keeps typing into the focused window too.
+- **Virtual device:** with `CONFIG_INPUT_UINPUT`, create a device named
+  `radio-keys` (for example `evemu-device` or python-evdev's `UInput`) and send
+  the codes in `app/platform_linux.c`. `radio-i2c` finds it without `--input`.
+  The development kernel has uinput disabled.
+- **Window:** `build/radio-gtk` has every key as a button and shortcut, but
+  draws on the simulated panel only.
+
 ## Wiring
 
 **U1, TCA9539 at 0x74** (A1=L, A0=L), raw I²C client of the panel code
@@ -72,7 +109,5 @@ internal ones). `INT` goes to a host GPIO with a pull-up.
 
 ## To confirm on hardware
 
-- The TCA9539 stays in the register pair across a long write (the whole stream depends on it)
-- Panel size: 240×160 is assumed; `--pattern geometry` shows the real one
 - TC/R (`--tcr`) for frame rate; 162 comes from the AVR project's 2 bpp setup
-- Pixel polarity (white = level 0 here)
+- The DRM driver, keys (`evtest`) and the overlay

+ 1 - 1
app/app.h

@@ -18,7 +18,7 @@ enum radio_key {
 
 enum play_state { PLAY_UNKNOWN, PLAY_PLAYING, PLAY_PAUSED, PLAY_STOPPED };
 
-#define LOG_ROWS	8
+#define LOG_ROWS	7
 #define LOG_COLS	44
 #define TITLE_MAX	512
 

+ 18 - 6
app/ui_render.c

@@ -4,11 +4,16 @@
 
 #include "app.h"
 
-/* Absolute sizes: these are panel pixels, not points */
+/*
+ * Absolute sizes: these are panel pixels, not points. Text is drawn without
+ * antialiasing, so these are fonts whose hinting holds up in plain black and
+ * white at 9-11 px. Verdana and Andale Mono are Microsoft core fonts, with
+ * Liberation as the fallback.
+ */
 #define FONT_TITLE	"DejaVu Sans 11px"
 #define FONT_STATUS	"DejaVu Sans Mono 10px"
-#define FONT_SMALL	"DejaVu Sans 9px"
-#define FONT_LOG	"DejaVu Sans Mono 9px"
+#define FONT_SMALL	"Verdana, Liberation Sans 9px"
+#define FONT_LOG	"Andale Mono, Liberation Mono 9px"
 
 #define TITLE_Y		0
 #define TITLE_LINES	3
@@ -18,7 +23,15 @@
 #define OPTIONS_Y	60
 #define LINK_Y		71
 #define LOG_Y		85
-#define LOG_LINE_H	9
+#define LOG_LINE_H	10	/* 9 px text: room for Polish accents */
+
+/*
+ * Gray edges look smeared on the panel at 2 bpp, so glyphs are rendered in
+ * plain black and white; full hinting snaps the outlines to the pixel grid.
+ */
+#ifndef UI_TEXT_ANTIALIAS
+#define UI_TEXT_ANTIALIAS	CAIRO_ANTIALIAS_NONE
+#endif
 
 static PangoLayout *new_layout(cairo_t *cr, const char *font)
 {
@@ -26,8 +39,7 @@ static PangoLayout *new_layout(cairo_t *cr, const char *font)
 	PangoFontDescription *d = pango_font_description_from_string(font);
 	cairo_font_options_t *fo = cairo_font_options_create();
 
-	/* crisp glyphs that survive reduction to four gray levels */
-	cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_GRAY);
+	cairo_font_options_set_antialias(fo, UI_TEXT_ANTIALIAS);
 	cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL);
 	cairo_font_options_set_hint_metrics(fo, CAIRO_HINT_METRICS_ON);
 	pango_cairo_context_set_font_options(pango_layout_get_context(l), fo);

+ 39 - 14
docs/REPORT.md

@@ -11,6 +11,24 @@ actual board (see `linux/README.md`), and the review in
 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-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 (`UI_TEXT_ANTIALIAS` overrides this
+  at build time). 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.
+
 ## 1. Summary
 
 The LPC1114 is replaced by software on the Linux board, with the S1D13700 LCD
@@ -124,7 +142,8 @@ Atomic KMS driver modelled on the in-tree `st7571-i2c`, built against 6.18. Plan
 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. Size, depth and
+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`)
@@ -137,13 +156,14 @@ Binds U1 to the driver, U2 to `gpio-pca953x`, and defines `radio-keys` and
 
 | Update (240×160, 2 bpp, 400 kHz) | I²C bytes | Bus time | Source |
 |---|---|---|---|
-| One 8×13 digit | 157 | 3.6 ms | test suite |
-| Full frame | 38 462 (38 messages) | 866 ms | test suite |
+| 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.
+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
 
@@ -166,13 +186,12 @@ real MPD with key presses, to avoid changing playback.
 
 These can only be settled with hardware.
 
-- **TCA9539 write behaviour.** The whole stream relies on writes toggling within
-  the register pair. The datasheet text I confirmed describes this for reads.
-  Everything else depends on it, so test it first.
-- **Panel geometry.** 240×160 is an assumption. The sources disagree: the LPC UI
-  assumes 240×168 but sets 160 lines, and the AVR's C/R=79 implies 320 px.
+- ~~**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 and how the gray levels look.**
+- ~~**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
@@ -203,10 +222,11 @@ cost on the board.
 ## 9. Remaining work
 
 **Phase 0: bring-up (needs an adapter or the SoC)**
-- [ ] Wire U1 and the LCD, confirm 3.3 V logic
+- [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
-- [ ] `--pattern geometry`: find the real size, fix defaults and the UI layout
-- [ ] `--pattern gray`: confirm polarity and levels; tune `--tcr`
+- [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**
@@ -220,7 +240,8 @@ cost on the board.
 - [ ] 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
+- [ ] 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
@@ -244,6 +265,10 @@ cost on the board.
 - 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.
+- The overlay's `gpio-backlight` node (U2 P1.5) and the DRM driver (U1 P1.0)
+  both want the name `radio-backlight`. Only one may exist: drop the node from
+  the overlay if the backlight stays on U1, or the driver's registration if it
+  moves to U2.
 - 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