usecrate::protocol::START_BYTE; use downcast_rs::{impl_downcast, Downcast}; use std::io; use std::time::{Duration, Instant};
/// Represents the transport by which a target device can be communicated with, /// e.g. SPI, I2C, UART. pubtrait Transport: Downcast { /// Reads data from the target device. fn read(&mutself, buf: &mut [u8], deadline: Instant) -> io::Result<()>;
/// Read the start of a packet. /// /// Performs any polling as necessary. /// /// The default implementation defers to read(). /// /// # Arguments /// /// * `buf` - The packet buffer. Must be 2 as it includes /// the start byte and packet type. fn read_start(&mutself, buf: &mut [u8], deadline: Instant) -> io::Result<()> {
assert_eq!(buf.len(), 2);
self.read(buf, deadline)?;
let start_byte = buf[0]; if start_byte != START_BYTE { return Err(io::Error::new(
io::ErrorKind::Other,
format!("Invalid start byte: 0x{start_byte:X}"),
));
}
Ok(())
}
/// Writes data to the target device. fn write(&mutself, buf: &[u8], deadline: Instant) -> io::Result<()>;
fn set_irq_line(&mutself, line: &gpio_cdev::Line) -> io::Result<()> { let _ = line;
Err(io::Error::new(
io::ErrorKind::Other, "irq line not supported",
))
}
}
impl_downcast!(Transport);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.