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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Pin related functions

use embedded_hal::digital::v2::{InputPin, OutputPin};

use crate::full_command::FullCommand;

mod impl_crate_level_api;
mod impl_internal_api;
mod impl_pins_api;

/// [Pins] record [LCD][crate::LCD] related pins data
pub struct Pins<ControlPin, DBPin, const PIN_CNT: usize>
where
    ControlPin: OutputPin,
    DBPin: OutputPin + InputPin,
{
    rs_pin: ControlPin,
    rw_pin: ControlPin,
    en_pin: ControlPin,
    db_pins: [DBPin; PIN_CNT],
}

/// for 8 pin mode
pub trait FourPinsAPI<ControlPin, DBPin>
where
    ControlPin: OutputPin,
    DBPin: OutputPin + InputPin,
{
    fn new(
        rs: ControlPin,
        rw: ControlPin,
        en: ControlPin,
        db4: DBPin,
        db5: DBPin,
        db6: DBPin,
        db7: DBPin,
    ) -> Self
    where
        ControlPin: OutputPin,
        DBPin: OutputPin + InputPin;
}

/// for 4 pin mode
pub trait EightPinsAPI<ControlPin, DBPin>
where
    ControlPin: OutputPin,
    DBPin: OutputPin + InputPin,
{
    fn new(
        rs: ControlPin,
        rw: ControlPin,
        en: ControlPin,
        db0: DBPin,
        db1: DBPin,
        db2: DBPin,
        db3: DBPin,
        db4: DBPin,
        db5: DBPin,
        db6: DBPin,
        db7: DBPin,
    ) -> Self
    where
        ControlPin: OutputPin,
        DBPin: OutputPin + InputPin;
}

trait PinsInternalAPI {
    fn push_bits(&mut self, raw_bits: u8);
    fn fetch_bits(&mut self) -> u8;
}

pub(super) trait PinsCrateLevelAPI {
    fn send(&mut self, command: impl Into<FullCommand>) -> Option<u8>;
}