Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
playfulFence committed Jan 3, 2024
1 parent 2e2d67f commit e708731
Show file tree
Hide file tree
Showing 55 changed files with 103 additions and 134 deletions.
2 changes: 1 addition & 1 deletion esp-hal-common/src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ macro_rules! rtc_pins {
}

fn rtcio_pad_hold(&mut self, enable: bool) {
let rtc_ctrl = unsafe { &*crate::peripherals::RTC_CNTL::PTR };
let rtc_ctrl = unsafe { &*crate::peripherals::LPWR::PTR };

#[cfg(esp32)]
rtc_ctrl.hold_force().modify(|_, w| w.$hold().bit(enable));
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/src/otg_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ where

#[cfg(esp32s3)]
{
let rtc = &*peripherals::RTC_CNTL::PTR;
let rtc = &*peripherals::LPWR::PTR;
rtc.usb_conf()
.modify(|_, w| w.sw_hw_usb_phy_sel().set_bit().sw_usb_phy_sel().set_bit());
}
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/src/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//! ```
//! ### Accessing peripherals
//! ```no_run
//! let mut rtc = Rtc::new(peripherals.RTC_CNTL);
//! let mut rtc = Rtc::new(peripherals.LPWR);
//! ```
//! ```no_run
//! let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
Expand Down
56 changes: 26 additions & 30 deletions esp-hal-common/src/rtc_cntl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ pub use self::rtc::SocResetReason;
use crate::clock::XtalClock;
#[cfg(not(esp32))]
use crate::efuse::Efuse;
#[cfg(not(any(esp32c6, esp32h2)))]
use crate::peripherals::{LPWR, TIMG0};
#[cfg(any(esp32c6, esp32h2))]
use crate::peripherals::{LP_TIMER, LP_WDT};
#[cfg(not(any(esp32c6, esp32h2)))]
use crate::peripherals::{RTC_CNTL, TIMG0};
#[cfg(any(esp32, esp32s3, esp32c3))]
use crate::rtc_cntl::sleep::{RtcSleepConfig, WakeSource, WakeTriggers};
use crate::{
Expand All @@ -96,9 +96,9 @@ use crate::{
pub mod sleep;

#[cfg(any(esp32c6, esp32h2))]
type RtcCntl = crate::peripherals::LP_CLKRST;
type LowPowerDomain = crate::peripherals::LPWR;
#[cfg(not(any(esp32c6, esp32h2)))]
type RtcCntl = crate::peripherals::RTC_CNTL;
type LowPowerDomain = crate::peripherals::LPWR;

#[cfg_attr(esp32, path = "rtc/esp32.rs")]
#[cfg_attr(esp32c2, path = "rtc/esp32c2.rs")]
Expand Down Expand Up @@ -194,14 +194,14 @@ pub(crate) enum RtcCalSel {

/// Low-power Management
pub struct Rtc<'d> {
_inner: PeripheralRef<'d, RtcCntl>,
_inner: PeripheralRef<'d, LowPowerDomain>,
pub rwdt: Rwdt,
#[cfg(any(esp32c2, esp32c3, esp32c6, esp32h2, esp32s3))]
pub swd: Swd,
}

impl<'d> Rtc<'d> {
pub fn new(rtc_cntl: impl Peripheral<P = RtcCntl> + 'd) -> Self {
pub fn new(rtc_cntl: impl Peripheral<P = LowPowerDomain> + 'd) -> Self {
rtc::init();
rtc::configure_clock();

Expand All @@ -227,7 +227,7 @@ impl<'d> Rtc<'d> {
/// read the current value of the rtc time registers.
pub fn get_time_raw(&self) -> u64 {
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::ptr() };
let rtc_cntl = unsafe { &*LPWR::ptr() };
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_TIMER::ptr() };

Expand Down Expand Up @@ -346,7 +346,7 @@ impl RtcClock {
/// disabled to reduce power consumption.
#[cfg(not(any(esp32c6, esp32h2)))]
fn enable_8m(clk_8m_en: bool, d256_en: bool) {
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };

if clk_8m_en {
rtc_cntl.clk_conf().modify(|_, w| w.enb_ck8m().clear_bit());
Expand Down Expand Up @@ -376,7 +376,7 @@ impl RtcClock {
/// This is the value stored in RTC register RTC_XTAL_FREQ_REG by the
/// bootloader, as passed to rtc_clk_init function.
pub fn get_xtal_freq() -> XtalClock {
let xtal_freq_reg = unsafe { &*RTC_CNTL::PTR }.store4().read().bits();
let xtal_freq_reg = unsafe { &*LPWR::PTR }.store4().read().bits();

// Values of RTC_XTAL_FREQ_REG and RTC_APB_FREQ_REG are stored as two copies in
// lower and upper 16-bit halves. These are the routines to work with such a
Expand Down Expand Up @@ -405,7 +405,7 @@ impl RtcClock {
/// Get the RTC_SLOW_CLK source
#[cfg(not(any(esp32c6, esp32h2)))]
pub fn get_slow_freq() -> RtcSlowClock {
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
let slow_freq = rtc_cntl.clk_conf().read().ana_clk_rtc_sel().bits();
match slow_freq {
0 => RtcSlowClock::RtcSlowClockRtc,
Expand All @@ -419,7 +419,7 @@ impl RtcClock {
#[cfg(not(any(esp32c6, esp32h2)))]
fn set_slow_freq(slow_freq: RtcSlowClock) {
unsafe {
let rtc_cntl = &*RTC_CNTL::PTR;
let rtc_cntl = &*LPWR::PTR;
rtc_cntl.clk_conf().modify(|_, w| {
w.ana_clk_rtc_sel()
.bits(slow_freq as u8)
Expand Down Expand Up @@ -448,7 +448,7 @@ impl RtcClock {
#[cfg(not(any(esp32c6, esp32h2)))]
fn set_fast_freq(fast_freq: RtcFastClock) {
unsafe {
let rtc_cntl = &*RTC_CNTL::PTR;
let rtc_cntl = &*LPWR::PTR;
rtc_cntl.clk_conf().modify(|_, w| {
w.fast_clk_rtc_sel().bit(match fast_freq {
RtcFastClock::RtcFastClock8m => true,
Expand Down Expand Up @@ -479,7 +479,7 @@ impl RtcClock {
RtcCalSel::RtcCalInternalOsc => RtcCalSel::RtcCalRtcMux,
_ => cal_clk,
};
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
let timg0 = unsafe { &*TIMG0::PTR };

// Enable requested clock (150k clock is always on)
Expand Down Expand Up @@ -656,7 +656,7 @@ impl RtcClock {
// Number of 8M/256 clock cycles to use for XTAL frequency estimation.
const XTAL_FREQ_EST_CYCLES: u32 = 10;

let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
let clk_8m_enabled = rtc_cntl.clk_conf().read().enb_ck8m().bit_is_clear();
let clk_8md256_enabled = rtc_cntl.clk_conf().read().enb_ck8m_div().bit_is_clear();

Expand Down Expand Up @@ -719,7 +719,7 @@ impl Rwdt {

pub fn listen(&mut self) {
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_WDT::PTR };

Expand All @@ -744,7 +744,7 @@ impl Rwdt {

pub fn unlisten(&mut self) {
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_WDT::PTR };

Expand All @@ -771,7 +771,7 @@ impl Rwdt {

pub fn clear_interrupt(&mut self) {
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_WDT::PTR };

Expand All @@ -787,7 +787,7 @@ impl Rwdt {

pub fn is_interrupt_set(&self) -> bool {
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_WDT::PTR };

Expand All @@ -802,7 +802,7 @@ impl Rwdt {

pub fn feed(&mut self) {
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_WDT::PTR };

Expand All @@ -813,7 +813,7 @@ impl Rwdt {

fn set_write_protection(&mut self, enable: bool) {
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_WDT::PTR };

Expand All @@ -824,7 +824,7 @@ impl Rwdt {

fn set_enabled(&mut self, enable: bool) {
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_WDT::PTR };

Expand All @@ -839,7 +839,7 @@ impl Rwdt {

fn set_timeout(&mut self, timeout: MicrosDurationU64) {
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_WDT::PTR };

Expand Down Expand Up @@ -929,7 +929,7 @@ impl Swd {
/// Enable/disable write protection for WDT registers
fn set_write_protection(&mut self, enable: bool) {
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_WDT::PTR };

Expand All @@ -945,7 +945,7 @@ impl Swd {

fn set_enabled(&mut self, enable: bool) {
#[cfg(not(any(esp32c6, esp32h2)))]
let rtc_cntl = unsafe { &*RTC_CNTL::PTR };
let rtc_cntl = unsafe { &*LPWR::PTR };
#[cfg(any(esp32c6, esp32h2))]
let rtc_cntl = unsafe { &*LP_WDT::PTR };

Expand Down Expand Up @@ -986,19 +986,15 @@ pub fn get_wakeup_cause() -> SleepSource {
});
#[cfg(not(any(esp32, esp32c6, esp32h2)))]
let wakeup_cause = WakeupReason::from_bits_retain(unsafe {
(&*RTC_CNTL::PTR)
(&*LPWR::PTR)
.slp_wakeup_cause()
.read()
.wakeup_cause()
.bits()
});
#[cfg(esp32)]
let wakeup_cause = WakeupReason::from_bits_retain(unsafe {
(&*RTC_CNTL::PTR)
.wakeup_state()
.read()
.wakeup_cause()
.bits() as u32
(&*LPWR::PTR).wakeup_state().read().wakeup_cause().bits() as u32
});

if wakeup_cause.contains(WakeupReason::TimerTrigEn) {
Expand Down
10 changes: 5 additions & 5 deletions esp-hal-common/src/rtc_cntl/rtc/esp32h2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use strum::FromRepr;

use crate::{
clock::{clocks_ll::regi2c_write_mask, Clock, XtalClock},
peripherals::{LP_AON, LP_CLKRST, PCR, PMU, TIMG0},
peripherals::{LPWR, LP_AON, PCR, PMU, TIMG0},
};

const I2C_PMU: u8 = 0x6d;
Expand Down Expand Up @@ -306,7 +306,7 @@ impl RtcClock {
fn set_fast_freq(fast_freq: RtcFastClock) {
// components/hal/esp32s2/include/hal/clk_tree_ll.h
unsafe {
let lp_clkrst = &*LP_CLKRST::PTR;
let lp_clkrst = &*LPWR::PTR;
lp_clkrst.lp_clk_conf().modify(|_, w| {
w.fast_clk_sel().bits(match fast_freq {
RtcFastClock::RtcFastClockRcFast => 0b00,
Expand All @@ -319,7 +319,7 @@ impl RtcClock {

fn set_slow_freq(slow_freq: RtcSlowClock) {
unsafe {
let lp_clkrst = &*LP_CLKRST::PTR;
let lp_clkrst = &*LPWR::PTR;

lp_clkrst
.lp_clk_conf()
Expand All @@ -341,7 +341,7 @@ impl RtcClock {

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

let slow_freq = lp_clrst.lp_clk_conf().read().slow_clk_sel().bits();
match slow_freq {
Expand Down Expand Up @@ -382,7 +382,7 @@ impl RtcClock {
};
}

let lp_clkrst = unsafe { &*LP_CLKRST::ptr() };
let lp_clkrst = unsafe { &*LPWR::ptr() };
let pcr = unsafe { &*PCR::ptr() };
let pmu = unsafe { &*PMU::ptr() };

Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/src/soc/esp32/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ crate::peripherals! {
RMT <= RMT,
RNG <= RNG,
RSA <= RSA,
RTC_CNTL <= RTC_CNTL,
LPWR <= RTC_CNTL,
RTC_IO <= RTC_IO,
RTC_I2C <= RTC_I2C,
SDHOST <= SDHOST,
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/src/soc/esp32c2/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ crate::peripherals! {
INTERRUPT_CORE0 <= INTERRUPT_CORE0,
IO_MUX <= IO_MUX,
LEDC <= LEDC,
LPWR <= RTC_CNTL,
RNG <= RNG,
RTC_CNTL <= RTC_CNTL,
SENSITIVE <= SENSITIVE,
SHA <= SHA,
SPI0 <= SPI0,
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/src/soc/esp32c3/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ crate::peripherals! {
INTERRUPT_CORE0 <= INTERRUPT_CORE0,
IO_MUX <= IO_MUX,
LEDC <= LEDC,
LPWR <= RTC_CNTL,
RMT <= RMT,
RNG <= RNG,
RSA <= RSA,
RTC_CNTL <= RTC_CNTL,
SENSITIVE <= SENSITIVE,
SHA <= SHA,
SPI0 <= SPI0,
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/src/soc/esp32c6/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ crate::peripherals! {
INTPRI <= INTPRI,
IO_MUX <= IO_MUX,
LEDC <= LEDC,
LPWR <= LP_CLKRST,
LP_PERI <= LP_PERI,
LP_ANA <= LP_ANA,
LP_AON <= LP_AON,
LP_APM <= LP_APM,
LP_APM0 <= LP_APM0,
LP_CLKRST <= LP_CLKRST,
LP_I2C0 <= LP_I2C0,
LP_I2C_ANA_MST <= LP_I2C_ANA_MST,
LP_IO <= LP_IO,
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/src/soc/esp32h2/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ crate::peripherals! {
INTPRI <= INTPRI,
IO_MUX <= IO_MUX,
LEDC <= LEDC,
LPWR <= LP_CLKRST,
LP_ANA <= LP_ANA,
LP_AON <= LP_AON,
LP_APM <= LP_APM,
LP_CLKRST <= LP_CLKRST,
LP_PERI <= LP_PERI,
LP_TIMER <= LP_TIMER,
LP_WDT <= LP_WDT,
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/src/soc/esp32s2/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ crate::peripherals! {
INTERRUPT_CORE0 <= INTERRUPT_CORE0,
IO_MUX <= IO_MUX,
LEDC <= LEDC,
LPWR <= RTC_CNTL,
PCNT <= PCNT,
PMS <= PMS,
RMT <= RMT,
RNG <= RNG,
RSA <= RSA,
RTC_IO <= RTC_IO,
RTC_CNTL <= RTC_CNTL,
RTC_I2C <= RTC_I2C,
SENS <= SENS,
SHA <= SHA,
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/src/soc/esp32s3/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ crate::peripherals! {
IO_MUX <= IO_MUX,
LCD_CAM <= LCD_CAM,
LEDC <= LEDC,
LPWR <= RTC_CNTL,
PCNT <= PCNT,
PERI_BACKUP <= PERI_BACKUP,
MCPWM0 <= MCPWM0,
MCPWM1 <= MCPWM1,
RMT <= RMT,
RNG <= RNG,
RSA <= RSA,
RTC_CNTL <= RTC_CNTL,
RTC_I2C <= RTC_I2C,
RTC_IO <= RTC_IO,
SENS <= SENS,
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! ## Example
//!
//! ```no_run
//! let mut rtc = Rtc::new(peripherals.RTC_CNTL);
//! let mut rtc = Rtc::new(peripherals.LPWR);
//!
//! // Create timer groups
//! let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
Expand Down
Loading

0 comments on commit e708731

Please sign in to comment.