forked from M-Labs/artiq
1
0
Fork 0

firmware: Kasli I2C EEPROM cleanup

This commit is contained in:
Sebastien Bourdeauducq 2020-05-05 21:29:29 +08:00
parent 85e92ae28c
commit ef4e5bc69b
2 changed files with 8 additions and 14 deletions

View File

@ -1,10 +1,5 @@
use i2c; use i2c;
#[cfg(soc_platform = "kasli")]
const I2C_SWITCH0: u8 = 0x70;
#[cfg(soc_platform = "kasli")]
const I2C_SWITCH1: u8 = 0x71;
/// [Hardware manual](http://ww1.microchip.com/downloads/en/DeviceDoc/24AA02E48-24AA025E48-24AA02E64-24AA025E64-Data-Sheet-20002124H.pdf) /// [Hardware manual](http://ww1.microchip.com/downloads/en/DeviceDoc/24AA02E48-24AA025E48-24AA02E64-24AA025E64-Data-Sheet-20002124H.pdf)
pub struct EEPROM { pub struct EEPROM {
busno: u8, busno: u8,
@ -13,7 +8,8 @@ pub struct EEPROM {
} }
impl EEPROM { impl EEPROM {
pub fn kasli1_eeprom() -> Self { #[cfg(all(soc_platform = "kasli", any(hw_rev = "v1.0", hw_rev = "v1.1")))]
pub fn new() -> Self {
EEPROM { EEPROM {
busno: 0, busno: 0,
/// Same port as Si5324 /// Same port as Si5324
@ -22,7 +18,8 @@ impl EEPROM {
} }
} }
pub fn kasli2_eeprom() -> Self { #[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))]
pub fn new() -> Self {
EEPROM { EEPROM {
busno: 0, busno: 0,
/// SHARED I2C bus /// SHARED I2C bus
@ -31,11 +28,11 @@ impl EEPROM {
} }
} }
#[cfg(soc_platform = "kasli")]
fn select(&self) -> Result<(), &'static str> { fn select(&self) -> Result<(), &'static str> {
let mask: u16 = 1 << self.port; let mask: u16 = 1 << self.port;
i2c::pca9548_select(self.busno, I2C_SWITCH0, mask as u8)?; i2c::pca9548_select(self.busno, 0x70, mask as u8)?;
i2c::pca9548_select(self.busno, I2C_SWITCH1, (mask >> 8) as u8)?; i2c::pca9548_select(self.busno, 0x71, (mask >> 8) as u8)?;
Ok(()) Ok(())
} }

View File

@ -33,10 +33,7 @@ pub fn get_adresses() -> NetAddresses {
_ => { _ => {
#[cfg(soc_platform = "kasli")] #[cfg(soc_platform = "kasli")]
{ {
#[cfg(any(hw_rev = "v1.0", hw_rev = "v1.1"))] let eeprom = i2c_eeprom::EEPROM::new();
let eeprom = i2c_eeprom::EEPROM::kasli1_eeprom();
#[cfg(hw_rev = "v2.0")]
let eeprom = i2c_eeprom::EEPROM::kasli2_eeprom();
hardware_addr = hardware_addr =
eeprom.read_eui48() eeprom.read_eui48()
.map(|addr_buf| EthernetAddress(addr_buf)) .map(|addr_buf| EthernetAddress(addr_buf))