embedded_registers/i2c/codecs/
no_codec.rs

1use crate::{ReadableRegister, WritableRegister};
2
3/// A codec that represents absense of a codec. This has two main usecases:
4///
5/// Firstly, if this is used as the default codec for a device, it essentially
6/// requires any associated register to explicitly specify a codec. Otherwise
7/// accessing that register via the [`RegisterInterfaceSync`](crate::RegisterInterfaceSync)
8/// or [`RegisterInterfaceAsync`](crate::RegisterInterfaceAsync) trait will cause a panic.
9///
10/// Secondly, specifying this codec as the default for a register will cause
11/// any reads or writes to that register via the [`RegisterInterfaceSync`](crate::RegisterInterfaceSync)
12/// or [`RegisterInterfaceAsync`](crate::RegisterInterfaceAsync) traits to be performed
13/// through the default codec of the device.
14#[derive(Default)]
15pub struct NoCodec {}
16
17#[maybe_async_cfg::maybe(
18    idents(hal(sync = "embedded_hal", async = "embedded_hal_async"), Codec, I2cBoundBus),
19    sync(feature = "sync"),
20    async(feature = "async"),
21    keep_self
22)]
23impl crate::i2c::Codec for NoCodec {
24    #[inline]
25    async fn read_register<R, I, A>(_bound_bus: &mut crate::i2c::I2cBoundBus<I, A>) -> Result<R, I::Error>
26    where
27        R: ReadableRegister,
28        I: hal::i2c::I2c<A> + hal::i2c::ErrorType,
29        A: hal::i2c::AddressMode + Copy,
30    {
31        panic!("i2c::codecs::NoCodec cannot be used at runtime! Please specify a real codec to access this register.");
32    }
33
34    #[inline]
35    async fn write_register<R, I, A>(
36        _bound_bus: &mut crate::i2c::I2cBoundBus<I, A>,
37        _register: impl AsRef<R>,
38    ) -> Result<(), I::Error>
39    where
40        R: WritableRegister,
41        I: hal::i2c::I2c<A> + hal::i2c::ErrorType,
42        A: hal::i2c::AddressMode + Copy,
43    {
44        panic!("i2c::codecs::NoCodec cannot be used at runtime! Please specify a real codec to access this register.");
45    }
46}