2021-11-22 02:37:46 +01:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
|
|
pub struct Chip {
|
|
|
|
pub name: String,
|
|
|
|
pub family: String,
|
|
|
|
pub line: String,
|
|
|
|
pub cores: Vec<Core>,
|
2022-02-07 20:40:35 +01:00
|
|
|
pub memory: Vec<MemoryRegion>,
|
2021-11-22 02:37:46 +01:00
|
|
|
pub packages: Vec<Package>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
2022-02-07 20:40:35 +01:00
|
|
|
pub struct MemoryRegion {
|
|
|
|
pub name: String,
|
|
|
|
pub kind: MemoryRegionKind,
|
|
|
|
pub address: u32,
|
|
|
|
pub size: u32,
|
2021-11-22 02:37:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
2022-02-07 20:40:35 +01:00
|
|
|
pub enum MemoryRegionKind {
|
|
|
|
#[serde(rename = "flash")]
|
|
|
|
Flash,
|
|
|
|
#[serde(rename = "ram")]
|
|
|
|
Ram,
|
2021-11-22 02:37:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
|
|
pub struct Core {
|
|
|
|
pub name: String,
|
2022-02-07 02:10:12 +01:00
|
|
|
pub peripherals: Vec<Peripheral>,
|
|
|
|
pub interrupts: Vec<Interrupt>,
|
|
|
|
pub dma_channels: Vec<DmaChannel>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
|
|
pub struct Interrupt {
|
|
|
|
pub name: String,
|
|
|
|
pub number: u32,
|
2021-11-22 02:37:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
|
|
pub struct Package {
|
|
|
|
pub name: String,
|
|
|
|
pub package: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
|
|
pub struct Peripheral {
|
2022-02-07 02:10:12 +01:00
|
|
|
pub name: String,
|
2021-11-22 02:37:46 +01:00
|
|
|
pub address: u64,
|
|
|
|
#[serde(default)]
|
|
|
|
pub block: Option<String>,
|
|
|
|
#[serde(default)]
|
2021-11-29 02:10:06 +01:00
|
|
|
pub rcc: Option<PeripheralRcc>,
|
2021-11-22 02:37:46 +01:00
|
|
|
#[serde(default)]
|
2022-02-07 02:10:12 +01:00
|
|
|
pub pins: Vec<PeripheralPin>,
|
2021-11-22 02:37:46 +01:00
|
|
|
#[serde(default)]
|
2022-02-07 02:10:12 +01:00
|
|
|
pub dma_channels: Vec<PeripheralDmaChannel>,
|
2021-11-22 02:37:46 +01:00
|
|
|
#[serde(default)]
|
2022-02-07 02:10:12 +01:00
|
|
|
pub interrupts: Vec<PeripheralInterrupt>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
|
|
pub struct PeripheralInterrupt {
|
|
|
|
pub signal: String,
|
|
|
|
pub interrupt: String,
|
2021-11-22 02:37:46 +01:00
|
|
|
}
|
|
|
|
|
2021-11-29 02:10:06 +01:00
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
|
|
pub struct PeripheralRcc {
|
|
|
|
pub clock: String,
|
|
|
|
pub registers: PeripheralRccRegisters,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
|
|
pub struct PeripheralRccRegisters {
|
|
|
|
#[serde(default)]
|
|
|
|
pub enable: Option<PeripheralRccRegister>,
|
|
|
|
#[serde(default)]
|
|
|
|
pub reset: Option<PeripheralRccRegister>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
|
|
pub struct PeripheralRccRegister {
|
|
|
|
pub register: String,
|
|
|
|
pub field: String,
|
|
|
|
}
|
|
|
|
|
2021-11-22 02:37:46 +01:00
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
2022-02-07 02:10:12 +01:00
|
|
|
pub struct PeripheralPin {
|
2021-11-22 02:37:46 +01:00
|
|
|
pub pin: String,
|
|
|
|
pub signal: String,
|
|
|
|
pub af: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
|
|
|
pub struct DmaChannel {
|
2022-02-07 02:10:12 +01:00
|
|
|
pub name: String,
|
2021-11-22 02:37:46 +01:00
|
|
|
pub dma: String,
|
|
|
|
pub channel: u32,
|
|
|
|
pub dmamux: Option<String>,
|
|
|
|
pub dmamux_channel: Option<u32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)]
|
|
|
|
pub struct PeripheralDmaChannel {
|
2022-02-07 02:10:12 +01:00
|
|
|
pub signal: String,
|
2021-11-22 02:37:46 +01:00
|
|
|
pub channel: Option<String>,
|
|
|
|
pub dmamux: Option<String>,
|
|
|
|
pub request: Option<u32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct BlockInfo {
|
|
|
|
/// usart_v1/USART -> usart
|
|
|
|
pub module: String,
|
|
|
|
/// usart_v1/USART -> v1
|
|
|
|
pub version: String,
|
|
|
|
/// usart_v1/USART -> USART
|
|
|
|
pub block: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BlockInfo {
|
|
|
|
pub fn parse(s: &str) -> Self {
|
|
|
|
let mut s = s.split('/');
|
|
|
|
let module = s.next().unwrap();
|
|
|
|
let block = s.next().unwrap();
|
|
|
|
assert!(s.next().is_none());
|
|
|
|
let mut s = module.split('_');
|
|
|
|
let module = s.next().unwrap();
|
|
|
|
let version = s.next().unwrap();
|
|
|
|
assert!(s.next().is_none());
|
|
|
|
Self {
|
|
|
|
module: module.to_string(),
|
|
|
|
version: version.to_string(),
|
|
|
|
block: block.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|