#![cfg_attr(not(any(test, feature = "std")), no_std)]
#[macro_use]
pub(crate) mod fmt;
use thiserror::Error;
device_driver::create_device!(device_name: DrvLowLevel, manifest: "device.yaml");
#[derive(Debug, Error)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DrvError<SpiErr> {
#[error("SPI error")]
Spi(SpiErr),
#[error("SPI frame error detected in response")]
FrameError,
#[error("Feature or specific mode not supported/implemented: {0}")]
NotSupported(&'static str),
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct FaultStatus {
pub fault: bool,
pub gvdd_uv: bool,
pub gvdd_ov: bool,
pub pvdd_uv: bool,
pub otsd: bool,
pub otw: bool,
pub fetha_oc: bool,
pub fetla_oc: bool,
pub fethb_oc: bool,
pub fetlb_oc: bool,
pub fethc_oc: bool,
pub fetlc_oc: bool,
}
impl FaultStatus {
pub fn has_overcurrent(&self) -> bool {
self.fetha_oc
|| self.fetla_oc
|| self.fethb_oc
|| self.fetlb_oc
|| self.fethc_oc
|| self.fetlc_oc
}
pub fn has_thermal(&self) -> bool {
self.otsd || self.otw
}
pub fn has_voltage_fault(&self) -> bool {
self.gvdd_uv || self.gvdd_ov || self.pvdd_uv
}
pub fn is_ok(&self) -> bool {
!self.fault
}
pub fn phase_a_overcurrent(&self) -> bool {
self.fetha_oc || self.fetla_oc
}
pub fn phase_b_overcurrent(&self) -> bool {
self.fethb_oc || self.fetlb_oc
}
pub fn phase_c_overcurrent(&self) -> bool {
self.fethc_oc || self.fetlc_oc
}
}
pub struct DrvInterface<SpiBus> {
spi_bus: SpiBus,
}
impl<SpiBus> DrvInterface<SpiBus> {
pub fn new(spi_bus: SpiBus) -> Self {
Self { spi_bus }
}
}
#[path = "."]
mod asynchronous {
use bisync::asynchronous::*;
use device_driver::AsyncRegisterInterface as RegisterInterface;
use embedded_hal_async::spi::SpiDevice;
mod driver;
pub use driver::*;
}
pub use asynchronous::Drv8301 as Drv8301Async;
#[path = "."]
mod blocking {
use bisync::synchronous::*;
use device_driver::RegisterInterface;
use embedded_hal::spi::SpiDevice;
#[allow(clippy::duplicate_mod)]
mod driver;
pub use driver::*;
}
pub use blocking::Drv8301;