Wrote test code
This commit is contained in:
parent
f2f8705eff
commit
de3519cfe3
2 changed files with 94 additions and 0 deletions
|
|
@ -18,6 +18,8 @@ experimental = ["esp-idf-svc/experimental"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
esp-idf-svc = { version = "0.51", features = ["critical-section", "embassy-time-driver", "embassy-sync"] }
|
esp-idf-svc = { version = "0.51", features = ["critical-section", "embassy-time-driver", "embassy-sync"] }
|
||||||
|
cardputer-bsc = { version = "0.1.0", path = "../cardputer-bsc" }
|
||||||
|
embedded-graphics-core = "0.4.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
embuild = "0.33"
|
embuild = "0.33"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,14 @@
|
||||||
|
use std::{thread::sleep, time::Duration};
|
||||||
|
|
||||||
|
use cardputer_bsc::display::{DISPLAY_SIZE_HEIGHT, DISPLAY_SIZE_WIDTH};
|
||||||
|
use embedded_graphics_core::pixelcolor::Rgb565;
|
||||||
|
use esp_idf_svc::hal::{
|
||||||
|
ledc::{self, config::TimerConfig, LedcDriver, LedcTimerDriver, SpeedMode},
|
||||||
|
prelude::Peripherals,
|
||||||
|
rmt::config::DutyPercent,
|
||||||
|
units::Hertz,
|
||||||
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// It is necessary to call this function once. Otherwise some patches to the runtime
|
// 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
|
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
|
||||||
|
|
@ -7,4 +18,85 @@ fn main() {
|
||||||
esp_idf_svc::log::EspLogger::initialize_default();
|
esp_idf_svc::log::EspLogger::initialize_default();
|
||||||
|
|
||||||
log::info!("Hello, world!");
|
log::info!("Hello, world!");
|
||||||
|
|
||||||
|
let Ok(peripherals) = Peripherals::take() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut display = match cardputer_bsc::display::build(
|
||||||
|
peripherals.spi2,
|
||||||
|
peripherals.pins.gpio36,
|
||||||
|
peripherals.pins.gpio35,
|
||||||
|
peripherals.pins.gpio37,
|
||||||
|
peripherals.pins.gpio34,
|
||||||
|
peripherals.pins.gpio33,
|
||||||
|
) {
|
||||||
|
Ok(display) => display,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Failed to initialise display: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let timer_config = TimerConfig::new()
|
||||||
|
.resolution(ledc::Resolution::Bits8)
|
||||||
|
.frequency(Hertz(256).into());
|
||||||
|
let bl_timer_driver = match LedcTimerDriver::new(peripherals.ledc.timer3, &timer_config) {
|
||||||
|
Ok(bl_timer_driver) => bl_timer_driver,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Failed to create backlight timer: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut bl_driver = match LedcDriver::new(
|
||||||
|
peripherals.ledc.channel7,
|
||||||
|
bl_timer_driver,
|
||||||
|
peripherals.pins.gpio38,
|
||||||
|
) {
|
||||||
|
Ok(bl_driver) => bl_driver,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Failed to create backlight driver: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dbg!(display.is_sleeping());
|
||||||
|
|
||||||
|
display.set_pixels(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
DISPLAY_SIZE_WIDTH - 1,
|
||||||
|
DISPLAY_SIZE_HEIGHT - 1,
|
||||||
|
std::iter::repeat_n(
|
||||||
|
Rgb565::new(0, 0, 0),
|
||||||
|
DISPLAY_SIZE_WIDTH as usize * DISPLAY_SIZE_HEIGHT as usize,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
let _ = display
|
||||||
|
.set_pixels(
|
||||||
|
10,
|
||||||
|
10,
|
||||||
|
19,
|
||||||
|
39,
|
||||||
|
std::iter::repeat_n(Rgb565::new(0b00011111, 0, 0), 300),
|
||||||
|
)
|
||||||
|
.inspect_err(|e| log::error!("Failed to set pixels: {e:?}"));
|
||||||
|
|
||||||
|
match bl_driver.set_duty(bl_driver.get_max_duty()) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Failed to set duty: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match bl_driver.enable() {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Failed to enable driver: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loop {
|
||||||
|
sleep(Duration::from_secs(1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue