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 Mar 16, 2023
1 parent 644653b commit e73b851
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Implemented `retain` for `IndexMap` and `IndexSet`.
- Recover `StableDeref` trait for `pool::object::Object` and `pool::boxed::Box`.
- Add polyfills for ESP32S2
- 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
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ __trybuild = []
mpmc_large = []
# This flag has no version guarantee, the `defmt` dependency can be updated in a patch release
defmt-impl = ["defmt"]
embedded-dma = ["dep:embedded-dma"]

[target.thumbv6m-none-eabi.dependencies]
atomic-polyfill = { version = "1.0.1", optional = true }
Expand Down Expand Up @@ -59,6 +60,10 @@ default-features = false
version = "0.1"
optional = true

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

[dev-dependencies.ufmt]
version = "0.1"

Expand Down
24 changes: 24 additions & 0 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,30 @@ 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) {
use ops::Deref;
self.deref().as_read_buffer()
}
}

#[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;

// Use default implementation to return N as buffer size
}

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

0 comments on commit e73b851

Please sign in to comment.