Skip to main content

st7305_lcd/
command.rs

1use crate::instr::Instr;
2
3/// A command that can be sent with `write_command`: an opcode and its parameter bytes.
4pub trait WriteCommand {
5    /// Opcode, sent with `DC` low
6    const OPCODE: Instr;
7    /// Parameter bytes, sent with `DC` high
8    type Params: AsRef<[u8]>;
9    /// Parameter bytes of this command value.
10    fn params(&self) -> Self::Params;
11}
12
13macro_rules! no_param_command {
14    ($(#[$meta:meta])* $name:ident => $op:ident) => {
15        #[doc = concat!("`", stringify!($op), "`: command without parameters.")]
16        #[doc = ""]
17        $(#[$meta])*
18        #[derive(Clone, Copy, Debug, PartialEq, Eq)]
19        pub struct $name;
20        impl WriteCommand for $name {
21            const OPCODE: Instr = Instr::$op;
22            type Params = [u8; 0];
23            fn params(&self) -> Self::Params { [] }
24        }
25    };
26}
27
28pub(crate) use no_param_command;