From 3e95df1f640aa761740feaf9eec797acb58dd942 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 11 Feb 2022 13:46:51 +0800 Subject: [PATCH] pca954x_select: api supports no channel enabled --- libboard_zynq/src/i2c/eeprom.rs | 4 ++-- libboard_zynq/src/i2c/mod.rs | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libboard_zynq/src/i2c/eeprom.rs b/libboard_zynq/src/i2c/eeprom.rs index fb90f9c..a90670e 100644 --- a/libboard_zynq/src/i2c/eeprom.rs +++ b/libboard_zynq/src/i2c/eeprom.rs @@ -35,14 +35,14 @@ impl<'a> EEPROM<'a> { #[cfg(feature = "target_zc706")] fn select(&mut self) -> Result<(), &'static str> { - self.i2c.pca954x_select(0b1110100, self.port)?; + self.i2c.pca954x_select(0b1110100, Some(self.port))?; Ok(()) } #[cfg(feature = "target_kasli_soc")] fn select(&mut self) -> Result<(), &'static str> { // tca9548 is compatible with pca9548 - self.i2c.pca954x_select(0b1110001, self.port)?; + self.i2c.pca954x_select(0b1110001, Some(self.port))?; Ok(()) } diff --git a/libboard_zynq/src/i2c/mod.rs b/libboard_zynq/src/i2c/mod.rs index 0e48798..bd43379 100644 --- a/libboard_zynq/src/i2c/mod.rs +++ b/libboard_zynq/src/i2c/mod.rs @@ -301,14 +301,25 @@ impl I2c { Ok(data) } - pub fn pca954x_select(&mut self, address: u8, channel: u8) -> Result<(), &'static str> { + pub fn pca954x_select(&mut self, address: u8, channel: Option) -> Result<(), &'static str> { self.start()?; // PCA9547 supports only one channel at a time // for compatibility, PCA9548 is treated as such too + // channel - Some(x) - # of the channel [0,7], or None for all disabled let setting = match self.pca_type { - I2cMultiplexer::PCA9548 => 1 << channel, + I2cMultiplexer::PCA9548 => { + match channel { + Some(ch) => 1 << ch, + None => 0, + } + }, #[cfg(feature = "target_kasli_soc")] - I2cMultiplexer::PCA9547 => channel | 0x08, + I2cMultiplexer::PCA9547 => { + match channel { + Some(ch) => ch | 0x08, + None => 0, + } + } }; if !self.write(address << 1)? {