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

@@ -3,11 +3,10 @@ use running_average::RealTimeRunningAverage;
use crate::render::{Surface, SurfacePool, Display, Surfaces};
use crate::task::Task;
use crate::power;
use crate::power::{brightness_for_mw, AsMilliwatts};
use crate::time::Periodically;
use crate::lib8::RGB8;
use crate::geometry::*;
use crate::power::AsMilliwatts;
use smart_leds::brightness;
@@ -68,20 +67,20 @@ impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> Display<S> for SmartLedDisp
fn end_frame(&mut self) {
self.fps.insert(1);
let b = power::brightness_for_mw(self.total_mw, 255, self.max_mw);
let b = brightness_for_mw(self.total_mw, 255, self.max_mw);
self.fps_display.run(|| {
log::info!("FPS: {} frame={} brightness={} mw={}", self.fps.measurement(), self.frame, b, self.total_mw);
});
self.target.write(brightness(self.pixbuf.iter().cloned(), b));
let _ = self.target.write(brightness(self.pixbuf.iter().cloned(), b));
}
fn render_frame(&mut self) {
for x in 0..self.pixbuf.len() {
let virtCoords = VirtualCoordinates::new(x as u8, 0);
let virt_coords = VirtualCoordinates::new(x as u8, 0);
let mut pixel = RGB8::new(0, 0, 0);
for surface in self.surfaces.iter() {
surface.with_shader(|shader| {
pixel = shader.draw(virtCoords.clone());
pixel = shader.draw(virt_coords.clone());
})
}
self.total_mw += pixel.as_milliwatts();
@@ -89,3 +88,74 @@ impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> Display<S> for SmartLedDisp
};
}
}
#[cfg(feature="rmt")]
pub mod rmt {
use esp_idf_svc::hal::prelude::Peripherals;
use ws2812_esp32_rmt_driver::lib_smart_leds::Ws2812Esp32Rmt;
use crate::render::{Display, Surface};
use crate::task::Task;
use crate::smart_leds_lib::SmartLedDisplay;
use crate::platform::DisplayInit;
impl DisplayInit for Ws2812Esp32Rmt<'_> {
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 SmartLedDisplay::new(target, MAX_POWER_MW);
}
}
}
#[cfg(feature="spi")]
pub mod spi {
use ws2812_spi::Ws2812;
use crate::render::{Display, Surface};
use crate::task::Task;
use crate::smart_leds_lib::SmartLedDisplay;
use esp_idf_svc::hal::{
prelude::*,
gpio::AnyIOPin,
spi::{
config::{Config, DriverConfig},
Dma,
SpiBusDriver,
SpiDriver,
}
};
pub struct SPIDisplay {}
impl DisplayInit for SPIDisplay {
fn new_display<S: Surface>() -> impl Display<S> + Task {
let peripherals = Peripherals::take().unwrap();
let driver = SpiDriver::new_without_sclk(
peripherals.spi2,
peripherals.pins.gpio14,
Option::<AnyIOPin>::None,
&DriverConfig::new().dma(Dma::Auto(512))
).unwrap();
let cfg = Config::new().baudrate(3_200.kHz().into());
let spi = SpiBusDriver::new(driver, &cfg).unwrap();
const POWER_VOLTS : u32 = 5;
const POWER_MA : u32 = 500;
const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA;
let target = Ws2812::new(spi);
return SmartLedDisplay::new(target, MAX_POWER_MW)
}
}
}