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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use super::chip::Chip;
use super::flash_algorithm::RawFlashAlgorithm;
use super::memory::MemoryRegion;
use super::registry::TargetIdentifier;
use crate::core::{Architecture, CoreType};
#[derive(Clone)]
pub struct Target {
pub identifier: TargetIdentifier,
pub flash_algorithms: Vec<RawFlashAlgorithm>,
pub core_type: CoreType,
pub memory_map: Vec<MemoryRegion>,
}
impl std::fmt::Debug for Target {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Target {{
identifier: {:?},
flash_algorithms: {:?},
memory_map: {:?},
}}",
self.identifier, self.flash_algorithms, self.memory_map
)
}
}
pub type TargetParseError = serde_yaml::Error;
impl Target {
pub fn new(
chip: &Chip,
flash_algorithms: Vec<RawFlashAlgorithm>,
core_type: CoreType,
) -> Target {
Target {
identifier: TargetIdentifier {
chip_name: chip.name.clone().into_owned(),
},
flash_algorithms,
core_type,
memory_map: chip.memory_map.clone().into_owned(),
}
}
pub fn architecture(&self) -> Architecture {
match &self.core_type {
CoreType::M0 => Architecture::ARM,
CoreType::M3 => Architecture::ARM,
CoreType::M33 => Architecture::ARM,
CoreType::M4 => Architecture::ARM,
CoreType::Riscv => Architecture::RISCV,
CoreType::M7 => Architecture::ARM,
}
}
}
#[derive(Debug, Clone)]
pub enum TargetSelector {
Unspecified(String),
Specified(Target),
Auto,
}
impl<'a> From<&'a str> for TargetSelector {
fn from(value: &'a str) -> Self {
TargetSelector::Unspecified(value.into())
}
}
impl<'a> From<&'a String> for TargetSelector {
fn from(value: &'a String) -> Self {
TargetSelector::Unspecified(value.into())
}
}
impl From<String> for TargetSelector {
fn from(value: String) -> Self {
TargetSelector::Unspecified(value)
}
}
impl From<()> for TargetSelector {
fn from(_value: ()) -> Self {
TargetSelector::Auto
}
}
impl From<Target> for TargetSelector {
fn from(target: Target) -> Self {
TargetSelector::Specified(target)
}
}