Skip to content

Commit de6c859

Browse files
committed
Add embedded_dma feature
1 parent 644653b commit de6c859

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515
- Implemented `retain` for `IndexMap` and `IndexSet`.
1616
- Recover `StableDeref` trait for `pool::object::Object` and `pool::boxed::Box`.
1717
- Add polyfills for ESP32S2
18+
- Add `embedded_dma` feature to one can send `Vec`, `pool::object::Object` and `pool::boxed::Box` to DMA as read/write buffers [#362].
1819

1920
### Changed
2021

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ __trybuild = []
2424
mpmc_large = []
2525
# This flag has no version guarantee, the `defmt` dependency can be updated in a patch release
2626
defmt-impl = ["defmt"]
27+
embedded-dma = ["dep:embedded-dma"]
2728

2829
[target.thumbv6m-none-eabi.dependencies]
2930
atomic-polyfill = { version = "1.0.1", optional = true }
@@ -59,6 +60,10 @@ default-features = false
5960
version = "0.1"
6061
optional = true
6162

63+
[dependencies.embedded-dma]
64+
version = "0.2"
65+
optional = true
66+
6267
[dev-dependencies.ufmt]
6368
version = "0.1"
6469

cfail/ui/not-send.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: `*const ()` cannot be sent between threads safely
2-
--> $DIR/not-send.rs:19:15
2+
--> ui/not-send.rs:19:15
33
|
44
19 | is_send::<Consumer<NotSend, 4>>();
55
| ^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
@@ -8,7 +8,7 @@ error[E0277]: `*const ()` cannot be sent between threads safely
88
= note: required because it appears within the type `PhantomData<*const ()>`
99
= note: required for `Consumer<'_, PhantomData<*const ()>, 4>` to implement `Send`
1010
note: required by a bound in `is_send`
11-
--> $DIR/not-send.rs:14:8
11+
--> ui/not-send.rs:14:8
1212
|
1313
12 | fn is_send<T>()
1414
| ------- required by a bound in this
@@ -17,7 +17,7 @@ note: required by a bound in `is_send`
1717
| ^^^^ required by this bound in `is_send`
1818

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

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

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

8080
error[E0277]: `*const ()` cannot be sent between threads safely
81-
--> $DIR/not-send.rs:23:15
81+
--> ui/not-send.rs:23:15
8282
|
8383
23 | is_send::<HistoryBuffer<NotSend, 4>>();
8484
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
@@ -90,7 +90,7 @@ error[E0277]: `*const ()` cannot be sent between threads safely
9090
= note: required because it appears within the type `[MaybeUninit<PhantomData<*const ()>>; 4]`
9191
= note: required because it appears within the type `HistoryBuffer<PhantomData<*const ()>, 4>`
9292
note: required by a bound in `is_send`
93-
--> $DIR/not-send.rs:14:8
93+
--> ui/not-send.rs:14:8
9494
|
9595
12 | fn is_send<T>()
9696
| ------- required by a bound in this

src/vec.rs

+26
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,32 @@ where
11811181
}
11821182
}
11831183

1184+
#[cfg(feature = "embedded-dma")]
1185+
unsafe impl<T, const N: usize> embedded_dma::ReadTarget for Vec<T, N>
1186+
where
1187+
T: embedded_dma::ReadTarget,
1188+
{
1189+
type Word = T::Word;
1190+
1191+
// Replace default implementation to return self.len() as buffer size
1192+
fn as_read_buffer(&self) -> (*const Self::Word, usize) {
1193+
(self.as_ptr() as *const T::Word, self.len)
1194+
}
1195+
}
1196+
1197+
#[cfg(feature = "embedded-dma")]
1198+
unsafe impl<T, const N: usize> embedded_dma::WriteTarget for Vec<T, N>
1199+
where
1200+
T: embedded_dma::WriteTarget,
1201+
{
1202+
type Word = T::Word;
1203+
1204+
// Replace default implementation to return N as buffer size
1205+
fn as_write_buffer(&mut self) -> (*mut Self::Word, usize) {
1206+
(self.as_mut_ptr() as *mut T::Word, N)
1207+
}
1208+
}
1209+
11841210
#[cfg(test)]
11851211
mod tests {
11861212
use crate::Vec;

0 commit comments

Comments
 (0)