diff options
Diffstat (limited to 'src/bin/example/main.rs')
| -rw-r--r-- | src/bin/example/main.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/bin/example/main.rs b/src/bin/example/main.rs new file mode 100644 index 0000000..94a8c9e --- /dev/null +++ b/src/bin/example/main.rs @@ -0,0 +1,89 @@ +#![no_std] +#![no_main] + +use alloc::boxed::Box; +use embassy_executor::Spawner; +use embassy_nrf::gpio::{Level, Output, OutputDrive}; +use embassy_nrf::{bind_interrupts, peripherals, spim}; +use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex}; +use embedded_alloc::LlffHeap as Heap; + +use {defmt_rtt as _, panic_probe as _}; + +extern crate alloc; + +#[cfg(feature = "display")] +mod display; + +mod radio; + +#[global_allocator] +static HEAP: Heap = Heap::empty(); + +bind_interrupts!(struct Irqs { + SPIM3 => spim::InterruptHandler<peripherals::SPI3>; + SPI2 => spim::InterruptHandler<peripherals::SPI2>; +}); + +type PinMutex<'a> = Mutex<CriticalSectionRawMutex, Output<'a>>; + +#[embassy_executor::task] +async fn led_task(led_pin: &'static PinMutex<'static>) { + t114_meshcore_example::led_task(led_pin).await; +} + +#[embassy_executor::main] +async fn main(spawner: Spawner) { + { + use core::mem::MaybeUninit; + const HEAP_SIZE: usize = 64 * 1024; + static mut HEAP_MEM: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE]; + unsafe { HEAP.init(&raw mut HEAP_MEM as usize, HEAP_SIZE) } + } + + let p = embassy_nrf::init(Default::default()); + + { + // led blink task + let led = Output::new(p.P1_03, Level::High, OutputDrive::Standard); + let pin: PinMutex = Mutex::new(led); + let pin_ref = Box::leak(Box::new(pin)); + spawner.spawn(led_task(pin_ref)).unwrap(); + } + + #[cfg(feature = "display")] + { + let display = display::init( + p.SPI3, + Irqs, + display::Pins { + ven: p.P0_21.into(), + rst: p.P0_05.into(), + sck: p.P1_12.into(), + sdo: p.P1_14.into(), + cs: p.P1_15.into(), + dc: p.P1_13.into(), + }, + ) + .await; + spawner.spawn(display::task(display)).unwrap(); + } + + { + let radio = radio::init( + p.SPI2, + Irqs, + radio::Pins { + sck: p.P0_19.into(), + miso: p.P0_23.into(), + mosi: p.P0_22.into(), + cs: p.P0_24.into(), + rst: p.P0_25.into(), + dio1: p.P0_20.into(), + busy: p.P0_17.into(), + }, + ) + .await; + spawner.spawn(radio::task(radio)).unwrap(); + } +} |
