aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/dma
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-04-15 21:47:37 +0200
committerDario Nieuwenhuis <[email protected]>2024-04-15 21:52:40 +0200
commit02da66aec8432f71b8f3121a972044191df2d7e8 (patch)
tree7ad749dd02caa40949f2d7892da13e15dc6ef3f9 /embassy-stm32/src/dma
parentd66c054aae616616377c7bcee47f5de8a312d085 (diff)
stm32/dma: add ChannelAndRequest helper.
Diffstat (limited to 'embassy-stm32/src/dma')
-rw-r--r--embassy-stm32/src/dma/mod.rs3
-rw-r--r--embassy-stm32/src/dma/util.rs60
2 files changed, 63 insertions, 0 deletions
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs
index 7e3681469..8766d0a60 100644
--- a/embassy-stm32/src/dma/mod.rs
+++ b/embassy-stm32/src/dma/mod.rs
@@ -16,6 +16,9 @@ mod dmamux;
16#[cfg(dmamux)] 16#[cfg(dmamux)]
17pub use dmamux::*; 17pub use dmamux::*;
18 18
19mod util;
20pub(crate) use util::*;
21
19pub(crate) mod ringbuffer; 22pub(crate) mod ringbuffer;
20pub mod word; 23pub mod word;
21 24
diff --git a/embassy-stm32/src/dma/util.rs b/embassy-stm32/src/dma/util.rs
new file mode 100644
index 000000000..962ea2501
--- /dev/null
+++ b/embassy-stm32/src/dma/util.rs
@@ -0,0 +1,60 @@
1use embassy_hal_internal::PeripheralRef;
2
3use super::word::Word;
4use super::{AnyChannel, Request, Transfer, TransferOptions};
5
6/// Convenience wrapper, contains a channel and a request number.
7///
8/// Commonly used in peripheral drivers that own DMA channels.
9pub(crate) struct ChannelAndRequest<'d> {
10 pub channel: PeripheralRef<'d, AnyChannel>,
11 pub request: Request,
12}
13
14impl<'d> ChannelAndRequest<'d> {
15 pub unsafe fn read<'a, W: Word>(
16 &'a mut self,
17 peri_addr: *mut W,
18 buf: &'a mut [W],
19 options: TransferOptions,
20 ) -> Transfer<'a> {
21 Transfer::new_read(&mut self.channel, self.request, peri_addr, buf, options)
22 }
23
24 pub unsafe fn read_raw<'a, W: Word>(
25 &'a mut self,
26 peri_addr: *mut W,
27 buf: *mut [W],
28 options: TransferOptions,
29 ) -> Transfer<'a> {
30 Transfer::new_read_raw(&mut self.channel, self.request, peri_addr, buf, options)
31 }
32
33 pub unsafe fn write<'a, W: Word>(
34 &'a mut self,
35 buf: &'a [W],
36 peri_addr: *mut W,
37 options: TransferOptions,
38 ) -> Transfer<'a> {
39 Transfer::new_write(&mut self.channel, self.request, buf, peri_addr, options)
40 }
41
42 pub unsafe fn write_raw<'a, W: Word>(
43 &'a mut self,
44 buf: *const [W],
45 peri_addr: *mut W,
46 options: TransferOptions,
47 ) -> Transfer<'a> {
48 Transfer::new_write_raw(&mut self.channel, self.request, buf, peri_addr, options)
49 }
50
51 pub unsafe fn write_repeated<'a, W: Word>(
52 &'a mut self,
53 repeated: &'a W,
54 count: usize,
55 peri_addr: *mut W,
56 options: TransferOptions,
57 ) -> Transfer<'a> {
58 Transfer::new_write_repeated(&mut self.channel, self.request, repeated, count, peri_addr, options)
59 }
60}