forked from M-Labs/thermostat
replace channel[01].adc with pins_adc
This commit is contained in:
parent
ec6aa03dc3
commit
5418488a2f
@ -19,8 +19,6 @@ pub struct Channel<C: ChannelPins> {
|
|||||||
/// 1 / Volts
|
/// 1 / Volts
|
||||||
pub dac_factor: f64,
|
pub dac_factor: f64,
|
||||||
pub shdn: C::Shdn,
|
pub shdn: C::Shdn,
|
||||||
/// stm32f4 integrated adc
|
|
||||||
pub adc: C::Adc,
|
|
||||||
pub vref_pin: C::VRefPin,
|
pub vref_pin: C::VRefPin,
|
||||||
pub itec_pin: C::ItecPin,
|
pub itec_pin: C::ItecPin,
|
||||||
/// feedback from `dac` output
|
/// feedback from `dac` output
|
||||||
@ -42,7 +40,6 @@ impl<C: ChannelPins> Channel<C> {
|
|||||||
state,
|
state,
|
||||||
dac, dac_factor,
|
dac, dac_factor,
|
||||||
shdn: pins.shdn,
|
shdn: pins.shdn,
|
||||||
adc: pins.adc,
|
|
||||||
vref_pin: pins.vref_pin,
|
vref_pin: pins.vref_pin,
|
||||||
itec_pin: pins.itec_pin,
|
itec_pin: pins.itec_pin,
|
||||||
dac_feedback_pin: pins.dac_feedback_pin,
|
dac_feedback_pin: pins.dac_feedback_pin,
|
||||||
|
@ -16,6 +16,8 @@ pub struct Channels {
|
|||||||
channel0: Channel<Channel0>,
|
channel0: Channel<Channel0>,
|
||||||
channel1: Channel<Channel1>,
|
channel1: Channel<Channel1>,
|
||||||
pub adc: ad7172::Adc<pins::AdcSpi, pins::AdcNss>,
|
pub adc: ad7172::Adc<pins::AdcSpi, pins::AdcNss>,
|
||||||
|
/// stm32f4 integrated adc
|
||||||
|
pins_adc: pins::PinsAdc,
|
||||||
tec_u_meas_adc: pins::TecUMeasAdc,
|
tec_u_meas_adc: pins::TecUMeasAdc,
|
||||||
pub pwm: pins::PwmPins,
|
pub pwm: pins::PwmPins,
|
||||||
}
|
}
|
||||||
@ -24,6 +26,7 @@ impl Channels {
|
|||||||
pub fn new(pins: pins::Pins) -> Self {
|
pub fn new(pins: pins::Pins) -> Self {
|
||||||
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 tec_u_meas_adc = pins.tec_u_meas_adc;
|
let tec_u_meas_adc = pins.tec_u_meas_adc;
|
||||||
let pwm = pins.pwm;
|
let pwm = pins.pwm;
|
||||||
|
|
||||||
@ -47,7 +50,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, tec_u_meas_adc, pwm }
|
Channels { channel0, channel1, adc, pins_adc, tec_u_meas_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 {
|
||||||
@ -106,19 +109,21 @@ impl Channels {
|
|||||||
pub fn read_dac_feedback(&mut self, channel: usize) -> Volts {
|
pub fn read_dac_feedback(&mut self, channel: usize) -> Volts {
|
||||||
match channel {
|
match channel {
|
||||||
0 => {
|
0 => {
|
||||||
let sample = self.channel0.adc.convert(
|
let sample = self.pins_adc.convert(
|
||||||
&self.channel0.dac_feedback_pin,
|
&self.channel0.dac_feedback_pin,
|
||||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||||
);
|
);
|
||||||
let mv = self.channel0.adc.sample_to_millivolts(sample);
|
let mv = self.pins_adc.sample_to_millivolts(sample);
|
||||||
|
info!("dac0_fb: {}/{:03X}", mv, sample);
|
||||||
Volts(mv as f64 / 1000.0)
|
Volts(mv as f64 / 1000.0)
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
let sample = self.channel1.adc.convert(
|
let sample = self.pins_adc.convert(
|
||||||
&self.channel1.dac_feedback_pin,
|
&self.channel1.dac_feedback_pin,
|
||||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||||
);
|
);
|
||||||
let mv = self.channel1.adc.sample_to_millivolts(sample);
|
let mv = self.pins_adc.sample_to_millivolts(sample);
|
||||||
|
info!("dac1_fb: {}/{:03X}", mv, sample);
|
||||||
Volts(mv as f64 / 1000.0)
|
Volts(mv as f64 / 1000.0)
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
@ -140,19 +145,19 @@ impl Channels {
|
|||||||
pub fn read_itec(&mut self, channel: usize) -> Volts {
|
pub fn read_itec(&mut self, channel: usize) -> Volts {
|
||||||
match channel {
|
match channel {
|
||||||
0 => {
|
0 => {
|
||||||
let sample = self.channel0.adc.convert(
|
let sample = self.pins_adc.convert(
|
||||||
&self.channel0.itec_pin,
|
&self.channel0.itec_pin,
|
||||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||||
);
|
);
|
||||||
let mv = self.channel0.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.channel1.adc.convert(
|
let sample = self.pins_adc.convert(
|
||||||
&self.channel1.itec_pin,
|
&self.channel1.itec_pin,
|
||||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||||
);
|
);
|
||||||
let mv = self.channel1.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!(),
|
||||||
@ -163,19 +168,19 @@ impl Channels {
|
|||||||
pub fn read_vref(&mut self, channel: usize) -> Volts {
|
pub fn read_vref(&mut self, channel: usize) -> Volts {
|
||||||
match channel {
|
match channel {
|
||||||
0 => {
|
0 => {
|
||||||
let sample = self.channel0.adc.convert(
|
let sample = self.pins_adc.convert(
|
||||||
&self.channel0.vref_pin,
|
&self.channel0.vref_pin,
|
||||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||||
);
|
);
|
||||||
let mv = self.channel0.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.channel1.adc.convert(
|
let sample = self.pins_adc.convert(
|
||||||
&self.channel1.vref_pin,
|
&self.channel1.vref_pin,
|
||||||
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
stm32f4xx_hal::adc::config::SampleTime::Cycles_480
|
||||||
);
|
);
|
||||||
let mv = self.channel1.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!(),
|
||||||
|
15
src/pins.rs
15
src/pins.rs
@ -26,7 +26,6 @@ pub trait ChannelPins {
|
|||||||
type DacSpi: Transfer<u8>;
|
type DacSpi: Transfer<u8>;
|
||||||
type DacSync: OutputPin;
|
type DacSync: OutputPin;
|
||||||
type Shdn: OutputPin;
|
type Shdn: OutputPin;
|
||||||
type Adc;
|
|
||||||
type VRefPin;
|
type VRefPin;
|
||||||
type ItecPin;
|
type ItecPin;
|
||||||
type DacFeedbackPin;
|
type DacFeedbackPin;
|
||||||
@ -37,7 +36,6 @@ impl ChannelPins for Channel0 {
|
|||||||
type DacSpi = Dac0Spi;
|
type DacSpi = Dac0Spi;
|
||||||
type DacSync = PE4<Output<PushPull>>;
|
type DacSync = PE4<Output<PushPull>>;
|
||||||
type Shdn = PE10<Output<PushPull>>;
|
type Shdn = PE10<Output<PushPull>>;
|
||||||
type Adc = Adc<ADC1>;
|
|
||||||
type VRefPin = PA0<Analog>;
|
type VRefPin = PA0<Analog>;
|
||||||
type ItecPin = PA6<Analog>;
|
type ItecPin = PA6<Analog>;
|
||||||
type DacFeedbackPin = PA4<Analog>;
|
type DacFeedbackPin = PA4<Analog>;
|
||||||
@ -48,7 +46,6 @@ impl ChannelPins for Channel1 {
|
|||||||
type DacSpi = Dac1Spi;
|
type DacSpi = Dac1Spi;
|
||||||
type DacSync = PF6<Output<PushPull>>;
|
type DacSync = PF6<Output<PushPull>>;
|
||||||
type Shdn = PE15<Output<PushPull>>;
|
type Shdn = PE15<Output<PushPull>>;
|
||||||
type Adc = Adc<ADC2>;
|
|
||||||
type VRefPin = PA3<Analog>;
|
type VRefPin = PA3<Analog>;
|
||||||
type ItecPin = PB0<Analog>;
|
type ItecPin = PB0<Analog>;
|
||||||
type DacFeedbackPin = PA5<Analog>;
|
type DacFeedbackPin = PA5<Analog>;
|
||||||
@ -60,6 +57,7 @@ pub type AdcSpi = Spi<SPI2, (PB10<Alternate<AF5>>, PB14<Alternate<AF5>>, PB15<Al
|
|||||||
pub type AdcNss = PB12<Output<PushPull>>;
|
pub type AdcNss = PB12<Output<PushPull>>;
|
||||||
type Dac0Spi = Spi<SPI4, (PE2<Alternate<AF5>>, NoMiso, PE6<Alternate<AF5>>)>;
|
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 TecUMeasAdc = Adc<ADC3>;
|
pub type TecUMeasAdc = Adc<ADC3>;
|
||||||
|
|
||||||
@ -67,7 +65,6 @@ 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,
|
||||||
pub shdn: C::Shdn,
|
pub shdn: C::Shdn,
|
||||||
pub adc: C::Adc,
|
|
||||||
pub vref_pin: C::VRefPin,
|
pub vref_pin: C::VRefPin,
|
||||||
pub itec_pin: C::ItecPin,
|
pub itec_pin: C::ItecPin,
|
||||||
pub dac_feedback_pin: C::DacFeedbackPin,
|
pub dac_feedback_pin: C::DacFeedbackPin,
|
||||||
@ -78,6 +75,7 @@ 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 tec_u_meas_adc: TecUMeasAdc,
|
||||||
|
pub pins_adc: PinsAdc,
|
||||||
pub pwm: PwmPins,
|
pub pwm: PwmPins,
|
||||||
pub channel0: ChannelPinSet<Channel0>,
|
pub channel0: ChannelPinSet<Channel0>,
|
||||||
pub channel1: ChannelPinSet<Channel1>,
|
pub channel1: ChannelPinSet<Channel1>,
|
||||||
@ -107,6 +105,7 @@ impl Pins {
|
|||||||
let adc_spi = Self::setup_spi_adc(clocks, spi2, gpiob.pb10, gpiob.pb14, gpiob.pb15);
|
let adc_spi = Self::setup_spi_adc(clocks, spi2, gpiob.pb10, gpiob.pb14, gpiob.pb15);
|
||||||
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 tec_u_meas_adc = Adc::adc3(adc3, true, Default::default());
|
let tec_u_meas_adc = Adc::adc3(adc3, true, Default::default());
|
||||||
|
|
||||||
let pwm = PwmPins::setup(
|
let pwm = PwmPins::setup(
|
||||||
@ -122,8 +121,6 @@ impl Pins {
|
|||||||
);
|
);
|
||||||
let mut shdn0 = gpioe.pe10.into_push_pull_output();
|
let mut shdn0 = gpioe.pe10.into_push_pull_output();
|
||||||
let _ = shdn0.set_low();
|
let _ = shdn0.set_low();
|
||||||
let mut adc0 = Adc::adc1(adc1, true, Default::default());
|
|
||||||
adc0.enable();
|
|
||||||
let vref0_pin = gpioa.pa0.into_analog();
|
let vref0_pin = gpioa.pa0.into_analog();
|
||||||
let itec0_pin = gpioa.pa6.into_analog();
|
let itec0_pin = gpioa.pa6.into_analog();
|
||||||
let dac_feedback0_pin = gpioa.pa4.into_analog();
|
let dac_feedback0_pin = gpioa.pa4.into_analog();
|
||||||
@ -132,7 +129,6 @@ impl Pins {
|
|||||||
dac_spi: dac0_spi,
|
dac_spi: dac0_spi,
|
||||||
dac_sync: dac0_sync,
|
dac_sync: dac0_sync,
|
||||||
shdn: shdn0,
|
shdn: shdn0,
|
||||||
adc: adc0,
|
|
||||||
vref_pin: vref0_pin,
|
vref_pin: vref0_pin,
|
||||||
itec_pin: itec0_pin,
|
itec_pin: itec0_pin,
|
||||||
dac_feedback_pin: dac_feedback0_pin,
|
dac_feedback_pin: dac_feedback0_pin,
|
||||||
@ -145,8 +141,6 @@ impl Pins {
|
|||||||
);
|
);
|
||||||
let mut shdn1 = gpioe.pe15.into_push_pull_output();
|
let mut shdn1 = gpioe.pe15.into_push_pull_output();
|
||||||
let _ = shdn1.set_low();
|
let _ = shdn1.set_low();
|
||||||
let mut adc1 = Adc::adc2(adc2, true, Default::default());
|
|
||||||
adc1.enable();
|
|
||||||
let vref1_pin = gpioa.pa3.into_analog();
|
let vref1_pin = gpioa.pa3.into_analog();
|
||||||
let itec1_pin = gpiob.pb0.into_analog();
|
let itec1_pin = gpiob.pb0.into_analog();
|
||||||
let dac_feedback1_pin = gpioa.pa5.into_analog();
|
let dac_feedback1_pin = gpioa.pa5.into_analog();
|
||||||
@ -155,7 +149,6 @@ impl Pins {
|
|||||||
dac_spi: dac1_spi,
|
dac_spi: dac1_spi,
|
||||||
dac_sync: dac1_sync,
|
dac_sync: dac1_sync,
|
||||||
shdn: shdn1,
|
shdn: shdn1,
|
||||||
adc: adc1,
|
|
||||||
vref_pin: vref1_pin,
|
vref_pin: vref1_pin,
|
||||||
itec_pin: itec1_pin,
|
itec_pin: itec1_pin,
|
||||||
dac_feedback_pin: dac_feedback1_pin,
|
dac_feedback_pin: dac_feedback1_pin,
|
||||||
@ -164,7 +157,7 @@ impl Pins {
|
|||||||
|
|
||||||
Pins {
|
Pins {
|
||||||
adc_spi, adc_nss,
|
adc_spi, adc_nss,
|
||||||
tec_u_meas_adc,
|
pins_adc, tec_u_meas_adc,
|
||||||
pwm,
|
pwm,
|
||||||
channel0,
|
channel0,
|
||||||
channel1,
|
channel1,
|
||||||
|
Loading…
Reference in New Issue
Block a user