use crate::{MaybeBitdumpFormattable, TransportError};
pub mod i2c;
pub mod spi;
pub trait RegisterCodec {
type Error: core::fmt::Debug;
}
pub trait Register: Default + Clone + bytemuck::Pod + MaybeBitdumpFormattable {
const REGISTER_SIZE: usize;
const ADDRESS: u64;
type Unpacked;
type CodecError: core::fmt::Debug;
#[cfg(all(feature = "sync", not(feature = "async")))]
type SpiCodec: spi::CodecSync<Error = Self::CodecError>;
#[cfg(all(not(feature = "sync"), feature = "async"))]
type SpiCodec: spi::CodecAsync<Error = Self::CodecError>;
#[cfg(all(feature = "sync", feature = "async"))]
type SpiCodec: spi::CodecSync<Error = Self::CodecError> + spi::CodecAsync<Error = Self::CodecError>;
#[cfg(all(feature = "sync", not(feature = "async")))]
type I2cCodec: i2c::CodecSync<Error = Self::CodecError>;
#[cfg(all(not(feature = "sync"), feature = "async"))]
type I2cCodec: i2c::CodecAsync<Error = Self::CodecError>;
#[cfg(all(feature = "sync", feature = "async"))]
type I2cCodec: i2c::CodecSync<Error = Self::CodecError> + i2c::CodecAsync<Error = Self::CodecError>;
}
pub trait ReadableRegister: Register {}
pub trait WritableRegister: Register {}
#[maybe_async_cfg::maybe(sync(feature = "sync"), async(feature = "async"))]
#[allow(async_fn_in_trait)]
pub trait RegisterInterface {
type BusError: core::fmt::Debug;
async fn read_register<R>(&mut self) -> Result<R, TransportError<<R as Register>::CodecError, Self::BusError>>
where
R: ReadableRegister;
async fn write_register<R>(
&mut self,
register: impl AsRef<R>,
) -> Result<(), TransportError<<R as Register>::CodecError, Self::BusError>>
where
R: WritableRegister;
}