replace tec_u_meas_adc with pins_adc

This commit is contained in:
Astro 2020-05-28 02:06:32 +02:00
parent 5418488a2f
commit 3c94342448
2 changed files with 8 additions and 14 deletions

View File

@ -18,7 +18,6 @@ pub struct Channels {
pub adc: ad7172::Adc<pins::AdcSpi, pins::AdcNss>,
/// 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<I: Into<usize>>(&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!(),

View File

@ -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<SPI4, (PE2<Alternate<AF5>>, NoMiso, PE6<Alternate<AF5>>)>;
type Dac1Spi = Spi<SPI5, (PF7<Alternate<AF5>>, NoMiso, PF9<Alternate<AF5>>)>;
pub type PinsAdc = Adc<ADC1>;
pub type TecUMeasAdc = Adc<ADC3>;
pub struct ChannelPinSet<C: ChannelPins> {
pub dac_spi: C::DacSpi,
pub dac_sync: C::DacSync,
@ -74,7 +72,6 @@ pub struct ChannelPinSet<C: ChannelPins> {
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<Channel0>,
@ -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,