sdmmc-core 0.5.0

SD/MMC core data structures and algorithms
Documentation
use crate::lib_bitfield;

use super::{ExtCsd, ExtCsdIndex};

lib_bitfield! {
    /// Represents the `SECURE_WP_INFO` field of the [ExtCsd] register.
    SecureWpInfo: u8,
    mask: 0x3,
    default: 0,
    {
        /// Indicates if `Secure Write Protection` is enabled.
        secure_wp_en_status: 1;
        /// Indicates support for `Secure Write Protection`.
        secure_wp_support: 0;
    }
}

impl ExtCsd {
    /// Gets the `SECURE_WP_INFO` field of the [ExtCsd] register.
    pub const fn secure_wp_info(&self) -> SecureWpInfo {
        SecureWpInfo::from_inner(self.0[ExtCsdIndex::SecureWpInfo.into_inner()])
    }

    /// Sets the `SECURE_WP_INFO` field of the [ExtCsd] register.
    pub(crate) fn set_secure_wp_info(&mut self, val: SecureWpInfo) {
        self.0[ExtCsdIndex::SecureWpInfo.into_inner()] = val.into_inner();
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_secure_wp_info() {
        let mut ext_csd = ExtCsd::new();

        assert_eq!(ext_csd.secure_wp_info(), SecureWpInfo::new());

        (0..=u8::MAX)
            .map(SecureWpInfo::from_inner)
            .for_each(|info| {
                ext_csd.set_secure_wp_info(info);
                assert_eq!(ext_csd.secure_wp_info(), info);
            });
    }
}