diff --git a/mipidsi/CHANGELOG.md b/mipidsi/CHANGELOG.md index 9d2ccbb..4737131 100644 --- a/mipidsi/CHANGELOG.md +++ b/mipidsi/CHANGELOG.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - removed `Model::default_options` - bumped MSRV to `v1.75` - fixed `DrawTarget::fill_contiguous` for images that overlap the edge of the framebuffer +- replaced model specific `Builder` constructors (like `Builder::gc9a01`) with one generic `Builder::new` constructor ### Removed diff --git a/mipidsi/docs/MIGRATION.md b/mipidsi/docs/MIGRATION.md index b163016..9b52ea0 100644 --- a/mipidsi/docs/MIGRATION.md +++ b/mipidsi/docs/MIGRATION.md @@ -1,5 +1,20 @@ # Migration guide for MIPIDSI driver +## v0.7 -> 0.8 + +### Users + +* The model specific constructors (like `Builder::ili9341_rgb565`) have been removed. Use the generic `Builder::new` constructor instead: + ```rust + // 0.7 + use mipidsi::Builder; + let display = Builder::ili9341_rgb565(di).init(&mut delay, Some(rst))?; + + // 0.8 + use mipidsi::{Builder, models::ILI9341Rgb565}; + let display = Builder::new(ILI9341Rgb565, di).init(&mut delay, Some(rst))?; + ``` + ## v0.6 -> 0.7 No breaking changes. diff --git a/mipidsi/src/builder.rs b/mipidsi/src/builder.rs index c63a22f..e6c1c9f 100644 --- a/mipidsi/src/builder.rs +++ b/mipidsi/src/builder.rs @@ -14,12 +14,12 @@ use crate::options::{ColorInversion, ColorOrder, ModelOptions, Orientation, Refr /// # Examples /// /// ``` -/// use mipidsi::{Builder, options::ColorOrder}; +/// use mipidsi::{Builder, options::ColorOrder, models::ILI9342CRgb565}; /// /// # let di = mipidsi::_mock::MockDisplayInterface; /// # let rst = mipidsi::_mock::MockOutputPin; /// # let mut delay = mipidsi::_mock::MockDelay; -/// let mut display = Builder::ili9342c_rgb565(di) +/// let mut display = Builder::new(ILI9342CRgb565, di) /// .with_color_order(ColorOrder::Bgr) /// .with_display_size(320, 240) /// .init(&mut delay, Some(rst)).unwrap(); @@ -40,18 +40,9 @@ where MODEL: Model, { /// - /// Constructs a new builder from given [WriteOnlyDataCommand], [Model] - /// and [ModelOptions]. For use by [Model] helpers, not public + /// Constructs a new builder for given [Model]. /// - pub(crate) fn new(di: DI, model: MODEL, options: ModelOptions) -> Self { - Self { di, model, options } - } - - /// - /// Constructs a new builder for given [Model] using the model's - /// `default_options` - /// - pub fn with_model(di: DI, model: MODEL) -> Self { + pub fn new(model: MODEL, di: DI) -> Self { Self { di, model, diff --git a/mipidsi/src/lib.rs b/mipidsi/src/lib.rs index d31e898..36f11ca 100644 --- a/mipidsi/src/lib.rs +++ b/mipidsi/src/lib.rs @@ -22,7 +22,7 @@ //! **For the ili9486 display, using the SPI interface with no chip select:** //! ``` //! use display_interface_spi::SPIInterface; // Provides the builder for DisplayInterface -//! use mipidsi::Builder; // Provides the builder for Display +//! use mipidsi::{Builder, models::ILI9486Rgb666}; // Provides the builder for Display //! use embedded_graphics::{prelude::*, pixelcolor::Rgb666}; // Provides the required color type //! //! /* Define the SPI interface as the variable `spi` */ @@ -37,7 +37,7 @@ //! let di = SPIInterface::new(spi, dc); //! //! // Create the ILI9486 display driver from the display interface and optional RST pin -//! let mut display = Builder::ili9486_rgb666(di) +//! let mut display = Builder::new(ILI9486Rgb666, di) //! .init(&mut delay, Some(rst)).unwrap(); //! //! // Clear the display to black @@ -50,7 +50,7 @@ //! // Provides the builder for DisplayInterface //! use display_interface_parallel_gpio::{Generic8BitBus, PGPIO8BitInterface}; //! // Provides the builder for Display -//! use mipidsi::Builder; +//! use mipidsi::{Builder, models::ILI9341Rgb666}; //! // Provides the required color type //! use embedded_graphics::{prelude::*, pixelcolor::Rgb666}; //! @@ -77,7 +77,7 @@ //! let di = PGPIO8BitInterface::new(bus, dc, wr); //! //! // Create the ILI9341 display driver from the display interface with the RGB666 color space -//! let mut display = Builder::ili9341_rgb666(di) +//! let mut display = Builder::new(ILI9341Rgb666, di) //! .with_color_order(mipidsi::options::ColorOrder::Bgr) //! .init(&mut delay, Some(rst)).unwrap(); //! @@ -376,7 +376,7 @@ pub mod _mock { use crate::{models::ILI9341Rgb565, Builder, Display}; pub fn new_mock_display() -> Display { - Builder::ili9341_rgb565(MockDisplayInterface) + Builder::new(ILI9341Rgb565, MockDisplayInterface) .init(&mut MockDelay, Some(MockOutputPin)) .unwrap() } diff --git a/mipidsi/src/models/gc9a01.rs b/mipidsi/src/models/gc9a01.rs index 72d439a..f15d988 100644 --- a/mipidsi/src/models/gc9a01.rs +++ b/mipidsi/src/models/gc9a01.rs @@ -7,10 +7,8 @@ use crate::{ BitsPerPixel, ExitSleepMode, PixelFormat, SetAddressMode, SetDisplayOn, SetInvertMode, SetPixelFormat, SoftReset, WriteMemoryStart, }, - error::Error, - error::InitError, + error::{Error, InitError}, options::ModelOptions, - Builder, }; use super::{Dcs, Model}; @@ -145,22 +143,3 @@ impl Model for GC9A01 { Ok(()) } } - -// simplified constructor on Display - -impl Builder -where - DI: WriteOnlyDataCommand, -{ - /// Creates a new display builder for GC9A01 displays in Rgb565 color mode. - /// - /// The default framebuffer size is 240x240 pixels and display size is 240x240 pixels. - /// - /// # Arguments - /// - /// * `di` - a [display interface](WriteOnlyDataCommand) for communicating with the display - /// - pub fn gc9a01(di: DI) -> Self { - Self::with_model(di, GC9A01) - } -} diff --git a/mipidsi/src/models/ili9341.rs b/mipidsi/src/models/ili9341.rs index 5131705..b31293f 100644 --- a/mipidsi/src/models/ili9341.rs +++ b/mipidsi/src/models/ili9341.rs @@ -4,11 +4,9 @@ use embedded_hal::{delay::DelayNs, digital::OutputPin}; use crate::{ dcs::{BitsPerPixel, Dcs, PixelFormat, SetAddressMode, SoftReset}, - error::Error, - error::InitError, + error::{Error, InitError}, models::{ili934x, Model}, options::ModelOptions, - Builder, }; /// ILI9341 display in Rgb565 color mode. @@ -84,43 +82,3 @@ impl Model for ILI9341Rgb666 { ili934x::write_pixels_rgb666(dcs, colors) } } - -// simplified constructor for Display - -impl Builder -where - DI: WriteOnlyDataCommand, -{ - /// Creates a new display builder for an ILI9341 display in Rgb565 color mode. - /// - /// The default framebuffer size and display size is 240x320 pixels. - /// - /// # Limitations - /// - /// The Rgb565 color mode is not supported for displays with SPI connection. - /// - /// # Arguments - /// - /// * `di` - a [display interface](WriteOnlyDataCommand) for communicating with the display - /// - pub fn ili9341_rgb565(di: DI) -> Self { - Self::with_model(di, ILI9341Rgb565) - } -} - -impl Builder -where - DI: WriteOnlyDataCommand, -{ - /// Creates a new display builder for an ILI9341 display in Rgb565 color mode. - /// - /// The default framebuffer size and display size is 240x320 pixels. - /// - /// # Arguments - /// - /// * `di` - a [display interface](WriteOnlyDataCommand) for communicating with the display - /// - pub fn ili9341_rgb666(di: DI) -> Self { - Self::with_model(di, ILI9341Rgb666) - } -} diff --git a/mipidsi/src/models/ili9342c.rs b/mipidsi/src/models/ili9342c.rs index 72d4869..f1e6602 100644 --- a/mipidsi/src/models/ili9342c.rs +++ b/mipidsi/src/models/ili9342c.rs @@ -4,11 +4,9 @@ use embedded_hal::{delay::DelayNs, digital::OutputPin}; use crate::{ dcs::{BitsPerPixel, Dcs, PixelFormat, SetAddressMode, SoftReset}, - error::Error, - error::InitError, + error::{Error, InitError}, models::{ili934x, Model}, options::ModelOptions, - Builder, }; /// ILI9342C display in Rgb565 color mode. @@ -84,43 +82,3 @@ impl Model for ILI9342CRgb666 { ili934x::write_pixels_rgb666(dcs, colors) } } - -// simplified constructor for Display - -impl Builder -where - DI: WriteOnlyDataCommand, -{ - /// Creates a new display builder for an ILI9342C display in Rgb565 color mode. - /// - /// The default framebuffer size and display size is 320x240 pixels. - /// - /// # Limitations - /// - /// The Rgb565 color mode is not supported for displays with SPI connection. - /// - /// # Arguments - /// - /// * `di` - a [display interface](WriteOnlyDataCommand) for communicating with the display - /// - pub fn ili9342c_rgb565(di: DI) -> Self { - Self::with_model(di, ILI9342CRgb565) - } -} - -impl Builder -where - DI: WriteOnlyDataCommand, -{ - /// Creates a new display builder for an ILI9342C display in Rgb666 color mode. - /// - /// The default framebuffer size and display size is 320x240 - /// - /// # Arguments - /// - /// * `di` - a [display interface](WriteOnlyDataCommand) for communicating with the display - /// - pub fn ili9342c_rgb666(di: DI) -> Self { - Self::with_model(di, ILI9342CRgb666) - } -} diff --git a/mipidsi/src/models/ili9486.rs b/mipidsi/src/models/ili9486.rs index 45707e4..b745f6e 100644 --- a/mipidsi/src/models/ili9486.rs +++ b/mipidsi/src/models/ili9486.rs @@ -10,10 +10,8 @@ use crate::{ BitsPerPixel, Dcs, EnterNormalMode, ExitSleepMode, PixelFormat, SetAddressMode, SetDisplayOn, SetInvertMode, SetPixelFormat, SoftReset, WriteMemoryStart, }, - error::Error, - error::InitError, + error::{Error, InitError}, options::ModelOptions, - Builder, }; use super::Model; @@ -108,46 +106,6 @@ impl Model for ILI9486Rgb666 { } } -// simplified constructor for Display - -impl Builder -where - DI: WriteOnlyDataCommand, -{ - /// Creates a new display builder for an ILI9486 display in Rgb565 color mode. - /// - /// The default framebuffer size and display size is 320x480 pixels. - /// - /// # Limitations - /// - /// The Rgb565 color mode is not supported for displays with SPI connection. - /// - /// # Arguments - /// - /// * `di` - a [display interface](WriteOnlyDataCommand) for communicating with the display - /// - pub fn ili9486_rgb565(di: DI) -> Self { - Self::with_model(di, ILI9486Rgb565) - } -} - -impl Builder -where - DI: WriteOnlyDataCommand, -{ - /// Creates a new display builder for ILI9486 displays in Rgb666 color mode. - /// - /// The default framebuffer size and display size is 320x480 pixels. - /// - /// # Arguments - /// - /// * `di` - a [display interface](WriteOnlyDataCommand) for communicating with the display - /// - pub fn ili9486_rgb666(di: DI) -> Self { - Self::with_model(di, ILI9486Rgb666) - } -} - // common init for all color format models fn init_common( dcs: &mut Dcs, diff --git a/mipidsi/src/models/st7735s.rs b/mipidsi/src/models/st7735s.rs index e8b3ca2..b72748c 100644 --- a/mipidsi/src/models/st7735s.rs +++ b/mipidsi/src/models/st7735s.rs @@ -4,17 +4,14 @@ use embedded_hal::{delay::DelayNs, digital::OutputPin}; use crate::{ dcs::{ - BitsPerPixel, ExitSleepMode, PixelFormat, SetAddressMode, SetDisplayOn, SetInvertMode, + BitsPerPixel, Dcs, ExitSleepMode, PixelFormat, SetAddressMode, SetDisplayOn, SetInvertMode, SetPixelFormat, SoftReset, WriteMemoryStart, }, - error::Error, - error::InitError, + error::{Error, InitError}, + models::Model, options::ModelOptions, - Builder, }; -use super::{Dcs, Model}; - /// ST7735s display in Rgb565 color mode. pub struct ST7735s; @@ -93,22 +90,3 @@ impl Model for ST7735s { Ok(()) } } - -// simplified constructor on Display - -impl Builder -where - DI: WriteOnlyDataCommand, -{ - /// Creates a new display builder for ST7735s displays in Rgb565 color mode. - /// - /// The default framebuffer size is 132x162 pixels and display size is 80x160 pixels. - /// - /// # Arguments - /// - /// * `di` - a [display interface](WriteOnlyDataCommand) for communicating with the display - /// - pub fn st7735s(di: DI) -> Self { - Self::with_model(di, ST7735s) - } -} diff --git a/mipidsi/src/models/st7789.rs b/mipidsi/src/models/st7789.rs index a65837f..e74a3a4 100644 --- a/mipidsi/src/models/st7789.rs +++ b/mipidsi/src/models/st7789.rs @@ -7,16 +7,11 @@ use crate::{ BitsPerPixel, Dcs, EnterNormalMode, ExitSleepMode, PixelFormat, SetAddressMode, SetDisplayOn, SetInvertMode, SetPixelFormat, SoftReset, WriteMemoryStart, }, - error::Error, - error::InitError, + error::{Error, InitError}, + models::Model, options::ModelOptions, }; -use super::Model; - -/// Module containing all ST7789 variants. -mod variants; - /// ST7789 display in Rgb565 color mode. /// /// Interfaces implemented by the [display-interface](https://crates.io/crates/display-interface) are supported. diff --git a/mipidsi/src/models/st7789/variants.rs b/mipidsi/src/models/st7789/variants.rs deleted file mode 100644 index 632a843..0000000 --- a/mipidsi/src/models/st7789/variants.rs +++ /dev/null @@ -1,42 +0,0 @@ -use display_interface::WriteOnlyDataCommand; - -use crate::{ - options::{ColorInversion, ModelOptions}, - Builder, -}; - -use super::ST7789; - -impl Builder -where - DI: WriteOnlyDataCommand, -{ - /// Creates a new display builder for a ST7789 display in Rgb565 color mode. - /// - /// The default framebuffer size and display size is 240x320 pixels. - /// - /// # Arguments - /// - /// * `di` - a [display interface](WriteOnlyDataCommand) for communicating with the display - /// - pub fn st7789(di: DI) -> Self { - Self::with_model(di, ST7789) - } - - /// Creates a new display builder for the pico1 variant of a ST7789 display in Rgb565 color - /// mode. - /// - /// The pico1 variant uses a display and framebuffer size of 135x240 and a clipping offset. - /// - /// # Arguments - /// - /// * `di` - a [display interface](WriteOnlyDataCommand) for communicating with the display - /// - pub fn st7789_pico1(di: DI) -> Self { - let mut options = ModelOptions::with_all((135, 240), (52, 40)); - options.set_invert_colors(ColorInversion::Inverted); - - // pico v1 is cropped to 135x240 size with an offset of (40, 53) - Self::new(di, ST7789, options) - } -}