Skip to main content

FrameBufferedDisplayDriver

Struct FrameBufferedDisplayDriver 

Source
pub struct FrameBufferedDisplayDriver<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize>
where B: DisplayBus, P: Panel<B>, C: PixelColor<Raw = R>,
{ pub driver: DisplayDriver<B, P>, /* private fields */ }
Expand description

A display driver that buffers drawing operations in a framebuffer.

This struct wraps an underlying DisplayDriver and a mutable reference to an embedded-graphics Framebuffer. It implements the DrawTarget trait, forwarding all drawing operations to the framebuffer, and provides methods to flush the buffered pixels to the display.

It supports both full-screen refreshes and partial updates (when the framebuffer covers only a specific sub-area of the screen).

§Usage Examples

§Full Screen Refreshing

By default, using the new constructor configures the driver to refresh the full area corresponding to the framebuffer size (W x H) starting at the origin (0, 0):

// Initialize driver and framebuffer
let mut fb_display = FrameBufferedDisplayDriver::new(driver, &mut framebuffer);

// Draw elements onto the framebuffer
fb_display.clear(BinaryColor::Off).unwrap();
Circle::new(Point::new(10, 10), 20)
    .into_styled(PrimitiveStyle::with_stroke(BinaryColor::On, 1))
    .draw(&mut fb_display)
    .unwrap();

// Flush the changes to the screen
fb_display.flush().await.unwrap();

§Partial Screen Refreshing

If the framebuffer is only used to update a specific sub-region of the screen, use new_partial:

let area = Area::new(50, 50, 100, 100); // W=100, H=100
let mut fb_display = FrameBufferedDisplayDriver::new_partial(driver, area, &mut framebuffer)?;

// Flush to the specified sub-region of the screen
fb_display.flush().await.unwrap();

Fields§

§driver: DisplayDriver<B, P>

Implementations§

Source§

impl<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize> FrameBufferedDisplayDriver<'a, B, P, C, R, BO, W, H, N>
where B: DisplayBus, P: Panel<B>, C: PixelColor<Raw = R>,

Source

