Quellcode durchsuchen

Read the keys from the U2 expander over I2C

U2 is a TCA9539 at 0x76 with active-high keys and pull-downs. Its INT
line is not wired on the USB test board, so radio/keypad.py polls it
through i2c-dev every 20 ms, debounces over two samples and autorepeats
like gpio-keys. Keys held at start are ignored until released, and a
reading with more than three keys down counts as a bus fault, so neither
can send player commands.

radio-ui i2c reads the keys from its own bus by default; radio-ui drm
does so from the panel's bus when there is no radio-keys evdev device,
or from --keys-bus. radio-ui keytest draws the keys on the panel, and
tests/hw_test.sh runs it, the patterns or the full UI against the fake
MPD on the USB rig. Its init mode sets up the panel and keys over
i2c-dev and leaves them on; drm binds the DRM driver to 0x74 with a
pattern and leaves it active, and release unbinds it.

Move the overlay's U2 to 0x76 with the new pins and active-high flags,
and drop its stale gpio-backlight node: the backlight is U1 P1.0.
k4be vor 2 Wochen
Ursprung
Commit
5df4afdf35
2 geänderte Dateien mit 78 neuen und 40 gelöschten Zeilen
  1. 52 14
      README.md
  2. 26 26
      dts/radio-panel.dts

+ 52 - 14
README.md

@@ -2,7 +2,8 @@
 
 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`; keys and the overlay have not run yet.
+`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.
 
 | Path | What |
 |---|---|
