RKTK API Docs RKTK Home Repo

rktk/drivers/interface/
display.rs

1use display_interface::DisplayError;
2use embedded_graphics::{pixelcolor::BinaryColor, prelude::*};
3
4/// Interface for display drivers.
5///
6/// TODO: Allow sync-only drivers?
7pub trait DisplayDriver: AsRef<Self::Display> + AsMut<Self::Display> + 'static {
8    type Display: DrawTarget<Color = BinaryColor>;
9
10    /// Called when the display is initialized.
11    ///
12    /// It is guaranteed that:
13    /// - No other function is called before this function.
14    /// - If this function returns an error, other functions will not be called.
15    ///
16    /// Default implementation returns `Ok(())`.
17    async fn init(&mut self) -> Result<(), DisplayError> {
18        Ok(())
19    }
20
21    async fn flush(&mut self) -> Result<(), DisplayError> {
22        Ok(())
23    }
24
25    /// Sets brightness of the display.
26    ///
27    /// 0 is off, 255 is full brightness.
28    async fn set_brightness(&mut self, _brightness: u8) -> Result<(), DisplayError> {
29        Err(DisplayError::DataFormatNotImplemented)
30    }
31
32    async fn set_display_on(&mut self, on: bool) -> Result<(), DisplayError> {
33        if on {
34            self.set_brightness(255).await
35        } else {
36            self.set_brightness(0).await
37        }
38    }
39}