sdmmc_core/command/class/class0/cmd0/
arg.rs

1use crate::lib_bitfield;
2use crate::result::{Error, Result};
3
4mod fast_boot;
5
6pub use fast_boot::*;
7
8lib_bitfield! {
9    /// Represents the command argument for [Cmd0](super::Cmd0).
10    pub Argument(u32): u32 {
11        raw_fast_boot_mode: 31, 0;
12    }
13}
14
15impl Argument {
16    /// Represents the byte length of the [Argument].
17    pub const LEN: usize = 4;
18    /// Represents the raw default value of the [Argument].
19    pub const DEFAULT: u32 = 0;
20
21    /// Creates a new [Argument].
22    pub const fn new() -> Self {
23        Self(Self::DEFAULT)
24    }
25
26    /// Gets the [FastBootMode] field of the [Argument].
27    pub const fn fast_boot_mode(&self) -> Result<FastBootMode> {
28        FastBootMode::from_raw(self.raw_fast_boot_mode())
29    }
30
31    /// Sets the [FastBootMode] field of the [Argument].
32    pub fn set_fast_boot_mode(&mut self, val: FastBootMode) {
33        self.set_raw_fast_boot_mode(val.into_raw())
34    }
35
36    /// Attempts to convert a [`u32`] into an [Argument].
37    pub const fn try_from_bits(val: u32) -> Result<Self> {
38        match Self(val) {
39            arg if arg.fast_boot_mode().is_err() => Err(Error::invalid_field_variant(
40                "cmd::arg::fast_boot_mode",
41                arg.raw_fast_boot_mode() as usize,
42            )),
43            arg => Ok(arg),
44        }
45    }
46}
47
48impl Default for Argument {
49    fn default() -> Self {
50        Self::new()
51    }
52}