2025-08-05 16:06:46 +08:00
|
|
|
|
/* Private includes -----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
// includes
|
|
|
|
|
|
// sys
|
|
|
|
|
|
#include "usart.h"
|
|
|
|
|
|
#include "tim.h"
|
|
|
|
|
|
#include "stm32f4xx_it.h"
|
2025-08-13 11:00:00 +08:00
|
|
|
|
#include "adc.h"
|
2025-09-27 19:11:39 +08:00
|
|
|
|
#include "rtc.h"
|
2025-10-14 16:24:47 +08:00
|
|
|
|
#include "i2c.h"
|
2025-08-05 16:06:46 +08:00
|
|
|
|
// user
|
|
|
|
|
|
#include "user_TasksInit.h"
|
|
|
|
|
|
|
|
|
|
|
|
// bsp
|
|
|
|
|
|
#include "key.h"
|
|
|
|
|
|
#include "lcd.h"
|
|
|
|
|
|
#include "lcd_init.h"
|
2025-08-13 11:00:00 +08:00
|
|
|
|
#include "gate.h"
|
2025-09-22 21:42:47 +08:00
|
|
|
|
#include "data_queue.h"
|
2025-10-14 16:24:47 +08:00
|
|
|
|
#include "fusb302_dev.h"
|
2025-10-18 19:23:22 +08:00
|
|
|
|
#include "BL24C02.h" // settings
|
2025-08-05 16:06:46 +08:00
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
2025-08-13 11:00:00 +08:00
|
|
|
|
// uart start
|
2025-10-19 11:58:49 +08:00
|
|
|
|
HAL_UART_Receive_DMA(&huart6, (uint8_t*)uart_receive_buf, USART_RX_BUFFER_SIZE);
|
2025-08-13 11:00:00 +08:00
|
|
|
|
__HAL_UART_ENABLE_IT(&huart6, UART_IT_IDLE);
|
|
|
|
|
|
//
|
|
|
|
|
|
UART6_TX_Send((uint8_t *)"power-pico\r\n", 13);
|
2025-08-18 14:13:43 +08:00
|
|
|
|
|
2025-09-22 21:42:47 +08:00
|
|
|
|
// queue for voltage and current
|
2025-10-18 11:25:33 +08:00
|
|
|
|
global_voltage_queue = queue_create(32);
|
|
|
|
|
|
global_current_queue = queue_create(32);
|
|
|
|
|
|
for(int i = 0; i < 32; i++) {
|
2025-10-15 10:25:22 +08:00
|
|
|
|
queue_push(global_voltage_queue, 0.0);
|
|
|
|
|
|
queue_push(global_current_queue, 0.0);
|
|
|
|
|
|
}
|
2025-08-18 14:13:43 +08:00
|
|
|
|
|
2025-09-22 21:42:47 +08:00
|
|
|
|
// adc packet init
|
2025-08-24 10:37:58 +08:00
|
|
|
|
adc_packet.header[0] = 0x55;
|
|
|
|
|
|
adc_packet.header[1] = 0xAA;
|
2025-09-11 16:34:17 +08:00
|
|
|
|
// 填充模式位
|
2025-09-14 18:47:02 +08:00
|
|
|
|
adc_packet.header[2] = 0x03;
|
2025-08-13 11:00:00 +08:00
|
|
|
|
|
|
|
|
|
|
// gate, for current flow route selection, high current by default
|
|
|
|
|
|
Gate_Port_Init();
|
|
|
|
|
|
flow_route_selection(HIGH_CUR);
|
2025-08-05 16:06:46 +08:00
|
|
|
|
|
2025-09-22 21:42:47 +08:00
|
|
|
|
// ADC sample start
|
|
|
|
|
|
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_packet.data, ADC_TIMES * ADC_CHANELS); /*启动ADC的DMA传输,配合定时器触发ADC转换 12位的ADC对应0-4095 */
|
|
|
|
|
|
HAL_TIM_Base_Start(&htim2); /*开启定时器,用溢出时间来触发ADC*/
|
|
|
|
|
|
|
2025-08-05 16:06:46 +08:00
|
|
|
|
// PWM Start for LCD backlight
|
|
|
|
|
|
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_3);
|
|
|
|
|
|
|
2025-08-18 14:13:43 +08:00
|
|
|
|
// beep
|
|
|
|
|
|
// HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_4);
|
|
|
|
|
|
|
2025-08-05 16:06:46 +08:00
|
|
|
|
// key
|
|
|
|
|
|
Key_Port_Init();
|
|
|
|
|
|
|
2025-10-18 19:23:22 +08:00
|
|
|
|
// system settings from eeprom
|
2025-10-19 12:13:15 +08:00
|
|
|
|
if(!EEPROM_Init_Check()) {
|
|
|
|
|
|
Sys_Setting_Get();
|
|
|
|
|
|
}
|
2025-10-18 19:23:22 +08:00
|
|
|
|
|
2025-10-15 10:25:22 +08:00
|
|
|
|
// FUSB CC pin dis connect
|
|
|
|
|
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET);
|
2025-10-14 16:24:47 +08:00
|
|
|
|
|
2025-08-05 16:06:46 +08:00
|
|
|
|
// lcd
|
|
|
|
|
|
// done in lvgl disp init
|
|
|
|
|
|
|
2025-09-27 19:11:39 +08:00
|
|
|
|
// rtc
|
|
|
|
|
|
SetReferenceTime();
|
|
|
|
|
|
|
2025-08-05 16:06:46 +08:00
|
|
|
|
// ui
|
|
|
|
|
|
// LVGL and disp init
|
|
|
|
|
|
lv_init();
|
|
|
|
|
|
lv_port_disp_init();
|
|
|
|
|
|
ui_init();
|
|
|
|
|
|
|
|
|
|
|
|
xTaskResumeAll();
|
|
|
|
|
|
vTaskDelete(NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|