adc: merge acquire_buffer and release_buffer again

This commit is contained in:
Robert Jördens 2020-11-30 15:38:14 +01:00
parent b1301a6184
commit 34d59dac5d
2 changed files with 3 additions and 17 deletions

View File

@ -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()
}
}
};

View File

@ -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);