forked from M-Labs/thermostat
replace tec_u_meas_adc with pins_adc
This commit is contained in:
parent
5418488a2f
commit
3c94342448
|
@ -18,7 +18,6 @@ pub struct Channels {
|
||||||
pub adc: ad7172::Adc<pins::AdcSpi, pins::AdcNss>,
|
pub adc: ad7172::Adc<pins::AdcSpi, pins::AdcNss>,
|
||||||
/// stm32f4 integrated adc
|
/// stm32f4 integrated adc
|
||||||
pins_adc: pins::PinsAdc,
|
pins_adc: pins::PinsAdc,
|
||||||
tec_u_meas_adc: pins::TecUMeasAdc,
|
|
||||||
pub pwm: pins::PwmPins,
|
pub pwm: pins::PwmPins,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +26,6 @@ impl Channels {
|
||||||
let channel0 = Channel::new(pins.channel0);
|
let channel0 = Channel::new(pins.channel0);
|
||||||
let channel1 = Channel::new(pins.channel1);
|
let channel1 = Channel::new(pins.channel1);
|
||||||
let pins_adc = pins.pins_adc;
|
let pins_adc = pins.pins_adc;
|
||||||
let tec_u_meas_adc = pins.tec_u_meas_adc;
|
|
||||||
let pwm = pins.pwm;
|
let pwm = pins.pwm;
|
||||||
|
|
||||||
let mut adc = ad7172::Adc::new(pins.adc_spi, pins.adc_nss).unwrap();
|
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.setup_channel(1, ad7172::Input::Ain2, ad7172::Input::Ain3).unwrap();
|
||||||
adc.start_continuous_conversion().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 {
|
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 {
|
pub fn read_tec_u_meas(&mut self, channel: usize) -> Volts {
|
||||||
match channel {
|
match channel {
|
||||||
0 => {
|
0 => {
|
||||||
let sample = self.tec_u_meas_adc.convert(
|
let sample = self.pins_adc.convert(
|
||||||
&self.channel0.tec_u_meas_pin,
|
&self.channel0.tec_u_meas_pin,
|
||||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
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)
|
Volts(mv as f64 / 1000.0)
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
let sample = self.tec_u_meas_adc.convert(
|
let sample = self.pins_adc.convert(
|
||||||
&self.channel1.tec_u_meas_pin,
|
&self.channel1.tec_u_meas_pin,
|
||||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
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)
|
Volts(mv as f64 / 1000.0)
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
|
10
src/pins.rs
10
src/pins.rs
|
@ -16,7 +16,7 @@ use stm32f4xx_hal::{
|
||||||
rcc::Clocks,
|
rcc::Clocks,
|
||||||
pwm::{self, PwmChannels},
|
pwm::{self, PwmChannels},
|
||||||
spi::{Spi, NoMiso},
|
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,
|
time::U32Ext,
|
||||||
};
|
};
|
||||||
use crate::channel::{Channel0, Channel1};
|
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>>)>;
|
type Dac1Spi = Spi<SPI5, (PF7<Alternate<AF5>>, NoMiso, PF9<Alternate<AF5>>)>;
|
||||||
pub type PinsAdc = Adc<ADC1>;
|
pub type PinsAdc = Adc<ADC1>;
|
||||||
|
|
||||||
pub type TecUMeasAdc = Adc<ADC3>;
|
|
||||||
|
|
||||||
pub struct ChannelPinSet<C: ChannelPins> {
|
pub struct ChannelPinSet<C: ChannelPins> {
|
||||||
pub dac_spi: C::DacSpi,
|
pub dac_spi: C::DacSpi,
|
||||||
pub dac_sync: C::DacSync,
|
pub dac_sync: C::DacSync,
|
||||||
|
@ -74,7 +72,6 @@ pub struct ChannelPinSet<C: ChannelPins> {
|
||||||
pub struct Pins {
|
pub struct Pins {
|
||||||
pub adc_spi: AdcSpi,
|
pub adc_spi: AdcSpi,
|
||||||
pub adc_nss: AdcNss,
|
pub adc_nss: AdcNss,
|
||||||
pub tec_u_meas_adc: TecUMeasAdc,
|
|
||||||
pub pins_adc: PinsAdc,
|
pub pins_adc: PinsAdc,
|
||||||
pub pwm: PwmPins,
|
pub pwm: PwmPins,
|
||||||
pub channel0: ChannelPinSet<Channel0>,
|
pub channel0: ChannelPinSet<Channel0>,
|
||||||
|
@ -88,7 +85,7 @@ impl Pins {
|
||||||
tim1: TIM1, tim3: TIM3,
|
tim1: TIM1, tim3: TIM3,
|
||||||
gpioa: GPIOA, gpiob: GPIOB, gpioc: GPIOC, gpioe: GPIOE, gpiof: GPIOF, gpiog: GPIOG,
|
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, adc3: ADC3,
|
adc1: ADC1,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let gpioa = gpioa.split();
|
let gpioa = gpioa.split();
|
||||||
let gpiob = gpiob.split();
|
let gpiob = gpiob.split();
|
||||||
|
@ -106,7 +103,6 @@ impl Pins {
|
||||||
let adc_nss = gpiob.pb12.into_push_pull_output();
|
let adc_nss = gpiob.pb12.into_push_pull_output();
|
||||||
|
|
||||||
let pins_adc = Adc::adc1(adc1, true, Default::default());
|
let pins_adc = Adc::adc1(adc1, true, Default::default());
|
||||||
let tec_u_meas_adc = Adc::adc3(adc3, true, Default::default());
|
|
||||||
|
|
||||||
let pwm = PwmPins::setup(
|
let pwm = PwmPins::setup(
|
||||||
clocks, tim1, tim3,
|
clocks, tim1, tim3,
|
||||||
|
@ -157,7 +153,7 @@ impl Pins {
|
||||||
|
|
||||||
Pins {
|
Pins {
|
||||||
adc_spi, adc_nss,
|
adc_spi, adc_nss,
|
||||||
pins_adc, tec_u_meas_adc,
|
pins_adc,
|
||||||
pwm,
|
pwm,
|
||||||
channel0,
|
channel0,
|
||||||
channel1,
|
channel1,
|
||||||
|
|
Loading…
Reference in New Issue