sdmmc-core 0.5.0

SD/MMC core data structures and algorithms
Documentation
use crate::lib_bitfield;
use crate::result::Result;

use super::{ExtCsd, ExtCsdIndex};

mod rst_n;

pub use rst_n::*;

lib_bitfield! {
    /// Represents the `RST_n_FUNCTION` field of the [ExtCsd] register.
    ResetnFunction: u8,
    mask: 0x3,
    default: 0,
    {
        /// Indicates the configuration of the `RST_n` signal.
        rst_n_enable: ResetnEnable, 1, 0;
    }
}

impl ExtCsd {
    /// Gets the `RST_n_FUNCTION` field of the [ExtCsd] register.
    pub const fn rst_n_function(&self) -> Result<ResetnFunction> {
        ResetnFunction::try_from_inner(self.0[ExtCsdIndex::RstnFunction.into_inner()])
    }

    /// Sets the `RST_n_FUNCTION` field of the [ExtCsd] register.
    pub fn set_rst_n_function(&mut self, val: ResetnFunction) {
        self.0[ExtCsdIndex::RstnFunction.into_inner()] = val.into_inner();
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_rst_n_function() {
        let mut ext_csd = ExtCsd::new();
        let mut rst_n_fn = ResetnFunction::new();

        assert_eq!(ext_csd.rst_n_function(), Ok(rst_n_fn));

        [
            ResetnEnable::TempDisable,
            ResetnEnable::PermEnable,
            ResetnEnable::PermDisable,
        ]
        .into_iter()
        .for_each(|rst_n| {
            rst_n_fn.set_rst_n_enable(rst_n);
            assert_eq!(rst_n_fn.rst_n_enable(), Ok(rst_n));

            ext_csd.set_rst_n_function(rst_n_fn);
            assert_eq!(ext_csd.rst_n_function(), Ok(rst_n_fn));
        });
    }
}