11use embassy_executor:: { Executor , Spawner } ;
22use embedded_services:: type_c:: controller;
3- use embedded_services:: type_c:: external:: execute_ucsi_command;
3+ use embedded_services:: type_c:: external:: { UcsiResponseResult , execute_ucsi_command} ;
4+ use embedded_usb_pd:: GlobalPortId ;
5+ use embedded_usb_pd:: ucsi:: ppm:: ack_cc_ci:: Ack ;
46use embedded_usb_pd:: ucsi:: ppm:: get_capability:: ResponseData as UcsiCapabilities ;
57use embedded_usb_pd:: ucsi:: ppm:: set_notification_enable:: NotificationEnable ;
6- use embedded_usb_pd:: ucsi:: { Command , ppm} ;
8+ use embedded_usb_pd:: ucsi:: { Command , lpm , ppm} ;
79use log:: * ;
810use static_cell:: StaticCell ;
911use type_c_service:: service:: config:: Config ;
@@ -15,39 +17,98 @@ async fn task(_spawner: Spawner) {
1517 controller:: init ( ) ;
1618
1719 info ! ( "Resetting PPM..." ) ;
18- let response = execute_ucsi_command ( Command :: PpmCommand ( ppm:: Command :: PpmReset ) )
20+ let response: UcsiResponseResult = execute_ucsi_command ( Command :: PpmCommand ( ppm:: Command :: PpmReset ) )
1921 . await
20- . unwrap ( ) ;
21- if !response. response . cci . reset_complete ( ) || response. response . cci . error ( ) {
22- error ! ( "PPM reset failed: {:?}" , response. response. cci) ;
22+ . into ( ) ;
23+ let response = response. unwrap ( ) ;
24+ if !response. cci . reset_complete ( ) || response. cci . error ( ) {
25+ error ! ( "PPM reset failed: {:?}" , response. cci) ;
2326 } else {
2427 info ! ( "PPM reset successful" ) ;
2528 }
2629
2730 info ! ( "Set Notification enable..." ) ;
2831 let mut notifications = NotificationEnable :: default ( ) ;
2932 notifications. set_cmd_complete ( true ) ;
30- let response = execute_ucsi_command ( Command :: PpmCommand ( ppm:: Command :: SetNotificationEnable (
33+ let response: UcsiResponseResult = execute_ucsi_command ( Command :: PpmCommand ( ppm:: Command :: SetNotificationEnable (
3134 ppm:: set_notification_enable:: Args {
3235 notification_enable : notifications,
3336 } ,
3437 ) ) )
3538 . await
36- . unwrap ( ) ;
37- if !response. response . cci . cmd_complete ( ) || response. response . cci . error ( ) {
38- error ! ( "Set Notification enable failed: {:?}" , response. response. cci) ;
39+ . into ( ) ;
40+ let response = response. unwrap ( ) ;
41+ if !response. cci . cmd_complete ( ) || response. cci . error ( ) {
42+ error ! ( "Set Notification enable failed: {:?}" , response. cci) ;
3943 } else {
4044 info ! ( "Set Notification enable successful" ) ;
4145 }
4246
47+ info ! ( "Sending command complete ack..." ) ;
48+ let response: UcsiResponseResult =
49+ execute_ucsi_command ( Command :: PpmCommand ( ppm:: Command :: AckCcCi ( ppm:: ack_cc_ci:: Args {
50+ ack : * Ack :: default ( ) . set_command_complete ( true ) ,
51+ } ) ) )
52+ . await
53+ . into ( ) ;
54+ let response = response. unwrap ( ) ;
55+ if !response. cci . ack_command ( ) || response. cci . error ( ) {
56+ error ! ( "Sending command complete ack failed: {:?}" , response. cci) ;
57+ } else {
58+ info ! ( "Sending command complete ack successful" ) ;
59+ }
60+
4361 info ! ( "Get PPM capabilities..." ) ;
44- let response = execute_ucsi_command ( Command :: PpmCommand ( ppm:: Command :: GetCapability ) )
62+ let response: UcsiResponseResult = execute_ucsi_command ( Command :: PpmCommand ( ppm:: Command :: GetCapability ) )
4563 . await
46- . unwrap ( ) ;
47- if !response. response . cci . cmd_complete ( ) || response. response . cci . error ( ) {
64+ . into ( ) ;
65+ let response = response. unwrap ( ) ;
66+ if !response. cci . cmd_complete ( ) || response. cci . error ( ) {
4867 error ! ( "Get PPM capabilities failed: {response:?}" ) ;
4968 } else {
50- info ! ( "Get PPM capabilities successful: {:?}" , response. response. data) ;
69+ info ! ( "Get PPM capabilities successful: {:?}" , response. data) ;
70+ }
71+
72+ info ! ( "Sending command complete ack..." ) ;
73+ let response: UcsiResponseResult =
74+ execute_ucsi_command ( Command :: PpmCommand ( ppm:: Command :: AckCcCi ( ppm:: ack_cc_ci:: Args {
75+ ack : * Ack :: default ( ) . set_command_complete ( true ) ,
76+ } ) ) )
77+ . await
78+ . into ( ) ;
79+ let response = response. unwrap ( ) ;
80+ if !response. cci . ack_command ( ) || response. cci . error ( ) {
81+ error ! ( "Sending command complete ack failed: {:?}" , response. cci) ;
82+ } else {
83+ info ! ( "Sending command complete ack successful" ) ;
84+ }
85+
86+ info ! ( "Get connector status..." ) ;
87+ let response: UcsiResponseResult = execute_ucsi_command ( Command :: LpmCommand ( lpm:: GlobalCommand {
88+ port : GlobalPortId ( 0 ) ,
89+ operation : lpm:: CommandData :: GetConnectorStatus ,
90+ } ) )
91+ . await
92+ . into ( ) ;
93+ let response = response. unwrap ( ) ;
94+ if !response. cci . cmd_complete ( ) || response. cci . error ( ) {
95+ error ! ( "Get connector status failed: {:?}" , response. cci) ;
96+ } else {
97+ info ! ( "Get connector status successful: {:?}" , response. data) ;
98+ }
99+
100+ info ! ( "Sending command complete ack..." ) ;
101+ let response: UcsiResponseResult =
102+ execute_ucsi_command ( Command :: PpmCommand ( ppm:: Command :: AckCcCi ( ppm:: ack_cc_ci:: Args {
103+ ack : * Ack :: default ( ) . set_command_complete ( true ) ,
104+ } ) ) )
105+ . await
106+ . into ( ) ;
107+ let response = response. unwrap ( ) ;
108+ if !response. cci . ack_command ( ) || response. cci . error ( ) {
109+ error ! ( "Sending command complete ack failed: {:?}" , response. cci) ;
110+ } else {
111+ info ! ( "Sending command complete ack successful" ) ;
51112 }
52113}
53114
0 commit comments