0
0
Fork 0

main: Add feature flag for GNSS module

This commit is contained in:
Jannik Beyerstedt 2026-06-15 21:36:34 +02:00
commit 57a6b7983d
4 changed files with 19 additions and 4 deletions

View file

@ -9,6 +9,7 @@ use alloc::vec::Vec;
use esp_println::println;
#[cfg(feature = "spat")]
use log::{debug, error};
#[cfg(feature = "gnss")]
use log::{info, warn};
#[cfg(feature = "spat")]
@ -39,12 +40,16 @@ const GLOSA_LANE_LEFT_OFFSET_M: f64 = 20.;
#[cfg(feature = "spat")]
const GLOSA_STOP_LINE_PASSED_M: f64 = 10.;
#[allow(unused)]
pub struct State {
initialized: bool,
time: chrono::NaiveDateTime,
#[allow(unused)]
position: geo_types::Point,
#[allow(unused)]
heading_deg: Option<f32>,
#[allow(unused)]
speed_mps: Option<f32>,
#[cfg(feature = "spat")]
@ -96,7 +101,7 @@ impl State {
}
}
#[cfg(feature = "esp")]
#[cfg(all(feature = "esp", feature = "gnss"))]
pub fn update_with_gpsfix(&mut self, fix: &embassy_gps::types::GpsFix) {
self.position = geo_types::Point::new(fix.longitude_deg, fix.latitude_deg);
@ -122,6 +127,7 @@ impl State {
}
}
#[cfg(feature = "gnss")]
pub fn print_fix(&self) -> alloc::string::String {
alloc::format!(
"{:?}, {:.4} N, {:.4} E, {:.0}°, {:.2} m/s",

View file

@ -13,6 +13,7 @@ use core::cell::RefCell;
use critical_section::Mutex;
use crossbeam_queue::ArrayQueue;
use embassy_executor::Spawner;
#[cfg(feature = "gnss")]
use embassy_gps::gps::l76k;
use esp_backtrace as _;
use esp_hal::clock::CpuClock;
@ -34,6 +35,7 @@ const WIFI_CHANNEL: radio::Channel = 180;
// 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(feature = "gnss")]
static GNSS_UPDATE: Mutex<RefCell<Option<embassy_gps::types::GpsFix>>> =
Mutex::new(RefCell::new(None));
static WIFI_RX_QUEUE: Mutex<RefCell<Option<ArrayQueue<Vec<u8>>>>> = Mutex::new(RefCell::new(None));
@ -93,6 +95,7 @@ async fn main(spawner: Spawner) -> ! {
// TX: D6/ GPIO11
// WAKEUP: D0/ GPIO1 -> HIGH for active, LOW for Sleep
// RESET: D2/ GPIO25 -> HIGH for normal, LOW for Reset
#[cfg(feature = "gnss")]
spawner.spawn(
gnss_task(
peripherals.GPIO1,
@ -109,6 +112,7 @@ async fn main(spawner: Spawner) -> ! {
loop {
embassy_time::Timer::after(embassy_time::Duration::from_millis(5)).await;
#[cfg(feature = "gnss")]
critical_section::with(|cs| {
let gnss_update_ref = GNSS_UPDATE.borrow(cs);
@ -236,6 +240,7 @@ fn handle_frame(frame: wifi::sniffer::PromiscuousPkt<'_>) {
});
}
#[cfg(feature = "gnss")]
#[allow(clippy::large_stack_frames, reason = "GNSS driver needs some space")]
#[embassy_executor::task]
async fn gnss_task(