Skip to content

Commit

Permalink
Merge pull request #111 from rfuest/remove-model-constructors
Browse files Browse the repository at this point in the history
Remove model specific constructors
  • Loading branch information
almindor authored Feb 2, 2024
2 parents 05d2bb3 + 59f83d1 commit 16d4a97
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 243 deletions.
1 change: 1 addition & 0 deletions mipidsi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions mipidsi/docs/MIGRATION.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
17 changes: 4 additions & 13 deletions mipidsi/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions mipidsi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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` */
Expand All @@ -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
Expand All @@ -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};
//!
Expand All @@ -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();
//!
Expand Down Expand Up @@ -376,7 +376,7 @@ pub mod _mock {
use crate::{models::ILI9341Rgb565, Builder, Display};

pub fn new_mock_display() -> Display<MockDisplayInterface, ILI9341Rgb565, MockOutputPin> {
Builder::ili9341_rgb565(MockDisplayInterface)
Builder::new(ILI9341Rgb565, MockDisplayInterface)
.init(&mut MockDelay, Some(MockOutputPin))
.unwrap()
}
Expand Down
23 changes: 1 addition & 22 deletions mipidsi/src/models/gc9a01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -145,22 +143,3 @@ impl Model for GC9A01 {
Ok(())
}
}

// simplified constructor on Display

impl<DI> Builder<DI, GC9A01>
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)
}
}
44 changes: 1 addition & 43 deletions mipidsi/src/models/ili9341.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -84,43 +82,3 @@ impl Model for ILI9341Rgb666 {
ili934x::write_pixels_rgb666(dcs, colors)
}
}

// simplified constructor for Display

impl<DI> Builder<DI, ILI9341Rgb565>
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<DI> Builder<DI, ILI9341Rgb666>
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)
}
}
44 changes: 1 addition & 43 deletions mipidsi/src/models/ili9342c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -84,43 +82,3 @@ impl Model for ILI9342CRgb666 {
ili934x::write_pixels_rgb666(dcs, colors)
}
}

// simplified constructor for Display

impl<DI> Builder<DI, ILI9342CRgb565>
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<DI> Builder<DI, ILI9342CRgb666>
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)
}
}
44 changes: 1 addition & 43 deletions mipidsi/src/models/ili9486.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,46 +106,6 @@ impl Model for ILI9486Rgb666 {
}
}

// simplified constructor for Display

impl<DI> Builder<DI, ILI9486Rgb565>
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<DI> Builder<DI, ILI9486Rgb666>
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<DELAY, DI>(
dcs: &mut Dcs<DI>,
Expand Down
28 changes: 3 additions & 25 deletions mipidsi/src/models/st7735s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -93,22 +90,3 @@ impl Model for ST7735s {
Ok(())
}
}

// simplified constructor on Display

impl<DI> Builder<DI, ST7735s>
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)
}
}
9 changes: 2 additions & 7 deletions mipidsi/src/models/st7789.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 16d4a97

Please sign in to comment.