diff options
| author | xoviat <[email protected]> | 2025-11-10 09:56:42 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2025-11-10 09:56:42 -0600 |
| commit | 12b59dc610fb659a4d51ccc364865a7e154379d6 (patch) | |
| tree | 4d91375fb1ba72c65a5a50ab213181a03828c280 /tests | |
| parent | 1da05747c416c989a128aabbbde4b46df7bba9b9 (diff) | |
adc: remove sample_time from struct
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/stm32/src/bin/dac.rs | 9 | ||||
| -rw-r--r-- | tests/stm32/src/bin/dac_l1.rs | 11 |
2 files changed, 14 insertions, 6 deletions
diff --git a/tests/stm32/src/bin/dac.rs b/tests/stm32/src/bin/dac.rs index d34bbb255..747b11e7f 100644 --- a/tests/stm32/src/bin/dac.rs +++ b/tests/stm32/src/bin/dac.rs | |||
| @@ -10,7 +10,7 @@ use core::f32::consts::PI; | |||
| 10 | use common::*; | 10 | use common::*; |
| 11 | use defmt::assert; | 11 | use defmt::assert; |
| 12 | use embassy_executor::Spawner; | 12 | use embassy_executor::Spawner; |
| 13 | use embassy_stm32::adc::Adc; | 13 | use embassy_stm32::adc::{Adc, SampleTime}; |
| 14 | use embassy_stm32::dac::{DacCh1, Value}; | 14 | use embassy_stm32::dac::{DacCh1, Value}; |
| 15 | use embassy_time::Timer; | 15 | use embassy_time::Timer; |
| 16 | use micromath::F32Ext; | 16 | use micromath::F32Ext; |
| @@ -37,7 +37,7 @@ async fn main(_spawner: Spawner) { | |||
| 37 | dac.set(Value::Bit8(0)); | 37 | dac.set(Value::Bit8(0)); |
| 38 | // Now wait a little to obtain a stable value | 38 | // Now wait a little to obtain a stable value |
| 39 | Timer::after_millis(30).await; | 39 | Timer::after_millis(30).await; |
| 40 | let offset = adc.blocking_read(&mut adc_pin); | 40 | let offset = adc.blocking_read(&mut adc_pin, SampleTime::from_bits(0)); |
| 41 | 41 | ||
| 42 | for v in 0..=255 { | 42 | for v in 0..=255 { |
| 43 | // First set the DAC output value | 43 | // First set the DAC output value |
| @@ -48,7 +48,10 @@ async fn main(_spawner: Spawner) { | |||
| 48 | Timer::after_millis(30).await; | 48 | Timer::after_millis(30).await; |
| 49 | 49 | ||
| 50 | // Need to steal the peripherals here because PA4 is obviously in use already | 50 | // Need to steal the peripherals here because PA4 is obviously in use already |
| 51 | let measured = adc.blocking_read(&mut unsafe { embassy_stm32::Peripherals::steal() }.PA4); | 51 | let measured = adc.blocking_read( |
| 52 | &mut unsafe { embassy_stm32::Peripherals::steal() }.PA4, | ||
| 53 | SampleTime::from_bits(0), | ||
| 54 | ); | ||
| 52 | // Calibrate and normalize the measurement to get close to the dac_output_val | 55 | // Calibrate and normalize the measurement to get close to the dac_output_val |
| 53 | let measured_normalized = ((measured as i32 - offset as i32) / normalization_factor) as i16; | 56 | let measured_normalized = ((measured as i32 - offset as i32) / normalization_factor) as i16; |
| 54 | 57 | ||
diff --git a/tests/stm32/src/bin/dac_l1.rs b/tests/stm32/src/bin/dac_l1.rs index e6400f28e..2fe0cf1f1 100644 --- a/tests/stm32/src/bin/dac_l1.rs +++ b/tests/stm32/src/bin/dac_l1.rs | |||
| @@ -10,7 +10,7 @@ use core::f32::consts::PI; | |||
| 10 | use common::*; | 10 | use common::*; |
| 11 | use defmt::assert; | 11 | use defmt::assert; |
| 12 | use embassy_executor::Spawner; | 12 | use embassy_executor::Spawner; |
| 13 | use embassy_stm32::adc::Adc; | 13 | use embassy_stm32::adc::{Adc, SampleTime}; |
| 14 | use embassy_stm32::dac::{DacCh1, Value}; | 14 | use embassy_stm32::dac::{DacCh1, Value}; |
| 15 | use embassy_stm32::{bind_interrupts, peripherals}; | 15 | use embassy_stm32::{bind_interrupts, peripherals}; |
| 16 | use embassy_time::Timer; | 16 | use embassy_time::Timer; |
| @@ -47,7 +47,7 @@ async fn main(_spawner: Spawner) { | |||
| 47 | dac.set(Value::Bit8(0)); | 47 | dac.set(Value::Bit8(0)); |
| 48 | // Now wait a little to obtain a stable value | 48 | // Now wait a little to obtain a stable value |
| 49 | Timer::after_millis(30).await; | 49 | Timer::after_millis(30).await; |
| 50 | let offset = adc.read(&mut adc_pin).await; | 50 | let offset = adc.read(&mut adc_pin, SampleTime::from_bits(0)).await; |
| 51 | 51 | ||
| 52 | for v in 0..=255 { | 52 | for v in 0..=255 { |
| 53 | // First set the DAC output value | 53 | // First set the DAC output value |
| @@ -58,7 +58,12 @@ async fn main(_spawner: Spawner) { | |||
| 58 | Timer::after_millis(30).await; | 58 | Timer::after_millis(30).await; |
| 59 | 59 | ||
| 60 | // Need to steal the peripherals here because PA4 is obviously in use already | 60 | // Need to steal the peripherals here because PA4 is obviously in use already |
| 61 | let measured = adc.read(&mut unsafe { embassy_stm32::Peripherals::steal() }.PA4).await; | 61 | let measured = adc |
| 62 | .read( | ||
| 63 | &mut unsafe { embassy_stm32::Peripherals::steal() }.PA4, | ||
| 64 | SampleTime::from_bits(0), | ||
| 65 | ) | ||
| 66 | .await; | ||
| 62 | // Calibrate and normalize the measurement to get close to the dac_output_val | 67 | // Calibrate and normalize the measurement to get close to the dac_output_val |
| 63 | let measured_normalized = ((measured as i32 - offset as i32) / normalization_factor) as i16; | 68 | let measured_normalized = ((measured as i32 - offset as i32) / normalization_factor) as i16; |
| 64 | 69 | ||
