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 5 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
 
184
 
185
 ### Status LED descriptions
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
 /*
387
 /*
388
  * Set the output state, with LED indication.
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
     /* Update the present voltage */
392
     /* Update the present voltage */
393
     dpm_data->_present_voltage = dpm_data->_requested_voltage;
393
     dpm_data->_present_voltage = dpm_data->_requested_voltage;
395
     /* Set the power output */
395
     /* Set the power output */
396
     if (state && dpm_data->output_enabled) {
396
     if (state && dpm_data->output_enabled) {
397
         /* Turn the output on */
397
         /* Turn the output on */
398
-        if (dpm_data->led_pd_status) {
398
+        if (dpm_data->led_pd_status && led) {
399
             chEvtSignal(pdbs_led_thread, PDBS_EVT_LED_OUTPUT_ON);
399
             chEvtSignal(pdbs_led_thread, PDBS_EVT_LED_OUTPUT_ON);
400
         }
400
         }
401
         palSetLine(LINE_OUT_CTRL);
401
         palSetLine(LINE_OUT_CTRL);
402
     } else {
402
     } else {
403
         /* Turn the output off */
403
         /* Turn the output off */
404
-        if (dpm_data->led_pd_status) {
404
+        if (dpm_data->led_pd_status && led) {
405
             chEvtSignal(pdbs_led_thread, PDBS_EVT_LED_OUTPUT_OFF);
405
             chEvtSignal(pdbs_led_thread, PDBS_EVT_LED_OUTPUT_OFF);
406
         }
406
         }
407
         palClearLine(LINE_OUT_CTRL);
407
         palClearLine(LINE_OUT_CTRL);
416
     /* Pretend we requested 5 V */
416
     /* Pretend we requested 5 V */
417
     dpm_data->_requested_voltage = 5000;
417
     dpm_data->_requested_voltage = 5000;
418
     /* Turn the output off */
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
 void pdbs_dpm_transition_min(struct pdb_config *cfg)
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
 void pdbs_dpm_transition_standby(struct pdb_config *cfg)
427
 void pdbs_dpm_transition_standby(struct pdb_config *cfg)
443
     /* Cast the dpm_data to the right type */
443
     /* Cast the dpm_data to the right type */
444
     struct pdbs_dpm_data *dpm_data = cfg->dpm_data;
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
  */
100
  */
101
 void pdbs_dpm_transition_requested(struct pdb_config *cfg);
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
 #endif /* PDBS_DEVICE_POLICY_MANAGER_H */
109
 #endif /* PDBS_DEVICE_POLICY_MANAGER_H */

+ 8
- 0
src/led.c View File

101
                     palToggleLine(LINE_LED);
101
                     palToggleLine(LINE_LED);
102
                 }
102
                 }
103
                 break;
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
             case PDBS_EVT_LED_FAST_BLINK_SLOW:
112
             case PDBS_EVT_LED_FAST_BLINK_SLOW:
105
                 timeout = LED_FAST;
113
                 timeout = LED_FAST;
106
                 if (i == 0) {
114
                 if (i == 0) {

+ 2
- 0
src/led.h View File

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

+ 1
- 1
src/main.c View File

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

Loading…
Cancel
Save