build: configure different displays based on cargo configs

This commit is contained in:
2024-10-30 19:52:02 +01:00
parent 739d7c2e6d
commit f803d8fe93
7 changed files with 221 additions and 160 deletions

View File

@@ -16,21 +16,7 @@ use crate::render::*;
use crate::time::Periodically;
use crate::task::Task;
use crate::geometry::*;
impl<T: RgbColor> AsMilliwatts for T {
fn as_milliwatts(&self) -> u32 {
const RED_MW : u32 = 16 * 5; //< 16mA @ 5v = 80mW
const GREEN_MW : u32 = 11 * 5; //< 11mA @ 5v = 55mW
const BLUE_MW : u32 = 15 * 5; //< 15mA @ 5v = 75mW
const DARK_MW : u32 = 1 * 5; //< 1mA @ 5v = 5mW
let red = (self.r() as u32 * RED_MW).wrapping_shr(8);
let green = (self.g() as u32 * GREEN_MW).wrapping_shr(8);
let blue = (self.b() as u32 * BLUE_MW).wrapping_shr(8);
return red + green + blue + DARK_MW;
}
}
use crate::platform::DisplayInit;
pub struct EmbeddedDisplay<T, S>
where
@@ -124,3 +110,39 @@ impl<T: LedPixelShape, S: Surface> Display<S> for EmbeddedDisplay<Ws2812DrawTarg
).unwrap();
}
}
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);
}
}
pub struct PonderjarMatrix {}
impl LedPixelShape for PonderjarMatrix {
fn size() -> Size {
Size::new(17, 17)
}
fn pixel_index(point: Point) -> Option<usize> {
if (0..Self::size().width as i32).contains(&point.x) && (0..Self::size().height as i32).contains(&point.y) {
if point.y % 2 == 0 {
Some((point.y as u32 * Self::size().width as u32 + point.x as u32).try_into().unwrap())
} else {
Some((point.y as u32 * Self::size().width as u32 - point.x as u32).try_into().unwrap())
}
} else {
None
}
}
}
pub type PonderjarTarget<'a> = Ws2812DrawTarget<'a, PonderjarMatrix>;