diff options
| author | huntc <[email protected]> | 2022-01-24 17:08:24 +1100 |
|---|---|---|
| committer | huntc <[email protected]> | 2022-01-24 17:22:35 +1100 |
| commit | 48afef28a0c85d8296b0b984217350dad75daf46 (patch) | |
| tree | 76a0523ef781ba54c133c44e382550ad68a591d6 | |
| parent | 7598b8a40fba7e7035d67da5867f27d16818ea62 (diff) | |
Strengthen the borrow
The start method is now safe. Because it has the potential of borrowing the sequence and mutating itself, the sequence must outlive the Pwm struct.
| -rw-r--r-- | embassy-nrf/src/pwm.rs | 2 | ||||
| -rw-r--r-- | examples/nrf/src/bin/pwm_sequence.rs | 2 | ||||
| -rw-r--r-- | examples/nrf/src/bin/pwm_sequence_ppi.rs | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index cffe5a3b0..61a282833 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs | |||
| @@ -138,7 +138,7 @@ impl<'d, T: Instance> SequencePwm<'d, T> { | |||
| 138 | 138 | ||
| 139 | /// Start or restart playback | 139 | /// Start or restart playback |
| 140 | #[inline(always)] | 140 | #[inline(always)] |
| 141 | pub fn start(&self, sequence: &'d [u16], times: SequenceMode) -> Result<(), Error> { | 141 | pub fn start(&mut self, sequence: &'d [u16], times: SequenceMode) -> Result<(), Error> { |
| 142 | slice_in_ram_or(sequence, Error::DMABufferNotInDataMemory)?; | 142 | slice_in_ram_or(sequence, Error::DMABufferNotInDataMemory)?; |
| 143 | 143 | ||
| 144 | if sequence.len() > 32767 { | 144 | if sequence.len() > 32767 { |
diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs index 9877b54a6..561bc1dd1 100644 --- a/examples/nrf/src/bin/pwm_sequence.rs +++ b/examples/nrf/src/bin/pwm_sequence.rs | |||
| @@ -25,7 +25,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 25 | config.refresh = 624; | 25 | config.refresh = 624; |
| 26 | // thus our sequence takes 5 * 5000ms or 25 seconds | 26 | // thus our sequence takes 5 * 5000ms or 25 seconds |
| 27 | 27 | ||
| 28 | let pwm = unwrap!(SequencePwm::new( | 28 | let mut pwm = unwrap!(SequencePwm::new( |
| 29 | p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, | 29 | p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, |
| 30 | )); | 30 | )); |
| 31 | let _ = pwm.start(&seq_values_1, SequenceMode::Infinite); | 31 | let _ = pwm.start(&seq_values_1, SequenceMode::Infinite); |
diff --git a/examples/nrf/src/bin/pwm_sequence_ppi.rs b/examples/nrf/src/bin/pwm_sequence_ppi.rs index f72ccc112..213ef5ed7 100644 --- a/examples/nrf/src/bin/pwm_sequence_ppi.rs +++ b/examples/nrf/src/bin/pwm_sequence_ppi.rs | |||
| @@ -26,7 +26,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 26 | // thus our sequence takes 5 * 250ms or 1.25 seconds | 26 | // thus our sequence takes 5 * 250ms or 1.25 seconds |
| 27 | config.refresh = 30; | 27 | config.refresh = 30; |
| 28 | 28 | ||
| 29 | let pwm = unwrap!(SequencePwm::new( | 29 | let mut pwm = unwrap!(SequencePwm::new( |
| 30 | p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, | 30 | p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, |
| 31 | )); | 31 | )); |
| 32 | 32 | ||
