src: implement ego tracking models, and port shaders from renderbug into here

This commit is contained in:
2025-09-22 13:16:39 +02:00
parent 29ba78d5b2
commit 19875f6ae5
18 changed files with 1191 additions and 184 deletions

View File

@@ -5,27 +5,32 @@
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
holding buffers for the duration of a data transfer."
)]
#![feature(future_join)]
use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice;
use embassy_executor::Spawner;
use embassy_sync::blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex};
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::mutex::Mutex;
use embassy_sync::pubsub::PubSubChannel;
use esp_backtrace as _;
use esp_hal::i2c::master::{Config, I2c};
use esp_hal::gpio::Pin;
use esp_hal::Async;
use esp_hal::clock::CpuClock;
use esp_hal::rmt::Rmt;
use esp_hal::time::Rate;
use esp_hal::timer::systimer::SystemTimer;
use esp_hal::timer::timg::TimerGroup;
use figments::surface::BufferedSurfacePool;
use log::info;
use renderbug_embassy::events::BusGarage;
use renderbug_embassy::tasks::ui::{Ui, ui_main};
use renderbug_embassy::tasks::gps::gps_task;
use renderbug_embassy::tasks::motion::motion_task;
use static_cell::StaticCell;
use renderbug_embassy::{
tasks::i2c::*,
tasks::render::render,
events::Notification
tasks::mpu::*,
tasks::render::render
};
extern crate alloc;
@@ -35,7 +40,8 @@ extern crate alloc;
esp_bootloader_esp_idf::esp_app_desc!();
static I2C_BUS: StaticCell<Mutex<CriticalSectionRawMutex, I2c<'static, Async>>> = StaticCell::new();
static EVENT_BUS: StaticCell<PubSubChannel<NoopRawMutex, Notification, 4, 4, 4>> = StaticCell::new();
static BUS_GARAGE: StaticCell<BusGarage> = StaticCell::new();
#[esp_hal_embassy::main]
async fn main(spawner: Spawner) {
esp_println::logger::init_logger_from_env();
@@ -46,12 +52,12 @@ async fn main(spawner: Spawner) {
esp_alloc::heap_allocator!(size: 64 * 1024);
let timer0 = SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(timer0.alarm0);
esp_hal_embassy::init([timer0.alarm0, timer0.alarm1, timer0.alarm2]);
info!("Embassy initialized!");
let events = EVENT_BUS.init(PubSubChannel::<NoopRawMutex, Notification, 4, 4, 4>::new());
let garage = BUS_GARAGE.init(Default::default());
info!("Setting up wifi");
let rng = esp_hal::rng::Rng::new(peripherals.RNG);
let timer1 = TimerGroup::new(peripherals.TIMG0);
let wifi_init =
@@ -59,17 +65,23 @@ async fn main(spawner: Spawner) {
let (mut _wifi_controller, _interfaces) = esp_wifi::wifi::new(&wifi_init, peripherals.WIFI)
.expect("Failed to initialize WIFI controller");
info!("Launching i2c sensor tasks");
let i2c = I2c::new(peripherals.I2C1, Config::default().with_frequency(Rate::from_khz(400)).with_timeout(esp_hal::i2c::master::BusTimeout::Maximum)).unwrap().with_scl(peripherals.GPIO4).with_sda(peripherals.GPIO3).into_async();
let i2c_bus = I2C_BUS.init(Mutex::new(i2c));
spawner.must_spawn(mpu_task(garage.motion.sender(), garage.scenes.dyn_sender(), I2cDevice::new(i2c_bus)));
spawner.must_spawn(gps_task(garage.motion.sender(), garage.scenes.dyn_sender(), I2cDevice::new(i2c_bus)));
info!("Launching motion engine");
spawner.must_spawn(motion_task(garage.motion.receiver(), garage.scenes.dyn_sender()));
info!("Setting up rendering pipeline");
let mut surfaces = BufferedSurfacePool::default();
let ui = Ui::new(&mut surfaces, &garage.display);
let frequency: Rate = Rate::from_mhz(80);
let rmt = Rmt::new(peripherals.RMT, frequency)
.expect("Failed to initialize RMT").into_async();
let rmt_channel = rmt.channel0;
info!("Launching render task");
spawner.must_spawn(render(events.subscriber().unwrap(), rmt_channel, peripherals.GPIO5));
info!("Launching i2c task");
let i2c = I2c::new(peripherals.I2C1, Config::default().with_frequency(Rate::from_khz(400))).unwrap().with_scl(peripherals.GPIO36).with_sda(peripherals.GPIO33).into_async();
let i2c_bus = I2C_BUS.init(Mutex::new(i2c));
spawner.spawn(mpu_task(events.dyn_publisher().unwrap(), I2cDevice::new(i2c_bus))).unwrap();
spawner.spawn(gps_task(events.dyn_publisher().unwrap(), I2cDevice::new(i2c_bus))).unwrap();
spawner.must_spawn(render(rmt_channel, peripherals.GPIO5.degrade(), surfaces, &garage.display));
spawner.must_spawn(ui_main(garage.scenes.dyn_receiver(), ui));
}