main: split out display init code to a trait
This commit is contained in:
parent
f264964ebb
commit
a0d42d2274
35
src/main.rs
35
src/main.rs
@ -19,7 +19,8 @@ mod embedded_graphics_lib;
|
||||
use crate::time::Periodically;
|
||||
use crate::geometry::{Coordinates, VirtualCoordinates};
|
||||
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> {
|
||||
frame: u8,
|
||||
@ -84,6 +85,25 @@ impl LedPixelShape for PonderjarMatrix {
|
||||
|
||||
type PonderjarTarget<'a> = Ws2812DrawTarget<'a, PonderjarMatrix>;
|
||||
|
||||
trait DisplayInit {
|
||||
fn new_display<S: Surface>() -> impl Display<S> + Task;
|
||||
}
|
||||
|
||||
impl<Shape: LedPixelShape> DisplayInit for Ws2812DrawTarget<'_, Shape> {
|
||||
fn new_display<S: Surface>() -> impl Display<S> + Task {
|
||||
let peripherals = Peripherals::take().unwrap();
|
||||
let led_pin = peripherals.pins.gpio14;
|
||||
let channel = peripherals.rmt.channel0;
|
||||
|
||||
const POWER_VOLTS : u32 = 5;
|
||||
const POWER_MA : u32 = 500;
|
||||
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
|
||||
@ -92,19 +112,8 @@ fn main() {
|
||||
// Bind the log crate to the ESP Logging facilities
|
||||
esp_idf_svc::log::EspLogger::initialize_default();
|
||||
|
||||
log::info!("Hello, world!");
|
||||
|
||||
let peripherals = Peripherals::take().unwrap();
|
||||
let led_pin = peripherals.pins.gpio14;
|
||||
let channel = peripherals.rmt.channel0;
|
||||
|
||||
const POWER_VOLTS : u32 = 5;
|
||||
const POWER_MA : u32 = 500;
|
||||
const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA;
|
||||
|
||||
log::info!("Setting up display");
|
||||
let target = PonderjarTarget::new(channel, led_pin).unwrap();
|
||||
let mut display = EmbeddedDisplay::<PonderjarTarget, SimpleSurface>::new(target, MAX_POWER_MW);
|
||||
let mut display = PonderjarTarget::new_display::<SimpleSurface>();
|
||||
|
||||
log::info!("Creating runner");
|
||||
let mut runner = task::Scheduler::new(vec![
|
||||
|
Loading…
Reference in New Issue
Block a user