feat(presence): add configurable GPIO presence pin#17
Conversation
3763814 to
9216bee
Compare
9216bee to
fca95b9
Compare
|
I also implemented a feature similar to this PR a while ago. The underlying principles are similar, but there are some differences in the design. I would like to discuss this with @lpiob and @TheMaxMur to see if there is any room to optimize this feature. My branch is located at https://github.com/Curious-r/RS-Key/tree/touch-btn-config. Below is a summary of the similarities and differences between my implementation and this PR: Both implementations:
Key Differences
Detailed Discussion1. Compile-time vs Runtime ConfigurationThe merged PR uses env vars set during the build, which requires a reflash to change the presence pin. This is simple and has zero runtime storage overhead. However, RS-Key already has the phy record mechanism for the LED backend ( The phy record approach adds about 20 bytes of Rust code (a new TLV tag + parse/serialize) and ~40 lines of Python CLI. In return, users can reassign the button pin without reflashing — useful for testing different board layouts or for field reconfigurations. Could we support both? A reasonable middle ground: keep the compile-time env vars as a build default, but let an optional phy record override them at runtime. This gives the simplicity of env vars for known builds and the flexibility of runtime config for multi-board deployments. 2. PolarityThe merged PR hard-codes active-low with a pull-up, which covers the common button-to-GND wiring. Our implementation adds an
This is a small extension that adds no meaningful complexity but covers more hardware. 3. GPIO LED Pin SelectionWhile working on the presence button, we noticed the GPIO LED backend had the same pattern: a 30-arm match block selecting concrete let led_pin = unsafe { AnyPin::steal(led_gpio) };
let led = Output::new(led_pin, Level::Low);This eliminates 30 lines of boilerplate match arms. The safety argument is the same as for the presence button — the GPIO LED and WS2812 backends are mutually exclusive at runtime (different We could upstream this as a separate, trivial cleanup — it's not coupled to the presence button feature. 4. Struct DesignOur commit also renames // Upstream
pub struct BootselPresence {
button: Button,
}
enum Button { Bootsel(Peri<BOOTSEL>), Gpio(Input) }
// Our branch
pub enum PresenceButton {
Bootsel(Peri<'static, BOOTSEL>),
Gpio(Input<'static>, Polarity),
}The enum approach is slightly more idiomatic for a sum type and makes the polarity field naturally part of the Open Questions
I'd love to hear thoughts. |
Brings @lpiob's PRESENCE_PIN feature (a compile-time configurable GPIO presence button, with the BOOTSEL default preserved) onto the trusted-display branch. Conflict resolution: - firmware/src/presence.rs: combine main's Button{Bootsel,Gpio} enum + new_bootsel/new_gpio/pressed() with develop's display gating (#[cfg(not(feature = "display"))], the TouchPresence alias), the pub(crate) statics, the runtime PRESENCE_TIMEOUT_MS, and the Confirm-carrying UserPresence::request signature. - firmware/src/main.rs: the non-display presence path now picks BOOTSEL vs GPIO; the display path keeps TouchPresence. bcdDevice resolved to 0x0792 (after develop's 0x0791; main's parallel 0x0782 is a separate lineage). - nix/firmware.nix: keep both the ledKind and presencePin knobs. Integration (the minor follow-ons): - A display build takes presence from the touchscreen, so PRESENCE_PIN is now rejected at compile time (a const assert) rather than being silently ignored. - Add the CHANGELOG [Unreleased] entry PR #17 omitted (bcdDevice 0x0791 -> 0x0792). Both flavors build; `nix develop -c ./scripts/check.sh` is green and the PRESENCE_PIN GPIO build + the display-build rejection are verified. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@Curious-r pls check on v0.3.0 |
|
@TheMaxMur Okay, I’m looking at it right now. |
What
Presence button can be now remapped to a custom GPIO pin at compile time.
Backwards compatibility (default mapping to BOOTSEL) was preserved.
How it was tested
nix develop -c ./scripts/check.shpasses locallyTested on TenStar RP2350 with a quickly attached capacitive-touch button :

Checklist
config.device_release(bcdDevice) bumped by one (hex) infirmware/src/main.rsunsafe→ justified indocs/unsafe.mddocs/updatedAGPL-3.0-only)fido:,piv:,rsk:,docs:, …)