aboutsummaryrefslogtreecommitdiff
path: root/stm32-gen-features/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-04-08 03:40:51 +0200
committerDario Nieuwenhuis <[email protected]>2022-04-08 03:43:58 +0200
commit8b757e1aec6a82759c6df190e35a7ebc7d500ca3 (patch)
tree9df7c7de3511382479d13ad9c5cebf15e19a0cb9 /stm32-gen-features/src
parentb40c8342ecff2b7f5881cb1f54607d70b5331ae3 (diff)
Add stm32wlexx support
Diffstat (limited to 'stm32-gen-features/src')
-rw-r--r--stm32-gen-features/src/lib.rs44
1 files changed, 3 insertions, 41 deletions
diff --git a/stm32-gen-features/src/lib.rs b/stm32-gen-features/src/lib.rs
index bef11c2ad..7aaad9da3 100644
--- a/stm32-gen-features/src/lib.rs
+++ b/stm32-gen-features/src/lib.rs
@@ -1,38 +1,11 @@
1//! FIXME discuss about which errors to print and when to panic 1//! FIXME discuss about which errors to print and when to panic
2 2
3use std::{iter::FilterMap, path::Path, slice::Iter}; 3use std::path::Path;
4
5const SUPPORTED_FAMILIES: &[&str] = &[
6 "stm32f0", "stm32f1", "stm32f2", "stm32f3", "stm32f4", "stm32f7", "stm32g0", "stm32g4",
7 "stm32l0", "stm32l1", "stm32l4", "stm32l5", "stm32h7", "stm32u5", "stm32wb", "stm32wl5",
8];
9 4
10const SEPARATOR_START: &str = "# BEGIN GENERATED FEATURES\n"; 5const SEPARATOR_START: &str = "# BEGIN GENERATED FEATURES\n";
11const SEPARATOR_END: &str = "# END GENERATED FEATURES\n"; 6const SEPARATOR_END: &str = "# END GENERATED FEATURES\n";
12const HELP: &str = "# Generated by stm32-gen-features. DO NOT EDIT.\n"; 7const HELP: &str = "# Generated by stm32-gen-features. DO NOT EDIT.\n";
13 8
14/// True if the chip named `name` is supported else false
15fn is_supported(name: &str) -> bool {
16 SUPPORTED_FAMILIES
17 .iter()
18 .any(|family| name.starts_with(family))
19}
20
21type SupportedIter<'a> = FilterMap<
22 Iter<'a, (String, Vec<String>)>,
23 fn(&(String, Vec<String>)) -> Option<(&String, &Vec<String>)>,
24>;
25trait FilterSupported {
26 fn supported(&self) -> SupportedIter;
27}
28impl FilterSupported for &[(String, Vec<String>)] {
29 /// Get a new Vec with only the supported chips
30 fn supported(&self) -> SupportedIter {
31 self.iter()
32 .filter_map(|(name, cores)| is_supported(name).then(|| (name, cores)))
33 }
34}
35
36/// Get the list of all the chips and their supported cores 9/// Get the list of all the chips and their supported cores
37/// 10///
38/// Print errors to `stderr` when something is returned by the glob but is not in the returned 11/// Print errors to `stderr` when something is returned by the glob but is not in the returned
@@ -85,7 +58,7 @@ fn chip_cores(path: &Path) -> Vec<String> {
85/// Panics if a file contains yaml syntax errors or if a value does not have a consistent type 58/// Panics if a file contains yaml syntax errors or if a value does not have a consistent type
86pub fn embassy_stm32_needed_data(names_and_cores: &[(String, Vec<String>)]) -> String { 59pub fn embassy_stm32_needed_data(names_and_cores: &[(String, Vec<String>)]) -> String {
87 let mut result = String::new(); 60 let mut result = String::new();
88 for (chip_name, cores) in names_and_cores.supported() { 61 for (chip_name, cores) in names_and_cores {
89 if cores.len() > 1 { 62 if cores.len() > 1 {
90 for core_name in cores.iter() { 63 for core_name in cores.iter() {
91 result += &format!( 64 result += &format!(
@@ -151,21 +124,10 @@ mod tests {
151 use super::*; 124 use super::*;
152 125
153 #[test] 126 #[test]
154 fn stm32f407vg_is_supported() {
155 assert!(is_supported("stm32f407vg"))
156 }
157
158 #[test]
159 fn abcdef_is_not_supported() {
160 assert!(!is_supported("abcdef"))
161 }
162
163 #[test]
164 #[ignore] 127 #[ignore]
165 fn stm32f407vg_yaml_file_exists_and_is_supported() { 128 fn stm32f407vg_yaml_file_exists() {
166 assert!(chip_names_and_cores() 129 assert!(chip_names_and_cores()
167 .as_slice() 130 .as_slice()
168 .supported()
169 .into_iter() 131 .into_iter()
170 .any(|(name, _)| { name == "stm32f407vg" })) 132 .any(|(name, _)| { name == "stm32f407vg" }))
171 } 133 }