diff --git a/src/graphics/ssd1306.rs b/src/graphics/ssd1306.rs index c5e1f72..0ecb89e 100644 --- a/src/graphics/ssd1306.rs +++ b/src/graphics/ssd1306.rs @@ -99,7 +99,8 @@ pub struct SsdOutput { target: ssd1306::Ssd1306Async>, 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 { diff --git a/src/tasks/oled_render.rs b/src/tasks/oled_render.rs index 6682786..041b60d 100644 --- a/src/tasks/oled_render.rs +++ b/src/tasks/oled_render.rs @@ -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(); {