use portable_atomic::{AtomicU8, Ordering};
pub use self::soc::*;
#[cfg_attr(esp32, path = "esp32/mod.rs")]
#[cfg_attr(esp32c2, path = "esp32c2/mod.rs")]
#[cfg_attr(esp32c3, path = "esp32c3/mod.rs")]
#[cfg_attr(esp32c6, path = "esp32c6/mod.rs")]
#[cfg_attr(esp32h2, path = "esp32h2/mod.rs")]
#[cfg_attr(esp32s2, path = "esp32s2/mod.rs")]
#[cfg_attr(esp32s3, path = "esp32s3/mod.rs")]
mod soc;
mod efuse_field;
static MAC_OVERRIDE_STATE: AtomicU8 = AtomicU8::new(0);
static mut MAC_OVERRIDE: [u8; 6] = [0; 6];
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum SetMacError {
AlreadySet,
}
impl soc::efuse::Efuse {
pub fn set_mac_address(mac: [u8; 6]) -> Result<(), SetMacError> {
if MAC_OVERRIDE_STATE
.compare_exchange(0, 1, Ordering::Relaxed, Ordering::Relaxed)
.is_err()
{
return Err(SetMacError::AlreadySet);
}
unsafe {
MAC_OVERRIDE = mac;
}
MAC_OVERRIDE_STATE.store(2, Ordering::Relaxed);
Ok(())
}
pub fn get_mac_address() -> [u8; 6] {
if MAC_OVERRIDE_STATE.load(Ordering::Relaxed) == 2 {
unsafe { MAC_OVERRIDE }
} else {
Self::read_base_mac_address()
}
}
}
pub fn is_valid_ram_address(address: u32) -> bool {
if (soc::constants::SOC_DRAM_LOW..=soc::constants::SOC_DRAM_HIGH).contains(&address) {
true
} else {
false
}
}