adafruit_seesaw/devices/mod.rs
1#[cfg(feature = "device_arcade_button_1x4")]
2mod arcade_button_1x4;
3mod generic_device;
4pub mod macros;
5#[cfg(feature = "device_neokey_1x4")]
6mod neokey_1x4;
7#[cfg(feature = "device_neorotary4")]
8mod neorotary4;
9#[cfg(feature = "device_neoslider")]
10mod neoslider;
11#[cfg(feature = "device_neotrellis")]
12mod neotrellis;
13#[cfg(feature = "device_rotary_encoder")]
14mod rotary_encoder;
15use crate::{
16 modules::{status::StatusModule, HardwareId},
17 Driver, SeesawError,
18};
19#[cfg(feature = "device_arcade_button_1x4")]
20pub use arcade_button_1x4::*;
21pub use generic_device::*;
22#[cfg(feature = "device_neokey_1x4")]
23pub use neokey_1x4::*;
24#[cfg(feature = "device_neorotary4")]
25pub use neorotary4::*;
26#[cfg(feature = "device_neoslider")]
27pub use neoslider::*;
28#[cfg(feature = "device_neotrellis")]
29pub use neotrellis::*;
30#[cfg(feature = "device_rotary_encoder")]
31pub use rotary_encoder::*;
32
33pub trait SeesawDevice {
34 type Driver: crate::Driver;
35
36 const DEFAULT_ADDR: u8;
37 const HARDWARE_ID: HardwareId;
38 const PRODUCT_ID: u16;
39
40 fn addr(&self) -> u8;
41
42 fn driver(&mut self) -> &mut Self::Driver;
43
44 fn new(addr: u8, driver: Self::Driver) -> Self;
45
46 fn new_with_default_addr(driver: Self::Driver) -> Self;
47}
48
49/// All devices implement the status module
50impl<D: Driver, T: SeesawDevice<Driver = D>> StatusModule<D> for T {}
51
52/// At startup, Seesaw devices typically have a unique set of initialization
53/// calls to be made. e.g. for a Neokey1x4, we need to enable the on-board
54/// neopixel and also do some pin mode setting to get everything working.
55/// All devices implement `DeviceInit` with a set of sensible defaults.
56pub trait SeesawDeviceInit<D: Driver>: SeesawDevice<Driver = D>
57where
58 Self: Sized,
59{
60 fn init(self) -> Result<Self, SeesawError<D::Error>>;
61}