1use rktk_log::error;
2
3use crate::{
4 config::CONST_CONFIG,
5 config::Hand,
6 drivers::interface::{display::DisplayDriver, reporter::Output},
7 utils::{Channel, Signal},
8};
9
10pub mod default_display;
11pub mod utils;
12pub mod color_bar;
13
14pub enum DisplayMessage {
15 Clear,
16 Message(&'static str),
17 Master(Option<bool>),
18 MouseAvailable(bool),
19 MouseMove((i8, i8)),
20 Output(Output),
21 LayerState([bool; CONST_CONFIG.key_manager.layer_count as usize]),
22 Hand(Option<Hand>),
23 NumLock(bool),
24 CapsLock(bool),
25 Brightness(u8),
26 On(bool),
27}
28
29use embedded_graphics::prelude::PixelColor;
30
31#[allow(async_fn_in_trait)]
32pub trait DisplayConfig {
33 type Color: PixelColor;
34
35 async fn start<D: DisplayDriver<Color = Self::Color>, const N1: usize, const N2: usize>(
36 &mut self,
37 display: &mut D,
38 display_controller: &Channel<DisplayMessage, N1>,
39 display_dynamic_message_controller: &Signal<heapless::String<N2>>,
40 );
41}
42
43pub static DISPLAY_CONTROLLER: Channel<DisplayMessage, 5> = Channel::new();
44pub static DISPLAY_DYNAMIC_MESSAGE_CONTROLLER: Signal<heapless::String<256>> = Signal::new();
45
46pub(crate) async fn start<D: DisplayDriver, C: DisplayConfig<Color = D::Color>>(display: &mut D, config: &mut C) {
47 if display.init().await.is_err() {
48 error!("Failed to initialize display");
49 return;
50 }
51
52 let _ = display.clear().await;
53 let _ = display.flush().await;
54
55 config.start(display, &DISPLAY_CONTROLLER, &DISPLAY_DYNAMIC_MESSAGE_CONTROLLER).await;
56}