From f823a81aa8a54da70ac065436e4af684ec0b5045 Mon Sep 17 00:00:00 2001 From: Andrew Herbert Date: Wed, 15 Nov 2023 21:33:39 +1100 Subject: [PATCH] fix clippy warnings --- rp2040-hal/examples/dormant_sleep.rs | 71 +++++++++++++--------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/rp2040-hal/examples/dormant_sleep.rs b/rp2040-hal/examples/dormant_sleep.rs index 84187faa1..9c295f3a3 100644 --- a/rp2040-hal/examples/dormant_sleep.rs +++ b/rp2040-hal/examples/dormant_sleep.rs @@ -32,7 +32,7 @@ use hal::{ gpio, gpio::{Interrupt::EdgeLow, Pins}, pac, - pac::{interrupt, CLOCKS, PLL_SYS, PLL_USB, RESETS, ROSC, XOSC}, + pac::{interrupt, CLOCKS, PLL_SYS, PLL_USB, RESETS, XOSC}, pll::{ common_configs::{PLL_SYS_125MHZ, PLL_USB_48MHZ}, setup_pll_blocking, start_pll_blocking, Disabled, Locked, PhaseLockedLoop, @@ -46,6 +46,19 @@ use hal::{ use nb::block; +type ClocksAndPlls = ( + ClocksManager, + CrystalOscillator, + PhaseLockedLoop, + PhaseLockedLoop, +); + +type RestartedClockAndPlls = ( + CrystalOscillator, + PhaseLockedLoop, + PhaseLockedLoop, +); + /// The button input. type ButtonPin = gpio::Pin; @@ -74,7 +87,6 @@ fn main() -> ! { let (mut clocks, mut xosc, mut pll_sys, mut pll_usb) = init_clocks_and_plls( XTAL_FREQ_HZ, pac.XOSC, - pac.ROSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, @@ -84,6 +96,10 @@ fn main() -> ! { .ok() .unwrap(); + // Disable ring oscillator to maximise power savings - optional + let rosc = RingOscillator::new(pac.ROSC).initialize(); + rosc.disable(); + // Set the pins to their default state let pins = Pins::new( pac.IO_BANK0, @@ -139,11 +155,11 @@ fn main() -> ! { // Clear dormant wake interrupt status to enable wake next time critical_section::with(|cs| { let mut global_devices = GLOBAL_DEVICES.borrow(cs).borrow_mut(); - let Some(ref mut trigger_pin) = global_devices.deref_mut() else { - panic!() + if let Some(ref mut trigger_pin) = global_devices.deref_mut() { + trigger_pin.clear_interrupt(EdgeLow); + } else { + panic!(); }; - - trigger_pin.clear_interrupt(EdgeLow); }); } else { pulse(&mut led_pin, 2); @@ -172,21 +188,12 @@ fn pulse(pin: &mut P, count: u32) { fn init_clocks_and_plls( xosc_crystal_freq: u32, xosc_dev: XOSC, - rosc_dev: ROSC, clocks_dev: CLOCKS, pll_sys_dev: PLL_SYS, pll_usb_dev: PLL_USB, resets: &mut RESETS, watchdog: &mut Watchdog, -) -> Result< - ( - ClocksManager, - CrystalOscillator, - PhaseLockedLoop, - PhaseLockedLoop, - ), - InitError, -> { +) -> Result { let xosc = setup_xosc_blocking(xosc_dev, xosc_crystal_freq.Hz()).unwrap(); // Configure watchdog tick generation to tick over every microsecond @@ -215,9 +222,6 @@ fn init_clocks_and_plls( .init_default(&xosc, &pll_sys, &pll_usb) .map_err(InitError::ClockError)?; - let rosc = RingOscillator::new(rosc_dev).initialize(); - rosc.disable(); // disable ring oscillator to maximise power savings - Ok((clocks, xosc, pll_sys, pll_usb)) } @@ -257,14 +261,7 @@ fn restart_clocks_and_plls( disabled_pll_sys: PhaseLockedLoop, disabled_pll_usb: PhaseLockedLoop, resets: &mut RESETS, -) -> Result< - ( - CrystalOscillator, - PhaseLockedLoop, - PhaseLockedLoop, - ), - ClockError, -> { +) -> Result { // Wait for the restarted XOSC to stabilise let stable_xosc_token = block!(unstable_xosc.await_stabilization()).unwrap(); let xosc = unstable_xosc.get_stable(stable_xosc_token); @@ -281,17 +278,17 @@ fn restart_clocks_and_plls( fn IO_IRQ_BANK0() { critical_section::with(|cs| { let mut global_devices = GLOBAL_DEVICES.borrow(cs).borrow_mut(); - let Some(ref mut button_pin) = global_devices.deref_mut() else { - panic!() + if let Some(ref mut button_pin) = global_devices.deref_mut() { + // Check if the interrupt source is from the push button going from high-to-low. + // Note: this will always be true in this example, as that is the only enabled GPIO interrupt source + if button_pin.interrupt_status(EdgeLow) { + // Our interrupt doesn't clear itself. + // Do that now so we don't immediately jump back to this interrupt handler. + button_pin.clear_interrupt(EdgeLow); + } + } else { + panic!(); }; - - // Check if the interrupt source is from the push button going from high-to-low. - // Note: this will always be true in this example, as that is the only enabled GPIO interrupt source - if button_pin.interrupt_status(EdgeLow) { - // Our interrupt doesn't clear itself. - // Do that now so we don't immediately jump back to this interrupt handler. - button_pin.clear_interrupt(EdgeLow); - } }); }