i2c: move match outside unsafe, remove return

This commit is contained in:
spaqin 2022-03-02 10:49:22 +08:00
parent 41355e27f5
commit 710d6624a1
2 changed files with 13 additions and 13 deletions

View File

@ -308,7 +308,7 @@ impl Packet {
writer.write_u8(0x87)?;
writer.write_bool(succeeded)?;
},
Packet::I2cPca954xSelectRequest { destination, busno, address, mask } => {
Packet::I2cSwitchSelectRequest { destination, busno, address, mask } => {
writer.write_u8(0x88)?;
writer.write_u8(destination)?;
writer.write_u8(busno)?;

View File

@ -64,7 +64,6 @@ pub extern fn switch_select(busno: i32, address: i32, mask: i32) {
if busno > 0 {
artiq_raise!("I2CError", "I2C bus could not be accessed");
}
unsafe {
let ch = match mask { //decode from mainline, PCA9548-centric API
0x00 => None,
0x01 => Some(0),
@ -75,8 +74,9 @@ pub extern fn switch_select(busno: i32, address: i32, mask: i32) {
0x20 => Some(5),
0x40 => Some(6),
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() {
artiq_raise!("I2CError", "switch select failed");
}