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 time unit for the [Taac](super::TimeAsyncAccessCycles) field.
    AccessTimeUnit: u8 {
        default: Ns1,
        error: Error,
        /// Time unit: 1 nanosecond.
        Ns1 = 0,
        /// Time unit: 10 nanosecond.
        Ns10 = 1,
        /// Time unit: 100 nanosecond.
        Ns100 = 2,
        /// Time unit: 1 microsecond.
        Us1 = 3,
        /// Time unit: 10 microsecond.
        Us10 = 4,
        /// Time unit: 100 microsecond.
        Us100 = 5,
        /// Time unit: 1 millisecond.
        Ms1 = 6,
        /// Time unit: 10 millisecond.
        Ms10 = 7,
    }
}

impl AccessTimeUnit {
    /// Gets the nanosecond value for the [AccessTimeUnit].
    pub const fn ns(&self) -> u32 {
        match self {
            Self::Ns1 => 1,
            Self::Ns10 => 10,
            Self::Ns100 => 100,
            Self::Us1 => 1000,
            Self::Us10 => 10_000,
            Self::Us100 => 100_000,
            Self::Ms1 => 1_000_000,
            Self::Ms10 => 10_000_000,
        }
    }

    /// Attempts to convert a byte array into a [AccessTimeUnit].
    pub const fn try_from_inner(val: u8) -> Result<Self> {
        Self::from_raw(val)
    }

    /// Converts a [AccessTimeUnit] into an byte array.
    pub const fn into_inner(self) -> u8 {
        self.into_raw()
    }
}