1pub mod ap;
8pub mod dp;
9pub mod map;
10pub mod register;
11
12use core::fmt;
13
14use dp::IdCode;
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum Cortex {
19 M0,
21 M3,
23 M4,
25 M33,
27}
28
29impl Cortex {
30 pub const IDCODE_M0: IdCode = IdCode::from_u32(0x0BC12477);
31 pub const IDCODE_M3: IdCode = IdCode::from_u32(0x1BA01477);
32 pub const IDCODE_M4: IdCode = IdCode::from_u32(0x2BA01477);
33 pub const IDCODE_M33: IdCode = IdCode::from_u32(0x4C013477);
34
35 pub fn idcode(&self) -> IdCode {
37 match self {
38 Cortex::M0 => Self::IDCODE_M0,
39 Cortex::M3 => Self::IDCODE_M3,
40 Cortex::M4 => Self::IDCODE_M4,
41 Cortex::M33 => Self::IDCODE_M33,
42 }
43 }
44
45 pub fn as_str(&self) -> &'static str {
47 match self {
48 Cortex::M0 => "Cortex-M0",
49 Cortex::M3 => "Cortex-M3",
50 Cortex::M4 => "Cortex-M4",
51 Cortex::M33 => "Cortex-M33",
52 }
53 }
54
55 pub fn from_idcode(idcode: IdCode) -> Option<Cortex> {
56 match idcode {
57 Self::IDCODE_M0 => Some(Cortex::M0),
58 Self::IDCODE_M3 => Some(Cortex::M3),
59 Self::IDCODE_M4 => Some(Cortex::M4),
60 Self::IDCODE_M33 => Some(Cortex::M33),
61 _ => None,
62 }
63 }
64}
65
66impl fmt::Display for Cortex {
67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 write!(f, "ARM {}", self.as_str())
69 }
70}