diff --git a/esp-hal-common/src/peripherals/esp32.rs b/esp-hal-common/src/peripherals/esp32.rs index 80eecb42a50..8a2468f42dc 100644 --- a/esp-hal-common/src/peripherals/esp32.rs +++ b/esp-hal-common/src/peripherals/esp32.rs @@ -55,6 +55,7 @@ mod peripherals { I2C0, I2C1, RNG, + SHA, SPI0, SPI1, SPI2, diff --git a/esp-hal-common/src/peripherals/esp32c2.rs b/esp-hal-common/src/peripherals/esp32c2.rs index 3d833a462db..1f175ddce2d 100644 --- a/esp-hal-common/src/peripherals/esp32c2.rs +++ b/esp-hal-common/src/peripherals/esp32c2.rs @@ -36,6 +36,7 @@ mod peripherals { crate::create_peripherals! { I2C0, RNG, + SHA, SPI0, SPI1, SPI2, diff --git a/esp-hal-common/src/peripherals/esp32c3.rs b/esp-hal-common/src/peripherals/esp32c3.rs index 7e904dee5e2..87b6d050bcc 100644 --- a/esp-hal-common/src/peripherals/esp32c3.rs +++ b/esp-hal-common/src/peripherals/esp32c3.rs @@ -47,6 +47,7 @@ mod peripherals { crate::create_peripherals! { I2C0, RNG, + SHA, SPI0, SPI1, SPI2, diff --git a/esp-hal-common/src/peripherals/esp32s2.rs b/esp-hal-common/src/peripherals/esp32s2.rs index e7355b962b3..6eca796bc21 100644 --- a/esp-hal-common/src/peripherals/esp32s2.rs +++ b/esp-hal-common/src/peripherals/esp32s2.rs @@ -53,6 +53,7 @@ mod peripherals { I2C0, I2C1, RNG, + SHA, SPI0, SPI1, SPI2, diff --git a/esp-hal-common/src/peripherals/esp32s3.rs b/esp-hal-common/src/peripherals/esp32s3.rs index 354bf27e739..67fad379513 100644 --- a/esp-hal-common/src/peripherals/esp32s3.rs +++ b/esp-hal-common/src/peripherals/esp32s3.rs @@ -64,6 +64,7 @@ mod peripherals { I2C0, I2C1, RNG, + SHA, SPI0, SPI1, SPI2, diff --git a/esp-hal-common/src/sha.rs b/esp-hal-common/src/sha.rs index 6a5f0cdcf80..46084635e20 100644 --- a/esp-hal-common/src/sha.rs +++ b/esp-hal-common/src/sha.rs @@ -1,6 +1,9 @@ use core::convert::Infallible; -use crate::pac::SHA; +use crate::{ + peripheral::{Peripheral, PeripheralRef}, + peripherals::SHA, +}; // All the hash algorithms introduced in FIPS PUB 180-4 Spec. // – SHA-1 @@ -157,9 +160,8 @@ impl AlignmentHelper { } } -#[derive(Debug)] -pub struct Sha { - sha: SHA, +pub struct Sha<'d> { + sha: PeripheralRef<'d, SHA>, mode: ShaMode, alignment_helper: AlignmentHelper, cursor: usize, @@ -224,8 +226,10 @@ fn mode_as_bits(mode: ShaMode) -> u8 { // This implementation might fail after u32::MAX/8 bytes, to increase please see // ::finish() length/self.cursor usage -impl Sha { - pub fn new(sha: SHA, mode: ShaMode) -> Self { +impl<'d> Sha<'d> { + pub fn new(sha: impl Peripheral

+ 'd, mode: ShaMode) -> Self { + crate::into_ref!(sha); + // Setup SHA Mode #[cfg(not(esp32))] sha.mode @@ -508,8 +512,4 @@ impl Sha { Ok(()) } - - pub fn free(self) -> SHA { - self.sha - } } diff --git a/esp32-hal/examples/sha.rs b/esp32-hal/examples/sha.rs index 474910f156b..92bdbac12a1 100644 --- a/esp32-hal/examples/sha.rs +++ b/esp32-hal/examples/sha.rs @@ -66,7 +66,6 @@ fn main() -> ! { let hw_time = post_calc - pre_calc; println!("Took {} cycles", hw_time); println!("SHA512 Hash output {:02x?}", output); - let _usha = hasher.free(); let pre_calc = xtensa_lx::timer::get_cycle_count(); let mut hasher = Sha512::new(); diff --git a/esp32c2-hal/examples/sha.rs b/esp32c2-hal/examples/sha.rs index 290770886a9..8502930b888 100644 --- a/esp32c2-hal/examples/sha.rs +++ b/esp32c2-hal/examples/sha.rs @@ -65,7 +65,6 @@ fn main() -> ! { // let hw_time = post_calc - pre_calc; // println!("Took {} cycles", hw_time); println!("SHA256 Hash output {:02x?}", output); - let _usha = hasher.free(); // let pre_calc = xtensa_lx::timer::get_cycle_count(); let mut hasher = Sha256::new(); diff --git a/esp32c3-hal/examples/sha.rs b/esp32c3-hal/examples/sha.rs index 88d8e6eddd5..f2f58f756ca 100644 --- a/esp32c3-hal/examples/sha.rs +++ b/esp32c3-hal/examples/sha.rs @@ -65,7 +65,6 @@ fn main() -> ! { // let hw_time = post_calc - pre_calc; // println!("Took {} cycles", hw_time); println!("SHA256 Hash output {:02x?}", output); - let _usha = hasher.free(); // let pre_calc = xtensa_lx::timer::get_cycle_count(); let mut hasher = Sha256::new(); diff --git a/esp32s2-hal/examples/sha.rs b/esp32s2-hal/examples/sha.rs index c9d53c25980..ce1e47ffdf8 100644 --- a/esp32s2-hal/examples/sha.rs +++ b/esp32s2-hal/examples/sha.rs @@ -65,7 +65,6 @@ fn main() -> ! { let hw_time = post_calc - pre_calc; println!("Took {} cycles", hw_time); println!("SHA512 Hash output {:02x?}", output); - let _usha = hasher.free(); let pre_calc = xtensa_lx::timer::get_cycle_count(); let mut hasher = Sha512::new(); diff --git a/esp32s3-hal/examples/sha.rs b/esp32s3-hal/examples/sha.rs index bd81f660e79..a51163c9d50 100644 --- a/esp32s3-hal/examples/sha.rs +++ b/esp32s3-hal/examples/sha.rs @@ -65,7 +65,6 @@ fn main() -> ! { let hw_time = post_calc - pre_calc; println!("Took {} cycles", hw_time); println!("SHA512 Hash output {:02x?}", output); - let _usha = hasher.free(); let pre_calc = xtensa_lx::timer::get_cycle_count(); let mut hasher = Sha512::new();