From d632f29deedc18f83bf4f51d56a29b5ace9eded1 Mon Sep 17 00:00:00 2001 From: puffaboo Date: Wed, 13 Jul 2022 21:54:52 +0100 Subject: [PATCH] Initial commit -- have an eye --- .cargo/config.toml | 34 +++++++++++++++++++++ .gitignore | 4 +++ Cargo.toml | 30 ++++++++++++++++++ build.rs | 5 +++ rust-toolchain.toml | 2 ++ sdkconfig.defaults | 10 ++++++ src/eye.bmp | Bin 0 -> 8262 bytes src/main.rs | 73 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 158 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/eye.bmp create mode 100644 src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..357b621 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,34 @@ +[build] +# Uncomment the relevant target for your chip here (ESP32, ESP32-S2, ESP32-S3 or ESP32-C3) +target = "xtensa-esp32-espidf" +#target = "xtensa-esp32s2-espidf" +#target = "xtensa-esp32s3-espidf" +#target = "riscv32imc-esp-espidf" + +[target.xtensa-esp32-espidf] +linker = "ldproxy" + +[target.xtensa-esp32s2-espidf] +linker = "ldproxy" + +[target.xtensa-esp32s3-espidf] +linker = "ldproxy" + +[target.riscv32imc-esp-espidf] +linker = "ldproxy" + +# Future - necessary for the experimental "native build" of esp-idf-sys with ESP32C3 +# See also https://github.com/ivmarkov/embuild/issues/16 +rustflags = ["-C", "default-linker-libraries"] + +[unstable] + +build-std = ["std", "panic_abort"] +#build-std-features = ["panic_immediate_abort"] # Required for older ESP-IDF versions without a realpath implementation + +[env] +# Note: these variables are not used when using pio builder +# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF stable (v4.4) +ESP_IDF_VERSION = { value = "branch:release/v4.4" } +# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF master (mainline) +#ESP_IDF_VERSION = { value = "master" } 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..0899395 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "eyeiii" +version = "0.1.0" +authors = ["puffaboo "] +edition = "2018" +resolver = "2" + +[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] +pio = ["esp-idf-sys/pio"] + +[dependencies] +embedded-graphics = "0.7.1" +embedded-hal = "1.0.0-alpha.8" +esp-idf-hal = "0.38.0" +esp-idf-svc = "0.42.0" +esp-idf-sys = { version = "0.31.6", features = ["binstart"] } +ssd1331 = "0.3.0" +tinybmp = "0.3.3" + + +[build-dependencies] +embuild = "0.29" +anyhow = "1" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..4dd5e1f --- /dev/null +++ b/build.rs @@ -0,0 +1,5 @@ +// Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641 +fn main() -> anyhow::Result<()> { + embuild::build::CfgArgs::output_propagated("ESP_IDF")?; + embuild::build::LinkArgs::output_propagated("ESP_IDF") +} 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..a139649 --- /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=20000 + +# Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default). +# This allows to use 1 ms granuality 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/eye.bmp b/src/eye.bmp new file mode 100644 index 0000000000000000000000000000000000000000..b94fbde7d7715d10f3577168837d53ad302b832e GIT binary patch literal 8262 zcmeHLL1^1n7}l6gbjU%6z$`G#k4;b=HZbYP9Bh~aG9-||0)-~Qhq$zdndMMJ!D^j@ zHykh_fhG*@6h(baQPelhzmF(}`WXEZps3HjH2zw6Ls5VAP}HZb zFS_WWi!Qq8!W{&Dc;v<8LUJ$l^76~ed#Rb^lSz8$H=nz^Pl{=p9^6Zv+3-mZS`SgsV-^Fp`XvzGc8SFI8nJce}O-#*9JZZ%$12s#Bf>X#hec{XtHZid)PW& ztv3mP95Z5At*4d6@~I^?PmWVdi{-RJ=xjO>fzP&Yjk{McP4A^1 z$jHNXZb@s@7Rw|rdA3+?)T};8O&|VLzWs5{l?xv5s%S(`#G=Q3RvGSyo8(vX!%Jrs zLV>ob*JT7=+Q_}N7B2AjZ=-t45ZN@I_xfqiTiKDCo~74MNd=N-)MQ8+9yuxxk3(;^ zk?)<6OWIk*9lN2R-2>zTda@{QI#z#LPl5;F*nvw z63MHswbh|f6G%ZwYOlmwhvr8HoeMvmeo2=H)^E|0wvD{vTtt`MZ8`Ctd#A*8e zwtdZ`JHo29+f=fhv70J#A!`;+Es;IZRD&up4DX~cfA5sv(ffzmfNb?OmN41uK4S^% zwF5F<7fg2aiDsi%Ip12H`c|Byhg$!R^_kAmBR#p0_1gX&yhd61B`vN-AaliVV49w& zIOkr{wk#dDl(mc6`ki$)ZrN7=azKr%&$f*k_}eGShvdpZs2y9!F_lCsm))_o2FKRP zC*iZ%`k^vW$?7XYfVvsn4Ng?>ujJ8(;P*+p!JEP6zb_~cD}aNdQ?ArXBJiN&F~$`4}xT*vy8wpo9|>gYKEcnI%JL}@Q8fCU=`c>UeHj`bZBO?J2I zZy0``6o8inCS@CZ`|`&LlD@;EwgMS!aM zIKY9KWcz$P+5TIUN0aDzRiAanAB{DJ1IUG6mdP1;-1iSZyt|Ad=U8`d9~e=(>JtD5 z_@P%ts|NS)Uw(K{O&OZ*Kd%Y~~ z^T!83nP8C*G0;2ps+g9|HzP>Af1AqUYFa)h_D;nB%Ac2AW1Qx?djzO8#>1lL2_OdO z!8@tG6>X;=H}?H7tcF!TZ0w7&w$rz=kfaA=`gI)eyccea1pSCXt0Ypv0gmO^7?|UC zgS){wKBk|Wzj@h5OyYH1zxtOq6y%%T5kJCFlg5ZH@#T RrQbczU3Ae!7hU|H@E?w&>~a7A literal 0 HcmV?d00001 diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..4a43557 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,73 @@ +use std::{error::Error, thread::sleep, time::Duration}; + +use embedded_graphics::{image::Image, pixelcolor::Rgb565, prelude::*}; +use esp_idf_hal::{ + gpio::{Gpio16, Gpio17, Gpio18, Gpio23, Gpio5, Output}, + prelude::{Hertz, Peripherals}, + spi::{self, Pins, SPI3}, +}; +use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported +use ssd1331::{DisplayRotation::Rotate0, Ssd1331}; +use tinybmp::Bmp; + +fn secondary() -> Result<(), Box> { + // Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once, + // or else some patches to the runtime implemented by esp-idf-sys might not link properly. + esp_idf_sys::link_patches(); + + // Bind the log crate to the ESP Logging facilities + esp_idf_svc::log::EspLogger::initialize_default(); + let peripherals = Peripherals::take().unwrap(); + let spi3 = peripherals.spi3; + let pins = peripherals.pins; + let cs: Gpio17 = pins.gpio17.into_output()?; + let dc: Gpio16 = pins.gpio16.into_output()?; + let mosi: Gpio23 = pins.gpio23.into_output()?; + let sclk: Gpio18 = pins.gpio18.into_output()?; + let reset: Gpio5 = pins.gpio5.into_output()?; + + // // Set up SPI interface and digital pin. These are stub implementations used in examples. + let spiman = + spi::Master::, Gpio23, Gpio5, Gpio17>::new( + spi3, + Pins { + sclk: sclk, + sdo: mosi, + sdi: Some(reset), + cs: Some(cs), + }, + spi::config::Config { + baudrate: Hertz(24000000), + data_mode: embedded_hal::spi::MODE_0, + write_only: false, + dma: spi::Dma::Disabled, + }, + )?; + let mut display = Ssd1331::new(spiman, dc, Rotate0); + display.init().unwrap(); + + display.flush().unwrap(); + + let (w, h) = display.dimensions(); + println!("got resolution {} x {}", w.clone(), h.clone()); + + let bmp = Bmp::from_slice(include_bytes!("./eye.bmp")).expect("Failed to load BMP image"); + + let im: Image> = Image::new(&bmp, Point::zero()); + + // Position image in the center of the display + let moved = im.translate(Point::new( + (w as u32 - bmp.size().width) as i32 / 2, + (h as u32 - bmp.size().height) as i32 / 2, + )); + + moved.draw(&mut display).unwrap(); + + display.flush().unwrap(); + Ok(()) +} + +fn main() -> Result<(), Box> { + sleep(Duration::from_secs(1)); + Ok(secondary().unwrap()) +}