sdmmc-core 0.5.0

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

use super::{ExtCsd, ExtCsdIndex};

mod strobe;

pub use strobe::*;

lib_bitfield! {
    /// Represents the `STROBE_SUPPORT` field of the [ExtCsd] register.
    StrobeSupport: u8,
    mask: 0b1,
    default: 0,
    {
        /// Indicates support for `Enhanced Strobe` mode.
        enhanced_strobe_mode: EnhancedStrobe, 0;
    }
}

impl StrobeSupport {
    /// Converts an inner representation into a [StrobeSupport].
    pub const fn from_inner(val: u8) -> Self {
        Self(val & Self::MASK)
    }
}

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

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

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

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

        assert_eq!(ext_csd.strobe_support(), StrobeSupport::new());

        (0..=u8::MAX)
            .map(StrobeSupport::from_inner)
            .for_each(|strobe| {
                ext_csd.set_strobe_support(strobe);
                assert_eq!(ext_csd.strobe_support(), strobe);
            });
    }
}