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

aliases for serial tx/rx #59

Merged
merged 2 commits into from
Jun 3, 2019
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- Added type aliases `Tx1` for `Tx<USART1>`, `RxDma1` for `RxDma<USART1, dma1::C5>`, etc.

## [v0.3.0] - 2019-04-27

### Added
Expand Down
10 changes: 5 additions & 5 deletions src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ macro_rules! dma {
}

/// Returns `true` if there's a transfer in progress
fn in_progress(&self) -> bool {
pub fn in_progress(&self) -> bool {
self.isr().$tcifX().bit_is_clear()
}
}
Expand Down Expand Up @@ -449,20 +449,20 @@ dma! {
/// DMA Receiver
pub struct RxDma<PAYLOAD, RXCH> {
pub(crate) _payload: PhantomData<PAYLOAD>,
pub(crate) channel: RXCH,
pub channel: RXCH,
}

/// DMA Transmitter
pub struct TxDma<PAYLOAD, TXCH> {
pub(crate) _payload: PhantomData<PAYLOAD>,
pub(crate) channel: TXCH,
pub channel: TXCH,
}

/// DMA Receiver/Transmitter
pub struct RxTxDma<PAYLOAD, RXCH, TXCH> {
pub(crate) _payload: PhantomData<PAYLOAD>,
pub(crate) rxchannel: RXCH,
pub(crate) txchannel: TXCH,
pub rxchannel: RXCH,
pub txchannel: TXCH,
}

pub trait Receive {
Expand Down
36 changes: 27 additions & 9 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,28 +351,40 @@ hal! {
),
}

pub type Rx1 = Rx<USART1>;
pub type Tx1 = Tx<USART1>;
pub type Rx2 = Rx<USART2>;
pub type Tx2 = Tx<USART2>;
pub type Rx3 = Rx<USART3>;
pub type Tx3 = Tx<USART3>;

use crate::dma::{Transmit, Receive};

macro_rules! serialdma {
($(
$USARTX:ident: (
$rxdma:ident,
$txdma:ident,
$dmarxch:ty,
$dmatxch:ty,
),
)+) => {
$(
impl Receive for RxDma<$USARTX, $dmarxch> {
pub type $rxdma = RxDma<$USARTX, $dmarxch>;
pub type $txdma = TxDma<$USARTX, $dmatxch>;

impl Receive for $rxdma {
type RxChannel = $dmarxch;
type TransmittedWord = u8;
}

impl Transmit for TxDma<$USARTX, $dmatxch> {
impl Transmit for $txdma {
type TxChannel = $dmatxch;
type ReceivedWord = u8;
}

impl Rx<$USARTX> {
pub fn with_dma(self, channel: $dmarxch) -> RxDma<$USARTX, $dmarxch> {
pub fn with_dma(self, channel: $dmarxch) -> $rxdma {
RxDma {
_payload: PhantomData,
channel,
Expand All @@ -381,15 +393,15 @@ macro_rules! serialdma {
}

impl Tx<$USARTX> {
pub fn with_dma(self, channel: $dmatxch) -> TxDma<$USARTX, $dmatxch> {
pub fn with_dma(self, channel: $dmatxch) -> $txdma {
TxDma {
_payload: PhantomData,
channel,
}
}
}

impl RxDma<$USARTX, $dmarxch> {
impl $rxdma {
pub fn split(mut self) -> (Rx<$USARTX>, $dmarxch) {
self.stop();
let RxDma {_payload, channel} = self;
Expand All @@ -400,7 +412,7 @@ macro_rules! serialdma {
}
}

impl TxDma<$USARTX, $dmatxch> {
impl $txdma {
pub fn split(mut self) -> (Tx<$USARTX>, $dmatxch) {
self.stop();
let TxDma {_payload, channel} = self;
Expand All @@ -411,7 +423,7 @@ macro_rules! serialdma {
}
}

impl<B> crate::dma::CircReadDma<B, u8> for RxDma<$USARTX, $dmarxch> where B: AsMut<[u8]> {
impl<B> crate::dma::CircReadDma<B, u8> for $rxdma where B: AsMut<[u8]> {
fn circ_read(mut self, buffer: &'static mut [B; 2],
) -> CircBuffer<B, $dmarxch>
{
Expand Down Expand Up @@ -441,7 +453,7 @@ macro_rules! serialdma {
}
}

impl<B> crate::dma::ReadDma<B, u8> for RxDma<$USARTX, $dmarxch> where B: AsMut<[u8]> {
impl<B> crate::dma::ReadDma<B, u8> for $rxdma where B: AsMut<[u8]> {
fn read(mut self, buffer: &'static mut B,
) -> Transfer<W, &'static mut B, Self>
{
Expand All @@ -466,7 +478,7 @@ macro_rules! serialdma {
}
}

impl<A, B> crate::dma::WriteDma<A, B, u8> for TxDma<$USARTX, $dmatxch> where A: AsRef<[u8]>, B: Static<A> {
impl<A, B> crate::dma::WriteDma<A, B, u8> for $txdma where A: AsRef<[u8]>, B: Static<A> {
fn write(mut self, buffer: B
) -> Transfer<R, B, Self>
{
Expand Down Expand Up @@ -500,14 +512,20 @@ macro_rules! serialdma {

serialdma! {
USART1: (
RxDma1,
TxDma1,
dma1::C5,
dma1::C4,
),
USART2: (
RxDma2,
TxDma2,
dma1::C6,
dma1::C7,
),
USART3: (
RxDma3,
TxDma3,
dma1::C3,
dma1::C2,
),
Expand Down