Drive the 2720 Flip cover panel from userspace while closed
The shipping single-panel DTB left the external GC9305 unused because bananarchy-cover-idle only knew /dev/fb1. The compiled daemon now owns the shared QUP5 bus while the flip is closed: it claims gpio13/21/23 through the gpiochip ABI, replays the external firmware over /dev/spidev0.1 at the verified 25 MHz and pushes 240x240 RGB565 frames. LID OPEN restores the mux and releases the panel lines; activation also requires the main panel to be DPMS-off. Polarities are config keys and live SET knobs, with SET backend none as a rollback. /dev/fb1 keeps precedence and the two-panel spi-mux DT stays opt-in. Rebuilt the a1108/dejavu nokia-beatles image and pinned the verified hash ccc8c44517a6a3b78e16e45e9dddbf89f6f04a35ee4c52246d38d89970bd13ac in check-rebuild.sh. e2fsck -fn passes on both partitions, debugfs confirms the four updated rootfs files byte-for-byte, and the bootfs sync, boot image check, artifact sync, host tests and rebuild preflight all pass. This is an intermediate checkpoint: eyes-on confirmation that the cover lights up and several more polarity/CS fixes are still required.
This commit is contained in:
1 parent
d402a53221
commit
40a840b49b
12 files changed
+1085
-72
No files matched your search
@@ -72,9 +72,12 @@ Keep this file short. Full details live in `README.md`, `MANUAL.md`, `SDK.md`, `
|
||||
- The shipping 2720 Flip DTS/DTB is single-panel. The two-panel `/dev/fb1` layout is opt-in via
|
||||
`scripts/build-beatles-cover-panel.py`; rollback is `scripts/build-beatles-no-cover-dtb.py`. Do not make it default
|
||||
until gpio13 mux polarity and gpio21/gpio23 D/C/reset polarity are physically probed: a live test darkened both
|
||||
screens.
|
||||
screens. The shipping image drives the external GC9305 from userspace over `/dev/spidev0.1` while the flip is
|
||||
**closed only** (`bananarchy-cover-idle`); never claim gpio13/21/23 or send SPI traffic while the flip is open, and
|
||||
gate activation on the main panel being DPMS-off; always restore the mux to the internal panel on `LID OPEN`.
|
||||
- Keep the internal beatles panel at 25 MHz, `dc_gpio = -1` for the spidev fallback, external-panel firmware and
|
||||
initramfs module lists, the Xorg `card0` pin, `bananarchy-cover-diagnose.sh`, and `scripts/test-cover-dt.py` guards.
|
||||
initramfs module lists, the Xorg `card0` pin, `bananarchy-cover-diagnose.sh`, and the
|
||||
`scripts/test-cover-dt.py` / `scripts/test-cover-spidev.py` guards.
|
||||
- Build the lk2nd display image from pinned `bootloader/lk2nd/nokia-beatles.patch`. Exact stock IDs, 512 MiB memory
|
||||
fallback, appended DTB, `quiet splash`, and the low-bit reboot cookie matter. `check-lk2nd-beatles.py`,
|
||||
`test-lk2nd-beatles-port.py`, `check-beatles-bootimg.py`, `sync-beatles-bootfs.py --check`, and `check-rebuild.sh`
|
||||
|
||||
+10
-1
@@ -13,6 +13,15 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
|
||||
|
||||
Work since `a1108` has focused on reliable 2720 Flip hardware support and a reproducible boot/flash path. Earlier incremental and superseded diagnostic entries are consolidated here.
|
||||
|
||||
### Closed-flip external panel on the shipping 2720 Flip image
|
||||
|
||||
- **Problem**: both GC9305 panels share one BLSP1 QUP5 SPI bus through a gpio13 mux. The shipping image registers only the 240x320 internal panel, so `bananarchy-cover-idle` had no `/dev/fb1` and reported `backend=none`: the cover screen was never driven in the closed flip state. Registering both panels in the DT (`devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts`) does produce `/dev/fb1`, but an earlier live test darkened the main panel, so that layout is deliberately opt-in.
|
||||
- **Switch**: `src/bananarchy-daemons/bananarchy-cover-idle.c` now owns the external GC9305 from userspace while the flip is **closed only**. It claims gpio13 (mux), gpio21 (D/C) and gpio23 (reset) through the gpiochip v1 ABI, drives the mux to the cover panel, pulses reset, replays `/lib/firmware/nokia,beatles-gc9305-ext-panel.bin` over `/dev/spidev0.1` at the verified 25 MHz, and writes 240x240 RGB565 frames with proper D/C and CS framing. On `LID OPEN` it sends GC9305 display-off, restores the mux to the internal panel, releases the D/C and reset lines and stops all SPI traffic, so Xorg's `card0` cannot lose the bus. Activation additionally requires the main panel to be DPMS-off (`card0-SPI-1/dpms`), which is the real closed-flip condition and rejects the transient lid-state flap observed when `bananarchy-lid` restarts. While open the daemon holds no panel handles and issues no transfers; the mux line stays claimed for the daemon's lifetime so it is always explicitly driven back to the internal panel. `/dev/fb1` still takes precedence when the opt-in two-panel DT is installed (`backend = auto`), `backend = fb|spidev|none` forces a path, and `FBIOBLANK` blanking of the fbdev is unchanged.
|
||||
- **Hardware measurements**: on the live `nokia-beatles` target over root SSH, `/sys/kernel/debug/gpio` showed gpio13 `out low` with the main panel active (low = internal, high = cover), gpio21/gpio23 free inputs, gpio25 (`reset`) and gpio110 (`dc`) claimed by `panel-mipi-dbi-spi`, and `l17`/`l6` panel rails enabled. gpio13 therefore stays an output-low mux select and the daemon never requests gpio110. Polarities were *not* confirmed with eyes on the cover panel, so they remain config keys and runtime `bananarchy-coverctl SET` knobs, with `SET backend none` as a one-command rollback.
|
||||
- **Live verification**: the rebuilt ARM daemon, config, service and diagnostics were deployed to the phone. With the flip open, `STATUS` reports `backend=idle spi=1 mux=free` and gpio13 stays low. After `LID CLOSED` + `BUTTON` (lid broadcaster stopped, main panel DPMS-off to emulate a closed flip), `STATUS` reports `backend=spidev visible=1 mux=closed`, gpio13 goes high, the daemon holds `/dev/gpiochip0`, two `gpio-linehandle` fds and `/dev/spidev0.1`, and every init/frame ioctl succeeds. `BLANK` sends display-off; `LID OPEN` restores gpio13 low and `mux=open`. Xorg, dwm, `card0-SPI-1 dpms=On` and backlight 14 were restored afterwards, the lid service was restarted, and stopping the cover service leaves gpio13 output-low. Physical illumination of the cover still needs eyes-on sign-off.
|
||||
- **Guards and docs**: `scripts/test-cover-spidev.py` compiles the daemon in SPI simulation mode and verifies the open-flip bus silence, the DPMS-On gate, mux-first ordering, firmware replay, RGB565 frame size, display-off on blank, handover on open, polarity knobs, `SET backend none` rollback and `/dev/fb1` precedence. `scripts/check-rebuild.sh` guards the new source/config tokens and both compiled ARM copies. `bananarchy-cover-diagnose.sh` reports the spidev node, TLMM lines and polarity config. README, MANUAL and `AGENTS.md` describe the closed-flip-only ownership; the shipping DTB stays single-panel and the two-panel DT stays opt-in. `prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle` and its overlay mirror were rebuilt with `scripts/build-bananarchy-daemons.sh`.
|
||||
- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu` with the closed-flip external-panel backend; the verified raw hash is `ccc8c44517a6a3b78e16e45e9dddbf89f6f04a35ee4c52246d38d89970bd13ac`, pinned by `scripts/check-rebuild.sh`. `debugfs` confirms the image rootfs carries the rebuilt `bananarchy-cover-idle` and the new config, service and diagnostics byte-for-byte; `e2fsck -fn` passed on both `pmOS_boot` and `pmOS_root`; `sync-beatles-bootfs.py --check`, `check-beatles-bootimg.py`, artifact sync and `check-rebuild.sh` pass. The standalone `boot-bananarchy-nokia-beatles.img` hash is unchanged. Eyes-on confirmation that the cover panel lights up is still pending, so this is an intermediate build.
|
||||
|
||||
### Power menu label
|
||||
|
||||
- Shortened the Power menu item **Reboot to bootloader** to **Reboot to loader** in `dmenu.so`, `sxmo_appmenu.sh` and the context-menu hook so the full label fits the 240x320 screen. Rebuilt `dmenu.so`, updated the prebuilt and overlay artifacts and guards, and kept the `sxmo_power.sh bootloader` action unchanged.
|
||||
@@ -23,7 +32,7 @@ Work since `a1108` has focused on reliable 2720 Flip hardware support and a repr
|
||||
- **Connection path**: `overlay/rootfs/etc/bluetooth/main.conf` now uses `ControllerMode = dual`, preserving classic A2DP/HSP/HFP profiles while allowing LE HOGP. `input.conf` keeps `UserspaceHID=true`, `LEAutoSecurity=true` and `ClassicBondedOnly=false`. `bananarchy-bt-obex` powers the adapter on, calls the narrow `bananarchy-bt-le-enable.sh` helper, sets `PreferredBearer = le` for devices exposing HID service `00001812-...`, and automatically pairs unbonded peripherals selected through **Connect Device**.
|
||||
- **Daemon lifecycle**: `bananarchy-bt-obex stop` no longer calls `pkill`, which is absent from the BusyBox-based target rootfs; it now terminates the PID-file daemon and scans `/proc` directly for stale daemon command lines.
|
||||
- **Guards and live verification**: `scripts/test-bluetooth-hid.py` and `check-rebuild.sh` guard the dual-mode config, HOGP settings, pair/connect preflight, LE bearer selection and auto-pair logic. On the live phone, `bluetoothd -d` showed `Loading hog plugin` with no `System does not support hog plugin` rejection after the change, and `btmgmt info` showed `le` in the controller's current settings immediately after `bluetoothctl power on`.
|
||||
- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu` after the Bluetooth HID and Power menu label fixes; the verified raw hash is `16cc68cbfa9908dd42a36e1e4dd18149f9d8e43f7c5af30839695a89a5e60783`, pinned by `check-rebuild.sh`. `debugfs` confirms the image rootfs has `ControllerMode = dual`, the corrected `0755` `bananarchy-bt-obex` helper, the explicit Bluetooth packages and a `dmenu.so` containing only the compact `Reboot to loader` label; `e2fsck -fn` passed. This supersedes the previous image hash `c5dc3e2b...`.
|
||||
- **Image persistence**: rebuilt `images/bananarchy-nokia-beatles.img` at `a1108` / `dejavu` after the Bluetooth HID and Power menu label fixes; the verified raw hash at that point was `16cc68cbfa9908dd42a36e1e4dd18149f9d8e43f7c5af30839695a89a5e60783` (superseded by the closed-flip cover rebuild below). `debugfs` confirms the image rootfs has `ControllerMode = dual`, the corrected `0755` `bananarchy-bt-obex` helper, the explicit Bluetooth packages and a `dmenu.so` containing only the compact `Reboot to loader` label; `e2fsck -fn` passed. This supersedes the previous image hash `c5dc3e2b...`.
|
||||
|
||||
### Live Bluetooth peripheral discovery
|
||||
|
||||
|
||||
@@ -456,7 +456,7 @@ Three native X11 games (`/usr/bin/snake`, `/usr/bin/tetris`, and `/usr/bin/scoun
|
||||
- **X startup and keypad**: OpenRC starts independent services in parallel; `etc/init.d/local` replaces its stock `after *` dependency, which deadlocked with parallel startup on this image. `udev_settle_timeout=2` stops missing modem firmware from holding the display manager behind a long `udevadm settle`, and `bananarchy-sshd-debug` starts independently of `local.d`. A boot-open flip reads `/run/bananarchy/lid-state` and starts in `state=unlock` with no passcode screen, so the keypad is live as soon as `dwm` starts. If the keypad is dead, check `rc-service bananarchy-lid status`, `cat /run/bananarchy/lid-state`, `sxmo_state.sh get`, `/tmp/bananarchy_screen_locked`, `DISPLAY=:0 xwininfo -id 0xa00001` and `DISPLAY=:0 xinput list`.
|
||||
- **Display distortion above 71% brightness**: the internal panel uses 25 MHz SPI on `nokia-beatles`, rather than the 50 MHz timing used by the other targets. This keeps the link stable when the MPP2 backlight PWM duty rises above the level-10/14 operating point. The brightness range remains 1–14 with no artificial cap, and panel offsets/init registers are unchanged. The timing can be checked with `dtc -I dtb -O dts /boot/qcom-msm8905-nokia-beatles.dtb | grep -A8 'display@0'`.
|
||||
- **Closing the flip**: `bananarchy-lid` reads the current `EV_SW` switch mask from `/dev/input/event2`, follows hall edge events with an 80 ms stability window, and reconciles the raw gpio36/gpio92 debugfs levels every 200 ms even while evdev is present. This covers missed edges and stale `EVIOCGSW` state without a busy-polling loop. On close it blanks the main panel and keypad LED immediately, runs `sxmo_state.sh set screenoff` and tells the cover daemon `LID CLOSED`; on open it clears the lock flag, restores both backlights, sends a trusted `CLOSE` to `locker.so` and runs `sxmo_state.sh set unlock`. Check `rc-service bananarchy-lid status`, `sxmo_state.sh get` and `grep -E " gpio(36|92) " /sys/kernel/debug/gpio`. If the hall polarity is inverted on your unit, set `BANANARCHY_LID_GPIO_FILE` to a different debugfs GPIO file for the fallback path.
|
||||
- **Cover display status and behaviour**: `bananarchy-cover-idle` is the compiled 0%-CPU default daemon and answers `bananarchy-coverctl` (`PING`, `STATUS`, `LID CLOSED|OPEN`, `BUTTON`, `NETWORK`, `BATTERY`, `NOTIFY`, `BLANK`/`UNBLANK`, `TEST`); the native `bananarchy-coverd` is retained only for diagnostics. With the flip **open** the external panel is fully off (all-black frame plus backlight 0) and `BUTTON` is ignored. With the flip **closed** the panel stays off until an external side key is pressed: `bananarchy-volume-keys` reads `/run/bananarchy/lid-state` and sends the trusted `BUTTON` datagram instead of changing the volume, which shows the live clock, date, battery percentage and the compact main network indicators (`4G SIG75 WIFI`-style, published by `bananarchy-cover-status.sh` from the NetworkManager dispatcher and at service start). No further button blanks the cover after exactly the same **Config -> Screen blank** timeout that `dwm` uses (`~/.config/sxmo/idle_blank_timeout`, default 300 s, `0` = never; `blank_timeout = auto` in `/etc/bananarchy/cover-display.conf` selects it, a numeric value overrides it). The daemon blocks in `poll()` with no timer while off, so idle CPU stays at 0%. The renderer uses the 32-bpp fbdev `write()` path (not `mmap()`, which raises `SIGBUS` on the DRM fbdev). The shipping DTS deliberately keeps the verified single-panel layout, so `/dev/fb1` is normally absent. A live test produced a working 240x240 external framebuffer but made the main panel go dark, so the two-panel `spi-mux` wiring is opt-in in `devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts`: build it with `scripts/build-beatles-cover-panel.py`, install the resulting DTB/boot.img into `pmOS_boot`, and verify the main panel before keeping it. `scripts/build-beatles-no-cover-dtb.py` builds the single-panel rollback DTB. The external firmware and `mux-core`/`mux-gpio`/`spi-mux` modules are already provisioned in the initramfs; `bananarchy-coverctl STATUS` reports `backend=fb` only when the opt-in DT is installed, otherwise `backend=none`. `scripts/test-cover-idle.py` verifies the state machine with a fake framebuffer, while `scripts/test-cover-dt.py` validates both the shipping single-panel DTB and the opt-in two-panel DT, the firmware lists and the Xorg pin. Physical sign-off of gpio13 mux polarity, the external gpio21 D/C and gpio23 reset polarity, and the lk2nd boot splash is still required on a live 2720 Flip; `devices/nokia-beatles/cover-panel.dtsi` remains a compile-checked reference for older DTBs. Run `bananarchy-cover-diagnose.sh` on the phone to check `/dev/fb1`, its geometry, the DRM cards, the loaded mux/panel modules, the firmware, the lid state and `bananarchy-coverctl STATUS` in one report. If the external panel disturbs the main display during sign-off, `scripts/build-beatles-no-cover-dtb.py --install` builds the verified single-panel DTB and patches the local boot image / `pmOS_boot`; `sync-beatles-bootfs.py` without overrides restores the shipping DTB. "Fully off" is a black frame plus `FBIOBLANK`/`FB_BLANK_POWERDOWN` on the fbdev (and the optional `backlight_path` sysfs node when present).
|
||||
- **Cover display status and behaviour**: `bananarchy-cover-idle` is the compiled 0%-CPU default daemon and answers `bananarchy-coverctl` (`PING`, `STATUS`, `LID CLOSED|OPEN`, `BUTTON`, `NETWORK`, `BATTERY`, `NOTIFY`, `BLANK`/`UNBLANK`, `TEST`, `SET`); the native `bananarchy-coverd` is retained only for diagnostics. With the flip **open** the external panel is fully off and the daemon does not touch the shared QUP5 SPI bus at all; activation also requires `card0-SPI-1/dpms = Off`, so a transient lid-state flap cannot steal the bus from a live main panel. With the flip **closed** the daemon claims gpio13 (SPI bus mux), gpio21 (external D/C) and gpio23 (external reset) via `/dev/gpiochip0`, drives the mux to the cover panel, resets the GC9305, replays `/lib/firmware/nokia,beatles-gc9305-ext-panel.bin` over `/dev/spidev0.1` at 25 MHz and writes 240x240 RGB565 frames. `STATUS` reports `backend=spidev` and `mux=closed` while the cover owns the bus, and `mux=open` after `LID OPEN`, which sends display-off, restores the mux to the internal panel and releases the D/C and reset lines before Xorg flushes another frame. This is why the shipping image can use the cover screen without registering a second panel in the DT: both GC9305s share one SPI bus and the main panel is DPMS-off whenever the flip is closed. The panel stays off until an external side key is pressed: `bananarchy-volume-keys` reads `/run/bananarchy/lid-state` and sends the trusted `BUTTON` datagram instead of changing the volume, which shows the live clock, date, battery percentage and the compact main network indicators (`4G SIG75 WIFI`-style, published by `bananarchy-cover-status.sh` from the NetworkManager dispatcher and at service start). No further button blanks the cover after exactly the same **Config -> Screen blank** timeout that `dwm` uses (`~/.config/sxmo/idle_blank_timeout`, default 300 s, `0` = never; `blank_timeout = auto` in `/etc/bananarchy/cover-display.conf` selects it, a numeric value overrides it). The daemon blocks in `poll()` with no timer while off, so idle CPU stays at 0%. `backend = auto` prefers `/dev/fb1` when the opt-in two-panel DT is installed, using the 32-bpp fbdev `write()` path (not `mmap()`, which raises `SIGBUS`) and `FBIOBLANK`/`FB_BLANK_POWERDOWN` for "fully off". `backend = spidev` forces the userspace path, `backend = fb` forces the fbdev path and `backend = none` releases the bus; `SET backend none` is a live rollback. The external D/C, reset and mux polarities are config keys (`mux_closed_level`, `mux_open_level`, `dc_command_level`, `dc_data_level`, `reset_assert_level`, `reset_idle_level`) and runtime `SET` knobs, so physical sign-off needs no rebuild: close the flip (or hold `LID CLOSED` with the lid broadcaster stopped), run `bananarchy-coverctl TEST bars`, then try `SET mux_closed_level 0|1`, `SET reset_assert_level 0|1` and `SET dc_command_level 0|1` until the bars appear. The shipping DTS deliberately keeps the verified single-panel layout, so `/dev/fb1` is normally absent. A live test with two panels registered produced a working 240x240 external framebuffer but made the main panel go dark, so the two-panel `spi-mux` wiring is opt-in in `devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts`: build it with `scripts/build-beatles-cover-panel.py`, install the resulting DTB/boot.img into `pmOS_boot`, and verify the main panel before keeping it. `scripts/build-beatles-no-cover-dtb.py` builds the single-panel rollback DTB. The external firmware and `mux-core`/`mux-gpio`/`spi-mux` modules are already provisioned in the initramfs; `scripts/test-cover-idle.py`, `scripts/test-cover-spidev.py` and `scripts/test-cover-dt.py` verify the state machine, the closed-flip bus handover and both DT layouts on the host. Physical sign-off of the external D/C and reset polarity and of the cover backlight is still required with eyes on a live 2720 Flip; `devices/nokia-beatles/cover-panel.dtsi` remains a compile-checked reference for older DTBs. Run `bananarchy-cover-diagnose.sh` on the phone to check `/dev/fb1`, `/dev/spidev0.1`, the GPIO lines, the mux/panel modules, the firmware, the lid state and `bananarchy-coverctl STATUS` in one report. If the external panel disturbs the main display during sign-off, `SET backend none` releases the bus immediately and `scripts/build-beatles-no-cover-dtb.py --install` rebuilds the verified single-panel DTB/boot image for `pmOS_boot`.
|
||||
- **Camera app frozen / UI unresponsive**: check `top` for `bananarchy-volume-keys`. The daemon must be a single instance at 0% CPU; stale evdev fds are pruned by `prune_devices()`/`drop_device()` and guarded by `flock`. `rc-service bananarchy-volume-keys status` and `bananarchy-keypad-diagnose.sh` report its state. `xcamera` should return immediately and `bananarchy-photo <file>` should write a 600x800 JPEG.
|
||||
- **Camera**: `/dev/video0` is provided by the out-of-tree `msm8905-cam` module, loaded at boot by `/etc/modules-load.d/bananarchy-hardware.conf` and `etc/local.d/10-bananarchy-hardware.start`. Check with `v4l2-ctl --list-devices`; a missing node means the module did not load (previously caused by a missing `/bin/sed` breaking the `modules` service).
|
||||
- **Side volume keys**: the compiled evdev daemon `bananarchy-volume-keys` reads `KEY_VOLUMEUP`/`KEY_VOLUMEDOWN` directly and calls `sxmo_audio.sh vol up/down 5`; `sxmo_audio.sh` mirrors that percentage into the live PipeWire sink (the MSM8905 mainline kernel has no ALSA card yet). Press a side button and check `wpctl get-volume <sink-id>`; `bananarchy-keypad-diagnose.sh` reports the XKB mapping and both volume values.
|
||||
|
||||
@@ -50,7 +50,7 @@ Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs
|
||||
- **Kopher SmallWeb browser (`xkopher` / `kopher` / `xsmallweb` / `smallweb.so`)**: multi-protocol SmallWeb client for **Gopher** (`gopher://`) with optional TLS (`gophers://`), **Gemini** (`gemini://`), **Spartan** (`spartan://`), and **Nex** (`nex://`), featuring WAP-style default keypad controls from [Kopher](https://code.luxferre.top/luxferre/kopher.git), user-adjustable keybindings (`~/.config/sxmo/smallweb_controls.tsv`), 10 bookmarks, custom homepage support, and link focus that always scrolls the viewport to the focused link in both wrapped and unwrapped modes.
|
||||
- **Webarchy Web browser (`webarchy` / `xwebarchy` / `webarchy.so`)**: full-featured HTML5/CSS3/JS web browser built on WPE / WebKit (`webkit2gtk-4.1` + `libwpe-1.0`) with Adreno 304 hardware acceleration (`WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS`, WebGL, accelerated 2D canvas, and 512 MB RAM pressure tuning), default KaiOS 4.0 User-Agent (`Mozilla/5.0 (Mobile; rv:123.0) Gecko/123.0 Firefox/123.0 KAIOS/4.0`) with preset and custom User-Agent override (`~/.config/sxmo/webarchy_ua.txt`), `UTF-8` default encoding fallback, `Noto Sans` / `Noto Serif` (`font-noto` + `font-noto-emoji`) as the default non-monospace browser fonts and `Fira Code` with OpenType ligatures as the monospace font, full GStreamer multimedia (`MediaSource` / MSE, WebAudio, inline HTML5 `<video>`/`<audio>` autoplay without user gesture requirements), unobtrusive bookmarking (`*HTTPS`/`*HTTP` header badge, `*`+`0-9` save / `#`+`0-9` load chords, and bookmark manager), and dual navigation modes (keypad link-stepping mode with NeoUI multi-tap form input by default, plus an optional `*#` accelerated mouse cursor emulation mode), and a device-aware renderer profile: the 2720 Flip uses the WebKit CPU renderer (with automatic software fallback after a WebProcess crash) while the 8110 4G keeps Adreno 304 acceleration; `~/.config/sxmo/webarchy_software_renderer` forces the CPU profile on any target. The image build also compiles the installed GSettings schema XML into `usr/share/glib-2.0/schemas/gschemas.compiled`; without that database WebKit's network process aborts with an internal error before any renderer policy can help.
|
||||
- **GPS-only system time**: **Config -> Time source** switches from NTP to GNSS only (stopping `chronyd` and disabling every network-up NTP burst) and **Config -> Sync GPS time** steps the clock from a ModemManager GPS UTC value or a valid RMC fix, writes the RTC and refreshes the status bar. All GPS queries now resolve the GNSS-capable modem through `bananarchy-gps-modem.sh` instead of the ambiguous `mmcli -m any`, which fixes empty GPS data on the dual-SIM 2720 Flip. See `MANUAL.md` sections 5.6 and 5.8.
|
||||
- **2720 Flip cover display behaviour**: the compiled `bananarchy-cover-idle` renderer keeps the external panel fully off while the flip is open, waits for a side-button `BUTTON` event when closed, then shows the clock, battery and compact main network indicators until the same **Config -> Screen blank** timeout expires with no further button press. `bananarchy-volume-keys` turns the external keys into trusted cover wake events, `bananarchy-cover-status.sh` publishes modem/Wi-Fi indicators from network events, and the daemon blocks in `poll()` with no timer while off. The external GC9305 DT is **opt-in** (`devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts`, built with `scripts/build-beatles-cover-panel.py`): a live test produced `/dev/fb1` (240x240, 32bpp) and the full renderer state machine, but the shared SPI bus darkened the main panel, so the shipping DTB stays on the verified single-panel layout. `FBIOBLANK` powers the cover fbdev down when it is off, `bananarchy-cover-diagnose.sh` reports the live panel state, `scripts/test-cover-idle.py` and `scripts/test-cover-dt.py` validate the renderer and both DT layouts on the host, and `scripts/build-beatles-no-cover-dtb.py` builds the single-panel rollback.
|
||||
- **2720 Flip cover display behaviour**: the compiled `bananarchy-cover-idle` renderer keeps the external panel fully off while the flip is open, waits for a side-button `BUTTON` event when closed, then shows the clock, battery and compact main network indicators until the same **Config -> Screen blank** timeout expires with no further button press. `bananarchy-volume-keys` turns the external keys into trusted cover wake events, `bananarchy-cover-status.sh` publishes modem/Wi-Fi indicators from network events, and the daemon blocks in `poll()` with no timer while off. **The external 240x240 GC9305 is now driven on the shipping single-panel image**: with the flip closed the daemon claims gpio13 (SPI mux), gpio21 (D/C) and gpio23 (reset) through `/dev/gpiochip0`, replays `/lib/firmware/nokia,beatles-gc9305-ext-panel.bin` over `/dev/spidev0.1` at the verified 25 MHz, and pushes RGB565 frames, but only while the main panel is DPMS-off; on open it sends display-off, restores the mux to the internal panel and releases the panel lines before Xorg can flush another main-panel frame. `backend = auto` prefers `/dev/fb1` when the opt-in two-panel DT is installed. All mux/D-C/reset polarities are config keys plus live `bananarchy-coverctl SET` knobs, and `SET backend none` is a one-command rollback. The two-panel `spi-mux` DT (`devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts`, built with `scripts/build-beatles-cover-panel.py`) stays **opt-in**: a live test produced `/dev/fb1` (240x240, 32bpp) but darkened the main panel, so the shipping DTB keeps the verified single-panel layout until gpio13 and the external D/C/reset polarities are probed with eyes on the phone. `FBIOBLANK` powers the cover fbdev down when it is off, `bananarchy-cover-diagnose.sh` reports the live panel state, `scripts/test-cover-idle.py`, `scripts/test-cover-spidev.py` and `scripts/test-cover-dt.py` validate the renderer, the closed-flip backend and both DT layouts on the host, and `scripts/build-beatles-no-cover-dtb.py` builds the single-panel rollback.
|
||||
- **GPS reception test utility (`bananarchy-gps`) and OpenStreetMap navigator (`xgps` / `xmaps` / `xnav` / `gps.so`)**: CLI GNSS/GPS diagnostic tool (`bananarchy-gps status|enable|disable|nmea|watch`) and 3-tab NeoUI GPS navigator (`1:GPS Status`, `2:OSM Map`, `3:Nav/Search`) with live NMEA/QMI PDS satellite and 3GPP cell telemetry, interactive `240x212` OpenStreetMap slippy-map tile viewer with offline PNG tile cache (`~/.cache/sxmo/osm_tiles/`), Nominatim place search, saved waypoints, and OSRM turn-by-turn route geometry and step navigation.
|
||||
- **Themes (`xthemes`), wallpapers (`xwallpapers`), and ringtones (`xringtones`)**: installable `.Xresources` color and font themes (`~/.xthemes/*.xth`, 21 preinstalled schemes including `LynxLair.xth`) with live zero-restart reload across the entire UI, `dunst` notification popups (`bananarchy-sync-dunst-theme`), and terminal, alongside dedicated managers for desktop wallpapers and 3-tab call ringtones & notification/SMS alerts (`1:Ringtone`, `2:Notif/SMS`, `3:Settings`, supporting standard audio, tracker modules, and Nokia RTTTL `.nrt`/`.rtttl`/`.rtx`, Ericsson eMelody `.emy`, and IrDA iMelody `.imy` monophonic ringtones via `/usr/bin/bananarchy-melody`, wired into `sxmo_notifs.sh` and `sxmo_hook_notification.sh`) with 3-level vibration control.
|
||||
|
||||
@@ -201,7 +201,7 @@ sudo ./flash-edl.sh nokia-argon
|
||||
|
||||
The patched EDL client library is vendored under `vendor/edl/` (MIT), so a clean clone flashes without any manual download. `flash-edl.sh` also installs `pyusb` and `pyserial` into the gitignored `.flash-deps/` directory when the host lacks them; set `BANANARCHY_EDL_DIR` to use a different library checkout.
|
||||
|
||||
After a successful flash the phone boots lk2nd's branded boot splash, then the Plymouth boot splash, then X. Log in over the USB network with `ssh user@172.16.42.1` (password `147147`); if the main sshd's PAM stack is ever broken, a USB-only fallback listener accepts the same credentials on `ssh -p 2222 user@172.16.42.1`. Selecting **Reboot to loader** from the Power menu shows the visible lk2nd Fastboot menu; **Bootloader** stays in fastboot, **EDL** enters Sahara, and `fastboot reboot` returns to Linux. On the 2720 Flip, OpenRC starts independent services in parallel with a patched `local` service, a bounded `udevadm settle` and an independent USB fallback sshd keep X from waiting on modem firmware, a boot-open lid starts unlocked with a live keypad, and the external cover panel wiring is opt-in pending gpio13 mux / reset polarity sign-off; the shipping DTS keeps the known-good single internal panel. See `MANUAL.md` section 4.1 for first-boot troubleshooting of the boot splash, keypad input and the external cover display.
|
||||
After a successful flash the phone boots lk2nd's branded boot splash, then the Plymouth boot splash, then X. Log in over the USB network with `ssh user@172.16.42.1` (password `147147`); if the main sshd's PAM stack is ever broken, a USB-only fallback listener accepts the same credentials on `ssh -p 2222 user@172.16.42.1`. Selecting **Reboot to loader** from the Power menu shows the visible lk2nd Fastboot menu; **Bootloader** stays in fastboot, **EDL** enters Sahara, and `fastboot reboot` returns to Linux. On the 2720 Flip, OpenRC starts independent services in parallel with a patched `local` service, a bounded `udevadm settle` and an independent USB fallback sshd keep X from waiting on modem firmware, a boot-open lid starts unlocked with a live keypad, and the external cover panel is driven only while the flip is closed by the compiled userspace spidev backend; the two-panel `spi-mux` DT stays opt-in pending gpio13 mux / reset polarity sign-off and the shipping DTS keeps the known-good single internal panel. See `MANUAL.md` section 4.1 for first-boot troubleshooting of the boot splash, keypad input and the external cover display.
|
||||
|
||||
See [MANUAL.md](MANUAL.md) for complete EDL, Fastboot, and microSD installation instructions, keypad navigation shortcuts, and the multi-mode T9 reference.
|
||||
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
# /home/user/.config/bananarchy/cover-display.conf and are applied by
|
||||
# the xcover DWM plugin at session start.
|
||||
|
||||
# auto = /dev/fb1 (kernel spi-mux) -> /dev/spidev0.1 -> no hardware
|
||||
# auto = /dev/fb1 (opt-in two-panel spi-mux DT) when present, otherwise the
|
||||
# compiled /dev/spidev0.1 backend while the flip is closed. Both panels share
|
||||
# QUP5 SPI through the gpio13 mux, so the userspace backend is NEVER used with
|
||||
# the flip open: the main 240x320 panel keeps the bus then. fb = fbdev only,
|
||||
# spidev = force spidev, none = keep the bus untouched (rollback).
|
||||
backend = auto
|
||||
fb_device = /dev/fb1
|
||||
spidev_device = /dev/spidev0.1
|
||||
@@ -23,6 +27,24 @@ reset_gpio = 23
|
||||
# only when the spi-mux kernel modules own both panels instead.
|
||||
dc_gpio = -1
|
||||
|
||||
# Closed-flip userspace GC9305 backend. gpio13 is held low by the boot chain
|
||||
# while the main panel is active, so low = internal, high = cover. The 240x240
|
||||
# panel has its own D/C (gpio21) and reset (gpio23) lines. All polarities are
|
||||
# config knobs for the physical sign-off: change them here, restart the
|
||||
# service, and use bananarchy-coverctl TEST bars with LID CLOSED.
|
||||
spi_device = /dev/spidev0.1
|
||||
spi_mux_gpio = 13
|
||||
spi_dc_gpio = 21
|
||||
spi_reset_gpio = 23
|
||||
mux_open_level = 0
|
||||
mux_closed_level = 1
|
||||
dc_command_level = 0
|
||||
dc_data_level = 1
|
||||
reset_assert_level = 0
|
||||
reset_idle_level = 1
|
||||
# Keep the verified internal-panel clock on the shared bus.
|
||||
spi_speed_hz = 25000000
|
||||
|
||||
# Privacy defaults: no caller name, no notification body, no text in logs.
|
||||
enabled = 1
|
||||
show_caller = 0
|
||||
@@ -33,7 +55,6 @@ brightness = 160
|
||||
# Follow Config -> Screen blank (~/.config/sxmo/idle_blank_timeout, default
|
||||
# 300 s, 0 = never). A numeric value here overrides it for the cover panel.
|
||||
blank_timeout = auto
|
||||
# Optional sysfs node for the external panel backlight. Empty while the cover
|
||||
# panel DT overlay is hardware-gated: the daemon still writes an all-black
|
||||
# frame, which is the software-visible "fully off" state.
|
||||
# Optional sysfs node for the external panel backlight. Empty: the daemon
|
||||
# writes an all-black frame and sends GC9305 display-off (0x28) instead.
|
||||
backlight_path =
|
||||
@@ -5,8 +5,10 @@
|
||||
description="Nokia 2720 Flip external cover display"
|
||||
# The recovered native bananarchy-coverd busy-loops at 100% CPU on the
|
||||
# spidev backend (gpio110/DC is owned by panel-mipi-dbi-spi) and paints
|
||||
# nothing. Keep that binary installed for the future spi-mux work, but run
|
||||
# the compiled idle IPC server in the default runlevel. No Python runs here.
|
||||
# nothing. Keep that binary installed as a diagnostic, but run the compiled
|
||||
# idle IPC server: it drives the external panel through /dev/spidev0.1 only
|
||||
# while the flip is closed and hands the QUP5 bus back on open. No Python
|
||||
# runs here.
|
||||
command="/usr/bin/bananarchy-cover-idle"
|
||||
command_args="--config /etc/bananarchy/cover-display.conf"
|
||||
command_background="yes"
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#!/bin/sh
|
||||
# Report the live state of the 2720 Flip external panel (/dev/fb1).
|
||||
# Report the live state of the 2720 Flip external panel (closed-flip backend).
|
||||
# Intended for the physical gpio13/reset/DC sign-off: it never changes state.
|
||||
set -u
|
||||
|
||||
FB=/dev/fb1
|
||||
SYSFS=/sys/class/graphics/fb1
|
||||
SPI=/dev/spidev0.1
|
||||
GPIOCHIP=/dev/gpiochip0
|
||||
FW=/lib/firmware/nokia,beatles-gc9305-ext-panel.bin
|
||||
CONF=/etc/bananarchy/cover-display.conf
|
||||
COVERCTL=/usr/bin/bananarchy-coverctl
|
||||
|
||||
printf '=== Bananarchy cover display diagnostics ===\n'
|
||||
@@ -24,11 +27,22 @@ if [ -e "$FB" ]; then
|
||||
fi
|
||||
done
|
||||
else
|
||||
printf 'framebuffer : %s ABSENT (panel-mipi-dbi did not probe)\n' "$FB"
|
||||
printf 'framebuffer : %s absent (single-panel shipping DTB)\n' "$FB"
|
||||
fi
|
||||
if [ -e "$SPI" ]; then
|
||||
printf 'spidev : %s present\n' "$SPI"
|
||||
else
|
||||
printf 'spidev : %s MISSING\n' "$SPI"
|
||||
fi
|
||||
if [ -e "$GPIOCHIP" ]; then
|
||||
printf 'gpiochip : %s present\n' "$GPIOCHIP"
|
||||
else
|
||||
printf 'gpiochip : %s MISSING\n' "$GPIOCHIP"
|
||||
fi
|
||||
printf 'DRM cards : %s\n' "$(ls /dev/dri/card* 2>/dev/null | tr '\n' ' ')"
|
||||
printf 'main panel dpms : %s\n' "$(cat /sys/class/drm/card0-SPI-1/dpms 2>/dev/null || printf 'unknown')"
|
||||
printf 'fbdev nodes : %s\n' "$(ls /dev/fb* 2>/dev/null | tr '\n' ' ')"
|
||||
for mod in mux_core mux_gpio spi_mux panel_mipi_dbi; do
|
||||
for mod in mux_core mux_gpio spi_mux panel_mipi_dbi spidev; do
|
||||
if grep -q "^$mod " /proc/modules 2>/dev/null; then
|
||||
printf 'module %-20s: loaded\n' "$mod"
|
||||
else
|
||||
@@ -41,6 +55,14 @@ else
|
||||
printf 'panel firmware : %s MISSING\n' "$FW"
|
||||
fi
|
||||
printf 'mux select (lid-state): %s\n' "$(cat /run/bananarchy/lid-state 2>/dev/null || printf 'unknown')"
|
||||
if [ -r /sys/kernel/debug/gpio ]; then
|
||||
printf 'TLMM lines :\n'
|
||||
grep -E '^ gpio(13|21|23|25|110) ' /sys/kernel/debug/gpio | sed 's/^/ /'
|
||||
fi
|
||||
if [ -r "$CONF" ]; then
|
||||
printf 'backend config :\n'
|
||||
grep -E '^(backend|spi_device|spi_mux_gpio|spi_dc_gpio|spi_reset_gpio|mux_open_level|mux_closed_level|dc_command_level|dc_data_level|reset_assert_level|reset_idle_level|spi_speed_hz) ' "$CONF" | sed 's/^/ /'
|
||||
fi
|
||||
if [ -x "$COVERCTL" ]; then
|
||||
printf 'daemon : %s\n' "$("$COVERCTL" STATUS 2>/dev/null || printf 'not answering')"
|
||||
else
|
||||
@@ -49,4 +71,9 @@ fi
|
||||
if command -v rc-service >/dev/null 2>&1; then
|
||||
rc-service bananarchy-cover-display status 2>&1 | sed 's/^/service : /'
|
||||
fi
|
||||
printf 'sign-off : LID CLOSED; TEST bars, then LID OPEN\n'
|
||||
printf ' bananarchy-coverctl SET mux_closed_level 0|1\n'
|
||||
printf ' bananarchy-coverctl SET reset_assert_level 0|1\n'
|
||||
printf ' bananarchy-coverctl SET dc_command_level 0|1\n'
|
||||
printf ' rollback: bananarchy-coverctl SET backend none\n'
|
||||
exit 0
|
||||
Binary file not shown.
Binary file not shown.
@@ -373,7 +373,7 @@ fi
|
||||
echo "[check] Known-good flashable image set..."
|
||||
for pair in \
|
||||
"69a44f60eb123ebddf600be927155dc4a599ec35b7a0cf80060f4ba01f599f08 images/bananarchy-nokia-argon.img" \
|
||||
"16cc68cbfa9908dd42a36e1e4dd18149f9d8e43f7c5af30839695a89a5e60783 images/bananarchy-nokia-beatles.img" \
|
||||
"ccc8c44517a6a3b78e16e45e9dddbf89f6f04a35ee4c52246d38d89970bd13ac images/bananarchy-nokia-beatles.img" \
|
||||
"2b5c61aba307dbbda61f3b19a2ad5770f9854f41cba4e2c97e24efb7e20879f3 images/boot-bananarchy-nokia-beatles.img" \
|
||||
"b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d images/boot-lk2nd-nokia-beatles-display.img"; do
|
||||
set -- $pair
|
||||
@@ -1442,6 +1442,45 @@ if command -v gcc >/dev/null 2>&1 && \
|
||||
fail "host cover display behaviour test failed"
|
||||
fi
|
||||
|
||||
echo "[check] Closed-flip external panel backend..."
|
||||
for token in 'cover_hw_release' 'cover_spi_draw' 'hw_init_panel' \
|
||||
'mux_closed_level' 'reset_assert_level' 'spi_speed_hz' \
|
||||
'BANANARCHY_COVER_SPI_SIM' 'BA_GPIO_GET_LINEHANDLE' \
|
||||
'BA_SPI_IOC_MESSAGE' 'MIPI DBI' \
|
||||
'cover_main_panel_is_off'; do
|
||||
if ! grep -qF -- "$token" "$COVER_SRC"; then
|
||||
fail "bananarchy-cover-idle.c lost the closed-flip spidev backend: $token"
|
||||
fi
|
||||
done
|
||||
for token in 'backend = auto' 'spi_device = /dev/spidev0.1' \
|
||||
'spi_mux_gpio = 13' 'spi_dc_gpio = 21' 'spi_reset_gpio = 23' \
|
||||
'mux_closed_level = 1' 'mux_open_level = 0' \
|
||||
'dc_command_level = 0' 'dc_data_level = 1' \
|
||||
'reset_assert_level = 0' 'reset_idle_level = 1' \
|
||||
'spi_speed_hz = 25000000'; do
|
||||
if ! grep -qF -- "$token" "$COVER_CONF"; then
|
||||
fail "cover display config lost the spidev polarity key: $token"
|
||||
fi
|
||||
done
|
||||
if ! grep -qF 'flip_open' "$COVER_SRC" || \
|
||||
! grep -qF 'cover_hw_release(hw)' "$COVER_SRC" || \
|
||||
! grep -qF 'cover_draw(&hw, fb_path, &state)' "$COVER_SRC"; then
|
||||
fail "the cover daemon no longer gates the shared bus on the flip state"
|
||||
fi
|
||||
if [ ! -x "$BASE_DIR/scripts/test-cover-spidev.py" ]; then
|
||||
fail "missing host test scripts/test-cover-spidev.py"
|
||||
fi
|
||||
if command -v gcc >/dev/null 2>&1 && \
|
||||
! "$BASE_DIR/scripts/test-cover-spidev.py" >/dev/null 2>&1; then
|
||||
fail "host closed-flip external panel backend test failed"
|
||||
fi
|
||||
for f in "$BASE_DIR/prebuilt/bananarchy-daemons/usr/bin/bananarchy-cover-idle" \
|
||||
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-cover-idle"; do
|
||||
if ! strings "$f" 2>/dev/null | grep -qF 'frame lit=%d size=%zu'; then
|
||||
fail "${f#"$BASE_DIR/"} is stale: rebuild with scripts/build-bananarchy-daemons.sh"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "[check] 2720 Flip external panel (opt-in DT)..."
|
||||
if [ ! -f "$BASE_DIR/devices/nokia-beatles/qcom-msm8905-nokia-beatles-cover.dts" ] || \
|
||||
[ ! -x "$BASE_DIR/scripts/build-beatles-cover-panel.py" ] || \
|
||||
@@ -1464,8 +1503,10 @@ if [ ! -x "$COVER_DIAG" ] || ! sh -n "$COVER_DIAG" 2>/dev/null; then
|
||||
fi
|
||||
if ! grep -qF '/dev/fb1' "$COVER_DIAG" || \
|
||||
! grep -qF '/sys/class/graphics/fb1' "$COVER_DIAG" || \
|
||||
! grep -qF '/dev/spidev0.1' "$COVER_DIAG" || \
|
||||
! grep -qF 'spi_mux_gpio' "$COVER_DIAG" || \
|
||||
! grep -qF 'bananarchy-coverctl' "$COVER_DIAG"; then
|
||||
fail "cover diagnostics no longer inspect fb1 and the daemon"
|
||||
fail "cover diagnostics no longer inspect fb1, spidev and the daemon"
|
||||
fi
|
||||
if ! grep -qF 'bananarchy-cover-diagnose.sh' \
|
||||
"$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then
|
||||
|
||||
Executable
+323
@@ -0,0 +1,323 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Host test for the 2720 Flip closed-flip-only external panel backend.
|
||||
|
||||
Compiles bananarchy-cover-idle.c on the host and runs it in SPI simulation
|
||||
mode (BANANARCHY_COVER_SPI_SIM). The shared QUP5 bus must be untouched while
|
||||
the flip is open, claimed only while closed, released before Xorg can flush
|
||||
another main-panel frame, and the external firmware must be replayed before
|
||||
the first frame. Polarity knobs and the /dev/fb1 precedence are also checked.
|
||||
"""
|
||||
import os
|
||||
import pathlib
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
BASE = pathlib.Path(__file__).resolve().parent.parent
|
||||
SRC = BASE / "src/bananarchy-daemons/bananarchy-cover-idle.c"
|
||||
FIRMWARE = BASE / "devices/nokia-beatles/nokia,beatles-gc9305-ext-panel.bin"
|
||||
CONFIG = BASE / "overlay/rootfs/etc/bananarchy/cover-display.conf"
|
||||
|
||||
|
||||
class Cover:
|
||||
def __init__(self, root, exe, config, log, env_extra=None):
|
||||
self.root = root
|
||||
self.log = log
|
||||
self.sock_path = root / "cover.sock"
|
||||
self.client_path = root / "client.sock"
|
||||
self.env = dict(os.environ)
|
||||
self.env.update({
|
||||
"BANANARCHY_COVER_LOCK": str(root / "daemon.lock"),
|
||||
"BANANARCHY_COVER_MAIN_BLANK_CFG": str(root / "idle_blank_timeout"),
|
||||
"BANANARCHY_COVER_SPI_SIM": str(log),
|
||||
})
|
||||
if env_extra:
|
||||
self.env.update(env_extra)
|
||||
self.proc = subprocess.Popen([str(exe), "--config", str(config)],
|
||||
env=self.env, stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL)
|
||||
if self.client_path.exists():
|
||||
self.client_path.unlink()
|
||||
self.client = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
self.client.bind(str(self.client_path))
|
||||
self.client.settimeout(2)
|
||||
deadline = time.time() + 3
|
||||
while time.time() < deadline and not self.sock_path.exists():
|
||||
time.sleep(0.05)
|
||||
|
||||
def send(self, command):
|
||||
self.client.sendto(command.encode(), str(self.sock_path))
|
||||
try:
|
||||
return self.client.recv(512).decode().strip()
|
||||
except socket.timeout:
|
||||
return ""
|
||||
|
||||
def events(self):
|
||||
if not self.log.is_file():
|
||||
return []
|
||||
return self.log.read_text(encoding="utf-8", errors="replace").splitlines()
|
||||
|
||||
def wait_event(self, text, timeout=3.0):
|
||||
end = time.time() + timeout
|
||||
while time.time() < end:
|
||||
if any(text in line for line in self.events()):
|
||||
return True
|
||||
time.sleep(0.05)
|
||||
return False
|
||||
|
||||
def close(self):
|
||||
try:
|
||||
self.send("QUIT")
|
||||
except OSError:
|
||||
pass
|
||||
self.client.close()
|
||||
try:
|
||||
self.proc.wait(timeout=3)
|
||||
except subprocess.TimeoutExpired:
|
||||
self.proc.kill()
|
||||
self.proc.wait()
|
||||
if self.client_path.exists():
|
||||
self.client_path.unlink()
|
||||
|
||||
|
||||
def write_config(path, root, extra):
|
||||
lines = [
|
||||
"socket_path = %s" % (root / "cover.sock"),
|
||||
"fb_device = %s" % (root / "no-fb1"),
|
||||
"backlight_path = %s" % (root / "backlight"),
|
||||
"brightness = 160",
|
||||
"blank_timeout = 2",
|
||||
"backend = spidev",
|
||||
"spi_device = /dev/spidev0.1",
|
||||
"gpiochip_device = /dev/gpiochip0",
|
||||
"panel_firmware = %s" % FIRMWARE,
|
||||
"spi_mux_gpio = 13",
|
||||
"spi_dc_gpio = 21",
|
||||
"spi_reset_gpio = 23",
|
||||
"mux_closed_level = 1",
|
||||
"mux_open_level = 0",
|
||||
"dc_command_level = 0",
|
||||
"dc_data_level = 1",
|
||||
"reset_assert_level = 0",
|
||||
"reset_idle_level = 1",
|
||||
"spi_speed_hz = 25000000",
|
||||
]
|
||||
lines.extend("%s = %s" % item for item in extra.items())
|
||||
path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
|
||||
|
||||
def check(ok, message):
|
||||
if not ok:
|
||||
sys.stderr.write("FAIL: %s\n" % message)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def run_case(root, exe, extra, prepare=None, env_extra=None, dpms="Off"):
|
||||
case = root / ("case%d" % len(list(root.glob("case*"))))
|
||||
case.mkdir()
|
||||
log = case / "spi.log"
|
||||
conf = case / "cover.conf"
|
||||
(case / "idle_blank_timeout").write_text("300\n")
|
||||
(case / "dpms").write_text(dpms + "\n")
|
||||
write_config(conf, case, extra)
|
||||
if prepare:
|
||||
prepare(case)
|
||||
env = {"BANANARCHY_COVER_DPMS_PATH": str(case / "dpms")}
|
||||
if env_extra:
|
||||
env.update(env_extra)
|
||||
return Cover(case, exe, conf, log, env), case
|
||||
|
||||
|
||||
def main():
|
||||
if not SRC.is_file() or not FIRMWARE.is_file() or not CONFIG.is_file():
|
||||
sys.stderr.write("FAIL: missing cover sources or firmware\n")
|
||||
return 1
|
||||
source = SRC.read_text(encoding="utf-8")
|
||||
for token in ("cover_hw_release", "cover_spi_draw", "hw_init_panel",
|
||||
"mux_closed_level", "spi_speed_hz", "FBIOBLANK",
|
||||
"BANANARCHY_COVER_SPI_SIM", "cover_main_panel_is_off",
|
||||
"0x28", "0x29"):
|
||||
if token not in source:
|
||||
sys.stderr.write("FAIL: cover daemon lost %s\n" % token)
|
||||
return 1
|
||||
conf = CONFIG.read_text(encoding="utf-8")
|
||||
for token in ("backend = auto", "spi_device = /dev/spidev0.1",
|
||||
"spi_mux_gpio", "spi_dc_gpio", "spi_reset_gpio",
|
||||
"mux_closed_level", "spi_speed_hz = 25000000", "dc_gpio = -1"):
|
||||
if token not in conf:
|
||||
sys.stderr.write("FAIL: cover config lost %s\n" % token)
|
||||
return 1
|
||||
print("[ok] closed-flip spidev wiring and config are present")
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="bananarchy-cover-spi-") as tmp:
|
||||
root = pathlib.Path(tmp)
|
||||
exe = root / "cover-idle"
|
||||
build = subprocess.run(
|
||||
["gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
|
||||
"-I" + str(SRC.parent), str(SRC), "-o", str(exe)],
|
||||
capture_output=True, text=True)
|
||||
if build.returncode:
|
||||
sys.stderr.write(build.stderr)
|
||||
return 1
|
||||
print("[ok] host build of the compiled cover daemon")
|
||||
|
||||
daemon, case = run_case(root, exe, {})
|
||||
try:
|
||||
if "pong" not in daemon.send("PING"):
|
||||
sys.stderr.write("FAIL: daemon did not answer PING\n")
|
||||
return 1
|
||||
time.sleep(0.3)
|
||||
if daemon.events():
|
||||
return not check(False, "an open flip touched the shared SPI bus: %s" %
|
||||
daemon.events()[:4])
|
||||
status = daemon.send("STATUS")
|
||||
if "spi=1" not in status or "mux=free" not in status:
|
||||
return not check(False, "STATUS does not report the idle bus: %s" % status)
|
||||
print("[ok] open flip: no GPIO claim, no SPI transfer")
|
||||
|
||||
daemon.send("LID CLOSED")
|
||||
if not daemon.wait_event("claim"):
|
||||
return not check(False, "closing the flip did not claim the mux")
|
||||
if not daemon.wait_event("cmd fe 0") or not daemon.wait_event("cmd 29 0"):
|
||||
return not check(False, "external panel firmware was not replayed")
|
||||
if not daemon.wait_event("frame lit=0 size=115200"):
|
||||
return not check(False, "no dark frame after closing")
|
||||
events = daemon.events()
|
||||
mux_closed = [i for i, line in enumerate(events) if line == "gpio 1"]
|
||||
first_cmd = next((i for i, line in enumerate(events)
|
||||
if line.startswith("cmd ")), len(events))
|
||||
if not mux_closed or mux_closed[0] >= first_cmd:
|
||||
return not check(False, "mux was not switched before the first SPI command")
|
||||
if "backend=spidev" not in daemon.send("STATUS") or \
|
||||
"mux=closed" not in daemon.send("STATUS"):
|
||||
return not check(False, "STATUS does not report the spidev backend")
|
||||
print("[ok] closed flip: mux, reset, firmware init and dark frame")
|
||||
|
||||
daemon.send("BUTTON")
|
||||
if not daemon.wait_event("frame lit=1 size=115200"):
|
||||
return not check(False, "BUTTON did not light the external panel")
|
||||
if "cmd 29 0" not in daemon.events():
|
||||
return not check(False, "display-on command missing")
|
||||
print("[ok] external button: lit RGB565 frame on the cover")
|
||||
|
||||
daemon.send("BLANK")
|
||||
if not daemon.wait_event("cmd 28 0"):
|
||||
return not check(False, "display-off command missing when dark")
|
||||
print("[ok] blank: external panel is powered down again")
|
||||
|
||||
daemon.send("LID OPEN")
|
||||
if not daemon.wait_event("release"):
|
||||
return not check(False, "opening the flip did not release the panel lines")
|
||||
events = daemon.events()
|
||||
last_release = max(i for i, line in enumerate(events) if line == "release")
|
||||
tail = events[last_release + 1:]
|
||||
if any(line.startswith(("cmd ", "frame ", "claim")) for line in tail):
|
||||
return not check(False, "SPI activity continued after LID OPEN: %s" % tail)
|
||||
if "gpio 0" not in events[:last_release + 1]:
|
||||
return not check(False, "mux was not restored to the internal panel")
|
||||
if "mux=open" not in daemon.send("STATUS"):
|
||||
return not check(False, "STATUS does not report the restored mux")
|
||||
print("[ok] LID OPEN: mux restored, panel lines released, bus idle")
|
||||
finally:
|
||||
daemon.close()
|
||||
|
||||
# Polarity knobs must be honoured without a rebuild.
|
||||
rev, _ = run_case(root, exe, {"mux_closed_level": "0",
|
||||
"mux_open_level": "1"})
|
||||
try:
|
||||
rev.send("LID CLOSED")
|
||||
if not rev.wait_event("claim"):
|
||||
return not check(False, "inverted-polarity daemon did not activate")
|
||||
rev.send("LID OPEN")
|
||||
if not rev.wait_event("release"):
|
||||
return not check(False, "inverted-polarity daemon did not release")
|
||||
events = rev.events()
|
||||
if events.count("gpio 0") < 1 or events.count("gpio 1") < 1:
|
||||
return not check(False, "inverted mux polarity was ignored: %s" % events)
|
||||
print("[ok] mux polarity is a config knob, not a rebuild")
|
||||
finally:
|
||||
rev.close()
|
||||
|
||||
# The opt-in /dev/fb1 DT keeps precedence over the userspace backend.
|
||||
fb, fbcase = run_case(root, exe, {"backend": "auto"},
|
||||
prepare=lambda d: (d / "no-fb1").write_bytes(
|
||||
b"\x00" * (240 * 240 * 4)),
|
||||
env_extra={"BANANARCHY_COVER_FB_GEOM": "240,240,32"})
|
||||
try:
|
||||
fb.send("LID CLOSED")
|
||||
fb.send("BUTTON")
|
||||
time.sleep(0.3)
|
||||
if any(line.startswith(("claim", "cmd ", "frame ")) for line in fb.events()):
|
||||
return not check(False, "spidev backend overrode the /dev/fb1 path")
|
||||
if "backend=fb" not in fb.send("STATUS"):
|
||||
return not check(False, "fbdev backend not selected when /dev/fb1 exists")
|
||||
print("[ok] /dev/fb1 takes precedence when the opt-in DT is installed")
|
||||
finally:
|
||||
fb.close()
|
||||
|
||||
# Explicitly disabled backend must stay completely inert.
|
||||
off, _ = run_case(root, exe, {"backend": "none"})
|
||||
try:
|
||||
off.send("LID CLOSED")
|
||||
off.send("BUTTON")
|
||||
time.sleep(0.3)
|
||||
if off.events():
|
||||
return not check(False, "backend=none still touched the bus: %s" %
|
||||
off.events()[:4])
|
||||
if "spi=0" not in off.send("STATUS"):
|
||||
return not check(False, "backend=none did not disable spidev")
|
||||
print("[ok] backend=none keeps the shared bus untouched")
|
||||
finally:
|
||||
off.close()
|
||||
|
||||
# A transient lid flap must never steal the bus from a live main panel.
|
||||
live, _ = run_case(root, exe, {}, dpms="On")
|
||||
try:
|
||||
live.send("LID CLOSED")
|
||||
live.send("BUTTON")
|
||||
time.sleep(0.3)
|
||||
if any(e.startswith(("claim", "cmd ", "frame ")) for e in live.events()):
|
||||
return not check(False, "cover took the bus while the main panel was On")
|
||||
if "backend=pending" not in live.send("STATUS"):
|
||||
return not check(False, "STATUS does not report the DPMS gate")
|
||||
print("[ok] main panel DPMS-On blocks the closed-flip bus takeover")
|
||||
finally:
|
||||
live.close()
|
||||
|
||||
# Runtime SET knobs: polarity re-init and a one-command rollback.
|
||||
knobs, _ = run_case(root, exe, {})
|
||||
try:
|
||||
knobs.send("LID CLOSED")
|
||||
if not knobs.wait_event("cmd fe 0"):
|
||||
return not check(False, "runtime-knob daemon did not init the panel")
|
||||
before = len([e for e in knobs.events() if e == "cmd fe 0"])
|
||||
knobs.send("SET mux_closed_level 0")
|
||||
if not knobs.wait_event("release"):
|
||||
return not check(False, "SET polarity did not release the panel lines")
|
||||
if not check(any(e == "gpio 0" for e in knobs.events()),
|
||||
"SET mux_closed_level was ignored"):
|
||||
return 1
|
||||
after = len([e for e in knobs.events() if e == "cmd fe 0"])
|
||||
if after <= before:
|
||||
return not check(False, "SET polarity did not re-init the panel")
|
||||
knobs.send("SET backend none")
|
||||
if "spi=0" not in knobs.send("STATUS"):
|
||||
return not check(False, "SET backend none did not disable spidev")
|
||||
tail_start = len(knobs.events())
|
||||
knobs.send("BUTTON")
|
||||
time.sleep(0.3)
|
||||
if any(e.startswith("frame ") for e in knobs.events()[tail_start:]):
|
||||
return not check(False, "SET backend none still drew a frame")
|
||||
print("[ok] SET polarity and SET backend none are live sign-off knobs")
|
||||
finally:
|
||||
knobs.close()
|
||||
|
||||
print("closed-flip external panel backend: all checks passed")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -11,6 +11,14 @@
|
||||
* default 300 s, 0 = never) blanks the cover again when no button arrives;
|
||||
* - all other events (network, SMS, battery, calls, theme) only update the
|
||||
* frame while the cover is visible, so an idle daemon stays at 0% CPU.
|
||||
*
|
||||
* The 2720's two GC9305 panels share one QUP5 SPI bus through a gpio13 mux.
|
||||
* Registering both panels in the DT darkens the main panel, so the shipping
|
||||
* DTB keeps one panel and this daemon drives the external panel from userspace
|
||||
* on /dev/spidev0.1 ONLY while the flip is closed (the main panel is blanked
|
||||
* and DPMS-off then). On open it restores the mux to the internal panel and
|
||||
* releases every GPIO/SPIDEV handle before Xorg can flush another frame.
|
||||
* If the opt-in two-panel DT is installed, /dev/fb1 takes precedence instead.
|
||||
*/
|
||||
#include <ctype.h>
|
||||
#include <poll.h>
|
||||
@@ -44,6 +52,89 @@
|
||||
#define MAIN_BLANK_CFG "/home/user/.config/sxmo/idle_blank_timeout"
|
||||
#define DEFAULT_BLANK_SECS 300
|
||||
#define CLOCK_REDRAW_MS 30000
|
||||
#define COVER_SPI_WIDTH 240
|
||||
#define COVER_SPI_HEIGHT 240
|
||||
#define COVER_SPI_CHUNK 2048
|
||||
#define MAIN_DPMS_PATH "/sys/class/drm/card0-SPI-1/dpms"
|
||||
|
||||
/* Self-contained linux/gpio.h (v1 ABI) and linux/spi/spidev.h UAPI values.
|
||||
* The armv7 cross sysroot does not always ship these headers. The layouts are
|
||||
* fixed by the kernel ABI; a compile-time size check guards the cross build. */
|
||||
#define BA_GPIO_IOC_MAGIC 0xb4u
|
||||
#define BA_IOC_WR 1u
|
||||
#define BA_IOC_RDWR 3u
|
||||
#define BA_IOC(dir, type, nr, size) \
|
||||
(((unsigned int)(dir) << 30) | ((unsigned int)(type) << 8) | \
|
||||
((unsigned int)(nr) << 0) | ((unsigned int)(size) << 16))
|
||||
#define BA_SPI_IOC_MESSAGE(n) \
|
||||
BA_IOC(BA_IOC_WR, 'k', 0u, (unsigned int)(n) * 32u)
|
||||
#define BA_SPI_IOC_WR_MODE BA_IOC(BA_IOC_WR, 'k', 1u, 1u)
|
||||
#define BA_SPI_IOC_WR_BITS BA_IOC(BA_IOC_WR, 'k', 3u, 1u)
|
||||
#define BA_SPI_IOC_WR_SPEED BA_IOC(BA_IOC_WR, 'k', 4u, 4u)
|
||||
#define BA_GPIO_GET_LINEHANDLE BA_IOC(BA_IOC_RDWR, BA_GPIO_IOC_MAGIC, 3u, 364u)
|
||||
#define BA_GPIO_GET_VALUES BA_IOC(BA_IOC_RDWR, BA_GPIO_IOC_MAGIC, 8u, 64u)
|
||||
#define BA_GPIO_SET_VALUES BA_IOC(BA_IOC_RDWR, BA_GPIO_IOC_MAGIC, 9u, 64u)
|
||||
#define BA_GPIOHANDLE_REQUEST_OUTPUT (1u << 1)
|
||||
|
||||
struct ba_gpiohandle_request {
|
||||
uint32_t lineoffsets[64];
|
||||
uint32_t flags;
|
||||
uint8_t default_values[64];
|
||||
char consumer_label[32];
|
||||
uint32_t lines;
|
||||
int32_t fd;
|
||||
};
|
||||
|
||||
struct ba_gpiohandle_data {
|
||||
uint8_t values[64];
|
||||
};
|
||||
|
||||
struct ba_spi_ioc_transfer {
|
||||
uint64_t tx_buf;
|
||||
uint64_t rx_buf;
|
||||
uint32_t len;
|
||||
uint32_t speed_hz;
|
||||
uint16_t delay_usecs;
|
||||
uint8_t bits_per_word;
|
||||
uint8_t cs_change;
|
||||
uint8_t tx_nbits;
|
||||
uint8_t rx_nbits;
|
||||
uint8_t word_delay_usecs;
|
||||
uint8_t pad;
|
||||
};
|
||||
|
||||
_Static_assert(sizeof(struct ba_gpiohandle_request) == 364,
|
||||
"gpiochip v1 linehandle ABI size");
|
||||
_Static_assert(sizeof(struct ba_spi_ioc_transfer) == 32,
|
||||
"spidev transfer ABI size");
|
||||
|
||||
struct cover_hw {
|
||||
char backend[16];
|
||||
char spi_path[128];
|
||||
char gpio_path[128];
|
||||
char firmware[128];
|
||||
char sim_path[128];
|
||||
unsigned int mux_gpio;
|
||||
unsigned int dc_gpio;
|
||||
unsigned int reset_gpio;
|
||||
int mux_closed_level;
|
||||
int mux_open_level;
|
||||
int dc_command_level;
|
||||
int dc_data_level;
|
||||
int reset_assert_level;
|
||||
int reset_idle_level;
|
||||
unsigned int speed_hz;
|
||||
int sim;
|
||||
int spi_enabled;
|
||||
int fd_spi;
|
||||
int fd_chip;
|
||||
int fd_mux;
|
||||
int fd_panel;
|
||||
int fd_sim;
|
||||
int mux_claimed;
|
||||
int claimed;
|
||||
int initialized;
|
||||
};
|
||||
|
||||
struct glyph {
|
||||
char ch;
|
||||
@@ -272,6 +363,55 @@ static void set_backlight(const struct state *state, int on)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void render_frame(struct frame *fb, const struct state *state)
|
||||
{
|
||||
char clock[16];
|
||||
char date[32];
|
||||
char battery[32];
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
unsigned int width = fb->width;
|
||||
unsigned int height = fb->height;
|
||||
localtime_r(&now, &tm);
|
||||
strftime(clock, sizeof(clock), "%H:%M", &tm);
|
||||
strftime(date, sizeof(date), "%d.%m.%Y", &tm);
|
||||
if(state->test == 2) {
|
||||
frame_rect(fb, 0, 0, (int)width / 4, (int)height,
|
||||
rgb888(250, 40, 40));
|
||||
frame_rect(fb, (int)width / 4, 0, (int)width / 2, (int)height,
|
||||
rgb888(40, 230, 80));
|
||||
frame_rect(fb, (int)width / 2, 0, (int)width * 3 / 4, (int)height,
|
||||
rgb888(60, 110, 250));
|
||||
frame_rect(fb, (int)width * 3 / 4, 0, (int)width, (int)height,
|
||||
rgb888(245, 245, 245));
|
||||
} else if(state->test == 3) {
|
||||
frame_rect(fb, 0, 0, (int)width, (int)height,
|
||||
rgb888(245, 245, 245));
|
||||
} else if(!cover_is_lit(state)) {
|
||||
frame_rect(fb, 0, 0, (int)width, (int)height, rgb888(0, 0, 0));
|
||||
} else {
|
||||
frame_rect(fb, 0, 0, (int)width, (int)height, rgb888(8, 12, 26));
|
||||
frame_rect(fb, 0, 0, (int)width, 3, rgb888(250, 210, 60));
|
||||
frame_text(fb, "BANANARCHY", 12, 26, 2, rgb888(250, 210, 60));
|
||||
frame_text(fb, clock, 20, (int)height / 2 - 20,
|
||||
width >= 220 ? 5 : 3, rgb888(235, 240, 248));
|
||||
frame_text(fb, date, 30, (int)height / 2 + 40, 2,
|
||||
rgb888(90, 150, 240));
|
||||
/* Compact network / battery indicators, pushed by the event bridge. */
|
||||
if(state->network[0])
|
||||
frame_text(fb, state->network, 6, (int)height - 44, 1,
|
||||
rgb888(120, 230, 160));
|
||||
if(state->battery >= 0) {
|
||||
snprintf(battery, sizeof(battery), "BAT %d%%", state->battery);
|
||||
frame_text(fb, battery, 6, (int)height - 26, 1,
|
||||
rgb888(250, 210, 60));
|
||||
}
|
||||
if(state->message[0])
|
||||
frame_text(fb, state->message, 6, (int)height - 12, 1,
|
||||
rgb888(235, 240, 248));
|
||||
}
|
||||
}
|
||||
|
||||
static int draw_frame(const char *fb_path, const struct state *state)
|
||||
{
|
||||
int fd = open(fb_path, O_RDWR | O_CLOEXEC);
|
||||
@@ -282,11 +422,6 @@ static int draw_frame(const char *fb_path, const struct state *state)
|
||||
size_t size;
|
||||
unsigned char *mem;
|
||||
struct frame fb;
|
||||
char clock[16];
|
||||
char date[32];
|
||||
char battery[32];
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
if(fd < 0)
|
||||
return 0;
|
||||
if(!fb_geometry(fb_path, &width, &height, &bpp, &stride)) {
|
||||
@@ -304,44 +439,7 @@ static int draw_frame(const char *fb_path, const struct state *state)
|
||||
fb.height = height;
|
||||
fb.stride = stride;
|
||||
fb.bpp = bpp;
|
||||
localtime_r(&now, &tm);
|
||||
strftime(clock, sizeof(clock), "%H:%M", &tm);
|
||||
strftime(date, sizeof(date), "%d.%m.%Y", &tm);
|
||||
if(state->test == 2) {
|
||||
frame_rect(&fb, 0, 0, (int)width / 4, (int)height,
|
||||
rgb888(250, 40, 40));
|
||||
frame_rect(&fb, (int)width / 4, 0, (int)width / 2, (int)height,
|
||||
rgb888(40, 230, 80));
|
||||
frame_rect(&fb, (int)width / 2, 0, (int)width * 3 / 4, (int)height,
|
||||
rgb888(60, 110, 250));
|
||||
frame_rect(&fb, (int)width * 3 / 4, 0, (int)width, (int)height,
|
||||
rgb888(245, 245, 245));
|
||||
} else if(state->test == 3) {
|
||||
frame_rect(&fb, 0, 0, (int)width, (int)height,
|
||||
rgb888(245, 245, 245));
|
||||
} else if(!cover_is_lit(state)) {
|
||||
frame_rect(&fb, 0, 0, (int)width, (int)height, rgb888(0, 0, 0));
|
||||
} else {
|
||||
frame_rect(&fb, 0, 0, (int)width, (int)height, rgb888(8, 12, 26));
|
||||
frame_rect(&fb, 0, 0, (int)width, 3, rgb888(250, 210, 60));
|
||||
frame_text(&fb, "BANANARCHY", 12, 26, 2, rgb888(250, 210, 60));
|
||||
frame_text(&fb, clock, 20, (int)height / 2 - 20,
|
||||
width >= 220 ? 5 : 3, rgb888(235, 240, 248));
|
||||
frame_text(&fb, date, 30, (int)height / 2 + 40, 2,
|
||||
rgb888(90, 150, 240));
|
||||
/* Compact network / battery indicators, pushed by the event bridge. */
|
||||
if(state->network[0])
|
||||
frame_text(&fb, state->network, 6, (int)height - 44, 1,
|
||||
rgb888(120, 230, 160));
|
||||
if(state->battery >= 0) {
|
||||
snprintf(battery, sizeof(battery), "BAT %d%%", state->battery);
|
||||
frame_text(&fb, battery, 6, (int)height - 26, 1,
|
||||
rgb888(250, 210, 60));
|
||||
}
|
||||
if(state->message[0])
|
||||
frame_text(&fb, state->message, 6, (int)height - 12, 1,
|
||||
rgb888(235, 240, 248));
|
||||
}
|
||||
render_frame(&fb, state);
|
||||
if(lseek(fd, 0, SEEK_SET) < 0 || !write_all(fd, mem, size)) {
|
||||
free(mem);
|
||||
close(fd);
|
||||
@@ -359,6 +457,373 @@ static int draw_frame(const char *fb_path, const struct state *state)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --- Closed-flip-only userspace GC9305 backend (/dev/spidev0.1) --------- */
|
||||
|
||||
static void hw_event(struct cover_hw *hw, const char *line)
|
||||
{
|
||||
if(hw->fd_sim < 0)
|
||||
return;
|
||||
(void)!write(hw->fd_sim, line, strlen(line));
|
||||
(void)!write(hw->fd_sim, "\n", 1);
|
||||
}
|
||||
|
||||
static int hw_gpio_set(struct cover_hw *hw, int fd,
|
||||
const unsigned char *values, unsigned int count)
|
||||
{
|
||||
struct ba_gpiohandle_data data;
|
||||
char line[64];
|
||||
unsigned int i;
|
||||
snprintf(line, sizeof(line), "gpio");
|
||||
for(i = 0; i < count; i++)
|
||||
snprintf(line + strlen(line), sizeof(line) - strlen(line),
|
||||
" %u", values[i]);
|
||||
hw_event(hw, line);
|
||||
if(hw->sim)
|
||||
return 1;
|
||||
memset(&data, 0, sizeof(data));
|
||||
for(i = 0; i < count && i < sizeof(data.values); i++)
|
||||
data.values[i] = values[i];
|
||||
return ioctl(fd, BA_GPIO_SET_VALUES, &data) >= 0;
|
||||
}
|
||||
|
||||
static int hw_gpio_request(struct cover_hw *hw, const unsigned int *offsets,
|
||||
const unsigned char *defaults, unsigned int count)
|
||||
{
|
||||
struct ba_gpiohandle_request req;
|
||||
unsigned int i;
|
||||
if(hw->sim) {
|
||||
hw_event(hw, "claim");
|
||||
return 1;
|
||||
}
|
||||
if(hw->fd_chip < 0)
|
||||
return -1;
|
||||
memset(&req, 0, sizeof(req));
|
||||
for(i = 0; i < count && i < 64; i++) {
|
||||
req.lineoffsets[i] = offsets[i];
|
||||
req.default_values[i] = defaults[i];
|
||||
}
|
||||
req.flags = BA_GPIOHANDLE_REQUEST_OUTPUT;
|
||||
snprintf(req.consumer_label, sizeof(req.consumer_label),
|
||||
"bananarchy-cover");
|
||||
req.lines = count;
|
||||
req.fd = -1;
|
||||
if(ioctl(hw->fd_chip, BA_GPIO_GET_LINEHANDLE, &req) < 0)
|
||||
return -1;
|
||||
hw_event(hw, "claim");
|
||||
return req.fd;
|
||||
}
|
||||
|
||||
static int hw_xfer(struct cover_hw *hw, const unsigned char *tx, size_t len,
|
||||
int cs_change)
|
||||
{
|
||||
struct ba_spi_ioc_transfer tr;
|
||||
if(hw->sim)
|
||||
return 1;
|
||||
memset(&tr, 0, sizeof(tr));
|
||||
tr.tx_buf = (uint64_t)(uintptr_t)tx;
|
||||
tr.len = (uint32_t)len;
|
||||
tr.bits_per_word = 8;
|
||||
tr.cs_change = (uint8_t)(cs_change ? 1 : 0);
|
||||
return ioctl(hw->fd_spi, BA_SPI_IOC_MESSAGE(1), &tr) >= 0;
|
||||
}
|
||||
|
||||
static int hw_dc(struct cover_hw *hw, int level)
|
||||
{
|
||||
unsigned char values[2];
|
||||
values[0] = (unsigned char)level;
|
||||
values[1] = (unsigned char)hw->reset_idle_level;
|
||||
return hw_gpio_set(hw, hw->fd_panel, values, 2);
|
||||
}
|
||||
|
||||
static int hw_command(struct cover_hw *hw, unsigned char cmd,
|
||||
const unsigned char *params, size_t n)
|
||||
{
|
||||
char line[64];
|
||||
snprintf(line, sizeof(line), "cmd %02x %zu", cmd, n);
|
||||
hw_event(hw, line);
|
||||
if(hw->sim)
|
||||
return 1;
|
||||
if(!hw_dc(hw, hw->dc_command_level))
|
||||
return 0;
|
||||
if(!hw_xfer(hw, &cmd, 1, n ? 0 : 1))
|
||||
return 0;
|
||||
if(!n)
|
||||
return 1;
|
||||
if(!hw_dc(hw, hw->dc_data_level))
|
||||
return 0;
|
||||
while(n) {
|
||||
size_t chunk = n > COVER_SPI_CHUNK ? COVER_SPI_CHUNK : n;
|
||||
if(!hw_xfer(hw, params, chunk, chunk == n))
|
||||
return 0;
|
||||
params += chunk;
|
||||
n -= chunk;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int hw_init_panel(struct cover_hw *hw)
|
||||
{
|
||||
unsigned char blob[4096];
|
||||
unsigned char blank[2] = {0, 0};
|
||||
size_t len = 0;
|
||||
size_t p;
|
||||
ssize_t got;
|
||||
int fd = open(hw->firmware, O_RDONLY | O_CLOEXEC);
|
||||
if(fd < 0)
|
||||
return 0;
|
||||
got = read(fd, blob, sizeof(blob));
|
||||
close(fd);
|
||||
if(got < 17)
|
||||
return 0;
|
||||
len = (size_t)got;
|
||||
if(memcmp(blob, "MIPI DBI", 8) != 0)
|
||||
return 0;
|
||||
p = 16;
|
||||
while(p + 2 <= len) {
|
||||
unsigned char cmd = blob[p];
|
||||
size_t n = blob[p + 1];
|
||||
p += 2;
|
||||
if(p + n > len)
|
||||
break;
|
||||
if(cmd == 0x00 && n == 1) {
|
||||
/* Vendor "delay ms" record. Host simulation skips the wait. */
|
||||
if(!hw->sim)
|
||||
poll(NULL, 0, (int)blob[p] > 0 ? (int)blob[p] : 1);
|
||||
} else if(cmd == 0x2c && n == 0) {
|
||||
/* Memory-write marker: every command gets its own CS framing, so a
|
||||
* bare 0x2c is not part of the init sequence. */
|
||||
hw_event(hw, "skip 2c");
|
||||
} else {
|
||||
hw_command(hw, cmd, n ? blob + p : blank, n);
|
||||
}
|
||||
p += n;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int hw_activate(struct cover_hw *hw)
|
||||
{
|
||||
unsigned int mux_offset[1];
|
||||
unsigned int panel_offsets[2];
|
||||
unsigned char mux_default[1];
|
||||
unsigned char panel_default[2];
|
||||
unsigned char values[2];
|
||||
int fd;
|
||||
if(!hw->spi_enabled)
|
||||
return 0;
|
||||
if(!hw->sim && hw->fd_chip < 0) {
|
||||
hw->fd_chip = open(hw->gpio_path, O_RDWR | O_CLOEXEC);
|
||||
if(hw->fd_chip < 0)
|
||||
return 0;
|
||||
}
|
||||
if(!hw->mux_claimed) {
|
||||
mux_offset[0] = hw->mux_gpio;
|
||||
mux_default[0] = (unsigned char)hw->mux_open_level;
|
||||
fd = hw_gpio_request(hw, mux_offset, mux_default, 1);
|
||||
if(fd < 0)
|
||||
return 0;
|
||||
hw->fd_mux = fd;
|
||||
hw->mux_claimed = 1;
|
||||
}
|
||||
{
|
||||
unsigned char mux_value[1];
|
||||
mux_value[0] = (unsigned char)hw->mux_closed_level;
|
||||
hw_gpio_set(hw, hw->fd_mux, mux_value, 1);
|
||||
}
|
||||
if(!hw->claimed) {
|
||||
panel_offsets[0] = hw->dc_gpio;
|
||||
panel_offsets[1] = hw->reset_gpio;
|
||||
panel_default[0] = (unsigned char)hw->dc_data_level;
|
||||
panel_default[1] = (unsigned char)hw->reset_idle_level;
|
||||
fd = hw_gpio_request(hw, panel_offsets, panel_default, 2);
|
||||
if(fd < 0)
|
||||
return 0;
|
||||
hw->fd_panel = fd;
|
||||
hw->claimed = 1;
|
||||
hw->initialized = 0;
|
||||
if(hw->fd_spi < 0 && !hw->sim) {
|
||||
unsigned char mode = 0;
|
||||
unsigned char bits = 8;
|
||||
uint32_t speed = hw->speed_hz;
|
||||
hw->fd_spi = open(hw->spi_path, O_RDWR | O_CLOEXEC);
|
||||
if(hw->fd_spi < 0)
|
||||
return 0;
|
||||
if(ioctl(hw->fd_spi, BA_SPI_IOC_WR_MODE, &mode) < 0 ||
|
||||
ioctl(hw->fd_spi, BA_SPI_IOC_WR_BITS, &bits) < 0 ||
|
||||
ioctl(hw->fd_spi, BA_SPI_IOC_WR_SPEED, &speed) < 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(!hw->initialized) {
|
||||
/* Reset pulse on the external panel, then replay its firmware stream. */
|
||||
values[0] = (unsigned char)hw->dc_data_level;
|
||||
values[1] = (unsigned char)hw->reset_assert_level;
|
||||
hw_gpio_set(hw, hw->fd_panel, values, 2);
|
||||
if(!hw->sim)
|
||||
poll(NULL, 0, 20);
|
||||
values[1] = (unsigned char)hw->reset_idle_level;
|
||||
hw_gpio_set(hw, hw->fd_panel, values, 2);
|
||||
if(!hw->sim)
|
||||
poll(NULL, 0, 150);
|
||||
if(!hw_init_panel(hw))
|
||||
return 0;
|
||||
hw->initialized = 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int hw_frame(struct cover_hw *hw, const struct frame *fb, int lit)
|
||||
{
|
||||
unsigned char cmd = 0x2c;
|
||||
size_t size = (size_t)fb->stride * fb->height;
|
||||
size_t left = size;
|
||||
const unsigned char *pixels = fb->pixels;
|
||||
char line[96];
|
||||
snprintf(line, sizeof(line), "frame lit=%d size=%zu", lit, size);
|
||||
hw_event(hw, line);
|
||||
if(hw->sim)
|
||||
return 1;
|
||||
if(!hw_dc(hw, hw->dc_command_level))
|
||||
return 0;
|
||||
if(!hw_xfer(hw, &cmd, 1, 0))
|
||||
return 0;
|
||||
if(!hw_dc(hw, hw->dc_data_level))
|
||||
return 0;
|
||||
while(left) {
|
||||
size_t chunk = left > COVER_SPI_CHUNK ? COVER_SPI_CHUNK : left;
|
||||
if(!hw_xfer(hw, pixels, chunk, chunk == left))
|
||||
return 0;
|
||||
pixels += chunk;
|
||||
left -= chunk;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cover_spi_draw(struct cover_hw *hw, const struct state *state)
|
||||
{
|
||||
size_t size = COVER_SPI_WIDTH * COVER_SPI_HEIGHT * 2;
|
||||
unsigned char *mem;
|
||||
struct frame fb;
|
||||
int lit = cover_is_lit(state);
|
||||
if(!hw_activate(hw))
|
||||
return 0;
|
||||
mem = calloc(1, size);
|
||||
if(!mem)
|
||||
return 0;
|
||||
fb.pixels = mem;
|
||||
fb.width = COVER_SPI_WIDTH;
|
||||
fb.height = COVER_SPI_HEIGHT;
|
||||
fb.stride = COVER_SPI_WIDTH * 2;
|
||||
fb.bpp = 16;
|
||||
render_frame(&fb, state);
|
||||
if(lit)
|
||||
hw_command(hw, 0x29, NULL, 0);
|
||||
if(!hw_frame(hw, &fb, lit)) {
|
||||
free(mem);
|
||||
return 0;
|
||||
}
|
||||
if(!lit)
|
||||
hw_command(hw, 0x28, NULL, 0);
|
||||
free(mem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* On an open flip the daemon must not own the shared QUP5 bus at all. The
|
||||
* mux line stays claimed for the daemon's lifetime (so it is always driven
|
||||
* back to the internal panel), while the DC/reset handle is released. */
|
||||
static void cover_hw_release(struct cover_hw *hw)
|
||||
{
|
||||
unsigned char mux_value[1];
|
||||
if(!hw->mux_claimed)
|
||||
return;
|
||||
if(hw->initialized)
|
||||
hw_command(hw, 0x28, NULL, 0);
|
||||
mux_value[0] = (unsigned char)hw->mux_open_level;
|
||||
hw_gpio_set(hw, hw->fd_mux, mux_value, 1);
|
||||
hw_event(hw, "release");
|
||||
if(hw->claimed && !hw->sim)
|
||||
close(hw->fd_panel);
|
||||
hw->fd_panel = -1;
|
||||
hw->claimed = 0;
|
||||
hw->initialized = 0;
|
||||
}
|
||||
|
||||
static void cover_hw_shutdown(struct cover_hw *hw)
|
||||
{
|
||||
cover_hw_release(hw);
|
||||
if(!hw->sim) {
|
||||
if(hw->fd_mux >= 0)
|
||||
close(hw->fd_mux);
|
||||
if(hw->fd_spi >= 0)
|
||||
close(hw->fd_spi);
|
||||
if(hw->fd_chip >= 0)
|
||||
close(hw->fd_chip);
|
||||
}
|
||||
hw->fd_mux = -1;
|
||||
hw->fd_spi = -1;
|
||||
hw->fd_chip = -1;
|
||||
if(hw->fd_sim >= 0) {
|
||||
hw_event(hw, "close");
|
||||
close(hw->fd_sim);
|
||||
hw->fd_sim = -1;
|
||||
}
|
||||
hw->mux_claimed = 0;
|
||||
}
|
||||
|
||||
/* The cover may only own QUP5 while the main panel is DPMS-off. This is the
|
||||
* real closed-flip state and also rejects a transient lid-state flap at lid
|
||||
* daemon startup, when Xorg is still flushing frames to the internal panel. */
|
||||
static int cover_main_panel_is_off(void)
|
||||
{
|
||||
const char *path = getenv("BANANARCHY_COVER_DPMS_PATH");
|
||||
char buf[16];
|
||||
ssize_t got;
|
||||
int fd;
|
||||
if(!path || !*path)
|
||||
path = MAIN_DPMS_PATH;
|
||||
fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if(fd < 0)
|
||||
return 1;
|
||||
got = read(fd, buf, sizeof(buf) - 1);
|
||||
close(fd);
|
||||
if(got <= 0)
|
||||
return 1;
|
||||
buf[got] = '\0';
|
||||
return strncmp(buf, "Off", 3) == 0;
|
||||
}
|
||||
|
||||
static const char *cover_draw(struct cover_hw *hw, const char *fb_path,
|
||||
const struct state *state)
|
||||
{
|
||||
int flip_open = strcmp(state->lid, "open") == 0;
|
||||
int fb_present = access(fb_path, W_OK) == 0;
|
||||
int prefer_fb = strcmp(hw->backend, "spidev") != 0 &&
|
||||
strcmp(hw->backend, "none") != 0 && fb_present;
|
||||
if(flip_open) {
|
||||
cover_hw_release(hw);
|
||||
if(prefer_fb)
|
||||
return draw_frame(fb_path, state) ? "fb" : "none";
|
||||
return "idle";
|
||||
}
|
||||
if(strcmp(hw->backend, "none") == 0) {
|
||||
cover_hw_release(hw);
|
||||
return "none";
|
||||
}
|
||||
if(prefer_fb) {
|
||||
cover_hw_release(hw);
|
||||
return draw_frame(fb_path, state) ? "fb" : "none";
|
||||
}
|
||||
if(hw->spi_enabled) {
|
||||
if(!cover_main_panel_is_off()) {
|
||||
cover_hw_release(hw);
|
||||
return "pending";
|
||||
}
|
||||
return cover_spi_draw(hw, state) ? "spidev" : "none";
|
||||
}
|
||||
cover_hw_release(hw);
|
||||
return "none";
|
||||
}
|
||||
|
||||
static void mkdir_p(const char *path)
|
||||
{
|
||||
char buf[256];
|
||||
@@ -414,8 +879,50 @@ static long long blank_timeout_ms(const char *configured)
|
||||
return (long long)secs * 1000LL;
|
||||
}
|
||||
|
||||
static int config_level(const char *value, int fallback)
|
||||
{
|
||||
long v = strtol(value, NULL, 10);
|
||||
if(v < 0 || v > 1)
|
||||
return fallback;
|
||||
return (int)v;
|
||||
}
|
||||
|
||||
static void cover_hw_init(struct cover_hw *hw)
|
||||
{
|
||||
const char *sim;
|
||||
memset(hw, 0, sizeof(*hw));
|
||||
safe_copy(hw->backend, sizeof(hw->backend), "auto");
|
||||
hw->mux_gpio = 13;
|
||||
hw->dc_gpio = 21;
|
||||
hw->reset_gpio = 23;
|
||||
/* The live phone holds gpio13 low while the 240x320 main panel is active,
|
||||
* so low selects the internal panel and high must select the cover. */
|
||||
hw->mux_open_level = 0;
|
||||
hw->mux_closed_level = 1;
|
||||
hw->dc_command_level = 0;
|
||||
hw->dc_data_level = 1;
|
||||
hw->reset_assert_level = 0;
|
||||
hw->reset_idle_level = 1;
|
||||
hw->speed_hz = 25000000;
|
||||
hw->fd_spi = -1;
|
||||
hw->fd_chip = -1;
|
||||
hw->fd_mux = -1;
|
||||
hw->fd_panel = -1;
|
||||
hw->fd_sim = -1;
|
||||
sim = getenv("BANANARCHY_COVER_SPI_SIM");
|
||||
if(sim && *sim) {
|
||||
safe_copy(hw->sim_path, sizeof(hw->sim_path), sim);
|
||||
hw->fd_sim = open(sim, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
|
||||
if(hw->fd_sim >= 0)
|
||||
hw->sim = 1;
|
||||
else
|
||||
hw->sim_path[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static void read_config(const char *path, char *socket_path, size_t splen,
|
||||
char *fb_path, size_t fblen, struct state *state)
|
||||
char *fb_path, size_t fblen, struct state *state,
|
||||
struct cover_hw *hw)
|
||||
{
|
||||
char line[256];
|
||||
char blank[32];
|
||||
@@ -434,6 +941,7 @@ static void read_config(const char *path, char *socket_path, size_t splen,
|
||||
char *eq;
|
||||
char *key;
|
||||
char *value;
|
||||
long v;
|
||||
if(comment)
|
||||
*comment = '\0';
|
||||
eq = strchr(line, '=');
|
||||
@@ -451,14 +959,60 @@ static void read_config(const char *path, char *socket_path, size_t splen,
|
||||
else if(strcmp(key, "backlight_path") == 0)
|
||||
safe_copy(state->backlight_path, sizeof(state->backlight_path), value);
|
||||
else if(strcmp(key, "brightness") == 0) {
|
||||
long v = strtol(value, NULL, 10);
|
||||
v = strtol(value, NULL, 10);
|
||||
if(v > 0 && v <= 255)
|
||||
state->backlight_level = (int)v;
|
||||
} else if(strcmp(key, "blank_timeout") == 0)
|
||||
safe_copy(blank, sizeof(blank), value);
|
||||
else if(strcmp(key, "backend") == 0)
|
||||
safe_copy(hw->backend, sizeof(hw->backend), value);
|
||||
else if(strcmp(key, "spi_device") == 0)
|
||||
safe_copy(hw->spi_path, sizeof(hw->spi_path), value);
|
||||
else if(strcmp(key, "gpiochip_device") == 0)
|
||||
safe_copy(hw->gpio_path, sizeof(hw->gpio_path), value);
|
||||
else if(strcmp(key, "panel_firmware") == 0)
|
||||
safe_copy(hw->firmware, sizeof(hw->firmware), value);
|
||||
else if(strcmp(key, "spi_mux_gpio") == 0) {
|
||||
v = strtol(value, NULL, 10);
|
||||
if(v >= 0 && v < 1024)
|
||||
hw->mux_gpio = (unsigned int)v;
|
||||
} else if(strcmp(key, "spi_dc_gpio") == 0) {
|
||||
v = strtol(value, NULL, 10);
|
||||
if(v >= 0 && v < 1024)
|
||||
hw->dc_gpio = (unsigned int)v;
|
||||
} else if(strcmp(key, "spi_reset_gpio") == 0) {
|
||||
v = strtol(value, NULL, 10);
|
||||
if(v >= 0 && v < 1024)
|
||||
hw->reset_gpio = (unsigned int)v;
|
||||
} else if(strcmp(key, "mux_closed_level") == 0)
|
||||
hw->mux_closed_level = config_level(value, hw->mux_closed_level);
|
||||
else if(strcmp(key, "mux_open_level") == 0)
|
||||
hw->mux_open_level = config_level(value, hw->mux_open_level);
|
||||
else if(strcmp(key, "dc_command_level") == 0)
|
||||
hw->dc_command_level = config_level(value, hw->dc_command_level);
|
||||
else if(strcmp(key, "dc_data_level") == 0)
|
||||
hw->dc_data_level = config_level(value, hw->dc_data_level);
|
||||
else if(strcmp(key, "reset_assert_level") == 0)
|
||||
hw->reset_assert_level = config_level(value, hw->reset_assert_level);
|
||||
else if(strcmp(key, "reset_idle_level") == 0)
|
||||
hw->reset_idle_level = config_level(value, hw->reset_idle_level);
|
||||
else if(strcmp(key, "spi_speed_hz") == 0) {
|
||||
v = strtol(value, NULL, 10);
|
||||
if(v >= 1000000 && v <= 50000000)
|
||||
hw->speed_hz = (unsigned int)v;
|
||||
}
|
||||
}
|
||||
fclose(handle);
|
||||
state->blank_ms = blank_timeout_ms(blank);
|
||||
if(strcmp(hw->backend, "none") == 0 || strcmp(hw->backend, "fb") == 0 ||
|
||||
!hw->spi_path[0] || !hw->gpio_path[0] || !hw->firmware[0])
|
||||
return;
|
||||
if(!hw->sim) {
|
||||
hw->fd_chip = open(hw->gpio_path, O_RDWR | O_CLOEXEC);
|
||||
if(hw->fd_chip < 0)
|
||||
return;
|
||||
}
|
||||
hw->spi_enabled = 1;
|
||||
}
|
||||
|
||||
static void lower_string(char *value)
|
||||
@@ -492,7 +1046,8 @@ static int test_value(const char *mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void handle_command(char *buffer, struct state *state, int *redraw)
|
||||
static void handle_command(char *buffer, struct state *state,
|
||||
struct cover_hw *hw, int *redraw)
|
||||
{
|
||||
char command[32];
|
||||
char *save = NULL;
|
||||
@@ -551,8 +1106,36 @@ static void handle_command(char *buffer, struct state *state, int *redraw)
|
||||
} else if(strcmp(command, "SET") == 0) {
|
||||
char *key = strtok_r(NULL, " \t\r\n", &save);
|
||||
char *value = strtok_r(NULL, " \t\r\n", &save);
|
||||
if(key && value && strcmp(key, "enabled") == 0)
|
||||
if(!key || !value)
|
||||
return;
|
||||
if(strcmp(key, "enabled") == 0) {
|
||||
state->enabled = (int)strtol(value, NULL, 10);
|
||||
*redraw = 1;
|
||||
return;
|
||||
}
|
||||
/* Runtime polarity knobs and a one-command rollback for the physical
|
||||
* sign-off. Releasing forces the next draw to re-init the panel. */
|
||||
if(strcmp(key, "backend") == 0) {
|
||||
safe_copy(hw->backend, sizeof(hw->backend), value);
|
||||
hw->spi_enabled =
|
||||
strcmp(hw->backend, "none") != 0 && strcmp(hw->backend, "fb") != 0 &&
|
||||
hw->spi_path[0] && hw->gpio_path[0] && hw->firmware[0];
|
||||
} else if(strcmp(key, "mux_closed_level") == 0)
|
||||
hw->mux_closed_level = config_level(value, hw->mux_closed_level);
|
||||
else if(strcmp(key, "mux_open_level") == 0)
|
||||
hw->mux_open_level = config_level(value, hw->mux_open_level);
|
||||
else if(strcmp(key, "dc_command_level") == 0)
|
||||
hw->dc_command_level = config_level(value, hw->dc_command_level);
|
||||
else if(strcmp(key, "dc_data_level") == 0)
|
||||
hw->dc_data_level = config_level(value, hw->dc_data_level);
|
||||
else if(strcmp(key, "reset_assert_level") == 0)
|
||||
hw->reset_assert_level = config_level(value, hw->reset_assert_level);
|
||||
else if(strcmp(key, "reset_idle_level") == 0)
|
||||
hw->reset_idle_level = config_level(value, hw->reset_idle_level);
|
||||
else
|
||||
return;
|
||||
cover_hw_release(hw);
|
||||
*redraw = 1;
|
||||
} else if(strcmp(command, "TEST") == 0) {
|
||||
char *mode = strtok_r(NULL, " \t\r\n", &save);
|
||||
if(mode)
|
||||
@@ -576,7 +1159,7 @@ static void handle_command(char *buffer, struct state *state, int *redraw)
|
||||
}
|
||||
|
||||
static void reply_for(char *buffer, const struct state *state,
|
||||
char *reply, size_t len)
|
||||
const struct cover_hw *hw, char *reply, size_t len)
|
||||
{
|
||||
char command[32];
|
||||
char *save = NULL;
|
||||
@@ -592,10 +1175,11 @@ static void reply_for(char *buffer, const struct state *state,
|
||||
} else if(strcmp(command, "STATUS") == 0) {
|
||||
snprintf(reply, len,
|
||||
"OK lid=%s backend=%s enabled=%d visible=%d blank_ms=%lld "
|
||||
"battery=%d call=%s sms=%d network=%s\n",
|
||||
"battery=%d call=%s sms=%d network=%s spi=%d mux=%s\n",
|
||||
state->lid, state->backend, state->enabled, state->visible,
|
||||
state->blank_ms, state->battery, state->call, state->sms,
|
||||
state->network);
|
||||
state->network, hw->spi_enabled,
|
||||
hw->mux_claimed ? (hw->claimed ? "closed" : "open") : "free");
|
||||
} else if(strcmp(command, "LID") == 0) {
|
||||
snprintf(reply, len, "OK lid=%s\n", state->lid);
|
||||
} else if(strcmp(command, "TEST") == 0) {
|
||||
@@ -615,6 +1199,7 @@ int main(int argc, char **argv)
|
||||
struct sockaddr_un local;
|
||||
int server;
|
||||
struct state state;
|
||||
struct cover_hw hw;
|
||||
long long last_draw = 0;
|
||||
int redraw = 1;
|
||||
if(lock_fd < 0)
|
||||
@@ -629,8 +1214,9 @@ int main(int argc, char **argv)
|
||||
snprintf(state.call, sizeof(state.call), "none");
|
||||
state.enabled = 1;
|
||||
state.battery = -1;
|
||||
cover_hw_init(&hw);
|
||||
read_config(config, socket_path, sizeof(socket_path),
|
||||
fb_path, sizeof(fb_path), &state);
|
||||
fb_path, sizeof(fb_path), &state, &hw);
|
||||
mkdir_p(socket_path);
|
||||
unlink(socket_path);
|
||||
server = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
@@ -649,7 +1235,7 @@ int main(int argc, char **argv)
|
||||
struct pollfd pfd;
|
||||
char buffer[512];
|
||||
char original[512];
|
||||
char reply[256];
|
||||
char reply[512];
|
||||
struct sockaddr_un peer;
|
||||
socklen_t peer_len = sizeof(peer);
|
||||
ssize_t nread;
|
||||
@@ -676,7 +1262,7 @@ int main(int argc, char **argv)
|
||||
if(redraw) {
|
||||
set_backlight(&state, cover_is_lit(&state));
|
||||
snprintf(state.backend, sizeof(state.backend), "%s",
|
||||
draw_frame(fb_path, &state) ? "fb" : "none");
|
||||
cover_draw(&hw, fb_path, &state));
|
||||
last_draw = now;
|
||||
redraw = 0;
|
||||
}
|
||||
@@ -689,12 +1275,13 @@ int main(int argc, char **argv)
|
||||
if(nread > 0) {
|
||||
buffer[nread] = '\0';
|
||||
snprintf(original, sizeof(original), "%s", buffer);
|
||||
handle_command(buffer, &state, &redraw);
|
||||
reply_for(original, &state, reply, sizeof(reply));
|
||||
handle_command(buffer, &state, &hw, &redraw);
|
||||
reply_for(original, &state, &hw, reply, sizeof(reply));
|
||||
sendto(server, reply, strlen(reply), 0,
|
||||
(struct sockaddr *)&peer, peer_len);
|
||||
if(strncasecmp(original, "QUIT", 4) == 0) {
|
||||
set_backlight(&state, 0);
|
||||
cover_hw_shutdown(&hw);
|
||||
close(server);
|
||||
unlink(socket_path);
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user