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 22, 2023
1 parent 644653b commit de6c859
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 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
20 changes: 10 additions & 10 deletions cfail/ui/not-send.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: `*const ()` cannot be sent between threads safely
--> $DIR/not-send.rs:19:15
--> ui/not-send.rs:19:15
|
19 | is_send::<Consumer<NotSend, 4>>();
| ^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
Expand All @@ -8,7 +8,7 @@ error[E0277]: `*const ()` cannot be sent between threads safely
= note: required because it appears within the type `PhantomData<*const ()>`
= note: required for `Consumer<'_, PhantomData<*const ()>, 4>` to implement `Send`
note: required by a bound in `is_send`
--> $DIR/not-send.rs:14:8
--> ui/not-send.rs:14:8
|
12 | fn is_send<T>()
| ------- required by a bound in this
Expand All @@ -17,7 +17,7 @@ note: required by a bound in `is_send`
| ^^^^ required by this bound in `is_send`

error[E0277]: `*const ()` cannot be sent between threads safely
--> $DIR/not-send.rs:20:15
--> ui/not-send.rs:20:15
|
20 | is_send::<Producer<NotSend, 4>>();
| ^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
Expand All @@ -26,7 +26,7 @@ error[E0277]: `*const ()` cannot be sent between threads safely
= note: required because it appears within the type `PhantomData<*const ()>`
= note: required for `Producer<'_, PhantomData<*const ()>, 4>` to implement `Send`
note: required by a bound in `is_send`
--> $DIR/not-send.rs:14:8
--> ui/not-send.rs:14:8
|
12 | fn is_send<T>()
| ------- required by a bound in this
Expand All @@ -35,7 +35,7 @@ note: required by a bound in `is_send`
| ^^^^ required by this bound in `is_send`

error[E0277]: `*const ()` cannot be sent between threads safely
--> $DIR/not-send.rs:21:15
--> ui/not-send.rs:21:15
|
21 | is_send::<Queue<NotSend, 4>>();
| ^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
Expand All @@ -48,7 +48,7 @@ error[E0277]: `*const ()` cannot be sent between threads safely
= note: required because it appears within the type `[UnsafeCell<MaybeUninit<PhantomData<*const ()>>>; 4]`
= note: required because it appears within the type `Queue<PhantomData<*const ()>, 4>`
note: required by a bound in `is_send`
--> $DIR/not-send.rs:14:8
--> ui/not-send.rs:14:8
|
12 | fn is_send<T>()
| ------- required by a bound in this
Expand All @@ -57,7 +57,7 @@ note: required by a bound in `is_send`
| ^^^^ required by this bound in `is_send`

error[E0277]: `*const ()` cannot be sent between threads safely
--> $DIR/not-send.rs:22:15
--> ui/not-send.rs:22:15
|
22 | is_send::<Vec<NotSend, 4>>();
| ^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
Expand All @@ -69,7 +69,7 @@ error[E0277]: `*const ()` cannot be sent between threads safely
= note: required because it appears within the type `[MaybeUninit<PhantomData<*const ()>>; 4]`
= note: required because it appears within the type `heapless::Vec<PhantomData<*const ()>, 4>`
note: required by a bound in `is_send`
--> $DIR/not-send.rs:14:8
--> ui/not-send.rs:14:8
|
12 | fn is_send<T>()
| ------- required by a bound in this
Expand All @@ -78,7 +78,7 @@ note: required by a bound in `is_send`
| ^^^^ required by this bound in `is_send`

error[E0277]: `*const ()` cannot be sent between threads safely
--> $DIR/not-send.rs:23:15
--> ui/not-send.rs:23:15
|
23 | is_send::<HistoryBuffer<NotSend, 4>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
Expand All @@ -90,7 +90,7 @@ error[E0277]: `*const ()` cannot be sent between threads safely
= note: required because it appears within the type `[MaybeUninit<PhantomData<*const ()>>; 4]`
= note: required because it appears within the type `HistoryBuffer<PhantomData<*const ()>, 4>`
note: required by a bound in `is_send`
--> $DIR/not-send.rs:14:8
--> ui/not-send.rs:14:8
|
12 | fn is_send<T>()
| ------- required by a bound in this
Expand Down
26 changes: 26 additions & 0 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,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 de6c859

Please sign in to comment.