From 514b27eb18e09cba83785ee3713dd9c109820aeb Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 14 Sep 2025 02:07:14 +0800 Subject: [PATCH] add pio bit setting to api --- libs/cramium-api/src/api.rs | 2 ++ libs/cramium-api/src/iox.rs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/libs/cramium-api/src/api.rs b/libs/cramium-api/src/api.rs index 7d2a073a0..7947be76c 100644 --- a/libs/cramium-api/src/api.rs +++ b/libs/cramium-api/src/api.rs @@ -30,6 +30,8 @@ pub enum HalOpcode { SetGpioBank = 5, /// Return the value of a GPIO bank (blocking scalar) GetGpioBank = 6, + /// Configure BIO + ConfigureBio = 17, /// Configure UDMA clocks & events // blocking scalar diff --git a/libs/cramium-api/src/iox.rs b/libs/cramium-api/src/iox.rs index 5efcf7278..4c1659abb 100644 --- a/libs/cramium-api/src/iox.rs +++ b/libs/cramium-api/src/iox.rs @@ -82,6 +82,7 @@ pub trait IoSetup { slow_slew: Option, strength: Option, ); + fn set_pio_bit_from_port_and_pin(&self, port: IoxPort, pin: u8) -> Option; } /// Traits for accessing GPIOs after the port has been set up. @@ -259,6 +260,28 @@ impl IoSetup for IoxHal { let buf = xous_ipc::Buffer::into_buf(msg).unwrap(); buf.lend(self.conn, HalOpcode::ConfigureIox as u32).expect("Couldn't set up IO"); } + + fn set_pio_bit_from_port_and_pin(&self, port: IoxPort, pin: u8) -> Option { + match xous::send_message( + self.conn, + xous::Message::new_blocking_scalar( + HalOpcode::ConfigureBio.to_usize().unwrap(), + port as usize, + pin as usize, + 0, + 0, + ), + ) { + Ok(xous::Result::Scalar2(code, ok)) => { + if ok != 0 { + Some(code as u8) + } else { + None + } + } + _ => panic!("Internal error setting up BIO"), + } + } } #[cfg(feature = "std")]