hd44780_controller/controller/
common.rs1use core::marker::PhantomData;
2
3use crate::{command, device::*};
4
5use super::config::{InitialConfig, RuntimeConfig};
6
7pub mod state {
8 pub struct Empty;
9 pub struct Uninit;
10 pub struct Init;
11}
12
13#[derive(Copy, Clone, Debug, Eq, PartialEq)]
14pub enum Error {
15 CommandError,
16 OutOfBounds,
17}
18
19impl From<command::Error> for Error {
20 fn from(_value: command::Error) -> Self {
21 Error::CommandError
22 }
23}
24
25#[allow(unused)]
26pub struct Controller<D, S = state::Empty> {
27 pub(super) device: D,
28 pub(super) initial_config: InitialConfig,
29 pub(super) runtime_config: RuntimeConfig,
30 pub(super) _state: PhantomData<S>,
31}
32
33impl<D> Controller<D, state::Empty> {
34 pub fn new<Dev: Device>(
35 device: Dev,
36 initial_config: InitialConfig,
37 runtime_config: RuntimeConfig,
38 ) -> Controller<Dev, state::Uninit> {
39 Controller {
40 device,
41 initial_config,
42 runtime_config,
43 _state: PhantomData,
44 }
45 }
46
47 #[cfg(feature = "async")]
48 #[cfg_attr(docsrs, doc(cfg(feature = "async")))]
49 pub fn new_async<Dev: AsyncDevice>(
50 device: Dev,
51 initial_config: InitialConfig,
52 runtime_config: RuntimeConfig,
53 ) -> Controller<Dev, state::Uninit> {
54 Controller {
55 device,
56 initial_config,
57 runtime_config,
58 _state: PhantomData,
59 }
60 }
61}
62
63#[cfg(feature = "fmt")]
64#[cfg_attr(docsrs, doc(cfg(feature = "fmt")))]
65#[macro_export]
66macro_rules! lcd_write {
67 ($lcd:expr, $($arg:tt)*) => {
68 $lcd.write_fmt::<128>(format_args!($($arg)*))
69 };
70
71 ($lcd:expr, charset = $charset:expr, $($arg:tt)*) => {
72 $lcd.write_fmt_with_charset::<128>(format_args!($($arg)*), $charset)
73 };
74}
75
76#[cfg(feature = "fmt")]
77#[cfg_attr(docsrs, doc(cfg(feature = "fmt")))]
78#[macro_export]
79macro_rules! lcd_println {
80 ($lcd:expr, line = $line:expr, $($arg:tt)*) => {
81 $lcd.write_line_fmt::<128>($line, format_args!($($arg)*))
82 };
83
84 ($lcd:expr, line = $line:expr, charset = $charset:expr, $($arg:tt)*) => {
85 $lcd.write_line_fmt_with_charset::<128>(format_args!($($arg)*), $charset)
86 };
87}