i2c: move match outside unsafe, remove return

pull/167/head
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,19 +64,19 @@ pub extern fn switch_select(busno: i32, address: i32, mask: i32) {
if busno > 0 {
artiq_raise!("I2CError", "I2C bus could not be accessed");
}
let ch = match mask { //decode from mainline, PCA9548-centric API
0x00 => None,
0x01 => Some(0),
0x02 => Some(1),
0x04 => Some(2),
0x08 => Some(3),
0x10 => Some(4),
0x20 => Some(5),
0x40 => Some(6),
0x80 => Some(7),
_ => artiq_raise!("I2CError", "switch select supports only one channel")
};
unsafe {
let ch = match mask { //decode from mainline, PCA9548-centric API
0x00 => None,
0x01 => Some(0),
0x02 => Some(1),
0x04 => Some(2),
0x08 => Some(3),
0x10 => Some(4),
0x20 => Some(5),
0x40 => Some(6),
0x80 => Some(7),
_ => { artiq_raise!("I2CError", "switch select supports only one channel"); return }
};
if (&mut I2C_BUS).as_mut().unwrap().pca954x_select(address as u8, ch).is_err() {
artiq_raise!("I2CError", "switch select failed");
}