expose pca954x_select api #167

Merged
sb10q merged 4 commits from mwojcik/artiq-zynq:pca954x_select_api into master 2022-03-02 10:52:27 +08:00
2 changed files with 13 additions and 13 deletions
Showing only changes of commit 710d6624a1 - Show all commits

View File

@ -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)?;

View File

@ -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
Outdated
Review

At least the match statement does not need to be in unsafe.

At least the match statement does not need to be in unsafe.
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")
}; };
Outdated
Review

return is not needed I think?

return is not needed I think?
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");
} }