-
Notifications
You must be signed in to change notification settings - Fork 234
WIP: Attempt at DMA traits #26
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
Changes from all commits
196e070
0fdac0d
2b4784d
b08dae2
bdb505d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//! DMA Interface | ||
|
||
/// Static alias for DMA | ||
pub type Static<T> = &'static mut T; | ||
|
||
/// DMA Errors | ||
#[derive(Debug)] | ||
pub enum Error { | ||
/// Previous data got overwritten before it could be read because it was | ||
/// not accessed in a timely fashion | ||
Overrun, | ||
/// Transfer error | ||
Transfer, | ||
} | ||
|
||
|
||
/// DMA Transfer future | ||
pub trait Transfer { | ||
/// Return type | ||
type Item; | ||
/// Return type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation could be more helpful. What's the difference between |
||
type Payload; | ||
|
||
/// Get buffer | ||
fn deref(&self) -> &Self::Item; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to allow access to the data while the transfer is still ongoing? |
||
|
||
/// Check completion | ||
fn is_done(&self) -> Result<bool, Error>; | ||
|
||
/// Block | ||
fn wait(self) -> Result<(Self::Item, Self::Payload), Error>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
//! Serial Peripheral Interface | ||
|
||
use core::marker::Unsize; | ||
use nb; | ||
use dma; | ||
|
||
/// Full duplex (master mode) | ||
/// | ||
|
@@ -33,6 +34,46 @@ pub trait FullDuplex<Word> { | |
fn send(&mut self, word: Word) -> nb::Result<(), Self::Error>; | ||
} | ||
|
||
/// DMA Write mode | ||
pub trait DmaWrite<B, Word> | ||
where | ||
Self: Sized, | ||
B: Unsize<[Word]> + 'static | ||
{ | ||
/// Sends `words` to the slave. | ||
type Transfer: dma::Transfer<Item = &'static mut B, Payload = Self>; | ||
|
||
/// Sends `words` to the slave. | ||
fn send_dma(self, words: &'static mut B) -> Self::Transfer; | ||
} | ||
|
||
|
||
/// DMA Write mode | ||
pub trait DmaRead<Word> { | ||
/// Return type | ||
type Transfer: dma::Transfer + ?Sized; | ||
|
||
/// Recieve `words` from the slave. | ||
fn recieve_dma<Buffer, Payload>(self, words: &'static mut Buffer) -> Self::Transfer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spelling: |
||
where | ||
Buffer: Unsize<[Word]>; | ||
} | ||
|
||
/// DMA Write mode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation needs to be updated |
||
pub trait DmaReadWrite<Word> { | ||
/// Return type | ||
type Transfer: dma::Transfer + ?Sized; | ||
|
||
/// Send and recieve from the slave. | ||
fn transfer_dma<Buffer, Payload>( | ||
self, | ||
tx_words: &'static mut Buffer, | ||
rx_words: &'static mut Buffer, | ||
) -> Self::Transfer | ||
where | ||
Buffer: Unsize<[Word]>; | ||
} | ||
|
||
/// Clock polarity | ||
#[derive(Clone, Copy, PartialEq)] | ||
pub enum Polarity { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this alias being used anywhere