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
57
58
mod buffered_graphics;
mod terminal;
use crate::{command::AddrMode, rotation::DisplayRotation, size::DisplaySize, Ssd1306};
pub use buffered_graphics::*;
use display_interface::{DisplayError, WriteOnlyDataCommand};
pub use terminal::*;
pub trait DisplayConfig {
type Error;
fn set_rotation(&mut self, rotation: DisplayRotation) -> Result<(), Self::Error>;
fn init(&mut self) -> Result<(), Self::Error>;
}
#[derive(Debug, Copy, Clone)]
pub struct BasicMode;
impl<DI, SIZE> Ssd1306<DI, SIZE, BasicMode>
where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
{
pub fn clear(&mut self) -> Result<(), DisplayError> {
self.set_draw_area((0, 0), self.dimensions())?;
self.draw(&[0u8; 1024])
}
}
impl<DI, SIZE> DisplayConfig for Ssd1306<DI, SIZE, BasicMode>
where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
{
type Error = DisplayError;
fn set_rotation(&mut self, rot: DisplayRotation) -> Result<(), DisplayError> {
self.set_rotation(rot)
}
fn init(&mut self) -> Result<(), DisplayError> {
self.init_with_addr_mode(AddrMode::Horizontal)
}
}