46 lines
1.0 KiB
Rust
46 lines
1.0 KiB
Rust
use crate::hardware::mcp23017::Mcp23017;
|
|
use crate::hardware::mct8316a::Mct8316a;
|
|
use anyhow::Result;
|
|
use embedded_hal::pwm::SetDutyCycle;
|
|
use std::fmt::Debug;
|
|
|
|
pub trait Hardware {
|
|
type Mcp23017<'a>: Mcp23017 + Send + Debug
|
|
where
|
|
Self: 'a;
|
|
type Pwm: SetDutyCycle<Error: std::error::Error + Sync + Send> + Sync;
|
|
|
|
fn new_mcp23017_a(&self) -> Result<Self::Mcp23017<'_>>;
|
|
fn new_mcp23017_b(&self) -> Result<Self::Mcp23017<'_>>;
|
|
|
|
fn new_pwm0(&self) -> Result<Self::Pwm>;
|
|
|
|
fn new_mct8316a(&self) -> Result<impl Mct8316a + Sync>;
|
|
|
|
fn get_battery_voltage(&self) -> Result<f64>;
|
|
}
|
|
|
|
#[cfg(feature = "raspi")]
|
|
mod raspi;
|
|
|
|
#[cfg(feature = "raspi")]
|
|
pub fn initialize() -> Result<impl Hardware> {
|
|
raspi::RaspiHardware::new()
|
|
}
|
|
|
|
#[cfg(not(feature = "raspi"))]
|
|
#[allow(unreachable_code)]
|
|
pub fn initialize() -> Result<impl Hardware> {
|
|
Ok(sim::SimHardware::new())
|
|
}
|
|
|
|
pub mod error;
|
|
|
|
pub mod mcp23017;
|
|
#[cfg(feature = "raspi")]
|
|
mod mcp3208;
|
|
pub mod channelization;
|
|
pub mod mct8316a;
|
|
mod sim;
|
|
pub mod pin;
|