pub fn new( driver: DisplayDriver<B, P>, framebuffer: &'a mut Framebuffer<C, R, BO, W, H, N>, ) -> Self

Creates a new FrameBufferedDisplayDriver.

By default, the display area is set to the full size of the framebuffer (W x H), starting at the origin (0, 0).

§Arguments
  • driver - The underlying display driver.
  • framebuffer - A mutable reference to the framebuffer of size W x H.
Source

pub fn new_partial( driver: DisplayDriver<B, P>, area: Area, framebuffer: &'a mut Framebuffer<C, R, BO, W, H, N>, ) -> Result<Self, DisplayError<B::Error>>

Creates a new FrameBufferedDisplayDriver with a specific partial display area.

This is used when the framebuffer corresponds to a sub-region of the screen.

§Errors

Returns DisplayError::InvalidArgs if the size of the area does not exactly match the dimensions of the framebuffer (W x H).

§Arguments
  • driver - The underlying display driver.
  • area - The sub-region on the display screen where the framebuffer should be drawn.
  • framebuffer - A mutable reference to the framebuffer.
Source

pub fn set_area(&mut self, area: Area) -> Result<(), DisplayError<B::Error>>

Updates the display area where the framebuffer will be drawn.

§Errors

Returns DisplayError::InvalidArgs if the new area does not exactly match the dimensions of the framebuffer.

Source

pub fn area(&self) -> Area

Gets the current display area.

Source

pub fn framebuffer(&self) -> &Framebuffer<C, R, BO, W, H, N>

Gets a reference to the underlying framebuffer.

Source

pub fn framebuffer_mut(&mut self) -> &mut Framebuffer<C, R, BO, W, H, N>

Gets a mutable reference to the underlying framebuffer.

Source

pub async fn flush(&mut self) -> Result<(), DisplayError<B::Error>>

Flushes the underlying framebuffer to the display at the current display area.

Source

pub async fn flush_with_frame_control( &mut self, frame_control: FrameControl, ) -> Result<(), DisplayError<B::Error>>

Flushes the underlying framebuffer to the display at the current display area using custom frame control settings.

Frame control settings allow managing options such as whether this is a standalone write or part of a sequence of writes, which can be useful for double-buffering, tearing effect (TE) synchronization, or multi-part updates.

§Arguments
  • frame_control - The frame synchronization/control flags to use for the write.
Source

pub async fn flush_lines( &mut self, y_start: u16, y_end: u16, ) -> Result<(), DisplayError<B::Error>>

Flushes a specific range of lines from the framebuffer to the display.

This is useful when the entire framebuffer exceeds the DMA transfer limits of the microcontroller (e.g., >65535 bytes on STM32) or when only a portion of the screen needs to be updated.

§Arguments
  • y_start - The starting line (inclusive).
  • y_end - The ending line (inclusive).
Source

pub async fn flush_lines_with_frame_control( &mut self, y_start: u16, y_end: u16, frame_control: FrameControl, ) -> Result<(), DisplayError<B::Error>>

Flushes a specific range of lines from the framebuffer to the display using custom frame control settings.

§Arguments
  • y_start - The starting line (inclusive).
  • y_end - The ending line (inclusive).
  • frame_control - The frame synchronization/control flags to use for the write.
Source

pub fn into_inner(self) -> DisplayDriver<B, P>

Returns the inner DisplayDriver.

Source

pub async fn init( &mut self, delay: &mut impl DelayNs, ) -> Result<(), DisplayError<B::Error>>

Initializes the display.

Source

pub async fn set_color_format( &mut self, color_format: ColorFormat, ) -> Result<(), DisplayError<B::Error>>

Sets the pixel color format.

Source

pub async fn set_orientation( &mut self, orientation: Orientation, ) -> Result<(), DisplayError<B::Error>>

Sets the display orientation.

Source§

impl<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize> FrameBufferedDisplayDriver<'a, B, P, C, R, BO, W, H, N>
where B: DisplayBus, P: Panel<B> + PanelSetBrightness<B>, C: PixelColor<Raw = R>,

Source

pub async fn set_brightness( &mut self, brightness: u8, ) -> Result<(), DisplayError<B::Error>>

Sets the display brightness (if supported by the panel).

Trait Implementations§

Source§

impl<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize> DrawTarget for FrameBufferedDisplayDriver<'a, B, P, C, R, BO, W, H, N>
where B: DisplayBus, P: Panel<B>, C: PixelColor<Raw = R>, Framebuffer<C, R, BO, W, H, N>: DrawTarget<Color = C>,

Source§

type Color = C

The pixel color type the targetted display supports.
Source§

type Error = <Framebuffer<C, R, BO, W, H, N> as DrawTarget>::Error

Error type to return when a drawing operation fails. Read more
Source§

fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
where I: IntoIterator<Item = Pixel<Self::Color>>,

Draw individual pixels to the display without a defined order. Read more
Source§

fn fill_contiguous<I>( &mut self, area: &Rectangle, colors: I, ) -> Result<(), Self::Error>
where I: IntoIterator<Item = Self::Color>,

Fill a given area with an iterator providing a contiguous stream of pixel colors. Read more
Source§

fn fill_solid( &mut self, area: &Rectangle, color: Self::Color, ) -> Result<(), Self::Error>

Fill a given area with a solid color. Read more
Source§

fn clear(&mut self, color: Self::Color) -> Result<(), Self::Error>

Fill the entire display with a solid color. Read more
Source§

impl<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize> OriginDimensions for FrameBufferedDisplayDriver<'a, B, P, C, R, BO, W, H, N>
where B: DisplayBus, P: Panel<B>, C: PixelColor<Raw = R>,

Source§

fn size(&self) -> Size

Returns the size of the bounding box.

Auto Trait Implementations§

§

impl<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize> !UnwindSafe for FrameBufferedDisplayDriver<'a, B, P, C, R, BO, W, H, N>

§

impl<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize> Freeze for FrameBufferedDisplayDriver<'a, B, P, C, R, BO, W, H, N>
where DisplayDriver<B, P>: Freeze, &'a mut Framebuffer<C, R, BO, W, H, N>: Freeze,

§

impl<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize> RefUnwindSafe for FrameBufferedDisplayDriver<'a, B, P, C, R, BO, W, H, N>
where DisplayDriver<B, P>: RefUnwindSafe, &'a mut Framebuffer<C, R, BO, W, H, N>: RefUnwindSafe,

§

impl<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize> Send for FrameBufferedDisplayDriver<'a, B, P, C, R, BO, W, H, N>
where DisplayDriver<B, P>: Send, &'a mut Framebuffer<C, R, BO, W, H, N>: Send,

§

impl<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize> Sync for FrameBufferedDisplayDriver<'a, B, P, C, R, BO, W, H, N>
where DisplayDriver<B, P>: Sync, &'a mut Framebuffer<C, R, BO, W, H, N>: Sync,

§

impl<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize> Unpin for FrameBufferedDisplayDriver<'a, B, P, C, R, BO, W, H, N>
where DisplayDriver<B, P>: Unpin, &'a mut Framebuffer<C, R, BO, W, H, N>: Unpin,

§

impl<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize> UnsafeUnpin for FrameBufferedDisplayDriver<'a, B, P, C, R, BO, W, H, N>
where DisplayDriver<B, P>: UnsafeUnpin, &'a mut Framebuffer<C, R, BO, W, H, N>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> Dimensions for T

Source§

fn bounding_box(&self) -> Rectangle

Returns the bounding box.
Source§

impl<T> DrawTargetExt for T
where T: DrawTarget,

Source§

fn translated(&mut self, offset: Point) -> Translated<'_, T>

Creates a translated draw target based on this draw target. Read more
Source§

fn cropped(&mut self, area: &Rectangle) -> Cropped<'_, T>

Creates a cropped draw target based on this draw target. Read more
Source§

fn clipped(&mut self, area: &Rectangle) -> Clipped<'_, T>

Creates a clipped draw target based on this draw target. Read more
Source§

fn color_converted<C>(&mut self) -> ColorConverted<'_, T, C>
where C: PixelColor + Into<<T as DrawTarget>::Color>,

Creates a color conversion draw target. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.