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 6 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
 #ifndef PDB_PD_H
19
 #ifndef PDB_PD_H
20
 #define PDB_PD_H
20
 #define PDB_PD_H
21
 
21
 
22
+#include <stdint.h>
23
+
22
 #include <ch.h>
24
 #include <ch.h>
23
 
25
 
24
 
26
 
193
 #define PD_APDO_PPS_MIN_VOLTAGE_SET(v) (((v) << PD_APDO_PPS_MIN_VOLTAGE_SHIFT) & PD_APDO_PPS_MIN_VOLTAGE)
195
 #define PD_APDO_PPS_MIN_VOLTAGE_SET(v) (((v) << PD_APDO_PPS_MIN_VOLTAGE_SHIFT) & PD_APDO_PPS_MIN_VOLTAGE)
194
 
196
 
195
 /* PD Programmable Power Supply APDO current */
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
 #define PD_APDO_PPS_CURRENT_SET(i) (((i) << PD_APDO_PPS_CURRENT_SHIFT) & PD_APDO_PPS_CURRENT)
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
 
340
 
341
     /* If we have no configuration or don't want 5 V, Type-C Current can't
341
     /* If we have no configuration or don't want 5 V, Type-C Current can't
342
      * possibly satisfy our needs */
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
         dpm_data->_capability_match = false;
345
         dpm_data->_capability_match = false;
346
         return false;
346
         return false;
347
     }
347
     }
348
 
348
 
349
     /* Get the current we want */
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
     /* If 1.5 A is available and we want no more than that, great. */
352
     /* If 1.5 A is available and we want no more than that, great. */
353
     if (tcc == fusb_tcc_1_5 && current <= 150) {
353
     if (tcc == fusb_tcc_1_5 && current <= 150) {

Loading…
Cancel
Save