diff options
| author | crispaudio <[email protected]> | 2025-09-14 01:34:49 +0200 |
|---|---|---|
| committer | crispaudio <[email protected]> | 2025-09-14 01:34:49 +0200 |
| commit | 31b5a3f0a4fafd425aef34b9d6fb93ead851b4c6 (patch) | |
| tree | 43987fc7e35cdd3d0a533ee2818bd464299a39e8 /examples | |
| parent | b2fa01cec7164980333a17355af215feb3cb33c2 (diff) | |
mspm0-adc: implement From for AnyAdcChannel
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/mspm0g3507/src/bin/adc.rs | 9 | ||||
| -rw-r--r-- | examples/mspm0l1306/src/bin/adc.rs | 9 |
2 files changed, 6 insertions, 12 deletions
diff --git a/examples/mspm0g3507/src/bin/adc.rs b/examples/mspm0g3507/src/bin/adc.rs index 73711c75c..ceccc7c02 100644 --- a/examples/mspm0g3507/src/bin/adc.rs +++ b/examples/mspm0g3507/src/bin/adc.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_mspm0::adc::{self, Adc, AdcChannel, Vrsel}; | 6 | use embassy_mspm0::adc::{self, Adc, Vrsel}; |
| 7 | use embassy_mspm0::{bind_interrupts, peripherals, Config}; | 7 | use embassy_mspm0::{bind_interrupts, peripherals, Config}; |
| 8 | use embassy_time::Timer; | 8 | use embassy_time::Timer; |
| 9 | use {defmt_rtt as _, panic_halt as _}; | 9 | use {defmt_rtt as _, panic_halt as _}; |
| @@ -19,14 +19,11 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 19 | 19 | ||
| 20 | // Configure adc with sequence 0 to 1 | 20 | // Configure adc with sequence 0 to 1 |
| 21 | let mut adc = Adc::new_async(p.ADC0, Default::default(), Irqs); | 21 | let mut adc = Adc::new_async(p.ADC0, Default::default(), Irqs); |
| 22 | let pin1 = p.PA22.degrade_adc(); | 22 | let sequence = [(&p.PA22.into(), Vrsel::VddaVssa), (&p.PB20.into(), Vrsel::VddaVssa)]; |
| 23 | let pin2 = p.PB20.degrade_adc(); | ||
| 24 | let sequence = [(&pin1, Vrsel::VddaVssa), (&pin2, Vrsel::VddaVssa)]; | ||
| 25 | let mut readings = [0u16; 2]; | 23 | let mut readings = [0u16; 2]; |
| 26 | let mut pin3 = p.PA27; | ||
| 27 | 24 | ||
| 28 | loop { | 25 | loop { |
| 29 | let r = adc.read_channel(&mut pin3).await; | 26 | let r = adc.read_channel(&p.PA27).await; |
| 30 | info!("Raw adc PA27: {}", r); | 27 | info!("Raw adc PA27: {}", r); |
| 31 | // With a voltage range of 0-3.3V and a resolution of 12 bits, the raw value can be | 28 | // With a voltage range of 0-3.3V and a resolution of 12 bits, the raw value can be |
| 32 | // approximated to voltage (~0.0008 per step). | 29 | // approximated to voltage (~0.0008 per step). |
diff --git a/examples/mspm0l1306/src/bin/adc.rs b/examples/mspm0l1306/src/bin/adc.rs index a0c2c0cff..2806b98cc 100644 --- a/examples/mspm0l1306/src/bin/adc.rs +++ b/examples/mspm0l1306/src/bin/adc.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_mspm0::adc::{self, Adc, AdcChannel, Vrsel}; | 6 | use embassy_mspm0::adc::{self, Adc, Vrsel}; |
| 7 | use embassy_mspm0::{bind_interrupts, peripherals, Config}; | 7 | use embassy_mspm0::{bind_interrupts, peripherals, Config}; |
| 8 | use embassy_time::Timer; | 8 | use embassy_time::Timer; |
| 9 | use {defmt_rtt as _, panic_halt as _}; | 9 | use {defmt_rtt as _, panic_halt as _}; |
| @@ -19,14 +19,11 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 19 | 19 | ||
| 20 | // Configure adc with sequence 0 to 1 | 20 | // Configure adc with sequence 0 to 1 |
| 21 | let mut adc = Adc::new_async(p.ADC0, Default::default(), Irqs); | 21 | let mut adc = Adc::new_async(p.ADC0, Default::default(), Irqs); |
| 22 | let pin1 = p.PA22.degrade_adc(); | 22 | let sequence = [(&p.PA22.into(), Vrsel::VddaVssa), (&p.PA20.into(), Vrsel::VddaVssa)]; |
| 23 | let pin2 = p.PA20.degrade_adc(); | ||
| 24 | let sequence = [(&pin1, Vrsel::VddaVssa), (&pin2, Vrsel::VddaVssa)]; | ||
| 25 | let mut readings = [0u16; 2]; | 23 | let mut readings = [0u16; 2]; |
| 26 | let mut pin3 = p.PA27; | ||
| 27 | 24 | ||
| 28 | loop { | 25 | loop { |
| 29 | let r = adc.read_channel(&mut pin3).await; | 26 | let r = adc.read_channel(&p.PA27).await; |
| 30 | info!("Raw adc PA27: {}", r); | 27 | info!("Raw adc PA27: {}", r); |
| 31 | // With a voltage range of 0-3.3V and a resolution of 12 bits, the raw value can be | 28 | // With a voltage range of 0-3.3V and a resolution of 12 bits, the raw value can be |
| 32 | // approximated to voltage (~0.0008 per step). | 29 | // approximated to voltage (~0.0008 per step). |
