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 `FFU_FEATURES` field of the [ExtCsd] register.
    FfuFeatures: u8,
    mask: 0x1,
    default: 0,
    {
        /// Indicates support for the `MODE_OPERATION_CODES` field.
        supported_mode_operation_codes: 0;
    }
}

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

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

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

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

        assert_eq!(ext_csd.ffu_features(), FfuFeatures::new());

        (0..u8::MAX)
            .map(FfuFeatures::from_inner)
            .for_each(|feature| {
                ext_csd.set_ffu_features(feature);
                assert_eq!(ext_csd.ffu_features(), feature);
            });
    }
}