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