generalize futures

This commit is contained in:
xoviat 2020-12-31 16:11:23 -06:00
parent d52e1b2276
commit 142c01ad01

View File

@ -127,7 +127,10 @@ impl Uarte {
/// `tx_buffer` is marked as static as per `embedded-dma` requirements. /// `tx_buffer` is marked as static as per `embedded-dma` requirements.
/// It it safe to use a buffer with a non static lifetime if memory is not /// It it safe to use a buffer with a non static lifetime if memory is not
/// reused until the future has finished. /// reused until the future has finished.
pub fn send<'a, B>(&'a mut self, tx_buffer: B) -> SendFuture<'a, B> pub fn send<'a, B>(
&'a mut self,
tx_buffer: B,
) -> SendFuture<'a, B, USART1, Stream7<DMA2>, Channel4>
where where
B: WriteBuffer<Word = u8> + 'static, B: WriteBuffer<Word = u8> + 'static,
{ {
@ -165,7 +168,7 @@ impl Uarte {
pub fn receive<'a, B>( pub fn receive<'a, B>(
&'a mut self, &'a mut self,
rx_buffer: B, rx_buffer: B,
) -> ReceiveFuture<'a, B, Stream2<DMA2>, Channel4> ) -> ReceiveFuture<'a, B, USART1, Stream2<DMA2>, Channel4>
where where
B: WriteBuffer<Word = u8> + 'static, B: WriteBuffer<Word = u8> + 'static,
{ {
@ -191,19 +194,25 @@ impl Uarte {
} }
/// Future for the [`LowPowerUarte::send()`] method. /// Future for the [`LowPowerUarte::send()`] method.
pub struct SendFuture<'a, B: WriteBuffer<Word = u8> + 'static> { pub struct SendFuture<
uarte: &'a mut Uarte, 'a,
tx_transfer: Option<Transfer<Stream7<DMA2>, Channel4, USART1, MemoryToPeripheral, B>>,
}
impl<'a, B> Drop for SendFuture<'a, B>
where
B: WriteBuffer<Word = u8> + 'static, B: WriteBuffer<Word = u8> + 'static,
{ USART: PeriAddress<MemSize = u8>,
fn drop(self: &mut Self) {} STREAM: Stream,
CHANNEL,
> {
uarte: &'a mut Uarte,
tx_transfer: Option<Transfer<STREAM, CHANNEL, USART, MemoryToPeripheral, B>>,
} }
impl<'a, B> Future for SendFuture<'a, B> // impl<'a, B> Drop for SendFuture<'a, B>
// where
// B: WriteBuffer<Word = u8> + 'static,
// {
// fn drop(self: &mut Self) {}
// }
impl<'a, B> Future for SendFuture<'a, B, USART1, Stream7<DMA2>, Channel4>
where where
B: WriteBuffer<Word = u8> + 'static, B: WriteBuffer<Word = u8> + 'static,
{ {
@ -230,9 +239,15 @@ where
} }
/// Future for the [`Uarte::receive()`] method. /// Future for the [`Uarte::receive()`] method.
pub struct ReceiveFuture<'a, B: WriteBuffer<Word = u8> + 'static, STREAM: Stream, CHANNEL> { pub struct ReceiveFuture<
'a,
B: WriteBuffer<Word = u8> + 'static,
USART: PeriAddress<MemSize = u8>,
STREAM: Stream,
CHANNEL,
> {
uarte: &'a mut Uarte, uarte: &'a mut Uarte,
rx_transfer: Option<Transfer<STREAM, CHANNEL, USART1, PeripheralToMemory, B>>, rx_transfer: Option<Transfer<STREAM, CHANNEL, USART, PeripheralToMemory, B>>,
} }
// pub struct ReceiveFuture<'a, B: WriteBuffer<Word = u8> + 'static, DMA, STREAM, CHANNEL> { // pub struct ReceiveFuture<'a, B: WriteBuffer<Word = u8> + 'static, DMA, STREAM, CHANNEL> {
@ -247,7 +262,7 @@ pub struct ReceiveFuture<'a, B: WriteBuffer<Word = u8> + 'static, STREAM: Stream
// fn drop(self: &mut Self) {} // fn drop(self: &mut Self) {}
// } // }
impl<'a, B> Future for ReceiveFuture<'a, B, Stream2<DMA2>, Channel4> impl<'a, B> Future for ReceiveFuture<'a, B, USART1, Stream2<DMA2>, Channel4>
where where
B: WriteBuffer<Word = u8> + 'static + Unpin, B: WriteBuffer<Word = u8> + 'static + Unpin,
{ {