From a317eb60fdd6c0ec19ec3ca7fb54b3f644a1d6e8 Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 16 May 2020 19:36:00 +0200 Subject: [PATCH] rename ref_adc to dac_loopback --- src/channel.rs | 10 ++++++---- src/channels.rs | 10 +++++----- src/main.rs | 6 +++--- src/pins.rs | 36 ++++++++++++++++++------------------ 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/channel.rs b/src/channel.rs index 624e2f2..c3e885e 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -11,10 +11,12 @@ pub struct Channel1; pub struct Channel { pub state: ChannelState, + /// for `i_set` pub dac: ad5680::Dac, pub shdn: C::Shdn, - pub ref_adc: C::RefAdc, - pub ref_pin: C::RefPin, + /// feedback from `dac` output + pub dac_loopback: C::DacLoopback, + pub dac_loopback_pin: C::DacLoopbackPin, } impl Channel { @@ -27,8 +29,8 @@ impl Channel { state, dac, shdn: pins.shdn, - ref_adc: pins.ref_adc, - ref_pin: pins.ref_pin, + dac_loopback: pins.dac_loopback, + dac_loopback_pin: pins.dac_loopback_pin, } } } diff --git a/src/channels.rs b/src/channels.rs index 6416161..0f6c70e 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -82,14 +82,14 @@ impl Channels { } } - pub fn read_ref_adc(&mut self, channel: usize) -> u16 { + pub fn read_dac_loopback(&mut self, channel: usize) -> u16 { match channel { - 0 => self.channel0.ref_adc.convert( - &self.channel0.ref_pin, + 0 => self.channel0.dac_loopback.convert( + &self.channel0.dac_loopback_pin, stm32f4xx_hal::adc::config::SampleTime::Cycles_480 ), - 1 => self.channel1.ref_adc.convert( - &self.channel1.ref_pin, + 1 => self.channel1.dac_loopback.convert( + &self.channel1.dac_loopback_pin, stm32f4xx_hal::adc::config::SampleTime::Cycles_480 ), _ => unreachable!(), diff --git a/src/main.rs b/src/main.rs index 07e4b92..40d94e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,12 +141,12 @@ fn main() -> ! { Command::Show(ShowCommand::Input) => { for channel in 0..CHANNELS { if let Some(adc_data) = channels.channel_state(channel).adc_data { - let ref_adc_data = channels.read_ref_adc(channel); + let dac_loopback = channels.read_dac_loopback(channel); let state = channels.channel_state(channel); let _ = writeln!( - socket, "t={} raw{}=0x{:06X} ref_adc=0x{:X}", + socket, "t={} raw{}=0x{:06X} dac_loopback=0x{:X}", state.adc_time, channel, adc_data, - ref_adc_data + dac_loopback ); } } diff --git a/src/pins.rs b/src/pins.rs index de4b965..af43b64 100644 --- a/src/pins.rs +++ b/src/pins.rs @@ -26,24 +26,24 @@ pub trait ChannelPins { type DacSpi: Transfer; type DacSync: OutputPin; type Shdn: OutputPin; - type RefAdc; - type RefPin; + type DacLoopback; + type DacLoopbackPin; } impl ChannelPins for Channel0 { type DacSpi = Dac0Spi; type DacSync = PE4>; type Shdn = PE10>; - type RefAdc = Adc; - type RefPin = PA4; + type DacLoopback = Adc; + type DacLoopbackPin = PA4; } impl ChannelPins for Channel1 { type DacSpi = Dac1Spi; type DacSync = PF6>; type Shdn = PE15>; - type RefAdc = Adc; - type RefPin = PA5; + type DacLoopback = Adc; + type DacLoopbackPin = PA5; } /// SPI peripheral used for communication with the ADC @@ -57,8 +57,8 @@ pub struct ChannelPinSet { pub dac_spi: C::DacSpi, pub dac_sync: C::DacSync, pub shdn: C::Shdn, - pub ref_adc: C::RefAdc, - pub ref_pin: C::RefPin, + pub dac_loopback: C::DacLoopback, + pub dac_loopback_pin: C::DacLoopbackPin, } pub struct Pins { @@ -106,15 +106,15 @@ impl Pins { ); let mut shdn0 = gpioe.pe10.into_push_pull_output(); let _ = shdn0.set_low(); - let mut ref0_adc = Adc::adc1(adc1, true, Default::default()); - ref0_adc.enable(); - let ref0_pin = gpioa.pa4.into_analog(); + let mut dac_loopback0 = Adc::adc1(adc1, true, Default::default()); + dac_loopback0.enable(); + let dac_loopback0_pin = gpioa.pa4.into_analog(); let channel0 = ChannelPinSet { dac_spi: dac0_spi, dac_sync: dac0_sync, shdn: shdn0, - ref_adc: ref0_adc, - ref_pin: ref0_pin, + dac_loopback: dac_loopback0, + dac_loopback_pin: dac_loopback0_pin, }; let (dac1_spi, dac1_sync) = Self::setup_dac1( @@ -123,15 +123,15 @@ impl Pins { ); let mut shdn1 = gpioe.pe15.into_push_pull_output(); let _ = shdn1.set_low(); - let mut ref1_adc = Adc::adc2(adc2, true, Default::default()); - ref1_adc.enable(); - let ref1_pin = gpioa.pa5.into_analog(); + let mut dac_loopback1 = Adc::adc2(adc2, true, Default::default()); + dac_loopback1.enable(); + let dac_loopback1_pin = gpioa.pa5.into_analog(); let channel1 = ChannelPinSet { dac_spi: dac1_spi, dac_sync: dac1_sync, shdn: shdn1, - ref_adc: ref1_adc, - ref_pin: ref1_pin, + dac_loopback: dac_loopback1, + dac_loopback_pin: dac_loopback1_pin, }; Pins {