pub use crate::soc::{
I2C0_BASE, I2C1_BASE, I2C2_BASE, I2C3_BASE, I2C4_BASE, RTCSYS_I2C_BASE,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum I2cInstance {
I2c0 = 0,
I2c1 = 1,
I2c2 = 2,
I2c3 = 3,
I2c4 = 4,
RtcsysI2c = 5,
}
impl I2cInstance {
pub const fn base_address(&self) -> usize {
match self {
I2cInstance::I2c0 => I2C0_BASE,
I2cInstance::I2c1 => I2C1_BASE,
I2cInstance::I2c2 => I2C2_BASE,
I2cInstance::I2c3 => I2C3_BASE,
I2cInstance::I2c4 => I2C4_BASE,
I2cInstance::RtcsysI2c => RTCSYS_I2C_BASE,
}
}
pub const fn from_index(index: u8) -> Option<Self> {
match index {
0 => Some(I2cInstance::I2c0),
1 => Some(I2cInstance::I2c1),
2 => Some(I2cInstance::I2c2),
3 => Some(I2cInstance::I2c3),
4 => Some(I2cInstance::I2c4),
5 => Some(I2cInstance::RtcsysI2c),
_ => None,
}
}
pub const fn index(&self) -> u8 {
*self as u8
}
pub const fn is_active_domain(&self) -> bool {
!matches!(self, I2cInstance::RtcsysI2c)
}
pub const fn is_rtc_domain(&self) -> bool {
matches!(self, I2cInstance::RtcsysI2c)
}
}
#[derive(Debug, Clone, Copy)]
pub struct I2cClockConfig {
pub ss_scl_hcnt: u16,
pub ss_scl_lcnt: u16,
pub fs_scl_hcnt: u16,
pub fs_scl_lcnt: u16,
pub sda_hold: u16,
pub sda_setup: u8,
pub fs_spklen: u8,
}
impl I2cClockConfig {
pub const CLK_25MHZ: Self = Self {
ss_scl_hcnt: 115,
ss_scl_lcnt: 135,
fs_scl_hcnt: 21,
fs_scl_lcnt: 42,
sda_hold: 1,
sda_setup: 6,
fs_spklen: 2,
};
pub const CLK_100MHZ: Self = Self {
ss_scl_hcnt: 460,
ss_scl_lcnt: 540,
fs_scl_hcnt: 90,
fs_scl_lcnt: 160,
sda_hold: 1,
sda_setup: 25,
fs_spklen: 5,
};
}