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 `EXT_SUPPORT` field of the [ExtCsd] register.
    ExtSupport: u8,
    mask: 0x3,
    default: 0,
    {
        /// Indicates support for non-persistent mode.
        non_persistent: 1;
        /// Indicates support for system codes.
        system_code: 0;
    }
}

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

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

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

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

        assert_eq!(ext_csd.ext_support(), ExtSupport::new());

        (0..=u8::MAX)
            .map(ExtSupport::from_inner)
            .for_each(|support| {
                ext_csd.set_ext_support(support);
                assert_eq!(ext_csd.ext_support(), support);
            });
    }
}