Skip to content

Commit

Permalink
Remove unnecessary delay (#1794)
Browse files Browse the repository at this point in the history
* fix: Remove unnecesary delay

* docs: Update changelog

* fix: Remove unused variable

* fix: Remove clippy warning from examples
  • Loading branch information
SergioGasquez authored Jul 15, 2024
1 parent 10c900a commit 7ea471c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 29 deletions.
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved `#[ram(zeroed)]` soundness by adding a `bytemuck::Zeroable` type bound (#1677)
- EESP32-S2 / ESP32-S3: Fix UsbDm and UsbDp for Gpio19 and Gpio20
- Fix reading/writing small buffers via SPI master async dma (#1760)
- Remove unnecessary delay in rtc_ctnl (#1794)

### Changed

Expand Down
24 changes: 5 additions & 19 deletions esp-hal/src/rtc_cntl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,44 +286,30 @@ impl<'d> Rtc<'d> {

/// Enter deep sleep and wake with the provided `wake_sources`.
#[cfg(any(esp32, esp32s3, esp32c3, esp32c6))]
pub fn sleep_deep(
&mut self,
wake_sources: &[&dyn WakeSource],
delay: &mut crate::delay::Delay,
) -> ! {
pub fn sleep_deep(&mut self, wake_sources: &[&dyn WakeSource]) -> ! {
let config = RtcSleepConfig::deep();
self.sleep(&config, wake_sources, delay);
self.sleep(&config, wake_sources);
unreachable!();
}

/// Enter light sleep and wake with the provided `wake_sources`.
#[cfg(any(esp32, esp32s3, esp32c3, esp32c6))]
pub fn sleep_light(
&mut self,
wake_sources: &[&dyn WakeSource],
delay: &mut crate::delay::Delay,
) {
pub fn sleep_light(&mut self, wake_sources: &[&dyn WakeSource]) {
let config = RtcSleepConfig::default();
self.sleep(&config, wake_sources, delay);
self.sleep(&config, wake_sources);
}

/// Enter sleep with the provided `config` and wake with the provided
/// `wake_sources`.
#[cfg(any(esp32, esp32s3, esp32c3, esp32c6))]
pub fn sleep(
&mut self,
config: &RtcSleepConfig,
wake_sources: &[&dyn WakeSource],
delay: &mut crate::delay::Delay,
) {
pub fn sleep(&mut self, config: &RtcSleepConfig, wake_sources: &[&dyn WakeSource]) {
let mut config = *config;
let mut wakeup_triggers = WakeTriggers::default();
for wake_source in wake_sources {
wake_source.apply(self, &mut wakeup_triggers, &mut config)
}

config.apply();
delay.delay_millis(100);

config.start_sleep(wakeup_triggers);
config.finish_sleep();
Expand Down
4 changes: 2 additions & 2 deletions examples/src/bin/sleep_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let mut delay = Delay::new(&clocks);
let delay = Delay::new(&clocks);
let mut rtc = Rtc::new(peripherals.LPWR, None);

println!("up and runnning!");
Expand All @@ -37,5 +37,5 @@ fn main() -> ! {
let timer = TimerWakeupSource::new(Duration::from_secs(5));
println!("sleeping!");
delay.delay_millis(100);
rtc.sleep_deep(&[&timer], &mut delay);
rtc.sleep_deep(&[&timer]);
}
4 changes: 2 additions & 2 deletions examples/src/bin/sleep_timer_ext0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ fn main() -> ! {
let wake_reason = get_wakeup_cause();
println!("wake reason: {:?}", wake_reason);

let mut delay = Delay::new(&clocks);
let delay = Delay::new(&clocks);

let timer = TimerWakeupSource::new(Duration::from_secs(30));
let ext0 = Ext0WakeupSource::new(&mut ext0_pin, WakeupLevel::High);
println!("sleeping!");
delay.delay_millis(100);
rtc.sleep_deep(&[&timer, &ext0], &mut delay);
rtc.sleep_deep(&[&timer, &ext0]);
}
4 changes: 2 additions & 2 deletions examples/src/bin/sleep_timer_ext1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ fn main() -> ! {
let wake_reason = get_wakeup_cause();
println!("wake reason: {:?}", wake_reason);

let mut delay = Delay::new(&clocks);
let delay = Delay::new(&clocks);

let timer = TimerWakeupSource::new(Duration::from_secs(30));
let mut wakeup_pins: [&mut dyn RtcPin; 2] = [&mut pin_0, &mut pin_2];
let ext1 = Ext1WakeupSource::new(&mut wakeup_pins, WakeupLevel::High);
println!("sleeping!");
delay.delay_millis(100);
rtc.sleep_deep(&[&timer, &ext1], &mut delay);
rtc.sleep_deep(&[&timer, &ext1]);
}
4 changes: 2 additions & 2 deletions examples/src/bin/sleep_timer_lpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() -> ! {
let wake_reason = get_wakeup_cause();
println!("wake reason: {:?}", wake_reason);

let mut delay = Delay::new(&clocks);
let delay = Delay::new(&clocks);
let timer = TimerWakeupSource::new(Duration::from_secs(10));

let wakeup_pins: &mut [(&mut dyn RtcPinWithResistors, WakeupLevel)] = &mut [
Expand All @@ -55,5 +55,5 @@ fn main() -> ! {
let rtcio = Ext1WakeupSource::new(wakeup_pins);
println!("sleeping!");
delay.delay_millis(100);
rtc.sleep_deep(&[&timer, &rtcio], &mut delay);
rtc.sleep_deep(&[&timer, &rtcio]);
}
4 changes: 2 additions & 2 deletions examples/src/bin/sleep_timer_rtcio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() -> ! {
let wake_reason = get_wakeup_cause();
println!("wake reason: {:?}", wake_reason);

let mut delay = Delay::new(&clocks);
let delay = Delay::new(&clocks);
let timer = TimerWakeupSource::new(Duration::from_secs(10));

#[cfg(feature = "esp32c3")]
Expand All @@ -59,5 +59,5 @@ fn main() -> ! {
let rtcio = RtcioWakeupSource::new(wakeup_pins);
println!("sleeping!");
delay.delay_millis(100);
rtc.sleep_deep(&[&timer, &rtcio], &mut delay);
rtc.sleep_deep(&[&timer, &rtcio]);
}

0 comments on commit 7ea471c

Please sign in to comment.