-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathmain.rs
More file actions
129 lines (106 loc) · 3.5 KB
/
main.rs
File metadata and controls
129 lines (106 loc) · 3.5 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#![no_std]
#![no_main]
// Import the right HAL/PAC crate, depending on the target chip
#[cfg(feature = "52810")]
use nrf52810_hal as hal;
#[cfg(feature = "52832")]
use nrf52832_hal as hal;
#[cfg(feature = "52840")]
use nrf52840_hal as hal;
use {
bbqueue::{consts::*, BBBuffer, ConstBBBuffer},
core::sync::atomic::AtomicBool,
hal::{
gpio::Level,
pac::{TIMER1, TIMER2},
ppi::{Parts, Ppi0},
Timer,
},
rtt_target::{rprintln, rtt_init_print},
};
use hal::pac::UARTE0;
// Panic provider crate
use panic_reset as _;
#[rtic::app(device = crate::hal::pac, peripherals = true)]
const APP: () = {
struct Resources {
timer: Timer<TIMER1>,
uarte_timer: hal::bbq_uarte::irq::UarteTimer<TIMER2>,
uarte_irq: hal::bbq_uarte::irq::UarteIrq<U1024, U1024, Ppi0, UARTE0>,
uarte_app: hal::bbq_uarte::app::UarteApp<U1024, U1024>,
}
#[init]
fn init(ctx: init::Context) -> init::LateResources {
let _clocks = hal::clocks::Clocks::new(ctx.device.CLOCK).enable_ext_hfosc();
let p0 = hal::gpio::p0::Parts::new(ctx.device.P0);
let uart = ctx.device.UARTE0;
static UBUF: hal::bbq_uarte::buffer::UarteBuffer<U1024, U1024> =
hal::bbq_uarte::buffer::UarteBuffer {
txd_buf: BBBuffer(ConstBBBuffer::new()),
rxd_buf: BBBuffer(ConstBBBuffer::new()),
timeout_flag: AtomicBool::new(false),
};
rtt_init_print!();
let rxd = p0.p0_11.into_floating_input().degrade();
let txd = p0.p0_05.into_push_pull_output(Level::Low).degrade();
let ppi_channels = Parts::new(ctx.device.PPI);
let channel0 = ppi_channels.ppi0;
let uarte_pins = hal::uarte::Pins {
rxd,
txd,
cts: None,
rts: None,
};
let ue = UBUF
.try_split(
uarte_pins,
hal::uarte::Parity::EXCLUDED,
hal::uarte::Baudrate::BAUD230400,
ctx.device.TIMER2,
channel0,
uart,
32,
1_000_000,
)
.unwrap();
init::LateResources {
timer: Timer::new(ctx.device.TIMER1),
uarte_timer: ue.timer,
uarte_irq: ue.irq,
uarte_app: ue.app,
}
}
#[idle(resources = [timer, uarte_app])]
fn idle(ctx: idle::Context) -> ! {
let timer = ctx.resources.timer;
let uarte_app = ctx.resources.uarte_app;
use embedded_hal::timer::CountDown;
rprintln!("Start!");
timer.start(5_000_000u32);
loop {
if let Ok(rgr) = uarte_app.read() {
let len = rgr.len();
rprintln!("Brr: {}", len);
if let Ok(mut wgr) = uarte_app.write_grant(len) {
wgr.copy_from_slice(&rgr);
wgr.commit(len);
}
rgr.release(len);
}
if timer.wait().is_ok() {
rprintln!("Hello from idle!");
timer.start(5_000_000u32);
}
}
}
#[task(binds = TIMER2, resources = [uarte_timer])]
fn timer2(ctx: timer2::Context) {
// rprintln!("Hello from timer2!");
ctx.resources.uarte_timer.interrupt();
}
#[task(binds = UARTE0_UART0, resources = [uarte_irq])]
fn uarte0(ctx: uarte0::Context) {
// rprintln!("Hello from uarte0!");
ctx.resources.uarte_irq.interrupt();
}
};