platform: rewrite the platform-specific display creation traits into a new Board trait that also supports tasks
This commit is contained in:
52
src/main.rs
52
src/main.rs
@@ -9,31 +9,14 @@ mod animations;
|
||||
mod mappings;
|
||||
mod buffers;
|
||||
|
||||
use buffers::SurfacePool;
|
||||
use esp_idf_svc::hal::prelude::Peripherals;
|
||||
|
||||
use crate::platform::DisplayInit;
|
||||
use crate::render::Surfaces;
|
||||
use crate::platform::Board;
|
||||
use crate::task::{Task, Scheduler};
|
||||
use crate::render::{Surfaces, Renderer};
|
||||
use crate::geometry::Rectangle;
|
||||
|
||||
#[cfg(feature="embedded-graphics")]
|
||||
#[cfg(feature="rmt")]
|
||||
use crate::platform::embedded_graphics_lib::PonderjarTarget as DisplayType;
|
||||
|
||||
#[cfg(feature="smart-leds")]
|
||||
#[cfg(feature="rmt")]
|
||||
use crate::platform::smart_leds_lib::rmt::FastWs2812Esp32Rmt as DisplayType;
|
||||
|
||||
#[cfg(feature="smart-leds")]
|
||||
#[cfg(feature="spi")]
|
||||
use crate::platform::smart_leds_lib::spi::SPIDisplay as DisplayType;
|
||||
|
||||
#[cfg(feature="threads")]
|
||||
use crate::buffers::SharedSurface as SurfaceType;
|
||||
|
||||
#[cfg(not(feature="threads"))]
|
||||
use crate::buffers::SimpleSurface as SurfaceType;
|
||||
|
||||
use crate::render::Renderer;
|
||||
use crate::platform::esp32::Esp32Board as BoardType;
|
||||
|
||||
fn main() {
|
||||
// It is necessary to call this function once. Otherwise some patches to the runtime
|
||||
@@ -43,20 +26,27 @@ fn main() {
|
||||
// Bind the log crate to the ESP Logging facilities
|
||||
esp_idf_svc::log::EspLogger::initialize_default();
|
||||
|
||||
log::info!("Setting up display");
|
||||
let peripherals = Peripherals::take().unwrap();
|
||||
let mut board: BoardType = Board::new(peripherals);
|
||||
|
||||
log::info!("Board: {}", core::any::type_name_of_val(&board));
|
||||
|
||||
let display = DisplayType::new_display::<SurfaceType>();
|
||||
let output = board.output();
|
||||
log::info!("Output: {}", core::any::type_name_of_val(&output));
|
||||
|
||||
let mut surfaces: SurfacePool<SurfaceType> = SurfacePool::new();
|
||||
let mut surfaces = board.surfaces();
|
||||
log::info!("Surface implementation: {}", core::any::type_name_of_val(&output));
|
||||
|
||||
log::info!("Created new display type {}", core::any::type_name_of_val(&display));
|
||||
|
||||
log::info!("Creating runner");
|
||||
let mut runner = task::Scheduler::new(vec![
|
||||
log::info!("Creating animations");
|
||||
let mut tasks: Vec<Box<dyn Task + 'static>> = vec![
|
||||
Box::new(animations::IdleTask::new(&mut surfaces)),
|
||||
Box::new(animations::TestPattern::new(surfaces.new_surface(&Rectangle::everything()).unwrap())),
|
||||
Box::new(Renderer::new(display, surfaces)),
|
||||
]);
|
||||
];
|
||||
|
||||
tasks.append(&mut board.system_tasks());
|
||||
tasks.push(Box::new(Renderer::new(output, surfaces)));
|
||||
|
||||
let mut runner = Scheduler::new(tasks);
|
||||
|
||||
log::info!("Runner ready: {:?}", runner);
|
||||
|
||||
|
Reference in New Issue
Block a user