Browse Source

Allow the DPM to not control the LED

The DPM used to always set the LED to indicate the PD status.  This
caused fighting when the PD threads were run simultaneously with the
shell, making the LED show different things depending on what commands
the user ran.  Not cool!

This commit adds a bool pdb_dpm_led_pd_status, which prevents the DPM
from setting the LED when set to false.  This commit also sets it to
false before starting the PD threads in Setup mode, allowing the shell
to be in full control of the LED.  Right on!
Clara Hobbs 7 years ago
parent
commit
dd18e6a657
3 changed files with 23 additions and 4 deletions
  1. 15
    4
      src/device_policy_manager.c
  2. 4
    0
      src/device_policy_manager.h
  3. 4
    0
      src/main.c

+ 15
- 4
src/device_policy_manager.c View File

28
 #include "fusb302b.h"
28
 #include "fusb302b.h"
29
 
29
 
30
 
30
 
31
+bool pdb_dpm_led_pd_status = true;
32
+
33
+
31
 /* The current draw when the output is disabled */
34
 /* The current draw when the output is disabled */
32
 #define DPM_MIN_CURRENT PD_MA2PDI(100)
35
 #define DPM_MIN_CURRENT PD_MA2PDI(100)
33
 
36
 
48
     uint8_t numobj = PD_NUMOBJ_GET(capabilities);
51
     uint8_t numobj = PD_NUMOBJ_GET(capabilities);
49
 
52
 
50
     /* Make the LED blink to indicate ongoing power negotiations */
53
     /* Make the LED blink to indicate ongoing power negotiations */
51
-    chEvtSignal(pdb_led_thread, PDB_EVT_LED_NEGOTIATING);
54
+    if (pdb_dpm_led_pd_status) {
55
+        chEvtSignal(pdb_led_thread, PDB_EVT_LED_NEGOTIATING);
56
+    }
52
 
57
 
53
     /* Get whether or not the power supply is constrained */
58
     /* Get whether or not the power supply is constrained */
54
     dpm_unconstrained_power = capabilities->obj[0] & PD_PDO_SRC_FIXED_UNCONSTRAINED;
59
     dpm_unconstrained_power = capabilities->obj[0] & PD_PDO_SRC_FIXED_UNCONSTRAINED;
189
 
194
 
190
 void pdb_dpm_pd_start(void)
195
 void pdb_dpm_pd_start(void)
191
 {
196
 {
192
-    chEvtSignal(pdb_led_thread, PDB_EVT_LED_NEGOTIATING);
197
+    if (pdb_dpm_led_pd_status) {
198
+        chEvtSignal(pdb_led_thread, PDB_EVT_LED_NEGOTIATING);
199
+    }
193
 }
200
 }
194
 
201
 
195
 void pdb_dpm_sink_standby(void)
202
 void pdb_dpm_sink_standby(void)
211
     /* Set the power output */
218
     /* Set the power output */
212
     if (state) {
219
     if (state) {
213
         /* Turn the output on */
220
         /* Turn the output on */
214
-        chEvtSignal(pdb_led_thread, PDB_EVT_LED_OUTPUT_ON);
221
+        if (pdb_dpm_led_pd_status) {
222
+            chEvtSignal(pdb_led_thread, PDB_EVT_LED_OUTPUT_ON);
223
+        }
215
         palSetLine(LINE_OUT_CTRL);
224
         palSetLine(LINE_OUT_CTRL);
216
     } else {
225
     } else {
217
         /* Turn the output off */
226
         /* Turn the output off */
218
-        chEvtSignal(pdb_led_thread, PDB_EVT_LED_OUTPUT_OFF);
227
+        if (pdb_dpm_led_pd_status) {
228
+            chEvtSignal(pdb_led_thread, PDB_EVT_LED_OUTPUT_OFF);
229
+        }
219
         palClearLine(LINE_OUT_CTRL);
230
         palClearLine(LINE_OUT_CTRL);
220
     }
231
     }
221
 }
232
 }

+ 4
- 0
src/device_policy_manager.h View File

24
 #include "messages.h"
24
 #include "messages.h"
25
 
25
 
26
 
26
 
27
+/* Whether the DPM sets the LED to indicate the PD status */
28
+extern bool pdb_dpm_led_pd_status;
29
+
30
+
27
 /*
31
 /*
28
  * Create a Request message based on the given Source_Capabilities message.
32
  * Create a Request message based on the given Source_Capabilities message.
29
  *
33
  *

+ 4
- 0
src/main.c View File

42
 
42
 
43
 #include "priorities.h"
43
 #include "priorities.h"
44
 #include "led.h"
44
 #include "led.h"
45
+#include "device_policy_manager.h"
45
 #include "policy_engine.h"
46
 #include "policy_engine.h"
46
 #include "protocol_tx.h"
47
 #include "protocol_tx.h"
47
 #include "protocol_rx.h"
48
 #include "protocol_rx.h"
89
  */
90
  */
90
 static void setup(void)
91
 static void setup(void)
91
 {
92
 {
93
+    /* Set the DPM to not set the LED to show PD status */
94
+    pdb_dpm_led_pd_status = false;
95
+
92
     /* Start the USB Power Delivery threads */
96
     /* Start the USB Power Delivery threads */
93
     start_pd();
97
     start_pd();
94
 
98
 

Loading…
Cancel
Save