Skip to main content

ch32_hal/dma/
util.rs

1use super::word::Word;
2use super::{AnyChannel, Request, Transfer, TransferOptions};
3use crate::Peri;
4
5/// Convenience wrapper, contains a channel and a request number.
6///
7/// Commonly used in peripheral drivers that own DMA channels.
8pub(crate) struct ChannelAndRequest<'d> {
9    pub channel: Peri<'d, AnyChannel>,
10    pub request: Request,
11}
12
13impl<'d> ChannelAndRequest<'d> {
14    pub unsafe fn read<'a, W: Word>(
15        &'a mut self,
16        peri_addr: *mut W,
17        buf: &'a mut [W],
18        options: TransferOptions,
19    ) -> Transfer<'a> {
20        Transfer::new_read(self.channel.reborrow(), self.request, peri_addr, buf, options)
21    }
22
23    pub unsafe fn read_raw<'a, W: Word>(
24        &'a mut self,
25        peri_addr: *mut W,
26        buf: *mut [W],
27        options: TransferOptions,
28    ) -> Transfer<'a> {
29        Transfer::new_read_raw(self.channel.reborrow(), self.request, peri_addr, buf, options)
30    }
31
32    pub unsafe fn write<'a, W: Word>(
33        &'a mut self,
34        buf: &'a [W],
35        peri_addr: *mut W,
36        options: TransferOptions,
37    ) -> Transfer<'a> {
38        Transfer::new_write(self.channel.reborrow(), self.request, buf, peri_addr, options)
39    }
40
41    pub unsafe fn write_raw<'a, W: Word>(
42        &'a mut self,
43        buf: *const [W],
44        peri_addr: *mut W,
45        options: TransferOptions,
46    ) -> Transfer<'a> {
47        Transfer::new_write_raw(self.channel.reborrow(), self.request, buf, peri_addr, options)
48    }
49
50    pub unsafe fn write_repeated<'a, W: Word>(
51        &'a mut self,
52        repeated: &'a W,
53        count: usize,
54        peri_addr: *mut W,
55        options: TransferOptions,
56    ) -> Transfer<'a> {
57        Transfer::new_write_repeated(self.channel.reborrow(), self.request, repeated, count, peri_addr, options)
58    }
59}