adds simulated hardware
This commit is contained in:
51
flight/src/hardware/sim/mcp23017.rs
Normal file
51
flight/src/hardware/sim/mcp23017.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
use std::fmt::{Display, Formatter};
|
||||
use embedded_hal::i2c::{ErrorKind, ErrorType, I2c, Operation, SevenBitAddress};
|
||||
|
||||
pub struct SimMcp23017 {
|
||||
|
||||
}
|
||||
|
||||
impl SimMcp23017 {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ErrorWrapper(anyhow::Error);
|
||||
|
||||
impl embedded_hal::i2c::Error for ErrorWrapper {
|
||||
fn kind(&self) -> ErrorKind {
|
||||
ErrorKind::Other
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ErrorWrapper {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for ErrorWrapper {}
|
||||
|
||||
impl ErrorType for SimMcp23017 {
|
||||
type Error = ErrorWrapper;
|
||||
}
|
||||
|
||||
impl I2c for SimMcp23017 {
|
||||
fn transaction(&mut self, _address: SevenBitAddress, operations: &mut [Operation<'_>]) -> Result<(), Self::Error> {
|
||||
for operation in operations {
|
||||
match operation {
|
||||
Operation::Write(_write_buffer) => {
|
||||
// Ignore incoming write operations
|
||||
}
|
||||
Operation::Read(_read_buffer) => {
|
||||
todo!("SimMcp23017 read")
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user