use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum NxpDir {
Out,
In,
Inout,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpChip {
pub name: String,
pub arch: String,
pub package: String,
pub pac_crate: String,
pub target: String,
pub cpu_hz_max: u32,
#[serde(default)]
pub memory: Vec<NxpMemoryRegion>,
#[serde(default)]
pub cores: Vec<NxpCore>,
#[serde(default)]
pub gpio_ports: Vec<NxpGpioPort>,
pub clock_tree: NxpClockTree,
#[serde(default)]
pub peripherals: IndexMap<String, NxpPeripheral>,
#[serde(default)]
pub iomux: Vec<NxpIomuxPad>,
#[serde(default)]
pub daisy_chain: Vec<NxpDaisyChain>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpCore {
pub name: String,
pub arch: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpMemoryRegion {
pub name: String,
pub base: u32,
pub size: u32,
pub access: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpGpioPort {
pub port: u8,
pub pin_count: u8,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpClockTree {
pub xtal_hz: u32,
#[serde(default)]
pub plls: IndexMap<String, NxpPll>,
pub cpu_hz: u32,
pub ahb_hz: u32,
pub ipg_hz: u32,
#[serde(default)]
pub ccgr_gates: IndexMap<String, NxpCcgrGate>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpPll {
#[serde(default)]
pub base_hz: u64,
pub output_range: Option<(u64, u64)>,
pub configurable: Option<bool>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpCcgrGate {
pub ccgr: u8,
pub field: u8,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpPeripheral {
pub class: String,
pub instance: String,
pub base: u32,
pub irq: Option<u16>,
#[serde(default)]
pub signals: Vec<NxpPeripheralSignal>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpPeripheralSignal {
pub role: String,
pub direction: NxpDir,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpIomuxPad {
pub pad: String,
pub mux_reg: u32,
pub pad_reg: u32,
pub alt0: Option<String>,
pub alt1: Option<String>,
pub alt2: Option<String>,
pub alt3: Option<String>,
pub alt4: Option<String>,
pub alt5: Option<String>,
pub alt6: Option<String>,
pub alt7: Option<String>,
pub gpio_port: Option<u8>,
pub gpio_pin: Option<u8>,
}
impl NxpIomuxPad {
pub fn alt_signal(&self, alt: u8) -> Option<&str> {
match alt {
0 => self.alt0.as_deref(),
1 => self.alt1.as_deref(),
2 => self.alt2.as_deref(),
3 => self.alt3.as_deref(),
4 => self.alt4.as_deref(),
5 => self.alt5.as_deref(),
6 => self.alt6.as_deref(),
7 => self.alt7.as_deref(),
_ => None,
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpDaisyChain {
pub signal: String,
pub select_input_reg: u32,
pub options: Vec<NxpDaisyOption>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpDaisyOption {
pub pad: String,
pub alt: u8,
pub daisy_val: u8,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpBoard {
pub name: String,
pub chip: String,
pub flash_type: Option<String>,
pub flash_mb: Option<u32>,
pub sdram_mb: Option<u32>,
pub console: Option<NxpConsoleConfig>,
#[serde(default)]
pub pins: Vec<NxpPinAssignment>,
#[serde(default)]
pub features: IndexMap<String, String>,
#[serde(default)]
pub i2c_configs: IndexMap<String, NxpI2cConfig>,
#[serde(default)]
pub spi_configs: IndexMap<String, NxpSpiConfig>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpConsoleConfig {
pub peripheral: String,
pub baud: u32,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpPinAssignment {
pub pad: String,
pub signal: String,
pub peripheral: Option<String>,
pub role: Option<String>,
pub alt: u8,
pub direction: NxpDir,
pub label: Option<String>,
pub pull: Option<String>,
pub drive_strength: Option<String>,
pub slew_rate: Option<String>,
pub speed: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpI2cConfig {
pub scl_hz: u32,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpSpiConfig {
pub clk_hz: u32,
#[serde(default)]
pub mode: u8,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpIr {
pub chip: NxpChip,
pub board: NxpBoard,
pub clocks: NxpClocksConfig,
pub pins: Vec<NxpPinAssignment>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NxpClocksConfig {
pub cpu_hz: u32,
pub ahb_hz: u32,
pub ipg_hz: u32,
pub xtal_hz: u32,
}