cargo: clean up dependencies and improve build times

This commit is contained in:
2025-10-17 18:06:24 +02:00
parent baa85612b7
commit 088dde4450
13 changed files with 184 additions and 237 deletions

View File

@@ -79,13 +79,8 @@ async fn main(spawner: Spawner) {
#[allow(unused_variables)]
let hi_spawn = hi_exec.start(esp_hal::interrupt::Priority::max());
#[cfg(not(feature="headless"))]
{
wdt.enable();
hi_spawn.must_spawn(renderbug_embassy::tasks::render::render(peripherals.RMT, peripherals.GPIO5.degrade(), surfaces, safety_surfaces, garage.display.clone(), wdt));
}
#[cfg(feature="headless")]
garage.display.notify_render_is_running(true);
wdt.enable();
hi_spawn.must_spawn(renderbug_embassy::tasks::render::render(peripherals.RMT, peripherals.GPIO5.degrade(), surfaces, safety_surfaces, garage.display.clone(), wdt));
#[cfg(feature="motion")]
{

View File

@@ -8,9 +8,11 @@ use figments_render::{
gamma::{GammaCurve, WithGamma}, output::{Brightness, GammaCorrected, OutputAsync}, power::AsMilliwatts, smart_leds::PowerManagedWriterAsync
};
use smart_leds::SmartLedsWriteAsync;
pub const NUM_PIXELS: usize = 178;
// FIXME: We need a way to specify a different buffer format from the 'native' hardware output, due to sometimes testing with GRB strips instead of RGB
pub struct BikeOutput<T: SmartLedsWriteAsync> {
pixbuf: [T::Color; 178],
pixbuf: [T::Color; NUM_PIXELS],
writer: PowerManagedWriterAsync<T>,
controls: DisplayControls
}
@@ -24,18 +26,18 @@ impl<T:SmartLedsWriteAsync> GammaCorrected for BikeOutput<T> where T::Color: Pix
impl<T: SmartLedsWriteAsync> BikeOutput<T> where T::Color: PixelBlend<Rgb<u8>> + PixelFormat + WithGamma + 'static, T::Error: core::fmt::Debug {
pub fn new(target: T, max_mw: u32, controls: DisplayControls) -> Self {
Self {
pixbuf: [Default::default(); 178],
pixbuf: [Default::default(); NUM_PIXELS],
writer: PowerManagedWriterAsync::new(target, max_mw),
controls
}
}
pub fn blank(&mut self) {
self.pixbuf = [Default::default(); 178];
self.pixbuf = [Default::default(); NUM_PIXELS];
}
}
impl<'a, T: SmartLedsWriteAsync + 'a> OutputAsync<'a, SegmentSpace> for BikeOutput<T> where T::Color: PixelBlend<Rgb<u8>> + Debug + 'static + AsMilliwatts + PixelFormat + WithGamma, [T::Color; 178]: AsMilliwatts + WithGamma + Copy, T::Error: core::fmt::Debug {
impl<'a, T: SmartLedsWriteAsync + 'a> OutputAsync<'a, SegmentSpace> for BikeOutput<T> where T::Color: PixelBlend<Rgb<u8>> + Debug + 'static + AsMilliwatts + PixelFormat + WithGamma, [T::Color; NUM_PIXELS]: AsMilliwatts + WithGamma + Copy, T::Error: core::fmt::Debug {
async fn commit_async(&mut self) -> Result<(), T::Error> {
self.writer.controls().set_brightness(self.controls.brightness());
self.writer.controls().set_on(self.controls.is_on());
@@ -52,7 +54,7 @@ impl<'a, T: SmartLedsWriteAsync + 'a> OutputAsync<'a, SegmentSpace> for BikeOutp
}
}
impl<'a, T: SmartLedsWriteAsync> Sample<'a, SegmentSpace> for BikeOutput<T> where T::Color: Debug + PixelFormat + 'a, [T::Color; 178]: Sample<'a, SegmentSpace, Output = T::Color> {
impl<'a, T: SmartLedsWriteAsync> Sample<'a, SegmentSpace> for BikeOutput<T> where T::Color: Debug + PixelFormat + 'a, [T::Color; NUM_PIXELS]: Sample<'a, SegmentSpace, Output = T::Color> {
type Output = T::Color;
fn sample(&mut self, rect: &Rectangle<SegmentSpace>) -> impl Iterator<Item = (Coordinates<SegmentSpace>, &'a mut T::Color)> {
@@ -74,12 +76,12 @@ pub struct Segment {
length: usize,
}
impl<'a, T: PixelFormat> Sample<'a, SegmentSpace> for [T; 178] where T: 'static {
impl<'a, T: PixelFormat> Sample<'a, SegmentSpace> for [T; NUM_PIXELS] where T: 'static {
type Output = T;
fn sample(&mut self, rect: &Rectangle<SegmentSpace>) -> impl Iterator<Item = (Coordinates<SegmentSpace>, &'a mut Self::Output)> {
let bufref = unsafe {
&mut *(self as *mut [T; 178])
&mut *(self as *mut [T; NUM_PIXELS])
};
SegmentIter {
pixbuf: bufref,
@@ -97,7 +99,7 @@ impl CoordinateSpace for SegmentSpace {
}
pub struct SegmentIter<'a, Format: PixelFormat> {
pixbuf: &'a mut [Format; 178],
pixbuf: &'a mut [Format; NUM_PIXELS],
cur: Coordinates<SegmentSpace>,
end: Coordinates<SegmentSpace>,
}
@@ -129,7 +131,7 @@ impl<'a, Format: PixelFormat> Iterator for SegmentIter<'a, Format> {
}
let bufref = unsafe {
&mut *(self.pixbuf as *mut [Format; 178])
&mut *(self.pixbuf as *mut [Format; NUM_PIXELS])
};
Some((pixel_coords, &mut bufref[offset]))

View File

@@ -1,9 +1,7 @@
use embassy_sync::{channel::DynamicSender, pubsub::DynPublisher};
use embassy_time::{Duration, Instant};
use nalgebra::{Rotation3, Vector2, Vector3};
use nalgebra::{Rotation3, Vector2, Vector3, ComplexField, RealField};
use log::*;
//use micromath::F32Ext;
use nalgebra::{ComplexField, RealField};
use core::fmt::Debug;

View File

@@ -2,14 +2,20 @@
pub mod mpu;
#[cfg(feature="gps")]
pub mod gps;
pub mod render;
pub mod motion;
pub mod ui;
#[cfg(feature="radio")]
pub mod wifi;
#[cfg(feature="simulation")]
pub mod simulation;
pub mod predict;
#[cfg(feature="demo")]
pub mod demo;
#[cfg(feature="oled")]
pub mod oled;
// Prediction engines
pub mod predict;
pub mod motion;
// Graphics stack
pub mod ui;
pub mod safetyui;
pub mod oled;
pub mod render;

View File

@@ -1,25 +1,23 @@
use embassy_time::{Duration, Instant, Timer};
use esp_hal::{gpio::AnyPin, rmt::Rmt, time::Rate, timer::timg::Wdt};
use esp_hal_smartled::{buffer_size_async, SmartLedsAdapterAsync};
use figments::{prelude::*, surface::{BufferedSurfacePool, Surfaces}};
use figments::{prelude::*, surface::Surfaces};
use figments_render::gamma::GammaCurve;
use figments_render::output::{GammaCorrected, OutputAsync};
use log::{info, warn};
use rgb::Rgba;
use nalgebra::ComplexField;
use micromath::F32Ext;
use crate::display::{BikeOutput, DisplayControls, SegmentSpace, Uniforms};
//TODO: Import the bike surfaces from renderbug-prime, somehow make those surfaces into tasks
use crate::display::NUM_PIXELS;
use crate::{display::{BikeOutput, DisplayControls, Uniforms}, tasks::ui::UiSurfacePool};
#[embassy_executor::task]
pub async fn render(rmt: esp_hal::peripherals::RMT<'static>, gpio: AnyPin<'static>, surfaces: BufferedSurfacePool<Uniforms, SegmentSpace, Rgba<u8>>, safety_surfaces: BufferedSurfacePool<Uniforms, SegmentSpace, Rgba<u8>>, mut controls: DisplayControls, mut wdt: Wdt<esp_hal::peripherals::TIMG0<'static>>) {
pub async fn render(rmt: esp_hal::peripherals::RMT<'static>, gpio: AnyPin<'static>, surfaces: UiSurfacePool, safety_surfaces: UiSurfacePool, mut controls: DisplayControls, mut wdt: Wdt<esp_hal::peripherals::TIMG0<'static>>) {
let frequency: Rate = Rate::from_mhz(80);
let rmt = Rmt::new(rmt, frequency)
.expect("Failed to initialize RMT").into_async();
let rmt_channel = rmt.channel0;
let rmt_buffer = [0u32; buffer_size_async(178)];
let rmt_buffer = [0u32; buffer_size_async(NUM_PIXELS)];
//let target = SmartLedsAdapterAsync::new(rmt_channel, gpio, rmt_buffer);
let target = SmartLedsAdapterAsync::new(rmt_channel, gpio, rmt_buffer);
@@ -40,8 +38,6 @@ pub async fn render(rmt: esp_hal::peripherals::RMT<'static>, gpio: AnyPin<'stati
let mut output = BikeOutput::new(target, MAX_POWER_MW, controls.clone());
output.set_gamma(GammaCurve::new(1.3));
//#[cfg(not(feature="wokwi"))]
//output.set_gamma(GammaCurve::new(2.1));
info!("Rendering started! {}ms since boot", Instant::now().as_millis());
controls.notify_render_is_running(true);

View File

@@ -8,7 +8,7 @@ use crate::Breaker;
#[embassy_executor::task]
pub async fn motion_simulation_task(events: DynamicSender<'static, Measurement>) {
let mut rd = rmp::decode::Bytes::new(include_bytes!("../../test-data/motion.msgpack"));
let mut rd = rmp::decode::Bytes::new(include_bytes!("../../target/motion_test_data.msgpack"));
let mut runtime_secs = Breaker::default();
let mut runtime = Duration::default();
events.send(Measurement::SensorOnline(SensorSource::IMU)).await;
@@ -39,7 +39,7 @@ pub async fn motion_simulation_task(events: DynamicSender<'static, Measurement>)
#[embassy_executor::task]
pub async fn location_simulation_task(events: DynamicSender<'static, Measurement>) {
let mut rd = rmp::decode::Bytes::new(include_bytes!("../../test-data/gps.msgpack"));
let mut rd = rmp::decode::Bytes::new(include_bytes!("../../target/gps_test_data.msgpack"));
let mut runtime_secs = Breaker::default();
let mut runtime = Duration::default();
events.send(Measurement::SensorOnline(SensorSource::GPS)).await;

View File

@@ -200,9 +200,9 @@ impl<S: Debug + Surface<Uniforms = Uniforms, CoordinateSpace = SegmentSpace, Pix
}
}
#[cfg(feature="headless")]
#[cfg(not(feature="real-output"))]
pub type UiSurfacePool = NullBufferPool<NullSurface<Uniforms, SegmentSpace, Rgba<u8>>>;
#[cfg(not(feature="headless"))]
#[cfg(feature="real-output")]
pub type UiSurfacePool = BufferedSurfacePool<Uniforms, SegmentSpace, Rgba<u8>>;
#[embassy_executor::task]