sdmmc_core/command/class/class0/cmd0/
arg.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
use crate::lib_bitfield;
use crate::result::{Error, Result};

mod fast_boot;

pub use fast_boot::*;

lib_bitfield! {
    /// Represents the command argument for [Cmd0](super::Cmd0).
    pub Argument(u32): u32 {
        raw_fast_boot_mode: 31, 0;
    }
}

impl Argument {
    /// Represents the byte length of the [Argument].
    pub const LEN: usize = 4;
    /// Represents the raw default value of the [Argument].
    pub const DEFAULT: u32 = 0;

    /// Creates a new [Argument].
    pub const fn new() -> Self {
        Self(Self::DEFAULT)
    }

    /// Gets the [FastBootMode] field of the [Argument].
    pub const fn fast_boot_mode(&self) -> Result<FastBootMode> {
        FastBootMode::from_raw(self.raw_fast_boot_mode())
    }

    /// Sets the [FastBootMode] field of the [Argument].
    pub fn set_fast_boot_mode(&mut self, val: FastBootMode) {
        self.set_raw_fast_boot_mode(val.into_raw())
    }

    /// Attempts to convert a [`u32`] into an [Argument].
    pub const fn try_from_bits(val: u32) -> Result<Self> {
        match Self(val) {
            arg if arg.fast_boot_mode().is_err() => Err(Error::invalid_field_variant(
                "cmd::arg::fast_boot_mode",
                arg.raw_fast_boot_mode() as usize,
            )),
            arg => Ok(arg),
        }
    }
}

impl Default for Argument {
    fn default() -> Self {
        Self::new()
    }
}