device_driver/
lib.rs

1#![allow(async_fn_in_trait)]
2#![cfg_attr(not(test), no_std)]
3#![warn(missing_docs)]
4#![doc = include_str!(concat!("../", env!("CARGO_PKG_README")))]
5
6use core::fmt::{Debug, Display};
7
8pub use embedded_io;
9pub use embedded_io_async;
10
11mod register;
12pub use register::*;
13mod command;
14pub use command::*;
15mod buffer;
16pub use buffer::*;
17
18#[doc(hidden)]
19pub mod ops;
20
21#[cfg(feature = "_macros")]
22pub use device_driver_macros::*;
23
24#[doc(hidden)]
25pub trait FieldSet {
26    /// The size of the field set in number of bits
27    const SIZE_BITS: u32;
28
29    /// Create a new instance, loaded all 0's
30    fn new_with_zero() -> Self;
31
32    fn get_inner_buffer(&self) -> &[u8];
33    fn get_inner_buffer_mut(&mut self) -> &mut [u8];
34}
35
36/// The error returned by the generated [TryFrom]s.
37/// It contains the base type of the enum.
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
39#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
40pub struct ConversionError<T> {
41    /// The value of the thing that was tried to be converted
42    pub source: T,
43    /// The name of the target type
44    pub target: &'static str,
45}
46
47impl<T: Display> Display for ConversionError<T> {
48    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
49        write!(
50            f,
51            "Could not convert value from `{}` to type `{}`",
52            self.source, self.target
53        )
54    }
55}
56
57impl<T: Display + Debug> core::error::Error for ConversionError<T> {}
58
59#[doc(hidden)]
60pub struct WO;
61#[doc(hidden)]
62pub struct RO;
63#[doc(hidden)]
64pub struct RW;
65#[doc(hidden)]
66pub struct RC;
67#[doc(hidden)]
68pub struct CO;
69
70#[doc(hidden)]
71pub trait ReadCapability {}
72#[doc(hidden)]
73pub trait WriteCapability {}
74
75impl WriteCapability for WO {}
76
77impl ReadCapability for RO {}
78
79impl WriteCapability for RW {}
80impl ReadCapability for RW {}