sdmmc-core 0.5.0

SD/MMC core data structures and algorithms
Documentation
use super::{ExtCsd, ExtCsdIndex};

impl ExtCsd {
    /// Gets the `PACKED_FAILURE_INDEX` field of the [ExtCsd] register.
    ///
    /// Represents the command index of the last failed command.
    ///
    /// # Note
    ///
    /// Only meaningful if the `INDEXED_ERROR` bit is set in the `PACKED_COMMAND_STATUS` field.
    pub const fn packed_failure_index(&self) -> u8 {
        self.0[ExtCsdIndex::PackedFailureIndex.into_inner()]
    }

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

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

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

        assert_eq!(ext_csd.packed_failure_index(), 0);

        (0..=u8::MAX).for_each(|idx| {
            ext_csd.set_packed_failure_index(idx);
            assert_eq!(ext_csd.packed_failure_index(), idx);
        });
    }
}