mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
打包keil_MDK的工程
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
/* Private includes -----------------------------------------------------------*/
|
||||
|
||||
// includes
|
||||
// sys
|
||||
#include "tim.h"
|
||||
#include "adc.h"
|
||||
#include "i2c.h"
|
||||
|
||||
// user
|
||||
#include "user_TasksInit.h"
|
||||
|
||||
// bsp
|
||||
#include "key.h"
|
||||
#include "lcd.h"
|
||||
#include "lcd_init.h"
|
||||
#include "gate.h"
|
||||
#include "fusb302_dev.h"
|
||||
#include "BL24C02.h" // settings
|
||||
|
||||
// ui
|
||||
#include "lvgl.h"
|
||||
#include "lv_port_disp.h"
|
||||
#include "ui.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief hardwares init task
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
void HardwareInitTask(void *argument)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
vTaskSuspendAll();
|
||||
|
||||
// gate, for current flow route selection, high current by default
|
||||
Gate_Port_Init();
|
||||
flow_route_selection(HIGH_CUR);
|
||||
|
||||
// ADC sample start
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_raw_buffer, ADC_TIMES*2 * ADC_CHANNELS); /*启动ADC的DMA传输,配合定时器触发ADC转换 12位的ADC对应0-4095 */
|
||||
HAL_TIM_Base_Start(&htim2); /*开启定时器,用溢出时间来触发ADC*/
|
||||
|
||||
// PWM Start for LCD backlight
|
||||
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_3);
|
||||
|
||||
// beep
|
||||
// HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_4);
|
||||
|
||||
// key
|
||||
Key_Init();
|
||||
|
||||
// system settings from eeprom
|
||||
if(!EEPROM_Init_Check()) {
|
||||
EEPROM_SysSetting_Get();
|
||||
}
|
||||
|
||||
// FUSB CC pin dis connect
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET);
|
||||
|
||||
// FUSB302 init
|
||||
fusb302_dev_init();
|
||||
|
||||
// lcd
|
||||
// done in lvgl disp init
|
||||
|
||||
// tim5 for elapsed time (us)
|
||||
HAL_TIM_Base_Start(&htim5);
|
||||
|
||||
// ui
|
||||
// LVGL and disp init
|
||||
lv_init();
|
||||
lv_port_disp_init();
|
||||
ui_init();
|
||||
|
||||
xTaskResumeAll();
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/* Private includes -----------------------------------------------------------*/
|
||||
//includes
|
||||
#include "user_TasksInit.h"
|
||||
#include "main.h"
|
||||
#include "key.h"
|
||||
#include "beep.h"
|
||||
#include "BL24C02.h" // settings
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Key press check task
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
void KeyTask(void *argument)
|
||||
{
|
||||
key_event_t key_event;
|
||||
while(1)
|
||||
{
|
||||
if(Key_Scan(&key_event))
|
||||
{
|
||||
osMessageQueuePut(Key_MessageQueue, &key_event, 0, 1);
|
||||
// beep
|
||||
if(Sys_Get_KeySoundEnable())
|
||||
{
|
||||
beep_open();
|
||||
osDelay(50);
|
||||
beep_close();
|
||||
}
|
||||
}
|
||||
osDelay(10);
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/* Private includes -----------------------------------------------------------*/
|
||||
//includes
|
||||
|
||||
//bsp
|
||||
#include "key.h"
|
||||
|
||||
// tasks
|
||||
#include "user_TasksInit.h"
|
||||
#include "user_LVGLTask.h"
|
||||
|
||||
//gui
|
||||
#include "lvgl.h"
|
||||
#include "lv_lib_pm.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief FreeRTOS Tick Hook, to increase the LVGL tick
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void TaskTickHook(void)
|
||||
{
|
||||
//to increase the LVGL tick
|
||||
lv_tick_inc(1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief LVGL Handler task, to run the lvgl
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
void LvHandlerTask(void *argument)
|
||||
{
|
||||
key_event_t key_event;
|
||||
while(1)
|
||||
{
|
||||
if(osMessageQueueGet(Key_MessageQueue, &key_event, NULL, 1)==osOK) {
|
||||
lv_lib_pm_handle_key_event(&key_event);
|
||||
}
|
||||
lv_task_handler();
|
||||
osDelay(1);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/* Private includes -----------------------------------------------------------*/
|
||||
//includes
|
||||
#include "user_TasksInit.h"
|
||||
#include "user_MessageTask.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
#include "BL24C02.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief task for check the usart message
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
void MessageTask(void *argument)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
if(get_update_request()) {
|
||||
|
||||
// clear the flag
|
||||
set_update_request(false);
|
||||
// set the EEPROM flag
|
||||
EEPROM_UpdateCommand_Write(true);
|
||||
HAL_Delay(100);
|
||||
USER_USB_DEVICE_DeInit();
|
||||
// 给予PC足够的时间来识别设备断开
|
||||
HAL_Delay(500);
|
||||
// reset
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
osDelay(500);
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/* Private includes -----------------------------------------------------------*/
|
||||
//includes
|
||||
#include "user_TasksInit.h"
|
||||
#include "user_PDUFPTask.h"
|
||||
#include "main.h"
|
||||
#include "fusb302_dev.h"
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* 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 >= 5) { // 5秒超时
|
||||
ready = PD_EVT_PPS_FAILED;
|
||||
osMessageQueuePut(PD_handle_event_MsgQueue, &ready, 0, 1);
|
||||
time_count = 0;
|
||||
osTimerStop(PD_UFP_Task_timer_id);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET); // FUSB CC pin disconnect
|
||||
_pd_working_status = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief task for PD_UFP
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
void PDUFPTask(void *argument)
|
||||
{
|
||||
// 快充诱骗时需要另外一个端口也供电,因为快充口会有可能断电
|
||||
// 可以检测 status_power 来判断是否有PPS供电
|
||||
PD_command_msg_t ui_msg;
|
||||
// 创建定时器
|
||||
PD_UFP_Task_timer_id = osTimerNew(_timer_callback, osTimerPeriodic, NULL, NULL);
|
||||
while(1)
|
||||
{
|
||||
// 非阻塞获取消息
|
||||
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_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();
|
||||
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(_pd_working_status && ui_msg.event == PD_CMD_STOP) {
|
||||
// FUSB CC pin disconnect
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET);
|
||||
_pd_working_status = 0;
|
||||
|
||||
} 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), false);
|
||||
send_power_request();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(_pd_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);
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/* Private includes -----------------------------------------------------------*/
|
||||
//includes
|
||||
#include "user_TasksInit.h"
|
||||
//sys
|
||||
#include "sys.h"
|
||||
#include "stdio.h"
|
||||
|
||||
//bsp
|
||||
#include "key.h"
|
||||
|
||||
//gui
|
||||
#include "lvgl.h"
|
||||
#include "lv_lib_pm.h"
|
||||
|
||||
//tasks
|
||||
#include "user_HardwareInitTask.h"
|
||||
#include "user_LVGLTask.h"
|
||||
#include "user_PDUFPTask.h"
|
||||
#include "user_KeyTask.h"
|
||||
#include "user_MessageTask.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Timers --------------------------------------------------------------------*/
|
||||
osTimerId_t IdleTimerHandle;
|
||||
|
||||
|
||||
/* Tasks ---------------------------------------------------------------------*/
|
||||
// Hardwares initialization
|
||||
osThreadId_t HardwareInitTaskHandle;
|
||||
const osThreadAttr_t HardwareInitTask_attributes = {
|
||||
.name = "HardwareInitTask",
|
||||
.stack_size = 128 * 10,
|
||||
.priority = (osPriority_t) osPriorityHigh,
|
||||
};
|
||||
|
||||
// message task
|
||||
osThreadId_t MessageTaskHandle;
|
||||
const osThreadAttr_t MessageTask_attributes = {
|
||||
.name = "MessageTask",
|
||||
.stack_size = 128 * 1,
|
||||
.priority = (osPriority_t) osPriorityNormal2,
|
||||
};
|
||||
|
||||
// Key task
|
||||
osThreadId_t KeyTaskHandle;
|
||||
const osThreadAttr_t KeyTask_attributes = {
|
||||
.name = "KeyTask",
|
||||
.stack_size = 128 * 1,
|
||||
.priority = (osPriority_t) osPriorityNormal,
|
||||
};
|
||||
|
||||
// PDUFP task
|
||||
osThreadId_t PDUFPTaskHandle;
|
||||
const osThreadAttr_t PDUFPTask_attributes = {
|
||||
.name = "PDUFPTask",
|
||||
.stack_size = 128 * 5,
|
||||
.priority = (osPriority_t) osPriorityLow2,
|
||||
};
|
||||
|
||||
// LVGL Handler task
|
||||
osThreadId_t LvHandlerTaskHandle;
|
||||
const osThreadAttr_t LvHandlerTask_attributes = {
|
||||
.name = "LvHandlerTask",
|
||||
.stack_size = 128 * 24,
|
||||
.priority = (osPriority_t) osPriorityLow,
|
||||
};
|
||||
|
||||
|
||||
/* Message queues ------------------------------------------------------------*/
|
||||
// Key task 中发送出的按键信息的消息队列
|
||||
osMessageQueueId_t Key_MessageQueue;
|
||||
// UI layer发送给PDUFPTask任务的命令消息队列
|
||||
osMessageQueueId_t PD_cmd_MessageQueue;
|
||||
// PDUFPTask任务发送给UI层的通知处理情况的消息队列
|
||||
osMessageQueueId_t PD_handle_event_MsgQueue;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void LvHandlerTask(void *argument);
|
||||
|
||||
/**
|
||||
* @brief FreeRTOS initialization
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void User_Tasks_Init(void)
|
||||
{
|
||||
/* add mutexes, ... */
|
||||
|
||||
/* add semaphores, ... */
|
||||
|
||||
/* start timers, add new ones, ... */
|
||||
|
||||
/* add queues, ... */
|
||||
Key_MessageQueue = osMessageQueueNew(4, sizeof(key_event_t), NULL);
|
||||
PD_cmd_MessageQueue = osMessageQueueNew(4, sizeof(PD_command_msg_t), NULL);
|
||||
PD_handle_event_MsgQueue = osMessageQueueNew(4, 1, NULL); // uint8_t message
|
||||
|
||||
/* add threads, ... */
|
||||
HardwareInitTaskHandle = osThreadNew(HardwareInitTask, NULL, &HardwareInitTask_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);
|
||||
|
||||
/* add events, ... */
|
||||
|
||||
/* add others ... */
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user