Browse Source

Add new flag macros, clear flags with discretion

Firmware 1.2.0 will have more configuration flags than previous
versions.  This commit adds macros for those flags.  There's also a
field added to the flags halfword that says whether a current, power, or
resistance is configured, so this commit makes the clear_flags command
not modify that field.
Clara Hobbs 7 years ago
parent
commit
ceb4736209
2 changed files with 30 additions and 5 deletions
  1. 26
    3
      src/config.h
  2. 4
    2
      src/shell.c

+ 26
- 3
src/config.h View File

@@ -28,12 +28,27 @@
28 28
  * PD Buddy Sink configuration structure
29 29
  */
30 30
 struct pdbs_config {
31
+    /* Status halfword, used to indicate which config objects can be written to
32
+     * and which one is valid. */
31 33
     uint16_t status;
34
+    /* Flags halfword for miscellaneous small fields. */
32 35
     uint16_t flags;
36
+    /* Preferred voltage. */
33 37
     uint16_t v;
34
-    uint16_t i;
38
+    /* Union for specifying how much current to request. */
39
+    union {
40
+        /* Required current. */
41
+        uint16_t i;
42
+        /* Required power. */
43
+        uint16_t p;
44
+        /* Value of resistive load. */
45
+        uint16_t r;
46
+    };
47
+    /* Lower end of voltage range. */
35 48
     uint16_t vmin;
49
+    /* Upper end of voltage range. */
36 50
     uint16_t vmax;
51
+    /* Extra bytes reserved for future use. */
37 52
     uint16_t _reserved[2];
38 53
 } __attribute__((packed));
39 54
 
@@ -47,9 +62,17 @@ struct pdbs_config {
47 62
 
48 63
 /* Flags for configuration structures. */
49 64
 /* GiveBack supported */
50
-#define PDBS_CONFIG_FLAGS_GIVEBACK 0x0001
65
+#define PDBS_CONFIG_FLAGS_GIVEBACK (1 << 0)
51 66
 /* Variable and battery PDOs preferred (FIXME: not implemented) */
52
-#define PDBS_CONFIG_FLAGS_VAR_BAT 0x0002
67
+#define PDBS_CONFIG_FLAGS_VAR_BAT (1 << 1)
68
+/* High voltages preferred */
69
+#define PDBS_CONFIG_FLAGS_HV_PREFERRED (1 << 2)
70
+/* Current definition type */
71
+#define PDBS_CONFIG_FLAGS_CURRENT_DEFN_SHIFT 3
72
+#define PDBS_CONFIG_FLAGS_CURRENT_DEFN (0x3 << PDBS_CONFIG_FLAGS_CURRENT_DEFN_SHIFT)
73
+#define PDBS_CONFIG_FLAGS_CURRENT_DEFN_I (0 << PDBS_CONFIG_FLAGS_CURRENT_DEFN_SHIFT)
74
+#define PDBS_CONFIG_FLAGS_CURRENT_DEFN_P (1 << PDBS_CONFIG_FLAGS_CURRENT_DEFN_SHIFT)
75
+#define PDBS_CONFIG_FLAGS_CURRENT_DEFN_R (2 << PDBS_CONFIG_FLAGS_CURRENT_DEFN_SHIFT)
53 76
 
54 77
 
55 78
 /* Flash configuration array */

+ 4
- 2
src/shell.c View File

@@ -256,8 +256,10 @@ static void cmd_clear_flags(BaseSequentialStream *chp, int argc, char *argv[])
256 256
         return;
257 257
     }
258 258
 
259
-    /* Clear all flags */
260
-    tmpcfg.flags = 0;
259
+    /* Clear all flags that can be toggled with toggle_* commands */
260
+    tmpcfg.flags &= ~PDBS_CONFIG_FLAGS_GIVEBACK
261
+        & ~PDBS_CONFIG_FLAGS_VAR_BAT
262
+        & PDBS_CONFIG_FLAGS_HV_PREFERRED;
261 263
 }
262 264
 
263 265
 static void cmd_toggle_giveback(BaseSequentialStream *chp, int argc, char *argv[])

Loading…
Cancel
Save