sdmmc_core/command.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
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),
}
}