From 3c943424481a587fa8a0b65d5e6c1a407b9b3e86 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 28 May 2020 02:06:32 +0200 Subject: [PATCH] replace tec_u_meas_adc with pins_adc --- src/channels.rs | 12 +++++------- src/pins.rs | 10 +++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/channels.rs b/src/channels.rs index 8526732..09b081f 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -18,7 +18,6 @@ pub struct Channels { pub adc: ad7172::Adc, /// stm32f4 integrated adc pins_adc: pins::PinsAdc, - tec_u_meas_adc: pins::TecUMeasAdc, pub pwm: pins::PwmPins, } @@ -27,7 +26,6 @@ impl Channels { let channel0 = Channel::new(pins.channel0); let channel1 = Channel::new(pins.channel1); let pins_adc = pins.pins_adc; - let tec_u_meas_adc = pins.tec_u_meas_adc; let pwm = pins.pwm; let mut adc = ad7172::Adc::new(pins.adc_spi, pins.adc_nss).unwrap(); @@ -50,7 +48,7 @@ impl Channels { adc.setup_channel(1, ad7172::Input::Ain2, ad7172::Input::Ain3).unwrap(); adc.start_continuous_conversion().unwrap(); - Channels { channel0, channel1, adc, pins_adc, tec_u_meas_adc, pwm } + Channels { channel0, channel1, adc, pins_adc, pwm } } pub fn channel_state>(&mut self, channel: I) -> &mut ChannelState { @@ -190,19 +188,19 @@ impl Channels { pub fn read_tec_u_meas(&mut self, channel: usize) -> Volts { match channel { 0 => { - let sample = self.tec_u_meas_adc.convert( + let sample = self.pins_adc.convert( &self.channel0.tec_u_meas_pin, stm32f4xx_hal::adc::config::SampleTime::Cycles_480 ); - let mv = self.tec_u_meas_adc.sample_to_millivolts(sample); + let mv = self.pins_adc.sample_to_millivolts(sample); Volts(mv as f64 / 1000.0) } 1 => { - let sample = self.tec_u_meas_adc.convert( + let sample = self.pins_adc.convert( &self.channel1.tec_u_meas_pin, stm32f4xx_hal::adc::config::SampleTime::Cycles_480 ); - let mv = self.tec_u_meas_adc.sample_to_millivolts(sample); + let mv = self.pins_adc.sample_to_millivolts(sample); Volts(mv as f64 / 1000.0) } _ => unreachable!(), diff --git a/src/pins.rs b/src/pins.rs index 1ec0304..0269d92 100644 --- a/src/pins.rs +++ b/src/pins.rs @@ -16,7 +16,7 @@ use stm32f4xx_hal::{ rcc::Clocks, pwm::{self, PwmChannels}, spi::{Spi, NoMiso}, - stm32::{ADC1, ADC2, ADC3, GPIOA, GPIOB, GPIOC, GPIOE, GPIOF, GPIOG, SPI2, SPI4, SPI5, TIM1, TIM3}, + stm32::{ADC1, GPIOA, GPIOB, GPIOC, GPIOE, GPIOF, GPIOG, SPI2, SPI4, SPI5, TIM1, TIM3}, time::U32Ext, }; use crate::channel::{Channel0, Channel1}; @@ -59,8 +59,6 @@ type Dac0Spi = Spi>, NoMiso, PE6>)>; type Dac1Spi = Spi>, NoMiso, PF9>)>; pub type PinsAdc = Adc; -pub type TecUMeasAdc = Adc; - pub struct ChannelPinSet { pub dac_spi: C::DacSpi, pub dac_sync: C::DacSync, @@ -74,7 +72,6 @@ pub struct ChannelPinSet { pub struct Pins { pub adc_spi: AdcSpi, pub adc_nss: AdcNss, - pub tec_u_meas_adc: TecUMeasAdc, pub pins_adc: PinsAdc, pub pwm: PwmPins, pub channel0: ChannelPinSet, @@ -88,7 +85,7 @@ impl Pins { tim1: TIM1, tim3: TIM3, gpioa: GPIOA, gpiob: GPIOB, gpioc: GPIOC, gpioe: GPIOE, gpiof: GPIOF, gpiog: GPIOG, spi2: SPI2, spi4: SPI4, spi5: SPI5, - adc1: ADC1, adc2: ADC2, adc3: ADC3, + adc1: ADC1, ) -> Self { let gpioa = gpioa.split(); let gpiob = gpiob.split(); @@ -106,7 +103,6 @@ impl Pins { let adc_nss = gpiob.pb12.into_push_pull_output(); let pins_adc = Adc::adc1(adc1, true, Default::default()); - let tec_u_meas_adc = Adc::adc3(adc3, true, Default::default()); let pwm = PwmPins::setup( clocks, tim1, tim3, @@ -157,7 +153,7 @@ impl Pins { Pins { adc_spi, adc_nss, - pins_adc, tec_u_meas_adc, + pins_adc, pwm, channel0, channel1,