forked from M-Labs/zynq-rs
pca954x_select: api supports no channel enabled
This commit is contained in:
parent
26ab2927b9
commit
3e95df1f64
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
@ -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<u8>) -> 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)? {
|
||||
|
|
Loading…
Reference in New Issue