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 `S_CMD_SET` field in the `EXT_CSD` register.
    ///
    /// Values
    SupportedCommandSet: u8,
    mask: 0x1f,
    default: 0,
    {
        /// MMCA allocated command set 4 supported.
        mmca4: 4;
        /// MMCA allocated command set 3 supported.
        mmca3: 3;
        /// MMCA allocated command set 2 supported.
        mmca2: 2;
        /// MMCA allocated command set 1 supported.
        mmca1: 1;
        /// Standard MMC command set supported.
        standard_mmc: 0;
    }
}

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

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

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

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

        assert_eq!(ext_csd.s_cmd_set(), SupportedCommandSet::new());

        (0..=u8::MAX)
            .map(SupportedCommandSet::from_inner)
            .for_each(|cmd| {
                ext_csd.set_s_cmd_set(cmd);
                assert_eq!(ext_csd.s_cmd_set(), cmd);
            });
    }
}