how to setup spi screen #2522
-
I've spent a lot of time trying to figure out how this thing works. #![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
delay::Delay, gpio::{Io,Level},
prelude::*,
peripherals::Peripherals,
spi::{SpiMode,master::Spi}};
use embedded_graphics::{prelude::*, primitives::Rectangle, pixelcolor::Rgb565};
use display_interface_spi::{SPIInterface, SPIInterfaceNoCS};
use embedded_hal_compat::{ForwardCompat,ReverseCompat};
use st7789::ST7789;
extern crate alloc;
use core::{clone, mem::MaybeUninit};
fn init_heap() {
const HEAP_SIZE: usize = 32 * 1024;
static mut HEAP: MaybeUninit<[u8; HEAP_SIZE]> = MaybeUninit::uninit();
unsafe {
esp_alloc::HEAP.add_region(esp_alloc::HeapRegion::new(
HEAP.as_mut_ptr() as *mut u8,
HEAP_SIZE,
esp_alloc::MemoryCapability::Internal.into(),
));
}
}
#[entry]
fn main() -> ! {
#[allow(unused)]
let peripherals = esp_hal::init(esp_hal::Config::default());
let delay = Delay::new();
let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
// slint use heap, setup allocator
init_heap();
// -------- Setup clocks --------
let sclk = io.pins.gpio13;
let miso = io.pins.gpio12;
let mosi = io.pins.gpio11;
let cs_screen = io.pins.gpio9;
let cs_touch = io.pins.gpio10;
let rst = io.pins.gpio18;
let dc = io.pins.gpio17;
//let v1_dc = OldOutputPin::new(io.pins.gpio17);
//let v1_cs = OldOutputPin::new(io.pins.gpio9);
//let v1_rst = OldOutputPin::new(io.pins.gpio18);
let mut spi = Spi::new(
peripherals.SPI2,
100.kHz(),
SpiMode::Mode0,
)
.with_pins(sclk, mosi, miso, cs_screen);
//let v2_dc = dc.forward();
//let v2_cs_s = cs_screen.reverse();
let di = SPIInterface::new(spi, dc, cs_screen);
//let di = display_interface_spi::SPIInterface::new(spi, v1_dc,v1_cs);
//let mut display = ST7789::new(di, Some(rst), None, 320, 480);
//let mut delay = Delay::new();
esp_println::logger::init_logger_from_env();
loop {
log::info!("Hello world!");
delay.delay(500.millis());
}
} [package]
name = "slint-test"
version = "0.1.0"
authors = ["moonlight seashell"]
edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
esp-backtrace = { version = "0.14.2", features = [
"esp32s3",
"exception-handler",
"panic-handler",
"println",
] }
esp-hal = { version = "0.21.0", features = [ "esp32s3" ] }
esp-println = { version = "0.12.0", features = ["esp32s3", "log"] }
log = { version = "0.4.22" }
esp-alloc = { version = "0.5.0" }
st7789 = "0.7.0"
embedded-graphics = "0.8.1"
display-interface-spi = "0.4.1"
embedded-hal = "1.0.0"
embedded-hal-compat = "0.13.0"
[profile.dev]
# Rust debug is too slow.
# For debug builds always builds with some optimization
opt-level = "s"
slint = { version = "1.8", default-features = false, features = ["compat-1-2", "renderer-software"] }
[build-dependencies]
slint-build = "1.8.0"
[profile.release]
codegen-units = 1 # LLVM can perform better optimizations using a single thread
debug = 2
debug-assertions = false
incremental = false
lto = 'fat'
opt-level = 's'
overflow-checks = false im pretty sure half of my depedency are useless anyway i always end with : error[E0277]: the trait bound `GpioPin<17>: embedded_hal_compat::embedded_hal::digital::v2::OutputPin` is not satisfied
--> src/main.rs:67:37
|
67 | let di = SPIInterface::new(spi, dc, cs_screen);
| ----------------- ^^ the trait `_embedded_hal_digital_OutputPin` is not implemented for `GpioPin<17>`, which is required by `GpioPin<17>: embedded_hal_compat::embedded_hal::digital::v2::OutputPin`
| |
| required by a bound introduced by this call
| or with an v1 / v2 compatibility error |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
We have an I2C example that is similar enough to what you need: https://github.com/esp-rs/esp-hal/blob/v0.21.1/examples/src/bin/i2c_display.rs You're also asking for I2C in the title, then have SPI in your code, so I guess you should sort out some of the basics first. |
Beta Was this translation helpful? Give feedback.
-
To answer the |
Beta Was this translation helpful? Give feedback.
-
it seems that on the esp32 the spi is fully managed at the hardware level. #![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
delay::Delay,
gpio::{Io, Level, NoPin ,Output},
prelude::*,
spi::{master::Spi,SpiMode},
};
use embedded_hal::spi::SpiBus;
#[entry]
fn main() -> ! {
// Initialisation des périphériques
let peripherals = esp_hal::init(esp_hal::Config::default());
let delay = Delay::new();
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
esp_println::logger::init_logger_from_env();
log::info!("SPI Setup Start");
// Configuration des broches SPI
let sclk = io.pins.gpio12;
let miso = io.pins.gpio13;
let mosi = io.pins.gpio11;
let cs = Output::new(io.pins.gpio10, Level::High);
// Initialisation de SPI
let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0)
.with_pins(sclk, mosi, miso, cs);
log::info!("SPI Initialized");
let data1 : u8 = 0xAA;
let data2 : u8 = 0x55;
// spi
loop {
let mut _err = spi.write_byte(data1);
let _spi_err = spi.flush();
_err = spi.write_byte(data2);
delay.delay(500.millis());
}
} |
Beta Was this translation helpful? Give feedback.
ok yep
i replace
SPIInterface
bySPIInterfaceNoCS::new(spi, dc);
because my cs is already set in the spi setupand i use this instead