RKTK API Docs RKTK Home Repo

rktk/task/display/
mod.rs

1use embedded_graphics::{draw_target::DrawTarget, pixelcolor::BinaryColor};
2use rktk_log::error;
3
4use crate::{
5    config::CONST_CONFIG,
6    config::Hand,
7    drivers::interface::{display::DisplayDriver, reporter::Output},
8    utils::{Channel, Signal},
9};
10
11pub mod default_display;
12pub mod utils;
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
29#[allow(async_fn_in_trait)]
30pub trait DisplayConfig {
31    async fn start<D: DisplayDriver, const N1: usize, const N2: usize>(
32        &mut self,
33        display: &mut D,
34        display_controller: &Channel<DisplayMessage, N1>,
35        display_dynamic_message_controller: &Signal<heapless::String<N2>>,
36    );
37}
38
39pub static DISPLAY_CONTROLLER: Channel<DisplayMessage, 5> = Channel::new();
40pub static DISPLAY_DYNAMIC_MESSAGE_CONTROLLER: Signal<heapless::String<256>> = Signal::new();
41
42pub(crate) async fn start<D: DisplayDriver, C: DisplayConfig>(display: &mut D, config: &mut C) {
43    if display.init().await.is_err() {
44        error!("Failed to initialize display");
45        return;
46    }
47
48    let _ = display.as_mut().clear(BinaryColor::Off);
49    let _ = display.flush().await;
50
51    config
52        .start(
53            display,
54            &DISPLAY_CONTROLLER,
55            &DISPLAY_DYNAMIC_MESSAGE_CONTROLLER,
56        )
57        .await;
58}