Skip to content

Commit 1a6767a

Browse files
authored
USB PD: Improve requesting fixed voltage function (openwch#137)
thank you!
1 parent 4fb8a3f commit 1a6767a

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Diff for: libraries/USBPD_SINK/examples/usbpd_sink_request_voltage/usbpd_sink_request_voltage.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ void loop() {
2020

2121
if(usbpd_sink_get_ready())
2222
{
23-
usbpd_sink_set_request_fixed_voltage(setVoltage);
23+
if(usbpd_sink_set_request_fixed_voltage(setVoltage) == false)
24+
{
25+
Serial.printf("unsupported voltage\r\n");
26+
}
2427
}
2528

2629
// button, myIndex++

Diff for: libraries/USBPD_SINK/src/usbpd_sink.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void usbpd_sink_clear_ready(void)
3838
pdControl_g.cc_USBPD_READY = 0;
3939
}
4040

41-
void usbpd_sink_set_request_fixed_voltage(Request_voltage_t requestVoltage)
41+
bool usbpd_sink_set_request_fixed_voltage(Request_voltage_t requestVoltage)
4242
{
4343
uint16_t targetVoltage;
4444
switch (requestVoltage)
@@ -73,11 +73,12 @@ void usbpd_sink_set_request_fixed_voltage(Request_voltage_t requestVoltage)
7373
if(pdControl_g.cc_FixedSourceCap[i].Voltage == targetVoltage)
7474
{
7575
pdControl_g.cc_SetPDONum = i+1;
76-
return;
76+
return true;
7777
}
7878
}
79-
pdControl_g.cc_SetPDONum = (pdControl_g.cc_SourcePDONum - pdControl_g.cc_SourcePPSNum);
8079

80+
// unsupported voltage
81+
return false;
8182
}
8283

8384
void timer3_init(uint16_t arr, uint16_t psc)

Diff for: libraries/USBPD_SINK/src/usbpd_sink.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
extern "C" {
66
#endif /* end of __cplusplus */
77

8+
#include <stdbool.h>
89
#include "usbpd_def.h"
910

1011
// Register Bit Definition
@@ -201,7 +202,7 @@ void usbpd_sink_process(void);
201202
uint8_t usbpd_sink_get_ready(void);
202203
void usbpd_sink_clear_ready(void);
203204

204-
void usbpd_sink_set_request_fixed_voltage(Request_voltage_t requestVoltage);
205+
bool usbpd_sink_set_request_fixed_voltage(Request_voltage_t requestVoltage);
205206

206207

207208
#ifdef __cplusplus

0 commit comments

Comments
 (0)