Skip to content

Commit 6ff8113

Browse files
authored
Merge pull request #278 from embassy-rs/no-pac
Remove dependency on the PAC.
2 parents 991d28e + 7e017eb commit 6ff8113

File tree

7 files changed

+54
-66
lines changed

7 files changed

+54
-66
lines changed

.vscode/settings.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
{
22
"editor.formatOnSave": true,
3-
"rust-analyzer.cargo.allFeatures": false,
4-
"rust-analyzer.checkOnSave.allFeatures": false,
3+
"rust-analyzer.imports.granularity.group": "module",
4+
"rust-analyzer.cargo.allTargets": false,
55
"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
6-
"rust-analyzer.checkOnSave.allTargets": false,
7-
"rust-analyzer.procMacro.enable": true,
86
"rust-analyzer.linkedProjects": [
97
"examples/Cargo.toml"
108
],
9+
"rust-analyzer.cargo.features": [
10+
"nrf52840-dk"
11+
],
1112
"files.watcherExclude": {
1213
"**/.git/objects/**": true,
1314
"**/.git/subtree-cache/**": true,
1415
"**/target/**": true,
1516
},
16-
"rust-analyzer.imports.granularity.group": "module",
17-
"rust-analyzer.cargo.buildScripts.enable": true,
18-
"rust-analyzer.procMacro.attributes.enable": false,
1917
}

ci.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -euxo pipefail
44

5+
export RUSTFLAGS=-Dwarnings
6+
57
# Build examples
68
#===============
79

nrf-softdevice/Cargo.toml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ rust-version = "1.76"
1212

1313
[features]
1414

15-
nrf52805 = ["nrf52805-pac"]
16-
nrf52810 = ["nrf52810-pac"]
17-
nrf52811 = ["nrf52811-pac"]
18-
nrf52820 = ["nrf52820-pac"]
19-
nrf52832 = ["nrf52832-pac"]
20-
nrf52833 = ["nrf52833-pac"]
21-
nrf52840 = ["nrf52840-pac"]
15+
nrf52805 = []
16+
nrf52810 = []
17+
nrf52811 = []
18+
nrf52820 = []
19+
nrf52832 = []
20+
nrf52833 = []
21+
nrf52840 = []
2222

2323
s112 = ["nrf-softdevice-s112"]
2424
s113 = ["nrf-softdevice-s113"]
@@ -56,21 +56,12 @@ num_enum = { version = "0.7.0", default-features = false }
5656
embassy-sync = { version = "0.6.0" }
5757
embassy-futures = { version = "0.1.1" }
5858
cortex-m = "0.7.2"
59-
cortex-m-rt = ">=0.6.15,<0.8"
6059
heapless = "0.8.0"
6160
fixed = "1.5.0"
6261
futures = { version = "0.3.17", default-features = false }
6362
embedded-storage = "0.3.1"
6463
embedded-storage-async = { version = "0.4.1" }
6564

66-
nrf52805-pac = { version = "0.12.0", features = ["rt"], optional = true }
67-
nrf52810-pac = { version = "0.12.0", features = ["rt"], optional = true }
68-
nrf52811-pac = { version = "0.12.0", features = ["rt"], optional = true }
69-
nrf52820-pac = { version = "0.12.0", features = ["rt"], optional = true }
70-
nrf52832-pac = { version = "0.12.0", features = ["rt"], optional = true }
71-
nrf52833-pac = { version = "0.12.0", features = ["rt"], optional = true }
72-
nrf52840-pac = { version = "0.12.0", features = ["rt"], optional = true }
73-
7465
nrf-softdevice-s112 = { version = "0.1.1", path = "../nrf-softdevice-s112", optional = true }
7566
nrf-softdevice-s113 = { version = "0.1.1", path = "../nrf-softdevice-s113", optional = true }
7667
nrf-softdevice-s122 = { version = "0.1.1", path = "../nrf-softdevice-s122", optional = true }

nrf-softdevice/src/critical_section_impl.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
use core::arch::asm;
22
use core::sync::atomic::{compiler_fence, AtomicBool, Ordering};
33

4-
use crate::pac::{Interrupt, NVIC};
4+
use cortex_m::peripheral::NVIC;
55

6-
#[cfg(any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811"))]
7-
const RESERVED_IRQS: u32 = (1 << (Interrupt::POWER_CLOCK as u8))
8-
| (1 << (Interrupt::RADIO as u8))
9-
| (1 << (Interrupt::RTC0 as u8))
10-
| (1 << (Interrupt::TIMER0 as u8))
11-
| (1 << (Interrupt::RNG as u8))
12-
| (1 << (Interrupt::ECB as u8))
13-
| (1 << (Interrupt::CCM_AAR as u8))
14-
| (1 << (Interrupt::TEMP as u8))
15-
| (1 << (Interrupt::SWI5 as u8));
6+
use crate::Interrupt;
167

