-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
i2c_interface.rs
35 lines (30 loc) · 1.08 KB
/
i2c_interface.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
//! I2C interface factory
use display_interface_i2c::I2CInterface;
/// Helper struct to create preconfigured I2C interfaces for the display.
#[derive(Debug, Copy, Clone)]
pub struct I2CDisplayInterface(());
impl I2CDisplayInterface {
/// Create new builder with a default I2C address of 0x3C
#[allow(clippy::new_ret_no_self)]
// pub fn with_i2c<I>(i2c: I) -> I2CInterface<I> // alternative, but breaking change
pub fn new<I>(i2c: I) -> I2CInterface<I>
where
I: embedded_hal::blocking::i2c::Write,
{
Self::new_custom_address(i2c, 0x3C)
}
/// Create a new I2C interface with the alternate address 0x3D as specified in the datasheet.
pub fn new_alternate_address<I>(i2c: I) -> I2CInterface<I>
where
I: embedded_hal::blocking::i2c::Write,
{
Self::new_custom_address(i2c, 0x3D)
}
/// Create a new I2C interface with a custom address.
pub fn new_custom_address<I>(i2c: I, address: u8) -> I2CInterface<I>
where
I: embedded_hal::blocking::i2c::Write,
{
I2CInterface::new(i2c, address, 0x40)
}
}