From 6dd6bb2e1e0317745735a6139155bb63457cd8b1 Mon Sep 17 00:00:00 2001 From: Astro Date: Fri, 10 Apr 2020 21:05:05 +0200 Subject: [PATCH] pins: add ref[01] adc --- src/main.rs | 8 +++++++- src/pins.rs | 27 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index ace6455..d5fc4df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,7 +89,8 @@ fn main() -> ! { let pins = Pins::setup( clocks, dp.TIM1, dp.TIM3, dp.GPIOA, dp.GPIOB, dp.GPIOC, dp.GPIOE, dp.GPIOF, dp.GPIOG, - dp.SPI2, dp.SPI4, dp.SPI5 + dp.SPI2, dp.SPI4, dp.SPI5, + dp.ADC1, dp.ADC2, ); let mut adc = ad7172::Adc::new(pins.adc_spi, pins.adc_nss).unwrap(); @@ -187,6 +188,11 @@ fn main() -> ! { ); } } + + let ref0 = pins.ref0_adc.convert( + &pins.ref0_pin, stm32f4xx_hal::adc::config::SampleTime::Cycles_480 + ); + let _ = writeln!(socket, "ref0={}", ref0); } Command::Show(ShowCommand::Pid) => { for (channel, state) in channel_states.iter().enumerate() { diff --git a/src/pins.rs b/src/pins.rs index 0ec039b..50326fe 100644 --- a/src/pins.rs +++ b/src/pins.rs @@ -1,7 +1,8 @@ use stm32f4xx_hal::{ + adc::Adc, hal::digital::v2::OutputPin, gpio::{ - AF5, Alternate, + AF5, Alternate, Analog, gpioa::*, gpiob::*, gpioc::*, @@ -15,9 +16,10 @@ use stm32f4xx_hal::{ rcc::Clocks, pwm::{self, PwmChannels}, spi::{Spi, NoMiso}, - stm32::{GPIOA, GPIOB, GPIOC, GPIOE, GPIOF, GPIOG, SPI2, SPI4, SPI5, TIM1, TIM3}, + stm32::{ADC1, ADC2, GPIOA, GPIOB, GPIOC, GPIOE, GPIOF, GPIOG, SPI2, SPI4, SPI5, TIM1, TIM3}, time::U32Ext, }; +use crate::channel::{Channel0, Channel1}; /// SPI peripheral used for communication with the ADC @@ -32,19 +34,23 @@ pub struct Pins { pub dac0_spi: Dac0Spi, pub dac0_sync: PE4>, pub shdn0: PE10>, + pub ref0_adc: Adc, + pub ref0_pin: PA0, pub dac1_spi: Dac1Spi, pub dac1_sync: PF6>, pub shdn1: PE15>, + pub ref1_adc: Adc, + pub ref1_pin: PA3, } impl Pins { /// Setup GPIO pins and configure MCU peripherals pub fn setup( clocks: Clocks, - tim1: TIM1, - tim3: TIM3, + tim1: TIM1, tim3: TIM3, gpioa: GPIOA, gpiob: GPIOB, gpioc: GPIOC, gpioe: GPIOE, gpiof: GPIOF, gpiog: GPIOG, - spi2: SPI2, spi4: SPI4, spi5: SPI5 + spi2: SPI2, spi4: SPI4, spi5: SPI5, + adc1: ADC1, adc2: ADC2, ) -> Self { let gpioa = gpioa.split(); let gpiob = gpiob.split(); @@ -74,18 +80,25 @@ impl Pins { ); let mut shdn0 = gpioe.pe10.into_push_pull_output(); let _ = shdn0.set_low(); + let mut ref0_adc = Adc::adc1(adc1, true, Default::default()); + ref0_adc.enable(); + let ref0_pin = gpioa.pa0.into_analog(); + let (dac1_spi, dac1_sync) = Self::setup_dac1( clocks, spi5, gpiof.pf7, gpiof.pf6, gpiof.pf9 ); let mut shdn1 = gpioe.pe15.into_push_pull_output(); let _ = shdn1.set_low(); + let mut ref1_adc = Adc::adc2(adc2, true, Default::default()); + let ref1_pin = gpioa.pa3.into_analog(); + ref1_adc.enable(); Pins { adc_spi, adc_nss, pwm, - dac0_spi, dac0_sync, shdn0, - dac1_spi, dac1_sync, shdn1, + dac0_spi, dac0_sync, shdn0, ref0_adc, ref0_pin, + dac1_spi, dac1_sync, shdn1, ref1_adc, ref1_pin, } }