adds simulated hardware

This commit is contained in:
2025-10-20 20:17:50 -07:00
parent 086ac7f195
commit 2bcb122319
16 changed files with 325 additions and 81 deletions

View 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(())
}
}