Browse Source

Made the optional DPM functions actually optional

Now simple Sinks are easier to implement, as not all DPM functions have
to be provided.
Clara Hobbs 6 years ago
parent
commit
312a478303
2 changed files with 22 additions and 14 deletions
  1. 4
    4
      lib/include/pdb_dpm.h
  2. 18
    10
      lib/src/policy_engine.c

+ 4
- 4
lib/include/pdb_dpm.h View File

40
  * PD Buddy firmware library device policy manager callback structure
40
  * PD Buddy firmware library device policy manager callback structure
41
  *
41
  *
42
  * Optional functions may be set to NULL if the associated functionality is not
42
  * Optional functions may be set to NULL if the associated functionality is not
43
- * required. (TODO)
43
+ * required.
44
  */
44
  */
45
 struct pdb_dpm_callbacks {
45
 struct pdb_dpm_callbacks {
46
     pdb_dpm_eval_cap_func evaluate_capability;
46
     pdb_dpm_eval_cap_func evaluate_capability;
47
     pdb_dpm_get_sink_cap_func get_sink_capability;
47
     pdb_dpm_get_sink_cap_func get_sink_capability;
48
-    pdb_dpm_giveback_func giveback_enabled;
49
-    pdb_dpm_tcc_func evaluate_typec_current; /* Optional */
48
+    pdb_dpm_giveback_func giveback_enabled; /* Optional (missing means no GiveBack) */
49
+    pdb_dpm_tcc_func evaluate_typec_current; /* Optional (missing means no Type-C Current) */
50
     pdb_dpm_func pd_start; /* Optional */
50
     pdb_dpm_func pd_start; /* Optional */
51
     pdb_dpm_func transition_default;
51
     pdb_dpm_func transition_default;
52
     pdb_dpm_func transition_min; /* Optional if no GiveBack */
52
     pdb_dpm_func transition_min; /* Optional if no GiveBack */
53
     pdb_dpm_func transition_standby;
53
     pdb_dpm_func transition_standby;
54
     pdb_dpm_func transition_requested;
54
     pdb_dpm_func transition_requested;
55
-    pdb_dpm_func transition_typec; /* Optional */
55
+    pdb_dpm_func transition_typec; /* Optional if no Type-C Current */
56
 };
56
 };
57
 
57
 
58
 
58
 

+ 18
- 10
lib/src/policy_engine.c View File

49
 {
49
 {
50
     /* We don't have an explicit contract currently */
50
     /* We don't have an explicit contract currently */
51
     cfg->pe._explicit_contract = false;
51
     cfg->pe._explicit_contract = false;
52
-    /* Tell the DPM that we've started negotiations */
53
-    cfg->dpm.pd_start(cfg);
52
+    /* Tell the DPM that we've started negotiations, if it cares */
53
+    if (cfg->dpm.pd_start != NULL) {
54
+        cfg->dpm.pd_start(cfg);
55
+    }
54
 
56
 
55
     /* No need to reset the protocol layer here.  There are two ways into this
57
     /* No need to reset the protocol layer here.  There are two ways into this
56
      * state: startup and exiting hard reset.  On startup, the protocol layer
58
      * state: startup and exiting hard reset.  On startup, the protocol layer
357
             /* Handle GotoMin messages */
359
             /* Handle GotoMin messages */
358
             } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_GOTOMIN
360
             } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_GOTOMIN
359
                     && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
361
                     && PD_NUMOBJ_GET(cfg->pe._message) == 0) {
360
-                if (cfg->dpm.giveback_enabled(cfg)) {
362
+                if (cfg->dpm.giveback_enabled != NULL
363
+                        && cfg->dpm.giveback_enabled(cfg)) {
361
                     /* Transition to the minimum current level */
364
                     /* Transition to the minimum current level */
362
                     cfg->dpm.transition_min(cfg);
365
                     cfg->dpm.transition_min(cfg);
363
                     cfg->pe._min_power = true;
366
                     cfg->pe._min_power = true;
620
  */
623
  */
621
 static enum policy_engine_state pe_sink_source_unresponsive(struct pdb_config *cfg)
624
 static enum policy_engine_state pe_sink_source_unresponsive(struct pdb_config *cfg)
622
 {
625
 {
623
-    int tcc_match = cfg->dpm.evaluate_typec_current(cfg, fusb_get_typec_current(&cfg->fusb));
626
+    /* If the DPM can evaluate the Type-C Current advertisement */
627
+    if (cfg->dpm.evaluate_typec_current != NULL) {
628
+        /* Make the DPM evaluate the Type-C Current advertisement */
629
+        int tcc_match = cfg->dpm.evaluate_typec_current(cfg,
630
+                fusb_get_typec_current(&cfg->fusb));
631
+
632
+        /* If the last two readings are the same, set the output */
633
+        if (cfg->pe._old_tcc_match == tcc_match) {
634
+            cfg->dpm.transition_typec(cfg);
635
+        }
624
 
636
 
625
-    /* If the last two readings are the same, set the output */
626
-    if (cfg->pe._old_tcc_match == tcc_match) {
627
-        cfg->dpm.transition_typec(cfg);
637
+        /* Remember whether or not the last measurement succeeded */
638
+        cfg->pe._old_tcc_match = tcc_match;
628
     }
639
     }
629
 
640
 
630
-    /* Remember whether or not the last measurement succeeded */
631
-    cfg->pe._old_tcc_match = tcc_match;
632
-
633
     /* Wait tPDDebounce between measurements */
641
     /* Wait tPDDebounce between measurements */
634
     chThdSleep(PD_T_PD_DEBOUNCE);
642
     chThdSleep(PD_T_PD_DEBOUNCE);
635
 
643
 

Loading…
Cancel
Save