Add framebuffer to prevent redraw flicker
This commit is contained in:
parent
d59a15c91b
commit
aee648bfa5
20
Cargo.lock
generated
20
Cargo.lock
generated
@ -424,6 +424,15 @@ version = "0.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4fc247028eae04174b6635104a35b1ed336aabef4654f5e87a8f32327d231970"
|
checksum = "4fc247028eae04174b6635104a35b1ed336aabef4654f5e87a8f32327d231970"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-dma"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "994f7e5b5cb23521c22304927195f236813053eb9c065dd2226a32ba64695446"
|
||||||
|
dependencies = [
|
||||||
|
"stable_deref_trait",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embedded-graphics"
|
name = "embedded-graphics"
|
||||||
version = "0.8.1"
|
version = "0.8.1"
|
||||||
@ -447,6 +456,16 @@ dependencies = [
|
|||||||
"byteorder",
|
"byteorder",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-graphics-framebuf"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "22354420f68727fa24d1e2741dae1e9a041065e80fb63b35a8d19c647a85be76"
|
||||||
|
dependencies = [
|
||||||
|
"embedded-dma",
|
||||||
|
"embedded-graphics",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embedded-hal"
|
name = "embedded-hal"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
@ -869,6 +888,7 @@ dependencies = [
|
|||||||
"embassy-sync",
|
"embassy-sync",
|
||||||
"embassy-time",
|
"embassy-time",
|
||||||
"embedded-graphics",
|
"embedded-graphics",
|
||||||
|
"embedded-graphics-framebuf",
|
||||||
"heapless",
|
"heapless",
|
||||||
"rtt-target",
|
"rtt-target",
|
||||||
"scd4x",
|
"scd4x",
|
||||||
|
@ -25,12 +25,15 @@ embassy-time = "0.4.0"
|
|||||||
embassy-sync = "0.6.2"
|
embassy-sync = "0.6.2"
|
||||||
embassy-embedded-hal = "0.3.0"
|
embassy-embedded-hal = "0.3.0"
|
||||||
static_cell = "2.1.0"
|
static_cell = "2.1.0"
|
||||||
embedded-graphics = "0.8.1"
|
|
||||||
|
|
||||||
# System
|
# System
|
||||||
cortex-m-rt = "0.7.5"
|
cortex-m-rt = "0.7.5"
|
||||||
rtt-target = "0.6.1"
|
rtt-target = "0.6.1"
|
||||||
|
|
||||||
|
# embedded-graphics
|
||||||
|
embedded-graphics = "0.8.1"
|
||||||
|
embedded-graphics-framebuf = "0.5.0"
|
||||||
|
|
||||||
# Peripherals
|
# Peripherals
|
||||||
scd4x = { git = "https://github.com/twokilohertz/scd4x-rs.git", branch = "conversion-fixes", features = [
|
scd4x = { git = "https://github.com/twokilohertz/scd4x-rs.git", branch = "conversion-fixes", features = [
|
||||||
"scd41",
|
"scd41",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// System
|
// System
|
||||||
use embassy_embedded_hal::shared_bus::blocking::spi::SpiDeviceWithConfig;
|
use embassy_embedded_hal::shared_bus::blocking::spi::SpiDeviceWithConfig;
|
||||||
use embassy_rp::{gpio::Output, spi::Config};
|
use embassy_rp::{gpio::Output, spi::Config};
|
||||||
|
use embedded_graphics_framebuf::FrameBuf;
|
||||||
use rtt_target::rprintln;
|
use rtt_target::rprintln;
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
@ -13,9 +14,11 @@ use ssd1351::{
|
|||||||
|
|
||||||
// Graphics
|
// Graphics
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
|
draw_target::DrawTarget,
|
||||||
mono_font::{ascii::FONT_6X10, MonoTextStyle},
|
mono_font::{ascii::FONT_6X10, MonoTextStyle},
|
||||||
pixelcolor::Rgb565,
|
pixelcolor::Rgb565,
|
||||||
prelude::{Point, WebColors},
|
prelude::{Point, RgbColor, Size, WebColors},
|
||||||
|
primitives::Rectangle,
|
||||||
text::{Alignment, Text},
|
text::{Alignment, Text},
|
||||||
Drawable,
|
Drawable,
|
||||||
};
|
};
|
||||||
@ -46,6 +49,10 @@ pub async fn display_output_task(
|
|||||||
display.reset(rst, &mut embassy_time::Delay).unwrap();
|
display.reset(rst, &mut embassy_time::Delay).unwrap();
|
||||||
display.init().unwrap();
|
display.init().unwrap();
|
||||||
|
|
||||||
|
// Framebuffer, prevents flickering on redraw
|
||||||
|
let buf = [Rgb565::BLACK; 128 * 128];
|
||||||
|
let mut framebuf = FrameBuf::new(buf, 128, 128);
|
||||||
|
|
||||||
let co2_text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::CSS_DARK_GREEN);
|
let co2_text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::CSS_DARK_GREEN);
|
||||||
let temp_text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::CSS_ORANGE);
|
let temp_text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::CSS_ORANGE);
|
||||||
let humidity_text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::CSS_AQUA);
|
let humidity_text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::CSS_AQUA);
|
||||||
@ -55,7 +62,10 @@ pub async fn display_output_task(
|
|||||||
let mut humidity_text_buf = heapless::String::<16>::new();
|
let mut humidity_text_buf = heapless::String::<16>::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Clear contents of buffers
|
// Clear the framebuffer
|
||||||
|
framebuf.clear(Rgb565::BLACK).unwrap();
|
||||||
|
|
||||||
|
// Clear contents of text buffers
|
||||||
co2_text_buf.clear();
|
co2_text_buf.clear();
|
||||||
temp_text_buf.clear();
|
temp_text_buf.clear();
|
||||||
humidity_text_buf.clear();
|
humidity_text_buf.clear();
|
||||||
@ -66,9 +76,6 @@ pub async fn display_output_task(
|
|||||||
write!(&mut temp_text_buf, "Temp: {:.1} C", data.temperature).unwrap();
|
write!(&mut temp_text_buf, "Temp: {:.1} C", data.temperature).unwrap();
|
||||||
write!(&mut humidity_text_buf, "RH: {:.1} %", data.humidity).unwrap();
|
write!(&mut humidity_text_buf, "RH: {:.1} %", data.humidity).unwrap();
|
||||||
|
|
||||||
// Clear the display
|
|
||||||
display.clear();
|
|
||||||
|
|
||||||
// Draw the text to the screen
|
// Draw the text to the screen
|
||||||
Text::with_alignment(
|
Text::with_alignment(
|
||||||
&co2_text_buf,
|
&co2_text_buf,
|
||||||
@ -76,7 +83,7 @@ pub async fn display_output_task(
|
|||||||
co2_text_style,
|
co2_text_style,
|
||||||
Alignment::Left,
|
Alignment::Left,
|
||||||
)
|
)
|
||||||
.draw(&mut display)
|
.draw(&mut framebuf)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Text::with_alignment(
|
Text::with_alignment(
|
||||||
@ -85,7 +92,7 @@ pub async fn display_output_task(
|
|||||||
temp_text_style,
|
temp_text_style,
|
||||||
Alignment::Left,
|
Alignment::Left,
|
||||||
)
|
)
|
||||||
.draw(&mut display)
|
.draw(&mut framebuf)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Text::with_alignment(
|
Text::with_alignment(
|
||||||
@ -94,7 +101,11 @@ pub async fn display_output_task(
|
|||||||
humidity_text_style,
|
humidity_text_style,
|
||||||
Alignment::Left,
|
Alignment::Left,
|
||||||
)
|
)
|
||||||
.draw(&mut display)
|
.draw(&mut framebuf)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// Draw the entire framebuffer to the display
|
||||||
|
let area: Rectangle = Rectangle::new(Point::new(0, 0), Size::new(128, 128));
|
||||||
|
display.fill_contiguous(&area, framebuf.data).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user