Explorar el Código

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 hace 7 años
padre
commit
dd18e6a657
Se han modificado 3 ficheros con 23 adiciones y 4 borrados
  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 Ver fichero

@@ -28,6 +28,9 @@
28 28
 #include "fusb302b.h"
29 29
 
30 30
 
31
+bool pdb_dpm_led_pd_status = true;
32
+
33
+
31 34
 /* The current draw when the output is disabled */
32 35
 #define DPM_MIN_CURRENT PD_MA2PDI(100)
33 36
 
@@ -48,7 +51,9 @@ bool pdb_dpm_evaluate_capability(const union pd_msg *capabilities, union pd_msg
48 51
     uint8_t numobj = PD_NUMOBJ_GET(capabilities);
49 52
 
50 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 58
     /* Get whether or not the power supply is constrained */
54 59
     dpm_unconstrained_power = capabilities->obj[0] & PD_PDO_SRC_FIXED_UNCONSTRAINED;
@@ -189,7 +194,9 @@ bool pdb_dpm_evaluate_typec_current(void)
189 194
 
190 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 202
 void pdb_dpm_sink_standby(void)
@@ -211,11 +218,15 @@ void pdb_dpm_output_set(bool state)
211 218
     /* Set the power output */
212 219
     if (state) {
213 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 224
         palSetLine(LINE_OUT_CTRL);
216 225
     } else {
217 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 230
         palClearLine(LINE_OUT_CTRL);
220 231
     }
221 232
 }

+ 4
- 0
src/device_policy_manager.h Ver fichero

@@ -24,6 +24,10 @@
24 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 32
  * Create a Request message based on the given Source_Capabilities message.
29 33
  *

+ 4
- 0
src/main.c Ver fichero

@@ -42,6 +42,7 @@
42 42
 
43 43
 #include "priorities.h"
44 44
 #include "led.h"
45
+#include "device_policy_manager.h"
45 46
 #include "policy_engine.h"
46 47
 #include "protocol_tx.h"
47 48
 #include "protocol_rx.h"
@@ -89,6 +90,9 @@ static void start_pd(void)
89 90
  */
90 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 96
     /* Start the USB Power Delivery threads */
93 97
     start_pd();
94 98
 

Loading…
Cancelar
Guardar