Skip to content

Add embedded_dma feature #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added `Deque::make_contiguous`.
- Added `VecView`, the `!Sized` version of `Vec`.
- Added pool implementations for 64-bit architectures.
- 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 @@ -48,6 +48,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_pointer_width = "32", target_pointer_width = "64"))'.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 @@ -2076,6 +2076,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 core::fmt::Write;
Expand Down
Loading