Skip to content

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

Closed
wants to merge 5 commits into from
Closed
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
32 changes: 32 additions & 0 deletions src/dma.rs
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;
Copy link

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


/// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation could be more helpful. What's the difference between Item and Payload?

type Payload;

/// Get buffer
fn deref(&self) -> &Self::Item;
Copy link
Contributor

Choose a reason for hiding this comment

The 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>;
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@
#![deny(missing_docs)]
#![deny(warnings)]
#![feature(never_type)]
#![feature(unsize)]
#![no_std]

#[macro_use]
Expand All @@ -617,6 +618,7 @@ pub mod digital;
pub mod prelude;
pub mod serial;
pub mod spi;
pub mod dma;

/// Input capture
///
Expand Down
43 changes: 42 additions & 1 deletion src/spi.rs
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)
///
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling: receive_dma

where
Buffer: Unsize<[Word]>;
}

/// DMA Write mode
Copy link
Contributor

Choose a reason for hiding this comment

The 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 {
Expand Down