microchip_eeprom_25x/
status.rs1use bit_field::BitField;
2
3pub struct Status {
4 pub value: u8
5}
6
7#[allow(dead_code)]
8#[repr(u8)]
9pub enum WriteProtection {
10 None = 0b00,
11 Quarter = 0b01,
12 Half = 0b10,
13 All = 0b11
14}
15
16impl Status {
17 pub fn write_latch_enabled(&self) -> bool {
19 self.value.get_bit(1)
20 }
21
22 pub fn write_in_progress(&self) -> bool {
24 self.value.get_bit(0)
25 }
26
27 pub fn write_protection_level(&self) -> WriteProtection {
29 let val = self.value.get_bits(2..3);
30 match val {
31 0b00 => WriteProtection::None,
32 0b01 => WriteProtection::Quarter,
33 0b10 => WriteProtection::Half,
34 0b11 => WriteProtection::All,
35 _ => WriteProtection::None
36 }
37 }
38
39 pub fn set_write_protection_level(&mut self, protection: WriteProtection) {
41 self.value.set_bits(2..3, protection as u8);
42 }
43
44 pub fn write_protection_enabled(&mut self) -> bool {
47 self.value.get_bit(7)
48 }
49
50 pub fn set_write_protection_enabled(&mut self, enabled: bool) {
52 self.value.set_bit(7, enabled);
53 }
54}