加入PD快充诱骗

This commit is contained in:
不吃油炸鸡
2025-12-05 20:16:08 +08:00
parent 3f9f22e55c
commit 31578725f9
3 changed files with 136 additions and 27 deletions

View File

@@ -10,8 +10,29 @@
/* Private variables ---------------------------------------------------------*/
uint8_t _pd_working_status = 0;
osTimerId_t PD_UFP_Task_timer_id;
/* Private function prototypes -----------------------------------------------*/
static void _timer_callback(void *argument)
{
PD_handle_event_t ready;
static uint8_t time_count = 0;
time_count++;
if(is_PPS_ready()) {
ready = PD_EVT_PPS_READY;
osMessageQueuePut(PD_handle_event_MsgQueue, &ready, 0, 1);
time_count = 0;
osTimerStop(PD_UFP_Task_timer_id);
} else if(time_count >= 10) { // 5秒超时
ready = PD_EVT_PPS_FAILED;
osMessageQueuePut(PD_handle_event_MsgQueue, &ready, 0, 1);
time_count = 0;
osTimerStop(PD_UFP_Task_timer_id);
}
}
/**
* @brief task for PD_UFP
* @param argument: Not used
@@ -21,31 +42,40 @@ void PDUFPTask(void *argument)
{
// 快充诱骗时需要另外一个端口也供电,因为快充口会有可能断电
// 可以检测status_power来判断是否有PPS供电
PD_UI_MSG_t ui_msg;
uint8_t _working_status = 0;
// set
PD_protocol_set_power_option(&app_pd.protocol, PD_POWER_OPTION_MAX_20V);
PD_command_msg_t ui_msg;
// 创建定时器
PD_UFP_Task_timer_id = osTimerNew(_timer_callback, osTimerPeriodic, NULL, NULL);
while(1)
{
if(osMessageQueueGet(PD_UI_MessageQueue, &ui_msg, NULL, 1)==osOK) {
if(ui_msg.event == PD_UI_EVT_START) {
// 非阻塞获取消息
if(osMessageQueueGet(PD_cmd_MessageQueue, &ui_msg, NULL, 0)==osOK) {
if(!_pd_working_status && ui_msg.event == PD_CMD_START) {
// FUSB CC pin connect
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_SET);
PD_protocol_init(&app_pd.protocol);
PD_protocol_set_PPS(&app_pd.protocol, PPS_V(5.0), PPS_A(1.0), true); // 初始PPS 5V 1A
PD_protocol_set_power_option(&app_pd.protocol, PD_POWER_OPTION_MAX_5V);
PD_protocol_set_PPS(&app_pd.protocol, PPS_V(5.0), PPS_A(1.0), false); // 初始PPS 5V 1A
send_power_request();
_working_status = 1;
} else if(ui_msg.event == PD_UI_EVT_STOP) {
if(osTimerIsRunning(PD_UFP_Task_timer_id)) {
osTimerStop(PD_UFP_Task_timer_id);
}
osTimerStart(PD_UFP_Task_timer_id, 1000); // 1s
_pd_working_status = 1;
} else if(ui_msg.event == PD_UI_EVT_SET_PPS) {
} else if(_pd_working_status && ui_msg.event == PD_CMD_STOP) {
} else if(_pd_working_status && ui_msg.event == PD_CMD_SET_PPS) {
// 设置PPS电压电流
if(ui_msg.set_voltage > 0 && ui_msg.set_current > 0 && ui_msg.set_voltage <= 20.0 && ui_msg.set_current <= 5.0) {
PD_protocol_set_PPS(&app_pd.protocol, PPS_V(ui_msg.set_voltage), PPS_A(ui_msg.set_current), true);
PD_protocol_set_PPS(&app_pd.protocol, PPS_V(ui_msg.set_voltage), PPS_A(ui_msg.set_current), false);
send_power_request();
}
}
}
if(_working_status)
if(_pd_working_status)
{
if (fusb302_timer() || HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4) == GPIO_PIN_RESET)
{