fix borrowing errors

This commit is contained in:
xoviat 2020-12-30 11:05:52 -06:00
parent 41db867d9a
commit 60c7d112b1

View File

@ -132,10 +132,7 @@ impl Uarte {
{ {
let tx_stream = self.tx_stream.take().unwrap(); let tx_stream = self.tx_stream.take().unwrap();
let usart = self.usart.take().unwrap(); let usart = self.usart.take().unwrap();
let mut tx_transfer = Transfer::init(
SendFuture {
uarte: self,
tx_transfer: Transfer::init(
tx_stream, tx_stream,
usart, usart,
tx_buffer, tx_buffer,
@ -144,7 +141,13 @@ impl Uarte {
.transfer_complete_interrupt(true) .transfer_complete_interrupt(true)
.memory_increment(true) .memory_increment(true)
.double_buffer(false), .double_buffer(false),
), );
SendFuture {
uarte: self,
tx_transfer: Some(tx_transfer),
// tx_stream: Some(tx_stream),
// usart: Some(usart),
} }
} }
@ -164,10 +167,7 @@ impl Uarte {
{ {
let rx_stream = self.rx_stream.take().unwrap(); let rx_stream = self.rx_stream.take().unwrap();
let usart = self.usart.take().unwrap(); let usart = self.usart.take().unwrap();
let mut rx_transfer = Transfer::init(
ReceiveFuture {
uarte: self,
rx_transfer: Transfer::init(
rx_stream, rx_stream,
usart, usart,
rx_buffer, rx_buffer,
@ -177,15 +177,19 @@ impl Uarte {
.half_transfer_interrupt(true) .half_transfer_interrupt(true)
.memory_increment(true) .memory_increment(true)
.double_buffer(false), .double_buffer(false),
), );
ReceiveFuture {
uarte: self,
rx_transfer: Some(rx_transfer),
} }
} }
} }
/// Future for the [`LowPowerUarte::send()`] method. /// Future for the [`LowPowerUarte::send()`] method.
pub struct SendFuture<'a, B: WriteBuffer<Word = u8> + 'static> { pub struct SendFuture<'a, B: WriteBuffer<Word = u8> + 'static> {
uarte: &'a Uarte, uarte: &'a mut Uarte,
tx_transfer: Transfer<Stream7<DMA2>, Channel4, USART1, MemoryToPeripheral, B>, tx_transfer: Option<Transfer<Stream7<DMA2>, Channel4, USART1, MemoryToPeripheral, B>>,
} }
impl<'a, B> Drop for SendFuture<'a, B> impl<'a, B> Drop for SendFuture<'a, B>
@ -202,12 +206,23 @@ where
type Output = (); type Output = ();
fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
if self.tx_transfer.is_done() { let Self { uarte, tx_transfer } = unsafe { self.get_unchecked_mut() };
if true {
// tx_transfer.unwrap().is_done() {
let (tx_stream, usart, buf, _) = tx_transfer.take().unwrap().free();
uarte.tx_stream.replace(tx_stream);
uarte.usart.replace(usart);
Poll::Ready(()) Poll::Ready(())
} else { } else {
// self.0.as_mut().tx_transfer.start(|usart| {});
waker_interrupt!(DMA2_STREAM7, cx.waker().clone()); waker_interrupt!(DMA2_STREAM7, cx.waker().clone());
// tx_transfer.take().start(|usart| {});
let mut taken = tx_transfer.take().unwrap();
taken.start(|usart| {});
tx_transfer.replace(taken);
Poll::Pending Poll::Pending
} }
} }
@ -215,8 +230,8 @@ where
/// Future for the [`Uarte::receive()`] method. /// Future for the [`Uarte::receive()`] method.
pub struct ReceiveFuture<'a, B: WriteBuffer<Word = u8> + 'static> { pub struct ReceiveFuture<'a, B: WriteBuffer<Word = u8> + 'static> {
uarte: &'a Uarte, uarte: &'a mut Uarte,
rx_transfer: Transfer<Stream2<DMA2>, Channel4, USART1, PeripheralToMemory, B>, rx_transfer: Option<Transfer<Stream2<DMA2>, Channel4, USART1, PeripheralToMemory, B>>,
} }
impl<'a, B> Drop for ReceiveFuture<'a, B> impl<'a, B> Drop for ReceiveFuture<'a, B>
@ -228,28 +243,30 @@ where
impl<'a, B> Future for ReceiveFuture<'a, B> impl<'a, B> Future for ReceiveFuture<'a, B>
where where
B: WriteBuffer<Word = u8> + 'static, B: WriteBuffer<Word = u8> + 'static + Unpin,
{ {
type Output = B; type Output = ();
fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<B> { fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
// if !self.transfer.is_none() && self.transfer.unwrap().is_done() { let Self { uarte, rx_transfer } = unsafe { self.get_unchecked_mut() };
// Poll::Ready(self.buf.take());
// } else {
// self.transfer = Some(&mut Transfer::init(
// StreamsTuple::new(self.uarte.dma).2,
// self.uarte.usart,
// self.buf,
// None,
// DmaConfig::default()
// .transfer_complete_interrupt(true)
// .half_transfer_interrupt(true)
// .memory_increment(true)
// .double_buffer(false),
// ));
if true {
// self.rx_transfer.unwrap().is_done() {
let (rx_stream, usart, buf, _) = rx_transfer.take().unwrap().free();
uarte.rx_stream.replace(rx_stream);
uarte.usart.replace(usart);
// Poll::Ready((buf))
Poll::Ready(())
} else {
waker_interrupt!(DMA2_STREAM2, cx.waker().clone()); waker_interrupt!(DMA2_STREAM2, cx.waker().clone());
let mut taken = rx_transfer.take().unwrap();
taken.start(|usart| {});
rx_transfer.replace(taken);
Poll::Pending Poll::Pending
// } }
} }
} }