aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/example/main.rs
blob: 94a8c9ea324329a5974b145d02f5c7b43a980dee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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();
    }
}