pub struct Ssd1306<DI, SIZE, MODE> { /* private fields */ }
Expand description
SSD1306 driver.
Note that some methods are only available when the display is configured in a certain mode
.
Implementations§
source§impl<DI, SIZE> Ssd1306<DI, SIZE, BufferedGraphicsMode<SIZE>>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
impl<DI, SIZE> Ssd1306<DI, SIZE, BufferedGraphicsMode<SIZE>>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
sourcepub fn clear_buffer(&mut self)
pub fn clear_buffer(&mut self)
Clear the underlying framebuffer. You need to call disp.flush()
for any effect on the screen.
sourcepub fn flush(&mut self) -> Result<(), DisplayError>
pub fn flush(&mut self) -> Result<(), DisplayError>
Write out data to a display.
This only updates the parts of the display that have changed since the last flush.
source§impl<DI, SIZE> Ssd1306<DI, SIZE, TerminalMode>where
DI: WriteOnlyDataCommand,
SIZE: TerminalDisplaySize,
impl<DI, SIZE> Ssd1306<DI, SIZE, TerminalMode>where
DI: WriteOnlyDataCommand,
SIZE: TerminalDisplaySize,
sourcepub fn clear(&mut self) -> Result<(), TerminalModeError>
pub fn clear(&mut self) -> Result<(), TerminalModeError>
Clear the display and reset the cursor to the top left corner
sourcepub fn print_char(&mut self, c: char) -> Result<(), TerminalModeError>
pub fn print_char(&mut self, c: char) -> Result<(), TerminalModeError>
Print a character to the display
sourcepub fn position(&self) -> Result<(u8, u8), TerminalModeError>
pub fn position(&self) -> Result<(u8, u8), TerminalModeError>
Get the current cursor position, in character coordinates. This is the (column, row) that the next character will be written to.
sourcepub fn set_position(
&mut self,
column: u8,
row: u8
) -> Result<(), TerminalModeError>
pub fn set_position( &mut self, column: u8, row: u8 ) -> Result<(), TerminalModeError>
Set the cursor position, in character coordinates. This is the (column, row) that the next character will be written to. If the position is out of bounds, an Err will be returned.
source§impl<DI, SIZE> Ssd1306<DI, SIZE, BasicMode>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
impl<DI, SIZE> Ssd1306<DI, SIZE, BasicMode>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
sourcepub fn clear(&mut self) -> Result<(), DisplayError>
pub fn clear(&mut self) -> Result<(), DisplayError>
Clear the display.
source§impl<DI, SIZE> Ssd1306<DI, SIZE, BasicMode>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
impl<DI, SIZE> Ssd1306<DI, SIZE, BasicMode>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
sourcepub fn new(interface: DI, size: SIZE, rotation: DisplayRotation) -> Self
pub fn new(interface: DI, size: SIZE, rotation: DisplayRotation) -> Self
Create a basic SSD1306 interface.
Use the into_*_mode
methods to enable more functionality.
source§impl<DI, SIZE, MODE> Ssd1306<DI, SIZE, MODE>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
impl<DI, SIZE, MODE> Ssd1306<DI, SIZE, MODE>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
sourcepub fn into_buffered_graphics_mode(
self
) -> Ssd1306<DI, SIZE, BufferedGraphicsMode<SIZE>>
pub fn into_buffered_graphics_mode( self ) -> Ssd1306<DI, SIZE, BufferedGraphicsMode<SIZE>>
Convert the display into a buffered graphics mode, supporting embedded-graphics.
See BufferedGraphicsMode for more information.
sourcepub fn into_terminal_mode(self) -> Ssd1306<DI, SIZE, TerminalMode>
pub fn into_terminal_mode(self) -> Ssd1306<DI, SIZE, TerminalMode>
Convert the display into a text-only, terminal-like mode.
See TerminalMode for more information.
sourcepub fn init_with_addr_mode(
&mut self,
mode: AddrMode
) -> Result<(), DisplayError>
pub fn init_with_addr_mode( &mut self, mode: AddrMode ) -> Result<(), DisplayError>
Initialise the display in one of the available addressing modes.
sourcepub fn set_addr_mode(&mut self, mode: AddrMode) -> Result<(), DisplayError>
pub fn set_addr_mode(&mut self, mode: AddrMode) -> Result<(), DisplayError>
Change the addressing mode
sourcepub fn bounded_draw(
&mut self,
buffer: &[u8],
disp_width: usize,
upper_left: (u8, u8),
lower_right: (u8, u8)
) -> Result<(), DisplayError>
pub fn bounded_draw( &mut self, buffer: &[u8], disp_width: usize, upper_left: (u8, u8), lower_right: (u8, u8) ) -> Result<(), DisplayError>
Send the data to the display for drawing at the current position in the framebuffer
and advance the position accordingly. Cf. set_draw_area
to modify the affected area by
this method.
This method takes advantage of a bounding box for faster writes.
sourcepub fn draw(&mut self, buffer: &[u8]) -> Result<(), DisplayError>
pub fn draw(&mut self, buffer: &[u8]) -> Result<(), DisplayError>
Send a raw buffer to the display.
sourcepub fn dimensions(&self) -> (u8, u8)
pub fn dimensions(&self) -> (u8, u8)
Get display dimensions, taking into account the current rotation of the display
use ssd1306::{mode::TerminalMode, prelude::*, Ssd1306};
let mut display = Ssd1306::new(
interface,
DisplaySize128x64,
DisplayRotation::Rotate0,
).into_terminal_mode();
assert_eq!(display.dimensions(), (128, 64));
let mut rotated_display = Ssd1306::new(
interface,
DisplaySize128x64,
DisplayRotation::Rotate90,
).into_terminal_mode();
assert_eq!(rotated_display.dimensions(), (64, 128));
sourcepub fn rotation(&self) -> DisplayRotation
pub fn rotation(&self) -> DisplayRotation
Get the display rotation.
sourcepub fn set_rotation(
&mut self,
rotation: DisplayRotation
) -> Result<(), DisplayError>
pub fn set_rotation( &mut self, rotation: DisplayRotation ) -> Result<(), DisplayError>
Set the display rotation.
sourcepub fn set_mirror(&mut self, mirror: bool) -> Result<(), DisplayError>
pub fn set_mirror(&mut self, mirror: bool) -> Result<(), DisplayError>
Set mirror enabled/disabled.
sourcepub fn set_brightness(
&mut self,
brightness: Brightness
) -> Result<(), DisplayError>
pub fn set_brightness( &mut self, brightness: Brightness ) -> Result<(), DisplayError>
Change the display brightness.
sourcepub fn set_display_on(&mut self, on: bool) -> Result<(), DisplayError>
pub fn set_display_on(&mut self, on: bool) -> Result<(), DisplayError>
Turn the display on or off. The display can be drawn to and retains all of its memory even while off.
sourcepub fn set_draw_area(
&mut self,
start: (u8, u8),
end: (u8, u8)
) -> Result<(), DisplayError>
pub fn set_draw_area( &mut self, start: (u8, u8), end: (u8, u8) ) -> Result<(), DisplayError>
Set the position in the framebuffer of the display limiting where any sent data should be
drawn. This method can be used for changing the affected area on the screen as well
as (re-)setting the start point of the next draw
call.
sourcepub fn set_column(&mut self, column: u8) -> Result<(), DisplayError>
pub fn set_column(&mut self, column: u8) -> Result<(), DisplayError>
Set the column address in the framebuffer of the display where any sent data should be drawn.
sourcepub fn set_row(&mut self, row: u8) -> Result<(), DisplayError>
pub fn set_row(&mut self, row: u8) -> Result<(), DisplayError>
Set the page address (row 8px high) in the framebuffer of the display where any sent data should be drawn.
Note that the parameter is in pixels, but the page will be set to the start of the 8px row which contains the passed-in row.
sourcepub fn set_invert(&mut self, invert: bool) -> Result<(), DisplayError>
pub fn set_invert(&mut self, invert: bool) -> Result<(), DisplayError>
Set the screen pixel on/off inversion
Trait Implementations§
source§impl<DI, SIZE> DisplayConfig for Ssd1306<DI, SIZE, BasicMode>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
impl<DI, SIZE> DisplayConfig for Ssd1306<DI, SIZE, BasicMode>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
source§fn set_rotation(&mut self, rot: DisplayRotation) -> Result<(), DisplayError>
fn set_rotation(&mut self, rot: DisplayRotation) -> Result<(), DisplayError>
Set the display rotation.
§type Error = DisplayError
type Error = DisplayError
source§impl<DI, SIZE> DisplayConfig for Ssd1306<DI, SIZE, BufferedGraphicsMode<SIZE>>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
impl<DI, SIZE> DisplayConfig for Ssd1306<DI, SIZE, BufferedGraphicsMode<SIZE>>where
DI: WriteOnlyDataCommand,
SIZE: DisplaySize,
source§fn set_rotation(&mut self, rot: DisplayRotation) -> Result<(), DisplayError>
fn set_rotation(&mut self, rot: DisplayRotation) -> Result<(), DisplayError>
Set the display rotation
This method resets the cursor but does not clear the screen.
source§fn init(&mut self) -> Result<(), DisplayError>
fn init(&mut self) -> Result<(), DisplayError>
Initialise and clear the display in graphics mode.
§type Error = DisplayError
type Error = DisplayError
source§impl<DI, SIZE> DisplayConfig for Ssd1306<DI, SIZE, TerminalMode>where
DI: WriteOnlyDataCommand,
SIZE: TerminalDisplaySize,
impl<DI, SIZE> DisplayConfig for Ssd1306<DI, SIZE, TerminalMode>where
DI: WriteOnlyDataCommand,
SIZE: TerminalDisplaySize,
source§fn set_rotation(
&mut self,
rot: DisplayRotation
) -> Result<(), TerminalModeError>
fn set_rotation( &mut self, rot: DisplayRotation ) -> Result<(), TerminalModeError>
Set the display rotation
This method resets the cursor but does not clear the screen.
source§fn init(&mut self) -> Result<(), TerminalModeError>
fn init(&mut self) -> Result<(), TerminalModeError>
Initialise the display in page mode (i.e. a byte walks down a column of 8 pixels) with column 0 on the left and column (SIZE::Width::U8 - 1) on the right, but no automatic line wrapping.