embedded-interfaces 0.10.3

Traits for common embedded interfaces and procedural macros for effortless definition of registers and commands for embedded device drivers
Documentation
use core::marker::PhantomData;

use crate::TransportError;
use crate::registers::{ReadableRegister, Register, RegisterCodec, WritableRegister};

/// A codec that represents absense of a codec. This is only used as a placeholder in register
/// definitions to specify that the associated interface is not supported.
pub struct UnsupportedCodec<E: core::fmt::Debug> {
    _marker: PhantomData<E>,
}

impl<E: core::fmt::Debug> RegisterCodec for UnsupportedCodec<E> {
    type Error = E;
}

#[maybe_async_cfg::maybe(
    idents(hal(sync = "embedded_hal", async = "embedded_hal_async"), Codec),
    sync(feature = "sync"),
    async(feature = "async"),
    keep_self
)]
impl<E: core::fmt::Debug> crate::registers::spi::Codec for UnsupportedCodec<E> {
    #[inline]
    async fn read_register<R, I>(_interface: &mut I) -> Result<R, TransportError<Self::Error, I::Error>>
    where
        R: Register<CodecError = Self::Error> + ReadableRegister,
        I: hal::spi::r#SpiDevice,
    {
        Err(TransportError::Unexpected("unsupported interface"))
    }

    #[inline]
    async fn write_register<R, I>(
        _interface: &mut I,
        _register: impl AsRef<R>,
    ) -> Result<(), TransportError<Self::Error, I::Error>>
    where
        R: Register<CodecError = Self::Error> + WritableRegister,
        I: hal::spi::r#SpiDevice,
    {
        Err(TransportError::Unexpected("unsupported interface"))
    }
}