use crate::svd::create_peripheral;
use crate::Result;
pub mod registers;
pub struct DwApbI2c {
peripheral: svd::Peripheral,
}
impl DwApbI2c {
pub fn create(
name: &str,
base_address: u64,
size: u32,
interrupt: Option<Vec<svd::Interrupt>>,
dim: u32,
) -> Result<Self> {
let dim_element = if dim > 0 {
Some(
svd::DimElement::builder()
.dim(dim)
.dim_increment(size)
.build(svd::ValidateLevel::Strict)?,
)
} else {
None
};
let peripheral = create_peripheral(
name,
format!("Synopsys DesignWare APB UART: {name}").as_str(),
base_address,
size,
interrupt,
Some(registers::create()?),
dim_element,
)?;
Ok(Self { peripheral })
}
pub const fn peripheral(&self) -> &svd::Peripheral {
&self.peripheral
}
pub fn peripheral_mut(&mut self) -> &mut svd::Peripheral {
&mut self.peripheral
}
pub fn to_inner(self) -> svd::Peripheral {
self.peripheral
}
}