From 34d59dac5dd876b1f1ae2ea20333f1cc35cdfb70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Mon, 30 Nov 2020 15:38:14 +0100 Subject: [PATCH] adc: merge acquire_buffer and release_buffer again --- src/adc.rs | 17 +++-------------- src/main.rs | 3 --- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/adc.rs b/src/adc.rs index 43fb0a5..e9120aa 100644 --- a/src/adc.rs +++ b/src/adc.rs @@ -185,9 +185,7 @@ macro_rules! adc_input { /// /// # Returns /// A reference to the underlying buffer that has been filled with ADC samples. - pub fn acquire_buffer( - &mut self, - ) -> &'static mut [u16; SAMPLE_BUFFER_SIZE] { + pub fn acquire_buffer(&mut self) -> &[u16; SAMPLE_BUFFER_SIZE] { // Wait for the transfer to fully complete before continuing. // Note: If a device hangs up, check that this conditional is passing correctly, as there is // no time-out checks here in the interest of execution speed. @@ -200,18 +198,9 @@ macro_rules! adc_input { let (prev_buffer, _) = self.transfer.next_transfer(next_buffer).unwrap(); - prev_buffer - } + self.next_buffer.replace(prev_buffer); // .unwrap_none() https://github.com/rust-lang/rust/issues/62633 - /// Release a buffer of ADC samples to the pool. - /// - /// # Args - /// * `next_buffer` - Buffer of ADC samples to be re-used. - pub fn release_buffer( - &mut self, - next_buffer: &'static mut [u16; SAMPLE_BUFFER_SIZE], - ) { - self.next_buffer.replace(next_buffer); // .unwrap_none() https://github.com/rust-lang/rust/issues/62633 + self.next_buffer.as_ref().unwrap() } } }; diff --git a/src/main.rs b/src/main.rs index 0aaf669..e6f83b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -763,9 +763,6 @@ const APP: () = { dac_samples[channel][sample] = y as i16 as u16 ^ 0x8000; } } - let [adc0, adc1] = adc_samples; - c.resources.adcs.0.release_buffer(adc0); - c.resources.adcs.0.release_buffer(adc1); let [dac0, dac1] = dac_samples; c.resources.dacs.0.release_buffer(dac0); c.resources.dacs.1.release_buffer(dac1);