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 `BKOPS_SUPPORT` field of the [ExtCsd] register.
    BackgroundOperationsSupport: u8,
    mask: 0x1,
    default: 1,
    {
        /// Indicates if the background operations fields are supported.
        ///
        /// # Note
        ///
        /// The background operations fields include:
        ///
        /// - `BKOPS_STATUS`
        /// - `BKOPS_EN`
        /// - `BKOPS_START`
        /// - `URGENT_BKOPS`
        supported: 0;
    }
}

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

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

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

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

        ext_csd.set_bkops_support(BackgroundOperationsSupport::new());
        assert_eq!(ext_csd.bkops_support(), BackgroundOperationsSupport::new());

        (0..=u8::MAX)
            .map(BackgroundOperationsSupport::from_inner)
            .for_each(|ops| {
                ext_csd.set_bkops_support(ops);
                assert_eq!(ext_csd.bkops_support(), ops);
            });
    }
}