Add basic BLE I/O
This commit is contained in:
parent
666499c240
commit
17b84d9aec
13 changed files with 806 additions and 23 deletions
47
src/main.rs
47
src/main.rs
|
|
@ -18,6 +18,9 @@ compile_error!("feature \"cam_tx\" needs a time and position source (either GNSS
|
|||
// we can't have both GNSS drivers enabled at the same time
|
||||
#[cfg(all(feature = "gnss_ubx", feature = "gnss_l67k"))]
|
||||
compile_error!("feature \"gnss_ubx\" and feature \"gnss_l67k\" cannot be enabled at the same time");
|
||||
// at least one V2X feature needs to be enabled
|
||||
#[cfg(not(any(feature = "spat", feature = "cam", feature = "denm")))]
|
||||
compile_error!("at least one V2X feature (\"spat\", \"cam\" or \"denm\") needs to be enabled");
|
||||
|
||||
use alloc::string::ToString as _;
|
||||
use alloc::vec::Vec;
|
||||
|
|
@ -45,9 +48,11 @@ use log::{error, info, warn};
|
|||
extern crate alloc;
|
||||
|
||||
mod applogic;
|
||||
#[cfg(feature = "ble")]
|
||||
mod ble;
|
||||
mod cache;
|
||||
mod geo_alg;
|
||||
#[cfg(feature = "uart")]
|
||||
#[cfg(any(feature = "uart", feature = "ble"))]
|
||||
mod io;
|
||||
#[cfg(feature = "screen")]
|
||||
mod screen;
|
||||
|
|
@ -89,7 +94,7 @@ static SERIAL: Mutex<RefCell<Option<esp_hal::uart::Uart<'static, esp_hal::Blocki
|
|||
#[esp_rtos::main]
|
||||
async fn main(spawner: Spawner) -> ! {
|
||||
// generator version: 1.3.0
|
||||
// generator parameters: --chip esp32c5 -o esp32c5-wroom-1-psram -o alloc -o log -o unstable-hal -o wifi -o esp-backtrace -o embassy
|
||||
// generator parameters: --chip esp32c5 -o esp32c5-wroom-1-psram -o alloc -o log -o unstable-hal -o wifi -o esp-backtrace -o embassy -o ble-trouble
|
||||
|
||||
esp_println::logger::init_logger_from_env();
|
||||
|
||||
|
|
@ -107,6 +112,8 @@ async fn main(spawner: Spawner) -> ! {
|
|||
// - GPIO28
|
||||
|
||||
esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 65536);
|
||||
// COEX needs more RAM - so we've added some more
|
||||
esp_alloc::heap_allocator!(size: 64 * 1024);
|
||||
esp_alloc::psram_allocator!(peripherals.PSRAM, esp_hal::psram);
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
|
|
@ -188,6 +195,13 @@ async fn main(spawner: Spawner) -> ! {
|
|||
let mac = esp_hal::efuse::base_mac_address();
|
||||
info!("WiFi MAC: {mac}");
|
||||
|
||||
// Setup BLE
|
||||
#[cfg(feature = "ble")]
|
||||
{
|
||||
let controller = ble::make_controller(peripherals.BT);
|
||||
spawner.spawn(ble::run(controller).expect("Failed to spawn BLE task"));
|
||||
}
|
||||
|
||||
// Setup GNSS:
|
||||
// Seeed XIAO L67K:
|
||||
// RX: D7/ GPIO12
|
||||
|
|
@ -365,6 +379,17 @@ async fn main(spawner: Spawner) -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ble")]
|
||||
{
|
||||
critical_section::with(|cs| {
|
||||
let mut data_rc = ble::RX_DATA.borrow(cs).borrow_mut();
|
||||
if let Some(pos) = data_rc.take() {
|
||||
let gnss_update_ref = GNSS_UPDATE.borrow(cs);
|
||||
gnss_update_ref.replace(Some(pos.into()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(feature = "_gnss")]
|
||||
{
|
||||
let mut new_position = false;
|
||||
|
|
@ -474,6 +499,13 @@ async fn main(spawner: Spawner) -> ! {
|
|||
} => {
|
||||
#[cfg(feature = "cam")]
|
||||
applogic::cam::handle_cam(&etsi);
|
||||
|
||||
// Send data to BLE thread
|
||||
#[cfg(all(feature = "ble", feature = "cam"))]
|
||||
critical_section::with(|cs| {
|
||||
let ble_update_ref = ble::TX_DATA.borrow(cs);
|
||||
ble_update_ref.replace(Some(ble::BleSendable::Cam(etsi.into())));
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(feature = "denm")]
|
||||
|
|
@ -481,7 +513,16 @@ async fn main(spawner: Spawner) -> ! {
|
|||
geonetworking: _,
|
||||
transport: _,
|
||||
etsi,
|
||||
} => applogic::denm::handle_denm(&etsi),
|
||||
} => {
|
||||
applogic::denm::handle_denm(&etsi);
|
||||
|
||||
// Send data to BLE thread
|
||||
#[cfg(feature = "ble")]
|
||||
critical_section::with(|cs| {
|
||||
let ble_update_ref = ble::TX_DATA.borrow(cs);
|
||||
ble_update_ref.replace(Some(ble::BleSendable::Denm(etsi.into())));
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "denm")]
|
||||
ItsMessage::DenmV1 {
|
||||
geonetworking: _,
|
||||
|
|
|
|||
Loading…
Reference in a new issue