aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
authornerwalt <[email protected]>2024-07-11 06:58:05 -0600
committernerwalt <[email protected]>2024-07-11 06:58:05 -0600
commit38d8abef26dbc3e28e94c367171a06e5be798a5f (patch)
tree86813371da222191fe66fedc71dfae8098cb4d22 /embassy-nrf
parent98263ac220102a60c1f7cd3a882acafbb59b53f1 (diff)
parented3da1721a4f704d3f2a8a1cf84d9fc051c71945 (diff)
Merge branch 'main' into nrf9151
Diffstat (limited to 'embassy-nrf')
-rw-r--r--embassy-nrf/CHANGELOG.md1
-rw-r--r--embassy-nrf/src/pwm.rs58
-rw-r--r--embassy-nrf/src/radio/ble.rs9
3 files changed, 56 insertions, 12 deletions
diff --git a/embassy-nrf/CHANGELOG.md b/embassy-nrf/CHANGELOG.md
index 773a1a108..6f07a8c6d 100644
--- a/embassy-nrf/CHANGELOG.md
+++ b/embassy-nrf/CHANGELOG.md
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
24- spi: Add support for configuring bit order for bus 24- spi: Add support for configuring bit order for bus
25- pwm: Expose `pwm::PWM_CLK_HZ` and add `is_enabled` method 25- pwm: Expose `pwm::PWM_CLK_HZ` and add `is_enabled` method
26- gpio: Drop GPIO Pin generics (API break) 26- gpio: Drop GPIO Pin generics (API break)
27- pwm: Allow specifying OutputDrive for PWM channels
27 28
28## 0.1.0 - 2024-01-12 29## 0.1.0 - 2024-01-12
29 30
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index 12057f7dd..8e8f166d7 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -6,7 +6,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
6 6
7use embassy_hal_internal::{into_ref, PeripheralRef}; 7use embassy_hal_internal::{into_ref, PeripheralRef};
8 8
9use crate::gpio::{AnyPin, Pin as GpioPin, PselBits, SealedPin as _}; 9use crate::gpio::{convert_drive, AnyPin, OutputDrive, Pin as GpioPin, PselBits, SealedPin as _};
10use crate::ppi::{Event, Task}; 10use crate::ppi::{Event, Task};
11use crate::util::slice_in_ram_or; 11use crate::util::slice_in_ram_or;
12use crate::{interrupt, pac, Peripheral}; 12use crate::{interrupt, pac, Peripheral};
@@ -128,19 +128,23 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
128 128
129 if let Some(pin) = &ch0 { 129 if let Some(pin) = &ch0 {
130 pin.set_low(); 130 pin.set_low();
131 pin.conf().write(|w| w.dir().output()); 131 pin.conf()
132 .write(|w| w.dir().output().drive().variant(convert_drive(config.ch0_drive)));
132 } 133 }
133 if let Some(pin) = &ch1 { 134 if let Some(pin) = &ch1 {
134 pin.set_low(); 135 pin.set_low();
135 pin.conf().write(|w| w.dir().output()); 136 pin.conf()
137 .write(|w| w.dir().output().drive().variant(convert_drive(config.ch1_drive)));
136 } 138 }
137 if let Some(pin) = &ch2 { 139 if let Some(pin) = &ch2 {
138 pin.set_low(); 140 pin.set_low();
139 pin.conf().write(|w| w.dir().output()); 141 pin.conf()
142 .write(|w| w.dir().output().drive().variant(convert_drive(config.ch2_drive)));
140 } 143 }
141 if let Some(pin) = &ch3 { 144 if let Some(pin) = &ch3 {
142 pin.set_low(); 145 pin.set_low();
143 pin.conf().write(|w| w.dir().output()); 146 pin.conf()
147 .write(|w| w.dir().output().drive().variant(convert_drive(config.ch3_drive)));
144 } 148 }
145 149
146 r.psel.out[0].write(|w| unsafe { w.bits(ch0.psel_bits()) }); 150 r.psel.out[0].write(|w| unsafe { w.bits(ch0.psel_bits()) });
@@ -319,6 +323,14 @@ pub struct Config {
319 pub prescaler: Prescaler, 323 pub prescaler: Prescaler,
320 /// How a sequence is read from RAM and is spread to the compare register 324 /// How a sequence is read from RAM and is spread to the compare register
321 pub sequence_load: SequenceLoad, 325 pub sequence_load: SequenceLoad,
326 /// Drive strength for the channel 0 line.
327 pub ch0_drive: OutputDrive,
328 /// Drive strength for the channel 1 line.
329 pub ch1_drive: OutputDrive,
330 /// Drive strength for the channel 2 line.
331 pub ch2_drive: OutputDrive,
332 /// Drive strength for the channel 3 line.
333 pub ch3_drive: OutputDrive,
322} 334}
323 335
324impl Default for Config { 336impl Default for Config {
@@ -328,6 +340,10 @@ impl Default for Config {
328 max_duty: 1000, 340 max_duty: 1000,
329 prescaler: Prescaler::Div16, 341 prescaler: Prescaler::Div16,
330 sequence_load: SequenceLoad::Common, 342 sequence_load: SequenceLoad::Common,
343 ch0_drive: OutputDrive::Standard,
344 ch1_drive: OutputDrive::Standard,
345 ch2_drive: OutputDrive::Standard,
346 ch3_drive: OutputDrive::Standard,
331 } 347 }
332 } 348 }
333} 349}
@@ -815,6 +831,38 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
815 let max_duty = self.max_duty() as u32; 831 let max_duty = self.max_duty() as u32;
816 clk / max_duty 832 clk / max_duty
817 } 833 }
834
835 /// Sets the PWM-Channel0 output drive strength
836 #[inline(always)]
837 pub fn set_ch0_drive(&self, drive: OutputDrive) {
838 if let Some(pin) = &self.ch0 {
839 pin.conf().modify(|_, w| w.drive().variant(convert_drive(drive)));
840 }
841 }
842
843 /// Sets the PWM-Channel1 output drive strength
844 #[inline(always)]
845 pub fn set_ch1_drive(&self, drive: OutputDrive) {
846 if let Some(pin) = &self.ch1 {
847 pin.conf().modify(|_, w| w.drive().variant(convert_drive(drive)));
848 }
849 }
850
851 /// Sets the PWM-Channel2 output drive strength
852 #[inline(always)]
853 pub fn set_ch2_drive(&self, drive: OutputDrive) {
854 if let Some(pin) = &self.ch2 {
855 pin.conf().modify(|_, w| w.drive().variant(convert_drive(drive)));
856 }
857 }
858
859 /// Sets the PWM-Channel3 output drive strength
860 #[inline(always)]
861 pub fn set_ch3_drive(&self, drive: OutputDrive) {
862 if let Some(pin) = &self.ch3 {
863 pin.conf().modify(|_, w| w.drive().variant(convert_drive(drive)));
864 }
865 }
818} 866}
819 867
820impl<'a, T: Instance> Drop for SimplePwm<'a, T> { 868impl<'a, T: Instance> Drop for SimplePwm<'a, T> {
diff --git a/embassy-nrf/src/radio/ble.rs b/embassy-nrf/src/radio/ble.rs
index 93003fb19..4f0b0641f 100644
--- a/embassy-nrf/src/radio/ble.rs
+++ b/embassy-nrf/src/radio/ble.rs
@@ -335,8 +335,6 @@ impl<'d, T: Instance> Radio<'d, T> {
335 } 335 }
336 336
337 async fn trigger_and_wait_end(&mut self, trigger: impl FnOnce()) { 337 async fn trigger_and_wait_end(&mut self, trigger: impl FnOnce()) {
338 //self.trace_state();
339
340 let r = T::regs(); 338 let r = T::regs();
341 let s = T::state(); 339 let s = T::state();
342 340
@@ -347,12 +345,10 @@ impl<'d, T: Instance> Radio<'d, T> {
347 trace!("radio drop: stopping"); 345 trace!("radio drop: stopping");
348 346
349 r.intenclr.write(|w| w.end().clear()); 347 r.intenclr.write(|w| w.end().clear());
350 r.events_end.reset();
351 348
352 r.tasks_stop.write(|w| unsafe { w.bits(1) }); 349 r.tasks_stop.write(|w| unsafe { w.bits(1) });
353 350
354 // The docs don't explicitly mention any event to acknowledge the stop task 351 r.events_end.reset();
355 while r.events_end.read().bits() == 0 {}
356 352
357 trace!("radio drop: stopped"); 353 trace!("radio drop: stopped");
358 }); 354 });
@@ -368,7 +364,6 @@ impl<'d, T: Instance> Radio<'d, T> {
368 364
369 // Trigger the transmission 365 // Trigger the transmission
370 trigger(); 366 trigger();
371 // self.trace_state();
372 367
373 // On poll check if interrupt happen 368 // On poll check if interrupt happen
374 poll_fn(|cx| { 369 poll_fn(|cx| {
@@ -382,7 +377,7 @@ impl<'d, T: Instance> Radio<'d, T> {
382 .await; 377 .await;
383 378
384 compiler_fence(Ordering::SeqCst); 379 compiler_fence(Ordering::SeqCst);
385 r.events_disabled.reset(); // ACK 380 r.events_end.reset(); // ACK
386 381
387 // Everthing ends fine, so it disable the drop 382 // Everthing ends fine, so it disable the drop
388 drop.defuse(); 383 drop.defuse();