|
@@ -31,6 +31,12 @@
|
31
|
31
|
/* Whether or not the power supply is unconstrained */
|
32
|
32
|
static bool dpm_unconstrained_power;
|
33
|
33
|
|
|
34
|
+/* The last explicitly or implicitly negotiated voltage in PDV */
|
|
35
|
+static int dpm_present_voltage = PD_MV2PDV(5000);
|
|
36
|
+
|
|
37
|
+/* The requested voltage */
|
|
38
|
+static int dpm_requested_voltage;
|
|
39
|
+
|
34
|
40
|
bool pdb_dpm_evaluate_capability(const union pd_msg *capabilities, union pd_msg *request)
|
35
|
41
|
{
|
36
|
42
|
/* Get the current configuration */
|
|
@@ -63,6 +69,10 @@ bool pdb_dpm_evaluate_capability(const union pd_msg *capabilities, union pd_msg
|
63
|
69
|
request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(cfg->i)
|
64
|
70
|
| PD_RDO_FV_CURRENT_SET(cfg->i)
|
65
|
71
|
| PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(i + 1);
|
|
72
|
+
|
|
73
|
+ /* Update requested voltage */
|
|
74
|
+ dpm_requested_voltage = cfg->v;
|
|
75
|
+
|
66
|
76
|
return true;
|
67
|
77
|
}
|
68
|
78
|
}
|
|
@@ -74,6 +84,10 @@ bool pdb_dpm_evaluate_capability(const union pd_msg *capabilities, union pd_msg
|
74
|
84
|
| PD_RDO_FV_CURRENT_SET(10)
|
75
|
85
|
| PD_RDO_NO_USB_SUSPEND | PD_RDO_CAP_MISMATCH
|
76
|
86
|
| PD_RDO_OBJPOS_SET(1);
|
|
87
|
+
|
|
88
|
+ /* Update requested voltage */
|
|
89
|
+ dpm_requested_voltage = PD_MV2PDV(5000);
|
|
90
|
+
|
77
|
91
|
return false;
|
78
|
92
|
}
|
79
|
93
|
|
|
@@ -126,6 +140,9 @@ bool pdb_dpm_evaluate_typec_current(void)
|
126
|
140
|
cfg_set = true;
|
127
|
141
|
}
|
128
|
142
|
|
|
143
|
+ /* We don't control the voltage anymore; it will always be 5 V. */
|
|
144
|
+ dpm_requested_voltage = PD_MV2PDV(5000);
|
|
145
|
+
|
129
|
146
|
/* If we have no configuration or don't want 5 V, Type-C Current can't
|
130
|
147
|
* possibly satisfy our needs */
|
131
|
148
|
if (cfg == NULL || cfg->v != 100) {
|
|
@@ -156,14 +173,38 @@ void pdb_dpm_pd_start(void)
|
156
|
173
|
chEvtSignal(pdb_led_thread, PDB_EVT_LED_FAST_BLINK);
|
157
|
174
|
}
|
158
|
175
|
|
159
|
|
-void pdb_dpm_output_on(void)
|
|
176
|
+void pdb_dpm_sink_standby(void)
|
|
177
|
+{
|
|
178
|
+ /* If the voltage is changing, enter Sink Standby */
|
|
179
|
+ if (dpm_requested_voltage != dpm_present_voltage) {
|
|
180
|
+ /* For the PD Buddy Sink, entering Sink Standby is equivalent to
|
|
181
|
+ * turning the output off. However, we don't want to change the LED
|
|
182
|
+ * state for standby mode. */
|
|
183
|
+ palClearLine(LINE_OUT_CTRL);
|
|
184
|
+ }
|
|
185
|
+}
|
|
186
|
+
|
|
187
|
+void pdb_dpm_output_set(bool state)
|
160
|
188
|
{
|
161
|
|
- chEvtSignal(pdb_led_thread, PDB_EVT_LED_MEDIUM_BLINK_OFF);
|
162
|
|
- palSetLine(LINE_OUT_CTRL);
|
|
189
|
+ /* Update the present voltage */
|
|
190
|
+ dpm_present_voltage = dpm_requested_voltage;
|
|
191
|
+
|
|
192
|
+ /* Set the power output */
|
|
193
|
+ if (state) {
|
|
194
|
+ /* Turn the output on */
|
|
195
|
+ chEvtSignal(pdb_led_thread, PDB_EVT_LED_MEDIUM_BLINK_OFF);
|
|
196
|
+ palSetLine(LINE_OUT_CTRL);
|
|
197
|
+ } else {
|
|
198
|
+ /* Turn the output off */
|
|
199
|
+ chEvtSignal(pdb_led_thread, PDB_EVT_LED_ON);
|
|
200
|
+ palClearLine(LINE_OUT_CTRL);
|
|
201
|
+ }
|
163
|
202
|
}
|
164
|
203
|
|
165
|
|
-void pdb_dpm_output_off(void)
|
|
204
|
+void pdb_dpm_output_default(void)
|
166
|
205
|
{
|
167
|
|
- chEvtSignal(pdb_led_thread, PDB_EVT_LED_ON);
|
168
|
|
- palClearLine(LINE_OUT_CTRL);
|
|
206
|
+ /* Pretend we requested 5 V */
|
|
207
|
+ dpm_requested_voltage = PD_MV2PDV(5000);
|
|
208
|
+ /* Turn the output off */
|
|
209
|
+ pdb_dpm_output_set(false);
|
169
|
210
|
}
|