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
use super::chip::Chip;
use super::flash_algorithm::RawFlashAlgorithm;
use crate::config::TargetParseError;
use jep106::JEP106Code;
use std::borrow::Cow;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChipFamily {
pub name: Cow<'static, str>,
pub manufacturer: Option<JEP106Code>,
pub variants: Cow<'static, [Chip]>,
pub flash_algorithms: Cow<'static, [RawFlashAlgorithm]>,
pub core: Cow<'static, str>,
}
impl ChipFamily {
pub fn from_yaml_reader<R: std::io::Read>(
definition_reader: R,
) -> Result<Self, TargetParseError> {
serde_yaml::from_reader(definition_reader)
}
pub fn variants(&self) -> &[Chip] {
&self.variants
}
pub fn algorithms(&self) -> &[RawFlashAlgorithm] {
&self.flash_algorithms
}
pub fn get_algorithm(&self, name: impl AsRef<str>) -> Option<&RawFlashAlgorithm> {
let name = name.as_ref();
self.flash_algorithms.iter().find(|elem| elem.name == name)
}
}