platform: rewrite the platform-specific display creation traits into a new Board trait that also supports tasks

This commit is contained in:
2024-11-30 16:06:17 +01:00
parent 57e660cbb6
commit 3af9ad408e
5 changed files with 276 additions and 80 deletions

View File

@@ -39,7 +39,7 @@ pub struct StrideOutput<P: Pixbuf, T: FastWrite> {
}
impl<P: Pixbuf, T: FastWrite> StrideOutput<P, T> {
fn new(pixbuf: P, stride_map: StrideMapping, target: T, max_mw: u32) -> Self {
pub fn new(pixbuf: P, stride_map: StrideMapping, target: T, max_mw: u32) -> Self {
assert!(stride_map.pixel_count <= pixbuf.pixel_count(), "map needs {} pixels, I only have PIXEL_NUM={}", stride_map.pixel_count, pixbuf.pixel_count());
StrideOutput {
pixbuf,
@@ -85,18 +85,12 @@ pub trait FastWrite {
#[cfg(feature="rmt")]
pub mod rmt {
use esp_idf_svc::{hal::prelude::Peripherals, sys::esp_efuse_mac_get_default};
use ws2812_esp32_rmt_driver::driver::color::LedPixelColorGrb24;
use smart_leds::SmartLedsWrite;
use rgb::Rgb;
use ws2812_esp32_rmt_driver::LedPixelEsp32Rmt;
use crate::mappings::StrideMapping;
use crate::platform::smart_leds_lib::StrideOutput;
use crate::render::Surface;
use crate::platform::DisplayInit;
use super::{Pixbuf, FastWrite};
use super::FastWrite;
pub type FastWs2812Esp32Rmt<'a> = LedPixelEsp32Rmt<'a, Rgb<u8>, LedPixelColorGrb24>;
@@ -111,43 +105,6 @@ pub mod rmt {
self.write_nocopy(iterator)
}
}
impl DisplayInit for FastWs2812Esp32Rmt<'_> {
type Output = StrideOutput<[Rgb<u8>; 310], Self>;
fn new_display<S: Surface>() -> Self::Output {
const POWER_VOLTS : u32 = 5;
const POWER_MA : u32 = 500;
const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA;
let peripherals = Peripherals::take().unwrap();
let channel = peripherals.rmt.channel0;
let pins = peripherals.pins;
let mut chip_id: [u8; 8] = [0; 8];
unsafe {
esp_efuse_mac_get_default(&mut chip_id as *mut u8);
}
let (pixmap, target) = match chip_id {
[72, 202, 67, 89, 145, 204, 0, 0] => {
(StrideMapping::new_panel(), Self::new(channel, pins.gpio5).unwrap())
},
[140, 170, 181, 131, 95, 116, 0, 0] => {
(StrideMapping::new_jar(), Self::new(channel, pins.gpio14).unwrap())
},
_ => {
(StrideMapping::new(), Self::new(channel, pins.gpio5).unwrap())
}
};
StrideOutput::new(
Pixbuf::new(),
pixmap,
target,
MAX_POWER_MW
)
}
}
}
#[cfg(feature="spi")]