Browse Source

Implement the typec_virtual PDO

The received Type-C Current advertisement is now kept in a global
variable which can be read by the command shell.  When there are no PD
capabilities but there is Type-C Current, the typec_virtual PDO is
reported as the one and only PDO.
Clara Hobbs 7 years ago
parent
commit
99ddfc08c9
3 changed files with 28 additions and 9 deletions
  1. 6
    6
      src/device_policy_manager.c
  2. 4
    0
      src/device_policy_manager.h
  3. 18
    3
      src/shell.c

+ 6
- 6
src/device_policy_manager.c View File

25
 #include "led.h"
25
 #include "led.h"
26
 #include "storage.h"
26
 #include "storage.h"
27
 #include "pd.h"
27
 #include "pd.h"
28
-#include "fusb302b.h"
29
 
28
 
30
 
29
 
31
 bool pdb_dpm_output_enabled = true;
30
 bool pdb_dpm_output_enabled = true;
33
 bool pdb_dpm_usb_comms = false;
32
 bool pdb_dpm_usb_comms = false;
34
 
33
 
35
 const union pd_msg *pdb_dpm_capabilities = NULL;
34
 const union pd_msg *pdb_dpm_capabilities = NULL;
35
+enum fusb_typec_current pdb_dpm_typec_current = None;
36
 
36
 
37
 
37
 
38
 /* The current draw when the output is disabled */
38
 /* The current draw when the output is disabled */
200
     /* We don't control the voltage anymore; it will always be 5 V. */
200
     /* We don't control the voltage anymore; it will always be 5 V. */
201
     dpm_requested_voltage = PD_MV2PDV(5000);
201
     dpm_requested_voltage = PD_MV2PDV(5000);
202
 
202
 
203
+    /* Get the present Type-C Current advertisement */
204
+    pdb_dpm_typec_current = fusb_get_typec_current();
205
+
203
     /* If we have no configuration or don't want 5 V, Type-C Current can't
206
     /* If we have no configuration or don't want 5 V, Type-C Current can't
204
      * possibly satisfy our needs */
207
      * possibly satisfy our needs */
205
     if (cfg == NULL || cfg->v != PD_MV2PDV(5000)) {
208
     if (cfg == NULL || cfg->v != PD_MV2PDV(5000)) {
206
         return false;
209
         return false;
207
     }
210
     }
208
 
211
 
209
-    /* Get the present Type-C Current advertisement */
210
-    enum fusb_typec_current tcc = fusb_get_typec_current();
211
-
212
     /* If 1.5 A is available and we want no more than that, great. */
212
     /* If 1.5 A is available and we want no more than that, great. */
213
-    if (tcc == OnePointFiveAmps && cfg->i <= 150) {
213
+    if (pdb_dpm_typec_current == OnePointFiveAmps && cfg->i <= 150) {
214
         return true;
214
         return true;
215
     }
215
     }
216
     /* If 3 A is available and we want no more than that, that's great too. */
216
     /* If 3 A is available and we want no more than that, that's great too. */
217
-    if (tcc == ThreePointZeroAmps && cfg->i <= 300) {
217
+    if (pdb_dpm_typec_current == ThreePointZeroAmps && cfg->i <= 300) {
218
         return true;
218
         return true;
219
     }
219
     }
220
     /* We're overly cautious if USB default current is available, since that
220
     /* We're overly cautious if USB default current is available, since that

+ 4
- 0
src/device_policy_manager.h View File

21
 
21
 
22
 #include <stdbool.h>
22
 #include <stdbool.h>
23
 
23
 
24
+#include "fusb302b.h"
24
 #include "messages.h"
25
 #include "messages.h"
25
 
26
 
26
 
27
 
36
 /* The most recently received Source_Capabilities message */
37
 /* The most recently received Source_Capabilities message */
37
 extern const union pd_msg *pdb_dpm_capabilities;
38
 extern const union pd_msg *pdb_dpm_capabilities;
38
 
39
 
40
+/* The most recently received Type-C Current advertisement */
41
+extern enum fusb_typec_current pdb_dpm_typec_current;
42
+
39
 
43
 
40
 /*
44
 /*
41
  * Create a Request message based on the given Source_Capabilities message.  If
45
  * Create a Request message based on the given Source_Capabilities message.  If

+ 18
- 3
src/shell.c View File

351
         return;
351
         return;
352
     }
352
     }
353
 
353
 
354
-    /* If we haven't seen any Source_Capabilities yet, bail out now */
354
+    /* If we haven't seen any Source_Capabilities */
355
     if (pdb_dpm_capabilities == NULL) {
355
     if (pdb_dpm_capabilities == NULL) {
356
-        chprintf(chp, "No Source_Capabilities\r\n");
357
-        return;
356
+        /* Have we started reading Type-C Current advertisements? */
357
+        if (pdb_dpm_typec_current != None) {
358
+            /* Type-C Current is available, so report it */
359
+            chprintf(chp, "PDO 1: typec_virtual\r\n");
360
+            if (pdb_dpm_typec_current == Default) {
361
+                chprintf(chp, "\ti: 0.50 A\r\n");
362
+            } else if (pdb_dpm_typec_current == OnePointFiveAmps) {
363
+                chprintf(chp, "\ti: 1.50 A\r\n");
364
+            } else if (pdb_dpm_typec_current == ThreePointZeroAmps) {
365
+                chprintf(chp, "\ti: 3.00 A\r\n");
366
+            }
367
+            return;
368
+        } else {
369
+            /* No Type-C Current, so report no capabilities */
370
+            chprintf(chp, "No Source_Capabilities\r\n");
371
+            return;
372
+        }
358
     }
373
     }
359
 
374
 
360
     /* Print all the PDOs */
375
     /* Print all the PDOs */

Loading…
Cancel
Save