embedded_registers/spi/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/// to be performed through the default codec of the device.
14pub struct NoCodec {}
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 crate::spi::Codec for NoCodec {
23    #[inline]
24    async fn read_register<R, I>(_interface: &mut I) -> Result<R, I::Error>
25    where
26        R: ReadableRegister,
27        I: hal::spi::r#SpiDevice,
28    {
29        panic!("spi::codecs::NoCodec cannot be used at runtime! Please specify a real codec to access this register.");
30    }
31
32    #[inline]
33    async fn write_register<R, I>(_interface: &mut I, _register: impl AsRef<R>) -> Result<(), I::Error>
34    where
35        R: WritableRegister,
36        I: hal::spi::r#SpiDevice,
37    {
38        panic!("spi::codecs::NoCodec cannot be used at runtime! Please specify a real codec to access this register.");
39    }
40}