Browse Source

Added LED status code for default USB power

It's useful to know when only default USB power is available, as opposed
to when some mechanism for negotiating higher power is available but it
isn't possible to get high enough power.  This can let users know e.g.
using a USB A to C cable can't provide high power, potentially reducing
confusion.

The blink code for this is 1 7/8 s on, 1/8 s off.  I think this is
sufficiently unlike other blink patterns that it won't cause any
confusion.
Clara Hobbs 6 years ago
parent
commit
b4680ab723
6 changed files with 47 additions and 15 deletions
  1. 9
    8
      README.md
  2. 22
    6
      src/device_policy_manager.c
  3. 5
    0
      src/device_policy_manager.h
  4. 8
    0
      src/led.c
  5. 2
    0
      src/led.h
  6. 1
    1
      src/main.c

+ 9
- 8
README.md View File

@@ -184,11 +184,12 @@ leave its output turned off.
184 184
 
185 185
 ### Status LED descriptions
186 186
 
187
-LED State            | Mode  | Meaning
188
----------------------|-------|---------------------------------------------------
189
-Fast blink (4/sec)   | Sink  | Negotiating USB Power Delivery contract
190
-Medium blink (2/sec) | Sink  | USB Power Delivery contract established, output on
191
-Off                  | Sink  | Output on
192
-On                   | Sink  | Unable to get configured power from source
193
-Slow blink (1/sec)   | Setup | Running in setup mode
194
-Fast blink (4/sec)   | Setup | `identify` command run
187
+LED State                  | Mode  | Meaning
188
+---------------------------|-------|---------------------------------------------------
189
+Fast blink (4 blink/sec)   | Sink  | Negotiating USB Power Delivery contract
190
+Medium blink (2 blink/sec) | Sink  | USB Power Delivery contract established, output on
191
+Off                        | Sink  | Output on
192
+On                         | Sink  | Unable to get configured power from source
193
+Long blink (1 blink/2 sec) | Sink  | Only default USB power is available (e.g. powered with USB A to C cable)
194
+Slow blink (1 blink/sec)   | Setup | Running in setup mode
195
+Fast blink (4 blink/sec)   | Setup | `identify` command run

+ 22
- 6
src/device_policy_manager.c View File

@@ -387,7 +387,7 @@ void pdbs_dpm_pd_start(struct pdb_config *cfg)
387 387
 /*
388 388
  * Set the output state, with LED indication.
389 389
  */
