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 `PACKED_COMMAND_STATUS` field of the [ExtCsd] register.
    PackedCommandStatus: u8,
    mask: 0x3,
    default: 0,
    {
        /// Indicates if an error occured inside one of the individual packed commands.
        indexed_error: 1;
        /// Indicates if an error occured during a packed command.
        error: 0;
    }
}

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

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

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

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

        assert_eq!(ext_csd.packed_command_status(), PackedCommandStatus::new());

        (0..=u8::MAX)
            .map(PackedCommandStatus::from_inner)
            .for_each(|pcs| {
                ext_csd.set_packed_command_status(pcs);
                assert_eq!(ext_csd.packed_command_status(), pcs);
            });
    }
}