Ver código fonte

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 anos atrás
pai
commit
ceb4736209
2 arquivos alterados com 30 adições e 5 exclusões
  1. 26
    3
      src/config.h
  2. 4
    2
      src/shell.c

+ 26
- 3
src/config.h Ver arquivo

28
  * PD Buddy Sink configuration structure
28
  * PD Buddy Sink configuration structure
29
  */
29
  */
30
 struct pdbs_config {
30
 struct pdbs_config {
31
+    /* Status halfword, used to indicate which config objects can be written to
32
+     * and which one is valid. */
31
     uint16_t status;
33
     uint16_t status;
34
+    /* Flags halfword for miscellaneous small fields. */
32
     uint16_t flags;
35
     uint16_t flags;
36
+    /* Preferred voltage. */
33
     uint16_t v;
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
     uint16_t vmin;
48
     uint16_t vmin;
49
+    /* Upper end of voltage range. */
36
     uint16_t vmax;
50
     uint16_t vmax;
51
+    /* Extra bytes reserved for future use. */
37
     uint16_t _reserved[2];
52
     uint16_t _reserved[2];
38
 } __attribute__((packed));
53
 } __attribute__((packed));
39
 
54
 
47
 
62
 
48
 /* Flags for configuration structures. */
63
 /* Flags for configuration structures. */
49
 /* GiveBack supported */
64
 /* GiveBack supported */
50
-#define PDBS_CONFIG_FLAGS_GIVEBACK 0x0001
65
+#define PDBS_CONFIG_FLAGS_GIVEBACK (1 << 0)
51
 /* Variable and battery PDOs preferred (FIXME: not implemented) */
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
 /* Flash configuration array */
78
 /* Flash configuration array */

+ 4
- 2
src/shell.c Ver arquivo

256
         return;
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
 static void cmd_toggle_giveback(BaseSequentialStream *chp, int argc, char *argv[])
265
 static void cmd_toggle_giveback(BaseSequentialStream *chp, int argc, char *argv[])

Carregando…
Cancelar
Salvar