Merge pull request #303 from xoviat/low-power

add stop mode rcc data
This commit is contained in:
xoviat 2023-11-05 22:29:38 +00:00 committed by GitHub
commit 04d773b7b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 1 deletions

View File

@ -6,7 +6,7 @@ use std::hash::Hash;
use anyhow::{anyhow, Ok};
use chiptool::ir::{BlockItemInner, Enum};
use stm32_data_serde::chip::core::peripheral;
use stm32_data_serde::chip::core::peripheral::rcc::Mux;
use stm32_data_serde::chip::core::peripheral::rcc::{Mux, StopMode};
use crate::regex;
use crate::registers::Registers;
@ -245,6 +245,13 @@ impl PeripheralToClock {
for field in &body.fields {
if let Some(peri) = field.name.strip_suffix("EN") {
let peri = if peri == "RTCAPB" { "RTC" } else { peri };
let stop_mode = if peri == "RTC" {
StopMode::Standby
} else if peri.starts_with("LP") {
StopMode::Stop2
} else {
StopMode::Stop1
};
// Timers are a bit special, they may have a x2 freq
let peri_clock = {
@ -280,6 +287,7 @@ impl PeripheralToClock {
register: reg.to_ascii_lowercase(),
field: field.name.to_ascii_lowercase(),
},
stop_mode,
reset,
mux,
});

View File

@ -10,6 +10,10 @@ macro_rules! regex {
}};
}
fn is_default<T: Default + PartialEq>(variant: &T) -> bool {
*variant == T::default()
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Chip {
pub name: String,
@ -116,6 +120,8 @@ pub mod chip {
pub reset: Option<rcc::Reset>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mux: Option<rcc::Mux>,
#[serde(default, skip_serializing_if = "crate::is_default")]
pub stop_mode: rcc::StopMode,
}
pub mod rcc {
@ -138,6 +144,14 @@ pub mod chip {
pub register: String,
pub field: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize, Default)]
pub enum StopMode {
#[default]
Stop1, // Peripheral prevents chip from entering Stop1
Stop2, // Peripheral prevents chip from entering Stop2
Standby, // Peripheral does not prevent chip from entering Stop
}
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]

View File

@ -182,6 +182,7 @@ pub struct PeripheralRcc {
pub enable: Option<PeripheralRccRegister>,
pub reset: Option<PeripheralRccRegister>,
pub mux: Option<PeripheralRccRegister>,
pub stop_mode: StopMode,
}
#[derive(Debug, Eq, PartialEq, Clone)]
@ -190,6 +191,14 @@ pub struct PeripheralRccRegister {
pub field: &'static str,
}
#[derive(Debug, Eq, PartialEq, Clone, Default)]
pub enum StopMode {
#[default]
Stop1, // Peripheral prevents chip from entering Stop1
Stop2, // Peripheral prevents chip from entering Stop2
Standby, // Peripheral does not prevent chip from entering Stop
}
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct PeripheralPin {
pub pin: &'static str,

View File

@ -325,6 +325,8 @@ pub struct PeripheralRcc {
pub reset: Option<PeripheralRccRegister>,
#[serde(default)]
pub mux: Option<PeripheralRccRegister>,
#[serde(default)]
pub stop_mode: StopMode,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
@ -333,6 +335,14 @@ pub struct PeripheralRccRegister {
pub field: String,
}
#[derive(EnumDebug, Eq, PartialEq, Clone, Deserialize, Default)]
pub enum StopMode {
#[default]
Stop1, // Peripheral prevents chip from entering Stop1
Stop2, // Peripheral prevents chip from entering Stop2
Standby, // Peripheral does not prevent chip from entering Stop
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
pub struct PeripheralPin {
pub pin: String,