pub struct Ssd1331<RST, DC, SPI> { /* private fields */ }
Expand description
The implementation of the driver.
Can be used with embedded-graphics
crate in async frameworks (e.g.
Embassy). Since the embedded-graphics
API is synchronous, the driver
assumes use of a framebuffer, and provides an async method to transfer its
contents to the display. Full-size framebuffer requires ~12Kb (6Kb for
8-bit color mode). The driver allows using a smaller buffer and addressing
a sub-area of the display; for example, it’s possible to draw monospaced
text one character at a time, or mix text and graphics areas.
The driver dutifully propagates all errors from the HAL, but the display
controller is stateful and the driver doesn’t attempt to return it to a
known good state after an error. You can call init()
to hard-reset the
display and reinitialize the driver after an error.
Implementations§
Source§impl<RST, DC, SPI, PinE, SpiE> Ssd1331<RST, DC, SPI>
impl<RST, DC, SPI, PinE, SpiE> Ssd1331<RST, DC, SPI>
Sourcepub async fn new(
data_mapping: Config,
rst: RST,
dc: DC,
spi: SPI,
delay: &mut impl DelayNs,
) -> Result<Self, Error<PinE, SpiE>>
pub async fn new( data_mapping: Config, rst: RST, dc: DC, spi: SPI, delay: &mut impl DelayNs, ) -> Result<Self, Error<PinE, SpiE>>
Creates a new driver instance and initializes the display.
Requires GPIO output pins connected to RST and DC pins on the display, and a SPI device with SDO and SCK outputs connected to the display. The CS (chip select) pin of the display can be controlled by the SPI device, or you can simply tie it low, and pass a DummyPin to the SPI device. SPI bus should be configured to MODE_0, MSB first (usually the default). Frequencies up to 50 MHz seem to work fine, even though the display datasheet specifies ~6 MHz max.
Sourcepub async fn init(
&mut self,
delay: &mut impl DelayNs,
) -> Result<(), Error<PinE, SpiE>>
pub async fn init( &mut self, delay: &mut impl DelayNs, ) -> Result<(), Error<PinE, SpiE>>
Hard-resets and re-initializes the display.
Also clears the display RAM. This will take a few milliseconds. Instances returned by Self::new are already initialized.
Sourcepub fn release(self) -> (RST, DC, SPI)
pub fn release(self) -> (RST, DC, SPI)
Consumes the driver and returns the peripherals to you.
Sourcepub async fn write_pixels(
&mut self,
data: &[u8],
bit_depth: BitDepth,
area: Rectangle,
) -> Result<(), Error<PinE, SpiE>>
pub async fn write_pixels( &mut self, data: &[u8], bit_depth: BitDepth, area: Rectangle, ) -> Result<(), Error<PinE, SpiE>>
Sends the data to the given area of the display’s frame buffer.
The area
is in your logical display coordinates; e.g if you use
Config::ccw90, the logical size is (64, 96) and the (0, 0) is the
top-right corner of the un-rotated physical screen.
You can fill the area using a smaller buffer by repeatedly calling
this method and passing the same area
. Sending more data than fits
in the area will wrap around and overwrite the beginning of the area.
§Panics
If the area is empty or not completely contained within the display bounds.