mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-04 04:27:34 +00:00
add a routine to initialize the ioconfig from the resource spec
in particular this makes sure the io config masks are extracted.
This commit is contained in:
parent
f0b0c038f2
commit
c38214865f
1 changed files with 18 additions and 0 deletions
|
|
@ -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<IoConfigMode>) -> Result<Self, String> {
|
||||
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)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue