删除测温ADC,更改加热引脚与状态跟初始电平,优化屏幕显示函数,增加 用UFT8转GBK的Python脚本,测试有效,实际使用待完善
This commit is contained in:
32
.mxproject
32
.mxproject
File diff suppressed because one or more lines are too long
@@ -1,52 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file adc.h
|
|
||||||
* @brief This file contains all the function prototypes for
|
|
||||||
* the adc.c file
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2026 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
|
||||||
#ifndef __ADC_H__
|
|
||||||
#define __ADC_H__
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
extern ADC_HandleTypeDef hadc1;
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Private defines */
|
|
||||||
|
|
||||||
/* USER CODE END Private defines */
|
|
||||||
|
|
||||||
void MX_ADC1_Init(void);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Prototypes */
|
|
||||||
|
|
||||||
/* USER CODE END Prototypes */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ADC_H__ */
|
|
||||||
|
|
||||||
127
Core/Inc/gbk_text.h
Normal file
127
Core/Inc/gbk_text.h
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
#ifndef __GBK_TEXT_H__
|
||||||
|
#define __GBK_TEXT_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// 对应文本(UTF8):智能按摩仪
|
||||||
|
// 对应GBK编码:0xD6, 0xC7, 0xC4, 0xDC, 0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xC7
|
||||||
|
const uint8_t text_device_name_GBK[] = {0xD6, 0xC7, 0xC4, 0xDC, 0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xC7};
|
||||||
|
#define text_device_name_LEN (sizeof(text_device_name_GBK))
|
||||||
|
#define text_device_name text_device_name_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):设备加载中请稍候
|
||||||
|
// 对应GBK编码:0xC9, 0xE8, 0xB1, 0xB8, 0xBC, 0xD3, 0xD4, 0xD8, 0xD6, 0xD0, 0xC7, 0xEB, 0xC9, 0xD4, 0xBA, 0xF2
|
||||||
|
const uint8_t text_device_loading_GBK[] = {0xC9, 0xE8, 0xB1, 0xB8, 0xBC, 0xD3, 0xD4, 0xD8, 0xD6, 0xD0, 0xC7, 0xEB, 0xC9, 0xD4, 0xBA, 0xF2};
|
||||||
|
#define text_device_loading_LEN (sizeof(text_device_loading_GBK))
|
||||||
|
#define text_device_loading text_device_loading_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):开始按摩
|
||||||
|
// 对应GBK编码:0xBF, 0xAA, 0xCA, 0xBC, 0xB0, 0xB4, 0xC4, 0xA6
|
||||||
|
const uint8_t text_start_massage_GBK[] = {0xBF, 0xAA, 0xCA, 0xBC, 0xB0, 0xB4, 0xC4, 0xA6};
|
||||||
|
#define text_start_massage_LEN (sizeof(text_start_massage_GBK))
|
||||||
|
#define text_start_massage text_start_massage_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):开始加热
|
||||||
|
// 对应GBK编码:0xBF, 0xAA, 0xCA, 0xBC, 0xBC, 0xD3, 0xC8, 0xC8
|
||||||
|
const uint8_t text_start_heating_GBK[] = {0xBF, 0xAA, 0xCA, 0xBC, 0xBC, 0xD3, 0xC8, 0xC8};
|
||||||
|
#define text_start_heating_LEN (sizeof(text_start_heating_GBK))
|
||||||
|
#define text_start_heating text_start_heating_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):停止按摩
|
||||||
|
// 对应GBK编码:0xCD, 0xA3, 0xD6, 0xB9, 0xB0, 0xB4, 0xC4, 0xA6
|
||||||
|
const uint8_t text_stop_massage_GBK[] = {0xCD, 0xA3, 0xD6, 0xB9, 0xB0, 0xB4, 0xC4, 0xA6};
|
||||||
|
#define text_stop_massage_LEN (sizeof(text_stop_massage_GBK))
|
||||||
|
#define text_stop_massage text_stop_massage_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):停止加热
|
||||||
|
// 对应GBK编码:0xCD, 0xA3, 0xD6, 0xB9, 0xBC, 0xD3, 0xC8, 0xC8
|
||||||
|
const uint8_t text_stop_heating_GBK[] = {0xCD, 0xA3, 0xD6, 0xB9, 0xBC, 0xD3, 0xC8, 0xC8};
|
||||||
|
#define text_stop_heating_LEN (sizeof(text_stop_heating_GBK))
|
||||||
|
#define text_stop_heating text_stop_heating_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):按摩档位:1级
|
||||||
|
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x31, 0xBC, 0xB6
|
||||||
|
const uint8_t text_massage_gear_1_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x31, 0xBC, 0xB6};
|
||||||
|
#define text_massage_gear_1_LEN (sizeof(text_massage_gear_1_GBK))
|
||||||
|
#define text_massage_gear_1 text_massage_gear_1_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):按摩档位:2级
|
||||||
|
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x32, 0xBC, 0xB6
|
||||||
|
const uint8_t text_massage_gear_2_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x32, 0xBC, 0xB6};
|
||||||
|
#define text_massage_gear_2_LEN (sizeof(text_massage_gear_2_GBK))
|
||||||
|
#define text_massage_gear_2 text_massage_gear_2_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):按摩档位:3级
|
||||||
|
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x33, 0xBC, 0xB6
|
||||||
|
const uint8_t text_massage_gear_3_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x33, 0xBC, 0xB6};
|
||||||
|
#define text_massage_gear_3_LEN (sizeof(text_massage_gear_3_GBK))
|
||||||
|
#define text_massage_gear_3 text_massage_gear_3_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):按摩时间:10分钟
|
||||||
|
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x31, 0x30, 0xB7, 0xD6, 0xD6, 0xD3
|
||||||
|
const uint8_t text_massage_time_10_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x31, 0x30, 0xB7, 0xD6, 0xD6, 0xD3};
|
||||||
|
#define text_massage_time_10_LEN (sizeof(text_massage_time_10_GBK))
|
||||||
|
#define text_massage_time_10 text_massage_time_10_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):按摩时间:15分钟
|
||||||
|
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x31, 0x35, 0xB7, 0xD6, 0xD6, 0xD3
|
||||||
|
const uint8_t text_massage_time_15_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x31, 0x35, 0xB7, 0xD6, 0xD6, 0xD3};
|
||||||
|
#define text_massage_time_15_LEN (sizeof(text_massage_time_15_GBK))
|
||||||
|
#define text_massage_time_15 text_massage_time_15_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):按摩时间:20分钟
|
||||||
|
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x32, 0x30, 0xB7, 0xD6, 0xD6, 0xD3
|
||||||
|
const uint8_t text_massage_time_20_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x32, 0x30, 0xB7, 0xD6, 0xD6, 0xD3};
|
||||||
|
#define text_massage_time_20_LEN (sizeof(text_massage_time_20_GBK))
|
||||||
|
#define text_massage_time_20 text_massage_time_20_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):按摩时间:30分钟
|
||||||
|
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x33, 0x30, 0xB7, 0xD6, 0xD6, 0xD3
|
||||||
|
const uint8_t text_massage_time_30_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x33, 0x30, 0xB7, 0xD6, 0xD6, 0xD3};
|
||||||
|
#define text_massage_time_30_LEN (sizeof(text_massage_time_30_GBK))
|
||||||
|
#define text_massage_time_30 text_massage_time_30_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):按摩时间:持续
|
||||||
|
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0xB3, 0xD6, 0xD0, 0xF8
|
||||||
|
const uint8_t text_massage_time_cont_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0xB3, 0xD6, 0xD0, 0xF8};
|
||||||
|
#define text_massage_time_cont_LEN (sizeof(text_massage_time_cont_GBK))
|
||||||
|
#define text_massage_time_cont text_massage_time_cont_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):剩余按摩时间为:%d
|
||||||
|
// 对应GBK编码:0xCA, 0xA3, 0xD3, 0xE0, 0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xCE, 0xAA, 0xA3, 0xBA, 0x25, 0x64
|
||||||
|
const uint8_t text_remaining_time_GBK[] = {0xCA, 0xA3, 0xD3, 0xE0, 0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xCE, 0xAA, 0xA3, 0xBA, 0x25, 0x64};
|
||||||
|
#define text_remaining_time_LEN (sizeof(text_remaining_time_GBK))
|
||||||
|
#define text_remaining_time text_remaining_time_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):加热已开启
|
||||||
|
// 对应GBK编码:0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xBF, 0xAA, 0xC6, 0xF4
|
||||||
|
const uint8_t text_heating_on_GBK[] = {0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xBF, 0xAA, 0xC6, 0xF4};
|
||||||
|
#define text_heating_on_LEN (sizeof(text_heating_on_GBK))
|
||||||
|
#define text_heating_on text_heating_on_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):加热已关闭
|
||||||
|
// 对应GBK编码:0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xB9, 0xD8, 0xB1, 0xD5
|
||||||
|
const uint8_t text_heating_off_GBK[] = {0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xB9, 0xD8, 0xB1, 0xD5};
|
||||||
|
#define text_heating_off_LEN (sizeof(text_heating_off_GBK))
|
||||||
|
#define text_heating_off text_heating_off_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):按摩中
|
||||||
|
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xD6, 0xD0
|
||||||
|
const uint8_t text_massage_running_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xD6, 0xD0};
|
||||||
|
#define text_massage_running_LEN (sizeof(text_massage_running_GBK))
|
||||||
|
#define text_massage_running text_massage_running_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):按摩已暂停
|
||||||
|
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xD4, 0xDD, 0xCD, 0xA3
|
||||||
|
const uint8_t text_massage_paused_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xD4, 0xDD, 0xCD, 0xA3};
|
||||||
|
#define text_massage_paused_LEN (sizeof(text_massage_paused_GBK))
|
||||||
|
#define text_massage_paused text_massage_paused_GBK
|
||||||
|
|
||||||
|
// 对应文本(UTF8):按摩已结束
|
||||||
|
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xBD, 0xE1, 0xCA, 0xF8
|
||||||
|
const uint8_t text_massage_ended_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xBD, 0xE1, 0xCA, 0xF8};
|
||||||
|
#define text_massage_ended_LEN (sizeof(text_massage_ended_GBK))
|
||||||
|
#define text_massage_ended text_massage_ended_GBK
|
||||||
|
|
||||||
|
|
||||||
|
#endif // __GBK_TEXT_H__
|
||||||
@@ -57,8 +57,6 @@ void Error_Handler(void);
|
|||||||
/* USER CODE END EFP */
|
/* USER CODE END EFP */
|
||||||
|
|
||||||
/* Private defines -----------------------------------------------------------*/
|
/* Private defines -----------------------------------------------------------*/
|
||||||
#define HOT_Pin GPIO_PIN_1
|
|
||||||
#define HOT_GPIO_Port GPIOA
|
|
||||||
#define RUN_LED_Pin GPIO_PIN_12
|
#define RUN_LED_Pin GPIO_PIN_12
|
||||||
#define RUN_LED_GPIO_Port GPIOB
|
#define RUN_LED_GPIO_Port GPIOB
|
||||||
#define ERR_LED_Pin GPIO_PIN_13
|
#define ERR_LED_Pin GPIO_PIN_13
|
||||||
@@ -71,6 +69,8 @@ void Error_Handler(void);
|
|||||||
#define HOT_KEY_GPIO_Port GPIOC
|
#define HOT_KEY_GPIO_Port GPIOC
|
||||||
#define TIME_KEY_Pin GPIO_PIN_9
|
#define TIME_KEY_Pin GPIO_PIN_9
|
||||||
#define TIME_KEY_GPIO_Port GPIOC
|
#define TIME_KEY_GPIO_Port GPIOC
|
||||||
|
#define HOT_Pin GPIO_PIN_8
|
||||||
|
#define HOT_GPIO_Port GPIOA
|
||||||
|
|
||||||
/* USER CODE BEGIN Private defines */
|
/* USER CODE BEGIN Private defines */
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ extern "C" {
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* 颜色使用统一的标志 */
|
||||||
|
#define TEXT_COLOR 15 /* 白色 */
|
||||||
|
#define BG_COLOR 0 /* 黑色 */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 发送原始命令字符串到屏幕(阻塞直到发送完成)
|
* @brief 发送原始命令字符串到屏幕(阻塞直到发送完成)
|
||||||
@@ -24,6 +29,7 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
int Screen_SendCmd(const char *cmd);
|
int Screen_SendCmd(const char *cmd);
|
||||||
|
|
||||||
|
void Screen_Init(void);
|
||||||
|
|
||||||
/* 常用封装 - 简短说明见各函数 */
|
/* 常用封装 - 简短说明见各函数 */
|
||||||
/** 清屏,layer: 要清除的层号(通常为0) */
|
/** 清屏,layer: 要清除的层号(通常为0) */
|
||||||
@@ -47,7 +53,7 @@ void Screen_BoxFill(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t
|
|||||||
void Screen_Circle(uint16_t x, uint16_t y, uint16_t r, uint8_t color);
|
void Screen_Circle(uint16_t x, uint16_t y, uint16_t r, uint8_t color);
|
||||||
void Screen_CircleFill(uint16_t x, uint16_t y, uint16_t r, uint8_t color);
|
void Screen_CircleFill(uint16_t x, uint16_t y, uint16_t r, uint8_t color);
|
||||||
void Screen_SetBGColor(uint8_t color);
|
void Screen_SetBGColor(uint8_t color);
|
||||||
|
void Screen_DrawText16V_GBK(uint16_t x, uint16_t y, const uint8_t *gbk_buf, uint16_t gbk_len, uint8_t color);
|
||||||
/* 带/不带背景的文本 */
|
/* 带/不带背景的文本 */
|
||||||
void Screen_DrawText16V(uint16_t x, uint16_t y, const char *text, uint8_t color);
|
void Screen_DrawText16V(uint16_t x, uint16_t y, const char *text, uint8_t color);
|
||||||
void Screen_DrawText24(uint16_t x, uint16_t y, const char *text, uint8_t color);
|
void Screen_DrawText24(uint16_t x, uint16_t y, const char *text, uint8_t color);
|
||||||
@@ -66,6 +72,19 @@ void Screen_QRCodeEx(uint16_t x, uint16_t y, const char *url, uint16_t size, uin
|
|||||||
/* 版本信息 */
|
/* 版本信息 */
|
||||||
void Screen_Ver(void);
|
void Screen_Ver(void);
|
||||||
|
|
||||||
|
// GBK
|
||||||
|
void Screen_DrawText16_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||||
|
void Screen_DrawText16V_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||||
|
|
||||||
|
void Screen_DrawText24_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||||
|
void Screen_DrawText24V_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||||
|
|
||||||
|
void Screen_DrawText32_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||||
|
void Screen_DrawText32V_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||||
|
|
||||||
|
void Screen_DrawText48_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color,uint8_t transparent);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define HAL_MODULE_ENABLED
|
#define HAL_MODULE_ENABLED
|
||||||
#define HAL_ADC_MODULE_ENABLED
|
/*#define HAL_ADC_MODULE_ENABLED */
|
||||||
/*#define HAL_CRYP_MODULE_ENABLED */
|
/*#define HAL_CRYP_MODULE_ENABLED */
|
||||||
/*#define HAL_CAN_MODULE_ENABLED */
|
/*#define HAL_CAN_MODULE_ENABLED */
|
||||||
/*#define HAL_CAN_LEGACY_MODULE_ENABLED */
|
/*#define HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __STM32F1xx_IT_H
|
#define __STM32F1xx_IT_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
|||||||
122
Core/Src/adc.c
122
Core/Src/adc.c
@@ -1,122 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file adc.c
|
|
||||||
* @brief This file provides code for the configuration
|
|
||||||
* of the ADC instances.
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2026 STMicroelectronics.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
|
||||||
* in the root directory of this software component.
|
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "adc.h"
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
ADC_HandleTypeDef hadc1;
|
|
||||||
|
|
||||||
/* ADC1 init function */
|
|
||||||
void MX_ADC1_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN ADC1_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END ADC1_Init 0 */
|
|
||||||
|
|
||||||
ADC_ChannelConfTypeDef sConfig = {0};
|
|
||||||
|
|
||||||
/* USER CODE BEGIN ADC1_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END ADC1_Init 1 */
|
|
||||||
|
|
||||||
/** Common config
|
|
||||||
*/
|
|
||||||
hadc1.Instance = ADC1;
|
|
||||||
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
|
||||||
hadc1.Init.ContinuousConvMode = ENABLE;
|
|
||||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
|
||||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
|
||||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
|
||||||
hadc1.Init.NbrOfConversion = 1;
|
|
||||||
if (HAL_ADC_Init(&hadc1) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Configure Regular Channel
|
|
||||||
*/
|
|
||||||
sConfig.Channel = ADC_CHANNEL_0;
|
|
||||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
|
||||||
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
|
|
||||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN ADC1_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END ADC1_Init 2 */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
|
||||||
{
|
|
||||||
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
if(adcHandle->Instance==ADC1)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN ADC1_MspInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END ADC1_MspInit 0 */
|
|
||||||
/* ADC1 clock enable */
|
|
||||||
__HAL_RCC_ADC1_CLK_ENABLE();
|
|
||||||
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
/**ADC1 GPIO Configuration
|
|
||||||
PA0-WKUP ------> ADC1_IN0
|
|
||||||
*/
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN ADC1_MspInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END ADC1_MspInit 1 */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(adcHandle->Instance==ADC1)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN ADC1_MspDeInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END ADC1_MspDeInit 0 */
|
|
||||||
/* Peripheral clock disable */
|
|
||||||
__HAL_RCC_ADC1_CLK_DISABLE();
|
|
||||||
|
|
||||||
/**ADC1 GPIO Configuration
|
|
||||||
PA0-WKUP ------> ADC1_IN0
|
|
||||||
*/
|
|
||||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END ADC1_MspDeInit 1 */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
@@ -1,38 +1,37 @@
|
|||||||
/* USER CODE BEGIN Header */
|
/* USER CODE BEGIN Header */
|
||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* File Name : freertos.c
|
* File Name : freertos.c
|
||||||
* Description : Code for freertos applications
|
* Description : Code for freertos applications
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
* Copyright (c) 2026 STMicroelectronics.
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
* in the root directory of this software component.
|
* in the root directory of this software component.
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header */
|
/* USER CODE END Header */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
|
||||||
#include "main.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
#include "usart.h"
|
|
||||||
#include "adc.h"
|
|
||||||
#include "tim.h"
|
|
||||||
#include "motor_driver.h"
|
|
||||||
#include "elog.h"
|
#include "elog.h"
|
||||||
|
#include "motor_driver.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "tim.h"
|
||||||
|
#include "usart.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "screen.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/_intsup.h>
|
#include <sys/_intsup.h>
|
||||||
|
|
||||||
@@ -57,7 +56,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
PUTCHAR_PROTOTYPE {
|
PUTCHAR_PROTOTYPE {
|
||||||
HAL_UART_Transmit(&huart5, (uint8_t *) &ch, 1, HAL_MAX_DELAY);
|
HAL_UART_Transmit(&huart5, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
/* USER CODE END PM */
|
/* USER CODE END PM */
|
||||||
@@ -65,56 +64,50 @@ PUTCHAR_PROTOTYPE {
|
|||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Variables */
|
/* USER CODE BEGIN Variables */
|
||||||
|
|
||||||
/* 按键状态位: bit0..bit3 分别对应 M__KEY, M__KEYC7, HOT_KEY, TIME_KEY, 为1表示按下 */
|
/* 按键状态位: bit0..bit3 分别对应 M__KEY, M__KEYC7, HOT_KEY, TIME_KEY,
|
||||||
|
* 为1表示按下 */
|
||||||
volatile uint8_t key_state = 0;
|
volatile uint8_t key_state = 0;
|
||||||
volatile uint8_t key_state_prev = 0; /* 上一次的按键状态,用于检测按键变化 */
|
volatile uint8_t key_state_prev = 0; /* 上一次的按键状态,用于检测按键变化 */
|
||||||
|
|
||||||
/* 设备状态标志:0表示关闭,1表示打开 */
|
/* 设备状态标志:0表示关闭,1表示打开 */
|
||||||
static uint8_t hot_state = 0; /* HOT 设备状态 */
|
static uint8_t hot_state = 0; /* HOT 设备状态 */
|
||||||
static uint8_t time_state = 0; /* TIME_KEY 时间状态 */
|
static uint8_t time_state = 0; /* TIME_KEY 时间状态 */
|
||||||
|
|
||||||
/* USER CODE END Variables */
|
/* USER CODE END Variables */
|
||||||
/* Definitions for defaultTask */
|
/* Definitions for defaultTask */
|
||||||
osThreadId_t defaultTaskHandle;
|
osThreadId_t defaultTaskHandle;
|
||||||
const osThreadAttr_t defaultTask_attributes = {
|
const osThreadAttr_t defaultTask_attributes = {
|
||||||
.name = "defaultTask",
|
.name = "defaultTask",
|
||||||
.stack_size = 128 * 4,
|
.stack_size = 128 * 4,
|
||||||
.priority = (osPriority_t) osPriorityNormal,
|
.priority = (osPriority_t)osPriorityNormal,
|
||||||
};
|
};
|
||||||
/* Definitions for KeyTask */
|
/* Definitions for KeyTask */
|
||||||
osThreadId_t KeyTaskHandle;
|
osThreadId_t KeyTaskHandle;
|
||||||
const osThreadAttr_t KeyTask_attributes = {
|
const osThreadAttr_t KeyTask_attributes = {
|
||||||
.name = "KeyTask",
|
.name = "KeyTask",
|
||||||
.stack_size = 512 * 4,
|
.stack_size = 512 * 4,
|
||||||
.priority = (osPriority_t) osPriorityRealtime,
|
.priority = (osPriority_t)osPriorityRealtime,
|
||||||
};
|
};
|
||||||
/* Definitions for Sensor_Task */
|
/* Definitions for Sensor_Task */
|
||||||
osThreadId_t Sensor_TaskHandle;
|
osThreadId_t Sensor_TaskHandle;
|
||||||
const osThreadAttr_t Sensor_Task_attributes = {
|
const osThreadAttr_t Sensor_Task_attributes = {
|
||||||
.name = "Sensor_Task",
|
.name = "Sensor_Task",
|
||||||
.stack_size = 512 * 4,
|
.stack_size = 512 * 4,
|
||||||
.priority = (osPriority_t) osPriorityHigh7,
|
.priority = (osPriority_t)osPriorityHigh7,
|
||||||
};
|
|
||||||
/* Definitions for Temp_Task */
|
|
||||||
osThreadId_t Temp_TaskHandle;
|
|
||||||
const osThreadAttr_t Temp_Task_attributes = {
|
|
||||||
.name = "Temp_Task",
|
|
||||||
.stack_size = 256 * 4,
|
|
||||||
.priority = (osPriority_t) osPriorityNormal,
|
|
||||||
};
|
};
|
||||||
/* Definitions for Motor_Task */
|
/* Definitions for Motor_Task */
|
||||||
osThreadId_t Motor_TaskHandle;
|
osThreadId_t Motor_TaskHandle;
|
||||||
const osThreadAttr_t Motor_Task_attributes = {
|
const osThreadAttr_t Motor_Task_attributes = {
|
||||||
.name = "Motor_Task",
|
.name = "Motor_Task",
|
||||||
.stack_size = 512 * 4,
|
.stack_size = 512 * 4,
|
||||||
.priority = (osPriority_t) osPriorityNormal1,
|
.priority = (osPriority_t)osPriorityNormal1,
|
||||||
};
|
};
|
||||||
/* Definitions for Screen_Tsak */
|
/* Definitions for Screen_Tsak */
|
||||||
osThreadId_t Screen_TsakHandle;
|
osThreadId_t Screen_TsakHandle;
|
||||||
const osThreadAttr_t Screen_Tsak_attributes = {
|
const osThreadAttr_t Screen_Tsak_attributes = {
|
||||||
.name = "Screen_Tsak",
|
.name = "Screen_Tsak",
|
||||||
.stack_size = 1024 * 4,
|
.stack_size = 1024 * 4,
|
||||||
.priority = (osPriority_t) osPriorityNormal,
|
.priority = (osPriority_t)osPriorityNormal,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@@ -125,22 +118,21 @@ const osThreadAttr_t Screen_Tsak_attributes = {
|
|||||||
void StartDefaultTask(void *argument);
|
void StartDefaultTask(void *argument);
|
||||||
void Key(void *argument);
|
void Key(void *argument);
|
||||||
void Sensor(void *argument);
|
void Sensor(void *argument);
|
||||||
void Temp(void *argument);
|
|
||||||
void Motor(void *argument);
|
void Motor(void *argument);
|
||||||
void Screen(void *argument);
|
void Screen(void *argument);
|
||||||
|
|
||||||
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief FreeRTOS initialization
|
* @brief FreeRTOS initialization
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void MX_FREERTOS_Init(void) {
|
void MX_FREERTOS_Init(void) {
|
||||||
/* USER CODE BEGIN Init */
|
/* USER CODE BEGIN Init */
|
||||||
easylogger_init(); /* 初始化 EasyLogger */
|
easylogger_init(); /* 初始化 EasyLogger */
|
||||||
__enable_irq(); //开启全局中断
|
__enable_irq(); // 开启全局中断
|
||||||
elog_i("task_init", "任务初始!");
|
elog_i("task_init", "任务初始!");
|
||||||
/* USER CODE END Init */
|
/* USER CODE END Init */
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_MUTEX */
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
@@ -161,7 +153,8 @@ void MX_FREERTOS_Init(void) {
|
|||||||
|
|
||||||
/* Create the thread(s) */
|
/* Create the thread(s) */
|
||||||
/* creation of defaultTask */
|
/* creation of defaultTask */
|
||||||
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
defaultTaskHandle =
|
||||||
|
osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
||||||
|
|
||||||
/* creation of KeyTask */
|
/* creation of KeyTask */
|
||||||
KeyTaskHandle = osThreadNew(Key, NULL, &KeyTask_attributes);
|
KeyTaskHandle = osThreadNew(Key, NULL, &KeyTask_attributes);
|
||||||
@@ -169,9 +162,6 @@ void MX_FREERTOS_Init(void) {
|
|||||||
/* creation of Sensor_Task */
|
/* creation of Sensor_Task */
|
||||||
Sensor_TaskHandle = osThreadNew(Sensor, NULL, &Sensor_Task_attributes);
|
Sensor_TaskHandle = osThreadNew(Sensor, NULL, &Sensor_Task_attributes);
|
||||||
|
|
||||||
/* creation of Temp_Task */
|
|
||||||
Temp_TaskHandle = osThreadNew(Temp, NULL, &Temp_Task_attributes);
|
|
||||||
|
|
||||||
/* creation of Motor_Task */
|
/* creation of Motor_Task */
|
||||||
Motor_TaskHandle = osThreadNew(Motor, NULL, &Motor_Task_attributes);
|
Motor_TaskHandle = osThreadNew(Motor, NULL, &Motor_Task_attributes);
|
||||||
|
|
||||||
@@ -185,74 +175,85 @@ void MX_FREERTOS_Init(void) {
|
|||||||
/* USER CODE BEGIN RTOS_EVENTS */
|
/* USER CODE BEGIN RTOS_EVENTS */
|
||||||
/* add events, ... */
|
/* add events, ... */
|
||||||
/* USER CODE END RTOS_EVENTS */
|
/* USER CODE END RTOS_EVENTS */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||||
/**
|
/**
|
||||||
* @brief Function implementing the defaultTask thread.
|
* @brief Function implementing the defaultTask thread.
|
||||||
* @param argument: Not used
|
* @param argument: Not used
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header_StartDefaultTask */
|
/* USER CODE END Header_StartDefaultTask */
|
||||||
void StartDefaultTask(void *argument)
|
void StartDefaultTask(void *argument) {
|
||||||
{
|
|
||||||
/* USER CODE BEGIN StartDefaultTask */
|
/* USER CODE BEGIN StartDefaultTask */
|
||||||
// 初始化命令
|
// 初始化命令
|
||||||
uint8_t init_cmd1[] = {0x7E, 0xFF, 0x06, 0x06, 0x00, 0x00, 0x1E, 0xFE, 0xD7, 0xEF}; // 开启声音
|
uint8_t init_cmd1[] = {0x7E, 0xFF, 0x06, 0x06, 0x00,
|
||||||
uint8_t init_cmd2[] = {0x7E, 0xFF, 0x06, 0x09, 0x00, 0x00, 0x02, 0xFE, 0xF0, 0xEF}; // 指定播放设备为TF卡
|
0x00, 0x1E, 0xFE, 0xD7, 0xEF}; // 开启声音
|
||||||
|
uint8_t init_cmd2[] = {0x7E, 0xFF, 0x06, 0x09, 0x00,
|
||||||
|
0x00, 0x02, 0xFE, 0xF0, 0xEF}; // 指定播放设备为TF卡
|
||||||
|
|
||||||
// 定义测试指令数据
|
// 定义测试指令数据
|
||||||
uint8_t test_cmd[] = {0x7E, 0xFF, 0x06, 0x12, 0x00, 0x00, 0x01, 0xFE, 0xE8, 0xEF};
|
uint8_t test_cmd[] = {0x7E, 0xFF, 0x06, 0x12, 0x00,
|
||||||
|
0x00, 0x01, 0xFE, 0xE8, 0xEF};
|
||||||
|
|
||||||
// 先让模块稳定
|
// 先让模块稳定
|
||||||
osDelay(2000);
|
osDelay(2000);
|
||||||
|
|
||||||
// 初始化:先发送开启声音指令,再发送指定播放设备指令
|
// 初始化:先发送开启声音指令,再发送指定播放设备指令
|
||||||
HAL_UART_Transmit(&huart3, init_cmd1, sizeof(init_cmd1), 1000);
|
HAL_UART_Transmit(&huart3, init_cmd1, sizeof(init_cmd1), 1000);
|
||||||
osDelay(1500); // 重要:等待模块响应
|
elog_d("MP3",
|
||||||
|
"发送的消息是:%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
|
||||||
|
init_cmd1[0], init_cmd1[1], init_cmd1[2], init_cmd1[3], init_cmd1[4],
|
||||||
|
init_cmd1[5], init_cmd1[6], init_cmd1[7], init_cmd1[8], init_cmd1[9]);
|
||||||
|
osDelay(1500); // 重要:等待模块响应
|
||||||
|
|
||||||
HAL_UART_Transmit(&huart3, init_cmd2, sizeof(init_cmd2), 1000);
|
HAL_UART_Transmit(&huart3, init_cmd2, sizeof(init_cmd2), 1000);
|
||||||
osDelay(1500); // 重要:等待初始化完成
|
elog_d("MP3",
|
||||||
|
"发送的消息是:%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
|
||||||
|
init_cmd2[0], init_cmd2[1], init_cmd2[2], init_cmd2[3], init_cmd2[4],
|
||||||
|
init_cmd2[5], init_cmd2[6], init_cmd2[7], init_cmd2[8], init_cmd2[9]);
|
||||||
|
osDelay(1500); // 重要:等待初始化完成
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
|
||||||
// 直接整包发送测试指令
|
// 直接整包发送测试指令
|
||||||
HAL_UART_Transmit(&huart3, test_cmd, sizeof(test_cmd), 1000);
|
HAL_UART_Transmit(&huart3, test_cmd, sizeof(test_cmd), 1000);
|
||||||
// 把发送的数据打印出来
|
// 把发送的数据打印出来
|
||||||
//elog_d("mp3_cmd","发送测试指令: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", test_cmd[0], test_cmd[1], test_cmd[2], test_cmd[3], test_cmd[4], test_cmd[5], test_cmd[6], test_cmd[7], test_cmd[8], test_cmd[9]);
|
elog_d("mp3_cmd",
|
||||||
|
"发送测试指令: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
|
||||||
|
test_cmd[0], test_cmd[1], test_cmd[2], test_cmd[3], test_cmd[4],
|
||||||
|
test_cmd[5], test_cmd[6], test_cmd[7], test_cmd[8], test_cmd[9]);
|
||||||
// 可选:等待发送完成
|
// 可选:等待发送完成
|
||||||
// while(__HAL_UART_GET_FLAG(&huart3, UART_FLAG_TC) == RESET);
|
// while(__HAL_UART_GET_FLAG(&huart3, UART_FLAG_TC) == RESET);
|
||||||
|
|
||||||
HAL_GPIO_TogglePin(RUN_LED_GPIO_Port, RUN_LED_Pin);
|
HAL_GPIO_TogglePin(RUN_LED_GPIO_Port, RUN_LED_Pin);
|
||||||
|
|
||||||
osDelay(1000); // 延时1秒
|
osDelay(10000); // 延时1秒
|
||||||
}
|
}
|
||||||
/* USER CODE END StartDefaultTask */
|
/* USER CODE END StartDefaultTask */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_Key */
|
/* USER CODE BEGIN Header_Key */
|
||||||
/**
|
/**
|
||||||
* @brief Function implementing the KeyTask thread.
|
* @brief Function implementing the KeyTask thread.
|
||||||
* @param argument: Not used
|
* @param argument: Not used
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header_Key */
|
/* USER CODE END Header_Key */
|
||||||
void Key(void *argument)
|
void Key(void *argument) {
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Key */
|
/* USER CODE BEGIN Key */
|
||||||
/* 防抖轮询实现四个低电平有效按键检测 */
|
/* 防抖轮询实现四个低电平有效按键检测 */
|
||||||
GPIO_TypeDef* key_ports[4] = {M__KEY_GPIO_Port, M__KEYC7_GPIO_Port, HOT_KEY_GPIO_Port, TIME_KEY_GPIO_Port};
|
GPIO_TypeDef *key_ports[4] = {M__KEY_GPIO_Port, M__KEYC7_GPIO_Port,
|
||||||
const uint16_t key_pins[4] = {M__KEY_Pin, M__KEYC7_Pin, HOT_KEY_Pin, TIME_KEY_Pin};
|
HOT_KEY_GPIO_Port, TIME_KEY_GPIO_Port};
|
||||||
|
const uint16_t key_pins[4] = {M__KEY_Pin, M__KEYC7_Pin, HOT_KEY_Pin,
|
||||||
|
TIME_KEY_Pin};
|
||||||
|
|
||||||
uint8_t press_count[4] = {0};
|
uint8_t press_count[4] = {0};
|
||||||
uint8_t release_count[4] = {0};
|
uint8_t release_count[4] = {0};
|
||||||
uint8_t pressed[4] = {0};
|
uint8_t pressed[4] = {0};
|
||||||
const uint8_t THRESH = 3; /* 3 * 10ms = 30ms 防抖 */
|
const uint8_t THRESH = 3; /* 3 * 10ms = 30ms 防抖 */
|
||||||
|
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
GPIO_PinState level = HAL_GPIO_ReadPin(key_ports[i], key_pins[i]);
|
GPIO_PinState level = HAL_GPIO_ReadPin(key_ports[i], key_pins[i]);
|
||||||
if (level == GPIO_PIN_RESET) { /* 低电平有效 */
|
if (level == GPIO_PIN_RESET) { /* 低电平有效 */
|
||||||
@@ -260,7 +261,7 @@ void Key(void *argument)
|
|||||||
release_count[i] = 0;
|
release_count[i] = 0;
|
||||||
if (!pressed[i] && press_count[i] >= THRESH) {
|
if (!pressed[i] && press_count[i] >= THRESH) {
|
||||||
pressed[i] = 1;
|
pressed[i] = 1;
|
||||||
key_state |= (1 << i); /* bit0..3 分别对应四个按键按下状态 */
|
key_state |= (1 << i); /* bit0..3 分别对应四个按键按下状态 */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
release_count[i]++;
|
release_count[i]++;
|
||||||
@@ -278,23 +279,21 @@ void Key(void *argument)
|
|||||||
|
|
||||||
/* USER CODE BEGIN Header_Sensor */
|
/* USER CODE BEGIN Header_Sensor */
|
||||||
/**
|
/**
|
||||||
* @brief Function implementing the Sensor_Task thread.
|
* @brief Function implementing the Sensor_Task thread.
|
||||||
* @param argument: Not used
|
* @param argument: Not used
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header_Sensor */
|
/* USER CODE END Header_Sensor */
|
||||||
void Sensor(void *argument)
|
void Sensor(void *argument) {
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Sensor */
|
/* USER CODE BEGIN Sensor */
|
||||||
/* 按键处理任务 - 按键状态切换控制 */
|
/* 按键处理任务 - 按键状态切换控制 */
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
|
||||||
/* 检测新按下的按键 */
|
/* 检测新按下的按键 */
|
||||||
uint8_t key_pressed = key_state & ~key_state_prev;
|
uint8_t key_pressed = key_state & ~key_state_prev;
|
||||||
key_state_prev = key_state;
|
key_state_prev = key_state;
|
||||||
|
|
||||||
/* ===== M__KEY (bit0) 控制 ===== */
|
/* ===== M__KEY (bit0) 控制 ===== */
|
||||||
if (key_pressed & (1 << 0)) {
|
if (key_pressed & (1 << 0)) {
|
||||||
/* M__KEY 按下:加档(提高转速) */
|
/* M__KEY 按下:加档(提高转速) */
|
||||||
@@ -312,14 +311,16 @@ void Sensor(void *argument)
|
|||||||
elog_i("Key", "M__KEYC7按下 - 降档");
|
elog_i("Key", "M__KEYC7按下 - 降档");
|
||||||
Motor_GearDown();
|
Motor_GearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===== HOT_KEY (bit2) 控制 ===== */
|
/* ===== HOT_KEY (bit2) 控制 ===== */
|
||||||
if (key_pressed & (1 << 2)) {
|
if (key_pressed & (1 << 2)) {
|
||||||
/* HOT_KEY 按下:切换热功能 */
|
/* HOT_KEY 按下:切换热功能 */
|
||||||
hot_state = !hot_state;
|
hot_state = !hot_state;
|
||||||
HAL_GPIO_WritePin(HOT_GPIO_Port, HOT_Pin, hot_state ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
elog_d("HOT", "加热的状态: %d", hot_state);
|
||||||
|
HAL_GPIO_WritePin(HOT_GPIO_Port, HOT_Pin,
|
||||||
|
hot_state ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===== TIME_KEY (bit3) 控制 ===== */
|
/* ===== TIME_KEY (bit3) 控制 ===== */
|
||||||
if (key_pressed & (1 << 3)) {
|
if (key_pressed & (1 << 3)) {
|
||||||
/* TIME_KEY 按下:切换定时 */
|
/* TIME_KEY 按下:切换定时 */
|
||||||
@@ -330,142 +331,27 @@ void Sensor(void *argument)
|
|||||||
// TODO: 添加定时关闭逻辑
|
// TODO: 添加定时关闭逻辑
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
osDelay(20); /* 20ms 检查一次按键状态 */
|
osDelay(20); /* 20ms 检查一次按键状态 */
|
||||||
}
|
}
|
||||||
/* USER CODE END Sensor */
|
/* USER CODE END Sensor */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_Temp */
|
|
||||||
/**
|
|
||||||
* @brief Function implementing the Temp_Task thread.
|
|
||||||
* @param argument: Not used
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header_Temp */
|
|
||||||
void Temp(void *argument)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Temp */
|
|
||||||
|
|
||||||
#ifdef ENABLE_TEMP_SENSOR
|
|
||||||
|
|
||||||
/* ADC采集参数 */
|
|
||||||
uint32_t adc_raw = 0; /* ADC原始值 */
|
|
||||||
uint32_t adc_sum = 0; /* 累加和(用于平均) */
|
|
||||||
uint16_t sample_count = 32; /* 采样次数 */
|
|
||||||
float voltage = 0.0f; /* 转换后的电压 */
|
|
||||||
float temperature = 0.0f; /* 转换后的温度 */
|
|
||||||
|
|
||||||
/* 电路参数 */
|
|
||||||
const float VREF = 3.3f; /* 参考电压 */
|
|
||||||
|
|
||||||
/* 一阶低通滤波器 */
|
|
||||||
float adc_filtered = 0.0f; /* 滤波后的ADC值 */
|
|
||||||
const float FILTER_ALPHA = 0.1f; /* 滤波系数 */
|
|
||||||
|
|
||||||
/* NTC 10K 3950参数 */
|
|
||||||
const float NTC_B_VALUE = 3950.0f; /* NTC B值 */
|
|
||||||
const float NTC_R0 = 10000.0f; /* 25°C时电阻10K */
|
|
||||||
const float NTC_T0 = 298.15f; /* 25°C对应的绝对温度(K) */
|
|
||||||
const float R_FIXED = 10000.0f; /* 分压电阻10K */
|
|
||||||
|
|
||||||
/* ADC校准 */
|
|
||||||
HAL_ADCEx_Calibration_Start(&hadc1);
|
|
||||||
|
|
||||||
/* 预热:先采集几次丢弃,稳定ADC */
|
|
||||||
for (uint16_t i = 0; i < 10; i++) {
|
|
||||||
HAL_ADC_Start(&hadc1);
|
|
||||||
HAL_ADC_PollForConversion(&hadc1, 100);
|
|
||||||
HAL_ADC_GetValue(&hadc1);
|
|
||||||
HAL_ADC_Stop(&hadc1);
|
|
||||||
osDelay(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
/* 采集多次求平均,提高精度 */
|
|
||||||
adc_sum = 0;
|
|
||||||
for (uint16_t i = 0; i < sample_count; i++) {
|
|
||||||
HAL_ADC_Start(&hadc1);
|
|
||||||
if (HAL_ADC_PollForConversion(&hadc1, 100) == HAL_OK) {
|
|
||||||
adc_sum += HAL_ADC_GetValue(&hadc1);
|
|
||||||
}
|
|
||||||
HAL_ADC_Stop(&hadc1);
|
|
||||||
osDelay(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 计算平均值 */
|
|
||||||
adc_raw = adc_sum / sample_count;
|
|
||||||
|
|
||||||
/* 一阶低通滤波 */
|
|
||||||
if (adc_filtered == 0.0f) {
|
|
||||||
adc_filtered = (float)adc_raw;
|
|
||||||
} else {
|
|
||||||
adc_filtered = FILTER_ALPHA * (float)adc_raw + (1.0f - FILTER_ALPHA) * adc_filtered;
|
|
||||||
}
|
|
||||||
adc_raw = (uint32_t)(adc_filtered + 0.5f);
|
|
||||||
|
|
||||||
/* 转换为电压 */
|
|
||||||
voltage = ((float)adc_raw / 4095.0f) * VREF;
|
|
||||||
|
|
||||||
/* ==================== NTC 10K 3950 温度计算 ====================
|
|
||||||
* 电路:3.3V ──[10K固定电阻]──┬── PA0 (ADC)
|
|
||||||
* │
|
|
||||||
* [NTC 10K]
|
|
||||||
* │
|
|
||||||
* GND
|
|
||||||
*
|
|
||||||
* Steinhart-Hart简化方程:
|
|
||||||
* 1/T = 1/T0 + (1/B) * ln(R/R0)
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
/* 计算NTC电阻值 */
|
|
||||||
float ntc_resistance = R_FIXED * voltage / (VREF - voltage);
|
|
||||||
|
|
||||||
/* Steinhart-Hart方程计算温度(K) */
|
|
||||||
float steinhart = logf(ntc_resistance / NTC_R0) / NTC_B_VALUE + 1.0f / NTC_T0;
|
|
||||||
temperature = 1.0f / steinhart - 273.15f; /* 转换为摄氏度 */
|
|
||||||
|
|
||||||
elog_i("Temp", "ADC:%lu 电压:%.3fV NTC:%.1fΩ 温度:%.1f°C",
|
|
||||||
adc_raw, voltage, ntc_resistance, temperature);
|
|
||||||
}
|
|
||||||
|
|
||||||
osDelay(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
/* 温度传感器未启用,任务空转 */
|
|
||||||
elog_i("Temp", "温度传感器未启用,等待NTC改装...");
|
|
||||||
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
osDelay(5000);
|
|
||||||
elog_i("Temp", "温度传感器未启用,等待NTC改装...");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* ENABLE_TEMP_SENSOR */
|
|
||||||
|
|
||||||
/* USER CODE END Temp */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Header_Motor */
|
/* USER CODE BEGIN Header_Motor */
|
||||||
/**
|
/**
|
||||||
* @brief Function implementing the Motor_Task thread.
|
* @brief Function implementing the Motor_Task thread.
|
||||||
* @param argument: Not used
|
* @param argument: Not used
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header_Motor */
|
/* USER CODE END Header_Motor */
|
||||||
void Motor(void *argument)
|
void Motor(void *argument) {
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Motor */
|
/* USER CODE BEGIN Motor */
|
||||||
|
|
||||||
/* 电机驱动初始化 */
|
/* 电机驱动初始化 */
|
||||||
Motor_Init();
|
Motor_Init();
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
|
||||||
/* 电机任务主要功能:
|
/* 电机任务主要功能:
|
||||||
* - 监控电机状态(超温保护、过流保护等)
|
* - 监控电机状态(超温保护、过流保护等)
|
||||||
* - 定期打印状态信息
|
* - 定期打印状态信息
|
||||||
@@ -483,21 +369,17 @@ void Motor(void *argument)
|
|||||||
|
|
||||||
/* USER CODE BEGIN Header_Screen */
|
/* USER CODE BEGIN Header_Screen */
|
||||||
/**
|
/**
|
||||||
* @brief Function implementing the Screen_Tsak thread.
|
* @brief Function implementing the Screen_Tsak thread.
|
||||||
* @param argument: Not used
|
* @param argument: Not used
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header_Screen */
|
/* USER CODE END Header_Screen */
|
||||||
void Screen(void *argument)
|
void Screen(void *argument) {
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Screen */
|
/* USER CODE BEGIN Screen */
|
||||||
char buf[100];
|
Screen_Init();
|
||||||
sprintf(buf, "CLR(1);\r\n");
|
// HAL_UART_Transmit(&huart1, (uint8_t *)buf, strlen(buf), HAL_MAX_DELAY);
|
||||||
//HAL_UART_Transmit(&huart1, (uint8_t *)buf, strlen(buf), HAL_MAX_DELAY);
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
|
||||||
HAL_UART_Transmit(&huart1, (uint8_t *)buf, strlen(buf), HAL_MAX_DELAY);
|
|
||||||
|
|
||||||
osDelay(2000);
|
osDelay(2000);
|
||||||
}
|
}
|
||||||
@@ -508,4 +390,3 @@ void Screen(void *argument)
|
|||||||
/* USER CODE BEGIN Application */
|
/* USER CODE BEGIN Application */
|
||||||
|
|
||||||
/* USER CODE END Application */
|
/* USER CODE END Application */
|
||||||
|
|
||||||
|
|||||||
@@ -46,23 +46,16 @@ void MX_GPIO_Init(void)
|
|||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
|
||||||
|
/*Configure GPIO pin Output Level */
|
||||||
|
HAL_GPIO_WritePin(GPIOB, RUN_LED_Pin|ERR_LED_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(HOT_GPIO_Port, HOT_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(HOT_GPIO_Port, HOT_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOB, RUN_LED_Pin|ERR_LED_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : HOT_Pin */
|
|
||||||
GPIO_InitStruct.Pin = HOT_Pin;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(HOT_GPIO_Port, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/*Configure GPIO pins : RUN_LED_Pin ERR_LED_Pin */
|
/*Configure GPIO pins : RUN_LED_Pin ERR_LED_Pin */
|
||||||
GPIO_InitStruct.Pin = RUN_LED_Pin|ERR_LED_Pin;
|
GPIO_InitStruct.Pin = RUN_LED_Pin|ERR_LED_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
@@ -76,6 +69,13 @@ void MX_GPIO_Init(void)
|
|||||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : HOT_Pin */
|
||||||
|
GPIO_InitStruct.Pin = HOT_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(HOT_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "adc.h"
|
|
||||||
#include "tim.h"
|
#include "tim.h"
|
||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
@@ -91,7 +90,6 @@ int main(void)
|
|||||||
|
|
||||||
/* Initialize all configured peripherals */
|
/* Initialize all configured peripherals */
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
MX_ADC1_Init();
|
|
||||||
MX_UART5_Init();
|
MX_UART5_Init();
|
||||||
MX_USART1_UART_Init();
|
MX_USART1_UART_Init();
|
||||||
MX_USART3_UART_Init();
|
MX_USART3_UART_Init();
|
||||||
@@ -101,9 +99,7 @@ int main(void)
|
|||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* Init scheduler */
|
/* Init scheduler */
|
||||||
osKernelInitialize();
|
osKernelInitialize(); /* Call init function for freertos objects (in cmsis_os2.c) */
|
||||||
|
|
||||||
/* Call init function for freertos objects (in cmsis_os2.c) */
|
|
||||||
MX_FREERTOS_Init();
|
MX_FREERTOS_Init();
|
||||||
|
|
||||||
/* Start scheduler */
|
/* Start scheduler */
|
||||||
@@ -131,7 +127,6 @@ void SystemClock_Config(void)
|
|||||||
{
|
{
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
* in the RCC_OscInitTypeDef structure.
|
* in the RCC_OscInitTypeDef structure.
|
||||||
@@ -161,12 +156,6 @@ void SystemClock_Config(void)
|
|||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
|
|
||||||
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
|
|
||||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
/* USER CODE BEGIN 4 */
|
||||||
@@ -186,7 +175,8 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|||||||
/* USER CODE BEGIN Callback 0 */
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
/* USER CODE END Callback 0 */
|
/* USER CODE END Callback 0 */
|
||||||
if (htim->Instance == TIM8) {
|
if (htim->Instance == TIM8)
|
||||||
|
{
|
||||||
HAL_IncTick();
|
HAL_IncTick();
|
||||||
}
|
}
|
||||||
/* USER CODE BEGIN Callback 1 */
|
/* USER CODE BEGIN Callback 1 */
|
||||||
@@ -208,8 +198,7 @@ void Error_Handler(void)
|
|||||||
}
|
}
|
||||||
/* USER CODE END Error_Handler_Debug */
|
/* USER CODE END Error_Handler_Debug */
|
||||||
}
|
}
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
/**
|
/**
|
||||||
* @brief Reports the name of the source file and the source line number
|
* @brief Reports the name of the source file and the source line number
|
||||||
* where the assert_param error has occurred.
|
* where the assert_param error has occurred.
|
||||||
|
|||||||
@@ -8,182 +8,316 @@
|
|||||||
/* USER CODE END Header */
|
/* USER CODE END Header */
|
||||||
|
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
#include "cmsis_os2.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdint.h>
|
||||||
|
#include "gbk_text.h"
|
||||||
/* 模块初始化:不要使用 MP3 的二进制初始化指令,改为屏幕清屏作为默认初始化 */
|
|
||||||
|
|
||||||
/* 发送缓冲 */
|
/* 发送缓冲 */
|
||||||
static char txbuf[256];
|
static uint8_t txbuf[512];
|
||||||
|
|
||||||
|
/* =========================================================
|
||||||
|
内部工具函数(替代 sprintf)
|
||||||
|
========================================================= */
|
||||||
|
|
||||||
/**
|
/* 将字符串复制到发送缓冲区 */
|
||||||
* @brief 发送字符串到串口屏(阻塞直到发送完成)
|
static uint16_t buf_str(uint16_t p,const char *s)
|
||||||
* @param cmd: 要发送的C字符串(不强制包含结尾CR/LF)
|
{
|
||||||
* @retval 0=OK, <0=错误
|
while(*s) txbuf[p++]=*s++;
|
||||||
*/
|
return p;
|
||||||
int Screen_SendCmd(const char *cmd) {
|
|
||||||
if (cmd == NULL) return -1;
|
|
||||||
size_t len = strlen(cmd);
|
|
||||||
if (len == 0) return -1;
|
|
||||||
HAL_StatusTypeDef st = HAL_UART_Transmit(&huart1, (uint8_t *)cmd, (uint16_t)len, HAL_MAX_DELAY);
|
|
||||||
return (st == HAL_OK) ? 0 : -2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* 将32位无符号整数转换为字符串并复制到发送缓冲区 */
|
||||||
* @brief 发送命令并等待模块返回 "OK\r\n",超时返回非0
|
static uint16_t buf_u32(uint16_t p,uint32_t v)
|
||||||
*/
|
{
|
||||||
int Screen_SendCmdWaitOK(const char *cmd, uint32_t timeout_ms) {
|
char tmp[12];
|
||||||
(void)timeout_ms;
|
int i=0;
|
||||||
/* 保留接口:当前不等待屏幕回包,直接发送后返回发送状态 */
|
if(v==0){ txbuf[p++]='0'; return p; }
|
||||||
return Screen_SendCmd(cmd);
|
while(v){ tmp[i++]=v%10+'0'; v/=10; }
|
||||||
|
while(i--) txbuf[p++]=tmp[i];
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_Init(void) {
|
/* 发送指定长度的数据 */
|
||||||
/*
|
static void send_buf(uint16_t len)
|
||||||
* 屏幕初始化:简单实现为上电等待并清除屏幕
|
{
|
||||||
* 若需要按照厂商例程发送更多配置指令,可在此扩展
|
HAL_UART_Transmit(&huart1,txbuf,len,HAL_MAX_DELAY);
|
||||||
*/
|
osDelay(100);
|
||||||
osDelay(1000);
|
|
||||||
Screen_Clear(0);
|
|
||||||
osDelay(200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 简单封装接口示例 */
|
/* =========================================================
|
||||||
void Screen_Clear(uint8_t layer) {
|
基础接口
|
||||||
sprintf(txbuf, "DIR(1);CLR(%u);\r\n", (unsigned)layer);
|
========================================================= */
|
||||||
Screen_SendCmd(txbuf);
|
|
||||||
|
/* 发送数据缓冲区 */
|
||||||
|
int Screen_SendBuf(const uint8_t *buf,uint16_t len)
|
||||||
|
{
|
||||||
|
if(!buf||!len) return -1;
|
||||||
|
HAL_StatusTypeDef st=HAL_UART_Transmit(&huart1,(uint8_t*)buf,len,HAL_MAX_DELAY);
|
||||||
|
osDelay(20);
|
||||||
|
return (st==HAL_OK)?0:-2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_DisplayImage(uint32_t addr) {
|
/* 发送命令字符串 */
|
||||||
sprintf(txbuf, "DIR(1);FSIMG(%lu,0,0,128,128,0);\r\n", (unsigned long)addr);
|
int Screen_SendCmd(const char *cmd)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
if(!cmd) return -1;
|
||||||
|
return Screen_SendBuf((uint8_t*)cmd,strlen(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_SetBrightness(uint8_t val) {
|
/* 发送命令并等待确认(当前未实现超时机制) */
|
||||||
sprintf(txbuf, "BL(%u);\r\n", (unsigned)val);
|
int Screen_SendCmdWaitOK(const char *cmd,uint32_t timeout_ms)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
(void)timeout_ms;
|
||||||
|
return Screen_SendCmd(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_DrawText16(uint16_t x, uint16_t y, const char *text, uint8_t color) {
|
/* =========================================================
|
||||||
sprintf(txbuf, "SBC(%u);DC16(%u,%u,'%s',%u);\r\n", (unsigned)color, (unsigned)x, (unsigned)y, text, (unsigned)color);
|
初始化
|
||||||
Screen_SendCmd(txbuf);
|
========================================================= */
|
||||||
|
|
||||||
|
/* 屏幕初始化函数 */
|
||||||
|
void Screen_Init(void)
|
||||||
|
{
|
||||||
|
osDelay(1000);
|
||||||
|
Screen_Clear(BG_COLOR);
|
||||||
|
osDelay(200);
|
||||||
|
Screen_SetBGColor(BG_COLOR);
|
||||||
|
Screen_SetBrightness(0);
|
||||||
|
osDelay(200);
|
||||||
|
Screen_Box(0,0,127,127,TEXT_COLOR);
|
||||||
|
Screen_DrawText24_GBK(5,1,text_device_name,text_device_name_LEN,TEXT_COLOR);
|
||||||
|
Screen_Line(0, 27, 127, 27, TEXT_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 额外封装实现 */
|
/* =========================================================
|
||||||
/* 以下为屏幕命令封装函数实现,均以字符串形式发送到串口屏 */
|
基础命令(全部保留)
|
||||||
/* 函数内部不等待屏幕回包,调用者若需确认执行结果请自行实现回包处理 */
|
========================================================= */
|
||||||
|
|
||||||
void Screen_SetRotation(uint8_t dir) {
|
/* 清除指定图层 */
|
||||||
sprintf(txbuf, "DIR(%u);\r\n", dir);
|
void Screen_Clear(uint8_t layer)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"DIR(1);CLR(");
|
||||||
|
p=buf_u32(p,layer);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_SetBaud(uint32_t baud) {
|
/* 显示指定地址的图片 */
|
||||||
sprintf(txbuf, "BPS(%lu);\r\n", (unsigned long)baud);
|
void Screen_DisplayImage(uint32_t addr)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
}
|
uint16_t p=0;
|
||||||
void Screen_DisplayImageAtAddr(uint32_t addr, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t mode) {
|
p=buf_str(p,"DIR(1);FSIMG(");
|
||||||
sprintf(txbuf, "FSIMG(%lu,%u,%u,%u,%u,%u);\r\n", (unsigned long)addr, (unsigned)x, (unsigned)y, (unsigned)w, (unsigned)h, (unsigned)mode);
|
p=buf_u32(p,addr);
|
||||||
Screen_SendCmd(txbuf);
|
p=buf_str(p,",0,0,128,128,0);\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_DisplayImageByIndex(uint32_t index, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t mode) {
|
/* 设置屏幕亮度 */
|
||||||
sprintf(txbuf, "FSIMG(%u,%u,%u,%u,%u,%u);\r\n", (unsigned)index, (unsigned)x, (unsigned)y, (unsigned)w, (unsigned)h, (unsigned)mode);
|
void Screen_SetBrightness(uint8_t val)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"BL(");
|
||||||
|
p=buf_u32(p,val);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_Pixel(uint16_t x, uint16_t y, uint8_t color) {
|
/* 设置屏幕旋转方向 */
|
||||||
sprintf(txbuf, "PS(%u,%u,%u);\r\n", (unsigned)x, (unsigned)y, (unsigned)color);
|
void Screen_SetRotation(uint8_t dir)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"DIR(");
|
||||||
|
p=buf_u32(p,dir);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_Line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t color) {
|
/* 设置串口波特率 */
|
||||||
sprintf(txbuf, "PL(%u,%u,%u,%u,%u);\r\n", (unsigned)x1, (unsigned)y1, (unsigned)x2, (unsigned)y2, (unsigned)color);
|
void Screen_SetBaud(uint32_t baud)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"BPS(");
|
||||||
|
p=buf_u32(p,baud);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_Box(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t color) {
|
/* 在指定位置显示图片 */
|
||||||
sprintf(txbuf, "BOX(%u,%u,%u,%u,%u);\r\n", (unsigned)x1, (unsigned)y1, (unsigned)x2, (unsigned)y2, (unsigned)color);
|
void Screen_DisplayImageAtAddr(uint32_t addr,uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint8_t mode)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"FSIMG(");
|
||||||
|
p=buf_u32(p,addr); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,x); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,y); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,w); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,h); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,mode);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_BoxFill(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t color) {
|
/* 通过索引显示图片 */
|
||||||
sprintf(txbuf, "BOXF(%u,%u,%u,%u,%u);\r\n", (unsigned)x1, (unsigned)y1, (unsigned)x2, (unsigned)y2, (unsigned)color);
|
void Screen_DisplayImageByIndex(uint32_t index,uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint8_t mode)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
Screen_DisplayImageAtAddr(index,x,y,w,h,mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_Circle(uint16_t x, uint16_t y, uint16_t r, uint8_t color) {
|
/* 绘制单个像素点 */
|
||||||
sprintf(txbuf, "CIR(%u,%u,%u,%u);\r\n", (unsigned)x, (unsigned)y, (unsigned)r, (unsigned)color);
|
void Screen_Pixel(uint16_t x,uint16_t y,uint8_t color)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"PS(");
|
||||||
|
p=buf_u32(p,x); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,y); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,color);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_CircleFill(uint16_t x, uint16_t y, uint16_t r, uint8_t color) {
|
/* 绘制直线 */
|
||||||
sprintf(txbuf, "CIRF(%u,%u,%u,%u);\r\n", (unsigned)x, (unsigned)y, (unsigned)r, (unsigned)color);
|
void Screen_Line(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t color)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"PL(");
|
||||||
|
p=buf_u32(p,x1); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,y1); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,x2); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,y2); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,color);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_SetBGColor(uint8_t color) {
|
/* 绘制矩形框 */
|
||||||
sprintf(txbuf, "SBC(%u);\r\n", (unsigned)color);
|
void Screen_Box(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t color)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"BOX(");
|
||||||
|
p=buf_u32(p,x1); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,y1); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,x2); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,y2); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,color);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_DrawText16V(uint16_t x, uint16_t y, const char *text, uint8_t color) {
|
/* 绘制填充矩形 */
|
||||||
sprintf(txbuf, "DCV16(%u,%u,'%s',%u);\r\n", (unsigned)x, (unsigned)y, text, (unsigned)color);
|
void Screen_BoxFill(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t color)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"BOXF(");
|
||||||
|
p=buf_u32(p,x1); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,y1); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,x2); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,y2); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,color);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_DrawText24(uint16_t x, uint16_t y, const char *text, uint8_t color) {
|
/* 绘制圆形 */
|
||||||
sprintf(txbuf, "DC24(%u,%u,'%s',%u);\r\n", (unsigned)x, (unsigned)y, text, (unsigned)color);
|
void Screen_Circle(uint16_t x,uint16_t y,uint16_t r,uint8_t color)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"CIR(");
|
||||||
|
p=buf_u32(p,x); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,y); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,r); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,color);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_DrawText24V(uint16_t x, uint16_t y, const char *text, uint8_t color) {
|
/* 绘制填充圆形 */
|
||||||
sprintf(txbuf, "DCV24(%u,%u,'%s',%u);\r\n", (unsigned)x, (unsigned)y, text, (unsigned)color);
|
void Screen_CircleFill(uint16_t x,uint16_t y,uint16_t r,uint8_t color)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"CIRF(");
|
||||||
|
p=buf_u32(p,x); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,y); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,r); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,color);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_DrawText32(uint16_t x, uint16_t y, const char *text, uint8_t color) {
|
/* 设置背景颜色 */
|
||||||
sprintf(txbuf, "DC32(%u,%u,'%s',%u);\r\n", (unsigned)x, (unsigned)y, text, (unsigned)color);
|
void Screen_SetBGColor(uint8_t color)
|
||||||
Screen_SendCmd(txbuf);
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"SBC(");
|
||||||
|
p=buf_u32(p,color);
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_DrawText32V(uint16_t x, uint16_t y, const char *text, uint8_t color) {
|
/* =========================================================
|
||||||
sprintf(txbuf, "DCV32(%u,%u,'%s',%u);\r\n", (unsigned)x, (unsigned)y, text, (unsigned)color);
|
GBK核心(所有字号)
|
||||||
Screen_SendCmd(txbuf);
|
========================================================= */
|
||||||
|
|
||||||
|
/* 绘制GBK文本的核心函数 */
|
||||||
|
static void draw_gbk(const char *cmd,
|
||||||
|
uint16_t x,uint16_t y,
|
||||||
|
const uint8_t *gbk,uint16_t len,
|
||||||
|
uint8_t color,
|
||||||
|
uint8_t extra,
|
||||||
|
uint8_t has_extra)
|
||||||
|
{
|
||||||
|
uint16_t p=0;
|
||||||
|
|
||||||
|
p=buf_str(p,cmd);
|
||||||
|
txbuf[p++]='(';
|
||||||
|
p=buf_u32(p,x); txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,y); txbuf[p++]=',';
|
||||||
|
txbuf[p++]='\'';
|
||||||
|
|
||||||
|
memcpy(&txbuf[p],gbk,len);
|
||||||
|
p+=len;
|
||||||
|
|
||||||
|
txbuf[p++]='\'';
|
||||||
|
txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,color);
|
||||||
|
|
||||||
|
if(has_extra){
|
||||||
|
txbuf[p++]=',';
|
||||||
|
p=buf_u32(p,extra);
|
||||||
|
}
|
||||||
|
|
||||||
|
p=buf_str(p,");\r\n");
|
||||||
|
send_buf(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen_DrawText48(uint16_t x, uint16_t y, const char *text, uint8_t color, uint8_t transparent) {
|
/* 16号字体GBK文本绘制 */
|
||||||
sprintf(txbuf, "DC48(%u,%u,'%s',%u,%u);\r\n", (unsigned)x, (unsigned)y, text, (unsigned)color, (unsigned)transparent);
|
void Screen_DrawText16_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DC16",x,y,g,l,c,0,0);}
|
||||||
Screen_SendCmd(txbuf);
|
void Screen_DrawText16V_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DCV16",x,y,g,l,c,0,0);}
|
||||||
}
|
|
||||||
|
|
||||||
void Screen_Button(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const char *label, uint8_t fontColor, uint8_t bgColor, uint8_t pressFlag, uint8_t style) {
|
/* 24号字体GBK文本绘制 */
|
||||||
sprintf(txbuf, "BTN(%u,%u,%u,%u,'%s',%u,%u,%u,%u);\r\n", (unsigned)x, (unsigned)y, (unsigned)w, (unsigned)h, label, (unsigned)fontColor, (unsigned)bgColor, (unsigned)pressFlag, (unsigned)style);
|
void Screen_DrawText24_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DC24",x,y,g,l,c,0,0);}
|
||||||
Screen_SendCmd(txbuf);
|
void Screen_DrawText24V_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DCV24",x,y,g,l,c,0,0);}
|
||||||
}
|
|
||||||
|
|
||||||
void Screen_QRCode(uint16_t x, uint16_t y, const char *url) {
|
/* 32号字体GBK文本绘制 */
|
||||||
sprintf(txbuf, "QRCODE(%u,%u,%s);\r\n", (unsigned)x, (unsigned)y, url);
|
void Screen_DrawText32_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DC32",x,y,g,l,c,0,0);}
|
||||||
Screen_SendCmd(txbuf);
|
void Screen_DrawText32V_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DCV32",x,y,g,l,c,0,0);}
|
||||||
}
|
|
||||||
|
|
||||||
void Screen_QRCodeEx(uint16_t x, uint16_t y, const char *url, uint16_t size, uint8_t color) {
|
/* 48号字体GBK文本绘制 */
|
||||||
sprintf(txbuf, "QRCODE(%u,%u,%s,%u,%u);\r\n", (unsigned)x, (unsigned)y, url, (unsigned)size, (unsigned)color);
|
void Screen_DrawText48_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c,uint8_t t)
|
||||||
Screen_SendCmd(txbuf);
|
{draw_gbk("DC48",x,y,g,l,c,t,1);}
|
||||||
}
|
|
||||||
|
|
||||||
void Screen_Ver(void) {
|
/* =========================================================
|
||||||
sprintf(txbuf, "VER();\r\n");
|
版本查询
|
||||||
Screen_SendCmd(txbuf);
|
========================================================= */
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN AdditionalFunctions */
|
/* 查询屏幕版本信息 */
|
||||||
/* 可以在这里扩展更多绘图/控件函数供应用层调用 */
|
void Screen_Ver(void)
|
||||||
|
{
|
||||||
/* USER CODE END AdditionalFunctions */
|
uint16_t p=0;
|
||||||
|
p=buf_str(p,"VER();\r\n");
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
send_buf(p);
|
||||||
|
}
|
||||||
@@ -52,7 +52,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
|||||||
/* Enable TIM8 clock */
|
/* Enable TIM8 clock */
|
||||||
__HAL_RCC_TIM8_CLK_ENABLE();
|
__HAL_RCC_TIM8_CLK_ENABLE();
|
||||||
|
|
||||||
/* Get clock configuration */
|
/* Get clock configuration */
|
||||||
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
|
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
|
||||||
|
|
||||||
/* Compute TIM8 clock */
|
/* Compute TIM8 clock */
|
||||||
@@ -65,12 +65,11 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
|||||||
htim8.Instance = TIM8;
|
htim8.Instance = TIM8;
|
||||||
|
|
||||||
/* Initialize TIMx peripheral as follow:
|
/* Initialize TIMx peripheral as follow:
|
||||||
|
* Period = [(TIM8CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||||
+ Period = [(TIM8CLK/1000) - 1]. to have a (1/1000) s time base.
|
* Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
|
||||||
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
|
* ClockDivision = 0
|
||||||
+ ClockDivision = 0
|
* Counter direction = Up
|
||||||
+ Counter direction = Up
|
*/
|
||||||
*/
|
|
||||||
htim8.Init.Period = (1000000U / 1000U) - 1U;
|
htim8.Init.Period = (1000000U / 1000U) - 1U;
|
||||||
htim8.Init.Prescaler = uwPrescalerValue;
|
htim8.Init.Prescaler = uwPrescalerValue;
|
||||||
htim8.Init.ClockDivision = 0;
|
htim8.Init.ClockDivision = 0;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user