From b5de1b5c70b0502f7b7ac9639079e887fa1366c8 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Arcos Date: Fri, 21 Apr 2023 13:07:55 +0200 Subject: [PATCH] Add ESP32- H2 soc/efuse methods (#486) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: ✨ Implement efuse methods * feat: ✨ Add NUM_PINS * doc: Update link to point at specific commit Co-authored-by: Jesse Braham --------- Co-authored-by: Jesse Braham --- esp-hal-common/src/soc/esp32h2/efuse.rs | 34 ++++++++++++++++++++++--- esp-hal-common/src/soc/esp32h2/gpio.rs | 3 ++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/esp-hal-common/src/soc/esp32h2/efuse.rs b/esp-hal-common/src/soc/esp32h2/efuse.rs index 2b53c682faa..4d6450e0e3a 100644 --- a/esp-hal-common/src/soc/esp32h2/efuse.rs +++ b/esp-hal-common/src/soc/esp32h2/efuse.rs @@ -1,3 +1,7 @@ +//! Reading of eFuses + +use crate::peripherals::EFUSE; + pub struct Efuse; impl Efuse { @@ -19,16 +23,40 @@ impl Efuse { /// ); /// ``` pub fn get_mac_address() -> [u8; 6] { - todo!() + let efuse = unsafe { &*EFUSE::ptr() }; + + let mac_low: u32 = efuse.rd_mac_sys_0.read().mac_0().bits(); + let mac_high: u32 = efuse.rd_mac_sys_1.read().mac_1().bits() as u32; + + let mac_low_bytes = mac_low.to_be_bytes(); + let mac_high_bytes = mac_high.to_be_bytes(); + + [ + mac_high_bytes[2], + mac_high_bytes[3], + mac_low_bytes[0], + mac_low_bytes[1], + mac_low_bytes[2], + mac_low_bytes[3], + ] } /// Get status of SPI boot encryption. pub fn get_flash_encryption() -> bool { - todo!() + let efuse = unsafe { &*EFUSE::ptr() }; + (efuse + .rd_repeat_data1 + .read() + .spi_boot_crypt_cnt() + .bits() + .count_ones() + % 2) + != 0 } /// Get the multiplier for the timeout value of the RWDT STAGE 0 register. pub fn get_rwdt_multiplier() -> u8 { - todo!() + let efuse = unsafe { &*EFUSE::ptr() }; + efuse.rd_repeat_data1.read().wdt_delay_sel().bits() } } diff --git a/esp-hal-common/src/soc/esp32h2/gpio.rs b/esp-hal-common/src/soc/esp32h2/gpio.rs index 1328a17bd6e..0a1208fce89 100644 --- a/esp-hal-common/src/soc/esp32h2/gpio.rs +++ b/esp-hal-common/src/soc/esp32h2/gpio.rs @@ -1,6 +1,7 @@ use paste::paste; -pub const NUM_PINS: usize = 0; // FIXME +// https://github.com/espressif/esp-idf/blob/df9310a/components/soc/esp32h2/gpio_periph.c#L42 +pub const NUM_PINS: usize = 27; pub type OutputSignalType = u8; pub const OUTPUT_SIGNAL_MAX: u8 = 0; // FIXME