
You own firmware for an embedded device where a physical button can trigger privileged actions such as pairing, recovery, or erase flows. During bring-up, you observe contact bounce, occasional repeated interrupts, and inconsistent behavior after sleep/wake transitions. You also need to ensure a noisy or manipulated GPIO signal cannot accidentally trigger sensitive state changes.
How would you design the button-handling path in firmware so it debounces reliably, behaves correctly across interrupts and low-power states, and resists accidental or malicious triggering of privileged actions? Walk through the architecture, the controls you would add, and how you would verify the implementation works on real hardware.