i2c: move match outside unsafe, remove return
This commit is contained in:
parent
41355e27f5
commit
710d6624a1
@ -308,7 +308,7 @@ impl Packet {
|
|||||||
writer.write_u8(0x87)?;
|
writer.write_u8(0x87)?;
|
||||||
writer.write_bool(succeeded)?;
|
writer.write_bool(succeeded)?;
|
||||||
},
|
},
|
||||||
Packet::I2cPca954xSelectRequest { destination, busno, address, mask } => {
|
Packet::I2cSwitchSelectRequest { destination, busno, address, mask } => {
|
||||||
writer.write_u8(0x88)?;
|
writer.write_u8(0x88)?;
|
||||||
writer.write_u8(destination)?;
|
writer.write_u8(destination)?;
|
||||||
writer.write_u8(busno)?;
|
writer.write_u8(busno)?;
|
||||||
|
@ -64,7 +64,6 @@ pub extern fn switch_select(busno: i32, address: i32, mask: i32) {
|
|||||||
if busno > 0 {
|
if busno > 0 {
|
||||||
artiq_raise!("I2CError", "I2C bus could not be accessed");
|
artiq_raise!("I2CError", "I2C bus could not be accessed");
|
||||||
}
|
}
|
||||||
unsafe {
|
|
||||||
let ch = match mask { //decode from mainline, PCA9548-centric API
|
let ch = match mask { //decode from mainline, PCA9548-centric API
|
||||||
0x00 => None,
|
0x00 => None,
|
||||||
0x01 => Some(0),
|
0x01 => Some(0),
|
||||||
@ -75,8 +74,9 @@ pub extern fn switch_select(busno: i32, address: i32, mask: i32) {
|
|||||||
0x20 => Some(5),
|
0x20 => Some(5),
|
||||||
0x40 => Some(6),
|
0x40 => Some(6),
|
||||||
0x80 => Some(7),
|
0x80 => Some(7),
|
||||||
_ => { artiq_raise!("I2CError", "switch select supports only one channel"); return }
|
_ => artiq_raise!("I2CError", "switch select supports only one channel")
|
||||||
};
|
};
|
||||||
|
unsafe {
|
||||||
if (&mut I2C_BUS).as_mut().unwrap().pca954x_select(address as u8, ch).is_err() {
|
if (&mut I2C_BUS).as_mut().unwrap().pca954x_select(address as u8, ch).is_err() {
|
||||||
artiq_raise!("I2CError", "switch select failed");
|
artiq_raise!("I2CError", "switch select failed");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user