Skip to content

Commit ced5036

Browse files
committed
Merge upstream
2 parents a9ff28d + a20dfc3 commit ced5036

File tree

14 files changed

+223
-121
lines changed

14 files changed

+223
-121
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11-
timeout-minutes: 10
11+
timeout-minutes: 30
1212
continue-on-error: ${{ matrix.rust_version == 'nightly' }}
1313

1414
steps:
@@ -34,7 +34,12 @@ jobs:
3434
thumbv8m.main-none-eabi
3535
- name: Build Crates
3636
run: cargo test -p xtask
37+
env:
38+
RUSTFLAGS: ${{ matrix.rustflags }}
3739

3840
strategy:
3941
matrix:
40-
rust_version: [stable, beta, nightly]
42+
rust_version: [beta, nightly]
43+
include:
44+
- rust_version: stable
45+
rustflags: --deny warnings

CHANGELOG.md

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,42 @@
1010
- LPCOMP module ([#195]).
1111
- TWIS module ([#196]).
1212
- PWM module ([#200]).
13-
- I2S module ([#201]).
14-
- SPIS module ([#226]).
13+
- I2S module ([#201] [#209] [#225] [#237]).
14+
- SPIS module ([#226] [#236]).
1515
- Add support for the nRF52811 ([#227]).
16+
- Add PPI channel group tasks ([#212]).
17+
- Add PPI endpoints for timers ([#239]).
18+
19+
### Enhancements
20+
21+
- Improve SAADC docs ([#218]).
22+
- Update Embed.toml of all examples to new defaults ([#229]).
23+
- Make `ConfigurablePpi` and subtrait of `Ppi` ([#244]).
1624

1725
### Fixes
1826

1927
- Refuse to build nRF52+ HALs for thumbv6m targets ([#203]).
2028
- Refuse to build `nrf52810-hal` for hard-float targets, and `nrf51-hal` for thumbv7+ targets
2129
([#206]).
22-
- GPIOTE Port 1 and 0 differentiation for nRF52833 and nRF52840 ([#217])
30+
- Set the correct Port in GPIOTE ([#217] [#248]).
2331
- Correct TWIM port initialization for P1 pins ([#221]).
32+
- Fix race condition in RTC event handling ([#243]).
2433

2534
### Breaking Changes
2635

27-
- Remove `Spi::read` ([#190]).
36+
- Remove `Spi::read` in favor of `transfer_split_uneven` ([#190]).
2837
- Seal the `timer::Instance` trait ([#214]).
29-
- Make GPIOs start in a `Disconnected` state instead of `Input<Floating>` ([#220]).
38+
- Make GPIOs start in a `Disconnected` state instead of `Input<Floating>` ([#220] [#245]).
39+
- 🦭 all `Instance` traits ([#255]).
40+
- 🦭 PPI traits ([#259]).
41+
- Various TWIM fixes and improvements - removes automatic transfer splitting ([#242]).
42+
- Remove typestate from RTC to make it easier to use ([#252]).
43+
- Also return owned `Pins` from `Usart::free()` ([#261]).
44+
45+
### Internal Improvements
46+
47+
- Utilize [`cargo-xtask`] to simplify CI and the release process ([#207] [#210]).
48+
- Add `conf()` utility function to reduce code duplication in GPIO ([#250]).
3049

3150
[#185]: https://github.com/nrf-rs/nrf-hal/pull/185
3251
[#188]: https://github.com/nrf-rs/nrf-hal/pull/188
@@ -36,12 +55,35 @@
3655
[#200]: https://github.com/nrf-rs/nrf-hal/pull/200
3756
[#201]: https://github.com/nrf-rs/nrf-hal/pull/201
3857
[#203]: https://github.com/nrf-rs/nrf-hal/pull/203
58+
[#209]: https://github.com/nrf-rs/nrf-hal/pull/209
3959
[#190]: https://github.com/nrf-rs/nrf-hal/pull/190
4060
[#206]: https://github.com/nrf-rs/nrf-hal/pull/206
61+
[#207]: https://github.com/nrf-rs/nrf-hal/pull/207
62+
[#210]: https://github.com/nrf-rs/nrf-hal/pull/210
63+
[#212]: https://github.com/nrf-rs/nrf-hal/pull/212
4164
[#217]: https://github.com/nrf-rs/nrf-hal/pull/217
4265
[#214]: https://github.com/nrf-rs/nrf-hal/pull/214
66+
[#218]: https://github.com/nrf-rs/nrf-hal/pull/218
4367
[#220]: https://github.com/nrf-rs/nrf-hal/pull/220
4468
[#221]: https://github.com/nrf-rs/nrf-hal/pull/221
69+
[#225]: https://github.com/nrf-rs/nrf-hal/pull/225
70+
[#226]: https://github.com/nrf-rs/nrf-hal/pull/226
71+
[#227]: https://github.com/nrf-rs/nrf-hal/pull/227
72+
[#229]: https://github.com/nrf-rs/nrf-hal/pull/229
73+
[#236]: https://github.com/nrf-rs/nrf-hal/pull/236
74+
[#237]: https://github.com/nrf-rs/nrf-hal/pull/237
75+
[#239]: https://github.com/nrf-rs/nrf-hal/pull/239
76+
[#242]: https://github.com/nrf-rs/nrf-hal/pull/242
77+
[#243]: https://github.com/nrf-rs/nrf-hal/pull/243
78+
[#244]: https://github.com/nrf-rs/nrf-hal/pull/244
79+
[#245]: https://github.com/nrf-rs/nrf-hal/pull/245
80+
[#248]: https://github.com/nrf-rs/nrf-hal/pull/248
81+
[#250]: https://github.com/nrf-rs/nrf-hal/pull/250
82+
[#252]: https://github.com/nrf-rs/nrf-hal/pull/252
83+
[#255]: https://github.com/nrf-rs/nrf-hal/pull/255
84+
[#259]: https://github.com/nrf-rs/nrf-hal/pull/259
85+
[#261]: https://github.com/nrf-rs/nrf-hal/pull/261
86+
[`cargo-xtask`]: https://github.com/matklad/cargo-xtask
4587

4688
## [0.11.1]
4789

examples/rtc-demo/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ fn main() -> ! {
2424
let clocks = clocks.start_lfclk();
2525

2626
// Run RTC for 1 second
27-
let mut rtc = Rtc::new(p.RTC0);
27+
let mut rtc = Rtc::new(p.RTC0, 0).unwrap();
2828
rtc.set_compare(RtcCompareReg::Compare0, 32_768).unwrap();
2929
rtc.enable_event(RtcInterrupt::Compare0);
3030

3131
rprintln!("Starting RTC");
32-
let rtc = rtc.enable_counter();
32+
rtc.enable_counter();
3333

3434
rprintln!("Waiting for compare match");
3535
while !rtc.is_event_triggered(RtcInterrupt::Compare0) {}
3636
rtc.reset_event(RtcInterrupt::Compare0);
3737

3838
rprintln!("Compare match, stopping RTC");
39-
let rtc = rtc.disable_counter();
39+
rtc.disable_counter();
4040

4141
rprintln!("Counter stopped at {} ticks", rtc.get_counter());
4242

nrf-hal-common/src/gpio.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,22 @@ pub enum Port {
4343
Port1,
4444
}
4545

46+
#[cfg(any(feature = "52833", feature = "52840"))]
4647
impl Port {
47-
#[cfg(any(feature = "52833", feature = "52840"))]
4848
pub(crate) fn bit(&self) -> bool {
4949
match self {
5050
Port::Port0 => false,
5151
Port::Port1 => true,
5252
}
5353
}
54+
55+
pub(crate) fn from_bit(bit: bool) -> Port {
56+
if bit {
57+
Port::Port1
58+
} else {
59+
Port::Port0
60+
}
61+
}
5462
}
5563

5664
// ===============================================================
@@ -81,7 +89,7 @@ use crate::hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
8189
use void::Void;
8290

8391
impl<MODE> Pin<MODE> {
84-
fn new(port: Port, pin: u8) -> Self {
92+
pub(crate) fn new(port: Port, pin: u8) -> Self {
8593
let port_bits = match port {
8694
Port::Port0 => 0x00,
8795
#[cfg(any(feature = "52833", feature = "52840"))]

nrf-hal-common/src/ppi/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ mod sealed {
6161
pub trait ChannelGroup {
6262
const CHG: usize;
6363
}
64+
65+
pub trait PpiSealed {}
66+
pub trait PpiChannelGroupSealed {}
6467
}
65-
use sealed::{Channel, ChannelGroup, Event, NotFixed, Task};
68+
use sealed::{Channel, ChannelGroup, Event, NotFixed, PpiChannelGroupSealed, PpiSealed, Task};
6669

6770
pub struct TaskAddr(pub(crate) u32);
6871
pub struct EventAddr(pub(crate) u32);
6972

7073
/// Trait to represent a Programmable Peripheral Interconnect channel.
71-
pub trait Ppi {
74+
pub trait Ppi: PpiSealed {
7275
/// Enables the channel.
7376
fn enable(&mut self);
7477

@@ -93,7 +96,7 @@ pub trait ConfigurablePpi: Ppi {
9396
}
9497

9598
/// Trait for a PPI channel group.
96-
pub trait PpiChannelGroup {
99+
pub trait PpiChannelGroup: PpiChannelGroupSealed {
97100
/// Returns reference to `tasks_chg[x].en` endpoint for enabling channel group.
98101
fn task_enable(&self) -> &Reg<u32, _EN>;
99102
/// Returns reference to `tasks_chg[x].dis` endpoint for disabling channel group.
@@ -108,6 +111,7 @@ pub trait PpiChannelGroup {
108111

109112
// All unsafe `ptr` calls only uses registers atomically, and only changes the resources owned by
110113
// the type (guaranteed by the abstraction).
114+
impl<P: Channel> PpiSealed for P {}
111115
impl<P: Channel> Ppi for P {
112116
#[inline(always)]
113117
fn enable(&mut self) {
@@ -151,6 +155,7 @@ impl<P: Channel + NotFixed> ConfigurablePpi for P {
151155
}
152156
}
153157

158+
impl<G: ChannelGroup> PpiChannelGroupSealed for G {}
154159
impl<G: ChannelGroup> PpiChannelGroup for G {
155160
#[inline(always)]
156161
fn task_enable(&self) -> &Reg<u32, _EN> {

nrf-hal-common/src/pwm.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -463,34 +463,6 @@ where
463463
self
464464
}
465465

466-
fn load_seq<B>(&self, seq: Seq, buf: B) -> Result<(), Error>
467-
where
468-
B: ReadBuffer<Word = u16> + 'static,
469-
{
470-
let (ptr, len) = unsafe { buf.read_buffer() };
471-
if (ptr as usize) < SRAM_LOWER || (ptr as usize) > SRAM_UPPER {
472-
return Err(Error::DMABufferNotInDataMemory);
473-
}
474-
475-
if len > (1 << 15) / core::mem::size_of::<u16>() {
476-
return Err(Error::BufferTooLong);
477-
}
478-
479-
compiler_fence(Ordering::SeqCst);
480-
481-
match seq {
482-
Seq::Seq0 => {
483-
self.pwm.seq0.ptr.write(|w| unsafe { w.bits(ptr as u32) });
484-
self.pwm.seq0.cnt.write(|w| unsafe { w.bits(len as u32) });
485-
}
486-
Seq::Seq1 => {
487-
self.pwm.seq1.ptr.write(|w| unsafe { w.bits(ptr as u32) });
488-
self.pwm.seq1.cnt.write(|w| unsafe { w.bits(len as u32) });
489-
}
490-
}
491-
Ok(())
492-
}
493-
494466
/// Loads the first PWM value on all enabled channels from a sequence and starts playing that sequence.
495467
/// Causes PWM generation to start if not running.
496468
#[inline(always)]
@@ -1092,7 +1064,7 @@ pub enum Error {
10921064
BufferTooLong,
10931065
}
10941066

1095-
pub trait Instance: private::Sealed + Deref<Target = crate::pac::pwm0::RegisterBlock> {
1067+
pub trait Instance: sealed::Sealed + Deref<Target = crate::pac::pwm0::RegisterBlock> {
10961068
const INTERRUPT: Interrupt;
10971069

10981070
/// Provides access to the associated internal duty buffer for the instance.
@@ -1140,7 +1112,7 @@ impl Instance for PWM3 {
11401112
}
11411113
}
11421114

1143-
mod private {
1115+
mod sealed {
11441116
pub trait Sealed {}
11451117
impl Sealed for crate::pwm::PWM0 {}
11461118

nrf-hal-common/src/rtc.rs

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,9 @@ use crate::pac::{rtc0, Interrupt, NVIC, RTC0, RTC1};
1111
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
1212
use crate::pac::RTC2;
1313

14-
// Zero Size Type State structs
15-
16-
/// The RTC has been stopped.
17-
pub struct Stopped;
18-
/// The RTC has been started.
19-
pub struct Started;
20-
2114
/// An opaque high level interface to an RTC peripheral.
22-
pub struct Rtc<T, M> {
15+
pub struct Rtc<T> {
2316
periph: T,
24-
_mode: M,
25-
}
26-
27-
impl<T> Rtc<T, Stopped>
28-
where
29-
T: Instance,
30-
{
31-
pub fn new(rtc: T) -> Self {
32-
Rtc {
33-
periph: rtc,
34-
_mode: Stopped,
35-
}
36-
}
3717
}
3818

3919
/// Interrupts/Events that can be generated by the RTCn peripheral.
@@ -54,30 +34,34 @@ pub enum RtcCompareReg {
5434
Compare3,
5535
}
5636

57-
impl<T, M> Rtc<T, M>
37+
impl<T> Rtc<T>
5838
where
5939
T: Instance,
6040
{
41+
/// Creates a new RTC peripheral instance with a 12 bits prescaler.
42+
/// fRTC = 32_768 / (`prescaler` + 1 )
43+
pub fn new(rtc: T, prescaler: u32) -> Result<Self, Error> {
44+
if prescaler >= (1 << 12) {
45+
return Err(Error::PrescalerOutOfRange);
46+
}
47+
48+
unsafe { rtc.prescaler.write(|w| w.bits(prescaler)) };
49+
50+
Ok(Rtc { periph: rtc })
51+
}
52+
6153
/// Enable/start the Real Time Counter.
62-
pub fn enable_counter(self) -> Rtc<T, Started> {
54+
pub fn enable_counter(&self) {
6355
unsafe {
6456
self.periph.tasks_start.write(|w| w.bits(1));
6557
}
66-
Rtc {
67-
periph: self.periph,
68-
_mode: Started,
69-
}
7058
}
7159

7260
/// Disable/stop the Real Time Counter.
73-
pub fn disable_counter(self) -> Rtc<T, Stopped> {
61+
pub fn disable_counter(&self) {
7462
unsafe {
7563
self.periph.tasks_stop.write(|w| w.bits(1));
7664
}
77-
Rtc {
78-
periph: self.periph,
79-
_mode: Stopped,
80-
}
8165
}
8266

8367
/// Enable the generation of a hardware interrupt from a given stimulus.
@@ -234,35 +218,23 @@ pub enum Error {
234218
CompareOutOfRange,
235219
}
236220

237-
impl<T> Rtc<T, Stopped>
238-
where
239-
T: Instance,
240-
{
241-
/// Set the prescaler for the RTC peripheral. 12 bits of range.
242-
/// fRTC = 32_768 / (`prescaler` + 1 )
243-
pub fn set_prescaler(&mut self, prescaler: u32) -> Result<(), Error> {
244-
if prescaler >= (1 << 12) {
245-
return Err(Error::PrescalerOutOfRange);
246-
}
247-
248-
unsafe { self.periph.prescaler.write(|w| w.bits(prescaler)) };
249-
250-
Ok(())
251-
}
252-
}
253-
254221
/// Implemented by all RTC instances.
255-
pub trait Instance: Deref<Target = rtc0::RegisterBlock> {
222+
pub trait Instance: Deref<Target = rtc0::RegisterBlock> + sealed::Sealed {
256223
/// The interrupt associated with this RTC instance.
257224
const INTERRUPT: Interrupt;
258225
}
259226

227+
mod sealed {
228+
pub trait Sealed {}
229+
}
230+
260231
macro_rules! impl_instance {
261232
($($name:ident,)*) => {
262233
$(
263234
impl Instance for $name {
264235
const INTERRUPT: Interrupt = Interrupt::$name;
265236
}
237+
impl sealed::Sealed for $name {}
266238
)*
267239
}
268240
}

nrf-hal-common/src/spi.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,14 @@ pub enum Error {
128128
}
129129

130130
/// Trait implemented by all SPI peripheral instances.
131-
pub trait Instance: Deref<Target = spi0::RegisterBlock> {}
131+
pub trait Instance: Deref<Target = spi0::RegisterBlock> + sealed::Sealed {}
132132

133+
mod sealed {
134+
pub trait Sealed {}
135+
}
136+
137+
impl sealed::Sealed for SPI0 {}
133138
impl Instance for SPI0 {}
134139

140+
impl sealed::Sealed for SPI1 {}
135141
impl Instance for SPI1 {}

0 commit comments

Comments
 (0)