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 `BARRIER_SUPPORT` field of the [ExtCsd] register.
    BarrierSupport: u8,
    mask: 0x1,
    default: 0,
    {
        /// Indicates whether the barrier command is supported.
        support: 0;
    }
}

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

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

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

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

        assert_eq!(ext_csd.barrier_support(), BarrierSupport::new());

        (0..u8::MAX)
            .map(BarrierSupport::from_inner)
            .for_each(|support| {
                ext_csd.set_barrier_support(support);
                assert_eq!(ext_csd.barrier_support(), support);
            });
    }
}