cargo: gate motion sim behind feature flag

This commit is contained in:
2025-09-24 08:53:15 +02:00
parent 0cd2cc94b9
commit 019d134022
4 changed files with 51 additions and 32 deletions

View File

@@ -12,38 +12,48 @@ use core::ptr::addr_of_mut;
use bleps::ad_structure::{create_advertising_data, AdStructure, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE};
use bleps::attribute_server::{AttributeServer, NotificationData};
use bleps::{gatt, Ble, HciConnector};
use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice;
use embassy_executor::Spawner;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::channel::DynamicReceiver;
use embassy_sync::mutex::Mutex;
use embassy_time::{Instant, Timer};
use esp_backtrace as _;
use esp_hal::gpio::Pin;
use esp_hal::i2c::master::{Config, I2c};
use esp_hal::interrupt::software::SoftwareInterruptControl;
use esp_hal::system::{AppCoreGuard, CpuControl, Stack};
use esp_hal::timer::AnyTimer;
use esp_hal::Async;
use esp_hal::clock::CpuClock;
use esp_hal::time::Rate;
use esp_hal::timer::systimer::SystemTimer;
use esp_hal::timer::timg::TimerGroup;
use esp_hal::{
gpio::Pin,
interrupt::software::SoftwareInterruptControl,
clock::CpuClock,
system::{AppCoreGuard, CpuControl, Stack},
timer::{AnyTimer, systimer::SystemTimer, timg::TimerGroup}
};
use esp_hal_embassy::{Executor, InterruptExecutor};
use esp_wifi::ble::controller::BleConnector;
use figments::surface::BufferedSurfacePool;
use log::info;
use renderbug_embassy::events::{BusGarage, Measurement, Telemetry};
use renderbug_embassy::tasks::simulation::{motion_simulation_task, location_simulation_task};
use renderbug_embassy::tasks::ui::{Ui, ui_main};
use renderbug_embassy::tasks::gps::gps_task;
use renderbug_embassy::tasks::motion::motion_task;
use serde_json::json;
use static_cell::StaticCell;
use renderbug_embassy::{
tasks::mpu::*,
tasks::render::render
#[cfg(feature="simulation")]
use renderbug_embassy::tasks::simulation::{motion_simulation_task, location_simulation_task};
#[cfg(not(feature="simulation"))]
use renderbug_embassy::tasks::{gps::gps_task, mpu::mpu_task};
#[cfg(not(feature="simulation"))]
use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice;
#[cfg(not(feature="simulation"))]
use esp_hal::{
time::Rate,
i2c::master::{Config, I2c},
Async,
};
#[cfg(not(feature="simulation"))]
use embassy_sync::{
mutex::Mutex,
blocking_mutex::raw::CriticalSectionRawMutex
};
use renderbug_embassy::tasks::{
render::render,
motion::motion_task,
ui::{Ui, ui_main}
};
extern crate alloc;
@@ -51,7 +61,9 @@ extern crate alloc;
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();
#[cfg(not(feature="simulation"))]
static I2C_BUS: StaticCell<Mutex<CriticalSectionRawMutex, I2c<'static, Async>>> = StaticCell::new();
static BUS_GARAGE: StaticCell<BusGarage> = StaticCell::new();
static mut CORE2_STACK: Stack<8192> = Stack::new();
static CORE_HANDLE: StaticCell<AppCoreGuard> = StaticCell::new();
@@ -81,16 +93,20 @@ async fn main(spawner: Spawner) {
let hi_spawn = hi_exec.start(esp_hal::interrupt::Priority::Priority1);
hi_spawn.must_spawn(render(peripherals.RMT, peripherals.GPIO5.degrade(), surfaces, &garage.display));
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));
#[cfg(not(feature="simulation"))]
{
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.dyn_sender(), I2cDevice::new(i2c_bus)));
spawner.must_spawn(gps_task(garage.motion.dyn_sender(), I2cDevice::new(i2c_bus)));
}
spawner.must_spawn(mpu_task(garage.motion.dyn_sender(), I2cDevice::new(i2c_bus)));
spawner.must_spawn(gps_task(garage.motion.dyn_sender(), I2cDevice::new(i2c_bus)));
// TODO: Only run the motion sim sources with cfg(simulation)
spawner.must_spawn(motion_simulation_task(garage.motion.dyn_sender()));
spawner.must_spawn(location_simulation_task(garage.motion.dyn_sender()));
#[cfg(feature="simulation")]
{
spawner.must_spawn(motion_simulation_task(garage.motion.dyn_sender()));
spawner.must_spawn(location_simulation_task(garage.motion.dyn_sender()));
}
info!("Launching motion engine");
spawner.must_spawn(motion_task(garage.motion.dyn_receiver(), garage.scenes.dyn_sender(), garage.telemetry.dyn_sender()));