embedded_sdmmc/filesystem/
attributes.rs1#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
4#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq)]
5pub struct Attributes(pub(crate) u8);
6
7impl Attributes {
8 pub const READ_ONLY: u8 = 0x01;
10 pub const HIDDEN: u8 = 0x02;
12 pub const SYSTEM: u8 = 0x04;
14 pub const VOLUME: u8 = 0x08;
16 pub const DIRECTORY: u8 = 0x10;
18 pub const ARCHIVE: u8 = 0x20;
21 pub const LFN: u8 = Self::READ_ONLY | Self::HIDDEN | Self::SYSTEM | Self::VOLUME;
24
25 pub(crate) fn create_from_fat(value: u8) -> Attributes {
28 Attributes(value)
29 }
30
31 pub(crate) fn set_archive(&mut self, flag: bool) {
32 let archive = if flag { 0x20 } else { 0x00 };
33 self.0 |= archive;
34 }
35
36 pub fn is_read_only(self) -> bool {
38 (self.0 & Self::READ_ONLY) == Self::READ_ONLY
39 }
40
41 pub fn is_hidden(self) -> bool {
43 (self.0 & Self::HIDDEN) == Self::HIDDEN
44 }
45
46 pub fn is_system(self) -> bool {
48 (self.0 & Self::SYSTEM) == Self::SYSTEM
49 }
50
51 pub fn is_volume(self) -> bool {
53 (self.0 & Self::VOLUME) == Self::VOLUME
54 }
55
56 pub fn is_directory(self) -> bool {
58 (self.0 & Self::DIRECTORY) == Self::DIRECTORY
59 }
60
61 pub fn is_archive(self) -> bool {
63 (self.0 & Self::ARCHIVE) == Self::ARCHIVE
64 }
65
66 pub fn is_lfn(self) -> bool {
68 (self.0 & Self::LFN) == Self::LFN
69 }
70}
71
72impl core::fmt::Debug for Attributes {
73 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
74 let mut output = heapless::String::<7>::new();
76 if self.is_lfn() {
77 output.push_str("LFN").unwrap();
78 } else {
79 if self.is_directory() {
80 output.push_str("D").unwrap();
81 } else {
82 output.push_str("F").unwrap();
83 }
84 if self.is_read_only() {
85 output.push_str("R").unwrap();
86 }
87 if self.is_hidden() {
88 output.push_str("H").unwrap();
89 }
90 if self.is_system() {
91 output.push_str("S").unwrap();
92 }
93 if self.is_volume() {
94 output.push_str("V").unwrap();
95 }
96 if self.is_archive() {
97 output.push_str("A").unwrap();
98 }
99 }
100 f.pad(&output)
101 }
102}
103
104