Skip to content

Commit 7d5f2cd

Browse files
Merge pull request #236 from kalkyl/spis-static
Add 'static lifetime bounds to SPIS DMA buffers
2 parents 22910ee + 6a36313 commit 7d5f2cd

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

nrf-hal-common/src/spis.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ where
328328
#[allow(unused_mut)]
329329
pub fn transfer<W, B>(mut self, mut buffer: B) -> Result<Transfer<T, B>, (Error, Spis<T>, B)>
330330
where
331-
B: WriteBuffer<Word = W>,
331+
B: WriteBuffer<Word = W> + 'static,
332332
{
333333
let (ptr, len) = unsafe { buffer.write_buffer() };
334334
let maxcnt = len * core::mem::size_of::<W>();
@@ -371,8 +371,8 @@ where
371371
mut rx_buffer: RxB,
372372
) -> Result<TransferSplit<T, TxB, RxB>, (Error, Spis<T>, TxB, RxB)>
373373
where
374-
TxB: ReadBuffer<Word = TxW>,
375-
RxB: WriteBuffer<Word = RxW>,
374+
TxB: ReadBuffer<Word = TxW> + 'static,
375+
RxB: WriteBuffer<Word = RxW> + 'static,
376376
{
377377
let (rx_ptr, rx_len) = unsafe { rx_buffer.write_buffer() };
378378
let (tx_ptr, tx_len) = unsafe { tx_buffer.read_buffer() };
@@ -420,6 +420,7 @@ where
420420

421421
/// A DMA transfer
422422
pub struct Transfer<T: Instance, B> {
423+
// FIXME: Always `Some`, only using `Option` here to allow moving fields out of `inner`.
423424
inner: Option<Inner<T, B>>,
424425
}
425426

@@ -463,6 +464,7 @@ impl<T: Instance, B> Drop for Transfer<T, B> {
463464
}
464465
/// A full duplex DMA transfer
465466
pub struct TransferSplit<T: Instance, TxB, RxB> {
467+
// FIXME: Always `Some`, only using `Option` here to allow moving fields out of `inner`.
466468
inner: Option<InnerSplit<T, TxB, RxB>>,
467469
}
468470

@@ -490,15 +492,15 @@ impl<T: Instance, TxB, RxB> TransferSplit<T, TxB, RxB> {
490492
pub fn is_done(&mut self) -> bool {
491493
let inner = self
492494
.inner
493-
.take()
495+
.as_mut()
494496
.unwrap_or_else(|| unsafe { core::hint::unreachable_unchecked() });
495497
inner.spis.is_done()
496498
}
497499
}
498500

499501
impl<T: Instance, TxB, RxB> Drop for TransferSplit<T, TxB, RxB> {
500502
fn drop(&mut self) {
501-
if let Some(inner) = self.inner.as_mut() {
503+
if let Some(inner) = self.inner.take() {
502504
compiler_fence(Ordering::SeqCst);
503505
while !inner.spis.is_done() {}
504506
inner.spis.disable();

0 commit comments

Comments
 (0)