Skip to content

Commit

Permalink
make DCS construction consistent, fixed #92
Browse files Browse the repository at this point in the history
  • Loading branch information
almindor committed Jan 22, 2024
1 parent c969262 commit 46ce76d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions mipidsi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 8 additions & 1 deletion mipidsi/src/dcs/set_invert_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion mipidsi/src/dcs/set_tearing_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion mipidsi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

///
Expand Down
2 changes: 1 addition & 1 deletion mipidsi/src/models/gc9a01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion mipidsi/src/models/ili934x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion mipidsi/src/models/ili9486.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mipidsi/src/models/st7735s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mipidsi/src/models/st7789.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Self::ColorFormat>());
dcs.write_command(SetPixelFormat::new(pf))?;
Expand Down

0 comments on commit 46ce76d

Please sign in to comment.