Skip to content

Commit

Permalink
Rebase branch, update rtc_cntl implementation, add rtc_time example
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebraham committed May 8, 2023
1 parent ca54d29 commit 5de726f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
10 changes: 5 additions & 5 deletions esp-hal-common/src/rtc_cntl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use fugit::MicrosDurationU64;

pub use self::rtc::SocResetReason;
#[cfg(not(any(esp32c6, esp32h2)))]
use crate::clock::{Clock, XtalClock};
use crate::clock::XtalClock;
#[cfg(not(esp32))]
use crate::efuse::Efuse;
#[cfg(any(esp32c6, esp32h2))]
use crate::peripherals::LP_WDT;
use crate::peripherals::{LP_TIMER, LP_WDT};
#[cfg(not(any(esp32c6, esp32h2)))]
use crate::peripherals::{RTC_CNTL, TIMG0};
use crate::{
Expand Down Expand Up @@ -144,9 +144,9 @@ impl<'d> Rtc<'d> {

/// read the current value of the rtc time registers.
pub fn get_time_raw(&self) -> u64 {
#[cfg(not(esp32c6))]
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::ptr() };
#[cfg(esp32c6)]
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_TIMER::ptr() };

#[cfg(esp32)]
Expand All @@ -169,7 +169,7 @@ impl<'d> Rtc<'d> {
let l = rtc_cntl.time_low0.read().timer_value0_low().bits();
(l, h)
};
#[cfg(esp32c6)]
#[cfg(any(esp32c6, esp32h2))]
let (l, h) = {
rtc_cntl.update.write(|w| w.main_timer_update().set_bit());
let h = rtc_cntl.main_buf0_high.read().main_timer_buf0_high().bits();
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/src/rtc_cntl/rtc/esp32h2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl RtcClock {
}

/// Get the RTC_SLOW_CLK source
fn get_slow_freq() -> RtcSlowClock {
pub(crate) fn get_slow_freq() -> RtcSlowClock {
let lp_clrst = unsafe { &*LP_CLKRST::ptr() };

let slow_freq = lp_clrst.lp_clk_conf.read().slow_clk_sel().bits();
Expand Down
51 changes: 51 additions & 0 deletions esp32h2-hal/examples/rtc_time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//! Prints time in milliseconds from the RTC Timer

#![no_std]
#![no_main]

use esp32h2_hal::{
clock::ClockControl,
peripherals::Peripherals,
prelude::*,
timer::TimerGroup,
Delay,
Rtc,
};
use esp_backtrace as _;

#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let mut system = peripherals.PCR.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

// Disable the watchdog timers. For the ESP32-H2, this includes the Super WDT,
// and the TIMG WDTs.
let mut rtc = Rtc::new(peripherals.LP_CLKRST);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt1 = timer_group1.wdt;

rtc.swd.disable();
rtc.rwdt.disable();
wdt0.disable();
wdt1.disable();

// Initialize the Delay peripheral, and use it to toggle the LED state in a
// loop.
let mut delay = Delay::new(&clocks);

loop {
esp_println::println!("rtc time in milliseconds is {}", rtc.get_time_ms());
delay.delay_ms(1000u32);
}
}

0 comments on commit 5de726f

Please sign in to comment.