-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathlib.rs
56 lines (49 loc) · 1.4 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(const_evaluatable_unchecked, incomplete_features, rustdoc::bare_urls)]
#![feature(array_try_map, generic_const_exprs)]
// TODO improve the organization of the exports/visibility
// Re-export rgb
pub use rgb;
pub mod bus;
pub mod devices;
pub mod modules;
pub mod prelude {
pub use super::{
devices::{SeesawDevice, SeesawDeviceInit},
driver::DriverExt,
modules::{
adc::*, encoder::*, gpio::*, keypad::*, neopixel::*, status::*, timer::*, HardwareId,
},
};
}
mod driver;
use bus::{Bus, BusMutex, RefCellBus};
pub use driver::*;
use embedded_hal::{delay::DelayNs, i2c::I2c};
use modules::HardwareId;
pub type SeesawRefCell<BUS> = Seesaw<RefCellBus<BUS>>;
#[cfg(feature = "std")]
pub type SeesawStdMutex<BUS> = Seesaw<std::sync::Mutex<BUS>>;
/// The owner of the driver from which new seesaw devices can be created
pub struct Seesaw<M>(M);
impl<DELAY, I2C, M> Seesaw<M>
where
DELAY: DelayNs,
I2C: I2c,
M: BusMutex<Bus = (DELAY, I2C)>,
{
pub fn new(delay: DELAY, i2c: I2C) -> Self {
Seesaw(M::create((delay, i2c)))
}
pub fn acquire_driver(&self) -> Bus<'_, M> {
Bus(&self.0)
}
}
#[derive(Copy, Clone, Debug)]
pub enum SeesawError<E> {
/// I2C bus error
I2c(E),
/// Occurs when an invalid hardware ID is read
InvalidHardwareId(u8),
}