aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf-examples/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-03-19 04:08:44 +0100
committerDario Nieuwenhuis <[email protected]>2021-03-29 00:58:57 +0200
commitfcf6a63b5cf1d1505ec01ea42a1a75f33794b038 (patch)
treecc8acfe57060d25979d13820cebaf49959b6d025 /embassy-nrf-examples/src
parentd9aaa0edf88e822b9e5d6deb5f4a133dd32449fa (diff)
nrf: add owned Peripherals struct, migrate gpio and spim
Diffstat (limited to 'embassy-nrf-examples/src')
-rw-r--r--embassy-nrf-examples/src/bin/spim.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/embassy-nrf-examples/src/bin/spim.rs b/embassy-nrf-examples/src/bin/spim.rs
index d3d942e4e..8eaac5e15 100644
--- a/embassy-nrf-examples/src/bin/spim.rs
+++ b/embassy-nrf-examples/src/bin/spim.rs
@@ -6,6 +6,8 @@
6 6
7#[path = "../example_common.rs"] 7#[path = "../example_common.rs"]
8mod example_common; 8mod example_common;
9use embassy_nrf::gpio::{Level, Output};
10use embassy_nrf::peripherals::Peripherals;
9use embassy_traits::spi::FullDuplex; 11use embassy_traits::spi::FullDuplex;
10use example_common::*; 12use example_common::*;
11 13
@@ -16,7 +18,6 @@ use embassy::util::Forever;
16use embedded_hal::digital::v2::*; 18use embedded_hal::digital::v2::*;
17use futures::pin_mut; 19use futures::pin_mut;
18use nrf52840_hal::clocks; 20use nrf52840_hal::clocks;
19use nrf52840_hal::gpio;
20 21
21use embassy_nrf::{interrupt, pac, rtc, spim}; 22use embassy_nrf::{interrupt, pac, rtc, spim};
22 23
@@ -24,25 +25,20 @@ use embassy_nrf::{interrupt, pac, rtc, spim};
24async fn run() { 25async fn run() {
25 info!("running!"); 26 info!("running!");
26 27
27 let p = unsafe { embassy_nrf::pac::Peripherals::steal() }; 28 let mut p = unsafe { Peripherals::steal() };
28 let p0 = gpio::p0::Parts::new(p.P0);
29 29
30 let pins = spim::Pins {
31 sck: p0.p0_29.into_push_pull_output(gpio::Level::Low).degrade(),
32 miso: Some(p0.p0_28.into_floating_input().degrade()),
33 mosi: Some(p0.p0_30.into_push_pull_output(gpio::Level::Low).degrade()),
34 };
35 let config = spim::Config { 30 let config = spim::Config {
36 pins,
37 frequency: spim::Frequency::M16, 31 frequency: spim::Frequency::M16,
38 mode: spim::MODE_0, 32 mode: spim::MODE_0,
39 orc: 0x00, 33 orc: 0x00,
40 }; 34 };
41 35
42 let mut ncs = p0.p0_31.into_push_pull_output(gpio::Level::High); 36 let mut irq = interrupt::take!(SPIM3);
43 let spim = spim::Spim::new(p.SPIM3, interrupt::take!(SPIM3), config); 37 let spim = spim::Spim::new(p.spim3, irq, p.p0_29, p.p0_28, p.p0_30, config);
44 pin_mut!(spim); 38 pin_mut!(spim);
45 39
40 let mut ncs = Output::new(p.p0_31, Level::High);
41
46 // Example on how to talk to an ENC28J60 chip 42 // Example on how to talk to an ENC28J60 chip
47 43
48 // softreset 44 // softreset