use heterob::{endianness::LeBytesTryInto, Seq};
use super::CapabilityDataError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DebugPort {
pub offset: u16,
pub bar_number: u8,
}
impl TryFrom<&[u8]> for DebugPort {
type Error = CapabilityDataError;
fn try_from(slice: &[u8]) -> Result<Self, Self::Error> {
let Seq { head, .. }: Seq<u16, _> =
slice.le_bytes_try_into().map_err(|_| CapabilityDataError {
name: "Debug port",
size: 2,
})?;
Ok(DebugPort {
offset: head & 0x1fff,
bar_number: (head >> 13) as u8,
})
}
}