Skip to content

Commit 0103362

Browse files
Fix CI. Fix wrong sha mode for esp32
1 parent 61ecc03 commit 0103362

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

esp-hal/src/sha/mod.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
//! ```rust, no_run
3333
#![doc = crate::before_snippet!()]
3434
//! # use esp_hal::sha::Sha;
35-
//! # use esp_hal::sha::ShaMode;
35+
//! # use esp_hal::sha::Sha256;
3636
//! # use core::option::Option::None;
3737
//! # use nb::block;
3838
//! let source_data = "HELLO, ESPRESSIF!".as_bytes();
3939
//! let mut remaining = source_data;
40-
//! let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA256);
40+
//! let mut hasher = Sha256::new(peripherals.SHA);
4141
//! // Short hashes can be created by decreasing the output buffer to the
4242
//! // desired length
4343
//! let mut output = [0u8; 32];
@@ -124,7 +124,8 @@ pub trait Sha<'d, DM: crate::Mode>: core::ops::DerefMut<Target = Context<DM>> {
124124

125125
fn digest_length(&self) -> usize;
126126

127-
/// ESP32 requires that a control register to be written to calculate the final SHA hash.
127+
/// ESP32 requires that a control register to be written to calculate the
128+
/// final SHA hash.
128129
#[cfg(esp32)]
129130
fn load_reg(&self);
130131

@@ -347,8 +348,8 @@ pub trait Sha<'d, DM: crate::Mode>: core::ops::DerefMut<Target = Context<DM>> {
347348
}
348349
}
349350

350-
/// This macro implements the Sha<'a, DM> trait for a specified Sha algorithm and a set of
351-
/// parameters
351+
/// This macro implements the Sha<'a, DM> trait for a specified Sha algorithm
352+
/// and a set of parameters
352353
macro_rules! impl_sha {
353354
($name: ident, $mode_bits: tt, $digest_length: tt, $chunk_length: tt) => {
354355
pub struct $name<'d, DM: crate::Mode>(PeripheralRef<'d, SHA>, Context<DM>);
@@ -404,7 +405,9 @@ macro_rules! impl_sha {
404405
// ESP32 uses different registers for its operation
405406
#[cfg(esp32)]
406407
fn load_reg(&self) {
407-
unsafe { self.0.sha1_load().write(|w| w.bits(1)) };
408+
paste::paste! {
409+
unsafe { self.0.[< $name:lower _load >]().write(|w| w.bits(1)) };
410+
}
408411
}
409412

410413
#[cfg(esp32)]
@@ -416,24 +419,27 @@ macro_rules! impl_sha {
416419

417420
#[cfg(esp32)]
418421
fn process_buffer(&mut self) {
419-
if self.first_run {
420-
self.0.sha1_start().write(|w| unsafe { w.bits(1) });
421-
self.first_run = false;
422-
} else {
423-
self.0.sha1_continue().write(|w| unsafe { w.bits(1) });
422+
paste::paste! {
423+
if self.first_run {
424+
self.0.[< $name:lower _start >]().write(|w| unsafe { w.bits(1) });
425+
self.first_run = false;
426+
} else {
427+
self.0.[< $name:lower _continue >]().write(|w| unsafe { w.bits(1) });
428+
}
424429
}
425430
}
426431
}
427432

428433
/// implement digest traits if digest feature is present.
429-
/// Note: digest has a blanket trait implementation for [digest::Digest] for any element
430-
/// that implements FixedOutput + Default + Update + HashMarker
434+
/// Note: digest has a blanket trait implementation for [digest::Digest] for any
435+
/// element that implements FixedOutput + Default + Update + HashMarker
431436
#[cfg(feature = "digest")]
432437
impl<'d, DM: crate::Mode> digest::HashMarker for $name<'d, DM> {}
433438

434439
#[cfg(feature = "digest")]
435440
impl<'a, DM: crate::Mode> digest::OutputSizeUser for $name<'a, DM> {
436-
// We use paste to append `U` to the digest size to match a const defined in digest
441+
// We use paste to append `U` to the digest size to match a const defined in
442+
// digest
437443
paste::paste! {
438444
type OutputSize = digest::consts::[< U $digest_length >];
439445
}

hil-test/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ embedded-hal-02 = { version = "0.2.7", package = "embedded-hal", features = [
131131
embedded-hal-async = { version = "1.0.0", optional = true }
132132
embedded-hal-nb = { version = "1.0.0", optional = true }
133133
esp-backtrace = { path = "../esp-backtrace", default-features = false, features = ["exception-handler", "panic-handler", "defmt", "semihosting"] }
134-
esp-hal = { path = "../esp-hal", features = ["defmt", "embedded-hal", "embedded-hal-02", "digest"], optional = true }
134+
esp-hal = { path = "../esp-hal", features = ["defmt", "digest", "embedded-hal", "embedded-hal-02"], optional = true }
135135
esp-hal-embassy = { path = "../esp-hal-embassy", optional = true }
136136
portable-atomic = "1.6.0"
137137
static_cell = { version = "2.1.0", features = ["nightly"] }

0 commit comments

Comments
 (0)