diff --git a/CHANGELOG.md b/CHANGELOG.md index 87100e77..f45aff1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ - **(breaking)** [#184](https://github.com/jamwaffles/ssd1306/pull/184) Increased MSRV to 1.61.0 - **(breaking)** [#179](https://github.com/jamwaffles/ssd1306/pull/179) Changed `Ssd1306::reset` signature. - [#181](https://github.com/jamwaffles/ssd1306/pull/181) Update embedded-graphics-core dependency to 0.4 +- **(breaking)** [#185](https://github.com/jamwaffles/ssd1306/pull/185) The inherent `BufferedGraphicsMode::clear` has been renamed to `clear_buffer`. +- [#185](https://github.com/jamwaffles/ssd1306/pull/185) Some methods no longer require `DI: WriteOnlyDataCommand`. ## [0.7.1] - 2022-08-15 diff --git a/src/command.rs b/src/command.rs index f980aa23..7682264f 100644 --- a/src/command.rs +++ b/src/command.rs @@ -8,7 +8,6 @@ use display_interface::{DataFormat::U8, DisplayError, WriteOnlyDataCommand}; /// Commands #[derive(Debug, Copy, Clone)] -#[allow(dead_code)] pub enum Command { /// Set contrast. Higher number is higher contrast. Default = 0x7F Contrast(u8), diff --git a/src/lib.rs b/src/lib.rs index d56ff51a..d77015a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,7 +126,6 @@ use crate::mode::BasicMode; use brightness::Brightness; use command::{AddrMode, Command, VcomhLevel}; use display_interface::{DataFormat::U8, DisplayError, WriteOnlyDataCommand}; -use display_interface_spi::{SPIInterface, SPIInterfaceNoCS}; use embedded_hal::{blocking::delay::DelayMs, digital::v2::OutputPin}; use error::Error; use mode::{BufferedGraphicsMode, TerminalMode}; @@ -412,7 +411,7 @@ where } // SPI-only reset -impl Ssd1306, SIZE, MODE> { +impl Ssd1306 { /// Reset the display. pub fn reset( &mut self, @@ -423,34 +422,18 @@ impl Ssd1306, SIZE, MODE> { RST: OutputPin, DELAY: DelayMs, { - inner_reset(rst, delay).map_err(Error::Pin) - } -} + fn inner_reset(rst: &mut RST, delay: &mut DELAY) -> Result<(), RST::Error> + where + RST: OutputPin, + DELAY: DelayMs, + { + rst.set_high()?; + delay.delay_ms(1); + rst.set_low()?; + delay.delay_ms(10); + rst.set_high() + } -// SPI-only reset -impl Ssd1306, SIZE, MODE> { - /// Reset the display. - pub fn reset( - &mut self, - rst: &mut RST, - delay: &mut DELAY, - ) -> Result<(), Error> - where - RST: OutputPin, - DELAY: DelayMs, - { inner_reset(rst, delay).map_err(Error::Pin) } } - -fn inner_reset(rst: &mut RST, delay: &mut DELAY) -> Result<(), RST::Error> -where - RST: OutputPin, - DELAY: DelayMs, -{ - rst.set_high()?; - delay.delay_ms(1); - rst.set_low()?; - delay.delay_ms(10); - rst.set_high() -} diff --git a/src/mode/buffered_graphics.rs b/src/mode/buffered_graphics.rs index f86dc91e..6a9cfb66 100644 --- a/src/mode/buffered_graphics.rs +++ b/src/mode/buffered_graphics.rs @@ -58,7 +58,7 @@ where /// Initialise and clear the display in graphics mode. fn init(&mut self) -> Result<(), DisplayError> { - self.clear(); + self.clear_impl(false); self.init_with_addr_mode(AddrMode::Horizontal) } } @@ -68,11 +68,8 @@ where DI: WriteOnlyDataCommand, SIZE: DisplaySize, { - /// Clear the display buffer. You need to call `disp.flush()` for any effect on the screen - pub fn clear(&mut self) { - for b in self.mode.buffer.as_mut() { - *b = 0; - } + fn clear_impl(&mut self, value: bool) { + self.mode.buffer.as_mut().fill(value as u8); let (width, height) = self.dimensions(); self.mode.min_x = 0; @@ -81,6 +78,11 @@ where self.mode.max_y = height - 1; } + /// Clear the underlying framebuffer. You need to call `disp.flush()` for any effect on the screen. + pub fn clear_buffer(&mut self) { + self.clear_impl(false); + } + /// Write out data to a display. /// /// This only updates the parts of the display that have changed since the last flush. @@ -225,6 +227,11 @@ where Ok(()) } + + fn clear(&mut self, color: Self::Color) -> Result<(), Self::Error> { + self.clear_impl(color.is_on()); + Ok(()) + } } #[cfg(feature = "graphics")]