@@ -718,6 +718,151 @@ pub fn get_pd_info(ec: &CrosEc, ports: u8) -> Vec<EcResult<UsbPdPowerInfo>> {
718718 info
719719}
720720
721+ #[ derive( Debug ) ]
722+ enum CypdTypeCState {
723+ Nothing ,
724+ Sink ,
725+ Source ,
726+ Debug ,
727+ Audio ,
728+ PoweredAccessory ,
729+ Unsupported ,
730+ Invalid ,
731+ }
732+
733+ impl From < u8 > for CypdTypeCState {
734+ fn from ( v : u8 ) -> Self {
735+ match v {
736+ 0 => CypdTypeCState :: Nothing ,
737+ 1 => CypdTypeCState :: Sink ,
738+ 2 => CypdTypeCState :: Source ,
739+ 3 => CypdTypeCState :: Debug ,
740+ 4 => CypdTypeCState :: Audio ,
741+ 5 => CypdTypeCState :: PoweredAccessory ,
742+ 6 => CypdTypeCState :: Unsupported ,
743+ _ => CypdTypeCState :: Invalid ,
744+ }
745+ }
746+ }
747+
748+ #[ derive( Debug ) ]
749+ enum CypdPdPowerRole {
750+ Sink ,
751+ Source ,
752+ Unknown ,
753+ }
754+
755+ impl From < u8 > for CypdPdPowerRole {
756+ fn from ( v : u8 ) -> Self {
757+ match v {
758+ 0 => CypdPdPowerRole :: Sink ,
759+ 1 => CypdPdPowerRole :: Source ,
760+ _ => CypdPdPowerRole :: Unknown ,
761+ }
762+ }
763+ }
764+
765+ #[ derive( Debug ) ]
766+ enum CypdPdDataRole {
767+ Ufp ,
768+ Dfp ,
769+ Disconnected ,
770+ Unknown ,
771+ }
772+
773+ impl From < u8 > for CypdPdDataRole {
774+ fn from ( v : u8 ) -> Self {
775+ match v {
776+ 0 => CypdPdDataRole :: Ufp ,
777+ 1 => CypdPdDataRole :: Dfp ,
778+ 2 => CypdPdDataRole :: Disconnected ,
779+ _ => CypdPdDataRole :: Unknown ,
780+ }
781+ }
782+ }
783+
784+ pub fn get_and_print_cypd_pd_info ( ec : & CrosEc ) {
785+ let fl16 = Some ( PlatformFamily :: Framework16 ) == smbios:: get_family ( ) ;
786+ let ports = 4u8 ;
787+
788+ for port in 0 ..ports {
789+ println ! (
790+ "USB-C Port {} ({}):" ,
791+ port,
792+ match port {
793+ 0 => "Right Back" ,
794+ 1 =>
795+ if fl16 {
796+ "Right Middle"
797+ } else {
798+ "Right Front"
799+ } ,
800+ 2 =>
801+ if fl16 {
802+ "Left Middle"
803+ } else {
804+ "Left Front"
805+ } ,
806+ 3 => "Left Back" ,
807+ _ => "??" ,
808+ }
809+ ) ;
810+
811+ let result = EcRequestGetPdPortState { port } . send_command ( ec) ;
812+ match result {
813+ Ok ( info) => {
814+ let c_state = CypdTypeCState :: from ( info. c_state ) ;
815+ let power_role = CypdPdPowerRole :: from ( info. power_role ) ;
816+ let data_role = CypdPdDataRole :: from ( info. data_role ) ;
817+ let voltage = { info. voltage } ;
818+ let current = { info. current } ;
819+ let watts_mw = voltage as u32 * current as u32 / 1000 ;
820+
821+ println ! ( " Type-C State: {:?}" , c_state) ;
822+ println ! (
823+ " PD Contract: {}" ,
824+ if info. pd_state != 0 { "Yes" } else { "No" }
825+ ) ;
826+ println ! ( " Power Role: {:?}" , power_role) ;
827+ println ! ( " Data Role: {:?}" , data_role) ;
828+ println ! (
829+ " VCONN: {}" ,
830+ if info. vconn != 0 { "On" } else { "Off" }
831+ ) ;
832+ println ! (
833+ " Voltage: {}.{:03} V" ,
834+ voltage / 1000 ,
835+ voltage % 1000
836+ ) ;
837+ println ! ( " Current: {} mA" , current) ;
838+ println ! ( " Power: {}.{} W" , watts_mw / 1000 , watts_mw % 1000 ) ;
839+ println ! (
840+ " EPR: {}{}" ,
841+ if info. epr_active != 0 {
842+ "Active"
843+ } else {
844+ "Inactive"
845+ } ,
846+ if info. epr_support != 0 {
847+ " (Supported)"
848+ } else {
849+ ""
850+ }
851+ ) ;
852+ println ! ( " CC Polarity: CC{}" , info. cc_polarity + 1 ) ;
853+ println ! (
854+ " Active Port: {}" ,
855+ if info. active_port != 0 { "Yes" } else { "No" }
856+ ) ;
857+ println ! ( " Alt Mode: 0x{:02X}" , info. pd_alt_mode_status) ;
858+ }
859+ Err ( e) => {
860+ print_err :: < ( ) > ( Err ( e) ) ;
861+ }
862+ }
863+ }
864+ }
865+
721866pub fn get_and_print_pd_info ( ec : & CrosEc ) {
722867 let fl16 = Some ( PlatformFamily :: Framework16 ) == smbios:: get_family ( ) ;
723868 let ports = 4 ; // All our platforms have 4 PD ports so far
0 commit comments