Skip to content

Commit 70126c8

Browse files
authored
Rename esp_hal::time::current_time to esp_hal::time::now (#2091)
* rename esp_hal::time::current_time to esp_hal::time::uptime * changelog * move more things to init * s/uptime/now/g
1 parent f11c18a commit 70126c8

File tree

21 files changed

+73
-152
lines changed

21 files changed

+73
-152
lines changed

esp-hal-embassy/src/time_driver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use embassy_time_driver::{AlarmHandle, Driver};
55
use esp_hal::{
66
interrupt::{InterruptHandler, Priority},
77
prelude::*,
8-
time::current_time,
8+
time::now,
99
timer::{ErasedTimer, OneShotTimer},
1010
};
1111

@@ -119,7 +119,7 @@ impl EmbassyTimer {
119119
}
120120

121121
fn arm(timer: &mut Timer, timestamp: u64) {
122-
let now = current_time().duration_since_epoch();
122+
let now = now().duration_since_epoch();
123123
let ts = timestamp.micros();
124124
// if the TS is already in the past make the timer fire immediately
125125
let timeout = if ts > now { ts - now } else { 0.micros() };
@@ -130,7 +130,7 @@ impl EmbassyTimer {
130130

131131
impl Driver for EmbassyTimer {
132132
fn now(&self) -> u64 {
133-
current_time().ticks()
133+
now().ticks()
134134
}
135135

136136
unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {

esp-hal/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- `Delay::new()` is now a `const` function (#1999)
2323
- You can now create an `AnyPin` out of an `ErasedPin`. (#2072)
2424
- `Input`, `Output`, `OutputOpenDrain` and `Flex` are now type-erased by default. Use the new `new_typed` constructor to keep using the ZST pin types. (#2075)
25+
- To avoid confusion with the `Rtc::current_time` wall clock time APIs, we've renamed `esp_hal::time::current_time` to `esp_hal::time::now`. (#2091)
2526

2627
### Fixed
2728
- SHA driver can now be safely used in multiple contexts concurrently (#2049)

esp-hal/MIGRATING-0.20.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,12 @@ However, if you want to, you can keep using their typed form!
5050
```rust
5151
let pin = Input::new(io.gpio0); // pin will have the type `Input<'some>` (or `Input<'some, ErasedPin>` if you want to be explicit about it)
5252
let pin = Input::new_typed(io.gpio0); // pin will have the type `Input<'some, GpioPin<0>>`
53+
54+
## `esp_hal::time::current_time` rename
55+
56+
To avoid confusion with the `Rtc::current_time` wall clock time APIs, we've renamed `esp_hal::time::current_time` to `esp_hal::time::now()`.
57+
58+
```diff
59+
- use esp_hal::time::current_time;
60+
+ use esp_hal::time::now;
5361
```

esp-hal/src/delay.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! ## Overview
44
//!
55
//! The Delay driver provides blocking delay functionalities using the
6-
//! [current_time] function.
6+
//! [now] function.
77
//!
88
//! ## Configuration
99
//!
@@ -31,7 +31,7 @@
3131
//! [DelayMs]: embedded_hal_02::blocking::delay::DelayMs
3232
//! [DelayUs]: embedded_hal_02::blocking::delay::DelayUs
3333
//! [embedded-hal]: https://docs.rs/embedded-hal/1.0.0/embedded_hal/delay/index.html
34-
//! [current_time]: crate::time::current_time
34+
//! [now]: crate::time::now
3535
3636
pub use fugit::MicrosDurationU64;
3737

@@ -75,7 +75,7 @@ impl Delay {
7575

7676
/// Delay for the specified time
7777
pub fn delay(&self, delay: MicrosDurationU64) {
78-
let start = crate::time::current_time();
78+
let start = crate::time::now();
7979

8080
while elapsed_since(start) < delay {}
8181
}
@@ -101,12 +101,12 @@ impl Delay {
101101
}
102102

103103
fn elapsed_since(start: fugit::Instant<u64, 1, 1_000_000>) -> MicrosDurationU64 {
104-
let now = crate::time::current_time();
104+
let now = crate::time::now();
105105

106106
if start.ticks() <= now.ticks() {
107107
now - start
108108
} else {
109-
// current_time specifies at least 7 happy years, let's ignore this issue for
109+
// now specifies at least 7 happy years, let's ignore this issue for
110110
// now.
111111
panic!("Time has wrapped around, which we currently don't handle");
112112
}

esp-hal/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,26 @@ pub struct Config {
734734
///
735735
/// This function sets up the CPU clock and returns the peripherals and clocks.
736736
pub fn init(config: Config) -> Peripherals {
737-
let peripherals = Peripherals::take();
737+
let mut peripherals = Peripherals::take();
738738

739739
Clocks::init(config.cpu_clock);
740740

741+
#[cfg(xtensa)]
742+
crate::interrupt::setup_interrupts();
743+
#[cfg(esp32)]
744+
crate::time::time_init();
745+
746+
// RTC domain must be enabled before we try to disable
747+
let mut rtc = crate::rtc_cntl::Rtc::new(&mut peripherals.LPWR);
748+
#[cfg(not(any(esp32, esp32s2)))]
749+
rtc.swd.disable();
750+
rtc.rwdt.disable();
751+
752+
unsafe {
753+
crate::timer::timg::Wdt::<self::peripherals::TIMG0, Blocking>::set_wdt_enabled(false);
754+
#[cfg(timg1)]
755+
crate::timer::timg::Wdt::<self::peripherals::TIMG1, Blocking>::set_wdt_enabled(false);
756+
}
757+
741758
peripherals
742759
}

esp-hal/src/soc/esp32/mod.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
88
use core::ptr::addr_of_mut;
99

10-
use self::peripherals::{LPWR, TIMG0, TIMG1};
11-
use crate::{
12-
rtc_cntl::{Rtc, SocResetReason},
13-
timer::timg::Wdt,
14-
};
10+
use crate::rtc_cntl::SocResetReason;
1511

1612
pub mod cpu_control;
1713
pub mod efuse;
@@ -111,9 +107,6 @@ pub unsafe extern "C" fn ESP32Reset() -> ! {
111107
stack_chk_guard.write_volatile(0xdeadbabe);
112108
}
113109

114-
crate::interrupt::setup_interrupts();
115-
crate::time::time_init();
116-
117110
// continue with default reset handler
118111
xtensa_lx_rt::Reset();
119112
}
@@ -126,13 +119,3 @@ pub unsafe extern "C" fn ESP32Reset() -> ! {
126119
pub extern "Rust" fn __init_data() -> bool {
127120
false
128121
}
129-
130-
#[export_name = "__post_init"]
131-
unsafe fn post_init() {
132-
// RTC domain must be enabled before we try to disable
133-
let mut rtc = Rtc::new(LPWR::steal());
134-
rtc.rwdt.disable();
135-
136-
Wdt::<TIMG0, crate::Blocking>::set_wdt_enabled(false);
137-
Wdt::<TIMG1, crate::Blocking>::set_wdt_enabled(false);
138-
}

esp-hal/src/soc/esp32c2/mod.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
//! The `SOC` module provides access, functions and structures that are useful
66
//! for interacting with various system-related peripherals on `ESP32-C2` chip.
77
8-
use self::peripherals::{LPWR, TIMG0};
9-
use crate::{rtc_cntl::Rtc, timer::timg::Wdt};
10-
118
pub mod efuse;
129
pub mod gpio;
1310
pub mod peripherals;
@@ -38,13 +35,3 @@ pub(crate) mod constants {
3835
/// RC FAST Clock value (Hertz).
3936
pub const RC_FAST_CLK: fugit::HertzU32 = fugit::HertzU32::kHz(17500);
4037
}
41-
42-
#[export_name = "__post_init"]
43-
unsafe fn post_init() {
44-
// RTC domain must be enabled before we try to disable
45-
let mut rtc = Rtc::new(LPWR::steal());
46-
rtc.swd.disable();
47-
rtc.rwdt.disable();
48-
49-
Wdt::<TIMG0, crate::Blocking>::set_wdt_enabled(false);
50-
}

esp-hal/src/soc/esp32c3/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
//! * I2S_SCLK: 160_000_000 - I2S clock frequency
1010
//! * I2S_DEFAULT_CLK_SRC: 2 - I2S clock source
1111
12-
use self::peripherals::{LPWR, TIMG0, TIMG1};
13-
use crate::{rtc_cntl::Rtc, timer::timg::Wdt};
14-
1512
pub mod efuse;
1613
pub mod gpio;
1714
pub mod peripherals;
@@ -56,14 +53,3 @@ pub(crate) mod constants {
5653
/// RC FAST Clock value (Hertz).
5754
pub const RC_FAST_CLK: fugit::HertzU32 = fugit::HertzU32::kHz(17500);
5855
}
59-
60-
#[export_name = "__post_init"]
61-
unsafe fn post_init() {
62-
// RTC domain must be enabled before we try to disable
63-
let mut rtc = Rtc::new(LPWR::steal());
64-
rtc.swd.disable();
65-
rtc.rwdt.disable();
66-
67-
Wdt::<TIMG0, crate::Blocking>::set_wdt_enabled(false);
68-
Wdt::<TIMG1, crate::Blocking>::set_wdt_enabled(false);
69-
}

esp-hal/src/soc/esp32c6/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
//! * I2S_DEFAULT_CLK_SRC: 2 - I2S clock source
1111
//! * I2S_SCLK: 160_000_000 - I2S clock frequency
1212
13-
use self::peripherals::{LPWR, TIMG0, TIMG1};
14-
use crate::{rtc_cntl::Rtc, timer::timg::Wdt};
15-
1613
pub mod efuse;
1714
pub mod gpio;
1815
pub mod lp_core;
@@ -64,14 +61,3 @@ pub(crate) mod constants {
6461
/// RC FAST Clock value (Hertz).
6562
pub const RC_FAST_CLK: fugit::HertzU32 = fugit::HertzU32::kHz(17_500);
6663
}
67-
68-
#[export_name = "__post_init"]
69-
unsafe fn post_init() {
70-
// RTC domain must be enabled before we try to disable
71-
let mut rtc = Rtc::new(LPWR::steal());
72-
rtc.swd.disable();
73-
rtc.rwdt.disable();
74-
75-
Wdt::<TIMG0, crate::Blocking>::set_wdt_enabled(false);
76-
Wdt::<TIMG1, crate::Blocking>::set_wdt_enabled(false);
77-
}

esp-hal/src/soc/esp32h2/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
//! * I2S_DEFAULT_CLK_SRC: 1 - I2S clock source
1111
//! * I2S_SCLK: 96_000_000 - I2S clock frequency
1212
13-
use self::peripherals::{LPWR, TIMG0, TIMG1};
14-
use crate::{rtc_cntl::Rtc, timer::timg::Wdt};
15-
1613
pub mod efuse;
1714
pub mod gpio;
1815
pub mod peripherals;
@@ -64,14 +61,3 @@ pub(crate) mod constants {
6461
/// RC FAST Clock value (Hertz).
6562
pub const RC_FAST_CLK: fugit::HertzU32 = fugit::HertzU32::kHz(17500);
6663
}
67-
68-
#[export_name = "__post_init"]
69-
unsafe fn post_init() {
70-
// RTC domain must be enabled before we try to disable
71-
let mut rtc = Rtc::new(LPWR::steal());
72-
rtc.swd.disable();
73-
rtc.rwdt.disable();
74-
75-
Wdt::<TIMG0, crate::Blocking>::set_wdt_enabled(false);
76-
Wdt::<TIMG1, crate::Blocking>::set_wdt_enabled(false);
77-
}

0 commit comments

Comments
 (0)