initial working version of ili9341 disp

This commit is contained in:
2026-07-26 19:40:48 +00:00
parent f62b5165b4
commit 6201fcaab1
11 changed files with 2148 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
[target.xtensa-esp32s3-none-elf]
runner = "espflash flash --monitor --chip esp32s3"
[env]
ESP_LOG="info"
[build]
rustflags = [
"-C", "link-arg=-nostartfiles",
]
target = "xtensa-esp32s3-none-elf"
[unstable]
build-std = ["alloc", "core"]
+1
View File
@@ -0,0 +1 @@
stack-size-threshold = 1024
+26
View File
@@ -0,0 +1,26 @@
# will have compiled files and executables
debug/
target/
# Editor configuration
.vscode/
.zed/
.helix/
.nvim.lua
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# Ignore .DS_Store file in mac
**/.DS_Store
Generated
+1784
View File
File diff suppressed because it is too large Load Diff
+66
View File
@@ -0,0 +1,66 @@
[package]
edition = "2024"
name = "creaturedex"
rust-version = "1.88"
version = "0.1.0"
[[bin]]
name = "creaturedex"
path = "./src/bin/main.rs"
[dependencies]
esp-hal = { version = "~1.1.0", features = ["esp32s3", "log-04", "unstable"] }
esp-rtos = { version = "0.3.0", features = [
"esp-alloc",
"esp-radio",
"esp32s3",
"log-04",
] }
esp-bootloader-esp-idf = { version = "0.5.0", features = ["esp32s3", "log-04"] }
log = "0.4.27"
critical-section = "1.2.0"
embedded-io = "0.7.1"
esp-alloc = "0.10.0"
esp-println = { version = "0.17.0", features = ["esp32s3", "log-04"] }
esp-radio = { version = "0.18.0", features = [
"esp-alloc",
"esp32s3",
"log-04",
"unstable",
"wifi",
] }
smoltcp = { version = "0.13.0", default-features = false, features = [
"log",
"medium-ethernet",
"multicast",
"proto-dhcpv4",
"proto-dns",
"proto-ipv4",
"socket-dns",
"socket-icmp",
"socket-raw",
"socket-tcp",
"socket-udp",
] }
display-interface-spi = "0.5.0"
ili9341 = "0.6.0"
embedded-hal = "1.0.0"
embedded-hal-bus = "0.3.0"
embedded-graphics = "0.8.2"
embedded-graphics-core = "0.4.1"
# For fine tuning these settings, please refer to https://doc.rust-lang.org/cargo/reference/profiles.html
[profile.dev]
# The default debug profile is too slow and too big for resource-constrained devices.
# Always build with some optimizations enabled.
opt-level = "s"
[profile.release]
codegen-units = 1 # LLVM can perform better optimizations using a single thread
debug = 2 # prefer slower builds but better debugging experience
lto = 'fat'
opt-level = 's'
+70
View File
@@ -0,0 +1,70 @@
fn main() {
linker_be_nice();
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
println!("cargo:rustc-link-arg=-Tlinkall.x");
}
fn linker_be_nice() {
let args: Vec<String> = std::env::args().collect();
if args.len() > 1 {
let kind = &args[1];
let what = &args[2];
match kind.as_str() {
"undefined-symbol" => match what.as_str() {
what if what.starts_with("_defmt_") => {
eprintln!();
eprintln!(
"💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`"
);
eprintln!();
}
"_stack_start" => {
eprintln!();
eprintln!("💡 Is the linker script `linkall.x` missing?");
eprintln!();
}
what if what.starts_with("esp_rtos_") => {
eprintln!();
eprintln!(
"💡 `esp-radio` has no scheduler enabled. Make sure you have initialized `esp-rtos` or provided an external scheduler."
);
eprintln!();
}
"embedded_test_linker_file_not_added_to_rustflags" => {
eprintln!();
eprintln!(
"💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests"
);
eprintln!();
}
"free"
| "malloc"
| "calloc"
| "get_free_internal_heap_size"
| "malloc_internal"
| "realloc_internal"
| "calloc_internal"
| "free_internal" => {
eprintln!();
eprintln!(
"💡 Did you forget the `esp-alloc` dependency or didn't enable the `compat` feature on it?"
);
eprintln!();
}
_ => (),
},
// we don't have anything helpful for "missing-lib" yet
_ => {
std::process::exit(1);
}
}
std::process::exit(0);
}
println!(
"cargo:rustc-link-arg=-Wl,--error-handling-script={}",
std::env::current_exe().unwrap().display()
);
}
+44
View File
@@ -0,0 +1,44 @@
{
"version": 1,
"editor": "wokwi",
"parts": [
{ "type": "board-esp32-s3-devkitc-1", "id": "esp1", "top": 67.2, "left": -263.96, "attrs": {} },
{
"type": "board-ili9341-cap-touch",
"id": "lcd1",
"top": -191.24,
"left": -0.38,
"attrs": {}
},
{
"type": "wokwi-led",
"id": "led1",
"top": -82.89,
"left": 196.26,
"attrs": { "color": "red" }
},
{
"type": "wokwi-resistor",
"id": "r1",
"top": 183.86,
"left": 154.06,
"attrs": { "value": "220" }
}
],
"connections": [
[ "lcd1:VCC", "esp1:3V3", "red", [ "v19.2", "h-57.6", "v-105.6", "h-124.95" ] ],
[ "lcd1:GND", "esp1:GND.2", "black", [ "v28.8", "h-76.8", "v-76.8" ] ],
[ "lcd1:CS", "esp1:11", "orange", [ "v0" ] ],
[ "lcd1:D/C", "esp1:12", "gold", [ "v0" ] ],
[ "lcd1:RESET", "esp1:10", "brown", [ "v0" ] ],
[ "lcd1:MOSI", "esp1:35", "violet", [ "v105.6", "h-124.8", "v-144" ] ],
[ "lcd1:SCK", "esp1:36", "white", [ "v115.2", "h-144", "v-86.4" ] ],
[ "esp1:37", "lcd1:MISO", "magenta", [ "h57.6", "v105.6", "h172.8" ] ],
[ "esp1:22", "lcd1:SCL", "yellow", [ "h48", "v163.2", "h192" ] ],
[ "esp1:21", "lcd1:SDA", "cyan", [ "h38.4", "v144", "h211.2" ] ],
[ "r1:2", "led1:A", "green", [ "h8.4", "v-230.4" ] ],
[ "esp1:GND.2", "led1:C", "black", [ "v0", "h86.4", "v76.8", "h278.4" ] ],
[ "esp1:17", "r1:1", "green", [ "h0" ] ]
],
"dependencies": {}
}
+2
View File
@@ -0,0 +1,2 @@
[toolchain]
channel = "esp"
+134
View File
@@ -0,0 +1,134 @@
#![no_std]
#![no_main]
#![deny(
clippy::mem_forget,
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
holding buffers for the duration of a data transfer."
)]
#![deny(clippy::large_stack_frames)]
use display_interface_spi::SPIInterface;
use embedded_graphics::Drawable;
use embedded_graphics::mono_font::MonoTextStyle;
use embedded_graphics::mono_font::ascii::FONT_6X10;
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::Point;
use embedded_graphics::prelude::RgbColor;
use embedded_graphics::text::Text;
use embedded_graphics_core::draw_target::DrawTarget;
use embedded_hal_bus::spi::ExclusiveDevice;
use esp_hal::clock::CpuClock;
use esp_hal::delay::Delay;
use esp_hal::gpio::Level;
use esp_hal::gpio::Output;
use esp_hal::gpio::OutputConfig;
use esp_hal::main;
use esp_hal::spi::{
Mode,
master::{Config, Spi},
};
use esp_hal::time::Rate;
use esp_hal::time::{Duration, Instant};
use esp_hal::timer::timg::TimerGroup;
use ili9341::Ili9341;
use ili9341::Orientation;
use log::{error, info};
#[panic_handler]
fn panic(panic_info: &core::panic::PanicInfo) -> ! {
error!("{}", panic_info);
loop {}
}
extern crate alloc;
// This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();
#[allow(
clippy::large_stack_frames,
reason = "it's not unusual to allocate larger buffers etc. in main"
)]
#[main]
fn main() -> ! {
// generator version: 1.3.0
// generator parameters: --chip esp32s3 -o esp32s3-wroom-1-octal-psram -o unstable-hal -o alloc -o wifi -o log -o wokwi -o neovim -o vscode -o esp
esp_println::logger::init_logger_from_env();
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
// The following pins are used to bootstrap the chip. They are available
// for use, but check the datasheet of the module for more information on them.
// - GPIO0
// - GPIO3
// - GPIO45
// - GPIO46
// These GPIO pins are in use by some feature of the module and should not be used.
let _ = peripherals.GPIO27;
let _ = peripherals.GPIO28;
let _ = peripherals.GPIO29;
let _ = peripherals.GPIO30;
let _ = peripherals.GPIO31;
let _ = peripherals.GPIO32;
let _ = peripherals.GPIO33;
let _ = peripherals.GPIO34;
let _ = peripherals.GPIO35;
let _ = peripherals.GPIO36;
let _ = peripherals.GPIO37;
esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 73744);
let timg0 = TimerGroup::new(peripherals.TIMG0);
let sw_interrupt =
esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
let (mut _wifi_controller, _interfaces) =
esp_radio::wifi::new(peripherals.WIFI, Default::default())
.expect("Failed to initialize Wi-Fi controller");
let spi_bus = Spi::new(
peripherals.SPI2,
Config::default()
.with_frequency(Rate::from_khz(100))
.with_mode(Mode::_0),
)
.unwrap()
.with_sck(peripherals.GPIO36)
.with_mosi(peripherals.GPIO35)
.with_miso(peripherals.GPIO37);
let cs_main = Output::new(peripherals.GPIO11, Level::High, OutputConfig::default());
let mut delay = Delay::new();
let spi_dev = ExclusiveDevice::new(spi_bus, cs_main, delay).unwrap();
let reset_main = Output::new(peripherals.GPIO10, Level::High, OutputConfig::default());
let spi_dc = Output::new(peripherals.GPIO12, Level::High, OutputConfig::default());
let iface = SPIInterface::new(spi_dev, spi_dc);
let mut display = Ili9341::new(
iface,
reset_main,
&mut delay,
Orientation::Landscape,
ili9341::DisplaySize240x320,
)
.unwrap();
display.clear(Rgb565::BLACK).unwrap();
let style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
Text::new("Hello, ESP32!", Point::new(20, 100), style)
.draw(&mut display)
.unwrap();
loop {
info!("Hello world!");
let delay_start = Instant::now();
while delay_start.elapsed() < Duration::from_millis(500) {}
}
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.1.0/examples
}
+1
View File
@@ -0,0 +1 @@
#![no_std]
+5
View File
@@ -0,0 +1,5 @@
[wokwi]
version = 1
gdbServerPort = 3333
elf = "target/xtensa-esp32s3-none-elf/debug/creaturedex"
firmware = "target/xtensa-esp32s3-none-elf/debug/creaturedex"