Skip to content

Commit 3c0d187

Browse files
committed
dut_power: determine GPIO flags based on hardware generation
Now that we know the LXA TAC hardware generation we are running on there is no longer a need to guess based on the name of the GPIO driver's name. This also means we can remove the driver name shims for demo and test modes. Signed-off-by: Leonard Göhrs <[email protected]>
1 parent a741256 commit 3c0d187

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed

src/digital_io/gpio/demo_mode.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ impl BitOr for LineRequestFlags {
8080
}
8181
}
8282

83-
pub struct ChipDecoy;
84-
85-
impl ChipDecoy {
86-
pub fn label(&self) -> &'static str {
87-
"demo_mode"
88-
}
89-
}
90-
9183
pub struct FindDecoy {
9284
name: String,
9385
}
@@ -102,10 +94,6 @@ impl FindDecoy {
10294

10395
Ok(line_handle)
10496
}
105-
106-
pub fn chip(&self) -> ChipDecoy {
107-
ChipDecoy
108-
}
10997
}
11098

11199
pub fn find_line(name: &str) -> Option<FindDecoy> {

src/digital_io/gpio/test.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ impl BitOr for LineRequestFlags {
5757
}
5858
}
5959

60-
pub struct ChipDecoy;
61-
62-
impl ChipDecoy {
63-
pub fn label(&self) -> &'static str {
64-
"test"
65-
}
66-
}
67-
6860
pub struct FindDecoy {
6961
name: String,
7062
val: Arc<AtomicU8>,
@@ -80,10 +72,6 @@ impl FindDecoy {
8072
})
8173
}
8274

83-
pub fn chip(&self) -> ChipDecoy {
84-
ChipDecoy
85-
}
86-
8775
pub fn stub_get(&self) -> u8 {
8876
self.val.load(Ordering::Relaxed)
8977
}

src/dut_power.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::adc::AdcChannel;
3030
use crate::broker::{BrokerBuilder, Topic};
3131
use crate::digital_io::{find_line, LineHandle, LineRequestFlags};
3232
use crate::led::{BlinkPattern, BlinkPatternBuilder};
33+
use crate::system::HardwareGeneration;
3334
use crate::watched_tasks::WatchedTasksBuilder;
3435

3536
#[cfg(any(test, feature = "demo_mode"))]
@@ -71,6 +72,27 @@ const MIN_VOLTAGE: f32 = -1.0;
7172
const PWR_LINE_ASSERTED: u8 = 0;
7273
const DISCHARGE_LINE_ASSERTED: u8 = 0;
7374

75+
trait OutputFlags {
76+
fn output_flags(&self) -> LineRequestFlags;
77+
}
78+
79+
impl OutputFlags for HardwareGeneration {
80+
fn output_flags(&self) -> LineRequestFlags {
81+
// Early TACs have a i2c port expander on the power board.
82+
// This port expander is output only and can not be configured as
83+
// open drain.
84+
// The outputs on later TACs should however be driven open drain
85+
// for EMI reasons.
86+
87+
match self {
88+
HardwareGeneration::Gen1 => LineRequestFlags::OUTPUT,
89+
HardwareGeneration::Gen2 | HardwareGeneration::Gen3 => {
90+
LineRequestFlags::OUTPUT | LineRequestFlags::OPEN_DRAIN
91+
}
92+
}
93+
}
94+
}
95+
7496
#[derive(PartialEq, Clone, Copy, Serialize, Deserialize)]
7597
pub enum OutputRequest {
7698
Idle,
@@ -295,22 +317,14 @@ impl DutPwrThread {
295317
pwr_volt: AdcChannel,
296318
pwr_curr: AdcChannel,
297319
pwr_led: Arc<Topic<BlinkPattern>>,
320+
hardware_generation: HardwareGeneration,
298321
) -> Result<Self> {
299322
let pwr_line = find_line("DUT_PWR_EN")
300323
.ok_or_else(|| anyhow!("Could not find GPIO line DUT_PWR_EN"))?;
301324
let discharge_line = find_line("DUT_PWR_DISCH")
302325
.ok_or_else(|| anyhow!("Could not find GPIO line DUT_PWR_DISCH"))?;
303326

304-
// Early TACs have a i2c port expander on the power board.
305-
// This port expander is output only and can not be configured as
306-
// open drain.
307-
// The outputs on later TACs should however be driven open drain
308-
// for EMI reasons.
309-
let flags = match pwr_line.chip().label() {
310-
"pca9570" => LineRequestFlags::OUTPUT,
311-
_ => LineRequestFlags::OUTPUT | LineRequestFlags::OPEN_DRAIN,
312-
};
313-
327+
let flags = hardware_generation.output_flags();
314328
let pwr_line = pwr_line.request(flags, 1 - PWR_LINE_ASSERTED, "tacd")?;
315329
let discharge_line = discharge_line.request(flags, DISCHARGE_LINE_ASSERTED, "tacd")?;
316330

@@ -600,6 +614,7 @@ mod tests {
600614
use crate::adc::Adc;
601615
use crate::broker::{BrokerBuilder, Topic};
602616
use crate::digital_io::find_line;
617+
use crate::system::HardwareGeneration;
603618
use crate::watched_tasks::WatchedTasksBuilder;
604619

605620
use super::{
@@ -610,6 +625,7 @@ mod tests {
610625
#[test]
611626
fn failsafe() {
612627
let mut wtb = WatchedTasksBuilder::new();
628+
let hardware_generation = HardwareGeneration::Gen3;
613629
let pwr_line = find_line("DUT_PWR_EN").unwrap();
614630
let discharge_line = find_line("DUT_PWR_DISCH").unwrap();
615631

@@ -624,6 +640,7 @@ mod tests {
624640
adc.pwr_volt.clone(),
625641
adc.pwr_curr.clone(),
626642
led.clone(),
643+
hardware_generation,
627644
))
628645
.unwrap();
629646

@@ -769,6 +786,7 @@ mod tests {
769786
#[test]
770787
fn grace_period() {
771788
let mut wtb = WatchedTasksBuilder::new();
789+
let hardware_generation = HardwareGeneration::Gen3;
772790
let pwr_line = find_line("DUT_PWR_EN").unwrap();
773791
let discharge_line = find_line("DUT_PWR_DISCH").unwrap();
774792

@@ -783,6 +801,7 @@ mod tests {
783801
adc.pwr_volt.clone(),
784802
adc.pwr_curr.clone(),
785803
led,
804+
hardware_generation,
786805
))
787806
.unwrap();
788807

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ async fn init(screenshooter: ScreenShooter) -> Result<(Ui, WatchedTasksBuilder)>
8282
adc.pwr_volt.clone(),
8383
adc.pwr_curr.clone(),
8484
led.dut_pwr.clone(),
85+
hardware_generation,
8586
)
8687
.await?;
8788
let dig_io = DigitalIo::new(&mut bb, &mut wtb, led.out_0.clone(), led.out_1.clone())?;

0 commit comments

Comments
 (0)