Skip to content

Commit

Permalink
rf channel: cleanup redundant setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Oct 9, 2020
1 parent 01a98cf commit 5e39b98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
14 changes: 3 additions & 11 deletions ads7924/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ where

fn set_mode(&mut self, mode: OperationMode, channel: Option<Channel>) -> Result<(), Error> {
let mut mode_control: [u8; 1] = [0];
self.read(Register::ModeCntrl, &mut mode_control)?;

// The datasheet indicates that the device should always transition to active when switching
// operational modes to ensure internal logic is synchronized.
if mode != OperationMode::Active {
mode_control[0].set_bits(2..8, OperationMode::Active as u8);
self.write(Register::ModeCntrl, &mode_control)?;
}

if let Some(channel) = channel {
mode_control[0].set_bits(0..3, channel as u8);
}
Expand Down Expand Up @@ -310,14 +301,15 @@ where
// First, disable Autoscan mode.
self.set_mode(OperationMode::Active, None)?;

for (voltage, reg) in voltages.iter_mut().zip(upper_data_registers.iter()) {
for (i, reg) in upper_data_registers.iter().enumerate() {
let mut data = [0u8; 2];
self.read(*reg, &mut data)?;

// Convert the voltage register to an ADC code. The code is stored MSB-aligned, so we need
// to shift it back into alignment.
let code = u16::from_be_bytes(data) >> 4;

*voltage = code as f32 * self.volts_per_lsb;
voltages[i] = code as f32 * self.volts_per_lsb;
}

// Reenable Autoscan.
Expand Down
23 changes: 3 additions & 20 deletions src/rf_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,10 @@ impl Devices {
.expect("Power monitor did not respond");

// Configure alarm thresholds for the P5V0_MP signal.
// Ensure that P5V0MP remains valid. Note that
// the 5V rail is divided by 2.5 before entering the ADC.
ads7924
.set_thresholds(ads7924::Channel::Three, 0.0, 5.5 / 2.5)
.set_thresholds(ads7924::Channel::Three, 0.0, 6.5 / 2.5)
.expect("Power monitor failed to set thresholds");

// Verify that there is no active alarm condition.
Expand Down Expand Up @@ -499,13 +501,6 @@ impl RfChannel {
)
.unwrap();

// Place the bias DAC to drive the RF amplifier into pinch-off.
channel
.i2c_devices
.bias_dac
.set_voltage(3.2)
.expect("Failed to disable RF bias voltage");

// If the channel configuration specifies the channel as enabled, power up the
// channel now.
if channel.settings.data.enabled && platform::watchdog_detected() == false {
Expand All @@ -515,18 +510,6 @@ impl RfChannel {
.unwrap();
}

// Configure alerts/alarms for the power monitor.

// Ensure that P5V0MP remains within +/- 500mV of the specified voltage. Note that
// the 5V rail is divided by 2.5 before entering the ADC.
channel
.i2c_devices
.power_monitor
.set_thresholds(ads7924::Channel::Three, 0.0, 5.5 / 2.5)
.unwrap();

channel.i2c_devices.power_monitor.clear_alarm().unwrap();

Some(channel)
}
None => None,
Expand Down

0 comments on commit 5e39b98

Please sign in to comment.