Skip to content

Commit

Permalink
Add embedded_dma feature
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty19106 committed Feb 15, 2024
1 parent c593fa5 commit cc0f541
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added `Extend` impls for `Deque`.
- Added `Deque::make_contiguous`.
- Added `VecView`, the `!Sized` version of `Vec`.
- Add `embedded_dma` feature to one can send `Vec`, `pool::object::Object` and `pool::boxed::Box` to DMA as read/write buffers [#362].

### Changed

Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ serde = { version = "1", optional = true, default-features = false }
ufmt-write = { version = "0.1", optional = true }
defmt = { version = ">=0.2.0,<0.4", optional = true }

[dependencies.embedded-dma]
version = "0.2"
optional = true

# for the pool module
[target.'cfg(any(target_arch = "arm", target_arch = "x86"))'.dependencies]
stable_deref_trait = { version = "1", default-features = false }
Expand Down
26 changes: 26 additions & 0 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2078,6 +2078,32 @@ where
}
}

#[cfg(feature = "embedded-dma")]
unsafe impl<T, const N: usize> embedded_dma::ReadTarget for Vec<T, N>
where
T: embedded_dma::ReadTarget,
{
type Word = T::Word;

// Replace default implementation to return self.len() as buffer size
fn as_read_buffer(&self) -> (*const Self::Word, usize) {
(self.as_ptr() as *const T::Word, self.len)
}
}

#[cfg(feature = "embedded-dma")]
unsafe impl<T, const N: usize> embedded_dma::WriteTarget for Vec<T, N>
where
T: embedded_dma::WriteTarget,
{
type Word = T::Word;

// Replace default implementation to return N as buffer size
fn as_write_buffer(&mut self) -> (*mut Self::Word, usize) {
(self.as_mut_ptr() as *mut T::Word, N)
}
}

#[cfg(test)]
mod tests {
use crate::Vec;
Expand Down

0 comments on commit cc0f541

Please sign in to comment.