390
-static void dpm_output_set(struct pdbs_dpm_data *dpm_data, bool state)
390
+static void dpm_output_set(struct pdbs_dpm_data *dpm_data, bool state, bool led)
391 391
 {
392 392
     /* Update the present voltage */
393 393
     dpm_data->_present_voltage = dpm_data->_requested_voltage;
@@ -395,13 +395,13 @@ static void dpm_output_set(struct pdbs_dpm_data *dpm_data, bool state)
395 395
     /* Set the power output */
396 396
     if (state && dpm_data->output_enabled) {
397 397
         /* Turn the output on */
398
-        if (dpm_data->led_pd_status) {
398
+        if (dpm_data->led_pd_status && led) {
399 399
             chEvtSignal(pdbs_led_thread, PDBS_EVT_LED_OUTPUT_ON);
400 400
         }
401 401
         palSetLine(LINE_OUT_CTRL);
402 402
     } else {
403 403
         /* Turn the output off */
404
-        if (dpm_data->led_pd_status) {
404
+        if (dpm_data->led_pd_status && led) {
405 405
             chEvtSignal(pdbs_led_thread, PDBS_EVT_LED_OUTPUT_OFF);
406 406
         }
407 407
         palClearLine(LINE_OUT_CTRL);
@@ -416,12 +416,12 @@ void pdbs_dpm_transition_default(struct pdb_config *cfg)
416 416
     /* Pretend we requested 5 V */
417 417
     dpm_data->_requested_voltage = 5000;
418 418
     /* Turn the output off */
419
-    dpm_output_set(cfg->dpm_data, false);
419
+    dpm_output_set(cfg->dpm_data, false, true);
420 420
 }
421 421
 
422 422
 void pdbs_dpm_transition_min(struct pdb_config *cfg)
423 423
 {
424
-    dpm_output_set(cfg->dpm_data, false);
424
+    dpm_output_set(cfg->dpm_data, false, true);
425 425
 }
426 426
 
427 427
 void pdbs_dpm_transition_standby(struct pdb_config *cfg)
@@ -443,5 +443,21 @@ void pdbs_dpm_transition_requested(struct pdb_config *cfg)
443 443
     /* Cast the dpm_data to the right type */
444 444
     struct pdbs_dpm_data *dpm_data = cfg->dpm_data;
445 445
 
446
-    dpm_output_set(cfg->dpm_data, dpm_data->_capability_match);
446
+    dpm_output_set(cfg->dpm_data, dpm_data->_capability_match, true);
447
+}
448
+
449
+void pdbs_dpm_transition_typec(struct pdb_config *cfg)
450
+{
451
+    /* Cast the dpm_data to the right type */
452
+    struct pdbs_dpm_data *dpm_data = cfg->dpm_data;
453
+
454
+    /* If we only have default Type-C Current, set a special LED status */
455
+    if (dpm_data->led_pd_status
456
+            && dpm_data->typec_current == fusb_tcc_default) {
457
+        chEvtSignal(pdbs_led_thread, PDBS_EVT_LED_OUTPUT_OFF_NO_TYPEC);
458
+    }
459
+
460
+    /* Set the output, only setting the LED status if it wasn't set above */
461
+    dpm_output_set(cfg->dpm_data, dpm_data->_capability_match,
462
+            dpm_data->typec_current != fusb_tcc_default);
447 463
 }

+ 5
- 0
src/device_policy_manager.h View File

@@ -100,5 +100,10 @@ void pdbs_dpm_transition_standby(struct pdb_config *cfg);
100 100
  */
101 101
 void pdbs_dpm_transition_requested(struct pdb_config *cfg);
102 102
 
103
+/*
104
+ * Transition to the Type-C Current power level
105
+ */
106
+void pdbs_dpm_transition_typec(struct pdb_config *cfg);
107
+
103 108
 
104 109
 #endif /* PDBS_DEVICE_POLICY_MANAGER_H */

+ 8
- 0
src/led.c View File

@@ -101,6 +101,14 @@ static THD_FUNCTION(LED, arg) {
101 101
                     palToggleLine(LINE_LED);
102 102
                 }
103 103
                 break;
104
+            case PDBS_EVT_LED_LONG_BLINK:
105
+                timeout = LED_FAST;
106
+                if (i % 16 == 0) {
107
+                    palClearLine(LINE_LED);
108
+                } else {
109
+                    palSetLine(LINE_LED);
110
+                }
111
+                break;
104 112
             case PDBS_EVT_LED_FAST_BLINK_SLOW:
105 113
                 timeout = LED_FAST;
106 114
                 if (i == 0) {

+ 2
- 0
src/led.h View File

@@ -29,6 +29,7 @@
29 29
 #define PDBS_EVT_LED_MEDIUM_BLINK_OFF EVENT_MASK(3)
30 30
 #define PDBS_EVT_LED_SLOW_BLINK EVENT_MASK(4)
31 31
 #define PDBS_EVT_LED_FAST_BLINK_SLOW EVENT_MASK(5)
32
+#define PDBS_EVT_LED_LONG_BLINK EVENT_MASK(6)
32 33
 
33 34
 /* Semantic LED event names */
34 35
 #define PDBS_EVT_LED_CONFIG PDBS_EVT_LED_SLOW_BLINK
@@ -36,6 +37,7 @@
36 37
 #define PDBS_EVT_LED_NEGOTIATING PDBS_EVT_LED_FAST_BLINK
37 38
 #define PDBS_EVT_LED_OUTPUT_ON PDBS_EVT_LED_MEDIUM_BLINK_OFF
38 39
 #define PDBS_EVT_LED_OUTPUT_OFF PDBS_EVT_LED_ON
40
+#define PDBS_EVT_LED_OUTPUT_OFF_NO_TYPEC PDBS_EVT_LED_LONG_BLINK
39 41
 
40 42
 /* The LED thread object */
41 43
 extern thread_t *pdbs_led_thread;

+ 1
- 1
src/main.c View File

@@ -85,7 +85,7 @@ static struct pdb_config pdb_config = {
85 85
         pdbs_dpm_transition_min,
86 86
         pdbs_dpm_transition_standby,
87 87
         pdbs_dpm_transition_requested,
88
-        pdbs_dpm_transition_requested, /* transition_typec */
88
+        pdbs_dpm_transition_typec,
89 89
         NULL /* not_supported_received */
90 90
     },
91 91
     .dpm_data = &dpm_data

Loading…
Cancel
Save