pub trait Screen {
    fn get_resolution(&self) -> (usize, usize);
    fn get_pixel_format(&self) -> ScreenPixelFormat;
    fn get_rotation(&self) -> ScreenRotation;
    fn set_write_frame(
        &self,
        x: usize,
        y: usize,
        width: usize,
        height: usize
    ) -> Result<(), ErrorCode>; fn write(
        &self,
        buffer: &'static mut [u8],
        len: usize
    ) -> Result<(), ErrorCode>; fn write_continue(
        &self,
        buffer: &'static mut [u8],
        len: usize
    ) -> Result<(), ErrorCode>; fn set_client(&self, client: Option<&'static dyn ScreenClient>); fn set_brightness(&self, brightness: usize) -> Result<(), ErrorCode>; fn set_power(&self, enabled: bool) -> Result<(), ErrorCode>; fn set_invert(&self, enabled: bool) -> Result<(), ErrorCode>; }
Expand description

The basic trait for screens

Required Methods

Returns a tuple (width, height) with the current resolution (in pixels) This function is synchronous as the driver should know this value without requesting it from the screen.

Note that width and height may change due to rotation.

Returns the current pixel format This function is synchronous as the driver should know this value without requesting it from the screen.

Returns the current rotation. This function is synchronous as the driver should know this value without requesting it from the screen.

Sets the video memory frame. This function has to be called before the first call to the write function. This will generate a command_complete() callback when finished.

Return values:

  • Ok(()): The write frame is valid.
  • INVAL: The parameters of the write frame are not valid.
  • BUSY: Unable to set the write frame on the device.

Sends a write command to write data in the selected video memory frame. When finished, the driver will call the write_complete() callback.

Return values:

  • Ok(()): Write is valid and will be sent to the screen.
  • INVAL: Write is invalid or length is wrong.
  • BUSY: Another write is in progress.

Sends a write command to write data in the selected video memory frame without resetting the video memory frame position. It “continues” the write from the previous position. This allows using buffers that are smaller than the video mameory frame. When finished, the driver will call the write_complete() callback.

Return values:

  • Ok(()): Write is valid and will be sent to the screen.
  • INVAL: Write is invalid or length is wrong.
  • BUSY: Another write is in progress.

Set the object to receive the asynchronous command callbacks.

Sets the display brightness value

Depending on the display, this may not cause any actual changes until and unless power is enabled (see set_power).

The following values must be supported:

  • 0 - completely no light emitted
  • 1..MAX_BRIGHTNESS - on, set brightness to the given level

The display should interpret the brightness value as lightness (each increment should change preceived brightness the same). 1 shall be the minimum supported brightness, MAX_BRIGHTNESS and greater represent the maximum. Values in between should approximate the intermediate values; minimum and maximum included (e.g. when there is only 1 level).

Controls the screen power supply.

Use it to initialize the display device.

For screens where display needs nonzero brightness (e.g. LED), this shall set brightness to a default value if set_brightness was not called first.

The device may implement power independently from brightness, so call set_brightness to turn on/off the module completely.

To allow starting in the correct configuration, the driver is allowed to cache values like brightness or invert mode and apply them together when power is enabled. If the display cannot use selected configuration, this call returns INVAL.

When finished, calls ScreenClient::screen_is_ready, both when power was enabled and disabled.

Controls the color inversion mode.

Pixels already in the frame buffer, as well as newly submited, will be inverted. What that means depends on the current pixel format. May get disabled when switching to another pixel format. Returns ENOSUPPORT if the device does not accelerate color inversion. Returns EINVAL if the current pixel format does not support color inversion.

Implementors