@@ -30,6 +30,7 @@ use crate::adc::AdcChannel;
30
30
use crate :: broker:: { BrokerBuilder , Topic } ;
31
31
use crate :: digital_io:: { find_line, LineHandle , LineRequestFlags } ;
32
32
use crate :: led:: { BlinkPattern , BlinkPatternBuilder } ;
33
+ use crate :: system:: HardwareGeneration ;
33
34
use crate :: watched_tasks:: WatchedTasksBuilder ;
34
35
35
36
#[ cfg( any( test, feature = "demo_mode" ) ) ]
@@ -71,6 +72,27 @@ const MIN_VOLTAGE: f32 = -1.0;
71
72
const PWR_LINE_ASSERTED : u8 = 0 ;
72
73
const DISCHARGE_LINE_ASSERTED : u8 = 0 ;
73
74
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
+
74
96
#[ derive( PartialEq , Clone , Copy , Serialize , Deserialize ) ]
75
97
pub enum OutputRequest {
76
98
Idle ,
@@ -295,22 +317,14 @@ impl DutPwrThread {
295
317
pwr_volt : AdcChannel ,
296
318
pwr_curr : AdcChannel ,
297
319
pwr_led : Arc < Topic < BlinkPattern > > ,
320
+ hardware_generation : HardwareGeneration ,
298
321
) -> Result < Self > {
299
322
let pwr_line = find_line ( "DUT_PWR_EN" )
300
323
. ok_or_else ( || anyhow ! ( "Could not find GPIO line DUT_PWR_EN" ) ) ?;
301
324
let discharge_line = find_line ( "DUT_PWR_DISCH" )
302
325
. ok_or_else ( || anyhow ! ( "Could not find GPIO line DUT_PWR_DISCH" ) ) ?;
303
326
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 ( ) ;
314
328
let pwr_line = pwr_line. request ( flags, 1 - PWR_LINE_ASSERTED , "tacd" ) ?;
315
329
let discharge_line = discharge_line. request ( flags, DISCHARGE_LINE_ASSERTED , "tacd" ) ?;
316
330
@@ -600,6 +614,7 @@ mod tests {
600
614
use crate :: adc:: Adc ;
601
615
use crate :: broker:: { BrokerBuilder , Topic } ;
602
616
use crate :: digital_io:: find_line;
617
+ use crate :: system:: HardwareGeneration ;
603
618
use crate :: watched_tasks:: WatchedTasksBuilder ;
604
619
605
620
use super :: {
@@ -610,6 +625,7 @@ mod tests {
610
625
#[ test]
611
626
fn failsafe ( ) {
612
627
let mut wtb = WatchedTasksBuilder :: new ( ) ;
628
+ let hardware_generation = HardwareGeneration :: Gen3 ;
613
629
let pwr_line = find_line ( "DUT_PWR_EN" ) . unwrap ( ) ;
614
630
let discharge_line = find_line ( "DUT_PWR_DISCH" ) . unwrap ( ) ;
615
631
@@ -624,6 +640,7 @@ mod tests {
624
640
adc. pwr_volt . clone ( ) ,
625
641
adc. pwr_curr . clone ( ) ,
626
642
led. clone ( ) ,
643
+ hardware_generation,
627
644
) )
628
645
. unwrap ( ) ;
629
646
@@ -769,6 +786,7 @@ mod tests {
769
786
#[ test]
770
787
fn grace_period ( ) {
771
788
let mut wtb = WatchedTasksBuilder :: new ( ) ;
789
+ let hardware_generation = HardwareGeneration :: Gen3 ;
772
790
let pwr_line = find_line ( "DUT_PWR_EN" ) . unwrap ( ) ;
773
791
let discharge_line = find_line ( "DUT_PWR_DISCH" ) . unwrap ( ) ;
774
792
@@ -783,6 +801,7 @@ mod tests {
783
801
adc. pwr_volt . clone ( ) ,
784
802
adc. pwr_curr . clone ( ) ,
785
803
led,
804
+ hardware_generation,
786
805
) )
787
806
. unwrap ( ) ;
788
807
0 commit comments