From ae27ceab65e0a362f261fb169c719aabffb5b496 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Pelayo Date: Sun, 6 Nov 2022 12:49:03 +0100 Subject: [PATCH] Add support for the AZTouch MOD board with ILI9341 This commit adds basic support to run the demo on the AZTouch MOD board. --- Cargo.toml | 3 +++ src/main.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 25d36964..30fbcf56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,9 @@ qemu = [] # Enable this feature in case you have a Kaluga board and would like to see a LED screen demo kaluga = [] +# Enable this feature in case you have a AZTouch MOD board and would like to see a LED screen demo +aztouchmod = [] + # Enable this feature in case you have a TTGO board and would like to see a LED screen demo ttgo = [] diff --git a/src/main.rs b/src/main.rs index f8cdbd94..5a9dd765 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,10 @@ compile_error!("The `ip101` feature can only be built for the `xtensa-esp32-espi #[cfg(all(feature = "kaluga", not(esp32s2)))] compile_error!("The `kaluga` feature can only be built for the `xtensa-esp32s2-espidf` target."); +#[cfg(all(feature = "aztouchmod", not(esp32)))] +compile_error!("The `aztouchmod` feature can only be built for the `xtensa-esp32-espidf` target."); + + #[cfg(all(feature = "ttgo", not(esp32)))] compile_error!("The `ttgo` feature can only be built for the `xtensa-esp32-espidf` target."); @@ -88,7 +92,7 @@ use embedded_graphics::prelude::*; use embedded_graphics::primitives::*; use embedded_graphics::text::*; -use ili9341; +use ili9341::{DisplaySize240x320, Ili9341, Orientation}; use ssd1306; use ssd1306::mode::DisplayConfig; use st7789; @@ -166,6 +170,17 @@ fn main() -> Result<()> { pins.gpio26, )?; + #[cfg(feature = "aztouchmod")] + aztouchmod_hello_world( + pins.gpio15, + pins.gpio4, + pins.gpio22, + peripherals.spi3, + pins.gpio18, + pins.gpio23, + pins.gpio5, + )?; + #[cfg(feature = "kaluga")] kaluga_hello_world( pins.gpio6, @@ -873,6 +888,54 @@ fn kaluga_hello_world( } } +#[cfg(feature = "aztouchmod")] +fn aztouchmod_hello_world( + backlight: gpio::Gpio15, + dc: gpio::Gpio4, + rst: gpio::Gpio22, + spi: spi::SPI3, + sclk: gpio::Gpio18, + sdo: gpio::Gpio23, + cs: gpio::Gpio5, +) -> Result<()> { + info!( + "About to initialize the AZTouchMod ILI9341 SPI LED driver", + ); + + let config = ::default() + .baudrate(40.MHz().into()); + + let mut backlight = backlight.into_output()?; + backlight.set_low()?; + + let di = SPIInterfaceNoCS::new( + spi::Master::::new( + spi, + spi::Pins { + sclk, + sdo, + sdi: Option::>::None, + cs: Some(cs), + }, + config, + )?, + dc.into_output()?, + ); + + let reset = rst.into_output()?; + + let mut display = ili9341::Ili9341::new( + di, + reset, + &mut delay::Ets, + Orientation::LandscapeFlipped, + ili9341::DisplaySize240x320, + ) + .map_err(|e| anyhow::anyhow!("Display error: {:?}", e))?; + + led_draw(&mut display).map_err(|e| anyhow::anyhow!("Display error: {:?}", e)) +} + #[cfg(feature = "heltec")] fn heltec_hello_world( rst: gpio::Gpio16,