graphics: ssd1306: move init steps to new asyncn method

This commit is contained in:
2025-12-07 14:55:05 +01:00
parent 6123844cd7
commit 727e96a539
2 changed files with 15 additions and 8 deletions

View File

@@ -99,7 +99,8 @@ pub struct SsdOutput {
target: ssd1306::Ssd1306Async<ssd1306::prelude::I2CInterface<esp_hal::i2c::master::I2c<'static, esp_hal::Async>>, ssd1306::prelude::DisplaySize128x64, ssd1306::mode::BasicMode>,
controls: DisplayControls,
is_on: bool,
last_brightness: u8
last_brightness: u8,
reset_pin: Output<'static>
}
impl SsdOutput {
@@ -114,20 +115,24 @@ impl SsdOutput {
Some(SsdPixel { byte: pixref, bit, coords })
}
pub async fn new(i2c: I2c<'static, Async>, mut reset_pin: Output<'static>, controls: DisplayControls) -> Self {
pub async fn new(i2c: I2c<'static, Async>, reset_pin: Output<'static>, controls: DisplayControls) -> Self {
let interface = I2CDisplayInterface::new(i2c);
let mut display = Ssd1306Async::new(interface, DisplaySize128x64, DisplayRotation::Rotate0);
display.reset(&mut reset_pin, &mut Delay).await.unwrap();
display.init_with_addr_mode(ssd1306::command::AddrMode::Horizontal).await.unwrap();
let target = Ssd1306Async::new(interface, DisplaySize128x64, DisplayRotation::Rotate0);
Self {
pixbuf: [0; 128 * 64 / 8],
target: display,
target,
controls,
last_brightness: 255,
is_on: true
is_on: true,
reset_pin
}
}
pub async fn init(&mut self) -> Result<(), display_interface::DisplayError> {
self.target.reset(&mut self.reset_pin, &mut Delay).await.map_err(|_| { DisplayError::BusWriteError })?;
self.target.init_with_addr_mode(ssd1306::command::AddrMode::Horizontal).await
}
}
impl<'a> Sample<'a, Matrix2DSpace> for SsdOutput {

View File

@@ -17,7 +17,9 @@ pub async fn oled_render(mut output: SsdOutput, surfaces: OledUiSurfacePool, uni
const ANIMATION_TPS: u64 = 30;
const ANIMATION_FRAME_TIME: Duration = Duration::from_millis(1000 / ANIMATION_TPS);
info!("Starting Oled renderer");
info!("Starting Oled display driver");
output.init().await?;
loop {
let start = Instant::now();
{