sdmmc-core 0.5.0

SD/MMC core data structures and algorithms
Documentation
//! Command types for the SD/MMC bus protocols.

use crate::command_enum;

mod class;
mod types;

pub mod null;

pub use class::*;
pub use types::*;

/// Auxilliary trait for command argument bit values.
pub trait ArgumentBits {
    fn bits(self) -> u32;
}

impl ArgumentBits for u32 {
    fn bits(self) -> u32 {
        self
    }
}

/// Represents the byte length of command representations.
pub const CMD_LEN: usize = 6;

command_enum! {
    /// Generic wrapper around the various SD/MMC command types.
    ///
    /// # Example
    ///
    /// ```rust
    /// use sdmmc_core::{Command, class0};
    ///
    /// let inner_cmd = class0::cmd0::Cmd0::new();
    /// let class_cmd = class0::Command::Cmd0(inner_cmd);
    /// let cmd = Command::Class0(class_cmd);
    ///
    /// assert_eq!(class0::Command::try_from(inner_cmd), Ok(class_cmd));
    /// assert_eq!(class0::Command::try_from(inner_cmd).and_then(Command::try_from), Ok(cmd));
    /// assert_eq!(Command::try_from(class_cmd), Ok(cmd));
    ///
    /// assert_eq!(class0::Command::try_from(cmd), Ok(class_cmd));
    /// assert_eq!(class0::cmd0::Cmd0::try_from(class_cmd), Ok(inner_cmd));
    ///
    /// assert_eq!(cmd.command_index(), class_cmd.command_index());
    /// assert_eq!(cmd.command_index(), inner_cmd.command_index());
    ///
    /// assert_eq!(cmd.command_type(), class_cmd.command_type());
    /// assert_eq!(cmd.command_type(), inner_cmd.command_type());
    ///
    /// assert_eq!(cmd.response_type(), class_cmd.response_type());
    /// assert_eq!(cmd.response_type(), inner_cmd.response_type());
    ///
    /// assert_eq!(cmd.argument(), class_cmd.argument());
    /// assert_eq!(class_cmd.argument(), inner_cmd.argument().map(|a| a.bits()));
    ///
    /// assert_eq!(cmd.crc(), class_cmd.crc());
    /// assert_eq!(cmd.crc(), inner_cmd.crc());
    /// ```
    Command {
        default: Class0(class0::Command),
        Class0(class0::Command),
        Class1(class1::Command),
        Class2(class2::Command),
        Class4(class4::Command),
        Class5(class5::Command),
        Class6(class6::Command),
        Class7(class7::Command),
        Class8(class8::Command),
        Class9(class9::Command),
        Class10(class10::Command),
        Class11(class11::Command),
    }
}