sdmmc_core/
command.rs

1//! Command types for the SD/MMC bus protocols.
2
3use crate::command_enum;
4
5mod class;
6mod types;
7
8pub mod null;
9
10pub use class::*;
11pub use types::*;
12
13/// Auxilliary trait for command argument bit values.
14pub trait ArgumentBits {
15    fn bits(self) -> u32;
16}
17
18impl ArgumentBits for u32 {
19    fn bits(self) -> u32 {
20        self
21    }
22}
23
24/// Represents the byte length of command representations.
25pub const CMD_LEN: usize = 6;
26
27command_enum! {
28    /// Generic wrapper around the various SD/MMC command types.
29    ///
30    /// # Example
31    ///
32    /// ```rust
33    /// use sdmmc_core::{Command, class0};
34    ///
35    /// let inner_cmd = class0::cmd0::Cmd0::new();
36    /// let class_cmd = class0::Command::Cmd0(inner_cmd);
37    /// let cmd = Command::Class0(class_cmd);
38    ///
39    /// assert_eq!(class0::Command::try_from(inner_cmd), Ok(class_cmd));
40    /// assert_eq!(class0::Command::try_from(inner_cmd).and_then(Command::try_from), Ok(cmd));
41    /// assert_eq!(Command::try_from(class_cmd), Ok(cmd));
42    ///
43    /// assert_eq!(class0::Command::try_from(cmd), Ok(class_cmd));
44    /// assert_eq!(class0::cmd0::Cmd0::try_from(class_cmd), Ok(inner_cmd));
45    ///
46    /// assert_eq!(cmd.command_index(), class_cmd.command_index());
47    /// assert_eq!(cmd.command_index(), inner_cmd.command_index());
48    ///
49    /// assert_eq!(cmd.command_type(), class_cmd.command_type());
50    /// assert_eq!(cmd.command_type(), inner_cmd.command_type());
51    ///
52    /// assert_eq!(cmd.response_type(), class_cmd.response_type());
53    /// assert_eq!(cmd.response_type(), inner_cmd.response_type());
54    ///
55    /// assert_eq!(cmd.argument(), class_cmd.argument());
56    /// assert_eq!(class_cmd.argument(), inner_cmd.argument().map(|a| a.bits()));
57    ///
58    /// assert_eq!(cmd.crc(), class_cmd.crc());
59    /// assert_eq!(cmd.crc(), inner_cmd.crc());
60    /// ```
61    Command {
62        default: Class0(class0::Command),
63        Class0(class0::Command),
64        Class1(class1::Command),
65        Class2(class2::Command),
66        Class4(class4::Command),
67        Class5(class5::Command),
68        Class6(class6::Command),
69        Class7(class7::Command),
70        Class8(class8::Command),
71        Class9(class9::Command),
72        Class10(class10::Command),
73        Class11(class11::Command),
74    }
75}