From d8bad6a24513ce4262f799371355281231b6901e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=90=83=E6=B2=B9=E7=82=B8=E9=B8=A1?= <1425962791@qq.com> Date: Fri, 5 Dec 2025 15:33:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5UI=E5=B1=82=E4=B8=8EPD?= =?UTF-8?q?=E8=AF=B1=E9=AA=97=E5=A4=84=E7=90=86=E4=BB=BB=E5=8A=A1=E7=9A=84?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E9=80=9A=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Power_Pico/User/GUI/screens/ui_SetPage.c | 17 ++++++++-- Power_Pico/User/Tasks/Inc/user_PDUFPTask.h | 24 +++++++++++++ Power_Pico/User/Tasks/Inc/user_TasksInit.h | 2 ++ Power_Pico/User/Tasks/Src/user_PDUFPTask.c | 39 +++++++++++++++++----- Power_Pico/User/Tasks/Src/user_TasksInit.c | 10 ++++-- 5 files changed, 79 insertions(+), 13 deletions(-) diff --git a/Power_Pico/User/GUI/screens/ui_SetPage.c b/Power_Pico/User/GUI/screens/ui_SetPage.c index 1216010..9260265 100644 --- a/Power_Pico/User/GUI/screens/ui_SetPage.c +++ b/Power_Pico/User/GUI/screens/ui_SetPage.c @@ -5,6 +5,8 @@ #include "../ui.h" #include "./ui_PPSPage.h" +// comunicate with PD UFP Task +#include "user_PDUFPTask.h" lv_obj_t * ui_SetPage = NULL; // backlight @@ -31,6 +33,8 @@ static lv_obj_t * ui_LabelPPS = NULL; static lv_obj_t * ui_PanelAbout = NULL; static lv_obj_t * ui_LabelAbout = NULL; +static lv_timer_t * setting_timer = NULL; + static lv_obj_t * panels[6]; // 存储所有 panel 的指针 static int current_panel_index = 0; // 当前选中的 panel 索引 @@ -133,7 +137,14 @@ void ui_set_page_key_handler(void *key_event) // PPS page case 4: - lv_lib_pm_goto("PPS Page", NULL); // 跳转到 PPS 页面 + // 发送开启PD诱骗的信号 + if (((key_event_t*)key_event)->id == KEY_ID_Y && ((key_event_t*)key_event)->type == KEY_EVT_CLICK) + { + PD_UI_MSG_t pd_ui_msg; + pd_ui_msg.event = PD_UI_EVT_START; + osMessageQueuePut(PD_UI_MessageQueue, &pd_ui_msg, 0, 5); + // lv_lib_pm_goto("PPS Page", NULL); + } break; // about case 5: @@ -340,5 +351,7 @@ void ui_SetPage_screen_init(void) void ui_SetPage_screen_destroy(void) { - + if(setting_timer) { + lv_timer_delete(setting_timer); + } } diff --git a/Power_Pico/User/Tasks/Inc/user_PDUFPTask.h b/Power_Pico/User/Tasks/Inc/user_PDUFPTask.h index 31e9864..31a9958 100644 --- a/Power_Pico/User/Tasks/Inc/user_PDUFPTask.h +++ b/Power_Pico/User/Tasks/Inc/user_PDUFPTask.h @@ -5,6 +5,30 @@ extern "C" { #endif +#include "user_TasksInit.h" + +// 定义UI层发送给PDUFPTask的PD诱骗系列的信号 // +typedef enum { + PD_UI_EVT_START = 0, + PD_UI_EVT_STOP, + PD_UI_EVT_SET_PPS, +} PD_UI_EVENT_t; + +// 定义PDUFPTask任务发送给UI的信号 // +typedef enum { + PD_TASK_EVT_PPS_READY = 0, + PD_TASK_EVT_PPS_FAILED, +} PD_TASK_EVENT_t; + +// UI层发送过来PDUFPTask任务消费的信号结构体 // +typedef struct +{ + PD_UI_EVENT_t event; + float set_voltage; + float set_current; +} PD_UI_MSG_t; + + void PDUFPTask(void *argument); diff --git a/Power_Pico/User/Tasks/Inc/user_TasksInit.h b/Power_Pico/User/Tasks/Inc/user_TasksInit.h index cb1b5e4..fea6da5 100644 --- a/Power_Pico/User/Tasks/Inc/user_TasksInit.h +++ b/Power_Pico/User/Tasks/Inc/user_TasksInit.h @@ -9,6 +9,8 @@ extern "C" { #include "cmsis_os.h" extern osMessageQueueId_t Key_MessageQueue; +extern osMessageQueueId_t PD_UI_MessageQueue; +extern osMessageQueueId_t PD_Task_MessageQueue; void User_Tasks_Init(void); void TaskTickHook(void); diff --git a/Power_Pico/User/Tasks/Src/user_PDUFPTask.c b/Power_Pico/User/Tasks/Src/user_PDUFPTask.c index 4a919f8..4d8e10e 100644 --- a/Power_Pico/User/Tasks/Src/user_PDUFPTask.c +++ b/Power_Pico/User/Tasks/Src/user_PDUFPTask.c @@ -20,20 +20,41 @@ void PDUFPTask(void *argument) { // 快充诱骗时需要另外一个端口也供电,因为快充口会有可能断电 - // FUSB CC pin connect - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_SET); + // 可以检测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_protocol_set_PPS(&app_pd.protocol, PPS_V(5.0), PPS_A(1.0), false); - // 可以检测status_power来判断是否有PPS供电 while(1) { - if (fusb302_timer() || HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4) == GPIO_PIN_RESET) { - FUSB302_event_t FUSB302_events = 0; - for (uint8_t i = 0; i < 3 && FUSB302_alert(&fusb302_dev, &FUSB302_events) != FUSB302_SUCCESS; i++) {} - if (FUSB302_events) { - handle_FUSB302_event(FUSB302_events); + if(osMessageQueueGet(PD_UI_MessageQueue, &ui_msg, NULL, 1)==osOK) { + if(ui_msg.event == PD_UI_EVT_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 + send_power_request(); + _working_status = 1; + } else if(ui_msg.event == PD_UI_EVT_STOP) { + + } else if(ui_msg.event == PD_UI_EVT_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); + send_power_request(); } + } + } + if(_working_status) + { + if (fusb302_timer() || HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4) == GPIO_PIN_RESET) + { + FUSB302_event_t FUSB302_events = 0; + for (uint8_t i = 0; i < 3 && FUSB302_alert(&fusb302_dev, &FUSB302_events) != FUSB302_SUCCESS; i++) {} + if (FUSB302_events) { + handle_FUSB302_event(FUSB302_events); + } + } } osDelay(1); } diff --git a/Power_Pico/User/Tasks/Src/user_TasksInit.c b/Power_Pico/User/Tasks/Src/user_TasksInit.c index 3c2dd0c..ff261b7 100644 --- a/Power_Pico/User/Tasks/Src/user_TasksInit.c +++ b/Power_Pico/User/Tasks/Src/user_TasksInit.c @@ -74,8 +74,12 @@ const osThreadAttr_t LvHandlerTask_attributes = { /* Message queues ------------------------------------------------------------*/ -//Key message +// Key task 中发送出的按键信息的消息队列 osMessageQueueId_t Key_MessageQueue; +// UI layer发送给PDUFPTask任务的消息队列 +osMessageQueueId_t PD_UI_MessageQueue; +// PDUFPTask任务发送给UI层的消息队列 +osMessageQueueId_t PD_Task_MessageQueue; /* Private function prototypes -----------------------------------------------*/ void LvHandlerTask(void *argument); @@ -95,10 +99,12 @@ void User_Tasks_Init(void) /* add queues, ... */ Key_MessageQueue = osMessageQueueNew(4, sizeof(key_event_t), NULL); + PD_UI_MessageQueue = osMessageQueueNew(4, sizeof(PD_UI_MSG_t), NULL); + PD_Task_MessageQueue = osMessageQueueNew(4, 1, NULL); // uint8_t message /* add threads, ... */ HardwareInitTaskHandle = osThreadNew(HardwareInitTask, NULL, &HardwareInitTask_attributes); - // PDUFPTaskHandle = osThreadNew(PDUFPTask, NULL, &PDUFPTask_attributes); + PDUFPTaskHandle = osThreadNew(PDUFPTask, NULL, &PDUFPTask_attributes); KeyTaskHandle = osThreadNew(KeyTask, NULL, &KeyTask_attributes); MessageTaskHandle = osThreadNew(MessageTask, NULL, &MessageTask_attributes); LvHandlerTaskHandle = osThreadNew(LvHandlerTask, NULL, &LvHandlerTask_attributes);