Ver Fonte

Swap Play and Stop on U2, record the key test

Pressing every key on the rig's key screen showed Play on P1.6 and Stop
on P1.4, the reverse of the map. Fix it in keypad.py, the overlay and
the README pin table. All 13 keys now read correctly; autorepeat timing
is still unconfirmed.

Document the MPD mixer setting the volume keys need: the H3 codec has
no PCM control, so the ALSA output has to use DAC.
k4be há 2 semanas atrás
pai
commit
80b5426d52
3 ficheiros alterados com 45 adições e 23 exclusões
  1. 17 6
      README.md
  2. 26 15
      docs/REPORT.md
  3. 2 2
      radio/keypad.py

+ 17 - 6
README.md

@@ -2,15 +2,15 @@
 
 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`. The key expander answers on the test rig and reads idle; no
-key has been pressed yet. The overlay has not run.
+`radio-ui drm`. All 13 keys read correctly through the key expander on the test
+rig. The overlay has not run.
 
 | 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 and the `sim`, `i2c` and `drm` frontends |
+| `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 |
@@ -32,6 +32,17 @@ GTK 3 for `sim` and `--window-keys`; libdrm for `drm`. On Debian:
 
 `RADIO_PANEL_LIB` points it at the library if it is not in `build/`.
 
+Volume is set through MPD (`volume ±1`), so MPD needs a working mixer. The
+default hardware mixer looks for a `PCM` control, which the H3 codec does not
+have; the firmware's old `volup`/`voldown` scripts used `DAC`, so the ALSA
+output in `/etc/mpd.conf` needs:
+
+    mixer_type      "hardware"
+    mixer_device    "default"
+    mixer_control   "DAC"
+
+Without it MPD's status has no `volume:` line and the volume keys do nothing.
+
 ## Running
 
 Window with the simulated panel, using a real MPD:
@@ -164,13 +175,13 @@ test board, so the keys are polled; the final board wires it to a host GPIO.
 | P0.3 | Next | P1.1 | OK |
 | P0.4 | Left | P1.2 | Menu |
 | P0.5 | Down | P1.3 | List |
-| P0.6 | Up | P1.4 | Play |
+| P0.6 | Up | P1.4 | Stop |
 | P0.7 | Right | P1.5 | Pause |
-| | | P1.6 | Stop |
+| | | P1.6 | Play |
 | | | P1.7 | Prev |
 
 ## To confirm on hardware
 
 - TC/R (`--tcr`) for frame rate; 162 comes from the AVR project's 2 bpp setup
-- Every key on the key screen (`tests/hw_test.sh`); then the overlay (`evtest`)
+- Key autorepeat on Up/Down; then the overlay (`evtest`)
 - The application on the target's Python 3.7.3

+ 26 - 15
docs/REPORT.md

@@ -69,16 +69,19 @@ 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.
 
-**Written and compiled, but never run:** the DRM kernel driver, the DRM frontend,
-the i2c-dev frontend against a real bus, and the device tree overlay. No part of
-this has touched real hardware, so everything about the hardware itself is still
-unconfirmed (section 7).
+**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` | 13 keys + backlight = 14 of U2's 16 pins; no scanning |
+| 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 |
@@ -93,7 +96,7 @@ address binds to one driver, which is another reason for a separate expander.
 
     MPD (mpd.py, idle events) ───────┐
     /dev/kmsg (optional) ────────────┤
-    keys (evdev, or a window) ───────┤
+    keys (evdev, U2 polled, window) ─┤
                                      ▼
                   app.py  +  render.py (Cairo/Pango)       Python
                                      │  XRGB8888 frame + changed rows
@@ -160,7 +163,9 @@ python3-gi-cairo; GTK 3 only for the window and the test mode, libdrm only for
 | `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 |
-| `__main__.py` | Command line, `i2c` frontend and its `--pattern geometry` / `gray` |
+| `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
@@ -208,12 +213,13 @@ re-sending DISP ON (the cursor fix); the last two rows predate it.
 | 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`, 17 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 against the overlay | Pass on 3.14.7 |
+| 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) |
@@ -223,8 +229,9 @@ 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. `radio-ui i2c` was not run on hardware after the port:
-the DRM driver held the panel's address at the time.
+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
 
@@ -240,6 +247,9 @@ These can only be settled with hardware.
   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.
 
@@ -276,7 +286,8 @@ cost on the board.
 **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
-- [ ] Press every key on `tests/hw_test.sh` (key screen), check repeat on Up/Down
+- [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
@@ -319,8 +330,8 @@ cost on the board.
 
 ## 11. Open questions
 
-1. **Is the keypad a physical matrix?** The firmware scans it as one. If the traces are wired that way, direct sensing needs rework; otherwise `gpio-matrix-keypad` remains an option with no code changes to the app.
-2. **Volume.** `radio.lo` reports `volume: n/a`, and the old scripts used `amixer set DAC` directly. If MPD has no working mixer, the Up/Down keys will only log an error. The fix is either an MPD mixer configuration or an ALSA path on the board.
+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.
 
@@ -329,8 +340,8 @@ cost on the board.
 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 such as an
-MCP2221A; this needs `CONFIG_HID_MCP2221` and `CONFIG_GPIOLIB` enabled.
+`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
 

+ 2 - 2
radio/keypad.py

@@ -39,9 +39,9 @@ KEY_PINS = {
     9: "ok",
     10: "menu",
     11: "list",
-    12: "play",
+    12: "stop",
     13: "pause",
-    14: "stop",
+    14: "play",
     15: "prev",
 }
 KEY_MASK = sum(1 << b for b in KEY_PINS)