sdmmc-core 0.5.0

SD/MMC core data structures and algorithms
Documentation
use crate::result::Result;

/// Represents the `WAKEUP_PERIOD` sub-field of the [PeriodicWakeup](super::PeriodicWakeup) field.
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct WakeupPeriod(u8);

impl WakeupPeriod {
    /// Represents the bitmask of the [WakeupPeriod].
    pub const MASK: u8 = 0x1f;
    /// Represents the default byte value of the [WakeupPeriod].
    pub const DEFAULT: u8 = 0;

    /// Creates a new [WakeupPeriod].
    pub const fn new() -> Self {
        Self(Self::DEFAULT)
    }

    /// Converts an inner representation into a [WakeupPeriod].
    pub const fn from_inner(val: u8) -> Self {
        Self(val & Self::MASK)
    }

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

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

impl Default for WakeupPeriod {
    fn default() -> Self {
        Self::new()
    }
}

impl From<u8> for WakeupPeriod {
    fn from(val: u8) -> Self {
        Self::from_inner(val)
    }
}

impl From<WakeupPeriod> for u8 {
    fn from(val: WakeupPeriod) -> Self {
        val.into_inner()
    }
}