Skip to content

Commit

Permalink
USB PD: Improve requesting fixed voltage function
Browse files Browse the repository at this point in the history
  • Loading branch information
tako0910 committed Aug 22, 2024
1 parent 273620c commit 3ad2522
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ void loop() {

if(usbpd_sink_get_ready())
{
usbpd_sink_set_request_fixed_voltage(setVoltage);
if(usbpd_sink_set_request_fixed_voltage(setVoltage) == false)
{
Serial.printf("unsupported voltage\r\n");
}
}

// button, myIndex++
Expand Down
7 changes: 4 additions & 3 deletions libraries/USBPD_SINK/src/usbpd_sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void usbpd_sink_clear_ready(void)
pdControl_g.cc_USBPD_READY = 0;
}

void usbpd_sink_set_request_fixed_voltage(Request_voltage_t requestVoltage)
bool usbpd_sink_set_request_fixed_voltage(Request_voltage_t requestVoltage)
{
uint16_t targetVoltage;
switch (requestVoltage)
Expand Down Expand Up @@ -73,11 +73,12 @@ void usbpd_sink_set_request_fixed_voltage(Request_voltage_t requestVoltage)
if(pdControl_g.cc_FixedSourceCap[i].Voltage == targetVoltage)
{
pdControl_g.cc_SetPDONum = i+1;
return;
return true;
}
}
pdControl_g.cc_SetPDONum = (pdControl_g.cc_SourcePDONum - pdControl_g.cc_SourcePPSNum);

// unsupported voltage
return false;
}

void timer3_init(uint16_t arr, uint16_t psc)
Expand Down
3 changes: 2 additions & 1 deletion libraries/USBPD_SINK/src/usbpd_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
extern "C" {
#endif /* end of __cplusplus */

#include <stdbool.h>
#include "usbpd_def.h"

// Register Bit Definition
Expand Down Expand Up @@ -201,7 +202,7 @@ void usbpd_sink_process(void);
uint8_t usbpd_sink_get_ready(void);
void usbpd_sink_clear_ready(void);

void usbpd_sink_set_request_fixed_voltage(Request_voltage_t requestVoltage);
bool usbpd_sink_set_request_fixed_voltage(Request_voltage_t requestVoltage);


#ifdef __cplusplus
Expand Down

0 comments on commit 3ad2522

Please sign in to comment.