Initial commit

This commit is contained in:
ZacJW 2025-07-12 14:20:37 +01:00
commit 639ee2af7f
11 changed files with 1844 additions and 0 deletions

View file

@ -0,0 +1,25 @@
[package]
name = "display_test"
version = "0.1.0"
edition = "2024"
[[bin]]
name = "display_test"
harness = false # do not use the built in cargo test harness -> resolve rust-analyzer errors
[profile.release]
opt-level = "s"
debug = true
panic = "abort"
[profile.dev]
debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"
panic = "abort"
[dependencies]
cardputer-bsc-nostd = { version = "0.1.0", path = "../.." }
embedded-graphics = "0.8.1"
esp-hal = {version = "=1.0.0-beta.1", features = ["esp32s3", "unstable"]}
esp-println = { version = "0.14.0", features = ["esp32s3"] }
esp-bootloader-esp-idf = "0.1.0"

View file

@ -0,0 +1,52 @@
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() {
"_defmt_timestamp" => {
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!();
}
"esp_wifi_preempt_enable"
| "esp_wifi_preempt_yield_task"
| "esp_wifi_preempt_task_create" => {
eprintln!();
eprintln!("💡 `esp-wifi` has no scheduler enabled. Make sure you have the `builtin-scheduler` feature enabled, or that you provide 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!();
}
_ => (),
},
// 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()
);
}

View file

@ -0,0 +1,89 @@
#![no_std]
#![no_main]
use core::panic::PanicInfo;
use cardputer_bsc_nostd::display::{DISPLAY_SIZE_HEIGHT, DISPLAY_SIZE_WIDTH};
use embedded_graphics::pixelcolor::Rgb565;
use esp_hal::{
ledc::{LowSpeed, channel::ChannelIFace, timer::TimerIFace},
main,
};
use esp_println::println;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
println!("{info}");
esp_hal::system::software_reset()
}
esp_bootloader_esp_idf::esp_app_desc!();
#[main]
fn entrypoint() -> ! {
_main();
println!("main exited, entering infinite loop");
loop {}
}
fn _main() {
let peripherals = esp_hal::init(esp_hal::Config::default());
let mut display = cardputer_bsc_nostd::display::build(
peripherals.SPI2,
peripherals.GPIO36,
peripherals.GPIO35,
peripherals.GPIO37,
peripherals.GPIO34,
peripherals.GPIO33,
)
.unwrap();
let mut ledc = esp_hal::ledc::Ledc::new(peripherals.LEDC);
ledc.set_global_slow_clock(esp_hal::ledc::LSGlobalClkSource::APBClk);
let mut timer = ledc.timer::<LowSpeed>(esp_hal::ledc::timer::Number::Timer3);
timer.configure(esp_hal::ledc::timer::config::Config {
duty: esp_hal::ledc::timer::config::Duty::Duty8Bit,
clock_source: esp_hal::ledc::timer::LSClockSource::APBClk,
frequency: esp_hal::time::Rate::from_hz(256),
}).unwrap();
let mut backlight: esp_hal::ledc::channel::Channel<'_, _> =
ledc.channel(esp_hal::ledc::channel::Number::Channel7, peripherals.GPIO38);
backlight
.configure(esp_hal::ledc::channel::config::Config {
timer: &timer,
duty_pct: 100,
pin_config: esp_hal::ledc::channel::config::PinConfig::PushPull,
})
.unwrap();
display
.set_pixels(
0,
0,
DISPLAY_SIZE_WIDTH - 1,
DISPLAY_SIZE_HEIGHT - 1,
core::iter::repeat_n(
Rgb565::new(0, 0, 0),
DISPLAY_SIZE_WIDTH as usize * DISPLAY_SIZE_HEIGHT as usize,
),
)
.unwrap();
display
.set_pixels(
20,
20,
DISPLAY_SIZE_WIDTH - 21,
DISPLAY_SIZE_HEIGHT - 21,
core::iter::repeat_n(
Rgb565::new(31, 0, 0),
DISPLAY_SIZE_WIDTH as usize * DISPLAY_SIZE_HEIGHT as usize,
),
)
.unwrap();
}