//! Bootloader entry helpers shared between power-on checks and runtime combos. use crate::{KeyMatrix, StatusLed, layout, status::StatusMode}; #[cfg(all(test, feature = "std"))] use crate::NUMBER_OF_KEYS; use cortex_m::asm; use rp2040_hal::{ gpio::AnyPin, pio::{PIOExt, StateMachineIndex}, }; use usbd_human_interface_device::page::Keyboard; /// Returns true when the runtime bootloader chord is held. /// /// The chord requires two Fn buttons, both Shift buttons and the primary Ctrl. pub fn chord_requested(pressed_keys: &KeyMatrix) -> bool { if !modifier_pressed(pressed_keys, Keyboard::LeftShift) || !modifier_pressed(pressed_keys, Keyboard::RightShift) { return false; } if !modifier_pressed(pressed_keys, Keyboard::LeftControl) { return false; } let active_fn = layout::FN_BUTTONS .iter() .filter(|index| pressed_keys[**index as usize]) .count(); active_fn >= 2 } fn modifier_pressed(pressed_keys: &KeyMatrix, key: Keyboard) -> bool { layout::MAP[0] .iter() .enumerate() .any(|(index, mapped)| *mapped == key && pressed_keys[index]) } /// Puts the RP2040 into the ROM bootloader. pub fn enter
(status_led: &mut StatusLed
) -> !
where
P: PIOExt,
SM: StateMachineIndex,
I: AnyPin