Skip to content
Snippets Groups Projects
Commit 4bded63e authored by Per Lindgren's avatar Per Lindgren
Browse files

Stream trait works, but error on buffer

parent 5b1dfe92
No related branches found
No related tags found
No related merge requests found
...@@ -113,6 +113,8 @@ pub struct W; ...@@ -113,6 +113,8 @@ pub struct W;
pub struct Output<MODE> { pub struct Output<MODE> {
_mode: PhantomData<MODE>, _mode: PhantomData<MODE>,
} }
// === Usart1TxPin
pub unsafe trait Usart1TxStream<USART> {}
pub mod dma1 { pub mod dma1 {
use core::marker::PhantomData; use core::marker::PhantomData;
...@@ -160,10 +162,7 @@ pub mod dma1 { ...@@ -160,10 +162,7 @@ pub mod dma1 {
} }
} }
// === Usart1TxPin unsafe impl super::Usart1TxStream<USART2> for S5<C4> {}
pub unsafe trait Usart1TxStream<USART> {}
unsafe impl Usart1TxStream<USART2> for S5<C4> {}
pub struct Streams(pub S4<C0>, pub S5<C0>); pub struct Streams(pub S4<C0>, pub S5<C0>);
...@@ -183,7 +182,8 @@ pub mod dma1 { ...@@ -183,7 +182,8 @@ pub mod dma1 {
// lifcr low interrupt flag clear register // lifcr low interrupt flag clear register
// lisr low interrupt status register // lisr low interrupt status register
impl<CHANNEL> S5<CHANNEL> { // impl<CHANNEL> S5<CHANNEL> {
impl S5<C4> {
// sXcr stream x configuration register // sXcr stream x configuration register
pub(crate) fn cr(&mut self) -> &dma2::S5CR { pub(crate) fn cr(&mut self) -> &dma2::S5CR {
unsafe { &(*DMA1::ptr()).s5cr } unsafe { &(*DMA1::ptr()).s5cr }
...@@ -209,7 +209,7 @@ pub mod dma1 { ...@@ -209,7 +209,7 @@ pub mod dma1 {
unsafe { &(*DMA1::ptr()).s5ndtr } unsafe { &(*DMA1::ptr()).s5ndtr }
} }
// s0par stream x peripheral address register // sXpar stream x peripheral address register
pub(crate) fn par(&mut self) -> &dma2::S5PAR { pub(crate) fn par(&mut self) -> &dma2::S5PAR {
unsafe { &(*DMA1::ptr()).s5par } unsafe { &(*DMA1::ptr()).s5par }
} }
......
...@@ -8,11 +8,12 @@ ...@@ -8,11 +8,12 @@
use core::sync::atomic::{self, Ordering}; use core::sync::atomic::{self, Ordering};
use core::ptr; use core::ptr;
use core::marker::{PhantomData, Unsize}; use core::marker::{PhantomData, Unsize};
use cast::u16;
use hal::serial; use hal::serial;
use nb; use nb;
use stm32f4x::{USART1, USART2, USART6}; use stm32f4x::{USART1, USART2, USART6};
use dma::{Static, Transfer, R}; use dma::{Static, Transfer, Usart1TxStream, R};
// usart2 // usart2
use gpio::gpioa::{PA2, PA3}; use gpio::gpioa::{PA2, PA3};
...@@ -241,26 +242,21 @@ macro_rules! hal { ...@@ -241,26 +242,21 @@ macro_rules! hal {
} }
} }
impl Tx<$USARTX> { impl Tx<$USARTX> {
pub fn write_all<A, B, C>( pub fn write_all<A, B, S>(
self, self,
mut chan: C, mut stream: S,
buffer: B, buffer: B,
) -> Transfer<R, B, C, Self> ) -> Transfer<R, B, S, Self>
where where
A: Unsize<[u8]>, A: Unsize<[u8]>,
B: Static<A>, B: Static<A>,
C: S: Usart1TxStream<$USARTX>
{ {
// // write!(dma1, "hi {}", 1); // // write!(dma1, "hi {}", 1);
// let usart2 = self.0; // let usart2 = self.0;
// if dma1.s6cr.read().en().bit_is_set() { // let buffer: &[u8] = buffer.borrow();
// return Err(dma::Error::InUse); // stream.ndtr()
// }
// let buffer: &[u8] = buffer.lock();
// dma1.s6ndtr
// .write(|w| unsafe { w.ndt().bits(u16(buffer.len()).unwrap()) }); // .write(|w| unsafe { w.ndt().bits(u16(buffer.len()).unwrap()) });
// dma1.s6par // dma1.s6par
// .write(|w| unsafe { w.bits(&usart2.dr as *const _ as u32) }); // .write(|w| unsafe { w.bits(&usart2.dr as *const _ as u32) });
...@@ -284,7 +280,7 @@ macro_rules! hal { ...@@ -284,7 +280,7 @@ macro_rules! hal {
// TODO can we weaken this compiler barrier? // TODO can we weaken this compiler barrier?
// NOTE(compiler_fence) operations on `buffer` should not be reordered after // NOTE(compiler_fence) operations on `buffer` should not be reordered after
// the next statement, which starts the DMA transfer // the next statement, which starts the DMA transfer
atomic::compiler_fence(Ordering::SeqCst); // atomic::compiler_fence(Ordering::SeqCst);
// chan.ccr().modify(|_, w| { // chan.ccr().modify(|_, w| {
// w.mem2mem() // w.mem2mem()
...@@ -297,7 +293,7 @@ macro_rules! hal { ...@@ -297,7 +293,7 @@ macro_rules! hal {
// .bit8() // .bit8()
// .minc() // .minc()
// .set_bit() // .set_bit()
// .pinc() // .pinc()chan
// .clear_bit() // .clear_bit()
// .circ() // .circ()
// .clear_bit() // .clear_bit()
...@@ -308,7 +304,7 @@ macro_rules! hal { ...@@ -308,7 +304,7 @@ macro_rules! hal {
// }); // });
Transfer::r(buffer, chan, self) Transfer::r(buffer, stream, self)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment