@@ -783,110 +783,116 @@ impl From<u8> for CypdPdDataRole {
783783}
784784
785785pub fn get_and_print_cypd_pd_info ( ec : & CrosEc ) {
786+ // All of our systems have a maximum of 4 PD enabled ports
786787 let ports = 4u8 ;
787788
788789 for port in 0 ..ports {
789- println ! ( "USB-C Port {}:" , port) ;
790-
791790 let result = EcRequestGetPdPortState { port } . send_command ( ec) ;
792- match result {
793- Ok ( info) => {
794- let c_state = CypdTypeCState :: from ( info. c_state ) ;
795- let connected = !matches ! ( c_state, CypdTypeCState :: Nothing ) ;
796- let power_role = CypdPdPowerRole :: from ( info. power_role ) ;
797- let data_role = CypdPdDataRole :: from ( info. data_role ) ;
798- let voltage = { info. voltage } ;
799- let current = { info. current } ;
800- let watts_mw = voltage as u32 * current as u32 / 1000 ;
801- let has_pd_contract = info. pd_state != 0 ;
802791
803- println ! (
804- " PD Contract: {}" ,
805- if info. pd_state != 0 { "Yes" } else { "No" }
806- ) ;
807- println ! ( " Power Role: {:?}" , power_role) ;
808- println ! ( " Data Role: {:?}" , data_role) ;
809- if connected {
810- println ! (
811- " VCONN: {}" ,
812- if info. vconn != 0 { "On" } else { "Off" }
813- ) ;
814- println ! (
815- " Negotiated: {}.{:03} V, {} mA, {}.{} W" ,
816- voltage / 1000 ,
817- voltage % 1000 ,
818- current,
819- watts_mw / 1000 ,
820- watts_mw % 1000 ,
821- ) ;
822- println ! (
823- " CC Polarity: {}" ,
824- match info. cc_polarity {
825- 0 => "CC1" ,
826- 1 => "CC2" ,
827- 2 => "CC1 (Debug)" ,
828- 3 => "CC2 (Debug)" ,
829- _ => "Unknown" ,
830- }
831- ) ;
832- }
833- if has_pd_contract {
834- println ! ( " Port Partner: {:?}" , c_state) ;
835- println ! (
836- " EPR: {}{}" ,
837- if info. epr_active != 0 {
838- "Active"
839- } else {
840- "Inactive"
841- } ,
842- if info. epr_support != 0 {
843- " (Supported)"
844- } else {
845- ""
846- }
847- ) ;
848- if power_role == CypdPdPowerRole :: Sink {
849- println ! (
850- " Sink Active: {}" ,
851- if info. active_port != 0 { "Yes" } else { "No" }
852- ) ;
853- }
854- }
855- let alt = info. pd_alt_mode_status ;
856- // Bits 0-1 indicate DP alt mode is active (bit 0 = DFP_D/TBT,
857- // bit 1 = UFP_D). Only show when actually in DP alt mode.
858- if connected && ( alt & 0x03 ) != 0 {
859- let mut modes = vec ! [ ] ;
860- if alt & 0x01 != 0 {
861- modes. push ( "DFP_D Connected" ) ;
862- }
863- if alt & 0x02 != 0 {
864- modes. push ( "UFP_D Connected" ) ;
865- }
866- if alt & 0x04 != 0 {
867- modes. push ( "Power Low" ) ;
868- }
869- if alt & 0x08 != 0 {
870- modes. push ( "Enabled" ) ;
871- }
872- if alt & 0x10 != 0 {
873- modes. push ( "Multi-Function" ) ;
874- }
875- if alt & 0x20 != 0 {
876- modes. push ( "USB Config" ) ;
877- }
878- if alt & 0x40 != 0 {
879- modes. push ( "Exit Request" ) ;
880- }
881- if alt & 0x80 != 0 {
882- modes. push ( "HPD High" ) ;
883- }
884- println ! ( " DP Alt Mode: {} (0x{:02X})" , modes. join( ", " ) , alt) ;
885- }
792+ let info = match result {
793+ Ok ( info) => info,
794+ Err ( EcError :: Response ( EcResponseStatus :: InvalidParameter ) ) => {
795+ debug ! ( "Port {port} does not exist" ) ;
796+ continue ;
886797 }
887798 Err ( e) => {
888799 print_err :: < ( ) > ( Err ( e) ) ;
800+ continue ;
801+ }
802+ } ;
803+
804+ println ! ( "USB-C Port {}:" , port) ;
805+ let c_state = CypdTypeCState :: from ( info. c_state ) ;
806+ let connected = !matches ! ( c_state, CypdTypeCState :: Nothing ) ;
807+ let power_role = CypdPdPowerRole :: from ( info. power_role ) ;
808+ let data_role = CypdPdDataRole :: from ( info. data_role ) ;
809+ let voltage = { info. voltage } ;
810+ let current = { info. current } ;
811+ let watts_mw = voltage as u32 * current as u32 / 1000 ;
812+ let has_pd_contract = info. pd_state != 0 ;
813+
814+ println ! (
815+ " PD Contract: {}" ,
816+ if info. pd_state != 0 { "Yes" } else { "No" }
817+ ) ;
818+ println ! ( " Power Role: {:?}" , power_role) ;
819+ println ! ( " Data Role: {:?}" , data_role) ;
820+ if connected {
821+ println ! (
822+ " VCONN: {}" ,
823+ if info. vconn != 0 { "On" } else { "Off" }
824+ ) ;
825+ println ! (
826+ " Negotiated: {}.{:03} V, {} mA, {}.{} W" ,
827+ voltage / 1000 ,
828+ voltage % 1000 ,
829+ current,
830+ watts_mw / 1000 ,
831+ watts_mw % 1000 ,
832+ ) ;
833+ println ! (
834+ " CC Polarity: {}" ,
835+ match info. cc_polarity {
836+ 0 => "CC1" ,
837+ 1 => "CC2" ,
838+ 2 => "CC1 (Debug)" ,
839+ 3 => "CC2 (Debug)" ,
840+ _ => "Unknown" ,
841+ }
842+ ) ;
843+ }
844+ if has_pd_contract {
845+ println ! ( " Port Partner: {:?}" , c_state) ;
846+ println ! (
847+ " EPR: {}{}" ,
848+ if info. epr_active != 0 {
849+ "Active"
850+ } else {
851+ "Inactive"
852+ } ,
853+ if info. epr_support != 0 {
854+ " (Supported)"
855+ } else {
856+ ""
857+ }
858+ ) ;
859+ if power_role == CypdPdPowerRole :: Sink {
860+ println ! (
861+ " Sink Active: {}" ,
862+ if info. active_port != 0 { "Yes" } else { "No" }
863+ ) ;
864+ }
865+ }
866+ let alt = info. pd_alt_mode_status ;
867+ // Bits 0-1 indicate DP alt mode is active (bit 0 = DFP_D/TBT,
868+ // bit 1 = UFP_D). Only show when actually in DP alt mode.
869+ if connected && ( alt & 0x03 ) != 0 {
870+ let mut modes = vec ! [ ] ;
871+ if alt & 0x01 != 0 {
872+ modes. push ( "DFP_D Connected" ) ;
873+ }
874+ if alt & 0x02 != 0 {
875+ modes. push ( "UFP_D Connected" ) ;
876+ }
877+ if alt & 0x04 != 0 {
878+ modes. push ( "Power Low" ) ;
879+ }
880+ if alt & 0x08 != 0 {
881+ modes. push ( "Enabled" ) ;
882+ }
883+ if alt & 0x10 != 0 {
884+ modes. push ( "Multi-Function" ) ;
885+ }
886+ if alt & 0x20 != 0 {
887+ modes. push ( "USB Config" ) ;
888+ }
889+ if alt & 0x40 != 0 {
890+ modes. push ( "Exit Request" ) ;
891+ }
892+ if alt & 0x80 != 0 {
893+ modes. push ( "HPD High" ) ;
889894 }
895+ println ! ( " DP Alt Mode: {} (0x{:02X})" , modes. join( ", " ) , alt) ;
890896 }
891897 }
892898}
0 commit comments