aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf52840/src/bin/egu.rs
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2024-06-18 13:00:28 +0200
committerUlf Lilleengen <[email protected]>2024-06-18 13:13:33 +0200
commita44ee963ef65be41a9354b4e7e70b02d30fadd70 (patch)
tree0792cd1d50b5fb5b1ea8c22f320f0d5c81f7811d /examples/nrf52840/src/bin/egu.rs
parent3c414e99cb3df9a040a92ac413aa3d87faf87dc3 (diff)
add HAL and example for using nRF EGU peripheral
Diffstat (limited to 'examples/nrf52840/src/bin/egu.rs')
-rw-r--r--examples/nrf52840/src/bin/egu.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/examples/nrf52840/src/bin/egu.rs b/examples/nrf52840/src/bin/egu.rs
new file mode 100644
index 000000000..df96f7e56
--- /dev/null
+++ b/examples/nrf52840/src/bin/egu.rs
@@ -0,0 +1,55 @@
1//! This example shows the use of the EGU peripheral combined with PPI.
2//!
3//! It chains events from button -> egu0-trigger0 -> egu0-trigger1 -> led
4#![no_std]
5#![no_main]
6
7use embassy_executor::Spawner;
8use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
9use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity, OutputChannel, OutputChannelPolarity};
10use embassy_nrf::peripherals::{PPI_CH0, PPI_CH1, PPI_CH2};
11use embassy_nrf::ppi::Ppi;
12use embassy_nrf::egu::{Egu, TriggerNumber};
13use embassy_time::{Duration, Timer};
14use {defmt_rtt as _, panic_probe as _};
15
16#[embassy_executor::main]
17async fn main(_spawner: Spawner) {
18 let p = embassy_nrf::init(Default::default());
19
20 let led1 = Output::new(p.P0_13, Level::High, OutputDrive::Standard);
21 let btn1 = Input::new(p.P0_11, Pull::Up);
22
23 let mut egu1 = Egu::new(p.EGU0);
24 let led1 = OutputChannel::new(p.GPIOTE_CH0, led1, OutputChannelPolarity::Toggle);
25 let btn1 = InputChannel::new(p.GPIOTE_CH1, btn1, InputChannelPolarity::LoToHi);
26
27 let trigger0 = egu1.trigger(TriggerNumber::Trigger0);
28 let trigger1 = egu1.trigger(TriggerNumber::Trigger1);
29
30 let mut ppi1: Ppi<PPI_CH0, 1, 1> = Ppi::new_one_to_one(
31 p.PPI_CH0,
32 btn1.event_in(),
33 trigger0.task(),
34 );
35 ppi1.enable();
36
37 let mut ppi2: Ppi<PPI_CH1, 1, 1> = Ppi::new_one_to_one(
38 p.PPI_CH1,
39 trigger0.event(),
40 trigger1.task(),
41 );
42 ppi2.enable();
43
44 let mut ppi3: Ppi<PPI_CH2, 1, 1> = Ppi::new_one_to_one(
45 p.PPI_CH2,
46 trigger1.event(),
47 led1.task_out(),
48 );
49 ppi3.enable();
50
51 defmt::info!("Push the button to toggle the LED");
52 loop {
53 Timer::after(Duration::from_secs(60)).await;
54 }
55}