mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
更换串口为USB
This commit is contained in:
@@ -62,8 +62,7 @@ static void _flush_timer_cb(void) {
|
||||
char buf[5];
|
||||
float voltage = 0.0;
|
||||
float current = 0.0;
|
||||
current = ui_get_current(); // uA
|
||||
voltage = ui_get_voltage(); // V
|
||||
ui_get_vol_cur(&voltage, ¤t);
|
||||
sprintf(buf, "%.2f", voltage);
|
||||
lv_label_set_text(ui_LabelPPSVol, buf);
|
||||
sprintf(buf, "%.2f", current/1000000.0); // 转换为 A
|
||||
|
||||
@@ -130,8 +130,7 @@ static void _flush_timer_cb()
|
||||
{
|
||||
float voltage = 0.0;
|
||||
float current = 0.0;
|
||||
current = ui_get_current();
|
||||
voltage = ui_get_voltage();
|
||||
ui_get_vol_cur(&voltage, ¤t);
|
||||
set_val_cur_label(voltage, current);
|
||||
}
|
||||
|
||||
@@ -250,7 +249,7 @@ void ui_main_screen_init(void)
|
||||
lv_obj_set_style_text_font(ui_LabelTime, &ui_font_HeiTi48, LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
_flush_timer_cb(NULL);
|
||||
// flush timer
|
||||
_flush_timer = lv_timer_create(_flush_timer_cb, 500, NULL);
|
||||
_flush_timer = lv_timer_create(_flush_timer_cb, 250, NULL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@ static void main_timer_cb(lv_timer_t * timer)
|
||||
{
|
||||
// 1s 刷新一次全屏,防止有时候不知什么原因的LCD刷新错误(需要后续找到问题从根本解决不知是不是屏幕本身问题)
|
||||
ui_full_screen_refresh(lv_screen_active());
|
||||
ui_GetElapsedTime_HMS(NULL, NULL, NULL); // 更新经过时间计数器
|
||||
}
|
||||
|
||||
////////////////////////// Animation //////////////////////
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "BL24C02.h" // system settings
|
||||
#include "tim.h" // elapsed time
|
||||
#include "data_queue.h" // bsp/data_queue.h for voltage/current queues
|
||||
#include "adc.h" // for voltage/current minitor
|
||||
#include "user_PDUFPTask.h" // comunicate with PD UFP Task
|
||||
|
||||
#include "./ui_helpers.h"
|
||||
@@ -27,10 +27,7 @@ uint64_t ui_GetElaspseMicroseconds(void) {
|
||||
|
||||
// 获取经过的时间, 单位为时分秒, 必须定时运行以更新32位计数器溢出
|
||||
void ui_GetElapsedTime_HMS(uint8_t *hours, uint8_t *minutes, uint8_t *seconds) {
|
||||
// 1. 更新64位计数器
|
||||
UpdateMicrosecondCounter();
|
||||
|
||||
// 2. 基于更新后的64位计数值进行计算
|
||||
uint64_t total_us = GetMicrosecondCounter();
|
||||
uint32_t total_seconds = total_us / 1000000;
|
||||
|
||||
@@ -61,12 +58,9 @@ uint16_t ui_get_display_rotation(void) {
|
||||
return Sys_Get_Rotation();
|
||||
}
|
||||
|
||||
float ui_get_voltage(void) {
|
||||
return queue_average(global_voltage_queue);
|
||||
}
|
||||
|
||||
float ui_get_current(void) {
|
||||
return queue_average(global_current_queue);
|
||||
// 获取当前电压, 单位 V; 当前电流, 单位 uA
|
||||
void ui_get_vol_cur(float *voltage, float *current) {
|
||||
Data_Monitor_Get_Values(voltage, current);
|
||||
}
|
||||
|
||||
//////////////// set functions ///////////////
|
||||
@@ -91,6 +85,10 @@ void ui_set_display_rotation(uint16_t rotation) {
|
||||
Sys_Set_Rotation(rotation);
|
||||
}
|
||||
|
||||
void ui_clear_data_monitor(void) {
|
||||
Data_Monitor_Clear();
|
||||
}
|
||||
|
||||
//////////////// sys save functions ///////////////
|
||||
void ui_system_settings_save(void) {
|
||||
EEPROM_SysSetting_Save();
|
||||
|
||||
@@ -19,14 +19,13 @@ void ui_full_screen_refresh(lv_obj_t * screen);
|
||||
|
||||
// get functions
|
||||
|
||||
uint64_t ui_GetElapsedMicroseconds(void);
|
||||
uint64_t ui_GetElaspseMicroseconds(void);
|
||||
void ui_GetElapsedTime_HMS(uint8_t *hours, uint8_t *minutes, uint8_t *seconds);
|
||||
uint8_t ui_get_back_light_level(void);
|
||||
bool ui_get_key_sound_enable(void);
|
||||
uint8_t ui_get_language_select(void);
|
||||
uint16_t ui_get_display_rotation(void);
|
||||
float ui_get_voltage(void);
|
||||
float ui_get_current(void);
|
||||
void ui_get_vol_cur(float *voltage, float *current);
|
||||
|
||||
// set functions
|
||||
|
||||
@@ -35,6 +34,7 @@ void ui_set_back_light_level(uint8_t level);
|
||||
void ui_set_key_sound_enable(bool enable);
|
||||
void ui_set_language_select(uint8_t lang);
|
||||
void ui_set_display_rotation(uint16_t rotation);
|
||||
void ui_clear_data_monitor(void);
|
||||
|
||||
// sys save function
|
||||
void ui_system_settings_save(void);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
// includes
|
||||
// sys
|
||||
#include "usart.h"
|
||||
#include "tim.h"
|
||||
#include "stm32f4xx_it.h"
|
||||
#include "adc.h"
|
||||
@@ -16,7 +15,6 @@
|
||||
#include "lcd.h"
|
||||
#include "lcd_init.h"
|
||||
#include "gate.h"
|
||||
#include "data_queue.h"
|
||||
#include "fusb302_dev.h"
|
||||
#include "BL24C02.h" // settings
|
||||
|
||||
@@ -45,32 +43,12 @@ void HardwareInitTask(void *argument)
|
||||
{
|
||||
vTaskSuspendAll();
|
||||
|
||||
// uart start
|
||||
HAL_UART_Receive_DMA(&huart6, (uint8_t*)uart_receive_buf, USART_RX_BUFFER_SIZE);
|
||||
__HAL_UART_ENABLE_IT(&huart6, UART_IT_IDLE);
|
||||
//
|
||||
UART6_TX_Send((uint8_t *)"power-pico\r\n", 13);
|
||||
|
||||
// queue for voltage and current
|
||||
global_voltage_queue = queue_create(32);
|
||||
global_current_queue = queue_create(32);
|
||||
for(int i = 0; i < 32; i++) {
|
||||
queue_push(global_voltage_queue, 0.0);
|
||||
queue_push(global_current_queue, 0.0);
|
||||
}
|
||||
|
||||
// adc packet init
|
||||
adc_packet.header[0] = 0x55;
|
||||
adc_packet.header[1] = 0xAA;
|
||||
// 填充模式位
|
||||
adc_packet.header[2] = 0x03;
|
||||
|
||||
// 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_packet.data, ADC_TIMES * ADC_CHANELS); /*启动ADC的DMA传输,配合定时器触发ADC转换 12位的ADC对应0-4095 */
|
||||
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
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//includes
|
||||
#include "user_TasksInit.h"
|
||||
#include "user_MessageTask.h"
|
||||
#include "usart.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
#include "BL24C02.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -23,21 +23,15 @@ void MessageTask(void *argument)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
if(uart_receive_flag == 1) {
|
||||
if(get_update_request()) {
|
||||
|
||||
// clear the flag
|
||||
uart_receive_flag = 0;
|
||||
// check the received message is "update\r\n" ?
|
||||
if(strcmp((const char *)uart_receive_buf, "update\r\n") == 0) {
|
||||
// send response
|
||||
UART6_TX_Send((uint8_t *)"start update\r\n", 14);
|
||||
EEPROM_UpdateCommand_Write(true);
|
||||
HAL_Delay(100);
|
||||
// reset
|
||||
NVIC_SystemReset();
|
||||
} else {
|
||||
// do nothing
|
||||
}
|
||||
set_update_request(false);
|
||||
// set the EEPROM flag
|
||||
EEPROM_UpdateCommand_Write(true);
|
||||
HAL_Delay(100);
|
||||
// reset
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
osDelay(500);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user