factbird_common/
lib.rs

1#![no_std]
2
3use core::str::FromStr;
4
5pub mod memory_regions;
6
7#[non_exhaustive]
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)]
9#[cfg_attr(feature = "defmt", derive(defmt::Format))]
10#[repr(u32)]
11pub enum HardwareRevision {
12    RevE = 0,
13    RevE1,
14    V1_0,
15    V1_1,
16}
17
18impl Default for HardwareRevision {
19    fn default() -> Self {
20        Self::RevE1
21    }
22}
23
24impl HardwareRevision {
25    pub fn from_config() -> Self {
26        if cfg!(feature = "V1_1") {
27            Self::V1_1
28        } else {
29            Self::default()
30        }
31    }
32}
33
34impl FromStr for HardwareRevision {
35    type Err = ();
36
37    fn from_str(s: &str) -> Result<Self, Self::Err> {
38        match s {
39            "RevE" => Ok(Self::RevE),
40            "RevE1" => Ok(Self::RevE1),
41            "V1_0" => Ok(Self::V1_0),
42            "V1_1" => Ok(Self::V1_1),
43            _ => Err(()),
44        }
45    }
46}
47
48impl From<u32> for HardwareRevision {
49    fn from(v: u32) -> Self {
50        match v {
51            0 => Self::RevE,
52            1 => Self::RevE1,
53            2 => Self::V1_0,
54            3 => Self::V1_1,
55            _ => Self::default(),
56        }
57    }
58}