Closed shoutmarble closed 6 months ago
But, I can't use the display.clear(..) to set the background color because Rust doesn't know it's type?
Do you get a compiler error if you try to compile the code? Normally the compiler should be able to derive the necessary type by itself, which is a lot easier than having to specify the type manually, because the types in embedded projects can get very complex.
I did quickly check the rest of your code and found a few things that you might want to check:
.with_pins
part.VS Code is now able to see type of "display" type object on Line 58
let mut display = builder.init(&mut delay, Some(reset)).unwrap();
I now have to figure out the correct PINS
#![no_std]
#![no_main]
#![allow(warnings)]
use display_interface_spi::{SPIInterface, SPIInterfaceNoCS};
use embedded_graphics::pixelcolor::{Rgb565, RgbColor};
use esp_backtrace as _;
use esp_println::println;
use hal::{
clock::ClockControl,
gpio::{GpioPin, Output, PushPull},
peripheral,
peripherals::Peripherals,
peripherals::SPI2,
prelude::*,
spi::{self, master::Spi, FullDuplexMode, SpiMode},
Delay,
};
use mipidsi::{
error::InitError,
models::{Model, ST7789},
Builder, Display, Orientation,
};
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let mut clocks = ClockControl::max(system.clock_control).freeze();
let mut delay = Delay::new(&clocks);
let io = hal::IO::new(peripherals.GPIO, peripherals.IO_MUX);
let sclk = io.pins.gpio36;
let miso = io.pins.gpio37;
let mosi = io.pins.gpio35.into_push_pull_output();
let mut cs = io.pins.gpio7;
let mut spi =
hal::spi::master::Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &mut clocks)
.with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs));
// let mut i2c = io.pins.gpio21.into_push_pull_output();
let dc = io.pins.gpio39.into_push_pull_output();
let mut backlight = io.pins.gpio45.into_push_pull_output();
let mut reset = io.pins.gpio40.into_push_pull_output();
// let mut sda = io.pins.gpio42.into_push_pull_output();
// let mut scl = io.pins.gpio41.into_push_pull_output();
///
let di = SPIInterfaceNoCS::new(spi, dc);
let builder = Builder::st7789_pico1(di);
reset.set_high().unwrap();
let mut display = builder.init(&mut delay, Some(reset)).unwrap();
backlight.set_high().unwrap();
let colors = [Rgb565::RED, Rgb565::GREEN, Rgb565::BLUE];
display.set_pixels(240, 135, 0, 0, colors);
// display.set_pixels(0, 0, 240, 135, colors);
println!("Hello world!");
let mut count = 0;
loop {
println!("Loop...{count}");
count = count + 1;
delay.delay_ms(500u32);
}
}
Cargo.toml no change
[package]
name = "feather"
version = "0.1.0"
authors = ["Terry"]
edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
hal = { package = "esp32s3-hal", version = "0.14.0" }
esp-backtrace = { version = "0.9.0", features = ["esp32s3", "panic-handler", "exception-handler", "print-uart"] }
esp-println = { version = "0.7.0", features = ["esp32s3"] }
mipidsi = "0.7.1"
embedded-graphics = "0.8.1"
display-interface = "0.4.1"
display-interface-spi = "0.4.1"
VS Code can now see's the type of Display (Line 58)
I'm most likely not using the correct pins
The schematic of the Adafruit ESP32S3 TFT and the Pinouts on their website are not exactly the same.
Setting the GPIO 21 pin to high is critical (as you mentioned it)
#![no_std]
#![no_main]
#![allow(warnings)]
use display_interface_spi::{SPIInterface, SPIInterfaceNoCS};
use embedded_graphics::pixelcolor::{Rgb565, RgbColor};
use esp_backtrace as _;
use esp_println::println;
use hal::{
clock::ClockControl,
gpio::{GpioPin, Output, PushPull},
peripheral,
peripherals::Peripherals,
peripherals::SPI2,
prelude::*,
spi::{self, master::Spi, FullDuplexMode, SpiMode},
Delay,
};
use mipidsi::{
error::InitError,
models::{Model, ST7789},
Builder, Display, Orientation,
};
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let mut clocks = ClockControl::max(system.clock_control).freeze();
let mut delay = Delay::new(&clocks);
let io = hal::IO::new(peripherals.GPIO, peripherals.IO_MUX);
let sclk = io.pins.gpio36;
let miso = io.pins.gpio37;
let mosi = io.pins.gpio35.into_push_pull_output();
let mut cs = io.pins.gpio7;
let mut lcd_pwr = io.pins.gpio21.into_push_pull_output();
let mut spi =
hal::spi::master::Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &mut clocks)
.with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs));
let dc = io.pins.gpio39.into_push_pull_output();
let mut backlight = io.pins.gpio45.into_push_pull_output();
let mut reset = io.pins.gpio40.into_push_pull_output();
lcd_pwr.set_high().unwrap();
let di = SPIInterfaceNoCS::new(spi, dc);
let builder = Builder::st7789_pico1(di);
reset.set_high().unwrap();
let mut display = builder.init(&mut delay, Some(reset)).unwrap();
backlight.set_high().unwrap();
let colors = [Rgb565::RED, Rgb565::GREEN, Rgb565::BLUE];
display.set_pixels(240, 135, 0, 0, colors);
// display.set_pixels(0, 0, 240, 135, colors);
println!("Hello world!");
let mut count = 0;
loop {
println!("Loop...{count}");
count = count + 1;
delay.delay_ms(500u32);
}
}
I think it's working I believe that was all there was. Thank you!
I tried also with blue to see if the color would show more with the camera
It's hard to see in this color-reduced GIF (the yellow is actually a bright red)
#![no_std]
#![no_main]
#![allow(warnings)]
use display_interface_spi::{SPIInterface, SPIInterfaceNoCS};
use embedded_graphics::{
draw_target::DrawTarget,
geometry::Point,
pixelcolor::{Rgb565, Rgb666, RgbColor},
primitives::Circle,
};
use esp_backtrace as _;
use esp_println::println;
use hal::{
clock::ClockControl,
gpio::{GpioPin, Output, PushPull},
peripheral,
peripherals::Peripherals,
peripherals::SPI2,
prelude::*,
spi::{self, master::Spi, FullDuplexMode, SpiMode},
Delay,
};
use mipidsi::{
error::InitError,
models::{Model, ST7789},
Builder, Display, Orientation,
};
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let mut clocks = ClockControl::max(system.clock_control).freeze();
let mut delay = Delay::new(&clocks);
let io = hal::IO::new(peripherals.GPIO, peripherals.IO_MUX);
let sclk = io.pins.gpio36;
let miso = io.pins.gpio37;
let mosi = io.pins.gpio35.into_push_pull_output();
let mut cs = io.pins.gpio7;
let mut lcd_pwr = io.pins.gpio21.into_push_pull_output();
let mut spi =
hal::spi::master::Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &mut clocks)
.with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs));
let dc = io.pins.gpio39.into_push_pull_output();
let mut backlight = io.pins.gpio45.into_push_pull_output();
let mut reset = io.pins.gpio40.into_push_pull_output();
lcd_pwr.set_high().unwrap();
let di = SPIInterfaceNoCS::new(spi, dc);
let builder = Builder::st7789_pico1(di);
reset.set_high().unwrap();
let mut display = builder.init(&mut delay, Some(reset)).unwrap();
backlight.set_high().unwrap();
display.clear(Rgb565::RED).unwrap();
backlight.set_low().unwrap();
display.clear(Rgb666::RED.into()).unwrap();
println!("Hello world!");
let mut count = 0;
loop {
println!("Loop...{count}");
count = count + 1;
delay.delay_ms(500u32);
}
}
Confirmation, this can be closed.
main.rs
#![no_std]
#![no_main]
// #![allow(warnings)]
use display_interface_spi::SPIInterfaceNoCS;
use embedded_graphics::{geometry::Point, image::Image, Drawable};
use esp_backtrace as _;
use esp_println::println;
use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, spi::SpiMode, Delay};
use mipidsi::{Builder, Orientation};
use tinybmp::Bmp;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let mut clocks = ClockControl::max(system.clock_control).freeze();
let mut delay = Delay::new(&clocks);
let io = hal::IO::new(peripherals.GPIO, peripherals.IO_MUX);
let sclk = io.pins.gpio36;
let miso = io.pins.gpio37;
let mosi = io.pins.gpio35.into_push_pull_output();
let cs = io.pins.gpio7;
let mut lcd_pwr = io.pins.gpio21.into_push_pull_output();
let spi =
hal::spi::master::Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &mut clocks)
.with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs));
let dc = io.pins.gpio39.into_push_pull_output();
let mut backlight = io.pins.gpio45.into_push_pull_output();
let mut reset = io.pins.gpio40.into_push_pull_output();
lcd_pwr.set_high().unwrap();
let di = SPIInterfaceNoCS::new(spi, dc);
let builder = Builder::st7789_pico1(di);
reset.set_high().unwrap();
let mut display = builder.init(&mut delay, Some(reset)).unwrap();
display
.set_orientation(Orientation::Portrait(true))
.unwrap();
backlight.set_high().unwrap();
let bmp_data = include_bytes!("../jesus.bmp");
let bmp = Bmp::from_slice(bmp_data).unwrap();
Image::new(&bmp, Point::new(0, 0))
.draw(&mut display)
.unwrap();
println!("Hello world!");
let mut count = 0;
loop {
println!("Loop...{count}");
count = count + 1;
delay.delay_ms(500u32);
}
}
Cargo.toml
[package]
name = "feather"
version = "0.1.0"
authors = ["Terry"]
edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
hal = { package = "esp32s3-hal", version = "0.14.0" }
esp-backtrace = { version = "0.9.0", features = ["esp32s3", "panic-handler", "exception-handler", "print-uart"] }
esp-println = { version = "0.7.0", features = ["esp32s3"] }
mipidsi = "0.7.1"
embedded-graphics = "0.8.1"
display-interface = "0.4.1"
display-interface-spi = "0.4.1"
tinybmp = "0.5.0"
profont = "0.7.0"
Nice to see it working. If you haven't already done it yourself, I would suggest that you increase the SPI clock rate a bit to get faster updates. The ST7789 supports up to 62.5 MHz SPI clock, but I'm not sure about the ESP32.
That is much quicker and no penalties seen yet!
#![no_std]
#![no_main]
// #![allow(warnings)]
use display_interface_spi::SPIInterfaceNoCS;
use embedded_graphics::{geometry::Point, image::Image, Drawable};
use esp_backtrace as _;
use esp_println::println;
use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, spi::SpiMode, Delay};
use mipidsi::Builder;
use tinybmp::Bmp;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let mut clocks = ClockControl::max(system.clock_control).freeze();
let mut delay = Delay::new(&clocks);
let io = hal::IO::new(peripherals.GPIO, peripherals.IO_MUX);
let sclk = io.pins.gpio36;
let miso = io.pins.gpio37;
let mosi = io.pins.gpio35.into_push_pull_output();
let cs = io.pins.gpio7;
let mut lcd_pwr = io.pins.gpio21.into_push_pull_output();
let spi =
hal::spi::master::Spi::new(peripherals.SPI2, 60u32.MHz(), SpiMode::Mode0, &mut clocks)
.with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs));
let dc = io.pins.gpio39.into_push_pull_output();
let mut backlight = io.pins.gpio45.into_push_pull_output();
let mut reset = io.pins.gpio40.into_push_pull_output();
lcd_pwr.set_high().unwrap();
let di = SPIInterfaceNoCS::new(spi, dc);
let builder = Builder::st7789_pico1(di);
reset.set_high().unwrap();
let mut display = builder.init(&mut delay, Some(reset)).unwrap();
backlight.set_high().unwrap();
let bmp_data = include_bytes!("../jesus.bmp");
let bmp = Bmp::from_slice(bmp_data).unwrap();
Image::new(&bmp, Point::new(0, 0))
.draw(&mut display)
.unwrap();
println!("Hello world!");
let mut count = 0;
loop {
println!("Loop...{count}");
count = count + 1;
delay.delay_ms(500u32);
}
}
[package]
name = "feather"
version = "0.1.0"
authors = ["Terry"]
edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
hal = { package = "esp32s3-hal", version = "0.14.0" }
esp-backtrace = { version = "0.9.0", features = ["esp32s3", "panic-handler", "exception-handler", "print-uart"] }
esp-println = { version = "0.7.0", features = ["esp32s3"] }
mipidsi = "0.7.1"
embedded-graphics = "0.8.1"
display-interface = "0.4.1"
display-interface-spi = "0.4.1"
tinybmp = "0.5.0"
profont = "0.7.0"
I'm trying to draw a color on my Adafruit ESP32S3 TFT that has a display of 240x135
But, I can't use the display.clear(..) to set the background color because Rust doesn't know it's type?
I used espup and cargo-generate the template to create a skeleton project and flashing it with espflash.
I installed espflash and espmonitor.
And the remaining tools:
Generate Skeleton Project
Adafruit ESP32-S3 TFT Feather
Rust Version/Toolchains
Rust Version:
My Cargo.toml
In my main.rs
let mut display = builder.init(&mut delay, Some(reset)).unwrap();
I can't use the "display" to change the TFT color, because vscode can't tell the type?
display.clear(Rgb565::RED).unwrap();
The Pins I used
Flashing
I'm hitting ^R to refresh the display/blacklight
There are probably many more serious errors, this is my first go at using Rust on my micro-controller.