mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
加入UI层与PD诱骗处理任务的信号通信
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user