Make 2720 Flip lid switching instant and route closed-flip events to the cover

The lid daemon re-derived "observed" from a stale EV_SW mask on every 100 ms
iteration and only read the raw hall lines every 200 ms, so the candidate
oscillated and the 80 ms debounce almost never completed. A controlled hall
transition on the live phone took over 2.2 s to blank and lock the main panel.
The hall reading is now sticky, every EV_SW edge forces an immediate hall
re-read, the loop and debounce are 20 ms, and the daemon writes the lid state,
lock flag, Sxmo state and both backlights synchronously in C before spawning
hooks. A direct xset DPMS off/on stops or resumes Xorg's SPI flushes at once.
bananarchy-lid-state.sh guards the asynchronous hooks by lid state and a
transition generation counter, so a late screenoff cannot re-lock a flip that
was just opened.

bananarchy-lid-gate.sh now gates sxmo_wm.sh display on, the screen-wake
helper, the backlight udev helper, sxmo_state.sh set unlock (dwm calls it
directly) and both input handler copies. While the flip is closed it blocks
the main panel and keypad backlight, forces brightness/kbd/DPMS off against
stray writes, and forwards a WAKE datagram to the cover display. Ring,
notification and call-state hooks publish to the cover, and the cover daemon
gained WAKE, event wakes, immunity to repeated LID CLOSED rebroadcasts and a
bounded retry for a DPMS-deferred draw.

Live verification with controlled hall transitions and uinput switch/key
injection: close blanks and locks in ~45-90 ms (hall-poll fallback
~100-220 ms), open restores brightness, keypad backlight, unlock and DPMS in
~10-130 ms with no stale-hook re-lock. All three external keys and an
incoming call leave brightness=0, kbd_backlight=0 and DPMS=Off while the
cover reports backend=spidev visible=1; opening returns mux=open.

Rebuilt the a1108/dejavu nokia-beatles image and pinned the verified hash
0f33aa6e9fc70022574b453aaafb9307c4d185431d3be272782c8403dd0fb291 in
check-rebuild.sh. e2fsck -fn passed on both partitions, debugfs confirms
twelve 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 cover illumination and the
remaining polarity/CS fixes are still required.
This commit is contained in:
Luxferre committed 2026-11-10 20:23:06 +02:00
1 parent 40a840b49b
commit 2857ef4374
29 files changed
+567 -49

No files matched your search

