Skip to content

Commit e6de700

Browse files
committed
Merge remote-tracking branch 'upstream/master'
# Conflicts: # examples/blinky-button-demo/Embed.toml
2 parents 6a0341b + 3ce300c commit e6de700

File tree

7 files changed

+756
-1
lines changed

7 files changed

+756
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- TWIS module ([#196]).
1212
- PWM module ([#200]).
1313
- I2S module ([#201]).
14+
- SPIS module ([#226]).
1415

1516
### Fixes
1617

@@ -95,6 +96,5 @@ None
9596
[#168]: https://github.com/nrf-rs/nrf-hal/pull/168
9697
[#167]: https://github.com/nrf-rs/nrf-hal/pull/167
9798
[#172]: https://github.com/nrf-rs/nrf-hal/pull/172
98-
9999
[0.11.0]: https://github.com/nrf-rs/nrf-hal/releases/tag/v0.11.0
100100
[0.11.1]: https://github.com/nrf-rs/nrf-hal/releases/tag/v0.11.1

examples/spis-demo/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "spis-demo"
3+
version = "0.1.0"
4+
authors = ["Henrik Alsér"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
cortex-m = "0.6.2"
11+
cortex-m-rtic = "0.5.3"
12+
rtt-target = {version = "0.2.0", features = ["cortex-m"] }
13+
nrf52840-hal = { features = ["rt"], path = "../../nrf52840-hal" }
14+
15+
[dependencies.embedded-hal]
16+
version = "0.2.3"
17+
features = ["unproven"]

examples/spis-demo/Embed.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[default.probe]
2+
protocol = "Swd"
3+
4+
[default.flashing]
5+
enabled = true
6+
halt_afterwards = false
7+
restore_unwritten_bytes = false
8+
9+
[default.general]
10+
chip = "nRF52840"
11+
chip_descriptions = []
12+
log_level = "Warn"
13+
14+
[default.rtt]
15+
enabled = true
16+
channels = []
17+
timeout = 3000
18+
show_timestamps = true
19+
20+
[default.gdb]
21+
enabled = false

examples/spis-demo/src/main.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
// Demo for the SPIS module, transmitting the current buffer contents while receiving new data.
5+
// Press button to zero the buffer.
6+
7+
use {
8+
core::{
9+
panic::PanicInfo,
10+
sync::atomic::{compiler_fence, Ordering},
11+
},
12+
hal::{gpiote::Gpiote, pac::SPIS0, spis::*},
13+
nrf52840_hal as hal,
14+
rtt_target::{rprintln, rtt_init_print},
15+
};
16+
17+
#[rtic::app(device = crate::hal::pac, peripherals = true)]
18+
const APP: () = {
19+
struct Resources {
20+
gpiote: Gpiote,
21+
transfer: Option<Transfer<SPIS0, &'static mut [u8; 8]>>,
22+
}
23+
24+
#[init]
25+
fn init(ctx: init::Context) -> init::LateResources {
26+
static mut BUF: [u8; 8] = [0; 8];
27+
28+
let _clocks = hal::clocks::Clocks::new(ctx.device.CLOCK).enable_ext_hfosc();
29+
rtt_init_print!();
30+
rprintln!("Send me [u8; 8] over SPI");
31+
rprintln!("Press button to reset buffer");
32+
33+
let p0 = hal::gpio::p0::Parts::new(ctx.device.P0);
34+
let cs_pin = p0.p0_25.into_floating_input().degrade();
35+
let sck_pin = p0.p0_24.into_floating_input().degrade();
36+
let copi_pin = p0.p0_16.into_floating_input().degrade();
37+
let cipo_pin = p0.p0_14.into_floating_input().degrade();
38+
39+
let spis = Spis::new(
40+
ctx.device.SPIS0,
41+
Pins {
42+
sck: sck_pin,
43+
cs: cs_pin,
44+
copi: Some(copi_pin),
45+
cipo: Some(cipo_pin),
46+
},
47+
);
48+
spis.enable_interrupt(SpisEvent::End);
49+
50+
let btn = p0.p0_29.into_pullup_input().degrade();
51+
let gpiote = Gpiote::new(ctx.device.GPIOTE);
52+
gpiote.port().input_pin(&btn).low();
53+
gpiote.port().enable_interrupt();
54+
55+
init::LateResources {
56+
gpiote,
57+
transfer: spis.transfer(BUF).ok(),
58+
}
59+
}
60+
61+
#[task(binds = GPIOTE, resources = [gpiote, transfer])]
62+
fn on_gpiote(ctx: on_gpiote::Context) {
63+
ctx.resources.gpiote.reset_events();
64+
rprintln!("Reset buffer");
65+
let (buf, spis) = ctx.resources.transfer.take().unwrap().wait();
66+
buf.copy_from_slice(&[0; 8][..]);
67+
rprintln!("{:?}", buf);
68+
*ctx.resources.transfer = spis.transfer(buf).ok();
69+
}
70+
71+
#[task(binds = SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0, resources = [transfer])]
72+
fn on_spis(ctx: on_spis::Context) {
73+
let (buf, spis) = ctx.resources.transfer.take().unwrap().wait();
74+
spis.reset_event(SpisEvent::End);
75+
rprintln!("Received: {:?}", buf);
76+
*ctx.resources.transfer = spis.transfer(buf).ok();
77+
}
78+
};
79+
80+
#[inline(never)]
81+
#[panic_handler]
82+
fn panic(info: &PanicInfo) -> ! {
83+
cortex_m::interrupt::disable();
84+
rprintln!("{}", info);
85+
loop {
86+
compiler_fence(Ordering::SeqCst);
87+
}
88+
}

nrf-hal-common/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ pub mod saadc;
5757
pub mod spi;
5858
#[cfg(not(feature = "51"))]
5959
pub mod spim;
60+
#[cfg(not(feature = "51"))]
61+
pub mod spis;
6062
#[cfg(not(feature = "9160"))]
6163
pub mod temp;
6264
pub mod time;

0 commit comments

Comments
 (0)