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 6 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,7 +25,6 @@
25 25
 #include "led.h"
26 26
 #include "storage.h"
27 27
 #include "pd.h"
28
-#include "fusb302b.h"
29 28
 
30 29
 
31 30
 bool pdb_dpm_output_enabled = true;
@@ -33,6 +32,7 @@ bool pdb_dpm_led_pd_status = true;
33 32
 bool pdb_dpm_usb_comms = false;
34 33
 
35 34
 const union pd_msg *pdb_dpm_capabilities = NULL;
35
+enum fusb_typec_current pdb_dpm_typec_current = None;
36 36
 
37 37
 
38 38
 /* The current draw when the output is disabled */
@@ -200,21 +200,21 @@ bool pdb_dpm_evaluate_typec_current(void)
200 200
     /* We don't control the voltage anymore; it will always be 5 V. */
201 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 206
     /* If we have no configuration or don't want 5 V, Type-C Current can't
204 207
      * possibly satisfy our needs */
205 208
     if (cfg == NULL || cfg->v != PD_MV2PDV(5000)) {
206 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 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 214
         return true;
215 215
     }
216 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 218
         return true;
219 219
     }
220 220
     /* We're overly cautious if USB default current is available, since that

+ 4
- 0
src/device_policy_manager.h View File

@@ -21,6 +21,7 @@
21 21
 
22 22
 #include <stdbool.h>
23 23
 
24
+#include "fusb302b.h"
24 25
 #include "messages.h"
25 26
 
26 27
 
@@ -36,6 +37,9 @@ extern bool pdb_dpm_usb_comms;
36 37
 /* The most recently received Source_Capabilities message */
37 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 45
  * Create a Request message based on the given Source_Capabilities message.  If

+ 18
- 3
src/shell.c View File

@@ -351,10 +351,25 @@ static void cmd_get_source_cap(BaseSequentialStream *chp, int argc, char *argv[]
351 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 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 375
     /* Print all the PDOs */

Loading…
Cancel
Save