Merge pull request #2017 from ilya-epifanov/rp-adc-div
added sampling frequency setting to adc capture methods on rp2040
This commit is contained in:
commit
88ada52146
2 changed files with 16 additions and 4 deletions
|
@ -213,6 +213,7 @@ impl<'d> Adc<'d, Async> {
|
||||||
ch: &mut Channel<'_>,
|
ch: &mut Channel<'_>,
|
||||||
buf: &mut [W],
|
buf: &mut [W],
|
||||||
fcs_err: bool,
|
fcs_err: bool,
|
||||||
|
div: u16,
|
||||||
dma: impl Peripheral<P = impl dma::Channel>,
|
dma: impl Peripheral<P = impl dma::Channel>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let r = Self::regs();
|
let r = Self::regs();
|
||||||
|
@ -258,6 +259,7 @@ impl<'d> Adc<'d, Async> {
|
||||||
// start conversions and wait for dma to finish. we can't report errors early
|
// start conversions and wait for dma to finish. we can't report errors early
|
||||||
// because there's no interrupt to signal them, and inspecting every element
|
// because there's no interrupt to signal them, and inspecting every element
|
||||||
// of the fifo is too costly to do here.
|
// of the fifo is too costly to do here.
|
||||||
|
r.div().write_set(|w| w.set_int(div));
|
||||||
r.cs().write_set(|w| w.set_start_many(true));
|
r.cs().write_set(|w| w.set_start_many(true));
|
||||||
dma.await;
|
dma.await;
|
||||||
mem::drop(auto_reset);
|
mem::drop(auto_reset);
|
||||||
|
@ -275,9 +277,10 @@ impl<'d> Adc<'d, Async> {
|
||||||
&mut self,
|
&mut self,
|
||||||
ch: &mut Channel<'_>,
|
ch: &mut Channel<'_>,
|
||||||
buf: &mut [S],
|
buf: &mut [S],
|
||||||
|
div: u16,
|
||||||
dma: impl Peripheral<P = impl dma::Channel>,
|
dma: impl Peripheral<P = impl dma::Channel>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.read_many_inner(ch, buf, false, dma).await
|
self.read_many_inner(ch, buf, false, div, dma).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -285,11 +288,12 @@ impl<'d> Adc<'d, Async> {
|
||||||
&mut self,
|
&mut self,
|
||||||
ch: &mut Channel<'_>,
|
ch: &mut Channel<'_>,
|
||||||
buf: &mut [Sample],
|
buf: &mut [Sample],
|
||||||
|
div: u16,
|
||||||
dma: impl Peripheral<P = impl dma::Channel>,
|
dma: impl Peripheral<P = impl dma::Channel>,
|
||||||
) {
|
) {
|
||||||
// errors are reported in individual samples
|
// errors are reported in individual samples
|
||||||
let _ = self
|
let _ = self
|
||||||
.read_many_inner(ch, unsafe { mem::transmute::<_, &mut [u16]>(buf) }, true, dma)
|
.read_many_inner(ch, unsafe { mem::transmute::<_, &mut [u16]>(buf) }, true, div, dma)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,7 @@ async fn main(_spawner: Spawner) {
|
||||||
adc.read_many(
|
adc.read_many(
|
||||||
&mut Channel::new_pin(&mut p.PIN_29, Pull::Down),
|
&mut Channel::new_pin(&mut p.PIN_29, Pull::Down),
|
||||||
&mut low,
|
&mut low,
|
||||||
|
1,
|
||||||
&mut p.DMA_CH0,
|
&mut p.DMA_CH0,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -100,11 +101,17 @@ async fn main(_spawner: Spawner) {
|
||||||
adc.read_many(
|
adc.read_many(
|
||||||
&mut Channel::new_pin(&mut p.PIN_29, Pull::None),
|
&mut Channel::new_pin(&mut p.PIN_29, Pull::None),
|
||||||
&mut none,
|
&mut none,
|
||||||
|
1,
|
||||||
&mut p.DMA_CH0,
|
&mut p.DMA_CH0,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
adc.read_many_raw(&mut Channel::new_pin(&mut p.PIN_29, Pull::Up), &mut up, &mut p.DMA_CH0)
|
adc.read_many_raw(
|
||||||
|
&mut Channel::new_pin(&mut p.PIN_29, Pull::Up),
|
||||||
|
&mut up,
|
||||||
|
1,
|
||||||
|
&mut p.DMA_CH0,
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
defmt::assert!(low.iter().zip(none.iter()).all(|(l, n)| *l >> 4 < *n as u16));
|
defmt::assert!(low.iter().zip(none.iter()).all(|(l, n)| *l >> 4 < *n as u16));
|
||||||
defmt::assert!(up.iter().all(|s| s.good()));
|
defmt::assert!(up.iter().all(|s| s.good()));
|
||||||
|
@ -115,6 +122,7 @@ async fn main(_spawner: Spawner) {
|
||||||
adc.read_many(
|
adc.read_many(
|
||||||
&mut Channel::new_temp_sensor(&mut p.ADC_TEMP_SENSOR),
|
&mut Channel::new_temp_sensor(&mut p.ADC_TEMP_SENSOR),
|
||||||
&mut temp,
|
&mut temp,
|
||||||
|
1,
|
||||||
&mut p.DMA_CH0,
|
&mut p.DMA_CH0,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Reference in a new issue