Provide a way for a peripheral to query its clock frequency

Currently this looks up the frequency in the global singleton that must
be initialized by the per-chip RCC implementation. At present, this is
only done for the L0 family of chips.
This commit is contained in:
Ulf Lilleengen
2021-06-11 09:19:02 +02:00
parent 85f172dd93
commit 952f525af5
6 changed files with 44 additions and 28 deletions

View File

@ -287,8 +287,23 @@ pub fn gen(options: Options) {
match (en, rst) {
(Some((enable_reg, enable_field)), Some((reset_reg, reset_field))) => {
let clock = if clock_prefix == "" {
let re = Regex::new("([A-Z]+\\d*).*").unwrap();
if !re.is_match(enable_reg) {
panic!(
"unable to derive clock name from register name {}",
enable_reg
);
} else {
let caps = re.captures(enable_reg).unwrap();
caps.get(1).unwrap().as_str()
}
} else {
clock_prefix
};
peripheral_rcc_table.push(vec![
name.clone(),
clock.to_ascii_lowercase(),
enable_reg.to_ascii_lowercase(),
reset_reg.to_ascii_lowercase(),
format!("set_{}", enable_field.to_ascii_lowercase()),