adafruit_seesaw/devices/
macros.rs1#[macro_export(local_inner_macros)]
2macro_rules! seesaw_device {
3    (
4        $(#[$attr:meta])*
5        name: $name:ident,
6        hardware_id: $hardware_id:expr,
7        product_id: $product_id:expr,
8        default_addr: $default_addr:expr
9    ) => {
10        #[doc=core::concat!("[Adafruit Product Page](https://www.adafruit.com/product/", core::stringify!($product_id),")")]
11        #[doc=core::concat!("")]
12        $(#[$attr])*
13        #[derive(Debug)]
14        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
15        pub struct $name<D>(u8, D);
16
17        impl $name<()> {
18            pub const fn default_addr() -> u8 {
19                $default_addr
20            }
21            pub const fn hardware_id() -> $crate::modules::HardwareId {
22                $hardware_id
23            }
24            pub const fn product_id() -> u16 {
25                $product_id
26            }
27        }
28
29        impl<D: $crate::Driver> $crate::devices::SeesawDevice for $name<D> {
30            type Driver = D;
31            const DEFAULT_ADDR: u8 = $default_addr;
32            const HARDWARE_ID: $crate::modules::HardwareId = $hardware_id;
33            const PRODUCT_ID: u16 = $product_id;
34
35            fn addr(&self) -> u8 {
36                self.0
37            }
38
39            fn driver(&mut self) -> &mut D {
40                &mut self.1
41            }
42
43            fn new(addr: u8, driver: D) -> Self {
44                Self(addr, driver)
45            }
46
47            fn new_with_default_addr(driver: D) -> Self {
48                Self(Self::DEFAULT_ADDR, driver)
49            }
50        }
51    };
52}