embedded_interfaces/registers/i2c/codecs/
unsupported_codec.rs

1use core::marker::PhantomData;
2
3use crate::TransportError;
4use crate::registers::{ReadableRegister, Register, RegisterCodec, WritableRegister};
5
6/// A codec that represents absense of a codec. This is only used as a placeholder in register
7/// definitions to specify that the associated interface is not supported.
8pub struct UnsupportedCodec<E> {
9    _marker: PhantomData<E>,
10}
11
12impl<E: core::fmt::Debug> RegisterCodec for UnsupportedCodec<E> {
13    type Error = E;
14}
15
16#[maybe_async_cfg::maybe(
17    idents(hal(sync = "embedded_hal", async = "embedded_hal_async"), Codec, I2cBoundBus),
18    sync(feature = "sync"),
19    async(feature = "async"),
20    keep_self
21)]
22impl<E: core::fmt::Debug> crate::registers::i2c::Codec for UnsupportedCodec<E> {
23    #[inline]
24    async fn read_register<R, I, A>(
25        _bound_bus: &mut crate::i2c::I2cBoundBus<I, A>,
26    ) -> Result<R, TransportError<Self::Error, I::Error>>
27    where
28        R: Register<CodecError = Self::Error> + ReadableRegister,
29        I: hal::i2c::I2c<A> + hal::i2c::ErrorType,
30        A: hal::i2c::AddressMode + Copy,
31    {
32        Err(TransportError::Unexpected("unsupported interface"))
33    }
34
35    #[inline]
36    async fn write_register<R, I, A>(
37        _bound_bus: &mut crate::i2c::I2cBoundBus<I, A>,
38        _register: impl AsRef<R>,
39    ) -> Result<(), TransportError<Self::Error, I::Error>>
40    where
41        R: Register<CodecError = Self::Error> + WritableRegister,
42        I: hal::i2c::I2c<A> + hal::i2c::ErrorType,
43        A: hal::i2c::AddressMode + Copy,
44    {
45        Err(TransportError::Unexpected("unsupported interface"))
46    }
47}