Browse Source

Read the Type-C Current in the PE, not the DPM

Now the call to fusb_get_typec_current is made in the policy engine,
then passed to pdb_dpm_evaluate_typec_current.  This is more consistent
with pdb_dpm_evaluate_capability, improving the PD Buddy DPM API.
That's right, I'm thinking about API design now for when I split the
code into a library and application.
Clara Hobbs 7 years ago
parent
commit
8ac55494f8
3 changed files with 9 additions and 7 deletions
  1. 6
    5
      src/device_policy_manager.c
  2. 1
    1
      src/device_policy_manager.h
  3. 2
    1
      src/policy_engine.c

+ 6
- 5
src/device_policy_manager.c View File

@@ -185,15 +185,16 @@ bool pdb_dpm_giveback_enabled(void)
185 185
     return cfg->flags & PDB_CONFIG_FLAGS_GIVEBACK;
186 186
 }
187 187
 
188
-bool pdb_dpm_evaluate_typec_current(void)
188
+bool pdb_dpm_evaluate_typec_current(enum fusb_typec_current tcc)
189 189
 {
190 190
     struct pdb_config *cfg = pdb_config_flash_read();
191 191
 
192 192
     /* We don't control the voltage anymore; it will always be 5 V. */
193 193
     dpm_requested_voltage = PD_MV2PDV(5000);
194 194
 
195
-    /* Get the present Type-C Current advertisement */
196
-    pdb_dpm_typec_current = fusb_get_typec_current();
195
+    /* Make the present Type-C Current advertisement available to the rest of
196
+     * the DPM */
197
+    pdb_dpm_typec_current = tcc;
197 198
 
198 199
     /* If we have no configuration or don't want 5 V, Type-C Current can't
199 200
      * possibly satisfy our needs */
@@ -202,11 +203,11 @@ bool pdb_dpm_evaluate_typec_current(void)
202 203
     }
203 204
 
204 205
     /* If 1.5 A is available and we want no more than that, great. */
205
-    if (pdb_dpm_typec_current == OnePointFiveAmps && cfg->i <= 150) {
206
+    if (tcc == OnePointFiveAmps && cfg->i <= 150) {
206 207
         return true;
207 208
     }
208 209
     /* If 3 A is available and we want no more than that, that's great too. */
209
-    if (pdb_dpm_typec_current == ThreePointZeroAmps && cfg->i <= 300) {
210
+    if (tcc == ThreePointZeroAmps && cfg->i <= 300) {
210 211
         return true;
211 212
     }
212 213
     /* We're overly cautious if USB default current is available, since that

+ 1
- 1
src/device_policy_manager.h View File

@@ -66,7 +66,7 @@ bool pdb_dpm_giveback_enabled(void);
66 66
  *
67 67
  * Returns true if sufficient power is available, false otherwise.
68 68
  */
69
-bool pdb_dpm_evaluate_typec_current(void);
69
+bool pdb_dpm_evaluate_typec_current(enum fusb_typec_current tcc);
70 70
 
71 71
 /*
72 72
  * Indicate that power negotiations are starting.

+ 2
- 1
src/policy_engine.c View File

@@ -25,6 +25,7 @@
25 25
 #include "device_policy_manager.h"
26 26
 #include "protocol_tx.h"
27 27
 #include "hard_reset.h"
28
+#include "fusb302b.h"
28 29
 #include "pd.h"
29 30
 
30 31
 
@@ -637,7 +638,7 @@ static enum policy_engine_state pe_sink_send_reject(void)
637 638
 static enum policy_engine_state pe_sink_source_unresponsive(void)
638 639
 {
639 640
     static int old_tcc_match = -1;
640
-    int tcc_match = pdb_dpm_evaluate_typec_current();
641
+    int tcc_match = pdb_dpm_evaluate_typec_current(fusb_get_typec_current());
641 642
 
642 643
     /* If the last two readings are the same, set the output */
643 644
     if (old_tcc_match == tcc_match) {

Loading…
Cancel
Save