svd-generator 0.1.0

Converts device information from flattened device tree into an SVD description
Documentation
use alloc::string::String;

/// Represents the `compatible` property of a DeviceTree [`Node`].
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Compatible {
    /// Synopsys DesignWare APB I2C peripherals
    DwApbI2c,
    /// Synopsys DesignWare APB UART peripherals
    DwApbUart,
    /// ARM pl022 SSP SPI peripherals
    Pl022SspSpi,
    /// Unknown compatibility string
    Unknown(String),
    /// No compatible property
    None,
}

impl Compatible {
    /// Gets whether this is a known [Compatible] peripheral.
    pub const fn is_known(&self) -> bool {
        !(matches!(self, Self::Unknown(_)) || matches!(self, Self::None))
    }
}

impl From<&str> for Compatible {
    fn from(val: &str) -> Self {
        if val.contains("dw-apb-i2c") || val.contains("designware-i2c") {
            Self::DwApbI2c
        } else if val.contains("dw-apb-uart") {
            Self::DwApbUart
        } else if val.contains("arm,pl022") {
            Self::Pl022SspSpi
        } else if val.is_empty() {
            Self::None
        } else {
            Self::Unknown(val.into())
        }
    }
}

impl From<&device_tree::Node> for Compatible {
    fn from(val: &device_tree::Node) -> Self {
        val.prop_str("compatible").unwrap_or("").into()
    }
}

impl From<device_tree::Node> for Compatible {
    fn from(val: device_tree::Node) -> Self {
        (&val).into()
    }
}