Skip to content

Commit 23c6887

Browse files
authored
Some general cleanup, address clear conflict (#185)
1 parent 7271f39 commit 23c6887

File tree

4 files changed

+27
-36
lines changed

4 files changed

+27
-36
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
- **(breaking)** [#184](https://github.com/jamwaffles/ssd1306/pull/184) Increased MSRV to 1.61.0
2020
- **(breaking)** [#179](https://github.com/jamwaffles/ssd1306/pull/179) Changed `Ssd1306::reset` signature.
2121
- [#181](https://github.com/jamwaffles/ssd1306/pull/181) Update embedded-graphics-core dependency to 0.4
22+
- **(breaking)** [#185](https://github.com/jamwaffles/ssd1306/pull/185) The inherent `BufferedGraphicsMode::clear` has been renamed to `clear_buffer`.
23+
- [#185](https://github.com/jamwaffles/ssd1306/pull/185) Some methods no longer require `DI: WriteOnlyDataCommand`.
2224

2325
## [0.7.1] - 2022-08-15
2426

src/command.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use display_interface::{DataFormat::U8, DisplayError, WriteOnlyDataCommand};
88
99
/// Commands
1010
#[derive(Debug, Copy, Clone)]
11-
#[allow(dead_code)]
1211
pub enum Command {
1312
/// Set contrast. Higher number is higher contrast. Default = 0x7F
1413
Contrast(u8),

src/lib.rs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ use crate::mode::BasicMode;
126126
use brightness::Brightness;
127127
use command::{AddrMode, Command, VcomhLevel};
128128
use display_interface::{DataFormat::U8, DisplayError, WriteOnlyDataCommand};
129-
use display_interface_spi::{SPIInterface, SPIInterfaceNoCS};
130129
use embedded_hal::{blocking::delay::DelayMs, digital::v2::OutputPin};
131130
use error::Error;
132131
use mode::{BufferedGraphicsMode, TerminalMode};
@@ -412,7 +411,7 @@ where
412411
}
413412

414413
// SPI-only reset
415-
impl<SPI, DC, SIZE, MODE> Ssd1306<SPIInterfaceNoCS<SPI, DC>, SIZE, MODE> {
414+
impl<DI, SIZE, MODE> Ssd1306<DI, SIZE, MODE> {
416415
/// Reset the display.
417416
pub fn reset<RST, DELAY>(
418417
&mut self,
@@ -423,34 +422,18 @@ impl<SPI, DC, SIZE, MODE> Ssd1306<SPIInterfaceNoCS<SPI, DC>, SIZE, MODE> {
423422
RST: OutputPin,
424423
DELAY: DelayMs<u8>,
425424
{
426-
inner_reset(rst, delay).map_err(Error::Pin)
427-
}
428-
}
425+
fn inner_reset<RST, DELAY>(rst: &mut RST, delay: &mut DELAY) -> Result<(), RST::Error>
426+
where
427+
RST: OutputPin,
428+
DELAY: DelayMs<u8>,
429+
{
430+
rst.set_high()?;
431+
delay.delay_ms(1);
432+
rst.set_low()?;
433+
delay.delay_ms(10);
434+
rst.set_high()
435+
}
429436

430-
// SPI-only reset
431-
impl<SPI, DC, CS, SIZE, MODE> Ssd1306<SPIInterface<SPI, DC, CS>, SIZE, MODE> {
432-
/// Reset the display.
433-
pub fn reset<RST, DELAY>(
434-
&mut self,
435-
rst: &mut RST,
436-
delay: &mut DELAY,
437-
) -> Result<(), Error<Infallible, RST::Error>>
438-
where
439-
RST: OutputPin,
440-
DELAY: DelayMs<u8>,
441-
{
442437
inner_reset(rst, delay).map_err(Error::Pin)
443438
}
444439
}
445-
446-
fn inner_reset<RST, DELAY>(rst: &mut RST, delay: &mut DELAY) -> Result<(), RST::Error>
447-
where
448-
RST: OutputPin,
449-
DELAY: DelayMs<u8>,
450-
{
451-
rst.set_high()?;
452-
delay.delay_ms(1);
453-
rst.set_low()?;
454-
delay.delay_ms(10);
455-
rst.set_high()
456-
}

src/mode/buffered_graphics.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ where
5858

5959
/// Initialise and clear the display in graphics mode.
6060
fn init(&mut self) -> Result<(), DisplayError> {
61-
self.clear();
61+
self.clear_impl(false);
6262
self.init_with_addr_mode(AddrMode::Horizontal)
6363
}
6464
}
@@ -68,11 +68,8 @@ where
6868
DI: WriteOnlyDataCommand,
6969
SIZE: DisplaySize,
7070
{
71-
/// Clear the display buffer. You need to call `disp.flush()` for any effect on the screen
72-
pub fn clear(&mut self) {
73-
for b in self.mode.buffer.as_mut() {
74-
*b = 0;
75-
}
71+
fn clear_impl(&mut self, value: bool) {
72+
self.mode.buffer.as_mut().fill(value as u8);
7673

7774
let (width, height) = self.dimensions();
7875
self.mode.min_x = 0;
@@ -81,6 +78,11 @@ where
8178
self.mode.max_y = height - 1;
8279
}
8380

81+
/// Clear the underlying framebuffer. You need to call `disp.flush()` for any effect on the screen.
82+
pub fn clear_buffer(&mut self) {
83+
self.clear_impl(false);
84+
}
85+
8486
/// Write out data to a display.
8587
///
8688
/// This only updates the parts of the display that have changed since the last flush.
@@ -225,6 +227,11 @@ where
225227

226228
Ok(())
227229
}
230+
231+
fn clear(&mut self, color: Self::Color) -> Result<(), Self::Error> {
232+
self.clear_impl(color.is_on());
233+
Ok(())
234+
}
228235
}
229236

230237
#[cfg(feature = "graphics")]

0 commit comments

Comments
 (0)