From 3c280391c880593e7c4dc5ff958b9d138de22a45 Mon Sep 17 00:00:00 2001 From: zenonet Date: Sun, 7 Sep 2025 13:54:28 +0200 Subject: [PATCH] Not working upload but atleast no crash --- .cargo/config.toml | 16 +++++++ .gitignore | 4 ++ Cargo.toml | 51 +++++++++++++++++++++ build.rs | 3 ++ rust-toolchain.toml | 2 + sdkconfig.defaults | 10 +++++ src/main.rs | 107 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 193 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 rust-toolchain.toml create mode 100644 sdkconfig.defaults create mode 100644 src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..6fdd194 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,16 @@ +[build] +target = "xtensa-esp32-espidf" + +[target.xtensa-esp32-espidf] +linker = "ldproxy" +runner = "espflash flash --monitor" +rustflags = [ "--cfg", "espidf_time64"] + +[unstable] +build-std = ["std", "panic_abort"] + +[env] +MCU="esp32" +# Note: this variable is not used by the pio builder (`cargo build --features pio`) +ESP_IDF_VERSION = "v5.3.2" + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73a638b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.vscode +/.embuild +/target +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f1934b6 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,51 @@ +[package] +name = "esp-epd" +version = "0.1.0" +authors = ["zenonet "] +edition = "2021" +resolver = "2" +rust-version = "1.77" + +[[bin]] +name = "esp-epd" +harness = false # do not use the built in cargo test harness -> resolve rust-analyzer errors + +[profile.release] +opt-level = "s" + +[profile.dev] +debug = true # Symbols are nice and they don't increase the size on Flash +opt-level = "z" + +[features] +default = [] + +experimental = ["esp-idf-svc/experimental"] + +[dependencies] +log = "0.4" +esp-idf-svc = "0.51" +esp-idf-hal = "0.45.2" +epd-waveshare = "0.6.0" +embedded-graphics = "0.8.1" +embedded-hal = "1.0.0" + +# --- Optional Embassy Integration --- +# esp-idf-svc = { version = "0.51", features = ["critical-section", "embassy-time-driver", "embassy-sync"] } + +# If you enable embassy-time-driver, you MUST also add one of: + +# a) Standalone Embassy libs ( embassy-time, embassy-sync etc) with a foreign async runtime: +# embassy-time = { version = "0.4.0", features = ["generic-queue-8"] } # NOTE: any generic-queue variant will work + +# b) With embassy-executor: +# embassy-executor = { version = "0.7", features = ["executor-thread", "arch-std"] } + +# NOTE: if you use embassy-time with embassy-executor you don't need the generic-queue-8 feature + +# --- Temporary workaround for embassy-executor < 0.8 --- +# esp-idf-svc = { version = "0.51", features = ["embassy-time-driver", "embassy-sync"] } +# critical-section = { version = "1.1", features = ["std"], default-features = false } + +[build-dependencies] +embuild = "0.33" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..112ec3f --- /dev/null +++ b/build.rs @@ -0,0 +1,3 @@ +fn main() { + embuild::espidf::sysenv::output(); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..a2f5ab5 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "esp" diff --git a/sdkconfig.defaults b/sdkconfig.defaults new file mode 100644 index 0000000..c25b89d --- /dev/null +++ b/sdkconfig.defaults @@ -0,0 +1,10 @@ +# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K) +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8000 + +# Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default). +# This allows to use 1 ms granularity for thread sleeps (10 ms by default). +#CONFIG_FREERTOS_HZ=1000 + +# Workaround for https://github.com/espressif/esp-idf/issues/7631 +#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n +#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c183946 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,107 @@ +use embedded_graphics::{mono_font::MonoTextStyleBuilder, prelude::Point, Drawable, text::{Baseline, Text, TextStyleBuilder}}; +use epd_waveshare::{color::Color, epd7in5_v2::Epd7in5, prelude::WaveshareDisplay}; +use esp_idf_hal::{delay::{Delay, Ets}, gpio::PinDriver, spi::{config, Spi, SpiDriver, SpiDriverConfig}}; +use esp_idf_svc::hal::{prelude::*, spi::SpiDeviceDriver}; +use embedded_hal::delay::DelayNs; + + +//static mut display: epd_waveshare::epd7in5_v2::Display7in5 = epd_waveshare::epd7in5_v2::Display7in5::default(); + +static FRAMEBUF: [u8; 48000] = [1; 48000]; +fn main() { + // It is necessary to call this function once. Otherwise some patches to the runtime + // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 + esp_idf_svc::sys::link_patches(); + + // Bind the log crate to the ESP Logging facilities + esp_idf_svc::log::EspLogger::initialize_default(); + + log::info!("Hello, world!"); + log::info!("Just logging something again"); + + let peripherals = Peripherals::take().unwrap(); + + log::info!("Took peripherals"); + + let busy = PinDriver::input(peripherals.pins.gpio4).unwrap(); + let rst = PinDriver::output(peripherals.pins.gpio16).unwrap(); + let dc = PinDriver::output(peripherals.pins.gpio17).unwrap(); + let cs = peripherals.pins.gpio5; + let clk = peripherals.pins.gpio18; + let mosi = peripherals.pins.gpio23; + + log::info!("Initialized pins"); + + + let config = config::Config::new(); + + let mut spi = SpiDeviceDriver::new_single( + peripherals.spi3, + clk, + peripherals.pins.gpio21, + Some(mosi), + Some(cs), + &SpiDriverConfig::default(), + &config + ).unwrap(); + + log::info!("Initialized spi interface"); + + //static mut display: epd_waveshare::epd7in5_v2::Display7in5 = epd_waveshare::epd7in5_v2::Display7in5::default(); + + let mut delay = Ets; + + let mut epd7in5 = Epd7in5::new(&mut spi, busy, dc, rst, &mut delay, None).unwrap(); + log::info!("Created epd object"); + + log::info!("Created display object"); + + + //draw_text(&mut display, "Hello esp", 5, 50); + log::info!("Draw text done"); + + + let res = epd7in5.update_and_display_frame(&mut spi, &FRAMEBUF, &mut delay); + + + if let Err(e) = res{ + log::info!("{}", e); + } + +/* let mut i = 0; + loop{ + let d = &mut delay; + d.delay_ms(500); + log::info!("Loop {}", i); + i += 1; + + if i == 5{ + //let data = display.buffer(); + +/* for d in data{ + log::info!("{}", d) + } */ + + } + } */ + +/* + // Get SpiDevice trait implementation + //let mut spi_device = spi.into_device(); + + // let mut epd7in5 = Epd7in5::new(spi, busy, dc, rst, delay, delay_us) + */ +} + +fn draw_text(display: &mut epd_waveshare::epd7in5_v2::Display7in5, text: &str, x: i32, y: i32) { + let style = MonoTextStyleBuilder::new() + .font(&embedded_graphics::mono_font::ascii::FONT_6X10) + .text_color(Color::White) + .background_color(Color::Black) + .build(); + + let text_style = TextStyleBuilder::new().baseline(Baseline::Top).build(); + + // The problem: + //let _ = Text::with_text_style(text, Point::new(x, y), style, text_style).draw(display); +}