hd44780_controller/command/
mod.rs

1mod common;
2pub use common::*;
3
4pub mod enter_4bit;
5pub use enter_4bit::Enter4Bit;
6
7pub mod write_char;
8pub use write_char::WriteChar;
9
10pub mod set_backlight;
11pub use set_backlight::SetBacklight;
12
13pub mod clear_display;
14pub use clear_display::ClearDisplay;
15
16pub mod return_home;
17pub use return_home::ReturnHome;
18
19pub mod entry_mode_set;
20pub use entry_mode_set::EntryModeSet;
21
22pub mod display_on_off;
23pub use display_on_off::DisplayOnOff;
24
25pub mod cursor_or_display_shift;
26pub use cursor_or_display_shift::CursorOrDisplayShift;
27
28pub mod function_set;
29pub use function_set::FunctionSet;
30
31pub mod set_cgram_address;
32pub use set_cgram_address::SetCGRamAddress;
33
34pub mod set_ddram_address;
35pub use set_ddram_address::SetDDRamAddress;
36
37#[derive(Copy, Clone, Debug, Eq, PartialEq)]
38pub enum Error {
39    DeviceError,
40}
41
42macro_rules! define_commands {
43    (
44        $( $variant:ident($ty:ty) ),* $(,)?
45    ) => {
46        #[derive(Clone, Debug, Eq, PartialEq)]
47        pub enum Commands {
48            $( $variant($ty), )*
49        }
50
51
52        impl SyncCommand for Commands {
53            type Ret = ();
54            type Err = Error;
55
56            fn execute<D: super::device::SyncDevice + ?Sized>(&self, dev: &mut D) -> Result<Self::Ret, Self::Err> {
57                match self {
58                    $( Commands::$variant(cmd) => cmd.execute(dev), )*
59                }
60            }
61        }
62
63        #[cfg(feature = "async")]
64        #[cfg_attr(docsrs, doc(cfg(feature = "async")))]
65        impl AsyncCommand for Commands {
66            type Ret = ();
67            type Err = Error;
68
69            async fn execute_async<D: super::device::AsyncDevice + ?Sized>(
70                &self,
71                dev: &mut D,
72            ) -> Result<Self::Ret, Self::Err> {
73                match self {
74                    $( Commands::$variant(cmd) => cmd.execute_async(dev).await, )*
75                }
76            }
77        }
78
79        $(
80            impl From<$ty> for Commands {
81                fn from(cmd: $ty) -> Self {
82                    Commands::$variant(cmd)
83                }
84            }
85        )*
86    };
87}
88
89define_commands! {
90    Enter4Bit(Enter4Bit),
91    WriteChar(WriteChar),
92    SetBacklight(SetBacklight),
93    ClearDisplay(ClearDisplay),
94    ReturnHome(ReturnHome),
95    EntryModeSet(EntryModeSet),
96    DisplayOnOnff(DisplayOnOff),
97    CursorOrDisplayShift(CursorOrDisplayShift),
98    FunctionSet(FunctionSet),
99    SetCGRamAddress(SetCGRamAddress),
100    SetDDRamAddress(SetDDRamAddress),
101}