diff --git a/mipidsi/CHANGELOG.md b/mipidsi/CHANGELOG.md index 6f77f4c..1d41466 100644 --- a/mipidsi/CHANGELOG.md +++ b/mipidsi/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- added `Display::set_pixels_from_buffer` to allow high performance display writes + ## [v0.8.0] - 2024-05-24 ### Added diff --git a/mipidsi/examples/spi-ili9486-esp32-c3/Cargo.toml b/mipidsi/examples/spi-ili9486-esp32-c3/Cargo.toml index 823a6c2..1b8166b 100644 --- a/mipidsi/examples/spi-ili9486-esp32-c3/Cargo.toml +++ b/mipidsi/examples/spi-ili9486-esp32-c3/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" [dependencies] mipidsi = { path = "../../" } hal = { package = "esp-hal", version = "0.17.0", features = ["esp32c3"] } -esp-backtrace = { version = "0.11.1", features = ["esp32c3", "panic-handler", "exception-handler", "println"] } -esp-println = { version = "0.9.1", features = ["esp32c3"] } +esp-backtrace = { version = "0.14", features = ["esp32c3", "panic-handler", "exception-handler", "println"] } +esp-println = { version = "0.12", features = ["esp32c3"] } embedded-graphics = "0.8.0" display-interface-spi = "0.5.0" fugit = "0.3.7" diff --git a/mipidsi/src/lib.rs b/mipidsi/src/lib.rs index c4436e6..871983a 100644 --- a/mipidsi/src/lib.rs +++ b/mipidsi/src/lib.rs @@ -96,8 +96,8 @@ //! ## Troubleshooting //! See [document](https://github.com/almindor/mipidsi/blob/master/docs/TROUBLESHOOTING.md) -use dcs::Dcs; -use display_interface::WriteOnlyDataCommand; +use dcs::{Dcs, WriteMemoryStart}; +use display_interface::{DataFormat, WriteOnlyDataCommand}; pub mod error; use error::Error; @@ -222,6 +222,14 @@ where /// * `ex` - x coordinate end /// * `ey` - y coordinate end /// * `colors` - anything that can provide `IntoIterator` to iterate over pixel data + ///
+ /// + /// The end values of the X and Y coordinate ranges are inclusive, and no + /// bounds checking is performed on these values. Using out of range values + /// (e.g., passing `320` instead of `319` for a 320 pixel wide display) will + /// result in undefined behavior. + /// + ///
pub fn set_pixels( &mut self, sx: u16, @@ -239,6 +247,69 @@ where Ok(()) } + /// Copies raw pixel data to a rectangular region of the framebuffer. + /// + /// This method writes the pixel data stored in the `raw_buf` slice to the + /// specified rectangular region within the display controller's + /// framebuffer. If `raw_buf` contains more data than required to fill the + /// region, writing will wrap around to the top left corner after reaching + /// the bottom right corner. + /// + ///
+ /// + /// This method is intended for advanced use cases where low level access to + /// the displays framebuffer is required for performance reasons. The + /// caller must ensure the raw pixel data in `raw_buf` has the correct + /// format and endianness. + /// + /// For all other use cases it is recommended to instead use + /// [`embedded-graphics`](https://docs.rs/embedded-graphics/latest/embedded_graphics/) + /// to draw to the display. + /// + ///
+ /// + ///
+ /// + /// The method might not work the same for all `display-interface`s and is + /// known to not work as expected when used with a + /// [`PGPIO16BitInterface`](https://docs.rs/display-interface-parallel-gpio/latest/display_interface_parallel_gpio/struct.PGPIO16BitInterface.html) + /// from the `display-interface-gpio` crate. + /// + ///
+ /// + /// # Arguments + /// + /// * `sx` - x coordinate start + /// * `sy` - y coordinate start + /// * `ex` - x coordinate end (inclusive) + /// * `ey` - y coordinate end (inclusive) + /// * `raw_buf` - `&[u8]` buffer of raw pixel data in the format expected by the display + /// + ///
+ /// + /// The end values of the X and Y coordinate ranges are inclusive, and no + /// bounds checking is performed on these values. Using out of range values + /// (e.g., passing `320` instead of `319` for a 320 pixel wide display) will + /// result in undefined behavior. + /// + ///
+ pub fn set_pixels_from_buffer( + &mut self, + sx: u16, + sy: u16, + ex: u16, + ey: u16, + raw_buf: &[u8], + ) -> Result<(), Error> { + self.set_address_window(sx, sy, ex, ey)?; + + self.dcs.write_command(WriteMemoryStart)?; + + self.dcs.di.send_data(DataFormat::U8(raw_buf))?; + + Ok(()) + } + /// Sets the vertical scroll region. /// /// The `top_fixed_area` and `bottom_fixed_area` arguments can be used to diff --git a/mipidsi/src/models.rs b/mipidsi/src/models.rs index 5662482..7236f91 100644 --- a/mipidsi/src/models.rs +++ b/mipidsi/src/models.rs @@ -2,8 +2,7 @@ use crate::{ dcs::{Dcs, SetAddressMode}, - error::Error, - error::InitError, + error::{Error, InitError}, options::ModelOptions, }; use display_interface::WriteOnlyDataCommand;