删除测温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 */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define HOT_Pin GPIO_PIN_1
|
||||
#define HOT_GPIO_Port GPIOA
|
||||
#define RUN_LED_Pin GPIO_PIN_12
|
||||
#define RUN_LED_GPIO_Port GPIOB
|
||||
#define ERR_LED_Pin GPIO_PIN_13
|
||||
@@ -71,6 +69,8 @@ void Error_Handler(void);
|
||||
#define HOT_KEY_GPIO_Port GPIOC
|
||||
#define TIME_KEY_Pin GPIO_PIN_9
|
||||
#define TIME_KEY_GPIO_Port GPIOC
|
||||
#define HOT_Pin GPIO_PIN_8
|
||||
#define HOT_GPIO_Port GPIOA
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
|
||||
@@ -16,6 +16,11 @@ extern "C" {
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* 颜色使用统一的标志 */
|
||||
#define TEXT_COLOR 15 /* 白色 */
|
||||
#define BG_COLOR 0 /* 黑色 */
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 发送原始命令字符串到屏幕(阻塞直到发送完成)
|
||||
@@ -24,6 +29,7 @@ extern "C" {
|
||||
*/
|
||||
int Screen_SendCmd(const char *cmd);
|
||||
|
||||
void Screen_Init(void);
|
||||
|
||||
/* 常用封装 - 简短说明见各函数 */
|
||||
/** 清屏,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_CircleFill(uint16_t x, uint16_t y, uint16_t r, 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_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);
|
||||
|
||||
// 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
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
*/
|
||||
|
||||
#define HAL_MODULE_ENABLED
|
||||
#define HAL_ADC_MODULE_ENABLED
|
||||
/*#define HAL_ADC_MODULE_ENABLED */
|
||||
/*#define HAL_CRYP_MODULE_ENABLED */
|
||||
/*#define HAL_CAN_MODULE_ENABLED */
|
||||
/*#define HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
|
||||
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 */
|
||||
@@ -19,20 +19,19 @@
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "main.h"
|
||||
#include "task.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "usart.h"
|
||||
#include "adc.h"
|
||||
#include "tim.h"
|
||||
#include "motor_driver.h"
|
||||
#include "elog.h"
|
||||
#include "motor_driver.h"
|
||||
#include "screen.h"
|
||||
#include "tim.h"
|
||||
#include "usart.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "screen.h"
|
||||
#include <string.h>
|
||||
#include <sys/_intsup.h>
|
||||
|
||||
@@ -65,7 +64,8 @@ PUTCHAR_PROTOTYPE {
|
||||
/* Private 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_prev = 0; /* 上一次的按键状态,用于检测按键变化 */
|
||||
|
||||
@@ -95,13 +95,6 @@ const osThreadAttr_t Sensor_Task_attributes = {
|
||||
.stack_size = 512 * 4,
|
||||
.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 */
|
||||
osThreadId_t Motor_TaskHandle;
|
||||
const osThreadAttr_t Motor_Task_attributes = {
|
||||
@@ -125,7 +118,6 @@ const osThreadAttr_t Screen_Tsak_attributes = {
|
||||
void StartDefaultTask(void *argument);
|
||||
void Key(void *argument);
|
||||
void Sensor(void *argument);
|
||||
void Temp(void *argument);
|
||||
void Motor(void *argument);
|
||||
void Screen(void *argument);
|
||||
|
||||
@@ -161,7 +153,8 @@ void MX_FREERTOS_Init(void) {
|
||||
|
||||
/* Create the thread(s) */
|
||||
/* creation of defaultTask */
|
||||
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
||||
defaultTaskHandle =
|
||||
osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
||||
|
||||
/* creation of KeyTask */
|
||||
KeyTaskHandle = osThreadNew(Key, NULL, &KeyTask_attributes);
|
||||
@@ -169,9 +162,6 @@ void MX_FREERTOS_Init(void) {
|
||||
/* creation of Sensor_Task */
|
||||
Sensor_TaskHandle = osThreadNew(Sensor, NULL, &Sensor_Task_attributes);
|
||||
|
||||
/* creation of Temp_Task */
|
||||
Temp_TaskHandle = osThreadNew(Temp, NULL, &Temp_Task_attributes);
|
||||
|
||||
/* creation of Motor_Task */
|
||||
Motor_TaskHandle = osThreadNew(Motor, NULL, &Motor_Task_attributes);
|
||||
|
||||
@@ -185,7 +175,6 @@ void MX_FREERTOS_Init(void) {
|
||||
/* USER CODE BEGIN RTOS_EVENTS */
|
||||
/* add events, ... */
|
||||
/* USER CODE END RTOS_EVENTS */
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||
@@ -195,39 +184,51 @@ void MX_FREERTOS_Init(void) {
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_StartDefaultTask */
|
||||
void StartDefaultTask(void *argument)
|
||||
{
|
||||
void StartDefaultTask(void *argument) {
|
||||
/* USER CODE BEGIN StartDefaultTask */
|
||||
// 初始化命令
|
||||
uint8_t init_cmd1[] = {0x7E, 0xFF, 0x06, 0x06, 0x00, 0x00, 0x1E, 0xFE, 0xD7, 0xEF}; // 开启声音
|
||||
uint8_t init_cmd2[] = {0x7E, 0xFF, 0x06, 0x09, 0x00, 0x00, 0x02, 0xFE, 0xF0, 0xEF}; // 指定播放设备为TF卡
|
||||
uint8_t init_cmd1[] = {0x7E, 0xFF, 0x06, 0x06, 0x00,
|
||||
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);
|
||||
|
||||
// 初始化:先发送开启声音指令,再发送指定播放设备指令
|
||||
HAL_UART_Transmit(&huart3, init_cmd1, sizeof(init_cmd1), 1000);
|
||||
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);
|
||||
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 */
|
||||
for(;;)
|
||||
{
|
||||
for (;;) {
|
||||
// 直接整包发送测试指令
|
||||
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);
|
||||
|
||||
HAL_GPIO_TogglePin(RUN_LED_GPIO_Port, RUN_LED_Pin);
|
||||
|
||||
osDelay(1000); // 延时1秒
|
||||
osDelay(10000); // 延时1秒
|
||||
}
|
||||
/* USER CODE END StartDefaultTask */
|
||||
}
|
||||
@@ -239,20 +240,20 @@ void StartDefaultTask(void *argument)
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_Key */
|
||||
void Key(void *argument)
|
||||
{
|
||||
void Key(void *argument) {
|
||||
/* 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};
|
||||
const uint16_t key_pins[4] = {M__KEY_Pin, M__KEYC7_Pin, HOT_KEY_Pin, TIME_KEY_Pin};
|
||||
GPIO_TypeDef *key_ports[4] = {M__KEY_GPIO_Port, M__KEYC7_GPIO_Port,
|
||||
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 release_count[4] = {0};
|
||||
uint8_t pressed[4] = {0};
|
||||
const uint8_t THRESH = 3; /* 3 * 10ms = 30ms 防抖 */
|
||||
|
||||
for(;;)
|
||||
{
|
||||
for (;;) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
GPIO_PinState level = HAL_GPIO_ReadPin(key_ports[i], key_pins[i]);
|
||||
if (level == GPIO_PIN_RESET) { /* 低电平有效 */
|
||||
@@ -283,14 +284,12 @@ void Key(void *argument)
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_Sensor */
|
||||
void Sensor(void *argument)
|
||||
{
|
||||
void Sensor(void *argument) {
|
||||
/* USER CODE BEGIN Sensor */
|
||||
/* 按键处理任务 - 按键状态切换控制 */
|
||||
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
for (;;) {
|
||||
/* 检测新按下的按键 */
|
||||
uint8_t key_pressed = key_state & ~key_state_prev;
|
||||
key_state_prev = key_state;
|
||||
@@ -317,7 +316,9 @@ void Sensor(void *argument)
|
||||
if (key_pressed & (1 << 2)) {
|
||||
/* HOT_KEY 按下:切换热功能 */
|
||||
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) 控制 ===== */
|
||||
@@ -336,119 +337,6 @@ void Sensor(void *argument)
|
||||
/* 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 */
|
||||
/**
|
||||
* @brief Function implementing the Motor_Task thread.
|
||||
@@ -456,16 +344,14 @@ void Temp(void *argument)
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_Motor */
|
||||
void Motor(void *argument)
|
||||
{
|
||||
void Motor(void *argument) {
|
||||
/* USER CODE BEGIN Motor */
|
||||
|
||||
/* 电机驱动初始化 */
|
||||
Motor_Init();
|
||||
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
for (;;) {
|
||||
/* 电机任务主要功能:
|
||||
* - 监控电机状态(超温保护、过流保护等)
|
||||
* - 定期打印状态信息
|
||||
@@ -488,16 +374,12 @@ void Motor(void *argument)
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_Screen */
|
||||
void Screen(void *argument)
|
||||
{
|
||||
void Screen(void *argument) {
|
||||
/* USER CODE BEGIN Screen */
|
||||
char buf[100];
|
||||
sprintf(buf, "CLR(1);\r\n");
|
||||
Screen_Init();
|
||||
// HAL_UART_Transmit(&huart1, (uint8_t *)buf, strlen(buf), HAL_MAX_DELAY);
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
HAL_UART_Transmit(&huart1, (uint8_t *)buf, strlen(buf), HAL_MAX_DELAY);
|
||||
for (;;) {
|
||||
|
||||
osDelay(2000);
|
||||
}
|
||||
@@ -508,4 +390,3 @@ void Screen(void *argument)
|
||||
/* USER CODE BEGIN Application */
|
||||
|
||||
/* USER CODE END Application */
|
||||
|
||||
|
||||
@@ -46,23 +46,16 @@ void MX_GPIO_Init(void)
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_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 */
|
||||
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 */
|
||||
GPIO_InitStruct.Pin = RUN_LED_Pin|ERR_LED_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
@@ -76,6 +69,13 @@ void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
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 */
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "adc.h"
|
||||
#include "tim.h"
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
@@ -91,7 +90,6 @@ int main(void)
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_UART5_Init();
|
||||
MX_USART1_UART_Init();
|
||||
MX_USART3_UART_Init();
|
||||
@@ -101,9 +99,7 @@ int main(void)
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Init scheduler */
|
||||
osKernelInitialize();
|
||||
|
||||
/* Call init function for freertos objects (in cmsis_os2.c) */
|
||||
osKernelInitialize(); /* Call init function for freertos objects (in cmsis_os2.c) */
|
||||
MX_FREERTOS_Init();
|
||||
|
||||
/* Start scheduler */
|
||||
@@ -131,7 +127,6 @@ void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
@@ -161,12 +156,6 @@ void SystemClock_Config(void)
|
||||
{
|
||||
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 */
|
||||
@@ -186,7 +175,8 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
/* USER CODE BEGIN Callback 0 */
|
||||
|
||||
/* USER CODE END Callback 0 */
|
||||
if (htim->Instance == TIM8) {
|
||||
if (htim->Instance == TIM8)
|
||||
{
|
||||
HAL_IncTick();
|
||||
}
|
||||
/* USER CODE BEGIN Callback 1 */
|
||||
@@ -208,7 +198,6 @@ void Error_Handler(void)
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
|
||||
@@ -8,182 +8,316 @@
|
||||
/* USER CODE END Header */
|
||||
|
||||
#include "screen.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "main.h"
|
||||
#include "usart.h"
|
||||
#include "cmsis_os.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* 模块初始化:不要使用 MP3 的二进制初始化指令,改为屏幕清屏作为默认初始化 */
|
||||
#include <stdint.h>
|
||||
#include "gbk_text.h"
|
||||
|
||||
/* 发送缓冲 */
|
||||
static char txbuf[256];
|
||||
static uint8_t txbuf[512];
|
||||
|
||||
/* =========================================================
|
||||
内部工具函数(替代 sprintf)
|
||||
========================================================= */
|
||||
|
||||
/**
|
||||
* @brief 发送字符串到串口屏(阻塞直到发送完成)
|
||||
* @param cmd: 要发送的C字符串(不强制包含结尾CR/LF)
|
||||
* @retval 0=OK, <0=错误
|
||||
*/
|
||||
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);
|
||||
/* 将字符串复制到发送缓冲区 */
|
||||
static uint16_t buf_str(uint16_t p,const char *s)
|
||||
{
|
||||
while(*s) txbuf[p++]=*s++;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* 将32位无符号整数转换为字符串并复制到发送缓冲区 */
|
||||
static uint16_t buf_u32(uint16_t p,uint32_t v)
|
||||
{
|
||||
char tmp[12];
|
||||
int i=0;
|
||||
if(v==0){ txbuf[p++]='0'; return p; }
|
||||
while(v){ tmp[i++]=v%10+'0'; v/=10; }
|
||||
while(i--) txbuf[p++]=tmp[i];
|
||||
return p;
|
||||
}
|
||||
|
||||
/* 发送指定长度的数据 */
|
||||
static void send_buf(uint16_t len)
|
||||
{
|
||||
HAL_UART_Transmit(&huart1,txbuf,len,HAL_MAX_DELAY);
|
||||
osDelay(100);
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
基础接口
|
||||
========================================================= */
|
||||
|
||||
/* 发送数据缓冲区 */
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 发送命令并等待模块返回 "OK\r\n",超时返回非0
|
||||
*/
|
||||
int Screen_SendCmdWaitOK(const char *cmd, uint32_t timeout_ms) {
|
||||
/* 发送命令字符串 */
|
||||
int Screen_SendCmd(const char *cmd)
|
||||
{
|
||||
if(!cmd) return -1;
|
||||
return Screen_SendBuf((uint8_t*)cmd,strlen(cmd));
|
||||
}
|
||||
|
||||
/* 发送命令并等待确认(当前未实现超时机制) */
|
||||
int Screen_SendCmdWaitOK(const char *cmd,uint32_t timeout_ms)
|
||||
{
|
||||
(void)timeout_ms;
|
||||
/* 保留接口:当前不等待屏幕回包,直接发送后返回发送状态 */
|
||||
return Screen_SendCmd(cmd);
|
||||
}
|
||||
|
||||
void Screen_Init(void) {
|
||||
/*
|
||||
* 屏幕初始化:简单实现为上电等待并清除屏幕
|
||||
* 若需要按照厂商例程发送更多配置指令,可在此扩展
|
||||
*/
|
||||
/* =========================================================
|
||||
初始化
|
||||
========================================================= */
|
||||
|
||||
/* 屏幕初始化函数 */
|
||||
void Screen_Init(void)
|
||||
{
|
||||
osDelay(1000);
|
||||
Screen_Clear(0);
|
||||
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_Clear(uint8_t layer) {
|
||||
sprintf(txbuf, "DIR(1);CLR(%u);\r\n", (unsigned)layer);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* =========================================================
|
||||
基础命令(全部保留)
|
||||
========================================================= */
|
||||
|
||||
/* 清除指定图层 */
|
||||
void Screen_Clear(uint8_t layer)
|
||||
{
|
||||
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_DisplayImage(uint32_t addr) {
|
||||
sprintf(txbuf, "DIR(1);FSIMG(%lu,0,0,128,128,0);\r\n", (unsigned long)addr);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 显示指定地址的图片 */
|
||||
void Screen_DisplayImage(uint32_t addr)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"DIR(1);FSIMG(");
|
||||
p=buf_u32(p,addr);
|
||||
p=buf_str(p,",0,0,128,128,0);\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
void Screen_SetBrightness(uint8_t val) {
|
||||
sprintf(txbuf, "BL(%u);\r\n", (unsigned)val);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 设置屏幕亮度 */
|
||||
void Screen_SetBrightness(uint8_t val)
|
||||
{
|
||||
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_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_SetRotation(uint8_t dir)
|
||||
{
|
||||
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_SetRotation(uint8_t dir) {
|
||||
sprintf(txbuf, "DIR(%u);\r\n", dir);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 设置串口波特率 */
|
||||
void Screen_SetBaud(uint32_t baud)
|
||||
{
|
||||
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_SetBaud(uint32_t baud) {
|
||||
sprintf(txbuf, "BPS(%lu);\r\n", (unsigned long)baud);
|
||||
Screen_SendCmd(txbuf);
|
||||
}
|
||||
void Screen_DisplayImageAtAddr(uint32_t addr, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t mode) {
|
||||
sprintf(txbuf, "FSIMG(%lu,%u,%u,%u,%u,%u);\r\n", (unsigned long)addr, (unsigned)x, (unsigned)y, (unsigned)w, (unsigned)h, (unsigned)mode);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 在指定位置显示图片 */
|
||||
void Screen_DisplayImageAtAddr(uint32_t addr,uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint8_t mode)
|
||||
{
|
||||
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_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);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 通过索引显示图片 */
|
||||
void Screen_DisplayImageByIndex(uint32_t index,uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint8_t mode)
|
||||
{
|
||||
Screen_DisplayImageAtAddr(index,x,y,w,h,mode);
|
||||
}
|
||||
|
||||
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);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 绘制单个像素点 */
|
||||
void Screen_Pixel(uint16_t x,uint16_t y,uint8_t color)
|
||||
{
|
||||
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_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);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 绘制直线 */
|
||||
void Screen_Line(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t color)
|
||||
{
|
||||
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_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);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 绘制矩形框 */
|
||||
void Screen_Box(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t color)
|
||||
{
|
||||
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_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);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 绘制填充矩形 */
|
||||
void Screen_BoxFill(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t color)
|
||||
{
|
||||
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_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);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 绘制圆形 */
|
||||
void Screen_Circle(uint16_t x,uint16_t y,uint16_t r,uint8_t color)
|
||||
{
|
||||
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_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);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 绘制填充圆形 */
|
||||
void Screen_CircleFill(uint16_t x,uint16_t y,uint16_t r,uint8_t color)
|
||||
{
|
||||
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_SetBGColor(uint8_t color) {
|
||||
sprintf(txbuf, "SBC(%u);\r\n", (unsigned)color);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 设置背景颜色 */
|
||||
void Screen_SetBGColor(uint8_t color)
|
||||
{
|
||||
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_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);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* =========================================================
|
||||
GBK核心(所有字号)
|
||||
========================================================= */
|
||||
|
||||
/* 绘制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);
|
||||
}
|
||||
|
||||
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);
|
||||
Screen_SendCmd(txbuf);
|
||||
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);
|
||||
Screen_SendCmd(txbuf);
|
||||
/* 16号字体GBK文本绘制 */
|
||||
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);}
|
||||
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);}
|
||||
|
||||
/* 24号字体GBK文本绘制 */
|
||||
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);}
|
||||
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);}
|
||||
|
||||
/* 32号字体GBK文本绘制 */
|
||||
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);}
|
||||
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);}
|
||||
|
||||
/* 48号字体GBK文本绘制 */
|
||||
void Screen_DrawText48_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c,uint8_t t)
|
||||
{draw_gbk("DC48",x,y,g,l,c,t,1);}
|
||||
|
||||
/* =========================================================
|
||||
版本查询
|
||||
========================================================= */
|
||||
|
||||
/* 查询屏幕版本信息 */
|
||||
void Screen_Ver(void)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"VER();\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);
|
||||
Screen_SendCmd(txbuf);
|
||||
}
|
||||
|
||||
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);
|
||||
Screen_SendCmd(txbuf);
|
||||
}
|
||||
|
||||
void Screen_DrawText48(uint16_t x, uint16_t y, const char *text, uint8_t color, uint8_t transparent) {
|
||||
sprintf(txbuf, "DC48(%u,%u,'%s',%u,%u);\r\n", (unsigned)x, (unsigned)y, text, (unsigned)color, (unsigned)transparent);
|
||||
Screen_SendCmd(txbuf);
|
||||
}
|
||||
|
||||
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) {
|
||||
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);
|
||||
Screen_SendCmd(txbuf);
|
||||
}
|
||||
|
||||
void Screen_QRCode(uint16_t x, uint16_t y, const char *url) {
|
||||
sprintf(txbuf, "QRCODE(%u,%u,%s);\r\n", (unsigned)x, (unsigned)y, url);
|
||||
Screen_SendCmd(txbuf);
|
||||
}
|
||||
|
||||
void Screen_QRCodeEx(uint16_t x, uint16_t y, const char *url, uint16_t size, uint8_t color) {
|
||||
sprintf(txbuf, "QRCODE(%u,%u,%s,%u,%u);\r\n", (unsigned)x, (unsigned)y, url, (unsigned)size, (unsigned)color);
|
||||
Screen_SendCmd(txbuf);
|
||||
}
|
||||
|
||||
void Screen_Ver(void) {
|
||||
sprintf(txbuf, "VER();\r\n");
|
||||
Screen_SendCmd(txbuf);
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN AdditionalFunctions */
|
||||
/* 可以在这里扩展更多绘图/控件函数供应用层调用 */
|
||||
|
||||
/* USER CODE END AdditionalFunctions */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -65,11 +65,10 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
htim8.Instance = TIM8;
|
||||
|
||||
/* Initialize TIMx peripheral as follow:
|
||||
|
||||
+ Period = [(TIM8CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
|
||||
+ ClockDivision = 0
|
||||
+ Counter direction = Up
|
||||
* Period = [(TIM8CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||
* Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
|
||||
* ClockDivision = 0
|
||||
* Counter direction = Up
|
||||
*/
|
||||
htim8.Init.Period = (1000000U / 1000U) - 1U;
|
||||
htim8.Init.Prescaler = uwPrescalerValue;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user