embedded_interfaces/registers/
mod.rs1use crate::{MaybeBitdumpFormattable, TransportError};
2
3pub mod i2c;
4pub mod spi;
5
6pub trait RegisterCodec {
8 type Error: core::fmt::Debug;
10}
11
12pub trait Register: Default + Clone + bytemuck::Pod + MaybeBitdumpFormattable {
18 const REGISTER_SIZE: usize;
20 const ADDRESS: u64;
22
23 type Unpacked;
25 type CodecError: core::fmt::Debug;
27 #[cfg(all(feature = "sync", not(feature = "async")))]
30 type SpiCodec: spi::CodecSync<Error = Self::CodecError>;
31 #[cfg(all(not(feature = "sync"), feature = "async"))]
32 type SpiCodec: spi::CodecAsync<Error = Self::CodecError>;
33 #[cfg(all(feature = "sync", feature = "async"))]
34 type SpiCodec: spi::CodecSync<Error = Self::CodecError> + spi::CodecAsync<Error = Self::CodecError>;
35 #[cfg(all(feature = "sync", not(feature = "async")))]
38 type I2cCodec: i2c::CodecSync<Error = Self::CodecError>;
39 #[cfg(all(not(feature = "sync"), feature = "async"))]
40 type I2cCodec: i2c::CodecAsync<Error = Self::CodecError>;
41 #[cfg(all(feature = "sync", feature = "async"))]
42 type I2cCodec: i2c::CodecSync<Error = Self::CodecError> + i2c::CodecAsync<Error = Self::CodecError>;
43}
44
45pub trait ReadableRegister: Register {}
47
48pub trait WritableRegister: Register {}
50
51#[maybe_async_cfg::maybe(sync(feature = "sync"), async(feature = "async"))]
54#[allow(async_fn_in_trait)]
55pub trait RegisterInterface {
56 type BusError: core::fmt::Debug;
58
59 async fn read_register<R>(&mut self) -> Result<R, TransportError<<R as Register>::CodecError, Self::BusError>>
61 where
62 R: ReadableRegister;
63
64 async fn write_register<R>(
66 &mut self,
67 register: impl AsRef<R>,
68 ) -> Result<(), TransportError<<R as Register>::CodecError, Self::BusError>>
69 where
70 R: WritableRegister;
71}