Browse Source

Check if 5 V is in the range for Type-C Current

Previously, we didn't make use of the voltage range when checking a
Type-C Current advertisement.  That was bad, since if e.g. we want 6 V,
with the range 5-7 V, we could get the power we want from Type-C
Current.

This commit makes the firmware test if the configured voltage range
contains 5 V, and if it does, allows use of Type-C Current.
Clara Hobbs 4 years ago
parent
commit
38615f6b1e
2 changed files with 6 additions and 4 deletions
  1. 3
    1
      lib/include/pd.h
  2. 3
    3
      src/device_policy_manager.c

+ 3
- 1
lib/include/pd.h View File

@@ -19,6 +19,8 @@
19 19
 #ifndef PDB_PD_H
20 20
 #define PDB_PD_H
21 21
 
22
+#include <stdint.h>
23
+
22 24
 #include <ch.h>
23 25
 
24 26
 
@@ -193,7 +195,7 @@
193 195
 #define PD_APDO_PPS_MIN_VOLTAGE_SET(v) (((v) << PD_APDO_PPS_MIN_VOLTAGE_SHIFT) & PD_APDO_PPS_MIN_VOLTAGE)
194 196
 
195 197
 /* PD Programmable Power Supply APDO current */
196
-#define PD_APDO_PPS_CURRENT_GET(pdo) (((pdo) & PD_APDO_PPS_CURRENT) >> PD_APDO_PPS_CURRENT_SHIFT)
198
+#define PD_APDO_PPS_CURRENT_GET(pdo) ((uint8_t) (((pdo) & PD_APDO_PPS_CURRENT) >> PD_APDO_PPS_CURRENT_SHIFT))
197 199
 
198 200
 #define PD_APDO_PPS_CURRENT_SET(i) (((i) << PD_APDO_PPS_CURRENT_SHIFT) & PD_APDO_PPS_CURRENT)
199 201
 

+ 3
- 3
src/device_policy_manager.c View File

@@ -340,14 +340,14 @@ bool pdbs_dpm_evaluate_typec_current(struct pdb_config *cfg,
340 340
 
341 341
     /* If we have no configuration or don't want 5 V, Type-C Current can't
342 342
      * possibly satisfy our needs */
343
-    /* TODO Check if 5 V is inside the voltage range */
344
-    if (scfg == NULL || PD_MV2PDV(scfg->v) != PD_MV2PDV(5000)) {
343
+    if (scfg == NULL || (scfg->v != 5000 && (scfg->vmin > 5000
344
+            || scfg->vmax < 5000))) {
345 345
         dpm_data->_capability_match = false;
346 346
         return false;
347 347
     }
348 348
 
349 349
     /* Get the current we want */
350
-    uint16_t current = dpm_get_current(scfg, scfg->v);
350
+    uint16_t current = dpm_get_current(scfg, 5000);
351 351
 
352 352
     /* If 1.5 A is available and we want no more than that, great. */
353 353
     if (tcc == fusb_tcc_1_5 && current <= 150) {

Loading…
Cancel
Save