+57 -7
View File
@@ -373,7 +373,7 @@ fi
echo "[check] Known-good flashable image set..."
for pair in \
"69a44f60eb123ebddf600be927155dc4a599ec35b7a0cf80060f4ba01f599f08 images/bananarchy-nokia-argon.img" \
"ccc8c44517a6a3b78e16e45e9dddbf89f6f04a35ee4c52246d38d89970bd13ac images/bananarchy-nokia-beatles.img" \
"0f33aa6e9fc70022574b453aaafb9307c4d185431d3be272782c8403dd0fb291 images/bananarchy-nokia-beatles.img" \
"2b5c61aba307dbbda61f3b19a2ad5770f9854f41cba4e2c97e24efb7e20879f3 images/boot-bananarchy-nokia-beatles.img" \
"b5549698c20f4de7603fc746d32bb5baa96ec377e41e74407823c98506fc185d images/boot-lk2nd-nokia-beatles-display.img"; do
set -- $pair
@@ -419,7 +419,9 @@ for src in src/bananarchy-daemons/common.h \
fi
done
if ! grep -q 'CLOSED_MASK' "$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c" || \
! grep -q 'sxmo_state.sh' "$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c" || \
! grep -q 'bananarchy-lid-state.sh' "$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c" || \
! grep -q 'sxmo_state.sh' \
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-lid-state.sh" || \
! grep -q 'strcmp(level, "low")' "$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c"; then
fail "the compiled lid daemon lost its raw hall GPIO fallback"
fi
@@ -580,6 +582,8 @@ for f in overlay/rootfs/usr/lib/udev/rules.d/99-bananarchy-keypad.rules \
overlay/rootfs/usr/bin/bananarchy-keypad-diagnose.sh \
overlay/rootfs/usr/bin/bananarchy-coverd \
overlay/rootfs/usr/bin/bananarchy-cover-msg \
overlay/rootfs/usr/bin/bananarchy-lid-gate.sh \
overlay/rootfs/usr/bin/bananarchy-lid-state.sh \
overlay/rootfs/etc/init.d/bananarchy-cover-display \
overlay/rootfs/etc/bananarchy/cover-display.conf \
devices/nokia-beatles/cover-panel.dtsi \
@@ -895,15 +899,61 @@ fi
echo "[check] Flip lid responsiveness..."
LID_SRC="$BASE_DIR/src/bananarchy-daemons/bananarchy-lid.c"
for token in '#define LID_STABLE_MS 80' '#define HALL_POLL_MS 200' 'BA_EVIOCGSW' 'LID_STATE_FILE' \
'LOCKER_FIFO' 'unlink(LOCK_FLAG)' 'now - last_hall_poll >= HALL_POLL_MS'; do
for token in '#define LID_DEBOUNCE_MS 20' '#define HALL_EDGE_MS 20' \
'#define LID_LOOP_MS 20' 'BA_EVIOCGSW' 'LID_STATE_FILE' \
'LOCKER_FIFO' 'unlink(LOCK_FLAG)' 'hall_observed' 'fast_until' \
'if(edge)' 'write_session_file(state, "screenoff")' \
'write_session_file(state, "unlock")' 'cover_send("OPEN")' \
'LID_GENERATION_FILE' 'run_dpms' \
'bananarchy-lid-state.sh'; do
if ! grep -qF "$token" "$LID_SRC"; then
fail "the compiled lid daemon lost the low-latency EV_SW/unlock path ($token)"
fail "the compiled lid daemon lost the instant EV_SW/hall path ($token)"
fi
done
if grep -qF 'closed != was_closed' "$LID_SRC" || \
grep -qF '#define LID_STABLE_MS 600' "$LID_SRC"; then
fail "the compiled lid daemon still accepts slow immediate hall transitions"
grep -qF '#define LID_STABLE_MS 600' "$LID_SRC" || \
grep -qF '#define LID_STABLE_MS 80' "$LID_SRC" || \
grep -qF 'observed = (switch_mask &' "$LID_SRC"; then
fail "the compiled lid daemon still oscillates on a stale EV_SW mask"
fi
echo "[check] Closed-flip main-panel gate..."
LID_GATE="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-lid-gate.sh"
if [ ! -x "$LID_GATE" ] || ! sh -n "$LID_GATE" 2>/dev/null; then
fail "bananarchy-lid-gate.sh is missing or has bad syntax"
fi
for f in overlay/rootfs/usr/bin/sxmo_wm.sh \
overlay/rootfs/usr/bin/sxmo_state.sh \
overlay/rootfs/usr/bin/bananarchy-screen-wake.sh \
overlay/rootfs/usr/bin/bananarchy-display-power-sync \
overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_inputhandler.sh \
overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_inputhandler.sh; do
if ! grep -qF 'bananarchy-lid-gate.sh' "$BASE_DIR/$f"; then
fail "$f can still light the main panel with the flip closed"
fi
done
if ! grep -qF 'coverctl WAKE' \
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-cover-event.sh" || \
! grep -qF 'bananarchy-cover-event.sh ring' \
"$BASE_DIR/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_ring.sh" || \
! grep -qF 'bananarchy-cover-event.sh notification' \
"$BASE_DIR/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_notification.sh"; then
fail "closed-flip events are no longer forwarded to the cover display"
fi
if ! grep -qF 'cover_wake' "$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c" || \
! grep -qF 'strcmp(command, "WAKE")' \
"$BASE_DIR/src/bananarchy-daemons/bananarchy-cover-idle.c"; then
fail "the cover daemon no longer honours a closed-flip WAKE"
fi
if [ ! -x "$BASE_DIR/scripts/test-lid-gate.py" ] || \
! "$BASE_DIR/scripts/test-lid-gate.py" >/dev/null 2>&1; then
fail "host instant-lid / closed-flip gate test failed"
fi
LID_WRAPPER="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-lid-state.sh"
if [ ! -x "$LID_WRAPPER" ] || \
! grep -qF 'lid-generation' "$LID_WRAPPER" || \
! grep -qF 'lid-generation' "$LID_SRC"; then
fail "the guarded lid hook wrapper / generation check is missing"
fi
echo "[check] Fast X startup and boot keypad state..."