pins: add ref[01] adc

This commit is contained in:
Astro 2020-04-10 21:05:05 +02:00
parent 9682d7657d
commit 6dd6bb2e1e
2 changed files with 27 additions and 8 deletions

View File

@ -89,7 +89,8 @@ fn main() -> ! {
let pins = Pins::setup( let pins = Pins::setup(
clocks, dp.TIM1, dp.TIM3, clocks, dp.TIM1, dp.TIM3,
dp.GPIOA, dp.GPIOB, dp.GPIOC, dp.GPIOE, dp.GPIOF, dp.GPIOG, 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(); 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) => { Command::Show(ShowCommand::Pid) => {
for (channel, state) in channel_states.iter().enumerate() { for (channel, state) in channel_states.iter().enumerate() {

View File

@ -1,7 +1,8 @@
use stm32f4xx_hal::{ use stm32f4xx_hal::{
adc::Adc,
hal::digital::v2::OutputPin, hal::digital::v2::OutputPin,
gpio::{ gpio::{
AF5, Alternate, AF5, Alternate, Analog,
gpioa::*, gpioa::*,
gpiob::*, gpiob::*,
gpioc::*, gpioc::*,
@ -15,9 +16,10 @@ use stm32f4xx_hal::{
rcc::Clocks, rcc::Clocks,
pwm::{self, PwmChannels}, pwm::{self, PwmChannels},
spi::{Spi, NoMiso}, 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, time::U32Ext,
}; };
use crate::channel::{Channel0, Channel1};
/// SPI peripheral used for communication with the ADC /// SPI peripheral used for communication with the ADC
@ -32,19 +34,23 @@ pub struct Pins {
pub dac0_spi: Dac0Spi, pub dac0_spi: Dac0Spi,
pub dac0_sync: PE4<Output<PushPull>>, pub dac0_sync: PE4<Output<PushPull>>,
pub shdn0: PE10<Output<PushPull>>, pub shdn0: PE10<Output<PushPull>>,
pub ref0_adc: Adc<ADC1>,
pub ref0_pin: PA0<Analog>,
pub dac1_spi: Dac1Spi, pub dac1_spi: Dac1Spi,
pub dac1_sync: PF6<Output<PushPull>>, pub dac1_sync: PF6<Output<PushPull>>,
pub shdn1: PE15<Output<PushPull>>, pub shdn1: PE15<Output<PushPull>>,
pub ref1_adc: Adc<ADC2>,
pub ref1_pin: PA3<Analog>,
} }
impl Pins { impl Pins {
/// Setup GPIO pins and configure MCU peripherals /// Setup GPIO pins and configure MCU peripherals
pub fn setup( pub fn setup(
clocks: Clocks, clocks: Clocks,
tim1: TIM1, tim1: TIM1, tim3: TIM3,
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,
) -> Self { ) -> Self {
let gpioa = gpioa.split(); let gpioa = gpioa.split();
let gpiob = gpiob.split(); let gpiob = gpiob.split();
@ -74,18 +80,25 @@ 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 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( let (dac1_spi, dac1_sync) = Self::setup_dac1(
clocks, spi5, clocks, spi5,
gpiof.pf7, gpiof.pf6, gpiof.pf9 gpiof.pf7, gpiof.pf6, gpiof.pf9
); );
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 ref1_adc = Adc::adc2(adc2, true, Default::default());
let ref1_pin = gpioa.pa3.into_analog();
ref1_adc.enable();
Pins { Pins {
adc_spi, adc_nss, adc_spi, adc_nss,
pwm, pwm,
dac0_spi, dac0_sync, shdn0, dac0_spi, dac0_sync, shdn0, ref0_adc, ref0_pin,
dac1_spi, dac1_sync, shdn1, dac1_spi, dac1_sync, shdn1, ref1_adc, ref1_pin,
} }
} }