USB PD: Improve requesting fixed voltage function (#137)

thank you!
This commit is contained in:
tako 2024-09-30 10:30:02 +09:00 committed by GitHub
parent 4fb8a3fdc6
commit 1a6767a76b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

View File

@ -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++

View File

@ -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)
@ -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)

View File

@ -5,6 +5,7 @@
extern "C" {
#endif /* end of __cplusplus */
#include <stdbool.h>
#include "usbpd_def.h"
// Register Bit Definition
@ -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