diff --git a/mipidsi/CHANGELOG.md b/mipidsi/CHANGELOG.md index 9bf38d7..e4e55f4 100644 --- a/mipidsi/CHANGELOG.md +++ b/mipidsi/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed +- DCS commands param fields are now all consistently private with added constructors for all such commands - DCS command constructors (such as `SetAddressMode::new`) are now marked as `const`, so DCS commands can be constructed in [const contexts](https://doc.rust-lang.org/reference/const_eval.html#const-context) diff --git a/mipidsi/src/dcs/set_invert_mode.rs b/mipidsi/src/dcs/set_invert_mode.rs index 794df65..08ee6cd 100644 --- a/mipidsi/src/dcs/set_invert_mode.rs +++ b/mipidsi/src/dcs/set_invert_mode.rs @@ -4,7 +4,14 @@ use super::DcsCommand; /// Set Invert Mode #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct SetInvertMode(pub ColorInversion); +pub struct SetInvertMode(ColorInversion); + +impl SetInvertMode { + /// Construct a new SetInvertMode DCS with the given value + pub fn new(color_inversion: ColorInversion) -> Self { + SetInvertMode(color_inversion) + } +} impl DcsCommand for SetInvertMode { fn instruction(&self) -> u8 { diff --git a/mipidsi/src/dcs/set_tearing_effect.rs b/mipidsi/src/dcs/set_tearing_effect.rs index f7a53f0..f31d9f7 100644 --- a/mipidsi/src/dcs/set_tearing_effect.rs +++ b/mipidsi/src/dcs/set_tearing_effect.rs @@ -4,7 +4,14 @@ use super::DcsCommand; /// Set Tearing Effect #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct SetTearingEffect(pub TearingEffect); +pub struct SetTearingEffect(TearingEffect); + +impl SetTearingEffect { + /// Construct a new SetTearingEffect DCS with the given value + pub fn new(tearing_effect: TearingEffect) -> Self { + SetTearingEffect(tearing_effect) + } +} impl DcsCommand for SetTearingEffect { fn instruction(&self) -> u8 { diff --git a/mipidsi/src/lib.rs b/mipidsi/src/lib.rs index 9a97bd6..e9a9da0 100644 --- a/mipidsi/src/lib.rs +++ b/mipidsi/src/lib.rs @@ -257,7 +257,7 @@ where /// pub fn set_tearing_effect(&mut self, tearing_effect: TearingEffect) -> Result<(), Error> { self.dcs - .write_command(dcs::SetTearingEffect(tearing_effect)) + .write_command(dcs::SetTearingEffect::new(tearing_effect)) } /// diff --git a/mipidsi/src/models/gc9a01.rs b/mipidsi/src/models/gc9a01.rs index d307917..2ead2c7 100644 --- a/mipidsi/src/models/gc9a01.rs +++ b/mipidsi/src/models/gc9a01.rs @@ -119,7 +119,7 @@ impl Model for GC9A01 { dcs.write_raw(0x74, &[0x10, 0x85, 0x80, 0x00, 0x00, 0x4E, 0x00])?; dcs.write_raw(0x98, &[0x3e, 0x07])?; - dcs.write_command(SetInvertMode(options.invert_colors))?; // set color inversion + dcs.write_command(SetInvertMode::new(options.invert_colors))?; // set color inversion dcs.write_command(ExitSleepMode)?; // turn off sleep delay.delay_us(120_000); diff --git a/mipidsi/src/models/ili934x.rs b/mipidsi/src/models/ili934x.rs index 2a3d7f4..380d62a 100644 --- a/mipidsi/src/models/ili934x.rs +++ b/mipidsi/src/models/ili934x.rs @@ -29,7 +29,7 @@ where dcs.write_command(madctl)?; dcs.write_raw(0xB4, &[0x0])?; - dcs.write_command(SetInvertMode(options.invert_colors))?; + dcs.write_command(SetInvertMode::new(options.invert_colors))?; dcs.write_command(SetPixelFormat::new(pixel_format))?; dcs.write_command(EnterNormalMode)?; diff --git a/mipidsi/src/models/ili9486.rs b/mipidsi/src/models/ili9486.rs index aebfc23..d598e30 100644 --- a/mipidsi/src/models/ili9486.rs +++ b/mipidsi/src/models/ili9486.rs @@ -169,7 +169,7 @@ where dcs.write_command(madctl)?; // left -> right, bottom -> top RGB // dcs.write_command(Instruction::VCMOFSET, &[0x00, 0x48, 0x00, 0x48])?; //VCOM Control 1 [00 40 00 40] // dcs.write_command(Instruction::INVCO, &[0x0])?; //Inversion Control [00] - dcs.write_command(SetInvertMode(options.invert_colors))?; + dcs.write_command(SetInvertMode::new(options.invert_colors))?; // optional gamma setup // dcs.write_raw(Instruction::PGC, &[0x00, 0x2C, 0x2C, 0x0B, 0x0C, 0x04, 0x4C, 0x64, 0x36, 0x03, 0x0E, 0x01, 0x10, 0x01, 0x00])?; // Positive Gamma Control diff --git a/mipidsi/src/models/st7735s.rs b/mipidsi/src/models/st7735s.rs index 6883a0d..1a94521 100644 --- a/mipidsi/src/models/st7735s.rs +++ b/mipidsi/src/models/st7735s.rs @@ -42,7 +42,7 @@ impl Model for ST7735s { dcs.write_command(ExitSleepMode)?; // turn off sleep delay.delay_us(120_000); - dcs.write_command(SetInvertMode(options.invert_colors))?; // set color inversion + dcs.write_command(SetInvertMode::new(options.invert_colors))?; // set color inversion dcs.write_raw(0xB1, &[0x05, 0x3A, 0x3A])?; // set frame rate dcs.write_raw(0xB2, &[0x05, 0x3A, 0x3A])?; // set frame rate dcs.write_raw(0xB3, &[0x05, 0x3A, 0x3A, 0x05, 0x3A, 0x3A])?; // set frame rate diff --git a/mipidsi/src/models/st7789.rs b/mipidsi/src/models/st7789.rs index 91486d7..8de1bc8 100644 --- a/mipidsi/src/models/st7789.rs +++ b/mipidsi/src/models/st7789.rs @@ -51,7 +51,7 @@ impl Model for ST7789 { dcs.write_command(SetScrollArea::from(options))?; dcs.write_command(madctl)?; - dcs.write_command(SetInvertMode(options.invert_colors))?; + dcs.write_command(SetInvertMode::new(options.invert_colors))?; let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::()); dcs.write_command(SetPixelFormat::new(pf))?;