adafruit_seesaw/
lib.rs

1#![doc = include_str!("../README.md")]
2#![no_std]
3#![allow(const_evaluatable_unchecked, incomplete_features, rustdoc::bare_urls)]
4#![cfg_attr(feature = "module_neopixel", feature(generic_const_exprs))]
5
6use core::fmt::{Display, Formatter};
7// Re-export rgb
8pub use rgb;
9
10pub mod devices;
11pub mod modules;
12pub mod prelude {
13    #[cfg(feature = "module_adc")]
14    pub use super::modules::adc::*;
15    #[cfg(feature = "module_encoder")]
16    pub use super::modules::encoder::*;
17    #[cfg(feature = "module_gpio")]
18    pub use super::modules::gpio::*;
19    #[cfg(feature = "module_keypad")]
20    pub use super::modules::keypad::*;
21    #[cfg(feature = "module_neopixel")]
22    pub use super::modules::neopixel::*;
23    #[cfg(feature = "module_timer")]
24    pub use super::modules::timer::*;
25    #[cfg(feature = "module_touch")]
26    pub use super::modules::touch::*;
27    pub use super::{
28        devices::{SeesawDevice, SeesawDeviceInit},
29        driver::{DriverExt, SeesawDriver},
30        modules::{status::*, HardwareId},
31    };
32}
33mod driver;
34pub use driver::*;
35
36#[derive(Copy, Clone, Debug)]
37#[cfg_attr(feature = "defmt", derive(defmt::Format))]
38pub enum SeesawError<E> {
39    /// I2C bus error
40    I2c(E),
41    /// Occurs when an invalid hardware ID is read
42    InvalidHardwareId(u8),
43}
44
45impl<E> Display for SeesawError<E> {
46    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
47        match self {
48            SeesawError::I2c(_) => f.write_str("I2C error"),
49            SeesawError::InvalidHardwareId(id) => write!(f, "invalid hardware id: {id}"),
50        }
51    }
52}
53
54impl<E: core::fmt::Debug + core::error::Error + 'static> core::error::Error for SeesawError<E> {
55    fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
56        match self {
57            SeesawError::I2c(err) => Some(err),
58            _ => None,
59        }
60    }
61}