sdmmc-core 0.5.0

SD/MMC core data structures and algorithms
Documentation
use crate::lib_bitfield;
use crate::result::{Error, Result};

use super::{ExtCsd, ExtCsdIndex};

lib_bitfield! {
    /// Represents the `PARTITION_SETTING_COMPLETED` field of the [ExtCsd] register.
    PartitionSetting: u8,
    mask: 0x1,
    default: 0,
    {
        ///  Indicates whether parameter definition has completed.
        completed: 0;
    }
}

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

    /// Sets the `PARTITION_SETTING_COMPLETED` field of the [ExtCsd] register.
    pub fn set_partition_setting_completed(&mut self, val: PartitionSetting) {
        self.0[ExtCsdIndex::PartitionSettingCompleted.into_inner()] = val.into_inner();
    }
}

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

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

        assert_eq!(
            ext_csd.partition_setting_completed(),
            PartitionSetting::new()
        );

        (0..=u8::MAX)
            .map(PartitionSetting::from_inner)
            .for_each(|setting| {
                ext_csd.set_partition_setting_completed(setting);
                assert_eq!(ext_csd.partition_setting_completed(), setting);
            });
    }
}