Skip to content

Commit

Permalink
Merge pull request #166 from rfuest/ili9488
Browse files Browse the repository at this point in the history
Add support for ILI9488
  • Loading branch information
rfuest authored Jan 22, 2025
2 parents 30bb640 + 33d044b commit 60bbf6f
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- added `RM67162` model support
- made `InitError` visible
- added `ILI9488` model support

## Removed

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Variants that require different screen sizes and window addressing offsets are n
- ILI9341
- ILI9342C
- ILI9486
- ILI9488
- RM67162
- ST7735
- ST7789
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//! * ILI9341
//! * ILI9342C
//! * ILI9486
//! * ILI9488
//! * RM67162
//! * ST7735
//! * ST7789
Expand Down
3 changes: 3 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mod ili9341;
mod ili9342c;
mod ili934x;
mod ili9486;
mod ili9488;
mod ili948x;
mod rm67162;
mod st7735s;
mod st7789;
Expand All @@ -21,6 +23,7 @@ pub use gc9a01::*;
pub use ili9341::*;
pub use ili9342c::*;
pub use ili9486::*;
pub use ili9488::*;
pub use rm67162::*;
pub use st7735s::*;
pub use st7789::*;
Expand Down
44 changes: 4 additions & 40 deletions src/models/ili9486.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ use embedded_graphics_core::pixelcolor::{Rgb565, Rgb666};
use embedded_hal::delay::DelayNs;

use crate::{
dcs::{
BitsPerPixel, EnterNormalMode, ExitSleepMode, InterfaceExt, PixelFormat, SetAddressMode,
SetDisplayOn, SetInvertMode, SetPixelFormat,
},
dcs::{BitsPerPixel, PixelFormat, SetAddressMode},
interface::Interface,
options::ModelOptions,
};

use super::Model;
use super::{ili948x, Model};

/// ILI9486 display in Rgb565 color mode.
pub struct ILI9486Rgb565;
Expand All @@ -35,7 +32,7 @@ impl Model for ILI9486Rgb565 {
delay.delay_us(120_000);

let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::<Self::ColorFormat>());
init_common(di, delay, options, pf)
ili948x::init_common(di, delay, options, pf)
}
}

Expand All @@ -56,39 +53,6 @@ impl Model for ILI9486Rgb666 {
delay.delay_us(120_000);

let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::<Self::ColorFormat>());
init_common(di, delay, options, pf)
ili948x::init_common(di, delay, options, pf)
}
}

// common init for all color format models
fn init_common<DELAY, DI>(
di: &mut DI,
delay: &mut DELAY,
options: &ModelOptions,
pixel_format: PixelFormat,
) -> Result<SetAddressMode, DI::Error>
where
DELAY: DelayNs,
DI: Interface,
{
let madctl = SetAddressMode::from(options);
di.write_command(ExitSleepMode)?; // turn off sleep
di.write_command(SetPixelFormat::new(pixel_format))?; // pixel format
di.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]
di.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
// dcs.write_raw(Instruction::NGC, &[0x0F, 0x37, 0x37, 0x0C, 0x0F, 0x05, 0x50, 0x32, 0x36, 0x04, 0x0B, 0x00, 0x19, 0x14, 0x0F])?; // Negative Gamma Control

di.write_raw(0xB6, &[0b0000_0010, 0x02, 0x3B])?; // DFC
di.write_command(EnterNormalMode)?; // turn to normal mode
di.write_command(SetDisplayOn)?; // turn on display

// DISPON requires some time otherwise we risk SPI data issues
delay.delay_us(120_000);

Ok(madctl)
}
58 changes: 58 additions & 0 deletions src/models/ili9488.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use embedded_graphics_core::pixelcolor::{Rgb565, Rgb666};
use embedded_hal::delay::DelayNs;

use crate::{
dcs::{BitsPerPixel, PixelFormat, SetAddressMode},
interface::Interface,
options::ModelOptions,
};

use super::{ili948x, Model};

/// ILI9488 display in Rgb565 color mode.
pub struct ILI9488Rgb565;

/// ILI9488 display in Rgb666 color mode.
pub struct ILI9488Rgb666;

impl Model for ILI9488Rgb565 {
type ColorFormat = Rgb565;
const FRAMEBUFFER_SIZE: (u16, u16) = (320, 480);

fn init<DELAY, DI>(
&mut self,
di: &mut DI,
delay: &mut DELAY,
options: &ModelOptions,
) -> Result<SetAddressMode, DI::Error>
where
DELAY: DelayNs,
DI: Interface,
{
delay.delay_us(120_000);

let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::<Self::ColorFormat>());
ili948x::init_common(di, delay, options, pf)
}
}

impl Model for ILI9488Rgb666 {
type ColorFormat = Rgb666;
const FRAMEBUFFER_SIZE: (u16, u16) = (320, 480);

fn init<DELAY, DI>(
&mut self,
di: &mut DI,
delay: &mut DELAY,
options: &ModelOptions,
) -> Result<SetAddressMode, DI::Error>
where
DELAY: DelayNs,
DI: Interface,
{
delay.delay_us(120_000);

let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::<Self::ColorFormat>());
ili948x::init_common(di, delay, options, pf)
}
}
43 changes: 43 additions & 0 deletions src/models/ili948x.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use embedded_hal::delay::DelayNs;

use crate::{
dcs::{
EnterNormalMode, ExitSleepMode, InterfaceExt, PixelFormat, SetAddressMode, SetDisplayOn,
SetInvertMode, SetPixelFormat,
},
interface::Interface,
options::ModelOptions,
};

/// Common init for all ILI948x models and color formats.
pub fn init_common<DELAY, DI>(
di: &mut DI,
delay: &mut DELAY,
options: &ModelOptions,
pixel_format: PixelFormat,
) -> Result<SetAddressMode, DI::Error>
where
DELAY: DelayNs,
DI: Interface,
{
let madctl = SetAddressMode::from(options);
di.write_command(ExitSleepMode)?; // turn off sleep
di.write_command(SetPixelFormat::new(pixel_format))?; // pixel format
di.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]
di.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
// dcs.write_raw(Instruction::NGC, &[0x0F, 0x37, 0x37, 0x0C, 0x0F, 0x05, 0x50, 0x32, 0x36, 0x04, 0x0B, 0x00, 0x19, 0x14, 0x0F])?; // Negative Gamma Control

di.write_raw(0xB6, &[0b0000_0010, 0x02, 0x3B])?; // DFC
di.write_command(EnterNormalMode)?; // turn to normal mode
di.write_command(SetDisplayOn)?; // turn on display

// DISPON requires some time otherwise we risk SPI data issues
delay.delay_us(120_000);

Ok(madctl)
}

0 comments on commit 60bbf6f

Please sign in to comment.