Skip to main content
RKTK API Docs RKTK Home Repo

rktk/drivers/interface/
display.rs

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