almindor / mipidsi

MIPI Display Serial Interface unified driver
MIT License
108 stars 47 forks source link

builder.init() confuses VSCode? #88

Closed shoutmarble closed 6 months ago

shoutmarble commented 6 months ago

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?

2023-12-17_21-18

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:

cargo install espflash
cargo install cargo-espflash
cargo install cargo-espmonitor
cargo install cargo-generate 
cargo install espup 
espup install
cargo generate esp-rs/esp-template

Generate Skeleton Project

PS C:\Users\XXXXX\Documents\GIT> cargo generate esp-rs/esp-template
⚠️   Favorite `esp-rs/esp-template` not found in config, using it as a git repository: https://github.com/esp-rs/esp-template.git
🤷   Project Name: feather
🔧   Destination: C:\Users\XXXXX\Documents\GIT\feather ...
🔧   project-name: feather ...
🔧   Generating template ...
✔ 🤷   Which MCU to target? · esp32s3
✔ 🤷   Configure advanced template options? · true
✔ 🤷   Enable allocations via the esp-alloc crate? · false
✔ 🤷   Configure project to use Dev Containers (VS Code and GitHub Codespaces)? · false
✔ 🤷   Configure project to support Wokwi simulation with Wokwi VS Code extension? · false
✔ 🤷   Add CI files for GitHub Action? · false
✔ 🤷   Setup logging using the log crate? · false
✔ 🤷   Enable WiFi/Bluetooth/ESP-NOW via the esp-wifi crate? · false
🔧   Moving generated files into: `C:\Users\XXXXX\Documents\GIT\feather`...
🔧   Initializing a fresh Git repository
✨   Done! New project created 

Adafruit ESP32-S3 TFT Feather

enter image description here

enter image description here

Pinouts

Rust Version/Toolchains

PS C:\Users\XXXXX\Documents\GIT\feather> rustup show
Default host: x86_64-pc-windows-msvc
rustup home:  C:\Users\XXXXX\.rustup

installed toolchains
--------------------

stable-x86_64-pc-windows-msvc (default)
nightly-x86_64-pc-windows-msvc
esp

active toolchain
----------------

esp (overridden by 'C:\Users\XXXXX\Documents\GIT\feather\rust-toolchain.toml')
rustc 1.74.0-nightly (98053514f 2023-12-01) (1.74.0.1)

Rust Version:

PS C:\Users\XXXXX\Documents\GIT\feather> cargo version
cargo 1.74.0-nightly (ecb9851af 2023-10-18)
PS C:\Users\XXXXX\Documents\GIT\feather> rustc -V
rustc 1.74.0-nightly (98053514f 2023-12-01) (1.74.0.1)

output

My 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"

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();

#![no_std]
#![no_main]
#![allow(warnings)]

use display_interface_spi::{SPIInterface, SPIInterfaceNoCS};
use esp_backtrace as _;
use esp_println::println;
use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay};

use esp_backtrace as _;

use hal::{
    gpio::{GpioPin, Output, PushPull},
    peripherals::{SPI2},
    spi::{master::Spi, FullDuplexMode, SpiMode},
};
use mipidsi::{
    models::{Model}, Builder,
};

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take();
    let system = peripherals.SYSTEM.split();

    let clocks = ClockControl::max(system.clock_control).freeze();
    let mut delay = Delay::new(&clocks);

    let io = hal::IO::new(peripherals.GPIO, peripherals.IO_MUX);

    let sck = io.pins.gpio36;
    let mosi = io.pins.gpio35.into_push_pull_output();
    let miso = io.pins.gpio37.into_push_pull_output();

    let mut i2c = io.pins.gpio21.into_push_pull_output();
    let mut cs = io.pins.gpio7.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 spi = hal::spi::master::Spi::new(
        peripherals.SPI2,
        85_u32.kHz(),
        SpiMode::Mode2,
        &clocks,
    );

    let di = SPIInterfaceNoCS::new(spi, dc);

    let builder = Builder::st7789_pico1(di);
    let mut display = builder.init(&mut delay, Some(reset)).unwrap();

    backlight.set_high().unwrap();

    println!("Hello world!");
    let mut count = 0;
    loop {
        println!("Loop...{count}");
        count = count + 1;
        delay.delay_ms(500u32);
    }
}

