Browse Source

Pretty print PPS APDOs from get_source_cap

Clara Hobbs 7 years ago
parent
commit
c29813d8f6
2 changed files with 30 additions and 2 deletions
  1. 8
    2
      lib/include/pd.h
  2. 22
    0
      src/shell.c

+ 8
- 2
lib/include/pd.h View File

331
 #define PD_PDV_V(pdv) ((pdv) / 20)
331
 #define PD_PDV_V(pdv) ((pdv) / 20)
332
 #define PD_PDV_CV(pdv) (5 * ((pdv) % 20))
332
 #define PD_PDV_CV(pdv) (5 * ((pdv) % 20))
333
 
333
 
334
+#define PD_PAV_V(pav) ((pav) / 10)
335
+#define PD_PAV_CV(pav) (10 * ((pav) % 10))
336
+
334
 /* Get portions of a PD current in more normal units */
337
 /* Get portions of a PD current in more normal units */
335
-#define PD_PDI_A(pdv) ((pdv) / 100)
336
-#define PD_PDI_CA(pdv) ((pdv) % 100)
338
+#define PD_PDI_A(pdi) ((pdi) / 100)
339
+#define PD_PDI_CA(pdi) ((pdi) % 100)
340
+
341
+#define PD_PAI_A(pai) ((pai) / 20)
342
+#define PD_PAI_CA(pai) (5 * ((pai) % 20))
337
 
343
 
338
 /*
344
 /*
339
  * Unit constants
345
  * Unit constants

+ 22
- 0
src/shell.c View File

110
     chprintf(chp, "\ti: %d.%02d A\r\n", PD_PDI_A(tmp), PD_PDI_CA(tmp));
110
     chprintf(chp, "\ti: %d.%02d A\r\n", PD_PDI_A(tmp), PD_PDI_CA(tmp));
111
 }
111
 }
112
 
112
 
113
+static void print_src_pps_apdo(BaseSequentialStream *chp, uint32_t pdo)
114
+{
115
+    int tmp;
116
+
117
+    chprintf(chp, "pps\r\n");
118
+
119
+    /* Minimum voltage */
120
+    tmp = (pdo & PD_APDO_SRC_PPS_MIN_VOLTAGE) >> PD_APDO_SRC_PPS_MIN_VOLTAGE_SHIFT;
121
+    chprintf(chp, "\tvmin: %d.%02d V\r\n", PD_PAV_V(tmp), PD_PAV_CV(tmp));
122
+
123
+    /* Maximum voltage */
124
+    tmp = (pdo & PD_APDO_SRC_PPS_MAX_VOLTAGE) >> PD_APDO_SRC_PPS_MAX_VOLTAGE_SHIFT;
125
+    chprintf(chp, "\tvmax: %d.%02d V\r\n", PD_PAV_V(tmp), PD_PAV_CV(tmp));
126
+
127
+    /* Maximum current */
128
+    tmp = (pdo & PD_APDO_SRC_PPS_CURRENT) >> PD_APDO_SRC_PPS_CURRENT_SHIFT;
129
+    chprintf(chp, "\ti: %d.%02d A\r\n", PD_PAI_A(tmp), PD_PAI_CA(tmp));
130
+}
131
+
113
 static void print_src_pdo(BaseSequentialStream *chp, uint32_t pdo, uint8_t index)
132
 static void print_src_pdo(BaseSequentialStream *chp, uint32_t pdo, uint8_t index)
114
 {
133
 {
115
     /* If we have a positive index, print a label for the PDO */
134
     /* If we have a positive index, print a label for the PDO */
120
     /* Select the appropriate method for printing the PDO itself */
139
     /* Select the appropriate method for printing the PDO itself */
121
     if ((pdo & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) {
140
     if ((pdo & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) {
122
         print_src_fixed_pdo(chp, pdo);
141
         print_src_fixed_pdo(chp, pdo);
142
+    } else if ((pdo & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED
143
+            && (pdo & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) {
144
+        print_src_pps_apdo(chp, pdo);
123
     } else {
145
     } else {
124
         /* Unknown PDO, just print it as hex */
146
         /* Unknown PDO, just print it as hex */
125
         chprintf(chp, "%08X\r\n", pdo);
147
         chprintf(chp, "%08X\r\n", pdo);

Loading…
Cancel
Save