src: implement first iteration of a naive smart-leds display

This commit is contained in:
2024-10-29 01:27:20 +01:00
parent a0d42d2274
commit 8426f0b0e5
3 changed files with 133 additions and 1 deletions

View File

@@ -1,6 +1,5 @@
#![feature(trait_upcasting)]
#![allow(arithmetic_overflow)]
use esp_idf_svc::hal::prelude::Peripherals;
use ws2812_esp32_rmt_driver::lib_embedded_graphics::{LedPixelShape, Ws2812DrawTarget};
use embedded_graphics::{
prelude::*,
@@ -8,6 +7,12 @@ use embedded_graphics::{
use palette::Hsv;
use palette::convert::IntoColorUnclamped;
use esp_idf_svc::hal::{
prelude::*,
spi::{config::{Config, DriverConfig}, Dma, SpiDriver, SpiBusDriver},
gpio::AnyIOPin,
};
mod power;
mod lib8;
mod render;
@@ -15,13 +20,19 @@ mod task;
mod time;
mod geometry;
mod embedded_graphics_lib;
mod smart_leds_lib;
use crate::time::Periodically;
use crate::geometry::{Coordinates, VirtualCoordinates};
use crate::embedded_graphics_lib::EmbeddedDisplay;
use crate::smart_leds_lib::SmartLedDisplay;
use crate::render::{Surfaces, Surface, SimpleSurface, Display};
use crate::task::Task;
use ws2812_spi::Ws2812;
use smart_leds_trait::SmartLedsWrite;
use esp_idf_svc::hal::units::MegaHertz;
struct IdleTask<T: Surface> {
frame: u8,
surface: T,
@@ -104,6 +115,31 @@ impl<Shape: LedPixelShape> DisplayInit for Ws2812DrawTarget<'_, Shape> {
}
}
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)
}
}
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
@@ -113,6 +149,7 @@ fn main() {
esp_idf_svc::log::EspLogger::initialize_default();
log::info!("Setting up display");
//let mut display = SPIDisplay::new_display::<SimpleSurface>();
let mut display = PonderjarTarget::new_display::<SimpleSurface>();
log::info!("Creating runner");