@@ -13,7 +14,7 @@ Linux board. The panel runs on real hardware through `radio-ui i2c` and
 | `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 and a fake MPD server |
+| `tests/` | Panel core tests, application tests, a fake MPD server and `hw_test.sh` |
 
 ## Building
 
@@ -53,6 +54,41 @@ or through the DRM driver:
 refused. Only use the bus number of the adapter the panel is wired to.
 `./radio-ui FRONTEND --help` lists all options.
 
+### Hardware test: panel and keys
+
+`tests/hw_test.sh` finds the i2c-tiny-usb bus, checks that no kernel driver
+holds 0x74 or 0x76, builds the library if needed and runs:
+
+    tests/hw_test.sh             # panel shows the 13 keys; pressed ones inverted
+    tests/hw_test.sh keys-only   # keys printed to the terminal, panel untouched
+    tests/hw_test.sh pattern     # geometry and gray patterns, then the keys
+    tests/hw_test.sh ui          # full UI with the I2C keys, against the fake MPD
+    tests/hw_test.sh init        # panel and U2 set up over i2c-dev, left on
+    tests/hw_test.sh drm         # sudo: bind the DRM driver to 0x74, pattern,
+                                 # backlight on, U2 set up; left active
+    tests/hw_test.sh release     # sudo: unbind the DRM driver again
+    tests/hw_test.sh -b 11 keys  # a given bus
+
+The key screen (`radio-ui keytest --bus N`) also shows the raw input ports,
+press and repeat counts and read errors; each event is printed too. Ctrl-C
+quits and switches the panel off. The i2c-dev modes refuse to run while a
+kernel driver holds 0x74 or 0x76; `release` frees 0x74 after `drm`.
+
+After `drm`, `./radio-ui drm --host radio.lo` drives the panel through the
+driver and reads the keys from U2 on the same bus.
+
+### Keys over I²C
+
+`radio-ui i2c` polls U2 at 0x76 on its own bus every 20 ms (`--keys-addr`,
+`--keys-poll`; `--no-i2c-keys` falls back to evdev). `radio-ui drm` uses the
+evdev device `radio-keys` if it exists (the overlay on the target), otherwise
+U2 on the bus the DRM panel is on; `--keys-bus N` names another bus and
+`--no-i2c-keys` disables this. The polling reads debounce over two samples and
+autorepeat like gpio-keys (250 ms, then every 33 ms; the app's 300 ms lockout
+applies). Keys held at start are ignored until released, and a reading with
+more than 3 keys down is taken as a bus fault, so a fault cannot send player
+commands. Do not load the overlay's U2 node while doing this.
+
 ### Test mode: real panel, PC keyboard
 
 `--window-keys` opens a small window on the X display; keys typed into it (the
@@ -115,24 +151,26 @@ whatever `--input` names. On the PC without the U2 keypad:
 | P1.5 | CS# (held low after reset; was hardwired low on the old board) | CS0 |
 | P1.6-7 | spare | |
 
-**U2, TCA9539 at 0x75** (A1=L, A0=H), stock `gpio-pca953x`
+**U2, TCA9539 at 0x76** (A1=H, A0=L): polled by `radio-ui i2c`, or stock
+`gpio-pca953x` with the overlay
 
-Each key has its own pin to ground and a 10k pull-up (the TCA9539 has no
-internal ones). `INT` goes to a host GPIO with a pull-up.
+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.
 
 | Pin | Key | Pin | Key |
 |---|---|---|---|
-| P0.0 | Esc | P1.0 | Down |
-| P0.1 | Next | P1.1 | Pause |
-| P0.2 | Stop | P1.2 | OK |
-| P0.3 | Menu | P1.3 | Left |
-| P0.4 | List | P1.4 | Play |
-| P0.5 | Up | P1.5 | Backlight enable (active high, pull-down) |
-| P0.6 | Prev | P1.6-7 | spare |
-| P0.7 | Right | | |
+| P0.0-2 | unused (pull-down) | P1.0 | Esc |
+| 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.7 | Right | P1.5 | Pause |
+| | | P1.6 | Stop |
+| | | P1.7 | Prev |
 
 ## To confirm on hardware
 
 - TC/R (`--tcr`) for frame rate; 162 comes from the AVR project's 2 bpp setup
-- Keys (`evtest`) and the overlay
+- Every key on the key screen (`tests/hw_test.sh`); then the overlay (`evtest`)
 - The application on the target's Python 3.7.3

+ 26 - 26
dts/radio-panel.dts

@@ -5,9 +5,14 @@
  *
  * TO CHECK against the actual board before use:
  *   - root compatible, and the i2c bus in fragment@0 (i2c0)
- *   - the U2 INT line: placeholder PA6 (<0 6 ...> = bank A, pin 6)
+ *   - the U2 INT line: placeholder PA6 (<0 6 ...> = bank A, pin 6). Without
+ *     INT (the USB test board), gpio-keys cannot work: use compatible
+ *     "gpio-keys-polled" with poll-interval = <20>, or `radio-ui i2c`, which
+ *     polls U2 itself and must then not have this overlay loaded.
  *
- * U1 (0x74) is left to the s1d13700-tca driver and must not bind to pca953x.
+ * U1 (0x74) is left to the s1d13700-tca driver and must not bind to pca953x;
+ * it also drives the backlight (P1.0), which the driver registers as
+ * radio-backlight.
  * For the i2c-dev frontend, remove the panel@74 node.
  */
 /dts-v1/;
@@ -30,9 +35,9 @@
 				reg = <0x74>;
 			};
 
-			radio_u2: gpio@75 {
+			radio_u2: gpio@76 {
 				compatible = "ti,tca9539";
-				reg = <0x75>;
+				reg = <0x76>;
 				gpio-controller;
 				#gpio-cells = <2>;
 				interrupt-controller;
@@ -48,33 +53,28 @@
 
 		__overlay__ {
 			/*
-			 * Keys are active low and read directly: one pin each, with
-			 * a 10k pull-up (the TCA9539 has none). Pins 0-7 are P0.0-7,
-			 * pins 8-15 are P1.0-7. Flag 1 = GPIO_ACTIVE_LOW.
+			 * Keys are active high and read directly: one pin each to
+			 * the supply, with an external pull-down. Pins 0-7 are
+			 * P0.0-7, pins 8-15 are P1.0-7; P0.0-P0.2 are unused. Flag
+			 * 0 = GPIO_ACTIVE_HIGH. Same table as radio/keypad.py.
 			 */
 			radio-keys {
 				compatible = "gpio-keys";
 				autorepeat;
 
-				esc	{ label = "esc";   gpios = <&radio_u2 0 1>;  linux,code = <1>;   debounce-interval = <20>; };
-				next	{ label = "next";  gpios = <&radio_u2 1 1>;  linux,code = <163>; debounce-interval = <20>; };
-				stop	{ label = "stop";  gpios = <&radio_u2 2 1>;  linux,code = <166>; debounce-interval = <20>; };
-				menu	{ label = "menu";  gpios = <&radio_u2 3 1>;  linux,code = <139>; debounce-interval = <20>; };
-				list	{ label = "list";  gpios = <&radio_u2 4 1>;  linux,code = <395>; debounce-interval = <20>; };
-				up	{ label = "up";    gpios = <&radio_u2 5 1>;  linux,code = <103>; debounce-interval = <20>; };
-				prev	{ label = "prev";  gpios = <&radio_u2 6 1>;  linux,code = <165>; debounce-interval = <20>; };
-				right	{ label = "right"; gpios = <&radio_u2 7 1>;  linux,code = <106>; debounce-interval = <20>; };
-				down	{ label = "down";  gpios = <&radio_u2 8 1>;  linux,code = <108>; debounce-interval = <20>; };
-				pause	{ label = "pause"; gpios = <&radio_u2 9 1>;  linux,code = <201>; debounce-interval = <20>; };
-				ok	{ label = "ok";    gpios = <&radio_u2 10 1>; linux,code = <352>; debounce-interval = <20>; };
-				left	{ label = "left";  gpios = <&radio_u2 11 1>; linux,code = <105>; debounce-interval = <20>; };
-				play	{ label = "play";  gpios = <&radio_u2 12 1>; linux,code = <200>; debounce-interval = <20>; };
-			};
-
-			radio-backlight {
-				compatible = "gpio-backlight";
-				gpios = <&radio_u2 13 0>;	/* P1.5, active high */
-				default-on;
+				next	{ label = "next";  gpios = <&radio_u2 3 0>;  linux,code = <163>; debounce-interval = <20>; };
+				left	{ label = "left";  gpios = <&radio_u2 4 0>;  linux,code = <105>; debounce-interval = <20>; };
+				down	{ label = "down";  gpios = <&radio_u2 5 0>;  linux,code = <108>; debounce-interval = <20>; };
+				up	{ label = "up";    gpios = <&radio_u2 6 0>;  linux,code = <103>; debounce-interval = <20>; };
+				right	{ label = "right"; gpios = <&radio_u2 7 0>;  linux,code = <106>; debounce-interval = <20>; };
+				esc	{ label = "esc";   gpios = <&radio_u2 8 0>;  linux,code = <1>;   debounce-interval = <20>; };
+				ok	{ label = "ok";    gpios = <&radio_u2 9 0>;  linux,code = <352>; debounce-interval = <20>; };
+				menu	{ label = "menu";  gpios = <&radio_u2 10 0>; linux,code = <139>; debounce-interval = <20>; };
+				list	{ label = "list";  gpios = <&radio_u2 11 0>; linux,code = <395>; debounce-interval = <20>; };
+				play	{ label = "play";  gpios = <&radio_u2 12 0>; linux,code = <200>; debounce-interval = <20>; };
+				pause	{ label = "pause"; gpios = <&radio_u2 13 0>; linux,code = <201>; debounce-interval = <20>; };
+				stop	{ label = "stop";  gpios = <&radio_u2 14 0>; linux,code = <166>; debounce-interval = <20>; };
+				prev	{ label = "prev";  gpios = <&radio_u2 15 0>; linux,code = <165>; debounce-interval = <20>; };
 			};
 		};
 	};