pub struct FrameBufferedDisplayDriver<'a, B, P, C, R, BO, const W: usize, const H: usize, const N: usize>{
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>
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>
Sourcepub fn new(
driver: DisplayDriver<B, P>,
framebuffer: &'a mut Framebuffer<C, R, BO, W, H, N>,
) -> Self
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 sizeWxH.
Sourcepub fn new_partial(
driver: DisplayDriver<B, P>,
area: Area,
framebuffer: &'a mut Framebuffer<C, R, BO, W, H, N>,
) -> Result<Self, DisplayError<B::Error>>
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.
Sourcepub fn set_area(&mut self, area: Area) -> Result<(), DisplayError<B::Error>>
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.
Sourcepub fn framebuffer(&self) -> &Framebuffer<C, R, BO, W, H, N>
pub fn framebuffer(&self) -> &Framebuffer<C, R, BO, W, H, N>
Gets a reference to the underlying framebuffer.
Sourcepub fn framebuffer_mut(&mut self) -> &mut Framebuffer<C, R, BO, W, H, N>
pub fn framebuffer_mut(&mut self) -> &mut Framebuffer<C, R, BO, W, H, N>
Gets a mutable reference to the underlying framebuffer.
Sourcepub async fn flush(&mut self) -> Result<(), DisplayError<B::Error>>
pub async fn flush(&mut self) -> Result<(), DisplayError<B::Error>>
Flushes the underlying framebuffer to the display at the current display area.
Sourcepub async fn flush_with_frame_control(
&mut self,
frame_control: FrameControl,
) -> Result<(), DisplayError<B::Error>>
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.
Sourcepub async fn flush_lines(
&mut self,
y_start: u16,
y_end: u16,
) -> Result<(), DisplayError<B::Error>>
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).
Sourcepub async fn flush_lines_with_frame_control(
&mut self,
y_start: u16,
y_end: u16,
frame_control: FrameControl,
) -> Result<(), DisplayError<B::Error>>
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.
Sourcepub fn into_inner(self) -> DisplayDriver<B, P>
pub fn into_inner(self) -> DisplayDriver<B, P>
Returns the inner DisplayDriver.
Sourcepub async fn init(
&mut self,
delay: &mut impl DelayNs,
) -> Result<(), DisplayError<B::Error>>
pub async fn init( &mut self, delay: &mut impl DelayNs, ) -> Result<(), DisplayError<B::Error>>
Initializes the display.
Sourcepub async fn set_color_format(
&mut self,
color_format: ColorFormat,
) -> Result<(), DisplayError<B::Error>>
pub async fn set_color_format( &mut self, color_format: ColorFormat, ) -> Result<(), DisplayError<B::Error>>
Sets the pixel color format.
Sourcepub async fn set_orientation(
&mut self,
orientation: Orientation,
) -> Result<(), DisplayError<B::Error>>
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>
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>
Sourcepub async fn set_brightness(
&mut self,
brightness: u8,
) -> Result<(), DisplayError<B::Error>>
pub async fn set_brightness( &mut self, brightness: u8, ) -> Result<(), DisplayError<B::Error>>
Sets the display brightness (if supported by the panel).