Skip to content
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

Start adding embedded-dma support #75

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ license = "MIT OR Apache-2.0"
[dependencies]
generic-array = "0.13"
cortex-m = { version = "0.6.0", optional = true }
embedded-dma = "0.1.1"

[dependencies.defmt]
git = "https://github.com/knurling-rs/defmt"
branch = "main"
optional = true

[features]
thumbv6 = ["cortex-m"]
Expand All @@ -25,6 +31,15 @@ thumbv6 = ["cortex-m"]
atomic = []
std = []

enable-defmt = ["defmt"]

# do NOT modify these features
defmt-default = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []

[package.metadata.docs.rs]
all-features = true
29 changes: 29 additions & 0 deletions core/src/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,32 @@ where
self
}
}

use embedded_dma::{
WriteBuffer,
ReadBuffer,
};

unsafe impl<'a, N> WriteBuffer for FrameGrantW<'a, N>
where
N: ArrayLength<u8>,
{
type Word = u8;
unsafe fn write_buffer(&mut self) -> (*mut Self::Word, usize) {
let buf = self.deref_mut();
let len = buf.len();
(buf.as_mut_ptr(), len)
}
}

unsafe impl<'a, N> ReadBuffer for FrameGrantW<'a, N>
where
N: ArrayLength<u8>,
{
type Word = u8;
unsafe fn read_buffer(&self) -> (*const Self::Word, usize) {
let buf = self.deref();
let len = buf.len();
(buf.as_ptr(), len)
}
}
4 changes: 3 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ pub use generic_array::ArrayLength;
/// Result type used by the `BBQueue` interfaces
pub type Result<T> = CoreResult<T, Error>;

use defmt::Format;

/// Error type used by the `BBQueue` interfaces
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[derive(Debug, PartialEq, Eq, Copy, Clone, Format)]
pub enum Error {
/// The buffer does not contain sufficient size for the requested action
InsufficientSize,
Expand Down