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
use crate::lib_bitfield;
use super::{ExtCsd, ExtCsdIndex};
lib_bitfield! {
/// Represents the `USER_WP` field of the [ExtCsd] register.
UserAreaWriteProtection: u8,
mask: 0xdd,
default: 0,
{
/// Indicates whether to permanently disable password protection features.
perm_pswd_dis: 7;
/// Indicates whether to disable the use of `PERM_WRITE_PROTECT` (`CSD[13]`).
cd_perm_wp_dis: 6;
/// Indicates whether to disable permanent write protection.
us_perm_wp_dis: 4;
/// Indicates whether to disable power-on write protection.
us_pwr_wp_dis: 3;
/// Indicates whether to apply permanent write protection.
us_perm_wp_en: 2;
/// Indicates whether to apply power-on write protection.
us_pwr_wp_en: 0;
}
}
impl ExtCsd {
/// Gets the `USER_WP` field of the [ExtCsd] register.
pub const fn user_wp(&self) -> UserAreaWriteProtection {
UserAreaWriteProtection::from_inner(self.0[ExtCsdIndex::UserWp.into_inner()])
}
/// Sets the `USER_WP` field of the [ExtCsd] register.
pub fn set_user_wp(&mut self, val: UserAreaWriteProtection) {
self.0[ExtCsdIndex::UserWp.into_inner()] = val.into_inner();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_user_wp() {
let mut ext_csd = ExtCsd::new();
assert_eq!(ext_csd.user_wp(), UserAreaWriteProtection::new());
(0..=u8::MAX)
.map(UserAreaWriteProtection::from_inner)
.for_each(|user_wp| {
ext_csd.set_user_wp(user_wp);
assert_eq!(ext_csd.user_wp(), user_wp);
});
}
}