Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions esp-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ esp32 = { version = "0.40", features = ["critical-section"], optional = true,
esp32c2 = { version = "0.29", features = ["critical-section"], optional = true, git = "https://github.com/esp-rs/esp-pacs", rev = "8d0a072" }
esp32c3 = { version = "0.32", features = ["critical-section"], optional = true, git = "https://github.com/esp-rs/esp-pacs", rev = "8d0a072" }
esp32c5 = { version = "0.2", features = ["critical-section"], optional = true, git = "https://github.com/esp-rs/esp-pacs", rev = "8d0a072" }
esp32c6 = { version = "0.23", features = ["critical-section"], optional = true, git = "https://github.com/esp-rs/esp-pacs", rev = "8d0a072" }
esp32c6 = { version = "0.23", features = ["critical-section"], optional = true, git = "https://github.com/JurajSadel/esp-pacs", branch = "c6-h2-retention-registers" }
esp32c61 = { version = "0.3", features = ["critical-section"], optional = true, git = "https://github.com/esp-rs/esp-pacs", rev = "8d0a072" }
esp32h2 = { version = "0.19", features = ["critical-section"], optional = true, git = "https://github.com/esp-rs/esp-pacs", rev = "8d0a072" }
esp32h2 = { version = "0.19", features = ["critical-section"], optional = true, git = "https://github.com/JurajSadel/esp-pacs", branch = "c6-h2-retention-registers" }
esp32s2 = { version = "0.31", features = ["critical-section"], optional = true, git = "https://github.com/esp-rs/esp-pacs", rev = "8d0a072" }
esp32s3 = { version = "0.35", features = ["critical-section"], optional = true, git = "https://github.com/esp-rs/esp-pacs", rev = "8d0a072" }
esp32s31 = { version = "0.1", features = ["critical-section"], optional = true, git = "https://github.com/esp-rs/esp-pacs", rev = "8d0a072" }
esp32p4 = { version = "0.2", features = ["critical-section"], optional = true, git = "https://github.com/esp-rs/esp-pacs", rev = "8d0a072" }

[target.'cfg(target_arch = "riscv32")'.dependencies]
riscv = { version = "0.16.1" }
riscv = { version = "0.16.1", git = "https://github.com/JurajSadel/riscv.git", branch = "test" }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a bunch of PRs to the riscv upstream - test branch has all PRs changes merged.

esp-riscv-rt = { version = "0.14.0", path = "../esp-riscv-rt", optional = true }

[target.'cfg(target_arch = "xtensa")'.dependencies]
Expand Down
26 changes: 26 additions & 0 deletions esp-hal/src/i2c/master/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ mod low_level;
pub use low_level::{AnyI2c, Instance};
use low_level::{Driver, I2cClockGuard};

#[cfg(sleep_pd_retention)]
#[instability::unstable]
pub use crate::rtc_cntl::retention::I2cRetentionMemory;

const I2C_FIFO_SIZE: usize = property!("i2c_master.fifo_size");
// Chunk writes/reads by this size
const I2C_CHUNK_SIZE: usize = I2C_FIFO_SIZE - 1;
Expand Down Expand Up @@ -680,6 +684,12 @@ pub struct I2c<'d, Dm: DriverMode> {
phantom: PhantomData<Dm>,
guard: PeripheralGuard,
config: DriverConfig,
// Active keeps `TOP` powered; `with_retention_memory` swaps to retained.
#[cfg(sleep_pd_retention)]
power: crate::rtc_cntl::retention::PowerManagement<
'd,
crate::rtc_cntl::retention::I2cRetentionMemory,
>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -736,6 +746,8 @@ impl<'d> I2c<'d, Blocking> {
sda_pin,
scl_pin,
},
#[cfg(sleep_pd_retention)]
power: crate::rtc_cntl::retention::PowerManagement::new(),
};

// Make sure inputs are well-defined.
Expand All @@ -759,6 +771,8 @@ impl<'d> I2c<'d, Blocking> {
phantom: PhantomData,
guard: self.guard,
config: self.config,
#[cfg(sleep_pd_retention)]
power: self.power,
}
}

Expand Down Expand Up @@ -851,6 +865,8 @@ impl<'d> I2c<'d, Async> {
phantom: PhantomData,
guard: self.guard,
config: self.config,
#[cfg(sleep_pd_retention)]
power: self.power,
}
}

Expand Down Expand Up @@ -1038,6 +1054,16 @@ where
self.driver().reset_fsm(*error == Error::Timeout)
}

/// Retain this I2C's config registers in `mem` across a `TOP` power-down in
/// light sleep, dropping the lock that would otherwise keep `TOP` powered.
#[cfg(sleep_pd_retention)]
#[instability::unstable]
pub fn with_retention_memory(mut self, mem: &'d mut I2cRetentionMemory) -> Self {
let base = self.i2c.info().regs() as *const RegisterBlock as usize as u32;
self.power.retain(mem, base);
self
}

#[procmacros::doc_replace]
/// Connect a pin to the I2C SDA signal.
///
Expand Down
Loading
Loading