aboutsummaryrefslogtreecommitdiff
path: root/embassy-mcxa/src
diff options
context:
space:
mode:
authorJames Munns <[email protected]>2025-12-09 14:41:19 +0100
committerJames Munns <[email protected]>2025-12-09 14:41:19 +0100
commit4386b39e2516c453966d894b4fd265fae9d82c1a (patch)
tree455eec4232f060ee1906b479cc3ba3567f02c773 /embassy-mcxa/src
parentf7d5abfe946e71d426c9d0e96231e48faf27f6cd (diff)
Enforce scatter gather API statically
Diffstat (limited to 'embassy-mcxa/src')
-rw-r--r--embassy-mcxa/src/dma.rs19
1 files changed, 8 insertions, 11 deletions
diff --git a/embassy-mcxa/src/dma.rs b/embassy-mcxa/src/dma.rs
index d076949b8..1f604a340 100644
--- a/embassy-mcxa/src/dma.rs
+++ b/embassy-mcxa/src/dma.rs
@@ -2236,9 +2236,9 @@ pub struct ScatterGatherBuilder<'a, W: Word> {
2236 _plt: core::marker::PhantomData<&'a mut W>, 2236 _plt: core::marker::PhantomData<&'a mut W>,
2237} 2237}
2238 2238
2239impl<W: Word> ScatterGatherBuilder<'_, W> { 2239impl<'a, W: Word> ScatterGatherBuilder<'a, W> {
2240 /// Create a new scatter-gather builder. 2240 /// Create a new scatter-gather builder.
2241 pub fn new() -> ScatterGatherBuilder<'static, W> { 2241 pub fn new() -> Self {
2242 ScatterGatherBuilder { 2242 ScatterGatherBuilder {
2243 tcds: [Tcd::default(); MAX_SCATTER_GATHER_TCDS], 2243 tcds: [Tcd::default(); MAX_SCATTER_GATHER_TCDS],
2244 count: 0, 2244 count: 0,
@@ -2257,7 +2257,7 @@ impl<W: Word> ScatterGatherBuilder<'_, W> {
2257 /// # Panics 2257 /// # Panics
2258 /// 2258 ///
2259 /// Panics if the maximum number of segments (16) is exceeded. 2259 /// Panics if the maximum number of segments (16) is exceeded.
2260 pub fn add_transfer<'a>(mut self, src: &'a [W], dst: &'a mut [W]) -> &'a mut Self { 2260 pub fn add_transfer<'b: 'a>(&mut self, src: &'b [W], dst: &'b mut [W]) -> &mut Self {
2261 assert!(self.count < MAX_SCATTER_GATHER_TCDS, "Too many scatter-gather segments"); 2261 assert!(self.count < MAX_SCATTER_GATHER_TCDS, "Too many scatter-gather segments");
2262 assert!(!src.is_empty()); 2262 assert!(!src.is_empty());
2263 assert!(dst.len() >= src.len()); 2263 assert!(dst.len() >= src.len());
@@ -2300,12 +2300,7 @@ impl<W: Word> ScatterGatherBuilder<'_, W> {
2300 /// # Returns 2300 /// # Returns
2301 /// 2301 ///
2302 /// A `Transfer` future that completes when the entire chain has executed. 2302 /// A `Transfer` future that completes when the entire chain has executed.
2303 /// 2303 pub fn build<C: Channel>(&mut self, channel: &DmaChannel<C>) -> Result<Transfer<'a>, Error> {
2304 /// # Safety
2305 ///
2306 /// All source and destination buffers passed to `add_transfer()` must
2307 /// remain valid for the duration of the transfer.
2308 pub unsafe fn build<C: Channel>(&mut self, channel: &DmaChannel<C>) -> Result<Transfer<'_>, Error> {
2309 if self.count == 0 { 2304 if self.count == 0 {
2310 return Err(Error::Configuration); 2305 return Err(Error::Configuration);
2311 } 2306 }
@@ -2360,7 +2355,9 @@ impl<W: Word> ScatterGatherBuilder<'_, W> {
2360 cortex_m::asm::dsb(); 2355 cortex_m::asm::dsb();
2361 2356
2362 // Load first TCD into hardware 2357 // Load first TCD into hardware
2363 channel.load_tcd(&self.tcds[0]); 2358 unsafe {
2359 channel.load_tcd(&self.tcds[0]);
2360 }
2364 2361
2365 // Memory barrier before setting START 2362 // Memory barrier before setting START
2366 cortex_m::asm::dsb(); 2363 cortex_m::asm::dsb();
@@ -2377,7 +2374,7 @@ impl<W: Word> ScatterGatherBuilder<'_, W> {
2377 } 2374 }
2378} 2375}
2379 2376
2380impl<W: Word> Default for ScatterGatherBuilder<W> { 2377impl<W: Word> Default for ScatterGatherBuilder<'_, W> {
2381 fn default() -> Self { 2378 fn default() -> Self {
2382 Self::new() 2379 Self::new()
2383 } 2380 }