diff --git a/src/graphics/ssd1306.rs b/src/graphics/ssd1306.rs index 9a7e142..3629606 100644 --- a/src/graphics/ssd1306.rs +++ b/src/graphics/ssd1306.rs @@ -13,28 +13,24 @@ use embassy_time::Delay; use crate::graphics::display::DisplayControls; -pub struct SsdOutput { - pixbuf: [u8; 128 * 64 / 8], - target: ssd1306::Ssd1306Async>, ssd1306::prelude::DisplaySize128x64, ssd1306::mode::BasicMode>, - controls: DisplayControls, - is_on: bool, - last_brightness: u8 +#[derive(Clone, Copy)] +pub struct SsdPixel { + byte: *mut u8, + bit: u8, + coords: Coordinates } -#[derive(Copy, Clone)] -pub struct SsdPixel(*mut u8, u8, Coordinates); - impl SsdPixel { fn set_pixel(&self, value: BinaryColor) { if value.is_on() { - unsafe { *self.0 |= 1 << self.1 }; + unsafe { *self.byte |= 1 << self.bit }; } else { - unsafe { *self.0 &= !(1 << self.1) }; + unsafe { *self.byte &= !(1 << self.bit) }; } } fn get_pixel(&self) -> BinaryColor { - if unsafe { *self.0 >> self.1 & 0x01 == 0x01 } { + if unsafe { *self.byte >> self.bit & 0x01 == 0x01 } { BinaryColor::On } else { BinaryColor::Off @@ -51,8 +47,8 @@ impl PixelSink for SsdPixel { impl PixelBlend for SsdPixel { fn blend_pixel(self, overlay: BinaryColor, opacity: Fract8) -> Self { let scale = 48; - let x = self.2.x * scale; - let y = self.2.y * scale; + let x = self.coords.x * scale; + let y = self.coords.y * scale; let stiple_idx = noise::inoise8(x as i16, y as i16); if opacity >= stiple_idx { self.set_pixel(overlay); @@ -98,6 +94,14 @@ impl<'a> Iterator for SsdSampler<'a> { } } +pub struct SsdOutput { + pixbuf: [u8; 128 * 64 / 8], + target: ssd1306::Ssd1306Async>, ssd1306::prelude::DisplaySize128x64, ssd1306::mode::BasicMode>, + controls: DisplayControls, + is_on: bool, + last_brightness: u8 +} + impl SsdOutput { pub fn get_pixel(&mut self, coords: Coordinates) -> Option { if coords.x < 0 || coords.y < 0 || coords.x >= 128 || coords.y >= 64 { @@ -107,7 +111,7 @@ impl SsdOutput { let bit = (coords.y % 8) as u8; //info!("sample {coords:?} {idx}"); let pixref = &mut self.pixbuf[idx] as *mut u8; - Some(SsdPixel(pixref, bit, coords)) + Some(SsdPixel { byte: pixref, bit, coords }) } pub async fn new(i2c: I2c<'static, Async>, mut reset_pin: Output<'static>, controls: DisplayControls) -> Self {