sdmmc-core 0.5.0

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

lib_enum! {
    /// Represents the CSD version based on the `Physical Layer Specification Version` and card
    /// capacity.
    CsdStructure: u8 {
        default: V12,
        error: Error,
        /// CSD Version 1.0, Allocated by MMCA
        V10 = 0b00,
        /// CSD Version 1.1, Allocated by MMCA
        V11 = 0b01,
        /// CSD Version 1.2, Defined in Specification Version 4.1-5.1
        V12 = 0b10,
        /// CSD Version coded in the `CSD_STRUCTURE` field of the `EXT_CSD` field.
        Ext = 0b11,
    }
}

impl CsdStructure {
    /// Represents the bitmask for the [CsdStructure].
    pub const MASK: u8 = 0x3;

    /// Converts an inner representation into a [CsdStructure].
    pub const fn from_inner(val: u8) -> Self {
        match val & Self::MASK {
            0 => Self::V10,
            1 => Self::V11,
            2 => Self::V12,
            _ => Self::Ext,
        }
    }

    /// Attempts to convert an inner representation into a [CsdStructure].
    pub const fn try_from_inner(val: u8) -> Result<Self> {
        Self::from_raw(val)
    }

    /// Converts a [CsdStructure] into an inner representation.
    pub const fn into_inner(self) -> u8 {
        self.into_raw()
    }
}