From c38214865fc5fa55f886d2f35a411da233effd3f Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 28 Feb 2026 23:20:04 +0800 Subject: [PATCH] add a routine to initialize the ioconfig from the resource spec in particular this makes sure the io config masks are extracted. --- libs/bao1x-api/src/bio.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libs/bao1x-api/src/bio.rs b/libs/bao1x-api/src/bio.rs index 74c549f3a..e4c31bd6b 100644 --- a/libs/bao1x-api/src/bio.rs +++ b/libs/bao1x-api/src/bio.rs @@ -18,6 +18,8 @@ use num_traits::ToPrimitive; use xous::MemoryRange; use crate::IoxPort; +#[cfg(feature = "std")] +use crate::bio_resources::ResourceSpec; pub const BIO_SERVER_NAME: &'static str = "_BIO server_"; @@ -401,6 +403,22 @@ impl Default for IoConfig { } } } +#[cfg(feature = "std")] +impl IoConfig { + pub fn from_resource_spec(spec: &ResourceSpec, mode: &Option) -> Result { + let mut mask: u32 = 0; + for &pin in spec.static_pins.iter() { + if pin > 31 { + return Err(format!("Pin {} exceeds maximum bit position of 31", pin)); + } + mask |= 1u32 << pin; + } + let mut ret = IoConfig::default(); + ret.mapped = mask; + ret.mode = mode.unwrap_or(IoConfigMode::Overwrite); + Ok(ret) + } +} #[bitfield(u8)] #[derive(Debug)]