ソースを参照

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年前
コミット
312a478303
2個のファイルの変更22行の追加14行の削除
  1. 4
    4
      lib/include/pdb_dpm.h
  2. 18
    10
      lib/src/policy_engine.c

+ 4
- 4
lib/include/pdb_dpm.h ファイルの表示

@@ -40,19 +40,19 @@ typedef bool (*pdb_dpm_tcc_func)(struct pdb_config *, enum fusb_typec_current);
40 40
  * PD Buddy firmware library device policy manager callback structure
41 41
  *
42 42
  * Optional functions may be set to NULL if the associated functionality is not
43
- * required. (TODO)
43
+ * required.
44 44
  */
45 45
 struct pdb_dpm_callbacks {
46 46
     pdb_dpm_eval_cap_func evaluate_capability;
47 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 50
     pdb_dpm_func pd_start; /* Optional */
51 51
     pdb_dpm_func transition_default;
52 52
     pdb_dpm_func transition_min; /* Optional if no GiveBack */
53 53
     pdb_dpm_func transition_standby;
54 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 ファイルの表示

@@ -49,8 +49,10 @@ static enum policy_engine_state pe_sink_startup(struct pdb_config *cfg)
49 49
 {
50 50
     /* We don't have an explicit contract currently */
51 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 57
     /* No need to reset the protocol layer here.  There are two ways into this
56 58
      * state: startup and exiting hard reset.  On startup, the protocol layer
@@ -357,7 +359,8 @@ static enum policy_engine_state pe_sink_ready(struct pdb_config *cfg)
357 359
             /* Handle GotoMin messages */
358 360
             } else if (PD_MSGTYPE_GET(cfg->pe._message) == PD_MSGTYPE_GOTOMIN
359 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 364
                     /* Transition to the minimum current level */
362 365
                     cfg->dpm.transition_min(cfg);
363 366
                     cfg->pe._min_power = true;
@@ -620,16 +623,21 @@ static enum policy_engine_state pe_sink_send_reject(struct pdb_config *cfg)
620 623
  */
621 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 641
     /* Wait tPDDebounce between measurements */
634 642
     chThdSleep(PD_T_PD_DEBOUNCE);
635 643
 

読み込み中…
キャンセル
保存