From d4ed8e5779d5e09ea57728a48fc8654d93b786f8 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 7 Oct 2023 01:46:57 +0200 Subject: [PATCH] rp/bootsel: change it to a method on the peripheral. --- embassy-rp/src/bootsel.rs | 20 +++++++++++--------- embassy-rp/src/lib.rs | 1 + 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/embassy-rp/src/bootsel.rs b/embassy-rp/src/bootsel.rs index 69d620e8..540255ae 100644 --- a/embassy-rp/src/bootsel.rs +++ b/embassy-rp/src/bootsel.rs @@ -9,17 +9,19 @@ use crate::flash::in_ram; -/// Polls the BOOTSEL button. Returns true if the button is pressed. -/// -/// Polling isn't cheap, as this function waits for core 1 to finish it's current -/// task and for any DMAs from flash to complete -pub fn poll_bootsel() -> bool { - let mut cs_status = Default::default(); +impl crate::peripherals::BOOTSEL { + /// Polls the BOOTSEL button. Returns true if the button is pressed. + /// + /// Polling isn't cheap, as this function waits for core 1 to finish it's current + /// task and for any DMAs from flash to complete + pub fn is_pressed(&mut self) -> bool { + let mut cs_status = Default::default(); - unsafe { in_ram(|| cs_status = ram_helpers::read_cs_status()) }.expect("Must be called from Core 0"); + unsafe { in_ram(|| cs_status = ram_helpers::read_cs_status()) }.expect("Must be called from Core 0"); - // bootsel is active low, so invert - !cs_status.infrompad() + // bootsel is active low, so invert + !cs_status.infrompad() + } } mod ram_helpers { diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index fb918920..2728395b 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs @@ -194,6 +194,7 @@ embassy_hal_internal::peripherals! { PIO1, WATCHDOG, + BOOTSEL, } macro_rules! select_bootloader {