The Pins I used

pins

Flashing


PS C:\Users\XXXXX\Documents\GIT\feather> cargo espflash flash
[2023-12-18T03:46:46Z INFO ] Serial port: 'COM3'
[2023-12-18T03:46:46Z INFO ] Connecting...
[2023-12-18T03:46:47Z INFO ] Using flash stub
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
Chip type:         esp32s3 (revision v0.1)
Crystal frequency: 40MHz
Flash size:        4MB
Features:          WiFi, BLE  
MAC address:       f4:12:fa:59:c0:fc  
App/part. size:    250,336/4,128,768 bytes, 6.06%  
[00:00:00] [========================================]      14/14      0x0               
[00:00:00] [========================================]       1/1       0x8000            
[00:00:02] [========================================]      97/97      0x10000            
[2023-12-18T03:46:51Z INFO ] Flashing has completed!  

I'm hitting ^R to refresh the display/blacklight

PS C:\Users\Terry\Documents\GIT\feather> cargo espflash monitor
[2023-12-18T03:47:39Z INFO ] Serial port: 'COM3'
[2023-12-18T03:47:39Z INFO ] Connecting...
[2023-12-18T03:47:39Z INFO ] Using flash stub
Commands:
    CTRL+R    Reset chip
    CTRL+C    Exit

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40378c75
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fce3818,len:0x16f8
load:0x403c9700,len:0x4
load:0x403c9704,len:0xc00
load:0x403cc700,len:0x2eb0
SHA-256 comparison failed:
Calculated: eb1394d7fd5c733d434e3a8494a2eeeb0b810d83bda37d357f66a0456971275b
Expected: 3499e4149a363c2b1ee4ee9709ca5031f50ee6b595a532f697c8659516763ae3
Attempting to boot anyway...
entry 0x403c9908
I (45) boot: ESP-IDF v5.1-beta1-378-gea5e0ff298-dirt 2nd stage bootloader
I (46) boot: compile time Jun  7 2023 08:07:32
I (47) boot: Multicore bootloader
I (51) boot: chip revision: v0.1
I (55) boot.esp32s3: Boot SPI Speed : 40MHz
I (59) boot.esp32s3: SPI Mode       : DIO
I (64) boot.esp32s3: SPI Flash Size : 4MB
I (69) boot: Enabling RNG early entropy source...
I (74) boot: Partition Table:
I (78) boot: ## Label            Usage          Type ST Offset   Length
I (85) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (93) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (100) boot:  2 factory          factory app      00 00 00010000 003f0000
I (108) boot: End of partition table
I (112) esp_image: segment 0: paddr=00010020 vaddr=3c030020 size=08564h ( 34148) map    
I (129) esp_image: segment 1: paddr=0001858c vaddr=3fc89888 size=00004h (     4) load
I (129) esp_image: segment 2: paddr=00018598 vaddr=40378000 size=01888h (  6280) load   
I (139) esp_image: segment 3: paddr=00019e28 vaddr=00000000 size=061f0h ( 25072) 
I (152) esp_image: segment 4: paddr=00020020 vaddr=42000020 size=2d194h (184724) map    
I (200) boot: Loaded app from partition at offset 0x10000
I (201) boot: Disabling RNG early entropy source...
Hello world!
Loop...0
Loop...1
Loop...2
Loop...3
Loop...4
Loop...5
Loop...6
Loop...7
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x42010a38
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fce3818,len:0x16f8
load:0x403c9700,len:0x4
load:0x403c9704,len:0xc00
load:0x403cc700,len:0x2eb0
SHA-256 comparison failed:
Calculated: eb1394d7fd5c733d434e3a8494a2eeeb0b810d83bda37d357f66a0456971275b
Expected: 3499e4149a363c2b1ee4ee9709ca5031f50ee6b595a532f697c8659516763ae3
Attempting to boot anyway...
entry 0x403c9908
I (45) boot: ESP-IDF v5.1-beta1-378-gea5e0ff298-dirt 2nd stage bootloader
I (46) boot: compile time Jun  7 2023 08:07:32
I (47) boot: Multicore bootloader
I (51) boot: chip revision: v0.1
I (55) boot.esp32s3: Boot SPI Speed : 40MHz
I (59) boot.esp32s3: SPI Mode       : DIO
I (64) boot.esp32s3: SPI Flash Size : 4MB
I (69) boot: Enabling RNG early entropy source...
I (74) boot: Partition Table:
I (78) boot: ## Label            Usage          Type ST Offset   Length
I (85) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (93) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (100) boot:  2 factory          factory app      00 00 00010000 003f0000
I (108) boot: End of partition table
I (112) esp_image: segment 0: paddr=00010020 vaddr=3c030020 size=08564h ( 34148) map    
I (129) esp_image: segment 1: paddr=0001858c vaddr=3fc89888 size=00004h (     4) load
I (129) esp_image: segment 2: paddr=00018598 vaddr=40378000 size=01888h (  6280) load   
I (139) esp_image: segment 3: paddr=00019e28 vaddr=00000000 size=061f0h ( 25072) 
I (152) esp_image: segment 4: paddr=00020020 vaddr=42000020 size=2d194h (184724) map    
I (200) boot: Loaded app from partition at offset 0x10000
I (201) boot: Disabling RNG early entropy source...
Hello world!
Loop...0
Loop...1
Loop...2
Loop...3
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x42010a32
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fce3818,len:0x16f8
load:0x403c9700,len:0x4
load:0x403c9704,len:0xc00
load:0x403cc700,len:0x2eb0
SHA-256 comparison failed:
Calculated: eb1394d7fd5c733d434e3a8494a2eeeb0b810d83bda37d357f66a0456971275b
Expected: 3499e4149a363c2b1ee4ee9709ca5031f50ee6b595a532f697c8659516763ae3
Attempting to boot anyway...
entry 0x403c9908
I (45) boot: ESP-IDF v5.1-beta1-378-gea5e0ff298-dirt 2nd stage bootloader
I (46) boot: compile time Jun  7 2023 08:07:32
I (47) boot: Multicore bootloader
I (51) boot: chip revision: v0.1
I (55) boot.esp32s3: Boot SPI Speed : 40MHz
I (59) boot.esp32s3: SPI Mode       : DIO
I (64) boot.esp32s3: SPI Flash Size : 4MB
I (69) boot: Enabling RNG early entropy source...
I (74) boot: Partition Table:
I (78) boot: ## Label            Usage          Type ST Offset   Length
I (85) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (93) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (100) boot:  2 factory          factory app      00 00 00010000 003f0000
I (108) boot: End of partition table
I (112) esp_image: segment 0: paddr=00010020 vaddr=3c030020 size=08564h ( 34148) map    
I (129) esp_image: segment 1: paddr=0001858c vaddr=3fc89888 size=00004h (     4) load
I (129) esp_image: segment 2: paddr=00018598 vaddr=40378000 size=01888h (  6280) load   
I (139) esp_image: segment 3: paddr=00019e28 vaddr=00000000 size=061f0h ( 25072) 
I (152) esp_image: segment 4: paddr=00020020 vaddr=42000020 size=2d194h (184724) map
I (200) boot: Loaded app from partition at offset 0x10000
I (201) boot: Disabling RNG early entropy source...
Hello world!
Loop...0
Loop...1

There are probably many more serious errors, this is my first go at using Rust on my micro-controller.

rfuest commented 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:

shoutmarble commented 6 months ago

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

output

#![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) vscode

I'm most likely not using the correct pins featherpins

The schematic of the Adafruit ESP32S3 TFT and the Pinouts on their website are not exactly the same.

shoutmarble commented 6 months ago

Setting the GPIO 21 pin to high is critical (as you mentioned it)

output

#![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);
    }
}

lcd_power

shoutmarble commented 6 months ago

I think it's working I believe that was all there was. Thank you! image

I tried also with blue to see if the color would show more with the camera output

It's hard to see in this color-reduced GIF (the yellow is actually a bright red) output

#![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);
    }
}

red_blue

shoutmarble commented 6 months ago

Confirmation, this can be closed.

Adafruit ESP32-S3 TFT Feather

output

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"

grpahics

rfuest commented 6 months ago

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.

shoutmarble commented 6 months ago

That is much quicker and no penalties seen yet!

output

60Mhz

#![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"