Skip to content

Commit 9497867

Browse files
authored
Merge pull request #602 from bugadani/set
Add RegexSet
2 parents 169e382 + 1247ccf commit 9497867

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

d.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ param (
66
[string]$peri
77
)
88

9-
$REV="709c1060ac2ec57f6042f2b4eb9cf8c1821a6c57"
9+
$REV="1659e761beb29d3949bd1ec72039c3ce5f6bdf6c"
1010

1111
Switch ($CMD)
1212
{
@@ -40,6 +40,10 @@ Switch ($CMD)
4040

4141
}
4242
}
43+
"gen" {
44+
rm -r -Force build/data -ErrorAction SilentlyContinue
45+
cargo run --release --bin stm32-data-gen
46+
}
4347
default {
4448
echo "unknown command"
4549
}

stm32-data-gen/src/chips.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use gpio_af::pin_sort_key;
55
use perimap::PERIMAP;
66
use regex::Regex;
77
use stm32_data_serde::chip::core::peripheral::Pin;
8-
use util::RegexMap;
8+
use util::{RegexMap, RegexSet};
99

1010
use super::*;
1111
use crate::gpio_af::parse_signal_name;
@@ -210,28 +210,28 @@ pub fn parse_groups() -> Result<(HashMap<String, Chip>, Vec<ChipGroup>), anyhow:
210210
Ok((chips, chip_groups))
211211
}
212212

213-
static NOPELIST: RegexMap<()> = RegexMap::new(&[
213+
static NOPELIST: RegexSet = RegexSet::new(&[
214214
// Not supported, not planned unless someone wants to do it.
215-
("STM32MP.*", ()),
215+
"STM32MP.*",
216216
// TODO, PRs welcome :)
217-
("STM32C0[579].*", ()),
218-
("STM32U3.*", ()),
219-
("STM32N6.*", ()),
220-
("STM32G41[14].*", ()),
221-
("STM32G4.*xZ", ()),
222-
("STM32WBA6.*", ()),
223-
("STM32WB0.*", ()),
224-
("STM32WL3.*", ()),
217+
"STM32C0[579].*",
218+
"STM32U3.*",
219+
"STM32N6.*",
220+
"STM32G41[14].*",
221+
"STM32G4.*xZ",
222+
"STM32WBA6.*",
223+
"STM32WB0.*",
224+
"STM32WL3.*",
225225
// Does not exist in ST website. No datasheet, no RM.
226-
("STM32GBK.*", ()),
227-
("STM32L485.*", ()),
226+
"STM32GBK.*",
227+
"STM32L485.*",
228228
// STM32WxM modules. These are based on a chip that's supported on its own,
229229
// not sure why we want a separate target for it.
230-
("STM32WL5M.*", ()),
231-
("STM32WB1M.*", ()),
232-
("STM32WB3M.*", ()),
233-
("STM32WB5M.*", ()),
234-
("STM32WBA5M.*", ()),
230+
"STM32WL5M.*",
231+
"STM32WB1M.*",
232+
"STM32WB3M.*",
233+
"STM32WB5M.*",
234+
"STM32WBA5M.*",
235235
]);
236236

237237
fn parse_group(
@@ -241,7 +241,7 @@ fn parse_group(
241241
) -> anyhow::Result<()> {
242242
let ff = f.file_name().unwrap().to_string_lossy();
243243

244-
if NOPELIST.get(ff.split('.').next().unwrap()).is_some() {
244+
if NOPELIST.contains(ff.split('.').next().unwrap()) {
245245
return Ok(());
246246
}
247247

stm32-data-gen/src/util.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,19 @@ impl<'a, T> RegexMap<'a, T> {
5656
res
5757
}
5858
}
59+
60+
pub struct RegexSet<'a> {
61+
map: RegexMap<'a, ()>,
62+
}
63+
64+
impl<'a> RegexSet<'a> {
65+
pub const fn new(map: &'a [&'a str]) -> Self {
66+
Self {
67+
map: RegexMap::new(unsafe { std::mem::transmute(map) }),
68+
}
69+
}
70+
71+
pub fn contains(&self, key: &str) -> bool {
72+
self.map.get(key).is_some()
73+
}
74+
}

0 commit comments

Comments
 (0)