17-
#[cfg(not(any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811")))]
188
const RESERVED_IRQS: u32 = (1 << (Interrupt::POWER_CLOCK as u8))
199
| (1 << (Interrupt::RADIO as u8))
2010
| (1 << (Interrupt::RTC0 as u8))

nrf-softdevice/src/events.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use embassy_sync::waitqueue::AtomicWaker;
55
use futures::future::poll_fn;
66
use num_enum::{IntoPrimitive, TryFromPrimitive};
77

8-
use crate::pac::interrupt;
98
use crate::{raw, RawError};
109

1110
static SWI2_SOC_EVT_WAKER: AtomicWaker = AtomicWaker::new();
@@ -100,16 +99,15 @@ pub(crate) async fn run_ble() -> ! {
10099
.await
101100
}
102101

103-
#[cfg(any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811"))]
104-
#[interrupt]
105-
unsafe fn SWI2() {
106-
SWI2_SOC_EVT_WAKER.wake();
107-
SWI2_BLE_EVT_WAKER.wake();
108-
}
109-
110-
#[cfg(not(any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811")))]
111-
#[interrupt]
112-
unsafe fn SWI2_EGU2() {
102+
#[cfg_attr(
103+
any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811"),
104+
export_name = "SWI2"
105+
)]
106+
#[cfg_attr(
107+
not(any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811")),
108+
export_name = "SWI2_EGU2"
109+
)]
110+
unsafe extern "C" fn swi2_irq_handler() {
113111
SWI2_SOC_EVT_WAKER.wake();
114112
SWI2_BLE_EVT_WAKER.wake();
115113
}

nrf-softdevice/src/lib.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,6 @@ compile_error!("The selected softdevice does not support ble-peripheral.");
122122
))]
123123
compile_error!("The selected softdevice does not support ble-l2cap.");
124124

125-
#[cfg(feature = "nrf52805")]
126-
use nrf52805_pac as pac;
127-
#[cfg(feature = "nrf52810")]
128-
use nrf52810_pac as pac;
129-
#[cfg(feature = "nrf52811")]
130-
use nrf52811_pac as pac;
131-
#[cfg(feature = "nrf52820")]
132-
use nrf52820_pac as pac;
133-
#[cfg(feature = "nrf52832")]
134-
use nrf52832_pac as pac;
135-
#[cfg(feature = "nrf52833")]
136-
use nrf52833_pac as pac;
137-
#[cfg(feature = "nrf52840")]
138-
use nrf52840_pac as pac;
139125
#[cfg(feature = "s112")]
140126
pub use nrf_softdevice_s112 as raw;
141127
#[cfg(feature = "s113")]
@@ -169,3 +155,27 @@ pub use temperature::temperature_celsius;
169155
mod random;
170156
pub use nrf_softdevice_macro::*;
171157
pub use random::random_bytes;
158+
159+
// Numbers of interrupts we care about are identical in all nRF52xxx.
160+
// We copypaste the enum here to avoid depending on the PAC, which avoids version conflicts.
161+
#[allow(non_camel_case_types, dead_code)]
162+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
163+
enum Interrupt {
164+
POWER_CLOCK = 0,
165+
RADIO = 1,
166+
TIMER0 = 8,
167+
RTC0 = 11,
168+
TEMP = 12,
169+
RNG = 13,
170+
ECB = 14,
171+
CCM_AAR = 15,
172+
SWI2_EGU2 = 22,
173+
SWI5_EGU5 = 25,
174+
}
175+
176+
unsafe impl cortex_m::interrupt::InterruptNumber for Interrupt {
177+
#[inline]
178+
fn number(self) -> u16 {
179+
self as u16
180+
}
181+
}

nrf-softdevice/src/softdevice.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use core::mem::MaybeUninit;
33
use core::ptr;
44
use core::sync::atomic::{AtomicBool, Ordering};
55

6-
use crate::{pac, raw, RawError, SocEvent};
6+
use cortex_m::peripheral::NVIC;
7+
8+
use crate::{raw, Interrupt, RawError, SocEvent};
79

810
unsafe extern "C" fn fault_handler(id: u32, pc: u32, info: u32) {
911
match (id, info) {
@@ -70,7 +72,7 @@ fn get_app_ram_base() -> u32 {
7072
static mut __sdata: u32;
7173
}
7274

73-
unsafe { ptr::addr_of!(__sdata) as u32 }
75+
ptr::addr_of!(__sdata) as u32
7476
}
7577

7678
fn cfg_set(id: u32, cfg: &raw::ble_cfg_t) {
@@ -259,10 +261,7 @@ impl Softdevice {
259261
}
260262

261263
unsafe {
262-
#[cfg(any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811"))]
263-
pac::NVIC::unmask(pac::interrupt::SWI2);
264-
#[cfg(not(any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811")))]
265-
pac::NVIC::unmask(pac::interrupt::SWI2_EGU2);
264+
NVIC::unmask(Interrupt::SWI2_EGU2);
266265
}
267266

268267
#[cfg(feature = "ble-gatt")]

0 commit comments

Comments
 (0)