sdmmc-core 0.5.0

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

lib_enum! {
    /// Represents the `set_cd` field of the [Argument](super::Argument).
    CardDetect: u8 {
        default: Disable,
        error: Error,
        /// Disconnect the 50KOhm pull-up resistor on pin 1 (CD/DAT3) of the card.
        Disable = 0,
        /// Connect the 50KOhm pull-up resistor on pin 1 (CD/DAT3) of the card.
        Enable = 1,
    }
}

impl CardDetect {
    /// Converts a [`bool`] into a [CardDetect].
    pub const fn from_bool(val: bool) -> Self {
        match val {
            false => Self::Disable,
            true => Self::Enable,
        }
    }

    /// Converts a [CardDetect] into a [`bool`].
    pub const fn into_bool(self) -> bool {
        (self as u8) != 0
    }
}

impl From<bool> for CardDetect {
    fn from(val: bool) -> Self {
        Self::from_bool(val)
    }
}

impl From<CardDetect> for bool {
    fn from(val: CardDetect) -> Self {
        val.into_bool()
    }
}