pounder: fix attenuator indices (latch and shiftreg)

Before the discriminant was used despite being a compiler implementaiton
detail. This now fixes the discriminant to match byte index in the attenuator
shift register and latch-enable index of the gpio extender.
master
Robert Jördens 2021-05-26 14:53:32 +00:00
parent 94f60c100c
commit 3616f1fa5a
2 changed files with 6 additions and 11 deletions

View File

@ -35,7 +35,7 @@ pub trait AttenuatorInterface {
// The lowest 2 bits of the 8-bit shift register on the attenuator are ignored. Shift the
// attenuator code into the upper 6 bits of the register value. Note that the attenuator
// treats inputs as active-low, so the code is inverted before writing.
channels[channel as usize] = (!attenuation_code) << 2;
channels[channel as usize] = !(attenuation_code << 2);
self.transfer_attenuators(&mut channels)?;
// Finally, latch the output of the updated channel to force it into an active state.

View File

@ -41,10 +41,10 @@ pub enum Error {
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
pub enum Channel {
In0,
In1,
Out0,
Out1,
In0 = 0,
Out0 = 1,
In1 = 2,
Out1 = 3,
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
@ -340,12 +340,7 @@ impl AttenuatorInterface for PounderDevices {
/// Args:
/// * `channel` - The attenuator channel to latch.
fn latch_attenuator(&mut self, channel: Channel) -> Result<(), Error> {
let pin = match channel {
Channel::In0 => 0,
Channel::Out0 => 1,
Channel::In1 => 2,
Channel::Out1 => 3,
};
let pin = channel as u8;
self.mcp23017
.write_gpio(mcp23017::Port::GPIOB, 0x2f & !(1 << pin))
.map_err(|_| Error::I2c)?;