Use wfi in otherwise empty infinite loops in examples

- Clippy warns about empty loops, https://github.com/rust-lang/rust-clippy/issues/6161
- wfi allows to CPU to save some power

WFI was avoided in examples for fear of ill interactions with debuggers.
However the rp2040 debug port does continue to work, as long as the
relevant clocks are not disabled in SLEEP_EN0/SLEEP_EN1. (By default,
all clocks stay enabled in sleep mode.)

This patch replaces several different workarounds with just calling wfi.
This commit is contained in:
Jan Niehusmann 2022-08-01 14:50:48 +00:00
parent 6dafcc1ac0
commit 44019781e2
11 changed files with 19 additions and 23 deletions

View file

@ -149,7 +149,7 @@ fn main() -> ! {
print_temperature(&mut uart, temp); print_temperature(&mut uart, temp);
loop { loop {
cortex_m::asm::nop(); cortex_m::asm::wfi();
} }
} }

View file

@ -139,9 +139,8 @@ fn main() -> ! {
// In this case, we just ignore the result. A real application // In this case, we just ignore the result. A real application
// would do something with the measurement. // would do something with the measurement.
#[allow(clippy::empty_loop)]
loop { loop {
// Empty loop cortex_m::asm::wfi();
} }
} }

View file

@ -147,11 +147,7 @@ fn main() -> ! {
loop { loop {
// interrupts handle everything else in this example. // interrupts handle everything else in this example.
// if we wanted low power we could go to sleep. to cortex_m::asm::wfi();
// keep this example simple we'll just execute a `nop`.
// the `nop` (No Operation) instruction does nothing,
// but if we have no code here clippy would complain.
cortex_m::asm::nop();
} }
} }

View file

@ -97,9 +97,8 @@ fn main() -> ! {
// Demo finish - just loop until reset // Demo finish - just loop until reset
#[allow(clippy::empty_loop)]
loop { loop {
// Empty loop cortex_m::asm::wfi();
} }
} }

View file

@ -113,9 +113,8 @@ fn main() -> ! {
lcd.write_str("HD44780!", &mut delay).unwrap(); lcd.write_str("HD44780!", &mut delay).unwrap();
// Do nothing - we're finished // Do nothing - we're finished
#[allow(clippy::empty_loop)]
loop { loop {
// Empty loop cortex_m::asm::wfi();
} }
} }

View file

@ -64,6 +64,7 @@ fn main() -> ! {
sm.start(); sm.start();
// PIO runs in background, independently from CPU // PIO runs in background, independently from CPU
#[allow(clippy::empty_loop)] loop {
loop {} cortex_m::asm::wfi();
}
} }

View file

@ -54,6 +54,7 @@ fn main() -> ! {
sm.start(); sm.start();
// PIO runs in background, independently from CPU // PIO runs in background, independently from CPU
#[allow(clippy::empty_loop)] loop {
loop {} cortex_m::asm::wfi();
}
} }

View file

@ -57,6 +57,7 @@ fn main() -> ! {
sm.start(); sm.start();
// PIO runs in background, independently from CPU // PIO runs in background, independently from CPU
#[allow(clippy::empty_loop)] loop {
loop {} cortex_m::asm::wfi();
}
} }

View file

@ -91,6 +91,7 @@ fn main() -> ! {
cortex_m::asm::delay(10_000_000); cortex_m::asm::delay(10_000_000);
let _sm2 = sm2.stop(); let _sm2 = sm2.stop();
#[allow(clippy::empty_loop)] loop {
loop {} cortex_m::asm::wfi();
}
} }

View file

@ -166,7 +166,7 @@ fn main() -> ! {
// In case the reboot fails // In case the reboot fails
loop { loop {
cortex_m::asm::nop(); cortex_m::asm::wfi();
} }
} }

View file

@ -121,9 +121,8 @@ fn main() -> ! {
Err(_) => {} // handle errors Err(_) => {} // handle errors
}; };
#[allow(clippy::empty_loop)]
loop { loop {
// Empty loop cortex_m::asm::wfi();
} }
} }