#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PciType {
SingleFrame, FirstFrame, ConsecutiveFrame, FlowControl, }
#[derive(Debug, Clone, Copy)]
pub struct PciByte {
pub pci_type: PciType,
pub value: u8, }
impl From<PciByte> for u8 {
fn from(pci_byte: PciByte) -> Self {
match pci_byte.pci_type {
PciType::SingleFrame => pci_byte.value & 0x0F,
PciType::FirstFrame => 0x10 | (pci_byte.value & 0x0F),
PciType::ConsecutiveFrame => 0x20 | (pci_byte.value & 0x0F),
PciType::FlowControl => 0x30 | (pci_byte.value & 0x0F),
}
}
}
impl PciByte {
pub fn new(pci_type: PciType, value: u8) -> Self {
Self { pci_type, value }
}
pub fn get_type(&self) -> PciType {
self.pci_type
}
pub fn get_value(&self) -> u8 {
self.value
}
pub fn as_byte(&self) -> u8 {
match self.pci_type {
PciType::SingleFrame => self.value & 0x0F,
PciType::FirstFrame => 0x10 | (self.value & 0x0F),
PciType::ConsecutiveFrame => 0x20 | (self.value & 0x0F),
PciType::FlowControl => 0x30 | (self.value & 0x0F),
}
}
}