diff options
| author | pennae <[email protected]> | 2023-07-21 23:34:12 +0200 |
|---|---|---|
| committer | pennae <[email protected]> | 2023-08-02 17:04:32 +0200 |
| commit | a6b8f3d99478266b4f110e9c150ce3add5c3ffc6 (patch) | |
| tree | fe1fc04105c93efc5a3bd056ce87e05495cfcb04 /tests | |
| parent | b166ed6b78db0737005a65c1e444ce7563de7da3 (diff) | |
rp: add single-channel dma from adc
with uniform treatment of adc inputs it's easy enough to add a new
sampling method. dma sampling only supports one channel at the moment,
though round-robin sampling would be a simple extension (probably a new
trait that's implemented for Channel and &[Channel]). continuous dma as
proposed in #1608 also isn't done here, we'd expect that to be a
compound dma::Channel that internally splits a buffer in half and
dispatches callbacks or something like that.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/rp/src/bin/adc.rs | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/tests/rp/src/bin/adc.rs b/tests/rp/src/bin/adc.rs index 9006ce8cc..d6d58f0c0 100644 --- a/tests/rp/src/bin/adc.rs +++ b/tests/rp/src/bin/adc.rs | |||
| @@ -6,7 +6,7 @@ mod common; | |||
| 6 | 6 | ||
| 7 | use defmt::*; | 7 | use defmt::*; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_rp::adc::{Adc, Channel, Config, InterruptHandler}; | 9 | use embassy_rp::adc::{Adc, Channel, Config, InterruptHandler, Sample}; |
| 10 | use embassy_rp::bind_interrupts; | 10 | use embassy_rp::bind_interrupts; |
| 11 | use embassy_rp::gpio::Pull; | 11 | use embassy_rp::gpio::Pull; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -71,10 +71,57 @@ async fn main(_spawner: Spawner) { | |||
| 71 | defmt::assert!(low < none); | 71 | defmt::assert!(low < none); |
| 72 | defmt::assert!(none < up); | 72 | defmt::assert!(none < up); |
| 73 | } | 73 | } |
| 74 | { | ||
| 75 | let temp = convert_to_celsius( | ||
| 76 | adc.read(&mut Channel::new_temp_sensor(&mut p.ADC_TEMP_SENSOR)) | ||
| 77 | .await | ||
| 78 | .unwrap(), | ||
| 79 | ); | ||
| 80 | defmt::assert!(temp > 0.0); | ||
| 81 | defmt::assert!(temp < 60.0); | ||
| 82 | } | ||
| 74 | 83 | ||
| 75 | let temp = convert_to_celsius(adc.read(&mut Channel::new_sensor(p.ADC_TEMP_SENSOR)).await.unwrap()); | 84 | // run a bunch of conversions. we'll only check gp29 and the temp |
| 76 | defmt::assert!(temp > 0.0); | 85 | // sensor here for brevity, if those two work the rest will too. |
| 77 | defmt::assert!(temp < 60.0); | 86 | { |
| 87 | // gp29 is connected to vsys through a 200k/100k divider, | ||
| 88 | // adding pulls should change the value | ||
| 89 | let mut low = [0u16; 16]; | ||
| 90 | let mut none = [0u8; 16]; | ||
| 91 | let mut up = [Sample::default(); 16]; | ||
| 92 | adc.read_many( | ||
| 93 | &mut Channel::new_pin(&mut p.PIN_29, Pull::Down), | ||
| 94 | &mut low, | ||
| 95 | &mut p.DMA_CH0, | ||
| 96 | ) | ||
| 97 | .await | ||
| 98 | .unwrap(); | ||
| 99 | adc.read_many( | ||
| 100 | &mut Channel::new_pin(&mut p.PIN_29, Pull::None), | ||
| 101 | &mut none, | ||
| 102 | &mut p.DMA_CH0, | ||
| 103 | ) | ||
| 104 | .await | ||
| 105 | .unwrap(); | ||
| 106 | adc.read_many_raw(&mut Channel::new_pin(&mut p.PIN_29, Pull::Up), &mut up, &mut p.DMA_CH0) | ||
| 107 | .await; | ||
| 108 | defmt::assert!(low.iter().zip(none.iter()).all(|(l, n)| *l >> 4 < *n as u16)); | ||
| 109 | defmt::assert!(up.iter().all(|s| s.good())); | ||
| 110 | defmt::assert!(none.iter().zip(up.iter()).all(|(n, u)| (*n as u16) < u.value())); | ||
| 111 | } | ||
| 112 | { | ||
| 113 | let mut temp = [0u16; 16]; | ||
| 114 | adc.read_many( | ||
| 115 | &mut Channel::new_temp_sensor(&mut p.ADC_TEMP_SENSOR), | ||
| 116 | &mut temp, | ||
| 117 | &mut p.DMA_CH0, | ||
| 118 | ) | ||
| 119 | .await | ||
| 120 | .unwrap(); | ||
| 121 | let temp = temp.map(convert_to_celsius); | ||
| 122 | defmt::assert!(temp.iter().all(|t| *t > 0.0)); | ||
| 123 | defmt::assert!(temp.iter().all(|t| *t < 60.0)); | ||
| 124 | } | ||
| 78 | 125 | ||
| 79 | info!("Test OK"); | 126 | info!("Test OK"); |
| 80 | cortex_m::asm::bkpt(); | 127 | cortex_m::asm::bkpt(); |
