embedded_interfaces/registers/spi/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: core::fmt::Debug> {
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),
18    sync(feature = "sync"),
19    async(feature = "async"),
20    keep_self
21)]
22impl<E: core::fmt::Debug> crate::registers::spi::Codec for UnsupportedCodec<E> {
23    #[inline]
24    async fn read_register<R, I>(_interface: &mut I) -> Result<R, TransportError<Self::Error, I::Error>>
25    where
26        R: Register<CodecError = Self::Error> + ReadableRegister,
27        I: hal::spi::r#SpiDevice,
28    {
29        Err(TransportError::Unexpected("unsupported interface"))
30    }
31
32    #[inline]
33    async fn write_register<R, I>(
34        _interface: &mut I,
35        _register: impl AsRef<R>,
36    ) -> Result<(), TransportError<Self::Error, I::Error>>
37    where
38        R: Register<CodecError = Self::Error> + WritableRegister,
39        I: hal::spi::r#SpiDevice,
40    {
41        Err(TransportError::Unexpected("unsupported interface"))
42    }
43}