Skip to content

Commit

Permalink
Some general cleanup, address clear conflict (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani authored Jun 1, 2023
1 parent 7271f39 commit 23c6887
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 36 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
41 changes: 12 additions & 29 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -412,7 +411,7 @@ where
}

// SPI-only reset
impl<SPI, DC, SIZE, MODE> Ssd1306<SPIInterfaceNoCS<SPI, DC>, SIZE, MODE> {
impl<DI, SIZE, MODE> Ssd1306<DI, SIZE, MODE> {
/// Reset the display.
pub fn reset<RST, DELAY>(
&mut self,
Expand All @@ -423,34 +422,18 @@ impl<SPI, DC, SIZE, MODE> Ssd1306<SPIInterfaceNoCS<SPI, DC>, SIZE, MODE> {
RST: OutputPin,
DELAY: DelayMs<u8>,
{
inner_reset(rst, delay).map_err(Error::Pin)
}
}
fn inner_reset<RST, DELAY>(rst: &mut RST, delay: &mut DELAY) -> Result<(), RST::Error>
where
RST: OutputPin,
DELAY: DelayMs<u8>,
{
rst.set_high()?;
delay.delay_ms(1);
rst.set_low()?;
delay.delay_ms(10);
rst.set_high()
}

// SPI-only reset
impl<SPI, DC, CS, SIZE, MODE> Ssd1306<SPIInterface<SPI, DC, CS>, SIZE, MODE> {
/// Reset the display.
pub fn reset<RST, DELAY>(
&mut self,
rst: &mut RST,
delay: &mut DELAY,
) -> Result<(), Error<Infallible, RST::Error>>
where
RST: OutputPin,
DELAY: DelayMs<u8>,
{
inner_reset(rst, delay).map_err(Error::Pin)
}
}

fn inner_reset<RST, DELAY>(rst: &mut RST, delay: &mut DELAY) -> Result<(), RST::Error>
where
RST: OutputPin,
DELAY: DelayMs<u8>,
{
rst.set_high()?;
delay.delay_ms(1);
rst.set_low()?;
delay.delay_ms(10);
rst.set_high()
}
19 changes: 13 additions & 6 deletions src/mode/buffered_graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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")]
Expand Down

0 comments on commit 23c6887

Please sign in to comment.