Skip to content

Commit

Permalink
Use new DMA API
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Draaijer committed Jun 21, 2021
1 parent 588c0e1 commit 3999bd6
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ macro_rules! dma {
// the next statement, which starts a new DMA transfer
atomic::compiler_fence(Ordering::SeqCst);

let left_in_buffer = self.channel.get_cndtr() as usize;
let left_in_buffer = self.payload.channel.get_cndtr() as usize;
let got_data_len = old_buf.max_len() - left_in_buffer; // How many transfers were completed = how many bytes are available
unsafe {
old_buf.set_len(got_data_len);
Expand Down Expand Up @@ -847,7 +847,7 @@ macro_rules! dma {
// ,- half-buffer
// [ x x x x y y y y y z | z z z z z z z z z z ]
// ^- pending=11
let pending = self.channel.get_cndtr() as usize; // available transfers (= bytes) in _whole_ buffer
let pending = self.payload.channel.get_cndtr() as usize; // available transfers (= bytes) in _whole_ buffer
let slice = buf.as_ref();
let capacity = slice.len(); // capacity of _half_ a buffer
// <--- capacity=10 --->
Expand Down Expand Up @@ -1043,10 +1043,37 @@ macro_rules! dma {
}
}

impl<BUFFER, const N: usize> Transfer<W, BUFFER, dma1::C1, ADC>
impl TransferPayload for RxDma<ADC, dma1::C1> {
fn start(&mut self) {
self.channel.start();
}

fn stop(&mut self) {
self.channel.stop();
}
}

impl RxDma<ADC, dma1::C1> {
pub fn split(mut self) -> (ADC, dma1::C1) {
self.stop();
(self.payload, self.channel)
}
}

impl<BUFFER, const N: usize> Transfer<W, BUFFER, RxDma<ADC, dma1::C1>>
where
BUFFER: Sized + StableDeref<Target = [u16; N]> + DerefMut + 'static,
{
pub fn from_adc_dma(
dma: RxDma<ADC, dma1::C1>,
buffer: BUFFER,
dma_mode: adc::DmaMode,
transfer_complete_interrupt: bool,
) -> Self {
let (adc, channel) = dma.split();
Transfer::from_adc(adc, channel, buffer, dma_mode, transfer_complete_interrupt)
}

/// Initiate a new DMA transfer from an ADC.
///
/// `dma_mode` indicates the desired mode for DMA.
Expand Down Expand Up @@ -1109,8 +1136,10 @@ where
Transfer {
_mode: PhantomData {},
buffer,
channel,
payload: adc,
payload: RxDma {
channel,
payload: adc,
},
}
}
}
Expand Down

0 comments on commit 3999bd6

Please sign in to comment.