main: split out display init code to a trait

This commit is contained in:
Victoria Fischer 2024-10-28 23:31:21 +01:00
parent f264964ebb
commit a0d42d2274

View File

@ -19,7 +19,8 @@ mod embedded_graphics_lib;
use crate::time::Periodically; use crate::time::Periodically;
use crate::geometry::{Coordinates, VirtualCoordinates}; use crate::geometry::{Coordinates, VirtualCoordinates};
use crate::embedded_graphics_lib::EmbeddedDisplay; use crate::embedded_graphics_lib::EmbeddedDisplay;
use crate::render::{Surfaces, Surface, SimpleSurface}; use crate::render::{Surfaces, Surface, SimpleSurface, Display};
use crate::task::Task;
struct IdleTask<T: Surface> { struct IdleTask<T: Surface> {
frame: u8, frame: u8,
@ -84,16 +85,12 @@ impl LedPixelShape for PonderjarMatrix {
type PonderjarTarget<'a> = Ws2812DrawTarget<'a, PonderjarMatrix>; type PonderjarTarget<'a> = Ws2812DrawTarget<'a, PonderjarMatrix>;
fn main() { trait DisplayInit {
// It is necessary to call this function once. Otherwise some patches to the runtime fn new_display<S: Surface>() -> impl Display<S> + Task;
// 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!");
impl<Shape: LedPixelShape> DisplayInit for Ws2812DrawTarget<'_, Shape> {
fn new_display<S: Surface>() -> impl Display<S> + Task {
let peripherals = Peripherals::take().unwrap(); let peripherals = Peripherals::take().unwrap();
let led_pin = peripherals.pins.gpio14; let led_pin = peripherals.pins.gpio14;
let channel = peripherals.rmt.channel0; let channel = peripherals.rmt.channel0;
@ -102,9 +99,21 @@ fn main() {
const POWER_MA : u32 = 500; const POWER_MA : u32 = 500;
const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA; const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA;
let target = Self::new(channel, led_pin).unwrap();
return EmbeddedDisplay::<Self, S>::new(target, MAX_POWER_MW);
}
}
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!("Setting up display"); log::info!("Setting up display");
let target = PonderjarTarget::new(channel, led_pin).unwrap(); let mut display = PonderjarTarget::new_display::<SimpleSurface>();
let mut display = EmbeddedDisplay::<PonderjarTarget, SimpleSurface>::new(target, MAX_POWER_MW);
log::info!("Creating runner"); log::info!("Creating runner");
let mut runner = task::Scheduler::new(vec![ let mut runner = task::Scheduler::new(vec![