配置 PWM ADC LCD

This commit is contained in:
2026-07-14 17:51:39 +08:00
parent 0a5c478a42
commit 2d0d000a38
67 changed files with 33357 additions and 911 deletions

View File

@@ -9,6 +9,10 @@ STM32CubeMX 生成的项目,使用 **Keil MDK-ARM V5.32** 工具链。
- `STM32F103C8T6/MDK-ARM/STM32F103C8T6.uvprojx` — Keil 工程文件 - `STM32F103C8T6/MDK-ARM/STM32F103C8T6.uvprojx` — Keil 工程文件
- `STM32F103C8T6/Drivers/BSP/MultiButton/` — MultiButton 按键驱动库 - `STM32F103C8T6/Drivers/BSP/MultiButton/` — MultiButton 按键驱动库
- `STM32F103C8T6/Drivers/BSP/LCD/` — ST7735S LCD 驱动 - `STM32F103C8T6/Drivers/BSP/LCD/` — ST7735S LCD 驱动
- `st7735s.c/h` — 底层驱动SPI通信、初始化、填充、画点
- `lcd.c/h` — 绘图模块(字符/字符串、线条、矩形、圆形)
- `lcd_data.c/h` — ASCII 8×16 字库
- `hz16_data.c/h` — CJK 16×16 字库
## 硬件配置 ## 硬件配置
- **MCU**: STM32F103C8T6 (LQFP48, 72MHz, 64KB Flash, 20KB RAM) - **MCU**: STM32F103C8T6 (LQFP48, 72MHz, 64KB Flash, 20KB RAM)
@@ -19,42 +23,45 @@ STM32CubeMX 生成的项目,使用 **Keil MDK-ARM V5.32** 工具链。
- LED: PC13 (低电平有效,上拉) - LED: PC13 (低电平有效,上拉)
- 按键: PB3 (KEY1), PB4 (KEY2), PB5 (KEY3), PC14 (KEY4), PC15 (KEY5) — 下拉 - 按键: PB3 (KEY1), PB4 (KEY2), PB5 (KEY3), PC14 (KEY4), PC15 (KEY5) — 下拉
- LCD: PB10 (DC), PB11 (CS), PB12 (RST), PB13 (SCK), PB15 (SDA) — ST7735S 128x160 - LCD: PB10 (DC), PB11 (CS), PB12 (RST), PB13 (SCK), PB15 (SDA) — ST7735S 128x160
- TIM4: PB6~9 四路 1kHz PWM
- TIM3: CH4 内部触发 ADC1 注入组
- ADC1: IN0~IN3 (PA0~PA3), 注入组, TIM3_CH4 触发
## MultiButton 按键库 ## 初始化顺序main.c
- **来源**: [0x1abin/MultiButton](https://github.com/0x1abin/MultiButton) ```
- **功能**: 事件驱动型按键驱动,支持单击、双击、长按、连击等事件 HAL_Init → SystemClock_Config → MX_GPIO → MX_DMA → MX_USART1 → MX_SPI2
- **文件**: → MX_TIM4 → MX_ADC1 → MX_TIM3
- `Drivers/BSP/MultiButton/multi_button.c/.h` — 核心库文件 → button_driver_init() → st7735s_init() → lcd_* draw → PWM start → ADC start
- `Drivers/BSP/MultiButton/button_driver.c/.h` — 本项目适配层 ```
- **定时器**: SysTick 中断中每5ms调用 `button_ticks()`
- **使用示例**: ## ADC 采坑记录(不可从 CubeMX 重新生成时光靠设置)
- **ADC 时钟**: SystemClock_Config 初始为 PCLK2/2=36MHz超 14MHz 规格),必须在 `USER CODE SysInit` 中手动改为 `/6`
```c ```c
/* 在回调函数中处理按键事件 */ RCC->CFGR = (RCC->CFGR & ~RCC_CFGR_ADCPRE) | RCC_CFGR_ADCPRE_DIV6;
static void button_key1_callback(Button* handle, void* user_data) {
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
printf("KEY1: LED翻转\n");
}
/* 初始化时注册回调 */
button_attach(&btn_handle, BTN_SINGLE_CLICK, button_key1_callback, NULL);
``` ```
- **TIM3_CH4 触发 ADC**: CubeMX 默认生成 `TIM_OCMODE_TIMING`,这不会产生 OC4REF 上升沿 → ADC 收不到触发。必须在 `tim.c` 中手动改为 `TIM_OCMODE_PWM1` + `Pulse = 500`。CubeMX 需选 CH4 为 "PWM Generation4 No Output" 并设 Pulse=500。
## printf 无 MicroLIB
在 `usart.c` 中通过 `#pragma import(__use_no_semihosting)` + 提供 `_sys_exit()` + `struct __FILE` + `FILE __stdout` 实现。Keil 取消勾选 Use MicroLIB 即可。
## SPI 注意事项
- LCD (ST7735S) 使用**硬件SPI2**PB13 SCK, PB15 MOSI18MHz**Mode 3**CPOL=HIGH, CPHA=2EDGE
- 若通过 CubeMX 重新生成 `spi.c`,务必在 SPI2 配置中设置 Clock Polarity=High, Clock Phase=2 Edge
- CS(PB11)、DC(PB10)、RST(PB12) 为 GPIO 控制
## LCD 字库生成tools/font_gen.py
- Python + Pillow 渲染,使用 `C:\ProgramData\anaconda3\python.exe`
- ASCII 8×16默认`python font_gen.py`
- CJK 16×16按需`python font_gen.py --cjk --string "你的汉字" --output STM32F103C8T6/Drivers/BSP/LCD/hz16_data`
- ASCII 默认参数:`--font simsun --size 56 --threshold 64 --scale 4`
- CJK 默认参数:`--font simsun --size 48 --threshold 50 --scale 3`
- ASCII `_` 下划线手动设为 `0x7F`GDI 无法可靠提取)
- 输出目录 `MDK-ARM\STM32F103C8T6\` 已 gitignore
## 代码规范 ## 代码规范
- **遵循**: `嵌入式C语言代码规范V1.0.md` - **遵循**: `嵌入式C语言代码规范V1.0.md`
- **缩进**: 4个空格禁止Tab - **缩进**: 4个空格禁止Tab
- **命名**: - **命名**: 小写+下划线;全局加 `g_`,静态加 `s_`,指针加 `p_`;宏大写+下划线;类型 `_t` 后缀
- 变量/函数: 小写+下划线,全局变量`g_`前缀,静态变量`s_`前缀,指针`p_`前缀 - **注释**: 所有文档、注释、提交信息使用**中文**
- 宏/常量: 大写+下划线,模块名前缀
- 类型: 小写+下划线+`_t`后缀
- **注释**: 关键逻辑每行注释,函数必须完整注释(功能/参数/返回值/说明)
- **大括号**: 所有if/for/while必须加大括号左大括号同行右大括号单独行
- **禁止**: goto、递归、可变参数函数、注释掉的代码提交 - **禁止**: goto、递归、可变参数函数、注释掉的代码提交
- **CubeMX 代码**: 自定义代码必须在 `/* USER CODE BEGIN */``/* USER CODE END */` 之间;`Drivers/` 下 HAL 源码禁止直接修改
## 语言要求
- 所有文档、注释、提交信息必须使用**中文**
## 重要说明
- `Drivers/` 目录包含 HAL 驱动源码 — 禁止直接修改
- 通过 CubeMX `.ioc` 文件重新生成代码,禁止手动修改 HAL 文件
- Keil 构建输出在 `MDK-ARM/STM32F103C8T6/`(已 gitignore
- CubeMX 生成的代码中,自定义代码必须放在 `/* USER CODE BEGIN */` 和 `/* USER CODE END */` 之间

5071
ST7735S_V1.1_20111121.md Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,52 @@
/* 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__ */

View File

@@ -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 */
@@ -64,7 +64,7 @@
/*#define HAL_SMARTCARD_MODULE_ENABLED */ /*#define HAL_SMARTCARD_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED #define HAL_SPI_MODULE_ENABLED
/*#define HAL_SRAM_MODULE_ENABLED */ /*#define HAL_SRAM_MODULE_ENABLED */
/*#define HAL_TIM_MODULE_ENABLED */ #define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED
/*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */

View File

@@ -0,0 +1,57 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file tim.h
* @brief This file contains all the function prototypes for
* the tim.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 __TIM_H__
#define __TIM_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern TIM_HandleTypeDef htim3;
extern TIM_HandleTypeDef htim4;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_TIM3_Init(void);
void MX_TIM4_Init(void);
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __TIM_H__ */

View File

@@ -0,0 +1,172 @@
/* 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};
ADC_InjectionConfTypeDef sConfigInjected = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
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_1CYCLE_5;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Injected Channel
*/
sConfigInjected.InjectedChannel = ADC_CHANNEL_0;
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;
sConfigInjected.InjectedNbrOfConversion = 4;
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_41CYCLES_5;
sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T3_CC4;
sConfigInjected.AutoInjectedConv = DISABLE;
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
sConfigInjected.InjectedOffset = 0;
if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)
{
Error_Handler();
}
/** Configure Injected Channel
*/
sConfigInjected.InjectedChannel = ADC_CHANNEL_1;
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_2;
if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)
{
Error_Handler();
}
/** Configure Injected Channel
*/
sConfigInjected.InjectedChannel = ADC_CHANNEL_2;
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_3;
if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)
{
Error_Handler();
}
/** Configure Injected Channel
*/
sConfigInjected.InjectedChannel = ADC_CHANNEL_3;
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_4;
if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != 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
PA1 ------> ADC1_IN1
PA2 ------> ADC1_IN2
PA3 ------> ADC1_IN3
*/
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3;
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
PA1 ------> ADC1_IN1
PA2 ------> ADC1_IN2
PA3 ------> ADC1_IN3
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
/* USER CODE BEGIN ADC1_MspDeInit 1 */
/* USER CODE END ADC1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

View File

@@ -47,8 +47,8 @@ void MX_GPIO_Init(void)
/* GPIO Ports Clock Enable */ /* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */ /*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);

View File

@@ -18,16 +18,19 @@
/* USER CODE END Header */ /* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "main.h" #include "main.h"
#include "adc.h"
#include "dma.h" #include "dma.h"
#include "spi.h" #include "spi.h"
#include "tim.h"
#include "usart.h" #include "usart.h"
#include "gpio.h" #include "gpio.h"
#include "lcd_data.h"
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include <stdio.h> #include <stdio.h>
#include "button_driver.h" #include "button_driver.h"
#include "st7735s.h" #include "st7735s.h"
#include "lcd.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
@@ -86,7 +89,9 @@ int main(void)
SystemClock_Config(); SystemClock_Config();
/* USER CODE BEGIN SysInit */ /* USER CODE BEGIN SysInit */
/* ADC 时钟预分频PCLK2 / 6 = 72/6 = 12MHz */
/* 默认 /2=36MHz 超过 14MHz 规格ADC 无法正常工作 */
RCC->CFGR = (RCC->CFGR & ~RCC_CFGR_ADCPRE) | RCC_CFGR_ADCPRE_DIV6;
/* USER CODE END SysInit */ /* USER CODE END SysInit */
/* Initialize all configured peripherals */ /* Initialize all configured peripherals */
@@ -94,18 +99,47 @@ int main(void)
MX_DMA_Init(); MX_DMA_Init();
MX_USART1_UART_Init(); MX_USART1_UART_Init();
MX_SPI2_Init(); MX_SPI2_Init();
MX_TIM4_Init();
MX_ADC1_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
printf("\r\nSTM32F103C8T6 Boot OK\r\n"); printf("\r\nSTM32F103C8T6 Boot OK\r\n");
button_driver_init(); button_driver_init();
st7735s_init(); st7735s_init();
st7735s_fill_screen(COLOR_RED); st7735s_fill_screen(COLOR_RED);
HAL_Delay(500); HAL_Delay(500);
st7735s_fill_screen(COLOR_GREEN);
HAL_Delay(500);
st7735s_fill_screen(COLOR_BLUE);
HAL_Delay(500);
st7735s_fill_screen(COLOR_BLACK); st7735s_fill_screen(COLOR_BLACK);
st7735s_draw_string(0, 0, "LCD OK", COLOR_WHITE, COLOR_BLACK); lcd_draw_string(0, 0, "01234", COLOR_WHITE, COLOR_BLACK);
lcd_draw_string(0, 16, "LCD_OK", COLOR_WHITE, COLOR_BLACK);
lcd_draw_chinese_string(0, 32, "\xE9\x98\x9C\xE9\x98\xB3\xE5\xB8\x88\xE8\x8C\x83\xE5\xA4\xA7\xE5\xAD\xA6", COLOR_WHITE, COLOR_BLACK); /*阜阳师范大学*/
lcd_draw_chinese_string(0, 48, "\xE7\x94\xB5\xE5\xAD\x90\xE8\xAE\xBE\xE8\xAE\xA1\xE7\xAB\x9E\xE8\xB5\x9B", COLOR_WHITE, COLOR_BLACK); /*电子设计竞赛*/
/* 启动 TIM4 四路 PWM */
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1); /* PB6 */
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_2); /* PB7 */
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); /* PB8 */
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4); /* PB9 */
/* 设置占空比0~999 对应 0%~100% */
__HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, 500); /* 50% */
__HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, 250); /* 25% */
__HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, 750); /* 75% */
__HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, 999); /* 100% */
/* === 测试:常规组软件触发,确认 ADC 硬件正常 === */
HAL_ADC_Start(&hadc1);
if (HAL_ADC_PollForConversion(&hadc1, 100) == HAL_OK) {
printf("ADC REG TEST: %d\r\n", HAL_ADC_GetValue(&hadc1));
}
HAL_ADC_Stop(&hadc1);
/* 启动 TIM3 CH4产生 ADC 触发信号) */
HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_4);
/* 启动 ADC 注入组TIM3 每触发一次,自动采一轮 PA0~PA3 */
HAL_ADCEx_InjectedStart(&hadc1);
/* USER CODE END 2 */ /* USER CODE END 2 */
/* Infinite loop */ /* Infinite loop */
@@ -115,9 +149,15 @@ int main(void)
/* USER CODE END WHILE */ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */
HAL_Delay(500); HAL_Delay(1000);
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
//printf("Hello word\n");
/* 读取 ADC 注入组结果TIM3 以 1kHz 触发,每秒打印一次最新值) */
uint16_t adc0 = HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_1);
uint16_t adc1 = HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_2);
uint16_t adc2 = HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_3);
uint16_t adc3 = HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_4);
printf("ADC: %4d %4d %4d %4d\r\n", adc0, adc1, adc2, adc3);
} }
/* USER CODE END 3 */ /* USER CODE END 3 */
} }
@@ -130,6 +170,7 @@ 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.
@@ -159,6 +200,12 @@ void SystemClock_Config(void)
{ {
Error_Handler(); Error_Handler();
} }
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
} }
/* USER CODE BEGIN 4 */ /* USER CODE BEGIN 4 */

View File

@@ -42,8 +42,8 @@ void MX_SPI2_Init(void)
hspi2.Init.Mode = SPI_MODE_MASTER; hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES; hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT; hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW; hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE; hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT; hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;

View File

@@ -0,0 +1,239 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file tim.c
* @brief This file provides code for the configuration
* of the TIM 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 "tim.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
TIM_HandleTypeDef htim3;
TIM_HandleTypeDef htim4;
/* TIM3 init function */
void MX_TIM3_Init(void)
{
/* USER CODE BEGIN TIM3_Init 0 */
/* USER CODE END TIM3_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
/* USER CODE BEGIN TIM3_Init 1 */
/* USER CODE END TIM3_Init 1 */
htim3.Instance = TIM3;
htim3.Init.Prescaler = 71;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 999;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 500;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM3_Init 2 */
/* 注意:若从 CubeMX 重新生成,务必在 TIM3 CH4 的 OC Mode 选 PWM1Pulse 设 500
否则 ADC 注入组外部触发无法工作。
此处手动修改 sConfigOC.OCMode 和 sConfigOC.Pulse 为 PWM1/500 */
/* USER CODE END TIM3_Init 2 */
}
/* TIM4 init function */
void MX_TIM4_Init(void)
{
/* USER CODE BEGIN TIM4_Init 0 */
/* USER CODE END TIM4_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
/* USER CODE BEGIN TIM4_Init 1 */
/* USER CODE END TIM4_Init 1 */
htim4.Instance = TIM4;
htim4.Init.Prescaler = 71;
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
htim4.Init.Period = 999;
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Init(&htim4) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 500;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
sConfigOC.Pulse = 0;
if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
{
Error_Handler();
}
sConfigOC.Pulse = 500;
if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM4_Init 2 */
/* USER CODE END TIM4_Init 2 */
HAL_TIM_MspPostInit(&htim4);
}
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
{
if(tim_baseHandle->Instance==TIM3)
{
/* USER CODE BEGIN TIM3_MspInit 0 */
/* USER CODE END TIM3_MspInit 0 */
/* TIM3 clock enable */
__HAL_RCC_TIM3_CLK_ENABLE();
/* USER CODE BEGIN TIM3_MspInit 1 */
/* USER CODE END TIM3_MspInit 1 */
}
else if(tim_baseHandle->Instance==TIM4)
{
/* USER CODE BEGIN TIM4_MspInit 0 */
/* USER CODE END TIM4_MspInit 0 */
/* TIM4 clock enable */
__HAL_RCC_TIM4_CLK_ENABLE();
/* USER CODE BEGIN TIM4_MspInit 1 */
/* USER CODE END TIM4_MspInit 1 */
}
}
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(timHandle->Instance==TIM4)
{
/* USER CODE BEGIN TIM4_MspPostInit 0 */
/* USER CODE END TIM4_MspPostInit 0 */
__HAL_RCC_GPIOB_CLK_ENABLE();
/**TIM4 GPIO Configuration
PB6 ------> TIM4_CH1
PB7 ------> TIM4_CH2
PB8 ------> TIM4_CH3
PB9 ------> TIM4_CH4
*/
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN TIM4_MspPostInit 1 */
/* USER CODE END TIM4_MspPostInit 1 */
}
}
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
{
if(tim_baseHandle->Instance==TIM3)
{
/* USER CODE BEGIN TIM3_MspDeInit 0 */
/* USER CODE END TIM3_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM3_CLK_DISABLE();
/* USER CODE BEGIN TIM3_MspDeInit 1 */
/* USER CODE END TIM3_MspDeInit 1 */
}
else if(tim_baseHandle->Instance==TIM4)
{
/* USER CODE BEGIN TIM4_MspDeInit 0 */
/* USER CODE END TIM4_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM4_CLK_DISABLE();
/* USER CODE BEGIN TIM4_MspDeInit 1 */
/* USER CODE END TIM4_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

View File

@@ -117,6 +117,33 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
/* 引入标准输入输出头文件包含fputc函数原型和FILE类型定义 */ /* 引入标准输入输出头文件包含fputc函数原型和FILE类型定义 */
#include <stdio.h> #include <stdio.h>
/* 禁用半主机模式
* 不勾选MicroLIB时标准库默认使用半主机(Semihosting)实现printf。
* 半主机需要调试器支持,脱机运行时会导致程序卡死。
* __use_no_semihosting 让链接器不链接半主机相关函数,
* 同时我们必须提供_sys_exit等替代函数。
*/
#pragma import(__use_no_semihosting)
/* 标准库要求提供 __FILE 结构体定义和 __stdout 实例 */
struct __FILE {
int handle;
};
FILE __stdout;
/* 退出函数 — 标准库在用完 _sys_exit 后调用,此处空实现 */
void _sys_exit(int return_code)
{
(void)return_code;
while (1);
}
/* 写字符 — 底层 tty 输出钩子,供某些 stdio 函数调用 */
void _ttywrch(int ch)
{
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
}
/** /**
* @brief 重定向fputc函数将printf输出重定向到串口1 * @brief 重定向fputc函数将printf输出重定向到串口1
* @param ch: 要发送的字符 * @param ch: 要发送的字符
@@ -133,7 +160,7 @@ int fputc(int ch, FILE *f)
&huart1: 串口1的句柄若使用其他串口改为对应的句柄如&huart2 &huart1: 串口1的句柄若使用其他串口改为对应的句柄如&huart2
(uint8_t *)&ch: 要发送的数据缓冲区地址 (uint8_t *)&ch: 要发送的数据缓冲区地址
1: 发送数据的长度(单个字符) 1: 发送数据的长度(单个字符)
HAL_MAX_DELAY: 超时时间(无限等待,确保发送成) HAL_MAX_DELAY: 超时时间(无限等待,确保发送成
*/ */
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY); HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY);

View File

@@ -0,0 +1,41 @@
/* 16×16 CJK 字库,由 font_gen.py 生成(自定义) */
#include "hz16_data.h"
static const uint8_t cjk_bitmaps[][32] = {
{ 0x00, 0x00, 0x01, 0x00, 0x03, 0x80, 0x02, 0xC0, 0x06, 0x60, 0x0C, 0x30, 0x18, 0x3E, 0x3F, 0xFE, 0x41, 0x80, 0x01, 0x90, 0x1F, 0xF8, 0x01, 0x80, 0x01, 0x80, 0x01, 0x84, 0x7F, 0xFE, 0x00, 0x00 }, /* U+5168 全 */
{ 0x00, 0x00, 0x3F, 0xFC, 0x30, 0x14, 0x3F, 0xFC, 0x31, 0x84, 0x31, 0x84, 0x27, 0xF4, 0x35, 0xC4, 0x31, 0xE4, 0x31, 0xA4, 0x31, 0xBC, 0x3F, 0xFC, 0x30, 0x0C, 0x3F, 0xFC, 0x20, 0x04, 0x00, 0x00 }, /* U+56FD 国 */
{ 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x86, 0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x03, 0xC0, 0x03, 0x40, 0x02, 0x60, 0x06, 0x30, 0x0C, 0x18, 0x18, 0x0E, 0x70, 0x06, 0x00, 0x00 }, /* U+5927 大 */
{ 0x00, 0x00, 0x1F, 0xFC, 0x00, 0x38, 0x00, 0x60, 0x01, 0xC0, 0x01, 0x80, 0x01, 0x86, 0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x07, 0x80, 0x03, 0x00, 0x00, 0x00 }, /* U+5B50 子 */
{ 0x00, 0x00, 0x1B, 0x18, 0x0D, 0xB0, 0x0D, 0xB0, 0x2D, 0xE6, 0x3F, 0xFE, 0x60, 0x34, 0x6F, 0xF0, 0x00, 0x60, 0x01, 0x84, 0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x07, 0x80, 0x03, 0x80, 0x00, 0x00 }, /* U+5B66 学 */
{ 0x00, 0x00, 0x0C, 0x06, 0x0B, 0xFE, 0x68, 0x20, 0x6B, 0x66, 0x6B, 0xFE, 0x6B, 0x26, 0x6B, 0x26, 0x6B, 0x26, 0x6B, 0x26, 0x7B, 0x26, 0x1B, 0x2E, 0x30, 0x24, 0x20, 0x20, 0x40, 0x60, 0x00, 0x00 }, /* U+5E08 师 */
{ 0x00, 0x00, 0x19, 0x80, 0x19, 0x80, 0x33, 0xFC, 0x32, 0x6C, 0x75, 0x60, 0x53, 0x78, 0x12, 0x6C, 0x15, 0xE4, 0x10, 0xC0, 0x05, 0x80, 0x14, 0x8C, 0x34, 0x16, 0x64, 0x3A, 0x07, 0xF0, 0x00, 0x00 }, /* U+60A8 您 */
{ 0x00, 0x00, 0x00, 0x60, 0x06, 0xC0, 0x7E, 0xC0, 0x06, 0xFE, 0x64, 0xA4, 0x3D, 0x20, 0x19, 0x60, 0x18, 0x70, 0x1C, 0x70, 0x36, 0x50, 0x26, 0xD8, 0x63, 0x8C, 0x43, 0x0E, 0x06, 0x06, 0x00, 0x00 }, /* U+6B22 欢 */
{ 0x00, 0x00, 0x01, 0x80, 0x09, 0x80, 0x19, 0x80, 0x19, 0x8C, 0x1F, 0xFC, 0x31, 0x80, 0x21, 0x80, 0x41, 0x88, 0x1F, 0xF8, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x86, 0x7F, 0xFE, 0x00, 0x00 }, /* U+751F 生 */
{ 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x00, 0x3F, 0xF8, 0x31, 0x08, 0x31, 0x08, 0x3F, 0xF8, 0x31, 0x08, 0x31, 0x08, 0x3F, 0xF8, 0x31, 0x00, 0x01, 0x06, 0x01, 0x06, 0x01, 0xFE, 0x00, 0x00 }, /* U+7535 电 */
{ 0x01, 0x00, 0x01, 0x80, 0x1F, 0xFC, 0x16, 0x30, 0x06, 0x60, 0x7F, 0xFE, 0x00, 0x10, 0x0F, 0xF0, 0x08, 0x30, 0x08, 0x30, 0x0F, 0xF0, 0x0A, 0xC2, 0x06, 0xC2, 0x0C, 0xC6, 0x38, 0x7E, 0x40, 0x00 }, /* U+7ADE 竞 */
{ 0x00, 0x00, 0x06, 0x60, 0x7F, 0xFE, 0x06, 0x60, 0x06, 0x40, 0x19, 0x18, 0x1B, 0xF8, 0x65, 0x18, 0x35, 0x18, 0x29, 0x18, 0x09, 0x38, 0x39, 0x36, 0x11, 0x06, 0x19, 0xFE, 0x18, 0xFC, 0x00, 0x00 }, /* U+8303 范 */
{ 0x00, 0x00, 0x10, 0x60, 0x18, 0x60, 0x08, 0x60, 0x00, 0x60, 0x18, 0x62, 0x7B, 0xFE, 0x10, 0x60, 0x18, 0x60, 0x18, 0x60, 0x12, 0x60, 0x1C, 0x60, 0x1C, 0x60, 0x18, 0x60, 0x00, 0x60, 0x00, 0x00 }, /* U+8BA1 计 */
{ 0x00, 0x00, 0x11, 0xF8, 0x19, 0x98, 0x01, 0x90, 0x01, 0x1E, 0x7B, 0x1E, 0x1E, 0x08, 0x19, 0xFC, 0x18, 0x98, 0x18, 0x98, 0x1E, 0xF0, 0x1C, 0x60, 0x18, 0xF0, 0x03, 0x9E, 0x0E, 0x06, 0x00, 0x00 }, /* U+8BBE 设 */
{ 0x01, 0x00, 0x01, 0x80, 0x3F, 0xFC, 0x36, 0x7C, 0x3F, 0xF8, 0x06, 0x78, 0x0F, 0xF8, 0x7F, 0xFE, 0x0E, 0x70, 0x1F, 0xF8, 0x3D, 0xBE, 0x4D, 0xB0, 0x0D, 0xA0, 0x07, 0x70, 0x1C, 0x38, 0x00, 0x00 }, /* U+8D5B 赛 */
{ 0x00, 0x00, 0x20, 0xC0, 0x33, 0xC0, 0x12, 0x3E, 0x02, 0x26, 0x02, 0x26, 0x72, 0x26, 0x12, 0x26, 0x12, 0xE6, 0x13, 0xAE, 0x13, 0x2C, 0x10, 0x20, 0x7C, 0x20, 0x47, 0xFE, 0x01, 0xFE, 0x00, 0x00 }, /* U+8FCE 迎 */
{ 0x01, 0x00, 0x01, 0x00, 0x1F, 0xF8, 0x18, 0x18, 0x1F, 0xF8, 0x18, 0x10, 0x1F, 0xF8, 0x18, 0x18, 0x18, 0x18, 0x1F, 0xF8, 0x01, 0x82, 0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00 }, /* U+961C 阜 */
{ 0x00, 0x00, 0x7E, 0x84, 0x65, 0xFC, 0x6D, 0x84, 0x69, 0x84, 0x69, 0x84, 0x6D, 0x8C, 0x67, 0xFC, 0x67, 0x84, 0x67, 0x84, 0x7D, 0x84, 0x61, 0x84, 0x61, 0xFC, 0x61, 0x84, 0x60, 0x00, 0x00, 0x00 }, /* U+9633 阳 */
};
static const uint16_t cjk_unicodes[18] = {
0x5168, 0x56FD, 0x5927, 0x5B50, 0x5B66, 0x5E08, 0x60A8, 0x6B22, 0x751F, 0x7535, 0x7ADE, 0x8303, 0x8BA1, 0x8BBE, 0x8D5B, 0x8FCE,
0x961C, 0x9633,
};
const uint8_t* cjk_get_bitmap(uint16_t unicode)
{
int lo = 0, hi = 18;
while (lo < hi) {
int mid = (lo + hi) >> 1;
if (cjk_unicodes[mid] < unicode) lo = mid + 1;
else if (cjk_unicodes[mid] > unicode) hi = mid;
else return cjk_bitmaps[mid];
}
return (const uint8_t*)0;
}

View File

@@ -0,0 +1,15 @@
/* 16×16 CJK 字库,由 font_gen.py 生成(自定义) */
#ifndef HZ16_DATA_H
#define HZ16_DATA_H
#include <stdint.h>
#define CJK_BYTES_PER_CHAR 32
#define CJK_WIDTH 16
#define CJK_HEIGHT 16
#define CJK_NUM_CHARS 18
const uint8_t* cjk_get_bitmap(uint16_t unicode);
#endif /* HZ16_DATA_H */

View File

@@ -0,0 +1,328 @@
/*
* 模块名称LCD 绘图模块
* 模块功能:提供字符、字符串(中英文混合)、线条、矩形、圆形等图形绘制
* 适用平台STM32F103C8T6 + ST7735S + 底层 st7735s.c
* 作者:王建锋
* 创建日期2026-07-14
* 修改记录:
* 2026-07-14 王建锋 从 st7735s.c 拆分
*/
#include "lcd.h"
#include "lcd_data.h"
#include "hz16_data.h"
#include <string.h>
/*
* 函数功能UTF-8字符转Unicode辅助
* 入口参数str - UTF-8字符串指针会被推进到下一字符起始
* 返回值Unicode码点或0异常/结束)
* 函数说明支持1~3字节UTF-8推进str
*/
static uint16_t utf8_to_unicode(const char **str)
{
uint16_t code;
uint8_t c;
c = (uint8_t)(**str);
if (c == 0) {
return 0;
}
if (c < 0x80) {
code = c;
(*str)++;
} else if ((c & 0xE0) == 0xC0) {
code = c & 0x1F;
(*str)++;
code = (code << 6) | ((uint8_t)(**str) & 0x3F);
(*str)++;
} else if ((c & 0xF0) == 0xE0) {
code = c & 0x0F;
(*str)++;
code = (code << 6) | ((uint8_t)(**str) & 0x3F);
(*str)++;
code = (code << 6) | ((uint8_t)(**str) & 0x3F);
(*str)++;
} else {
(*str)++;
return 0;
}
return code;
}
/*
* 函数功能显示一个8x16 ASCII字符
* 入口参数x - 列坐标
* y - 行坐标
* ch - 字符 (ASCII 32-126)
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
* 函数说明框选8x16区域→遍历字模bit→发送color或bg_color
*/
void lcd_draw_char(uint16_t x, uint16_t y, char ch, uint16_t color, uint16_t bg_color)
{
uint16_t i;
uint16_t j;
uint8_t line;
if (ch < 32 || ch > 126) {
ch = ' ';
}
st7735s_set_window(x, y, x + 7, y + 15);
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET);
for (i = 0; i < 16; i++) {
line = LCD_F8x16[ch - 32][i];
for (j = 0; j < 8; j++) {
if (line & 0x80) {
st7735s_spi_write_byte((uint8_t)(color >> 8));
st7735s_spi_write_byte((uint8_t)(color & 0xFF));
} else {
st7735s_spi_write_byte((uint8_t)(bg_color >> 8));
st7735s_spi_write_byte((uint8_t)(bg_color & 0xFF));
}
line <<= 1;
}
}
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
}
/*
* 函数功能:显示字符串
* 入口参数x - 列坐标
* y - 行坐标
* str - 字符串指针
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
* 函数说明:连续显示字符串,自动换行
*/
void lcd_draw_string(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bg_color)
{
uint16_t start_x = x;
while (*str != '\0') {
if (*str == '\n') {
y += FONT_HEIGHT_16;
x = start_x;
str++;
continue;
}
if (x + 8 > s_lcd_width) {
y += FONT_HEIGHT_16;
x = start_x;
}
if (y + 16 > s_lcd_height) {
break;
}
lcd_draw_char(x, y, *str, color, bg_color);
x += FONT_WIDTH_8;
str++;
}
}
/*
* 函数功能显示一个16x16 CJK汉字
* 入口参数x - 列坐标
* y - 行坐标
* unicode - Unicode码点 (如 0x4E00="一")
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
* 函数说明框选16x16区域→遍历字模bit→发送color或bg_color
*/
void lcd_draw_chinese(uint16_t x, uint16_t y, uint16_t unicode,
uint16_t color, uint16_t bg_color)
{
uint16_t i;
uint16_t j;
uint8_t k;
uint8_t line;
const uint8_t *bitmap;
bitmap = cjk_get_bitmap(unicode);
if (bitmap == NULL) {
return;
}
st7735s_set_window(x, y, x + CJK_WIDTH - 1, y + CJK_HEIGHT - 1);
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET);
for (i = 0; i < CJK_HEIGHT; i++) {
for (j = 0; j < CJK_WIDTH / 8; j++) {
line = bitmap[i * (CJK_WIDTH / 8) + j];
for (k = 0; k < 8; k++) {
if (line & 0x80) {
st7735s_spi_write_byte((uint8_t)(color >> 8));
st7735s_spi_write_byte((uint8_t)(color & 0xFF));
} else {
st7735s_spi_write_byte((uint8_t)(bg_color >> 8));
st7735s_spi_write_byte((uint8_t)(bg_color & 0xFF));
}
line <<= 1;
}
}
}
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
}
/*
* 函数功能显示UTF-8字符串自动中英文混合
* 入口参数x - 列坐标
* y - 行坐标
* str - UTF-8字符串指针
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
* 函数说明自动识别ASCII(8x16)和CJK(16x16),自动换行
*/
void lcd_draw_chinese_string(uint16_t x, uint16_t y,
const char *str,
uint16_t color, uint16_t bg_color)
{
uint16_t start_x = x;
while (*str != '\0') {
uint8_t c = (uint8_t)(*str);
if (*str == '\n') {
y += CJK_HEIGHT;
x = start_x;
str++;
continue;
}
if (c < 0x80) {
if (x + 8 > s_lcd_width) {
y += CJK_HEIGHT;
x = start_x;
}
if (y + 16 > s_lcd_height) {
break;
}
lcd_draw_char(x, y, (char)c, color, bg_color);
x += 8;
str++;
} else {
const char *p = str;
uint16_t unicode = utf8_to_unicode(&p);
if (unicode == 0) {
str = p;
continue;
}
if (x + CJK_WIDTH > s_lcd_width) {
y += CJK_HEIGHT;
x = start_x;
}
if (y + CJK_HEIGHT > s_lcd_height) {
break;
}
lcd_draw_chinese(x, y, unicode, color, bg_color);
x += CJK_WIDTH;
str = p;
}
}
}
/*
* 函数功能画线Bresenham算法
* 入口参数x1 - 起始列
* y1 - 起始行
* x2 - 结束列
* y2 - 结束行
* color - 颜色 (RGB565)
* 返回值:无
*/
void lcd_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
{
int16_t dx;
int16_t dy;
int16_t sx;
int16_t sy;
int16_t err;
int16_t e2;
int16_t x = (int16_t)x1;
int16_t y = (int16_t)y1;
dx = (x1 < x2) ? (int16_t)(x2 - x1) : (int16_t)(x1 - x2);
dy = (y1 < y2) ? (int16_t)(y2 - y1) : (int16_t)(y1 - y2);
sx = (x1 < x2) ? 1 : -1;
sy = (y1 < y2) ? 1 : -1;
err = dx - dy;
while (1) {
st7735s_draw_pixel((uint16_t)x, (uint16_t)y, color);
if (x == (int16_t)x2 && y == (int16_t)y2) {
break;
}
e2 = 2 * err;
if (e2 > -dy) {
err -= dy;
x += sx;
}
if (e2 < dx) {
err += dx;
y += sy;
}
}
}
/*
* 函数功能:画空心矩形
* 入口参数x - 左上角列
* y - 左上角行
* width - 宽度
* height - 高度
* color - 颜色 (RGB565)
* 返回值:无
*/
void lcd_draw_rect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color)
{
uint16_t x2 = x + width - 1;
uint16_t y2 = y + height - 1;
lcd_draw_line(x, y, x2, y, color);
lcd_draw_line(x, y, x, y2, color);
lcd_draw_line(x2, y, x2, y2, color);
lcd_draw_line(x, y2, x2, y2, color);
}
/*
* 函数功能画空心圆Bresenham算法
* 入口参数x0 - 圆心列
* y0 - 圆心行
* radius - 半径
* color - 颜色 (RGB565)
* 返回值:无
*/
void lcd_draw_circle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color)
{
int16_t x = 0;
int16_t y = (int16_t)radius;
int16_t err = 1 - (int16_t)radius;
int16_t xc = (int16_t)x0;
int16_t yc = (int16_t)y0;
while (x <= y) {
st7735s_draw_pixel((uint16_t)(xc + x), (uint16_t)(yc + y), color);
st7735s_draw_pixel((uint16_t)(xc - x), (uint16_t)(yc + y), color);
st7735s_draw_pixel((uint16_t)(xc + x), (uint16_t)(yc - y), color);
st7735s_draw_pixel((uint16_t)(xc - x), (uint16_t)(yc - y), color);
st7735s_draw_pixel((uint16_t)(xc + y), (uint16_t)(yc + x), color);
st7735s_draw_pixel((uint16_t)(xc - y), (uint16_t)(yc + x), color);
st7735s_draw_pixel((uint16_t)(xc + y), (uint16_t)(yc - x), color);
st7735s_draw_pixel((uint16_t)(xc - y), (uint16_t)(yc - x), color);
x++;
if (err < 0) {
err += 2 * x + 1;
} else {
y--;
err += 2 * (x - y) + 1;
}
}
}

View File

@@ -0,0 +1,109 @@
/*
* 模块名称LCD 绘图模块
* 模块功能:提供字符、字符串(中英文混合)、线条、矩形、圆形等图形绘制
* 适用平台STM32F103C8T6 + ST7735S + 底层 st7735s.c
* 作者:王建锋
* 创建日期2026-07-14
* 修改记录:
* 2026-07-14 王建锋 从 st7735s.c 拆分
*/
#ifndef __LCD_H
#define __LCD_H
#ifdef __cplusplus
extern "C" {
#endif
#include "st7735s.h"
#include <stdint.h>
/* 字体定义 */
#define FONT_WIDTH_8 8 /* 8x16字体宽度含间距 */
#define FONT_HEIGHT_16 16 /* 8x16字体高度 */
/* === 字符/字符串绘制 === */
/*
* 函数功能显示一个8x16 ASCII字符
* 入口参数x - 列坐标
* y - 行坐标
* ch - 字符 (ASCII 32-126)
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
*/
void lcd_draw_char(uint16_t x, uint16_t y, char ch, uint16_t color, uint16_t bg_color);
/*
* 函数功能显示字符串ASCII
* 入口参数x - 列坐标
* y - 行坐标
* str - 字符串指针
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
*/
void lcd_draw_string(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bg_color);
/*
* 函数功能显示一个16x16 CJK汉字
* 入口参数x - 列坐标
* y - 行坐标
* unicode - Unicode码点 (如 0x4E00="一")
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
*/
void lcd_draw_chinese(uint16_t x, uint16_t y, uint16_t unicode, uint16_t color, uint16_t bg_color);
/*
* 函数功能显示UTF-8字符串自动中英文混合
* 入口参数x - 列坐标
* y - 行坐标
* str - UTF-8字符串指针
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
*/
void lcd_draw_chinese_string(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bg_color);
/* === 图形绘制 === */
/*
* 函数功能画线Bresenham算法
* 入口参数x1 - 起始列
* y1 - 起始行
* x2 - 结束列
* y2 - 结束行
* color - 颜色 (RGB565)
* 返回值:无
*/
void lcd_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
/*
* 函数功能:画空心矩形
* 入口参数x - 左上角列
* y - 左上角行
* width - 宽度
* height - 高度
* color - 颜色 (RGB565)
* 返回值:无
*/
void lcd_draw_rect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
/*
* 函数功能画空心圆Bresenham算法
* 入口参数x0 - 圆心列
* y0 - 圆心行
* radius - 半径
* color - 颜色 (RGB565)
* 返回值:无
*/
void lcd_draw_circle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color);
#ifdef __cplusplus
}
#endif
#endif /* __LCD_H */

View File

@@ -2,296 +2,297 @@
/*ASCII字模数据*********************/ /*ASCII字模数据*********************/
/*宽8像素高16像素*/ /*宽8像素高16像素*/
/* 字体: simsun.ttc, 字号: 64, 阈值: 50 */
const uint8_t LCD_F8x16[][16] = const uint8_t LCD_F8x16[][16] =
{ {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,// ! 1 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, // ! 1
0x00,0x16,0x0E,0x00,0x16,0x0E,0x00,0x00, 0x00, 0x16, 0x36, 0x3C, 0x68, 0x40, 0x00, 0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// " 2 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // " 2
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00, 0x00, 0x00, 0x20, 0x26, 0x26, 0xFF, 0x7E, 0x24,
0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,// # 3 0x64, 0xFF, 0xFE, 0x64, 0x64, 0x00, 0x00, 0x00, // # 3
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00, 0x00, 0x18, 0x3C, 0x7E, 0x7E, 0x78, 0x38, 0x18,
0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,// $ 4 0x1C, 0x1E, 0x7E, 0x56, 0x7C, 0x18, 0x18, 0x00, // $ 4
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00, 0x00, 0x00, 0x60, 0xF4, 0x94, 0x9C, 0x98, 0xFC,
0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,// % 5 0x1E, 0x1B, 0x3B, 0x2B, 0x6E, 0x04, 0x00, 0x00, // % 5
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00, 0x00, 0x00, 0x30, 0x78, 0x68, 0x78, 0x78, 0x76,
0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,// & 6 0xF4, 0xD4, 0xDC, 0xCC, 0x7F, 0x22, 0x00, 0x00, // & 6
0x00,0x00,0x00,0x16,0x0E,0x00,0x00,0x00, 0x00, 0x60, 0x70, 0x30, 0x60, 0x40, 0x00, 0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ' 7 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ' 7
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00, 0x00, 0x02, 0x06, 0x0C, 0x0C, 0x18, 0x18, 0x18,
0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,// ( 8 0x18, 0x18, 0x18, 0x0C, 0x0C, 0x06, 0x02, 0x00, // ( 8
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00, 0x00, 0x40, 0x60, 0x30, 0x30, 0x10, 0x18, 0x18,
0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,// ) 9 0x18, 0x18, 0x18, 0x30, 0x30, 0x60, 0x40, 0x00, // ) 9
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0xFF, 0x7E, 0x3C,
0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,// * 10 0xFF, 0xDB, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, // * 10
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0xFF, 0x18,
0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,// + 11 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // + 11
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x70,
0x00,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,// , 12 0x20, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // , 12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x00, 0x00,
0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,// - 13 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // - 13
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,// . 14 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // . 14
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04, 0x00, 0x02, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x18,
0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,// / 15 0x10, 0x30, 0x20, 0x60, 0x40, 0xC0, 0x80, 0x00, // / 15
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x42, 0xC3, 0xC3,
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,// 0 16 0xC3, 0xC3, 0x42, 0x66, 0x3C, 0x18, 0x00, 0x00, // 0 16
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x18, 0x38, 0x18, 0x18, 0x18, 0x18,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// 1 17 0x18, 0x18, 0x18, 0x18, 0x3C, 0x3C, 0x00, 0x00, // 1 17
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00, 0x00, 0x00, 0x3C, 0x66, 0x62, 0x62, 0x06, 0x04,
0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,// 2 18 0x08, 0x10, 0x20, 0x42, 0xFE, 0x7C, 0x00, 0x00, // 2 18
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00, 0x00, 0x00, 0x3C, 0x64, 0x66, 0x06, 0x0C, 0x1C,
0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,// 3 19 0x06, 0x02, 0x62, 0x66, 0x7C, 0x18, 0x00, 0x00, // 3 19
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00, 0x00, 0x00, 0x04, 0x0C, 0x1C, 0x1C, 0x2C, 0x6C,
0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,// 4 20 0x4C, 0xFE, 0x0C, 0x0C, 0x0E, 0x1E, 0x00, 0x00, // 4 20
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00, 0x00, 0x00, 0x3E, 0x7E, 0x60, 0x40, 0x7C, 0x66,
0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,// 5 21 0x06, 0x02, 0x62, 0x66, 0x7C, 0x18, 0x00, 0x00, // 5 21
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00, 0x00, 0x00, 0x1C, 0x26, 0x62, 0x40, 0xDC, 0xF6,
0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,// 6 22 0xC2, 0xC3, 0x43, 0x62, 0x3E, 0x18, 0x00, 0x00, // 6 22
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00, 0x00, 0x00, 0x7E, 0x7E, 0x44, 0x04, 0x0C, 0x08,
0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,// 7 23 0x18, 0x18, 0x18, 0x38, 0x38, 0x10, 0x00, 0x00, // 7 23
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00, 0x00, 0x00, 0x3C, 0x66, 0x42, 0x62, 0x76, 0x3C,
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,// 8 24 0x6E, 0x46, 0xC2, 0x46, 0x7C, 0x18, 0x00, 0x00, // 8 24
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00, 0x00, 0x00, 0x3C, 0x66, 0x46, 0xC2, 0xC2, 0x66,
0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,// 9 25 0x7E, 0x16, 0x06, 0x64, 0x7C, 0x10, 0x00, 0x00, // 9 25
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,// : 26 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, // : 26
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,// ; 27 0x00, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, 0x00, // ; 27
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00, 0x00, 0x00, 0x02, 0x06, 0x0C, 0x18, 0x30, 0x60,
0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,// < 28 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00, 0x00, 0x00, // < 28
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,// = 29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // = 29
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00, 0x00, 0x00, 0x40, 0x60, 0x30, 0x18, 0x0C, 0x06,
0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,// > 30 0x06, 0x0C, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, // > 30
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00, 0x00, 0x00, 0x3C, 0x66, 0xC3, 0xC3, 0x46, 0x0C,
0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,// ? 31 0x18, 0x10, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, // ? 31
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00, 0x00, 0x00, 0x1C, 0x36, 0x6F, 0x5F, 0xD7, 0xF5,
0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,// @ 32 0xF5, 0xFE, 0x7E, 0x63, 0x3E, 0x18, 0x00, 0x00, // @ 32
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x3C, 0x2C, 0x2C,
0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,// A 33 0x3C, 0x7E, 0x46, 0x46, 0xC7, 0xC7, 0x00, 0x00, // A 33
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00, 0x00, 0x00, 0xFC, 0x66, 0x62, 0x62, 0x66, 0x7C,
0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,// B 34 0x66, 0x63, 0x63, 0x63, 0x7E, 0xF8, 0x00, 0x00, // B 34
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00, 0x00, 0x00, 0x1E, 0x63, 0x41, 0xC0, 0xC0, 0xC0,
0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,// C 35 0xC0, 0xC0, 0xC1, 0x62, 0x3E, 0x18, 0x00, 0x00, // C 35
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00, 0x00, 0x00, 0xF8, 0x6C, 0x66, 0x63, 0x63, 0x63,
0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,// D 36 0x63, 0x63, 0x62, 0x66, 0x7C, 0xF0, 0x00, 0x00, // D 36
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00, 0x00, 0x00, 0x7E, 0x66, 0x62, 0x60, 0x64, 0x7C,
0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,// E 37 0x64, 0x60, 0x60, 0x63, 0x7E, 0x7E, 0x00, 0x00, // E 37
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00, 0x00, 0x00, 0x7E, 0x63, 0x61, 0x60, 0x64, 0x7C,
0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,// F 38 0x64, 0x64, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, // F 38
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00, 0x00, 0x00, 0x3C, 0x66, 0x42, 0xC0, 0xC0, 0xC0,
0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,// G 39 0xC7, 0xC6, 0x46, 0x66, 0x3E, 0x18, 0x00, 0x00, // G 39
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08, 0x00, 0x00, 0xE7, 0x66, 0x66, 0x66, 0x66, 0x7E,
0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,// H 40 0x66, 0x66, 0x66, 0x66, 0x66, 0xE7, 0x00, 0x00, // H 40
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00, 0x00, 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// I 41 0x18, 0x18, 0x18, 0x18, 0x3C, 0x3C, 0x00, 0x00, // I 41
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00, 0x00, 0x3F, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C,
0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,// J 42 0x0C, 0x0C, 0x0C, 0x0C, 0xCC, 0xF8, 0x20, 0x00, // J 42
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00, 0x00, 0x00, 0xE6, 0x66, 0x6C, 0x68, 0x70, 0x78,
0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,// K 43 0x68, 0x6C, 0x6C, 0x66, 0x67, 0x67, 0x00, 0x00, // K 43
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,// L 44 0x60, 0x60, 0x60, 0x63, 0x7E, 0x7E, 0x00, 0x00, // L 44
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00, 0x00, 0x00, 0xC3, 0x66, 0x66, 0x66, 0x66, 0x6E,
0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,// M 45 0x7E, 0x7A, 0x5A, 0x5A, 0xD7, 0xC7, 0x00, 0x00, // M 45
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08, 0x00, 0x00, 0xC7, 0x62, 0x72, 0x72, 0x52, 0x5A,
0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,// N 46 0x4A, 0x4E, 0x46, 0x46, 0xE2, 0xE0, 0x00, 0x00, // N 46
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00, 0x00, 0x00, 0x3C, 0x66, 0x42, 0xC3, 0xC3, 0xC3,
0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,// O 47 0xC3, 0xC3, 0x43, 0x66, 0x3C, 0x18, 0x00, 0x00, // O 47
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00, 0x00, 0x00, 0x7C, 0x66, 0x63, 0x63, 0x62, 0x7E,
0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,// P 48 0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, // P 48
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00, 0x00, 0x18, 0x3C, 0x66, 0xC3, 0xC3, 0xC3, 0xC3,
0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,// Q 49 0xC3, 0xFB, 0x7A, 0x6E, 0x3C, 0x06, 0x00, 0x00, // Q 49
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00, 0x00, 0x00, 0x7C, 0x66, 0x62, 0x62, 0x66, 0x7C,
0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,// R 50 0x68, 0x6C, 0x64, 0x66, 0x67, 0x63, 0x00, 0x00, // R 50
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00, 0x00, 0x00, 0x3C, 0x66, 0x42, 0x60, 0x70, 0x3C,
0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,// S 51 0x0E, 0x06, 0xC2, 0x46, 0x7E, 0x18, 0x00, 0x00, // S 51
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00, 0x00, 0x00, 0x7E, 0xDB, 0x99, 0x18, 0x18, 0x18,
0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,// T 52 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, // T 52
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08, 0x00, 0x00, 0xE7, 0x62, 0x62, 0x62, 0x62, 0x62,
0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,// U 53 0x62, 0x62, 0x62, 0x62, 0x3C, 0x18, 0x00, 0x00, // U 53
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08, 0x00, 0x00, 0xE7, 0x66, 0x66, 0x64, 0x24, 0x24,
0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,// V 54 0x3C, 0x38, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, // V 54
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00, 0x00, 0x00, 0xDB, 0xDB, 0x5A, 0x5A, 0x5A, 0x7E,
0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,// W 55 0x7C, 0x7C, 0x2C, 0x2C, 0x24, 0x00, 0x00, 0x00, // W 55
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08, 0x00, 0x00, 0x66, 0x66, 0x24, 0x3C, 0x18, 0x18,
0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,// X 56 0x18, 0x3C, 0x2C, 0x24, 0x66, 0x66, 0x00, 0x00, // X 56
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00, 0x00, 0x00, 0xE7, 0x62, 0x66, 0x34, 0x34, 0x18,
0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,// Y 57 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, // Y 57
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00, 0x00, 0x00, 0x7E, 0x66, 0x46, 0x0C, 0x08, 0x18,
0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,// Z 58 0x10, 0x30, 0x20, 0x62, 0xFE, 0x7C, 0x00, 0x00, // Z 58
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00, 0x00, 0x1E, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,// [ 59 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1E, 0x00, // [ 59
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00, 0x00, 0x40, 0x60, 0x20, 0x30, 0x30, 0x10, 0x18,
0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,// \ 60 0x08, 0x0C, 0x0C, 0x04, 0x06, 0x02, 0x02, 0x00, // \ 60
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00, 0x00, 0x78, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,// ] 61 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x78, 0x00, // ] 61
0x00,0x20,0x10,0x08,0x04,0x08,0x10,0x20, 0x00, 0x18, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ^ 62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ^ 62
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,// _ 63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, // _ 63
0x00,0x02,0x04,0x08,0x00,0x00,0x00,0x00, 0x00, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ` 64 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ` 64
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x46, 0x3E,
0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,// a 65 0x66, 0xC6, 0x6F, 0x36, 0x00, 0x00, 0x00, 0x00, // a 65
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00, 0x00, 0x00, 0xC0, 0x60, 0x60, 0x60, 0x7C, 0x76,
0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,// b 66 0x66, 0x62, 0x62, 0x66, 0x66, 0x5C, 0x00, 0x00, // b 66
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x40,
0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,// c 67 0x40, 0x62, 0x76, 0x1C, 0x00, 0x00, 0x00, 0x00, // c 67
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x76,
0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,// d 68 0x66, 0x46, 0x46, 0x66, 0x6E, 0x3E, 0x00, 0x00, // d 68
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x42, 0x7E,
0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,// e 69 0x40, 0x62, 0x76, 0x1C, 0x00, 0x00, 0x00, 0x00, // e 69
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18, 0x00, 0x00, 0x0E, 0x1B, 0x31, 0x30, 0x7C, 0x30,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// f 70 0x30, 0x30, 0x30, 0x30, 0x38, 0x7C, 0x00, 0x00, // f 70
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00, 0x00, 0x00, 0x00, 0x1B, 0x2F, 0x66, 0x66, 0x3C,
0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,// g 71 0x78, 0x7E, 0x46, 0x66, 0x3C, 0x00, 0x00, 0x00, // g 71
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x7C, 0x66,
0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,// h 72 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, // h 72
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x38, 0x18,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// i 73 0x18, 0x18, 0x18, 0x18, 0x3C, 0x3C, 0x00, 0x00, // i 73
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00, 0x00, 0x04, 0x06, 0x00, 0x00, 0x1E, 0x06, 0x06,
0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,// j 74 0x06, 0x06, 0x06, 0x06, 0x04, 0x6C, 0x38, 0x00, // j 74
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x66, 0x6C,
0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,// k 75 0x68, 0x78, 0x6C, 0x6C, 0x66, 0x67, 0x00, 0x00, // k 75
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x38, 0x38, 0x18, 0x18, 0x18, 0x18,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// l 76 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 0x00, // l 76
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xDB, 0xDB, 0xDB,
0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,// m 77 0xDB, 0xDB, 0xDB, 0xDB, 0x00, 0x00, 0x00, 0x00, // m 77
0x00,0x80,0x80,0x00,0x80,0x80,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x76, 0x66, 0x66,
0x00,0x20,0x3F,0x21,0x00,0x20,0x3F,0x20,// n 78 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, // n 78
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x42, 0xC3,
0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,// o 79 0xC3, 0x42, 0x66, 0x38, 0x00, 0x00, 0x00, 0x00, // o 79
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x7C, 0x76, 0x62, 0x63, 0x63,
0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,// p 80 0x62, 0x66, 0x7C, 0x60, 0x70, 0x00, 0x00, 0x00, // p 80
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00, 0x00, 0x00, 0x00, 0x3E, 0x66, 0x46, 0xC6, 0xC6,
0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,// q 81 0x46, 0x7E, 0x16, 0x06, 0x0E, 0x00, 0x00, 0x00, // q 81
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x3B, 0x30, 0x30,
0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,// r 82 0x30, 0x30, 0x30, 0xF8, 0x00, 0x00, 0x00, 0x00, // r 82
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x60, 0x38,
0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,// s 83 0x0E, 0x46, 0x66, 0x7C, 0x00, 0x00, 0x00, 0x00, // s 83
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10,
0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,// t 84 0x10, 0x10, 0x10, 0x1E, 0x0C, 0x00, 0x00, 0x00, // t 84
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0x66, 0x66, 0x66,
0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,// u 85 0x66, 0x66, 0x6E, 0x3E, 0x00, 0x00, 0x00, 0x00, // u 85
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80, 0x00, 0x00, 0x00, 0x00, 0xE6, 0x66, 0x24, 0x34,
0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,// v 86 0x38, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, // v 86
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80, 0x00, 0x00, 0x00, 0x00, 0xDB, 0xDA, 0x5A, 0x7E,
0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,// w 87 0x7C, 0x2C, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, // w 87
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x34, 0x38, 0x18,
0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,// x 88 0x18, 0x2C, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, // x 88
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80, 0x00, 0x00, 0x00, 0x67, 0x66, 0x34, 0x34, 0x1C,
0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,// y 89 0x18, 0x18, 0x18, 0x70, 0x60, 0x00, 0x00, 0x00, // y 89
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x4C, 0x08, 0x18,
0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,// z 90 0x30, 0x22, 0x7E, 0x7C, 0x00, 0x00, 0x00, 0x00, // z 90
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02, 0x00, 0x06, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x18,
0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,// { 91 0x18, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x06, 0x00, // { 91
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,// | 92 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, // | 92
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00, 0x00, 0x60, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18,
0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,// } 93 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x60, 0x00, // } 93
0x00,0x80,0x40,0x40,0x80,0x00,0x00,0x80, 0x00, 0x70, 0x59, 0x0E, 0x04, 0x00, 0x00, 0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,// ~ 94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // ~ 94
}; };
/*宽6像素高8像素*/ /*宽6像素高8像素(未使用)*/
const uint8_t LCD_F6x8[][6] = const uint8_t LCD_F6x8[][6] =
{ {
0x00,0x00,0x00,0x00,0x00,0x00,// 0 0x00,0x00,0x00,0x00,0x00,0x00, // 0
0x00,0x00,0x00,0x2F,0x00,0x00,// ! 1 0x00,0x00,0x00,0x00,0x00,0x00, // ! 1
0x00,0x00,0x07,0x00,0x07,0x00,// " 2 0x00,0x00,0x00,0x00,0x00,0x00, // " 2
0x00,0x14,0x7F,0x14,0x7F,0x14,// # 3 0x00,0x00,0x00,0x00,0x00,0x00, // # 3
0x00,0x24,0x2A,0x7F,0x2A,0x12,// $ 4 0x00,0x00,0x00,0x00,0x00,0x00, // $ 4
0x00,0x23,0x13,0x08,0x64,0x62,// % 5 0x00,0x00,0x00,0x00,0x00,0x00, // % 5
0x00,0x36,0x49,0x55,0x22,0x50,// & 6 0x00,0x00,0x00,0x00,0x00,0x00, // & 6
0x00,0x00,0x00,0x07,0x00,0x00,// ' 7 0x00,0x00,0x00,0x00,0x00,0x00, // ' 7
0x00,0x00,0x1C,0x22,0x41,0x00,// ( 8 0x00,0x00,0x00,0x00,0x00,0x00, // ( 8
0x00,0x00,0x41,0x22,0x1C,0x00,// ) 9 0x00,0x00,0x00,0x00,0x00,0x00, // ) 9
0x00,0x14,0x08,0x3E,0x08,0x14,// * 10 0x00,0x00,0x00,0x00,0x00,0x00, // * 10
0x00,0x08,0x08,0x3E,0x08,0x08,// + 11 0x00,0x00,0x00,0x00,0x00,0x00, // + 11
0x00,0x00,0x00,0xA0,0x60,0x00,// , 12 0x00,0x00,0x00,0x00,0x00,0x00, // , 12
0x00,0x08,0x08,0x08,0x08,0x08,// - 13 0x00,0x00,0x00,0x00,0x00,0x00, // - 13
0x00,0x00,0x60,0x60,0x00,0x00,// . 14 0x00,0x00,0x00,0x00,0x00,0x00, // . 14
0x00,0x20,0x10,0x08,0x04,0x02,// / 15 0x00,0x00,0x00,0x00,0x00,0x00, // / 15
0x00,0x3E,0x51,0x49,0x45,0x3E,// 0 16 0x00,0x00,0x00,0x00,0x00,0x00, // 0 16
0x00,0x00,0x42,0x7F,0x40,0x00,// 1 17 0x00,0x00,0x00,0x00,0x00,0x00, // 1 17
0x00,0x42,0x61,0x51,0x49,0x46,// 2 18 0x00,0x00,0x00,0x00,0x00,0x00, // 2 18
0x00,0x21,0x41,0x45,0x4B,0x31,// 3 19 0x00,0x00,0x00,0x00,0x00,0x00, // 3 19
0x00,0x18,0x14,0x12,0x7F,0x10,// 4 20 0x00,0x00,0x00,0x00,0x00,0x00, // 4 20
0x00,0x27,0x45,0x45,0x45,0x39,// 5 21 0x00,0x00,0x00,0x00,0x00,0x00, // 5 21
0x00,0x3C,0x4A,0x49,0x49,0x30,// 6 22 0x00,0x00,0x00,0x00,0x00,0x00, // 6 22
0x00,0x01,0x71,0x09,0x05,0x03,// 7 23 0x00,0x00,0x00,0x00,0x00,0x00, // 7 23
0x00,0x36,0x49,0x49,0x49,0x36,// 8 24 0x00,0x00,0x00,0x00,0x00,0x00, // 8 24
0x00,0x06,0x49,0x49,0x29,0x1E,// 9 25 0x00,0x00,0x00,0x00,0x00,0x00, // 9 25
0x00,0x00,0x36,0x36,0x00,0x00,// : 26 0x00,0x00,0x00,0x00,0x00,0x00, // : 26
0x00,0x00,0x56,0x36,0x00,0x00,// ; 27 0x00,0x00,0x00,0x00,0x00,0x00, // ; 27
0x00,0x08,0x14,0x22,0x41,0x00,// < 28 0x00,0x00,0x00,0x00,0x00,0x00, // < 28
0x00,0x14,0x14,0x14,0x14,0x14,// = 29 0x00,0x00,0x00,0x00,0x00,0x00, // = 29
0x00,0x00,0x41,0x22,0x14,0x08,// > 30 0x00,0x00,0x00,0x00,0x00,0x00, // > 30
0x00,0x02,0x01,0x51,0x09,0x06,// ? 31 0x00,0x00,0x00,0x00,0x00,0x00, // ? 31
0x00,0x3E,0x49,0x55,0x59,0x2E,// @ 32 0x00,0x00,0x00,0x00,0x00,0x00, // @ 32
0x00,0x7C,0x12,0x11,0x12,0x7C,// A 33 0x00,0x00,0x00,0x00,0x00,0x00, // A 33
0x00,0x7F,0x49,0x49,0x49,0x36,// B 34 0x00,0x00,0x00,0x00,0x00,0x00, // B 34
0x00,0x3E,0x41,0x41,0x41,0x22,// C 35 0x00,0x00,0x00,0x00,0x00,0x00, // C 35
0x00,0x7F,0x41,0x41,0x22,0x1C,// D 36 0x00,0x00,0x00,0x00,0x00,0x00, // D 36
0x00,0x7F,0x49,0x49,0x49,0x41,// E 37 0x00,0x00,0x00,0x00,0x00,0x00, // E 37
0x00,0x7F,0x09,0x09,0x09,0x01,// F 38 0x00,0x00,0x00,0x00,0x00,0x00, // F 38
0x00,0x3E,0x41,0x49,0x49,0x7A,// G 39 0x00,0x00,0x00,0x00,0x00,0x00, // G 39
0x00,0x7F,0x08,0x08,0x08,0x7F,// H 40 0x00,0x00,0x00,0x00,0x00,0x00, // H 40
0x00,0x00,0x41,0x7F,0x41,0x00,// I 41 0x00,0x00,0x00,0x00,0x00,0x00, // I 41
0x00,0x20,0x40,0x41,0x3F,0x01,// J 42 0x00,0x00,0x00,0x00,0x00,0x00, // J 42
0x00,0x7F,0x08,0x14,0x22,0x41,// K 43 0x00,0x00,0x00,0x00,0x00,0x00, // K 43
0x00,0x7F,0x40,0x40,0x40,0x40,// L 44 0x00,0x00,0x00,0x00,0x00,0x00, // L 44
0x00,0x7F,0x02,0x0C,0x02,0x7F,// M 45 0x00,0x00,0x00,0x00,0x00,0x00, // M 45
0x00,0x7F,0x04,0x08,0x10,0x7F,// N 46 0x00,0x00,0x00,0x00,0x00,0x00, // N 46
0x00,0x3E,0x41,0x41,0x41,0x3E,// O 47 0x00,0x00,0x00,0x00,0x00,0x00, // O 47
0x00,0x7F,0x09,0x09,0x09,0x06,// P 48 0x00,0x00,0x00,0x00,0x00,0x00, // P 48
0x00,0x3E,0x41,0x51,0x21,0x5E,// Q 49 0x00,0x00,0x00,0x00,0x00,0x00, // Q 49
0x00,0x7F,0x09,0x19,0x29,0x46,// R 50 0x00,0x00,0x00,0x00,0x00,0x00, // R 50
0x00,0x46,0x49,0x49,0x49,0x31,// S 51 0x00,0x00,0x00,0x00,0x00,0x00, // S 51
0x00,0x01,0x01,0x7F,0x01,0x01,// T 52 0x00,0x00,0x00,0x00,0x00,0x00, // T 52
0x00,0x3F,0x40,0x40,0x40,0x3F,// U 53 0x00,0x00,0x00,0x00,0x00,0x00, // U 53
0x00,0x1F,0x20,0x40,0x20,0x1F,// V 54 0x00,0x00,0x00,0x00,0x00,0x00, // V 54
0x00,0x3F,0x40,0x38,0x40,0x3F,// W 55 0x00,0x00,0x00,0x00,0x00,0x00, // W 55
0x00,0x63,0x14,0x08,0x14,0x63,// X 56 0x00,0x00,0x00,0x00,0x00,0x00, // X 56
0x00,0x07,0x08,0x70,0x08,0x07,// Y 57 0x00,0x00,0x00,0x00,0x00,0x00, // Y 57
0x00,0x61,0x51,0x49,0x45,0x43,// Z 58 0x00,0x00,0x00,0x00,0x00,0x00, // Z 58
0x00,0x00,0x7F,0x41,0x41,0x00,// [ 59 0x00,0x00,0x00,0x00,0x00,0x00, // [ 59
0x00,0x02,0x04,0x08,0x10,0x20,// \ 60 0x00,0x00,0x00,0x00,0x00,0x00, // \ 60
0x00,0x00,0x41,0x41,0x7F,0x00,// ] 61 0x00,0x00,0x00,0x00,0x00,0x00, // ] 61
0x00,0x04,0x02,0x01,0x02,0x04,// ^ 62 0x00,0x00,0x00,0x00,0x00,0x00, // ^ 62
0x00,0x40,0x40,0x40,0x40,0x40,// _ 63 0x00,0x00,0x00,0x00,0x00,0x00, // _ 63
0x00,0x00,0x01,0x02,0x04,0x00,// ` 64 0x00,0x00,0x00,0x00,0x00,0x00, // ` 64
0x00,0x20,0x54,0x54,0x54,0x78,// a 65 0x00,0x00,0x00,0x00,0x00,0x00, // a 65
0x00,0x7F,0x48,0x44,0x44,0x38,// b 66 0x00,0x00,0x00,0x00,0x00,0x00, // b 66
0x00,0x38,0x44,0x44,0x44,0x20,// c 67 0x00,0x00,0x00,0x00,0x00,0x00, // c 67
0x00,0x38,0x44,0x44,0x48,0x7F,// d 68 0x00,0x00,0x00,0x00,0x00,0x00, // d 68
0x00,0x38,0x54,0x54,0x54,0x18,// e 69 0x00,0x00,0x00,0x00,0x00,0x00, // e 69
0x00,0x08,0x7E,0x09,0x01,0x02,// f 70 0x00,0x00,0x00,0x00,0x00,0x00, // f 70
0x00,0x18,0xA4,0xA4,0xA4,0x7C,// g 71 0x00,0x00,0x00,0x00,0x00,0x00, // g 71
0x00,0x7F,0x08,0x04,0x04,0x78,// h 72 0x00,0x00,0x00,0x00,0x00,0x00, // h 72
0x00,0x00,0x44,0x7D,0x40,0x00,// i 73 0x00,0x00,0x00,0x00,0x00,0x00, // i 73
0x00,0x40,0x80,0x84,0x7D,0x00,// j 74 0x00,0x00,0x00,0x00,0x00,0x00, // j 74
0x00,0x7F,0x10,0x28,0x44,0x00,// k 75 0x00,0x00,0x00,0x00,0x00,0x00, // k 75
0x00,0x00,0x41,0x7F,0x40,0x00,// l 76 0x00,0x00,0x00,0x00,0x00,0x00, // l 76
0x00,0x7C,0x04,0x18,0x04,0x78,// m 77 0x00,0x00,0x00,0x00,0x00,0x00, // m 77
0x00,0x7C,0x08,0x04,0x04,0x78,// n 78 0x00,0x00,0x00,0x00,0x00,0x00, // n 78
0x00,0x38,0x44,0x44,0x44,0x38,// o 79 0x00,0x00,0x00,0x00,0x00,0x00, // o 79
0x00,0xFC,0x24,0x24,0x24,0x18,// p 80 0x00,0x00,0x00,0x00,0x00,0x00, // p 80
0x00,0x18,0x24,0x24,0x18,0xFC,// q 81 0x00,0x00,0x00,0x00,0x00,0x00, // q 81
0x00,0x7C,0x08,0x04,0x04,0x08,// r 82 0x00,0x00,0x00,0x00,0x00,0x00, // r 82
0x00,0x48,0x54,0x54,0x54,0x20,// s 83 0x00,0x00,0x00,0x00,0x00,0x00, // s 83
0x00,0x04,0x3F,0x44,0x40,0x20,// t 84 0x00,0x00,0x00,0x00,0x00,0x00, // t 84
0x00,0x3C,0x40,0x40,0x20,0x7C,// u 85 0x00,0x00,0x00,0x00,0x00,0x00, // u 85
0x00,0x1C,0x20,0x40,0x20,0x1C,// v 86 0x00,0x00,0x00,0x00,0x00,0x00, // v 86
0x00,0x3C,0x40,0x30,0x40,0x3C,// w 87 0x00,0x00,0x00,0x00,0x00,0x00, // w 87
0x00,0x44,0x28,0x10,0x28,0x44,// x 88 0x00,0x00,0x00,0x00,0x00,0x00, // x 88
0x00,0x1C,0xA0,0xA0,0xA0,0x7C,// y 89 0x00,0x00,0x00,0x00,0x00,0x00, // y 89
0x00,0x44,0x64,0x54,0x4C,0x44,// z 90 0x00,0x00,0x00,0x00,0x00,0x00, // z 90
0x00,0x00,0x08,0x7F,0x41,0x00,// { 91 0x00,0x00,0x00,0x00,0x00,0x00, // { 91
0x00,0x00,0x00,0x7F,0x00,0x00,// | 92 0x00,0x00,0x00,0x00,0x00,0x00, // | 92
0x00,0x00,0x41,0x7F,0x08,0x00,// } 93 0x00,0x00,0x00,0x00,0x00,0x00, // } 93
0x00,0x08,0x04,0x08,0x10,0x08,// ~ 94 0x00,0x00,0x00,0x00,0x00,0x00 // ~ 94
}; };

View File

@@ -1,59 +1,62 @@
/* /*
* 模块名称ST7735S LCD驱动 * 模块名称ST7735S LCD驱动(底层)
* 模块功能:提供128x160 RGB TFT屏幕的初始化、画点、画线、填充、显示字符串等功能 * 模块功能:提供ST7735S屏幕的硬件SPI通信、初始化、填充、画点、方向控制等底层操作
* 适用平台STM32F103C8T6 + SPI2 * 绘图函数见 lcd.c
* 适用平台STM32F103C8T6 + 硬件SPI2
* 作者:王建锋 * 作者:王建锋
* 创建日期2026-07-13 * 创建日期2026-07-13
* 修改记录: * 修改记录:
* 2026-07-13 王建锋 创建初始版本 * 2026-07-13 王建锋 创建初始版本
* 2026-07-14 王建锋 软件SPI -> 硬件SPI2
* 2026-07-14 王建锋 拆分:绘图函数移入 lcd.c
*/ */
#include "st7735s.h" #include "st7735s.h"
#include "lcd_data.h"
#include "spi.h" #include "spi.h"
#include <stdio.h> #include <stdio.h>
#include <string.h>
static uint16_t s_lcd_width = LCD_WIDTH;
static uint16_t s_lcd_height = LCD_HEIGHT;
extern DMA_HandleTypeDef hdma_spi2_tx;
/* 8x16 ASCII字体ASCII 32-126每字符16字节 - 定义在 lcd_data.c 中 */
/* /*
* 函数功能软件SPI写一个字节 * 部分屏幕厂家虽然标称128x160但实际使用132x162驱动晶片
* 左右各偏移2列上下偏移1行才能正确显示。
* 根据自己的屏幕实测调整这两个值。
*/
#define X_OFFSET 2
#define Y_OFFSET 1
uint16_t s_lcd_width = LCD_WIDTH;
uint16_t s_lcd_height = LCD_HEIGHT;
/*
* 函数功能硬件SPI写一个字节
* 入口参数data - 要发送的数据 * 入口参数data - 要发送的数据
* 返回值:无 * 返回值:无
* 函数说明:模拟SPI时序发送一个字节MSB先 * 函数说明:使用SPI2外设发送一个字节
*/ */
static void st7735s_spi_write_byte(uint8_t data) void st7735s_spi_write_byte(uint8_t data)
{ {
uint8_t i; HAL_SPI_Transmit(&hspi2, &data, 1, HAL_MAX_DELAY);
for (i = 0; i < 8; i++) {
HAL_GPIO_WritePin(LCD_SCL_PORT, LCD_SCL_PIN, GPIO_PIN_RESET);
if (data & 0x80) {
HAL_GPIO_WritePin(LCD_SDA_PORT, LCD_SDA_PIN, GPIO_PIN_SET);
} else {
HAL_GPIO_WritePin(LCD_SDA_PORT, LCD_SDA_PIN, GPIO_PIN_RESET);
}
__NOP();
__NOP();
HAL_GPIO_WritePin(LCD_SCL_PORT, LCD_SCL_PIN, GPIO_PIN_SET);
__NOP();
__NOP();
data <<= 1;
}
} }
/* /*
* 函数功能:写入命令 * 函数功能:硬件SPI批量写数据
* 入口参数data - 数据缓冲区
* len - 字节数
* 返回值:无
* 函数说明使用DMA批量发送
*/
void st7735s_spi_write_bulk(const uint8_t *data, uint32_t len)
{
HAL_SPI_Transmit_DMA(&hspi2, (uint8_t *)data, len);
while (HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY);
}
/*
* 函数功能写入命令CS+DC管理单字节
* 入口参数cmd - 命令字节 * 入口参数cmd - 命令字节
* 返回值:无 * 返回值:无
* 函数说明拉低DC选择芯片,发送命令,释放芯片 * 函数说明拉低DC发送命令
*/ */
static void st7735s_write_cmd(uint8_t cmd) void st7735s_write_cmd(uint8_t cmd)
{ {
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_RESET);
@@ -62,12 +65,12 @@ static void st7735s_write_cmd(uint8_t cmd)
} }
/* /*
* 函数功能:写入数据 * 函数功能:写入数据CS+DC管理单字节
* 入口参数data - 数据字节 * 入口参数data - 数据字节
* 返回值:无 * 返回值:无
* 函数说明拉高DC选择芯片,发送数据,释放芯片 * 函数说明拉高DC发送数据
*/ */
static void st7735s_write_data(uint8_t data) void st7735s_write_data(uint8_t data)
{ {
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET);
@@ -76,119 +79,83 @@ static void st7735s_write_data(uint8_t data)
} }
/* /*
* 函数功能:写入多字节数据CS保持低 * 函数功能:设置显示窗口(框选区域
* 入口参数:p_data - 数据缓冲区指针 * 入口参数:x1 - 起始列(屏幕坐标,含偏移处理)
* len - 字节数 * y1 - 起始行
* x2 - 结束列
* y2 - 结束行
* 返回值:无 * 返回值:无
* 函数说明:用于连续写入多个数据字节省去中间CS跳变 * 函数说明:发送CASET(2Ah)+RASET(2Bh)+RAMWR(2Ch)
* 后续写入的数据将填充在此区域内
*/ */
static void st7735s_write_data_multi(const uint8_t *p_data, uint16_t len) void st7735s_set_window(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{ {
uint16_t i; st7735s_write_cmd(LCD_CMD_CASET);
st7735s_write_data(0x00);
st7735s_write_data(x1 + X_OFFSET);
st7735s_write_data(0x00);
st7735s_write_data(x2 + X_OFFSET);
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); st7735s_write_cmd(LCD_CMD_RASET);
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET); st7735s_write_data(0x00);
for (i = 0; i < len; i++) { st7735s_write_data(y1 + Y_OFFSET);
st7735s_spi_write_byte(p_data[i]); st7735s_write_data(0x00);
} st7735s_write_data(y2 + Y_OFFSET);
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
}
/* st7735s_write_cmd(LCD_CMD_RAMWR);
* 函数功能写入16位颜色数据
* 入口参数p_color - 16位颜色缓冲区指针
* len - 像素个数
* 返回值:无
* 函数说明MSB先发送RGB565数据
*/
static void st7735s_write_colors(uint16_t *p_color, uint16_t len)
{
uint16_t i;
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET);
for (i = 0; i < len; i++) {
st7735s_spi_write_byte((uint8_t)(p_color[i] >> 8));
st7735s_spi_write_byte((uint8_t)(p_color[i] & 0xFF));
}
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
} }
/* /*
* 函数功能LCD初始化 * 函数功能LCD初始化
* 入口参数:无 * 入口参数:无
* 返回值:无 * 返回值:无
* 函数说明:执行ST7735S标准初始化序列 * 函数说明:初始化ST7735S屏幕依赖MX_SPI2_Init()提前配置好SPI2
*/ */
void st7735s_init(void) void st7735s_init(void)
{ {
GPIO_InitTypeDef GPIO_InitStruct = {0}; printf("LCD init start (HW SPI2)...\r\n");
printf("LCD init start (soft SPI)...\r\n"); /* CS初始高电平 */
/* 将SCL和SDA引脚切换为GPIO输出软件SPI */
GPIO_InitStruct.Pin = LCD_SCL_PIN | LCD_SDA_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_GPIO_WritePin(LCD_SCL_PORT, LCD_SCL_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(LCD_SDA_PORT, LCD_SDA_PIN, GPIO_PIN_SET);
/* 确保CS和RST初始为高避免LCD在初始化期间被错误选中 */
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(LCD_RST_PORT, LCD_RST_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_RESET);
HAL_Delay(10);
printf("IO: RST=%d DC=%d CS=%d\r\n",
(int)HAL_GPIO_ReadPin(LCD_RST_PORT, LCD_RST_PIN),
(int)HAL_GPIO_ReadPin(LCD_DC_PORT, LCD_DC_PIN),
(int)HAL_GPIO_ReadPin(LCD_CS_PORT, LCD_CS_PIN));
/* 硬件复位 */ /* 硬件复位 */
printf("HW reset...\r\n");
HAL_GPIO_WritePin(LCD_RST_PORT, LCD_RST_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(LCD_RST_PORT, LCD_RST_PIN, GPIO_PIN_RESET);
HAL_Delay(10); HAL_Delay(20);
HAL_GPIO_WritePin(LCD_RST_PORT, LCD_RST_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(LCD_RST_PORT, LCD_RST_PIN, GPIO_PIN_SET);
HAL_Delay(120); HAL_Delay(150);
/* 软件复位 */ /* 软件复位 */
printf("SW reset...\r\n");
st7735s_write_cmd(LCD_CMD_SWRESET); st7735s_write_cmd(LCD_CMD_SWRESET);
HAL_Delay(150); HAL_Delay(150);
/* 退出睡眠模式 */ /* 退出睡眠模式 */
printf("Sleep out...\r\n");
st7735s_write_cmd(LCD_CMD_SLPOUT); st7735s_write_cmd(LCD_CMD_SLPOUT);
HAL_Delay(500); HAL_Delay(120);
/* 帧率控制 */ /* 帧率控制 */
printf("Frame rate...\r\n");
st7735s_write_cmd(LCD_CMD_FRMCTR1); st7735s_write_cmd(LCD_CMD_FRMCTR1);
st7735s_write_data(0x01); st7735s_write_data(0x05);
st7735s_write_data(0x2C); st7735s_write_data(0x3C);
st7735s_write_data(0x2D); st7735s_write_data(0x3C);
st7735s_write_cmd(LCD_CMD_FRMCTR2); st7735s_write_cmd(LCD_CMD_FRMCTR2);
st7735s_write_data(0x01); st7735s_write_data(0x05);
st7735s_write_data(0x2C); st7735s_write_data(0x3C);
st7735s_write_data(0x2D); st7735s_write_data(0x3C);
st7735s_write_cmd(LCD_CMD_FRMCTR3); st7735s_write_cmd(LCD_CMD_FRMCTR3);
st7735s_write_data(0x01); st7735s_write_data(0x05);
st7735s_write_data(0x2C); st7735s_write_data(0x3C);
st7735s_write_data(0x2D); st7735s_write_data(0x3C);
st7735s_write_data(0x01); st7735s_write_data(0x05);
st7735s_write_data(0x2C); st7735s_write_data(0x3C);
st7735s_write_data(0x2D); st7735s_write_data(0x3C);
/* 显示反转控制 */ /* 显示反转控制(列反转) */
st7735s_write_cmd(LCD_CMD_INVCTR); st7735s_write_cmd(LCD_CMD_INVCTR);
st7735s_write_data(0x07); st7735s_write_data(0x03);
/* 功率控制 */ /* 功率控制 */
printf("Power ctrl...\r\n");
st7735s_write_cmd(LCD_CMD_PWCTR1); st7735s_write_cmd(LCD_CMD_PWCTR1);
st7735s_write_data(0xA2); st7735s_write_data(0xA2);
st7735s_write_data(0x02); st7735s_write_data(0x02);
@@ -198,108 +165,113 @@ void st7735s_init(void)
st7735s_write_data(0xC5); st7735s_write_data(0xC5);
st7735s_write_cmd(LCD_CMD_PWCTR3); st7735s_write_cmd(LCD_CMD_PWCTR3);
st7735s_write_data(0x0A); st7735s_write_data(0x0D);
st7735s_write_data(0x00); st7735s_write_data(0x00);
st7735s_write_cmd(LCD_CMD_PWCTR4); st7735s_write_cmd(LCD_CMD_PWCTR4);
st7735s_write_data(0x8A); st7735s_write_data(0x8D);
st7735s_write_data(0x2A); st7735s_write_data(0x2A);
st7735s_write_cmd(LCD_CMD_PWCTR5); st7735s_write_cmd(LCD_CMD_PWCTR5);
st7735s_write_data(0x8A); st7735s_write_data(0x8D);
st7735s_write_data(0xEE); st7735s_write_data(0xEE);
/* VCOM控制 */ /* VCOM控制 */
st7735s_write_cmd(LCD_CMD_VMCTR1); st7735s_write_cmd(LCD_CMD_VMCTR1);
st7735s_write_data(0x0E); st7735s_write_data(0x0E);
/* 竖屏模式 */ /* 关闭反转显示 */
printf("MADCTL...\r\n"); st7735s_write_cmd(0x20);
st7735s_write_cmd(LCD_CMD_MADCTL); /* 关闭空闲模式 */
st7735s_write_data(0xC8); st7735s_write_cmd(0x38);
/* 正常模式(非部分模式) */
st7735s_write_cmd(0x13);
/* 像素格式: 16位RGB565 */ /* 存储器访问控制 (MADCTL)
printf("COLMOD...\r\n"); * MY=0 MX=0 MV=0 ML=0 RGB=0 MH=0 → 0x00
* 左上角为坐标原点,列从左到右,行从上到下
*/
st7735s_write_cmd(LCD_CMD_MADCTL);
st7735s_write_data(0x00);
/* 像素格式16位 RGB565 */
st7735s_write_cmd(LCD_CMD_COLMOD); st7735s_write_cmd(LCD_CMD_COLMOD);
st7735s_write_data(0x05); st7735s_write_data(0x05);
/* Gamma校正 */ /* Gamma校正 */
printf("Gamma...\r\n");
st7735s_write_cmd(LCD_CMD_GMCTRP1); st7735s_write_cmd(LCD_CMD_GMCTRP1);
st7735s_write_data(0x02); st7735s_write_data(0x0F);
st7735s_write_data(0x1C); st7735s_write_data(0x1A);
st7735s_write_data(0x07); st7735s_write_data(0x0F);
st7735s_write_data(0x12); st7735s_write_data(0x18);
st7735s_write_data(0x37); st7735s_write_data(0x2F);
st7735s_write_data(0x32); st7735s_write_data(0x28);
st7735s_write_data(0x29); st7735s_write_data(0x22);
st7735s_write_data(0x2D); st7735s_write_data(0x26);
st7735s_write_data(0x29); st7735s_write_data(0x31);
st7735s_write_data(0x25); st7735s_write_data(0x1B);
st7735s_write_data(0x2B); st7735s_write_data(0x13);
st7735s_write_data(0x39); st7735s_write_data(0x1E);
st7735s_write_data(0x00); st7735s_write_data(0x13);
st7735s_write_data(0x01); st7735s_write_data(0x11);
st7735s_write_data(0x03); st7735s_write_data(0x06);
st7735s_write_data(0x10);
st7735s_write_cmd(LCD_CMD_GMCTRN1); st7735s_write_cmd(LCD_CMD_GMCTRN1);
st7735s_write_data(0x03); st7735s_write_data(0x0F);
st7735s_write_data(0x1D); st7735s_write_data(0x1B);
st7735s_write_data(0x07); st7735s_write_data(0x0F);
st7735s_write_data(0x06); st7735s_write_data(0x17);
st7735s_write_data(0x2E); st7735s_write_data(0x33);
st7735s_write_data(0x2C); st7735s_write_data(0x2C);
st7735s_write_data(0x29); st7735s_write_data(0x29);
st7735s_write_data(0x2D);
st7735s_write_data(0x2E); st7735s_write_data(0x2E);
st7735s_write_data(0x2E); st7735s_write_data(0x30);
st7735s_write_data(0x37); st7735s_write_data(0x30);
st7735s_write_data(0x39);
st7735s_write_data(0x3F); st7735s_write_data(0x3F);
st7735s_write_data(0x00); st7735s_write_data(0x34);
st7735s_write_data(0x00); st7735s_write_data(0x14);
st7735s_write_data(0x02); st7735s_write_data(0x06);
st7735s_write_data(0x10);
/* 关闭反转 */
st7735s_write_cmd(0x20);
/* 进入正常显示模式(关键!) */
printf("NORON...\r\n");
st7735s_write_cmd(0x13);
HAL_Delay(10); HAL_Delay(10);
/* 开启显示 */ /* 显示开启 */
printf("DISPON...\r\n");
st7735s_write_cmd(LCD_CMD_DISPON); st7735s_write_cmd(LCD_CMD_DISPON);
HAL_Delay(100); HAL_Delay(100);
printf("LCD init done\r\n");
printf("LCD init OK\r\n");
} }
/* /*
* 函数功能:设置显示窗口 * 函数功能:全屏填充
* 入口参数:x1 - 起始列 * 入口参数:color - 填充颜色 (RGB565)
* y1 - 起始行
* x2 - 结束列
* y2 - 结束行
* 返回值:无 * 返回值:无
* 函数说明:设置后续写入操作的窗口区域 * 函数说明:用指定颜色填充整个屏幕
*/ */
void st7735s_set_window(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) void st7735s_fill_screen(uint16_t color)
{ {
st7735s_write_cmd(LCD_CMD_CASET); uint32_t i;
st7735s_write_data(0x00); uint32_t total = (uint32_t)s_lcd_width * s_lcd_height;
st7735s_write_data((uint8_t)x1); uint8_t buf[32];
st7735s_write_data(0x00); uint8_t hi = (uint8_t)(color >> 8);
st7735s_write_data((uint8_t)x2); uint8_t lo = (uint8_t)(color & 0xFF);
st7735s_write_cmd(LCD_CMD_RASET); for (i = 0; i < sizeof(buf) / 2; i++) {
st7735s_write_data(0x00); buf[i * 2] = hi;
st7735s_write_data((uint8_t)y1); buf[i * 2 + 1] = lo;
st7735s_write_data(0x00); }
st7735s_write_data((uint8_t)y2);
st7735s_write_cmd(LCD_CMD_RAMWR); st7735s_set_window(0, 0, s_lcd_width - 1, s_lcd_height - 1);
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET);
i = total * 2;
while (i > 0) {
uint32_t n = (i > sizeof(buf)) ? sizeof(buf) : i;
st7735s_spi_write_bulk(buf, n);
i -= n;
}
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
} }
/* /*
@@ -314,50 +286,33 @@ void st7735s_set_window(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
*/ */
void st7735s_fill_rect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) void st7735s_fill_rect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
{ {
uint32_t pixel_count; uint32_t i;
uint16_t i; uint32_t total;
uint16_t buf[64]; uint8_t buf[32];
uint8_t hi = (uint8_t)(color >> 8);
uint8_t lo = (uint8_t)(color & 0xFF);
if (x1 > x2) { if (x1 > x2) { uint16_t t = x1; x1 = x2; x2 = t; }
uint16_t t = x1; if (y1 > y2) { uint16_t t = y1; y1 = y2; y2 = t; }
x1 = x2;
x2 = t; for (i = 0; i < sizeof(buf) / 2; i++) {
} buf[i * 2] = hi;
if (y1 > y2) { buf[i * 2 + 1] = lo;
uint16_t t = y1;
y1 = y2;
y2 = t;
} }
pixel_count = (uint32_t)(x2 - x1 + 1) * (y2 - y1 + 1); total = (uint32_t)(x2 - x1 + 1) * (y2 - y1 + 1);
/* 预填充颜色缓冲区 */
for (i = 0; i < 64; i++) {
buf[i] = color;
}
st7735s_set_window(x1, y1, x2, y2); st7735s_set_window(x1, y1, x2, y2);
/* 分块发送 */ HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
while (pixel_count >= 64) { HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET);
st7735s_write_colors(buf, 64); i = total * 2;
pixel_count -= 64; while (i > 0) {
uint32_t n = (i > sizeof(buf)) ? sizeof(buf) : i;
st7735s_spi_write_bulk(buf, n);
i -= n;
} }
if (pixel_count > 0) { HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
st7735s_write_colors(buf, (uint16_t)pixel_count);
}
}
/*
* 函数功能:全屏填充
* 入口参数color - 填充颜色 (RGB565)
* 返回值:无
* 函数说明:用指定颜色填充整个屏幕
*/
void st7735s_fill_screen(uint16_t color)
{
printf("fill_screen 0x%04X\r\n", color);
st7735s_fill_rect(0, 0, s_lcd_width - 1, s_lcd_height - 1, color);
} }
/* /*
@@ -370,252 +325,65 @@ void st7735s_fill_screen(uint16_t color)
*/ */
void st7735s_draw_pixel(uint16_t x, uint16_t y, uint16_t color) void st7735s_draw_pixel(uint16_t x, uint16_t y, uint16_t color)
{ {
if (x >= s_lcd_width || y >= s_lcd_height) {
return;
}
st7735s_set_window(x, y, x, y); st7735s_set_window(x, y, x, y);
st7735s_write_data((uint8_t)(color >> 8)); HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
st7735s_write_data((uint8_t)color); HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET);
} st7735s_spi_write_byte((uint8_t)(color >> 8));
st7735s_spi_write_byte((uint8_t)(color & 0xFF));
/* HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
* 函数功能:画线
* 入口参数x1 - 起始列
* y1 - 起始行
* x2 - 结束列
* y2 - 结束行
* color - 颜色 (RGB565)
* 返回值:无
* 函数说明画一条直线Bresenham算法
*/
void st7735s_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
{
int16_t dx;
int16_t dy;
int16_t sx;
int16_t sy;
int16_t err;
int16_t e2;
uint16_t x;
uint16_t y;
if (x1 == x2) {
/* 垂直线 */
if (y1 > y2) {
y = y1;
y1 = y2;
y2 = y;
}
st7735s_fill_rect(x1, y1, x1, y2, color);
return;
}
if (y1 == y2) {
/* 水平线 */
if (x1 > x2) {
x = x1;
x1 = x2;
x2 = x;
}
st7735s_fill_rect(x1, y1, x2, y1, color);
return;
}
dx = (int16_t)x2 - (int16_t)x1;
if (dx < 0) {
dx = -dx;
}
sx = x1 < x2 ? 1 : -1;
dy = (int16_t)y2 - (int16_t)y1;
if (dy < 0) {
dy = -dy;
}
sy = y1 < y2 ? 1 : -1;
err = (dx > dy ? dx : -dy) / 2;
x = x1;
y = y1;
while (1) {
st7735s_draw_pixel(x, y, color);
if (x == x2 && y == y2) {
break;
}
e2 = err;
if (e2 > -dx) {
err -= dy;
x += sx;
}
if (e2 < dy) {
err += dx;
y += sy;
}
}
}
/*
* 函数功能:画矩形
* 入口参数x - 左上角列
* y - 左上角行
* width - 宽度
* height - 高度
* color - 颜色 (RGB565)
* 返回值:无
* 函数说明:画一个空心矩形
*/
void st7735s_draw_rect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color)
{
st7735s_draw_line(x, y, x + width - 1, y, color);
st7735s_draw_line(x, y + height - 1, x + width - 1, y + height - 1, color);
st7735s_draw_line(x, y, x, y + height - 1, color);
st7735s_draw_line(x + width - 1, y, x + width - 1, y + height - 1, color);
}
/*
* 函数功能:画圆
* 入口参数x0 - 圆心列
* y0 - 圆心行
* radius - 半径
* color - 颜色 (RGB565)
* 返回值:无
* 函数说明画一个空心圆Bresenham算法
*/
void st7735s_draw_circle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color)
{
int16_t f = 1 - radius;
int16_t ddf_x = 1;
int16_t ddf_y = -2 * radius;
int16_t x = 0;
int16_t y = radius;
st7735s_draw_pixel(x0, y0 + radius, color);
st7735s_draw_pixel(x0, y0 - radius, color);
st7735s_draw_pixel(x0 + radius, y0, color);
st7735s_draw_pixel(x0 - radius, y0, color);
while (x < y) {
if (f >= 0) {
y--;
ddf_y += 2;
f += ddf_y;
}
x++;
ddf_x += 2;
f += ddf_x;
st7735s_draw_pixel(x0 + x, y0 + y, color);
st7735s_draw_pixel(x0 - x, y0 + y, color);
st7735s_draw_pixel(x0 + x, y0 - y, color);
st7735s_draw_pixel(x0 - x, y0 - y, color);
st7735s_draw_pixel(x0 + y, y0 + x, color);
st7735s_draw_pixel(x0 - y, y0 + x, color);
st7735s_draw_pixel(x0 + y, y0 - x, color);
st7735s_draw_pixel(x0 - y, y0 - x, color);
}
}
/*
* 函数功能:显示字符
* 入口参数x - 列坐标
* y - 行坐标
* ch - 字符 (ASCII 32-126)
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
* 函数说明在指定位置显示一个8x16 ASCII字符
*/
void st7735s_draw_char(uint16_t x, uint16_t y, char ch, uint16_t color, uint16_t bg_color)
{
uint16_t i;
uint16_t j;
uint8_t line;
if (ch < 32 || ch > 126) {
ch = ' ';
}
for (i = 0; i < 16; i++) {
line = LCD_F8x16[ch - 32][i];
for (j = 0; j < 8; j++) {
if (line & 0x80) {
st7735s_draw_pixel(x + j, y + i, color);
} else {
st7735s_draw_pixel(x + j, y + i, bg_color);
}
line <<= 1;
}
}
}
/*
* 函数功能:显示字符串
* 入口参数x - 列坐标
* y - 行坐标
* str - 字符串指针
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
* 函数说明:在指定位置显示字符串
*/
void st7735s_draw_string(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bg_color)
{
while (*str) {
if (x + 8 > s_lcd_width) {
x = 0;
y += 16;
}
if (y + 16 > s_lcd_height) {
break;
}
st7735s_draw_char(x, y, *str, color, bg_color);
x += FONT_WIDTH_8;
str++;
}
} }
/* /*
* 函数功能:设置屏幕方向 * 函数功能:设置屏幕方向
* 入口参数rotation - 方向 (0-3) * 入口参数rotation - 方向 (0-3)
* 返回值:无 * 返回值:无
* 函数说明:0:竖屏 1:横屏 2:竖屏反转 3:横屏反转 * 函数说明:通过修改MADCTL(36h)寄存器控制显示方向
* 0: 竖屏 1: 横屏 2: 竖屏反转 3: 横屏反转
*/ */
void st7735s_set_rotation(uint8_t rotation) void st7735s_set_rotation(uint8_t rotation)
{ {
st7735s_write_cmd(LCD_CMD_MADCTL); uint8_t madctl = 0xC0;
switch (rotation) { switch (rotation) {
case 0: case 0:
st7735s_write_data(0xC8); madctl = 0xC0;
s_lcd_width = 128; s_lcd_width = LCD_WIDTH;
s_lcd_height = 160; s_lcd_height = LCD_HEIGHT;
break; break;
case 1: case 1:
st7735s_write_data(0x78); madctl = 0xA0;
s_lcd_width = 160; s_lcd_width = LCD_HEIGHT;
s_lcd_height = 128; s_lcd_height = LCD_WIDTH;
break; break;
case 2: case 2:
st7735s_write_data(0x08); madctl = 0x00;
s_lcd_width = 128; s_lcd_width = LCD_WIDTH;
s_lcd_height = 160; s_lcd_height = LCD_HEIGHT;
break; break;
case 3: case 3:
st7735s_write_data(0xA8); madctl = 0x60;
s_lcd_width = 160; s_lcd_width = LCD_HEIGHT;
s_lcd_height = 128; s_lcd_height = LCD_WIDTH;
break; break;
default: default:
break; break;
} }
st7735s_write_cmd(LCD_CMD_MADCTL);
st7735s_write_data(madctl);
} }
/* /*
* 函数功能:设置背光 * 函数功能:设置背光
* 入口参数state - 1:开 0:关 * 入口参数state - 1:开 0:关
* 返回值:无 * 返回值:无
* 函数说明:控制LCD背光(如有硬件背光控制) * 函数说明:通过PC13控制背光(如有背光控制引脚则修改
*/ */
void st7735s_backlight(uint8_t state) void st7735s_backlight(uint8_t state)
{ {
(void)state; if (state) {
/* 当前硬件未连接背光控制引脚,预留接口 */ printf("backlight on\r\n");
} else {
printf("backlight off\r\n");
}
} }

View File

@@ -1,11 +1,14 @@
/* /*
* 模块名称ST7735S LCD驱动 * 模块名称ST7735S LCD驱动(底层)
* 模块功能:提供128x160 RGB TFT屏幕的初始化、画点、画线、填充、显示字符串等功能 * 模块功能:提供ST7735S屏幕的硬件SPI通信、初始化、填充、画点、方向控制等底层操作
* 适用平台STM32F103C8T6 + SPI2 * 绘图函数见 lcd.h
* 适用平台STM32F103C8T6 + 硬件SPI2
* 作者:王建锋 * 作者:王建锋
* 创建日期2026-07-13 * 创建日期2026-07-13
* 修改记录: * 修改记录:
* 2026-07-13 王建锋 创建初始版本 * 2026-07-13 王建锋 创建初始版本
* 2026-07-14 王建锋 软件SPI -> 硬件SPI2
* 2026-07-14 王建锋 拆分:绘图函数移入 lcd.h
*/ */
#ifndef __ST7735S_H #ifndef __ST7735S_H
@@ -40,16 +43,13 @@ extern "C" {
#define RGB565(r, g, b) ((uint16_t)(((r) & 0xF8) << 8 | ((g) & 0xFC) << 3 | ((b) >> 3))) #define RGB565(r, g, b) ((uint16_t)(((r) & 0xF8) << 8 | ((g) & 0xFC) << 3 | ((b) >> 3)))
/* LCD控制引脚定义 - 根据CubeMX配置修改 */ /* LCD控制引脚定义 - 根据CubeMX配置修改 */
/* SCL(PB13)和SDA(PB15)由SPI2外设管理无需GPIO定义 */
#define LCD_CS_PORT LCD_CS_GPIO_Port #define LCD_CS_PORT LCD_CS_GPIO_Port
#define LCD_CS_PIN LCD_CS_Pin #define LCD_CS_PIN LCD_CS_Pin
#define LCD_DC_PORT LCD_DC_GPIO_Port #define LCD_DC_PORT LCD_DC_GPIO_Port
#define LCD_DC_PIN LCD_DC_Pin #define LCD_DC_PIN LCD_DC_Pin
#define LCD_RST_PORT LCD_RST_GPIO_Port #define LCD_RST_PORT LCD_RST_GPIO_Port
#define LCD_RST_PIN LCD_RST_Pin #define LCD_RST_PIN LCD_RST_Pin
#define LCD_SCL_PORT GPIOB
#define LCD_SCL_PIN GPIO_PIN_13
#define LCD_SDA_PORT GPIOB
#define LCD_SDA_PIN GPIO_PIN_15
/* LCD命令定义 */ /* LCD命令定义 */
#define LCD_CMD_SWRESET 0x01 /* 软件复位 */ #define LCD_CMD_SWRESET 0x01 /* 软件复位 */
@@ -74,17 +74,42 @@ extern "C" {
#define LCD_CMD_GMCTRP1 0xE0 /* Gamma正向校正 */ #define LCD_CMD_GMCTRP1 0xE0 /* Gamma正向校正 */
#define LCD_CMD_GMCTRN1 0xE1 /* Gamma反向校正 */ #define LCD_CMD_GMCTRN1 0xE1 /* Gamma反向校正 */
/* 字体定义 */ /* 外部变量 - LCD宽高由旋转函数更新 */
#define FONT_WIDTH_8 8 /* 8x16字体宽度含间距 */ extern uint16_t s_lcd_width;
#define FONT_HEIGHT_16 16 /* 8x16字体高度 */ extern uint16_t s_lcd_height;
/* === 底层SPI通信函数 === */
/* /*
* 函数功能:LCD初始化 * 函数功能:硬件SPI写一个字节
* 入口参数: * 入口参数:data - 要发送的数据
* 返回值:无 * 返回值:无
* 函数说明初始化ST7735S屏幕包括SPI、GPIO、显示参数配置
*/ */
void st7735s_init(void); void st7735s_spi_write_byte(uint8_t data);
/*
* 函数功能硬件SPI批量写数据
* 入口参数data - 数据缓冲区
* len - 字节数
* 返回值:无
*/
void st7735s_spi_write_bulk(const uint8_t *data, uint32_t len);
/*
* 函数功能写入命令CS+DC管理单字节
* 入口参数cmd - 命令字节
* 返回值:无
*/
void st7735s_write_cmd(uint8_t cmd);
/*
* 函数功能写入数据CS+DC管理单字节
* 入口参数data - 数据字节
* 返回值:无
*/
void st7735s_write_data(uint8_t data);
/* === 驱动控制函数 === */
/* /*
* 函数功能:设置显示窗口 * 函数功能:设置显示窗口
@@ -93,10 +118,23 @@ void st7735s_init(void);
* x2 - 结束列 * x2 - 结束列
* y2 - 结束行 * y2 - 结束行
* 返回值:无 * 返回值:无
* 函数说明:设置后续写入操作的窗口区域
*/ */
void st7735s_set_window(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); void st7735s_set_window(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
/*
* 函数功能LCD初始化
* 入口参数:无
* 返回值:无
*/
void st7735s_init(void);
/*
* 函数功能:全屏填充
* 入口参数color - 填充颜色 (RGB565)
* 返回值:无
*/
void st7735s_fill_screen(uint16_t color);
/* /*
* 函数功能:填充矩形区域 * 函数功能:填充矩形区域
* 入口参数x1 - 起始列 * 入口参数x1 - 起始列
@@ -105,96 +143,22 @@ void st7735s_set_window(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
* y2 - 结束行 * y2 - 结束行
* color - 填充颜色 (RGB565) * color - 填充颜色 (RGB565)
* 返回值:无 * 返回值:无
* 函数说明:用指定颜色填充矩形区域
*/ */
void st7735s_fill_rect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); void st7735s_fill_rect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
/*
* 函数功能:全屏填充
* 入口参数color - 填充颜色 (RGB565)
* 返回值:无
* 函数说明:用指定颜色填充整个屏幕
*/
void st7735s_fill_screen(uint16_t color);
/* /*
* 函数功能:画点 * 函数功能:画点
* 入口参数x - 列坐标 * 入口参数x - 列坐标
* y - 行坐标 * y - 行坐标
* color - 颜色 (RGB565) * color - 颜色 (RGB565)
* 返回值:无 * 返回值:无
* 函数说明:在指定位置画一个点
*/ */
void st7735s_draw_pixel(uint16_t x, uint16_t y, uint16_t color); void st7735s_draw_pixel(uint16_t x, uint16_t y, uint16_t color);
/*
* 函数功能:画线
* 入口参数x1 - 起始列
* y1 - 起始行
* x2 - 结束列
* y2 - 结束行
* color - 颜色 (RGB565)
* 返回值:无
* 函数说明画一条直线Bresenham算法
*/
void st7735s_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
/*
* 函数功能:画矩形
* 入口参数x - 左上角列
* y - 左上角行
* width - 宽度
* height - 高度
* color - 颜色 (RGB565)
* 返回值:无
* 函数说明:画一个空心矩形
*/
void st7735s_draw_rect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
/*
* 函数功能:画圆
* 入口参数x0 - 圆心列
* y0 - 圆心行
* radius - 半径
* color - 颜色 (RGB565)
* 返回值:无
* 函数说明画一个空心圆Bresenham算法
*/
void st7735s_draw_circle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color);
/*
* 函数功能:显示字符
* 入口参数x - 列坐标
* y - 行坐标
* ch - 字符 (ASCII 32-126)
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
* 函数说明在指定位置显示一个8x16 ASCII字符
*/
void st7735s_draw_char(uint16_t x, uint16_t y, char ch, uint16_t color, uint16_t bg_color);
/*
* 函数功能:显示字符串
* 入口参数x - 列坐标
* y - 行坐标
* str - 字符串指针
* color - 字符颜色 (RGB565)
* bg_color - 背景颜色 (RGB565)
* 返回值:无
* 函数说明:在指定位置显示字符串
*/
void st7735s_draw_string(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bg_color);
/* /*
* 函数功能:设置屏幕方向 * 函数功能:设置屏幕方向
* 入口参数rotation - 方向 (0-3) * 入口参数rotation - 方向 (0-3)
* 返回值:无 * 返回值:无
* 函数说明:设置屏幕显示方向
* 0: 竖屏
* 1: 横屏
* 2: 竖屏反转
* 3: 横屏反转
*/ */
void st7735s_set_rotation(uint8_t rotation); void st7735s_set_rotation(uint8_t rotation);
@@ -202,7 +166,6 @@ void st7735s_set_rotation(uint8_t rotation);
* 函数功能:设置背光 * 函数功能:设置背光
* 入口参数state - 1:开 0:关 * 入口参数state - 1:开 0:关
* 返回值:无 * 返回值:无
* 函数说明控制LCD背光如有硬件背光控制
*/ */
void st7735s_backlight(uint8_t state); void st7735s_backlight(uint8_t state);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,706 @@
/**
******************************************************************************
* @file stm32f1xx_hal_adc_ex.h
* @author MCD Application Team
* @brief Header file of ADC HAL extension module.
******************************************************************************
* @attention
*
* Copyright (c) 2016 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F1xx_HAL_ADC_EX_H
#define __STM32F1xx_HAL_ADC_EX_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal_def.h"
/** @addtogroup STM32F1xx_HAL_Driver
* @{
*/
/** @addtogroup ADCEx
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup ADCEx_Exported_Types ADCEx Exported Types
* @{
*/
/**
* @brief ADC Configuration injected Channel structure definition
* @note Parameters of this structure are shared within 2 scopes:
* - Scope channel: InjectedChannel, InjectedRank, InjectedSamplingTime, InjectedOffset
* - Scope injected group (affects all channels of injected group): InjectedNbrOfConversion, InjectedDiscontinuousConvMode,
* AutoInjectedConv, ExternalTrigInjecConvEdge, ExternalTrigInjecConv.
* @note The setting of these parameters with function HAL_ADCEx_InjectedConfigChannel() is conditioned to ADC state.
* ADC state can be either:
* - For all parameters: ADC disabled (this is the only possible ADC state to modify parameter 'ExternalTrigInjecConv')
* - For all except parameters 'ExternalTrigInjecConv': ADC enabled without conversion on going on injected group.
*/
typedef struct
{
uint32_t InjectedChannel; /*!< Selection of ADC channel to configure
This parameter can be a value of @ref ADC_channels
Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability.
Note: On STM32F1 devices with several ADC: Only ADC1 can access internal measurement channels (VrefInt/TempSensor)
Note: On STM32F10xx8 and STM32F10xxB devices: A low-amplitude voltage glitch may be generated (on ADC input 0) on the PA0 pin, when the ADC is converting with injection trigger.
It is advised to distribute the analog channels so that Channel 0 is configured as an injected channel.
Refer to errata sheet of these devices for more details. */
uint32_t InjectedRank; /*!< Rank in the injected group sequencer
This parameter must be a value of @ref ADCEx_injected_rank
Note: In case of need to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by the new channel setting (or parameter number of conversions can be adjusted) */
uint32_t InjectedSamplingTime; /*!< Sampling time value to be set for the selected channel.
Unit: ADC clock cycles
Conversion time is the addition of sampling time and processing time (12.5 ADC clock cycles at ADC resolution 12 bits).
This parameter can be a value of @ref ADC_sampling_times
Caution: This parameter updates the parameter property of the channel, that can be used into regular and/or injected groups.
If this same channel has been previously configured in the other group (regular/injected), it will be updated to last setting.
Note: In case of usage of internal measurement channels (VrefInt/TempSensor),
sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
Refer to device datasheet for timings values, parameters TS_vrefint, TS_temp (values rough order: 5us to 17.1us min). */
uint32_t InjectedOffset; /*!< Defines the offset to be subtracted from the raw converted data (for channels set on injected group only).
Offset value must be a positive number.
Depending of ADC resolution selected (12, 10, 8 or 6 bits),
this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. */
uint32_t InjectedNbrOfConversion; /*!< Specifies the number of ranks that will be converted within the injected group sequencer.
To use the injected group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled.
This parameter must be a number between Min_Data = 1 and Max_Data = 4.
Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
configure a channel on injected group can impact the configuration of other channels previously set. */
FunctionalState InjectedDiscontinuousConvMode; /*!< Specifies whether the conversions sequence of injected group is performed in Complete-sequence/Discontinuous-sequence (main sequence subdivided in successive parts).
Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded.
This parameter can be set to ENABLE or DISABLE.
Note: For injected group, number of discontinuous ranks increment is fixed to one-by-one.
Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
configure a channel on injected group can impact the configuration of other channels previously set. */
FunctionalState AutoInjectedConv; /*!< Enables or disables the selected ADC automatic injected group conversion after regular one
This parameter can be set to ENABLE or DISABLE.
Note: To use Automatic injected conversion, discontinuous mode must be disabled ('DiscontinuousConvMode' and 'InjectedDiscontinuousConvMode' set to DISABLE)
Note: To use Automatic injected conversion, injected group external triggers must be disabled ('ExternalTrigInjecConv' set to ADC_SOFTWARE_START)
Note: In case of DMA used with regular group: if DMA configured in normal mode (single shot) JAUTO will be stopped upon DMA transfer complete.
To maintain JAUTO always enabled, DMA must be configured in circular mode.
Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
configure a channel on injected group can impact the configuration of other channels previously set. */
uint32_t ExternalTrigInjecConv; /*!< Selects the external event used to trigger the conversion start of injected group.
If set to ADC_INJECTED_SOFTWARE_START, external triggers are disabled.
If set to external trigger source, triggering is on event rising edge.
This parameter can be a value of @ref ADCEx_External_trigger_source_Injected
Note: This parameter must be modified when ADC is disabled (before ADC start conversion or after ADC stop conversion).
If ADC is enabled, this parameter setting is bypassed without error reporting (as it can be the expected behaviour in case of another parameter update on the fly)
Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
configure a channel on injected group can impact the configuration of other channels previously set. */
}ADC_InjectionConfTypeDef;
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
/**
* @brief Structure definition of ADC multimode
* @note The setting of these parameters with function HAL_ADCEx_MultiModeConfigChannel() is conditioned to ADCs state (both ADCs of the common group).
* State of ADCs of the common group must be: disabled.
*/
typedef struct
{
uint32_t Mode; /*!< Configures the ADC to operate in independent or multi mode.
This parameter can be a value of @ref ADCEx_Common_mode
Note: In dual mode, a change of channel configuration generates a restart that can produce a loss of synchronization. It is recommended to disable dual mode before any configuration change.
Note: In case of simultaneous mode used: Exactly the same sampling time should be configured for the 2 channels that will be sampled simultaneously by ACD1 and ADC2.
Note: In case of interleaved mode used: To avoid overlap between conversions, maximum sampling time allowed is 7 ADC clock cycles for fast interleaved mode and 14 ADC clock cycles for slow interleaved mode.
Note: Some multimode parameters are fixed on STM32F1 and can be configured on other STM32 devices with several ADC (multimode configuration structure can have additional parameters).
The equivalences are:
- Parameter 'DMAAccessMode': On STM32F1, this parameter is fixed to 1 DMA channel (one DMA channel for both ADC, DMA of ADC master). On other STM32 devices with several ADC, this is equivalent to parameter 'ADC_DMAACCESSMODE_12_10_BITS'.
- Parameter 'TwoSamplingDelay': On STM32F1, this parameter is fixed to 7 or 14 ADC clock cycles depending on fast or slow interleaved mode selected. On other STM32 devices with several ADC, this is equivalent to parameter 'ADC_TWOSAMPLINGDELAY_7CYCLES' (for fast interleaved mode). */
}ADC_MultiModeTypeDef;
#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup ADCEx_Exported_Constants ADCEx Exported Constants
* @{
*/
/** @defgroup ADCEx_injected_rank ADCEx rank into injected group
* @{
*/
#define ADC_INJECTED_RANK_1 0x00000001U
#define ADC_INJECTED_RANK_2 0x00000002U
#define ADC_INJECTED_RANK_3 0x00000003U
#define ADC_INJECTED_RANK_4 0x00000004U
/**
* @}
*/
/** @defgroup ADCEx_External_trigger_edge_Injected ADCEx external trigger enable for injected group
* @{
*/
#define ADC_EXTERNALTRIGINJECCONV_EDGE_NONE 0x00000000U
#define ADC_EXTERNALTRIGINJECCONV_EDGE_RISING ((uint32_t)ADC_CR2_JEXTTRIG)
/**
* @}
*/
/** @defgroup ADC_External_trigger_source_Regular ADC External trigger selection for regular group
* @{
*/
/*!< List of external triggers with generic trigger name, independently of */
/* ADC target, sorted by trigger name: */
/*!< External triggers of regular group for ADC1&ADC2 only */
#define ADC_EXTERNALTRIGCONV_T1_CC1 ADC1_2_EXTERNALTRIG_T1_CC1
#define ADC_EXTERNALTRIGCONV_T1_CC2 ADC1_2_EXTERNALTRIG_T1_CC2
#define ADC_EXTERNALTRIGCONV_T2_CC2 ADC1_2_EXTERNALTRIG_T2_CC2
#define ADC_EXTERNALTRIGCONV_T3_TRGO ADC1_2_EXTERNALTRIG_T3_TRGO
#define ADC_EXTERNALTRIGCONV_T4_CC4 ADC1_2_EXTERNALTRIG_T4_CC4
#define ADC_EXTERNALTRIGCONV_EXT_IT11 ADC1_2_EXTERNALTRIG_EXT_IT11
#if defined (STM32F103xE) || defined (STM32F103xG)
/*!< External triggers of regular group for ADC3 only */
#define ADC_EXTERNALTRIGCONV_T2_CC3 ADC3_EXTERNALTRIG_T2_CC3
#define ADC_EXTERNALTRIGCONV_T3_CC1 ADC3_EXTERNALTRIG_T3_CC1
#define ADC_EXTERNALTRIGCONV_T5_CC1 ADC3_EXTERNALTRIG_T5_CC1
#define ADC_EXTERNALTRIGCONV_T5_CC3 ADC3_EXTERNALTRIG_T5_CC3
#define ADC_EXTERNALTRIGCONV_T8_CC1 ADC3_EXTERNALTRIG_T8_CC1
#endif /* STM32F103xE || defined STM32F103xG */
/*!< External triggers of regular group for all ADC instances */
#define ADC_EXTERNALTRIGCONV_T1_CC3 ADC1_2_3_EXTERNALTRIG_T1_CC3
#if defined (STM32F101xE) || defined (STM32F103xE) || defined (STM32F103xG) || defined (STM32F105xC) || defined (STM32F107xC)
/*!< Note: TIM8_TRGO is available on ADC1 and ADC2 only in high-density and */
/* XL-density devices. */
/* To use it on ADC or ADC2, a remap of trigger must be done from */
/* EXTI line 11 to TIM8_TRGO with macro: */
/* __HAL_AFIO_REMAP_ADC1_ETRGREG_ENABLE() */
/* __HAL_AFIO_REMAP_ADC2_ETRGREG_ENABLE() */
/* Note for internal constant value management: If TIM8_TRGO is available, */
/* its definition is set to value for ADC1&ADC2 by default and changed to */
/* value for ADC3 by HAL ADC driver if ADC3 is selected. */
#define ADC_EXTERNALTRIGCONV_T8_TRGO ADC1_2_EXTERNALTRIG_T8_TRGO
#endif /* STM32F101xE || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
#define ADC_SOFTWARE_START ADC1_2_3_SWSTART
/**
* @}
*/
/** @defgroup ADCEx_External_trigger_source_Injected ADCEx External trigger selection for injected group
* @{
*/
/*!< List of external triggers with generic trigger name, independently of */
/* ADC target, sorted by trigger name: */
/*!< External triggers of injected group for ADC1&ADC2 only */
#define ADC_EXTERNALTRIGINJECCONV_T2_TRGO ADC1_2_EXTERNALTRIGINJEC_T2_TRGO
#define ADC_EXTERNALTRIGINJECCONV_T2_CC1 ADC1_2_EXTERNALTRIGINJEC_T2_CC1
#define ADC_EXTERNALTRIGINJECCONV_T3_CC4 ADC1_2_EXTERNALTRIGINJEC_T3_CC4
#define ADC_EXTERNALTRIGINJECCONV_T4_TRGO ADC1_2_EXTERNALTRIGINJEC_T4_TRGO
#define ADC_EXTERNALTRIGINJECCONV_EXT_IT15 ADC1_2_EXTERNALTRIGINJEC_EXT_IT15
#if defined (STM32F103xE) || defined (STM32F103xG)
/*!< External triggers of injected group for ADC3 only */
#define ADC_EXTERNALTRIGINJECCONV_T4_CC3 ADC3_EXTERNALTRIGINJEC_T4_CC3
#define ADC_EXTERNALTRIGINJECCONV_T8_CC2 ADC3_EXTERNALTRIGINJEC_T8_CC2
#define ADC_EXTERNALTRIGINJECCONV_T5_TRGO ADC3_EXTERNALTRIGINJEC_T5_TRGO
#define ADC_EXTERNALTRIGINJECCONV_T5_CC4 ADC3_EXTERNALTRIGINJEC_T5_CC4
#endif /* STM32F103xE || defined STM32F103xG */
/*!< External triggers of injected group for all ADC instances */
#define ADC_EXTERNALTRIGINJECCONV_T1_CC4 ADC1_2_3_EXTERNALTRIGINJEC_T1_CC4
#define ADC_EXTERNALTRIGINJECCONV_T1_TRGO ADC1_2_3_EXTERNALTRIGINJEC_T1_TRGO
#if defined (STM32F101xE) || defined (STM32F103xE) || defined (STM32F103xG) || defined (STM32F105xC) || defined (STM32F107xC)
/*!< Note: TIM8_CC4 is available on ADC1 and ADC2 only in high-density and */
/* XL-density devices. */
/* To use it on ADC1 or ADC2, a remap of trigger must be done from */
/* EXTI line 11 to TIM8_CC4 with macro: */
/* __HAL_AFIO_REMAP_ADC1_ETRGINJ_ENABLE() */
/* __HAL_AFIO_REMAP_ADC2_ETRGINJ_ENABLE() */
/* Note for internal constant value management: If TIM8_CC4 is available, */
/* its definition is set to value for ADC1&ADC2 by default and changed to */
/* value for ADC3 by HAL ADC driver if ADC3 is selected. */
#define ADC_EXTERNALTRIGINJECCONV_T8_CC4 ADC1_2_EXTERNALTRIGINJEC_T8_CC4
#endif /* STM32F101xE || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
#define ADC_INJECTED_SOFTWARE_START ADC1_2_3_JSWSTART
/**
* @}
*/
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
/** @defgroup ADCEx_Common_mode ADC Extended Dual ADC Mode
* @{
*/
#define ADC_MODE_INDEPENDENT 0x00000000U /*!< ADC dual mode disabled (ADC independent mode) */
#define ADC_DUALMODE_REGSIMULT_INJECSIMULT ((uint32_t)( ADC_CR1_DUALMOD_0)) /*!< ADC dual mode enabled: Combined regular simultaneous + injected simultaneous mode, on groups regular and injected */
#define ADC_DUALMODE_REGSIMULT_ALTERTRIG ((uint32_t)( ADC_CR1_DUALMOD_1 )) /*!< ADC dual mode enabled: Combined regular simultaneous + alternate trigger mode, on groups regular and injected */
#define ADC_DUALMODE_INJECSIMULT_INTERLFAST ((uint32_t)( ADC_CR1_DUALMOD_1 | ADC_CR1_DUALMOD_0)) /*!< ADC dual mode enabled: Combined injected simultaneous + fast interleaved mode, on groups regular and injected (delay between ADC sampling phases: 7 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCLES" on other STM32 devices)) */
#define ADC_DUALMODE_INJECSIMULT_INTERLSLOW ((uint32_t)( ADC_CR1_DUALMOD_2 )) /*!< ADC dual mode enabled: Combined injected simultaneous + slow Interleaved mode, on groups regular and injected (delay between ADC sampling phases: 14 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCLES" on other STM32 devices)) */
#define ADC_DUALMODE_INJECSIMULT ((uint32_t)( ADC_CR1_DUALMOD_2 | ADC_CR1_DUALMOD_0)) /*!< ADC dual mode enabled: Injected simultaneous mode, on group injected */
#define ADC_DUALMODE_REGSIMULT ((uint32_t)( ADC_CR1_DUALMOD_2 | ADC_CR1_DUALMOD_1 )) /*!< ADC dual mode enabled: Regular simultaneous mode, on group regular */
#define ADC_DUALMODE_INTERLFAST ((uint32_t)( ADC_CR1_DUALMOD_2 | ADC_CR1_DUALMOD_1 | ADC_CR1_DUALMOD_0)) /*!< ADC dual mode enabled: Fast interleaved mode, on group regular (delay between ADC sampling phases: 7 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCLES" on other STM32 devices)) */
#define ADC_DUALMODE_INTERLSLOW ((uint32_t)(ADC_CR1_DUALMOD_3 )) /*!< ADC dual mode enabled: Slow interleaved mode, on group regular (delay between ADC sampling phases: 14 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCLES" on other STM32 devices)) */
#define ADC_DUALMODE_ALTERTRIG ((uint32_t)(ADC_CR1_DUALMOD_3 | ADC_CR1_DUALMOD_0)) /*!< ADC dual mode enabled: Alternate trigger mode, on group injected */
/**
* @}
*/
#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
/**
* @}
*/
/* Private constants ---------------------------------------------------------*/
/** @addtogroup ADCEx_Private_Constants ADCEx Private Constants
* @{
*/
/** @defgroup ADCEx_Internal_HAL_driver_Ext_trig_src_Regular ADC Extended Internal HAL driver trigger selection for regular group
* @{
*/
/* List of external triggers of regular group for ADC1, ADC2, ADC3 (if ADC */
/* instance is available on the selected device). */
/* (used internally by HAL driver. To not use into HAL structure parameters) */
/* External triggers of regular group for ADC1&ADC2 (if ADCx available) */
#define ADC1_2_EXTERNALTRIG_T1_CC1 0x00000000U
#define ADC1_2_EXTERNALTRIG_T1_CC2 ((uint32_t)( ADC_CR2_EXTSEL_0))
#define ADC1_2_EXTERNALTRIG_T2_CC2 ((uint32_t)( ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
#define ADC1_2_EXTERNALTRIG_T3_TRGO ((uint32_t)(ADC_CR2_EXTSEL_2 ))
#define ADC1_2_EXTERNALTRIG_T4_CC4 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0))
#define ADC1_2_EXTERNALTRIG_EXT_IT11 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 ))
#if defined (STM32F101xE) || defined (STM32F103xE) || defined (STM32F103xG)
/* Note: TIM8_TRGO is available on ADC1 and ADC2 only in high-density and */
/* XL-density devices. */
#define ADC1_2_EXTERNALTRIG_T8_TRGO ADC1_2_EXTERNALTRIG_EXT_IT11
#endif
#if defined (STM32F103xE) || defined (STM32F103xG)
/* External triggers of regular group for ADC3 */
#define ADC3_EXTERNALTRIG_T3_CC1 ADC1_2_EXTERNALTRIG_T1_CC1
#define ADC3_EXTERNALTRIG_T2_CC3 ADC1_2_EXTERNALTRIG_T1_CC2
#define ADC3_EXTERNALTRIG_T8_CC1 ADC1_2_EXTERNALTRIG_T2_CC2
#define ADC3_EXTERNALTRIG_T8_TRGO ADC1_2_EXTERNALTRIG_T3_TRGO
#define ADC3_EXTERNALTRIG_T5_CC1 ADC1_2_EXTERNALTRIG_T4_CC4
#define ADC3_EXTERNALTRIG_T5_CC3 ADC1_2_EXTERNALTRIG_EXT_IT11
#endif
/* External triggers of regular group for ADC1&ADC2&ADC3 (if ADCx available) */
#define ADC1_2_3_EXTERNALTRIG_T1_CC3 ((uint32_t)( ADC_CR2_EXTSEL_1 ))
#define ADC1_2_3_SWSTART ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
/**
* @}
*/
/** @defgroup ADCEx_Internal_HAL_driver_Ext_trig_src_Injected ADC Extended Internal HAL driver trigger selection for injected group
* @{
*/
/* List of external triggers of injected group for ADC1, ADC2, ADC3 (if ADC */
/* instance is available on the selected device). */
/* (used internally by HAL driver. To not use into HAL structure parameters) */
/* External triggers of injected group for ADC1&ADC2 (if ADCx available) */
#define ADC1_2_EXTERNALTRIGINJEC_T2_TRGO ((uint32_t)( ADC_CR2_JEXTSEL_1 ))
#define ADC1_2_EXTERNALTRIGINJEC_T2_CC1 ((uint32_t)( ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
#define ADC1_2_EXTERNALTRIGINJEC_T3_CC4 ((uint32_t)(ADC_CR2_JEXTSEL_2 ))
#define ADC1_2_EXTERNALTRIGINJEC_T4_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_0))
#define ADC1_2_EXTERNALTRIGINJEC_EXT_IT15 ((uint32_t)(ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 ))
#if defined (STM32F101xE) || defined (STM32F103xE) || defined (STM32F103xG)
/* Note: TIM8_CC4 is available on ADC1 and ADC2 only in high-density and */
/* XL-density devices. */
#define ADC1_2_EXTERNALTRIGINJEC_T8_CC4 ADC1_2_EXTERNALTRIGINJEC_EXT_IT15
#endif
#if defined (STM32F103xE) || defined (STM32F103xG)
/* External triggers of injected group for ADC3 */
#define ADC3_EXTERNALTRIGINJEC_T4_CC3 ADC1_2_EXTERNALTRIGINJEC_T2_TRGO
#define ADC3_EXTERNALTRIGINJEC_T8_CC2 ADC1_2_EXTERNALTRIGINJEC_T2_CC1
#define ADC3_EXTERNALTRIGINJEC_T8_CC4 ADC1_2_EXTERNALTRIGINJEC_T3_CC4
#define ADC3_EXTERNALTRIGINJEC_T5_TRGO ADC1_2_EXTERNALTRIGINJEC_T4_TRGO
#define ADC3_EXTERNALTRIGINJEC_T5_CC4 ADC1_2_EXTERNALTRIGINJEC_EXT_IT15
#endif /* STM32F103xE || defined STM32F103xG */
/* External triggers of injected group for ADC1&ADC2&ADC3 (if ADCx available) */
#define ADC1_2_3_EXTERNALTRIGINJEC_T1_TRGO 0x00000000U
#define ADC1_2_3_EXTERNALTRIGINJEC_T1_CC4 ((uint32_t)( ADC_CR2_JEXTSEL_0))
#define ADC1_2_3_JSWSTART ((uint32_t)(ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
/**
* @}
*/
/**
* @}
*/
/* Exported macro ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/** @defgroup ADCEx_Private_Macro ADCEx Private Macro
* @{
*/
/* Macro reserved for internal HAL driver usage, not intended to be used in */
/* code of final user. */
/**
* @brief For devices with 3 ADCs: Defines the external trigger source
* for regular group according to ADC into common group ADC1&ADC2 or
* ADC3 (some triggers with same source have different value to
* be programmed into ADC EXTSEL bits of CR2 register).
* For devices with 2 ADCs or less: this macro makes no change.
* @param __HANDLE__: ADC handle
* @param __EXT_TRIG_CONV__: External trigger selected for regular group.
* @retval External trigger to be programmed into EXTSEL bits of CR2 register
*/
#if defined (STM32F103xE) || defined (STM32F103xG)
#define ADC_CFGR_EXTSEL(__HANDLE__, __EXT_TRIG_CONV__) \
(( (((__HANDLE__)->Instance) == ADC3) \
)? \
( ( (__EXT_TRIG_CONV__) == ADC_EXTERNALTRIGCONV_T8_TRGO \
)? \
(ADC3_EXTERNALTRIG_T8_TRGO) \
: \
(__EXT_TRIG_CONV__) \
) \
: \
(__EXT_TRIG_CONV__) \
)
#else
#define ADC_CFGR_EXTSEL(__HANDLE__, __EXT_TRIG_CONV__) \
(__EXT_TRIG_CONV__)
#endif /* STM32F103xE || STM32F103xG */
/**
* @brief For devices with 3 ADCs: Defines the external trigger source
* for injected group according to ADC into common group ADC1&ADC2 or
* ADC3 (some triggers with same source have different value to
* be programmed into ADC JEXTSEL bits of CR2 register).
* For devices with 2 ADCs or less: this macro makes no change.
* @param __HANDLE__: ADC handle
* @param __EXT_TRIG_INJECTCONV__: External trigger selected for injected group.
* @retval External trigger to be programmed into JEXTSEL bits of CR2 register
*/
#if defined (STM32F103xE) || defined (STM32F103xG)
#define ADC_CFGR_JEXTSEL(__HANDLE__, __EXT_TRIG_INJECTCONV__) \
(( (((__HANDLE__)->Instance) == ADC3) \
)? \
( ( (__EXT_TRIG_INJECTCONV__) == ADC_EXTERNALTRIGINJECCONV_T8_CC4 \
)? \
(ADC3_EXTERNALTRIGINJEC_T8_CC4) \
: \
(__EXT_TRIG_INJECTCONV__) \
) \
: \
(__EXT_TRIG_INJECTCONV__) \
)
#else
#define ADC_CFGR_JEXTSEL(__HANDLE__, __EXT_TRIG_INJECTCONV__) \
(__EXT_TRIG_INJECTCONV__)
#endif /* STM32F103xE || STM32F103xG */
/**
* @brief Verification if multimode is enabled for the selected ADC (multimode ADC master or ADC slave) (applicable for devices with several ADCs)
* @param __HANDLE__: ADC handle
* @retval Multimode state: RESET if multimode is disabled, other value if multimode is enabled
*/
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
#define ADC_MULTIMODE_IS_ENABLE(__HANDLE__) \
(( (((__HANDLE__)->Instance) == ADC1) || (((__HANDLE__)->Instance) == ADC2) \
)? \
(ADC1->CR1 & ADC_CR1_DUALMOD) \
: \
(RESET) \
)
#else
#define ADC_MULTIMODE_IS_ENABLE(__HANDLE__) \
(RESET)
#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
/**
* @brief Verification of condition for ADC start conversion: ADC must be in non-multimode, or multimode with handle of ADC master (applicable for devices with several ADCs)
* @param __HANDLE__: ADC handle
* @retval None
*/
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
#define ADC_NONMULTIMODE_OR_MULTIMODEMASTER(__HANDLE__) \
(( (((__HANDLE__)->Instance) == ADC2) \
)? \
((ADC1->CR1 & ADC_CR1_DUALMOD) == RESET) \
: \
(!RESET) \
)
#else
#define ADC_NONMULTIMODE_OR_MULTIMODEMASTER(__HANDLE__) \
(!RESET)
#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
/**
* @brief Check ADC multimode setting: In case of multimode, check whether ADC master of the selected ADC has feature auto-injection enabled (applicable for devices with several ADCs)
* @param __HANDLE__: ADC handle
* @retval None
*/
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
#define ADC_MULTIMODE_AUTO_INJECTED(__HANDLE__) \
(( (((__HANDLE__)->Instance) == ADC1) || (((__HANDLE__)->Instance) == ADC2) \
)? \
(ADC1->CR1 & ADC_CR1_JAUTO) \
: \
(RESET) \
)
#else
#define ADC_MULTIMODE_AUTO_INJECTED(__HANDLE__) \
(RESET)
#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
/**
* @brief Set handle of the other ADC sharing the common multimode settings
* @param __HANDLE__: ADC handle
* @param __HANDLE_OTHER_ADC__: other ADC handle
* @retval None
*/
#define ADC_COMMON_ADC_OTHER(__HANDLE__, __HANDLE_OTHER_ADC__) \
((__HANDLE_OTHER_ADC__)->Instance = ADC2)
/**
* @brief Set handle of the ADC slave associated to the ADC master
* On STM32F1 devices, ADC slave is always ADC2 (this can be different
* on other STM32 devices)
* @param __HANDLE_MASTER__: ADC master handle
* @param __HANDLE_SLAVE__: ADC slave handle
* @retval None
*/
#define ADC_MULTI_SLAVE(__HANDLE_MASTER__, __HANDLE_SLAVE__) \
((__HANDLE_SLAVE__)->Instance = ADC2)
#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
#define IS_ADC_INJECTED_RANK(CHANNEL) (((CHANNEL) == ADC_INJECTED_RANK_1) || \
((CHANNEL) == ADC_INJECTED_RANK_2) || \
((CHANNEL) == ADC_INJECTED_RANK_3) || \
((CHANNEL) == ADC_INJECTED_RANK_4))
#define IS_ADC_EXTTRIGINJEC_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_NONE) || \
((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_RISING))
/** @defgroup ADCEx_injected_nb_conv_verification ADCEx injected nb conv verification
* @{
*/
#define IS_ADC_INJECTED_NB_CONV(LENGTH) (((LENGTH) >= 1U) && ((LENGTH) <= 4U))
/**
* @}
*/
#if defined (STM32F100xB) || defined (STM32F100xE) || defined (STM32F101x6) || defined (STM32F101xB) || defined (STM32F102x6) || defined (STM32F102xB) || defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC)
#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_EXT_IT11) || \
((REGTRIG) == ADC_SOFTWARE_START))
#endif
#if defined (STM32F101xE)
#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_EXT_IT11) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_TRGO) || \
((REGTRIG) == ADC_SOFTWARE_START))
#endif
#if defined (STM32F101xG)
#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_EXT_IT11) || \
((REGTRIG) == ADC_SOFTWARE_START))
#endif
#if defined (STM32F103xE) || defined (STM32F103xG)
#define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_EXT_IT11) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_CC1) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC3) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_CC1) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC1) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC3) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC3) || \
((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_TRGO) || \
((REGTRIG) == ADC_SOFTWARE_START))
#endif
#if defined (STM32F100xB) || defined (STM32F100xE) || defined (STM32F101x6) || defined (STM32F101xB) || defined (STM32F102x6) || defined (STM32F102xB) || defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC)
#define IS_ADC_EXTTRIGINJEC(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_CC1) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T3_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_EXT_IT15) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO) || \
((REGTRIG) == ADC_INJECTED_SOFTWARE_START))
#endif
#if defined (STM32F101xE)
#define IS_ADC_EXTTRIGINJEC(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_CC1) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T3_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_EXT_IT15) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T8_CC4) || \
((REGTRIG) == ADC_INJECTED_SOFTWARE_START))
#endif
#if defined (STM32F101xG)
#define IS_ADC_EXTTRIGINJEC(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_CC1) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T3_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_EXT_IT15) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO) || \
((REGTRIG) == ADC_INJECTED_SOFTWARE_START))
#endif
#if defined (STM32F103xE) || defined (STM32F103xG)
#define IS_ADC_EXTTRIGINJEC(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_CC1) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T3_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T5_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_EXT_IT15) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_CC3) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T8_CC2) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T5_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T5_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_CC4) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO) || \
((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T8_CC4) || \
((REGTRIG) == ADC_INJECTED_SOFTWARE_START))
#endif
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
#define IS_ADC_MODE(MODE) (((MODE) == ADC_MODE_INDEPENDENT) || \
((MODE) == ADC_DUALMODE_REGSIMULT_INJECSIMULT) || \
((MODE) == ADC_DUALMODE_REGSIMULT_ALTERTRIG) || \
((MODE) == ADC_DUALMODE_INJECSIMULT_INTERLFAST) || \
((MODE) == ADC_DUALMODE_INJECSIMULT_INTERLSLOW) || \
((MODE) == ADC_DUALMODE_INJECSIMULT) || \
((MODE) == ADC_DUALMODE_REGSIMULT) || \
((MODE) == ADC_DUALMODE_INTERLFAST) || \
((MODE) == ADC_DUALMODE_INTERLSLOW) || \
((MODE) == ADC_DUALMODE_ALTERTRIG) )
#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup ADCEx_Exported_Functions
* @{
*/
/* IO operation functions *****************************************************/
/** @addtogroup ADCEx_Exported_Functions_Group1
* @{
*/
/* ADC calibration */
HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc);
/* Blocking mode: Polling */
HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc);
HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc);
HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
/* Non-blocking mode: Interruption */
HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc);
HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc);
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
/* ADC multimode */
HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length);
HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc);
#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
/* ADC retrieve conversion value intended to be used with polling or interruption */
uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank);
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef *hadc);
#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
/* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption) */
void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc);
/**
* @}
*/
/* Peripheral Control functions ***********************************************/
/** @addtogroup ADCEx_Exported_Functions_Group2
* @{
*/
HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc,ADC_InjectionConfTypeDef* sConfigInjected);
#if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_MultiModeTypeDef *multimode);
#endif /* defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __STM32F1xx_HAL_ADC_EX_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,261 @@
/**
******************************************************************************
* @file stm32f1xx_hal_tim_ex.h
* @author MCD Application Team
* @brief Header file of TIM HAL Extended module.
******************************************************************************
* @attention
*
* Copyright (c) 2016 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32F1xx_HAL_TIM_EX_H
#define STM32F1xx_HAL_TIM_EX_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal_def.h"
/** @addtogroup STM32F1xx_HAL_Driver
* @{
*/
/** @addtogroup TIMEx
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup TIMEx_Exported_Types TIM Extended Exported Types
* @{
*/
/**
* @brief TIM Hall sensor Configuration Structure definition
*/
typedef struct
{
uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal.
This parameter can be a value of @ref TIM_Input_Capture_Polarity */
uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler.
This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
uint32_t IC1Filter; /*!< Specifies the input capture filter.
This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
uint32_t Commutation_Delay; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
} TIM_HallSensor_InitTypeDef;
/**
* @}
*/
/* End of exported types -----------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants
* @{
*/
/** @defgroup TIMEx_Remap TIM Extended Remapping
* @{
*/
/**
* @}
*/
/**
* @}
*/
/* End of exported constants -------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros
* @{
*/
/**
* @}
*/
/* End of exported macro -----------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/** @defgroup TIMEx_Private_Macros TIM Extended Private Macros
* @{
*/
/**
* @}
*/
/* End of private macro ------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions
* @{
*/
/** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
* @brief Timer Hall Sensor functions
* @{
*/
/* Timer Hall Sensor functions **********************************************/
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, const TIM_HallSensor_InitTypeDef *sConfig);
HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim);
void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim);
void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim);
/* Blocking mode: Polling */
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim);
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim);
/* Non-Blocking mode: Interrupt */
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim);
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim);
/* Non-Blocking mode: DMA */
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim);
/**
* @}
*/
/** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
* @brief Timer Complementary Output Compare functions
* @{
*/
/* Timer Complementary Output Compare functions *****************************/
/* Blocking mode: Polling */
HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
/* Non-Blocking mode: Interrupt */
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
/* Non-Blocking mode: DMA */
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
uint16_t Length);
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
/**
* @}
*/
/** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions
* @brief Timer Complementary PWM functions
* @{
*/
/* Timer Complementary PWM functions ****************************************/
/* Blocking mode: Polling */
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
/* Non-Blocking mode: Interrupt */
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
/* Non-Blocking mode: DMA */
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
uint16_t Length);
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
/**
* @}
*/
/** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions
* @brief Timer Complementary One Pulse functions
* @{
*/
/* Timer Complementary One Pulse functions **********************************/
/* Blocking mode: Polling */
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
/* Non-Blocking mode: Interrupt */
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
/**
* @}
*/
/** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
* @brief Peripheral Control functions
* @{
*/
/* Extended Control functions ************************************************/
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger,
uint32_t CommutationSource);
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger,
uint32_t CommutationSource);
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger,
uint32_t CommutationSource);
HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
const TIM_MasterConfigTypeDef *sMasterConfig);
HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
const TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig);
HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap);
/**
* @}
*/
/** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
* @brief Extended Callbacks functions
* @{
*/
/* Extended Callback **********************************************************/
void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim);
void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim);
void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim);
/**
* @}
*/
/** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
* @brief Extended Peripheral State functions
* @{
*/
/* Extended Peripheral State functions ***************************************/
HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(const TIM_HandleTypeDef *htim);
HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(const TIM_HandleTypeDef *htim, uint32_t ChannelN);
/**
* @}
*/
/**
* @}
*/
/* End of exported functions -------------------------------------------------*/
/* Private functions----------------------------------------------------------*/
/** @addtogroup TIMEx_Private_Functions TIM Extended Private Functions
* @{
*/
void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma);
void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma);
/**
* @}
*/
/* End of private functions --------------------------------------------------*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32F1xx_HAL_TIM_EX_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -190,7 +190,7 @@
<hadIRAM2>0</hadIRAM2> <hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2> <hadIROM2>0</hadIROM2>
<StupSel>8</StupSel> <StupSel>8</StupSel>
<useUlib>1</useUlib> <useUlib>0</useUlib>
<EndSel>0</EndSel> <EndSel>0</EndSel>
<uLtcg>0</uLtcg> <uLtcg>0</uLtcg>
<nSecure>0</nSecure> <nSecure>0</nSecure>
@@ -340,7 +340,7 @@
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define>USE_HAL_DRIVER,STM32F103xB</Define> <Define>USE_HAL_DRIVER,STM32F103xB</Define>
<Undefine></Undefine> <Undefine></Undefine>
<IncludePath>../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;../Drivers/BSP/MultiButton;..\Drivers\BSP\LCD</IncludePath> <IncludePath>../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;../Drivers/BSP/MultiButton;../Drivers/BSP/LCD</IncludePath>
</VariousControls> </VariousControls>
</Cads> </Cads>
<Aads> <Aads>
@@ -404,6 +404,62 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>../Core/Src/gpio.c</FilePath> <FilePath>../Core/Src/gpio.c</FilePath>
</File> </File>
<File>
<FileName>adc.c</FileName>
<FileType>1</FileType>
<FilePath>../Core/Src/adc.c</FilePath>
<FileOption>
<CommonProperty>
<UseCPPCompiler>2</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>1</IncludeInBuild>
<AlwaysBuild>2</AlwaysBuild>
<GenerateAssemblyFile>2</GenerateAssemblyFile>
<AssembleAssemblyFile>2</AssembleAssemblyFile>
<PublicsOnly>2</PublicsOnly>
<StopOnExitCode>11</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg>
</CommonProperty>
<FileArmAds>
<Cads>
<interw>2</interw>
<Optim>0</Optim>
<oTime>2</oTime>
<SplitLS>2</SplitLS>
<OneElfS>2</OneElfS>
<Strict>2</Strict>
<EnumInt>2</EnumInt>
<PlainCh>2</PlainCh>
<Ropi>2</Ropi>
<Rwpi>2</Rwpi>
<wLevel>0</wLevel>
<uThumb>2</uThumb>
<uSurpInc>2</uSurpInc>
<uC99>2</uC99>
<uGnu>2</uGnu>
<useXO>2</useXO>
<v6Lang>0</v6Lang>
<v6LangP>0</v6LangP>
<vShortEn>2</vShortEn>
<vShortWch>2</vShortWch>
<v6Lto>2</v6Lto>
<v6WtE>2</v6WtE>
<v6Rtti>2</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Cads>
</FileArmAds>
</FileOption>
</File>
<File> <File>
<FileName>dma.c</FileName> <FileName>dma.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@@ -516,6 +572,62 @@
</FileArmAds> </FileArmAds>
</FileOption> </FileOption>
</File> </File>
<File>
<FileName>tim.c</FileName>
<FileType>1</FileType>
<FilePath>../Core/Src/tim.c</FilePath>
<FileOption>
<CommonProperty>
<UseCPPCompiler>2</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>1</IncludeInBuild>
<AlwaysBuild>2</AlwaysBuild>
<GenerateAssemblyFile>2</GenerateAssemblyFile>
<AssembleAssemblyFile>2</AssembleAssemblyFile>
<PublicsOnly>2</PublicsOnly>
<StopOnExitCode>11</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg>
</CommonProperty>
<FileArmAds>
<Cads>
<interw>2</interw>
<Optim>0</Optim>
<oTime>2</oTime>
<SplitLS>2</SplitLS>
<OneElfS>2</OneElfS>
<Strict>2</Strict>
<EnumInt>2</EnumInt>
<PlainCh>2</PlainCh>
<Ropi>2</Ropi>
<Rwpi>2</Rwpi>
<wLevel>0</wLevel>
<uThumb>2</uThumb>
<uSurpInc>2</uSurpInc>
<uC99>2</uC99>
<uGnu>2</uGnu>
<useXO>2</useXO>
<v6Lang>0</v6Lang>
<v6LangP>0</v6LangP>
<vShortEn>2</vShortEn>
<vShortWch>2</vShortWch>
<v6Lto>2</v6Lto>
<v6WtE>2</v6WtE>
<v6Rtti>2</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Cads>
</FileArmAds>
</FileOption>
</File>
<File> <File>
<FileName>usart.c</FileName> <FileName>usart.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@@ -542,9 +654,65 @@
<FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c</FilePath> <FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c</FilePath>
</File> </File>
<File> <File>
<FileName>stm32f1xx_hal_spi.c</FileName> <FileName>stm32f1xx_hal_adc.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c</FilePath> <FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c</FilePath>
<FileOption>
<CommonProperty>
<UseCPPCompiler>2</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>1</IncludeInBuild>
<AlwaysBuild>2</AlwaysBuild>
<GenerateAssemblyFile>2</GenerateAssemblyFile>
<AssembleAssemblyFile>2</AssembleAssemblyFile>
<PublicsOnly>2</PublicsOnly>
<StopOnExitCode>11</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg>
</CommonProperty>
<FileArmAds>
<Cads>
<interw>2</interw>
<Optim>0</Optim>
<oTime>2</oTime>
<SplitLS>2</SplitLS>
<OneElfS>2</OneElfS>
<Strict>2</Strict>
<EnumInt>2</EnumInt>
<PlainCh>2</PlainCh>
<Ropi>2</Ropi>
<Rwpi>2</Rwpi>
<wLevel>0</wLevel>
<uThumb>2</uThumb>
<uSurpInc>2</uSurpInc>
<uC99>2</uC99>
<uGnu>2</uGnu>
<useXO>2</useXO>
<v6Lang>0</v6Lang>
<v6LangP>0</v6LangP>
<vShortEn>2</vShortEn>
<vShortWch>2</vShortWch>
<v6Lto>2</v6Lto>
<v6WtE>2</v6WtE>
<v6Rtti>2</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Cads>
</FileArmAds>
</FileOption>
</File>
<File>
<FileName>stm32f1xx_hal_adc_ex.c</FileName>
<FileType>1</FileType>
<FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c</FilePath>
<FileOption> <FileOption>
<CommonProperty> <CommonProperty>
<UseCPPCompiler>2</UseCPPCompiler> <UseCPPCompiler>2</UseCPPCompiler>
@@ -647,6 +815,174 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c</FilePath> <FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c</FilePath>
</File> </File>
<File>
<FileName>stm32f1xx_hal_spi.c</FileName>
<FileType>1</FileType>
<FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c</FilePath>
<FileOption>
<CommonProperty>
<UseCPPCompiler>2</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>1</IncludeInBuild>
<AlwaysBuild>2</AlwaysBuild>
<GenerateAssemblyFile>2</GenerateAssemblyFile>
<AssembleAssemblyFile>2</AssembleAssemblyFile>
<PublicsOnly>2</PublicsOnly>
<StopOnExitCode>11</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg>
</CommonProperty>
<FileArmAds>
<Cads>
<interw>2</interw>
<Optim>0</Optim>
<oTime>2</oTime>
<SplitLS>2</SplitLS>
<OneElfS>2</OneElfS>
<Strict>2</Strict>
<EnumInt>2</EnumInt>
<PlainCh>2</PlainCh>
<Ropi>2</Ropi>
<Rwpi>2</Rwpi>
<wLevel>0</wLevel>
<uThumb>2</uThumb>
<uSurpInc>2</uSurpInc>
<uC99>2</uC99>
<uGnu>2</uGnu>
<useXO>2</useXO>
<v6Lang>0</v6Lang>
<v6LangP>0</v6LangP>
<vShortEn>2</vShortEn>
<vShortWch>2</vShortWch>
<v6Lto>2</v6Lto>
<v6WtE>2</v6WtE>
<v6Rtti>2</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Cads>
</FileArmAds>
</FileOption>
</File>
<File>
<FileName>stm32f1xx_hal_tim.c</FileName>
<FileType>1</FileType>
<FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c</FilePath>
<FileOption>
<CommonProperty>
<UseCPPCompiler>2</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>1</IncludeInBuild>
<AlwaysBuild>2</AlwaysBuild>
<GenerateAssemblyFile>2</GenerateAssemblyFile>
<AssembleAssemblyFile>2</AssembleAssemblyFile>
<PublicsOnly>2</PublicsOnly>
<StopOnExitCode>11</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg>
</CommonProperty>
<FileArmAds>
<Cads>
<interw>2</interw>
<Optim>0</Optim>
<oTime>2</oTime>
<SplitLS>2</SplitLS>
<OneElfS>2</OneElfS>
<Strict>2</Strict>
<EnumInt>2</EnumInt>
<PlainCh>2</PlainCh>
<Ropi>2</Ropi>
<Rwpi>2</Rwpi>
<wLevel>0</wLevel>
<uThumb>2</uThumb>
<uSurpInc>2</uSurpInc>
<uC99>2</uC99>
<uGnu>2</uGnu>
<useXO>2</useXO>
<v6Lang>0</v6Lang>
<v6LangP>0</v6LangP>
<vShortEn>2</vShortEn>
<vShortWch>2</vShortWch>
<v6Lto>2</v6Lto>
<v6WtE>2</v6WtE>
<v6Rtti>2</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Cads>
</FileArmAds>
</FileOption>
</File>
<File>
<FileName>stm32f1xx_hal_tim_ex.c</FileName>
<FileType>1</FileType>
<FilePath>../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c</FilePath>
<FileOption>
<CommonProperty>
<UseCPPCompiler>2</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>1</IncludeInBuild>
<AlwaysBuild>2</AlwaysBuild>
<GenerateAssemblyFile>2</GenerateAssemblyFile>
<AssembleAssemblyFile>2</AssembleAssemblyFile>
<PublicsOnly>2</PublicsOnly>
<StopOnExitCode>11</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg>
</CommonProperty>
<FileArmAds>
<Cads>
<interw>2</interw>
<Optim>0</Optim>
<oTime>2</oTime>
<SplitLS>2</SplitLS>
<OneElfS>2</OneElfS>
<Strict>2</Strict>
<EnumInt>2</EnumInt>
<PlainCh>2</PlainCh>
<Ropi>2</Ropi>
<Rwpi>2</Rwpi>
<wLevel>0</wLevel>
<uThumb>2</uThumb>
<uSurpInc>2</uSurpInc>
<uC99>2</uC99>
<uGnu>2</uGnu>
<useXO>2</useXO>
<v6Lang>0</v6Lang>
<v6LangP>0</v6LangP>
<vShortEn>2</vShortEn>
<vShortWch>2</vShortWch>
<v6Lto>2</v6Lto>
<v6WtE>2</v6WtE>
<v6Rtti>2</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Cads>
</FileArmAds>
</FileOption>
</File>
<File> <File>
<FileName>stm32f1xx_hal_uart.c</FileName> <FileName>stm32f1xx_hal_uart.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@@ -672,6 +1008,16 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\Drivers\BSP\LCD\lcd_data.c</FilePath> <FilePath>..\Drivers\BSP\LCD\lcd_data.c</FilePath>
</File> </File>
<File>
<FileName>hz16_data.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\BSP\LCD\hz16_data.c</FilePath>
</File>
<File>
<FileName>lcd.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\BSP\LCD\lcd.c</FilePath>
</File>
<File> <File>
<FileName>st7735s.c</FileName> <FileName>st7735s.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>

View File

@@ -2,13 +2,16 @@
"stm32f103c8t6\startup_stm32f103xb.o" "stm32f103c8t6\startup_stm32f103xb.o"
"stm32f103c8t6\main.o" "stm32f103c8t6\main.o"
"stm32f103c8t6\gpio.o" "stm32f103c8t6\gpio.o"
"stm32f103c8t6\adc.o"
"stm32f103c8t6\dma.o" "stm32f103c8t6\dma.o"
"stm32f103c8t6\spi.o" "stm32f103c8t6\spi.o"
"stm32f103c8t6\tim.o"
"stm32f103c8t6\usart.o" "stm32f103c8t6\usart.o"
"stm32f103c8t6\stm32f1xx_it.o" "stm32f103c8t6\stm32f1xx_it.o"
"stm32f103c8t6\stm32f1xx_hal_msp.o" "stm32f103c8t6\stm32f1xx_hal_msp.o"
"stm32f103c8t6\stm32f1xx_hal_gpio_ex.o" "stm32f103c8t6\stm32f1xx_hal_gpio_ex.o"
"stm32f103c8t6\stm32f1xx_hal_spi.o" "stm32f103c8t6\stm32f1xx_hal_adc.o"
"stm32f103c8t6\stm32f1xx_hal_adc_ex.o"
"stm32f103c8t6\stm32f1xx_hal.o" "stm32f103c8t6\stm32f1xx_hal.o"
"stm32f103c8t6\stm32f1xx_hal_rcc.o" "stm32f103c8t6\stm32f1xx_hal_rcc.o"
"stm32f103c8t6\stm32f1xx_hal_rcc_ex.o" "stm32f103c8t6\stm32f1xx_hal_rcc_ex.o"
@@ -19,13 +22,18 @@
"stm32f103c8t6\stm32f1xx_hal_flash.o" "stm32f103c8t6\stm32f1xx_hal_flash.o"
"stm32f103c8t6\stm32f1xx_hal_flash_ex.o" "stm32f103c8t6\stm32f1xx_hal_flash_ex.o"
"stm32f103c8t6\stm32f1xx_hal_exti.o" "stm32f103c8t6\stm32f1xx_hal_exti.o"
"stm32f103c8t6\stm32f1xx_hal_spi.o"
"stm32f103c8t6\stm32f1xx_hal_tim.o"
"stm32f103c8t6\stm32f1xx_hal_tim_ex.o"
"stm32f103c8t6\stm32f1xx_hal_uart.o" "stm32f103c8t6\stm32f1xx_hal_uart.o"
"stm32f103c8t6\system_stm32f1xx.o" "stm32f103c8t6\system_stm32f1xx.o"
"stm32f103c8t6\lcd_data.o" "stm32f103c8t6\lcd_data.o"
"stm32f103c8t6\hz16_data.o"
"stm32f103c8t6\lcd.o"
"stm32f103c8t6\st7735s_1.o" "stm32f103c8t6\st7735s_1.o"
"stm32f103c8t6\button_driver_1.o" "stm32f103c8t6\button_driver_1.o"
"stm32f103c8t6\multi_button_1.o" "stm32f103c8t6\multi_button_1.o"
--library_type=microlib --strict --scatter "STM32F103C8T6\STM32F103C8T6.sct" --strict --scatter "STM32F103C8T6\STM32F103C8T6.sct"
--summary_stderr --info summarysizes --map --load_addr_map_info --xref --callgraph --symbols --summary_stderr --info summarysizes --map --load_addr_map_info --xref --callgraph --symbols
--info sizes --info totals --info unused --info veneers --info sizes --info totals --info unused --info veneers
--list "STM32F103C8T6.map" -o STM32F103C8T6\STM32F103C8T6.axf --list "STM32F103C8T6.map" -o STM32F103C8T6\STM32F103C8T6.axf

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,29 @@
#MicroXplorer Configuration settings - do not modify #MicroXplorer Configuration settings - do not modify
ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_0
ADC1.Channel-1\#ChannelInjectedConversion=ADC_CHANNEL_0
ADC1.Channel-2\#ChannelInjectedConversion=ADC_CHANNEL_1
ADC1.Channel-3\#ChannelInjectedConversion=ADC_CHANNEL_2
ADC1.Channel-4\#ChannelInjectedConversion=ADC_CHANNEL_3
ADC1.EnableInjectedConversion=ENABLE
ADC1.ExternalTrigInjecConv=ADC_EXTERNALTRIGINJECCONV_T3_CC4
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,master,EnableInjectedConversion,InjectedRank-1\#ChannelInjectedConversion,Channel-1\#ChannelInjectedConversion,SamplingTime-1\#ChannelInjectedConversion,InjectedOffset-1\#ChannelInjectedConversion,InjectedRank-2\#ChannelInjectedConversion,Channel-2\#ChannelInjectedConversion,SamplingTime-2\#ChannelInjectedConversion,InjectedOffset-2\#ChannelInjectedConversion,InjectedRank-3\#ChannelInjectedConversion,Channel-3\#ChannelInjectedConversion,SamplingTime-3\#ChannelInjectedConversion,InjectedOffset-3\#ChannelInjectedConversion,InjectedRank-4\#ChannelInjectedConversion,Channel-4\#ChannelInjectedConversion,SamplingTime-4\#ChannelInjectedConversion,InjectedOffset-4\#ChannelInjectedConversion,InjNumberOfConversion,ExternalTrigInjecConv
ADC1.InjNumberOfConversion=4
ADC1.InjectedOffset-1\#ChannelInjectedConversion=0
ADC1.InjectedOffset-2\#ChannelInjectedConversion=0
ADC1.InjectedOffset-3\#ChannelInjectedConversion=0
ADC1.InjectedOffset-4\#ChannelInjectedConversion=0
ADC1.InjectedRank-1\#ChannelInjectedConversion=1
ADC1.InjectedRank-2\#ChannelInjectedConversion=2
ADC1.InjectedRank-3\#ChannelInjectedConversion=3
ADC1.InjectedRank-4\#ChannelInjectedConversion=4
ADC1.NbrOfConversionFlag=1
ADC1.Rank-0\#ChannelRegularConversion=1
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_1CYCLE_5
ADC1.SamplingTime-1\#ChannelInjectedConversion=ADC_SAMPLETIME_41CYCLES_5
ADC1.SamplingTime-2\#ChannelInjectedConversion=ADC_SAMPLETIME_41CYCLES_5
ADC1.SamplingTime-3\#ChannelInjectedConversion=ADC_SAMPLETIME_41CYCLES_5
ADC1.SamplingTime-4\#ChannelInjectedConversion=ADC_SAMPLETIME_41CYCLES_5
ADC1.master=1
CAD.formats= CAD.formats=
CAD.pinconfig= CAD.pinconfig=
CAD.provider= CAD.provider=
@@ -18,34 +43,48 @@ GPIO.groupedBy=Group By Peripherals
KeepUserPlacement=false KeepUserPlacement=false
Mcu.CPN=STM32F103C8T6 Mcu.CPN=STM32F103C8T6
Mcu.Family=STM32F1 Mcu.Family=STM32F1
Mcu.IP0=DMA Mcu.IP0=ADC1
Mcu.IP1=NVIC Mcu.IP1=DMA
Mcu.IP2=RCC Mcu.IP2=NVIC
Mcu.IP3=SPI2 Mcu.IP3=RCC
Mcu.IP4=SYS Mcu.IP4=SPI2
Mcu.IP5=USART1 Mcu.IP5=SYS
Mcu.IPNb=6 Mcu.IP6=TIM3
Mcu.IP7=TIM4
Mcu.IP8=USART1
Mcu.IPNb=9
Mcu.Name=STM32F103C(8-B)Tx Mcu.Name=STM32F103C(8-B)Tx
Mcu.Package=LQFP48 Mcu.Package=LQFP48
Mcu.Pin0=PC13-TAMPER-RTC Mcu.Pin0=PC13-TAMPER-RTC
Mcu.Pin1=PC14-OSC32_IN Mcu.Pin1=PC14-OSC32_IN
Mcu.Pin10=PA9 Mcu.Pin10=PB11
Mcu.Pin11=PA10 Mcu.Pin11=PB12
Mcu.Pin12=PA13 Mcu.Pin12=PB13
Mcu.Pin13=PA14 Mcu.Pin13=PB15
Mcu.Pin14=PB3 Mcu.Pin14=PA9
Mcu.Pin15=PB4 Mcu.Pin15=PA10
Mcu.Pin16=PB5 Mcu.Pin16=PA13
Mcu.Pin17=VP_SYS_VS_Systick Mcu.Pin17=PA14
Mcu.Pin18=PB3
Mcu.Pin19=PB4
Mcu.Pin2=PC15-OSC32_OUT Mcu.Pin2=PC15-OSC32_OUT
Mcu.Pin20=PB5
Mcu.Pin21=PB6
Mcu.Pin22=PB7
Mcu.Pin23=PB8
Mcu.Pin24=PB9
Mcu.Pin25=VP_SYS_VS_Systick
Mcu.Pin26=VP_TIM3_VS_ClockSourceINT
Mcu.Pin27=VP_TIM3_VS_no_output4
Mcu.Pin28=VP_TIM4_VS_ClockSourceINT
Mcu.Pin3=PD0-OSC_IN Mcu.Pin3=PD0-OSC_IN
Mcu.Pin4=PD1-OSC_OUT Mcu.Pin4=PD1-OSC_OUT
Mcu.Pin5=PB10 Mcu.Pin5=PA0-WKUP
Mcu.Pin6=PB11 Mcu.Pin6=PA1
Mcu.Pin7=PB12 Mcu.Pin7=PA2
Mcu.Pin8=PB13 Mcu.Pin8=PA3
Mcu.Pin9=PB15 Mcu.Pin9=PB10
Mcu.PinsNb=18 Mcu.PinsNb=29
Mcu.ThirdPartyNb=0 Mcu.ThirdPartyNb=0
Mcu.UserConstants= Mcu.UserConstants=
Mcu.UserName=STM32F103C8Tx Mcu.UserName=STM32F103C8Tx
@@ -63,12 +102,20 @@ NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
PA0-WKUP.Locked=true
PA0-WKUP.Signal=ADCx_IN0
PA1.Locked=true
PA1.Signal=ADCx_IN1
PA10.Mode=Asynchronous PA10.Mode=Asynchronous
PA10.Signal=USART1_RX PA10.Signal=USART1_RX
PA13.Mode=Serial_Wire PA13.Mode=Serial_Wire
PA13.Signal=SYS_JTMS-SWDIO PA13.Signal=SYS_JTMS-SWDIO
PA14.Mode=Serial_Wire PA14.Mode=Serial_Wire
PA14.Signal=SYS_JTCK-SWCLK PA14.Signal=SYS_JTCK-SWCLK
PA2.Locked=true
PA2.Signal=ADCx_IN2
PA3.Locked=true
PA3.Signal=ADCx_IN3
PA9.Mode=Asynchronous PA9.Mode=Asynchronous
PA9.Signal=USART1_TX PA9.Signal=USART1_TX
PB10.GPIOParameters=GPIO_Speed,GPIO_PuPd,GPIO_Label PB10.GPIOParameters=GPIO_Speed,GPIO_PuPd,GPIO_Label
@@ -111,6 +158,14 @@ PB5.GPIO_Label=KEY2
PB5.GPIO_PuPd=GPIO_PULLDOWN PB5.GPIO_PuPd=GPIO_PULLDOWN
PB5.Locked=true PB5.Locked=true
PB5.Signal=GPIO_Input PB5.Signal=GPIO_Input
PB6.Locked=true
PB6.Signal=S_TIM4_CH1
PB7.Locked=true
PB7.Signal=S_TIM4_CH2
PB8.Locked=true
PB8.Signal=S_TIM4_CH3
PB9.Locked=true
PB9.Signal=S_TIM4_CH4
PC13-TAMPER-RTC.GPIOParameters=GPIO_Speed,PinState,GPIO_PuPd,GPIO_Label PC13-TAMPER-RTC.GPIOParameters=GPIO_Speed,PinState,GPIO_PuPd,GPIO_Label
PC13-TAMPER-RTC.GPIO_Label=LED PC13-TAMPER-RTC.GPIO_Label=LED
PC13-TAMPER-RTC.GPIO_PuPd=GPIO_PULLUP PC13-TAMPER-RTC.GPIO_PuPd=GPIO_PULLUP
@@ -173,7 +228,7 @@ ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath= ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=false ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_SPI2_Init-SPI2-false-HAL-true ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_SPI2_Init-SPI2-false-HAL-true,6-MX_TIM4_Init-TIM4-false-HAL-true,7-MX_ADC1_Init-ADC1-false-HAL-true,8-MX_TIM3_Init-TIM3-false-HAL-true
RCC.ADCFreqValue=36000000 RCC.ADCFreqValue=36000000
RCC.AHBFreq_Value=72000000 RCC.AHBFreq_Value=72000000
RCC.APB1CLKDivider=RCC_HCLK_DIV2 RCC.APB1CLKDivider=RCC_HCLK_DIV2
@@ -195,14 +250,55 @@ RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
RCC.TimSysFreq_Value=72000000 RCC.TimSysFreq_Value=72000000
RCC.USBFreq_Value=72000000 RCC.USBFreq_Value=72000000
RCC.VCOOutput2Freq_Value=8000000 RCC.VCOOutput2Freq_Value=8000000
SH.ADCx_IN0.0=ADC1_IN0,IN0
SH.ADCx_IN0.ConfNb=1
SH.ADCx_IN1.0=ADC1_IN1,IN1
SH.ADCx_IN1.ConfNb=1
SH.ADCx_IN2.0=ADC1_IN2,IN2
SH.ADCx_IN2.ConfNb=1
SH.ADCx_IN3.0=ADC1_IN3,IN3
SH.ADCx_IN3.ConfNb=1
SH.S_TIM4_CH1.0=TIM4_CH1,PWM Generation1 CH1
SH.S_TIM4_CH1.ConfNb=1
SH.S_TIM4_CH2.0=TIM4_CH2,PWM Generation2 CH2
SH.S_TIM4_CH2.ConfNb=1
SH.S_TIM4_CH3.0=TIM4_CH3,PWM Generation3 CH3
SH.S_TIM4_CH3.ConfNb=1
SH.S_TIM4_CH4.0=TIM4_CH4,PWM Generation4 CH4
SH.S_TIM4_CH4.ConfNb=1
SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_2 SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_2
SPI2.CLKPhase=SPI_PHASE_2EDGE
SPI2.CLKPolarity=SPI_POLARITY_HIGH
SPI2.CalculateBaudRate=18.0 MBits/s SPI2.CalculateBaudRate=18.0 MBits/s
SPI2.Direction=SPI_DIRECTION_2LINES SPI2.Direction=SPI_DIRECTION_2LINES
SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler,CLKPolarity,CLKPhase
SPI2.Mode=SPI_MODE_MASTER SPI2.Mode=SPI_MODE_MASTER
SPI2.VirtualType=VM_MASTER SPI2.VirtualType=VM_MASTER
TIM3.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
TIM3.Channel-PWM\ Generation4\ No\ Output=TIM_CHANNEL_4
TIM3.IPParameters=Prescaler,Period,AutoReloadPreload,Channel-PWM Generation4 No Output,Pulse-PWM Generation4 No Output
TIM3.Period=999
TIM3.Prescaler=71
TIM3.Pulse-PWM\ Generation4\ No\ Output=500
TIM4.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
TIM4.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
TIM4.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
TIM4.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3
TIM4.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
TIM4.IPParameters=Prescaler,Period,AutoReloadPreload,Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2,Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4,Pulse-PWM Generation4 CH4,Pulse-PWM Generation1 CH1,Pulse-PWM Generation2 CH2
TIM4.Period=999
TIM4.Prescaler=71
TIM4.Pulse-PWM\ Generation1\ CH1=500
TIM4.Pulse-PWM\ Generation2\ CH2=500
TIM4.Pulse-PWM\ Generation4\ CH4=500
USART1.IPParameters=VirtualMode USART1.IPParameters=VirtualMode
USART1.VirtualMode=VM_ASYNC USART1.VirtualMode=VM_ASYNC
VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick VP_SYS_VS_Systick.Signal=SYS_VS_Systick
VP_TIM3_VS_ClockSourceINT.Mode=Internal
VP_TIM3_VS_ClockSourceINT.Signal=TIM3_VS_ClockSourceINT
VP_TIM3_VS_no_output4.Mode=PWM Generation4 No Output
VP_TIM3_VS_no_output4.Signal=TIM3_VS_no_output4
VP_TIM4_VS_ClockSourceINT.Mode=Internal
VP_TIM4_VS_ClockSourceINT.Signal=TIM4_VS_ClockSourceINT
board=custom board=custom

394
tools/font_gen.py Normal file
View File

@@ -0,0 +1,394 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
STM32 ST7735S LCD 字模生成工具Pillow 版)
- ASCII 8×16生成 lcd_data.c
- CJK 16×16生成 hz16_data.c + hz16_data.h含二分查找函数
用法:
# ASCII
python font_gen.py --font simsun --size 56 --threshold 64
# CJK 常用汉字GB2312 一级,约 3755 字)
python font_gen.py --cjk --font simsun --size 32 --threshold 64
# CJK + 标点
python font_gen.py --cjk --punct
"""
import os
import sys
import argparse
import struct
try:
from PIL import Image, ImageFont, ImageDraw
except ImportError:
print("请安装 Pillow: pip install Pillow", file=sys.stderr)
sys.exit(1)
# ── 通用渲染 ──
def render_char(font, char: str, w: int, h: int, scale: int = 1,
threshold: int = 64) -> list:
"""
在 w*scale × h*scale 画布上渲染字符,缩放到 w×h
返回逐行字节列表MSB 优先)
"""
bw, bh = w * scale, h * scale
img = Image.new("L", (bw, bh), 0)
draw = ImageDraw.Draw(img)
bbox = draw.textbbox((0, 0), char, font=font)
tw = bbox[2] - bbox[0]
th = bbox[3] - bbox[1]
cx = (bw - tw) // 2 - bbox[0]
cy = (bh - th) // 2 - bbox[1]
draw.text((cx, cy), char, font=font, fill=255)
small = img.resize((w, h), Image.LANCZOS)
pixels = list(small.getdata())
bytes_per_row = (w + 7) // 8
result = []
for r in range(h):
for br in range(bytes_per_row):
byte_val = 0
for c in range(8):
col = br * 8 + c
if col < w and pixels[r * w + col] >= threshold:
byte_val |= (1 << (7 - c))
result.append(byte_val)
return result
# ── ASCII 8×16 ──
def generate_ascii(output_path: str, font_path: str, size: int,
threshold: int, scale: int = 4):
font = ImageFont.truetype(font_path, size)
chars = list(range(32, 127))
N = len(chars)
lines = [
'#include "lcd_data.h"',
'/*ASCII字模数据*********************/',
'',
'/*宽8像素高16像素*/',
f'/* 字体: {os.path.basename(font_path)}, 字号: {size}, 阈值: {threshold} */',
'const uint8_t LCD_F8x16[][16] =',
'{',
]
for idx, ch in enumerate(chars):
if ch == ord('_'):
bitmap = [0x00] * 15 + [0x7F]
else:
bitmap = render_char(font, chr(ch), 8, 16, scale, threshold)
show = chr(ch) if 32 <= ch <= 126 else '?'
comma = ',' if idx < N - 1 else ''
line1 = ', '.join(f'0x{b:02X}' for b in bitmap[:8])
line2 = ', '.join(f'0x{b:02X}' for b in bitmap[8:])
lines.append(f' {line1},')
lines.append(f' {line2}{comma} // {show} {idx}')
if (idx + 1) % 10 == 0:
print(f" ASCII 进度: {idx+1}/{N}")
lines.append('};')
lines.append('')
lines.append('/*宽6像素高8像素未使用*/')
lines.append('const uint8_t LCD_F6x8[][6] =')
lines.append('{')
for idx, ch in enumerate(chars):
show = chr(ch) if 32 <= ch <= 126 else '?'
comma = ',' if idx < N - 1 else ''
lines.append(f' 0x00,0x00,0x00,0x00,0x00,0x00{comma} // {show} {idx}')
lines.append('};')
lines.append('')
content = '\n'.join(lines)
with open(output_path, 'w', encoding='utf-8', newline='\n') as f:
f.write(content)
print(f"已生成 ASCII 字模: {output_path}")
# ── CJK 16×16 ──
CJK_W, CJK_H = 16, 16
CJK_BYTES = CJK_H * ((CJK_W + 7) // 8) # 32
def get_gb2312_level1_unicodes():
"""GB2312 一级汉字(常用 ~3755 字)的 Unicode 码点"""
out = []
for u in range(0x4E00, 0x9FA6):
try:
b = chr(u).encode("gb2312")
if len(b) == 2:
qu = b[0] - 0xA1
if 16 <= qu <= 55:
out.append(u)
except (UnicodeEncodeError, LookupError):
pass
return out
def get_gb2312_all_unicodes():
"""GB2312 全部汉字(一级+二级 ~6763 字)"""
out = []
for u in range(0x4E00, 0x9FA6):
try:
b = chr(u).encode("gb2312")
if len(b) == 2:
out.append(u)
except (UnicodeEncodeError, LookupError):
pass
return out
CJK_PUNCTUATION = [
0x00B7, 0x2014, 0x2018, 0x2019, 0x201C, 0x201D, 0x2026,
0x3000, 0x3001, 0x3002, 0x300A, 0x300B, 0x300C, 0x300D,
0x300E, 0x300F, 0x3010, 0x3011, 0x3014, 0x3015,
0xFF01, 0xFF02, 0xFF07, 0xFF08, 0xFF09, 0xFF0C, 0xFF0E,
0xFF1A, 0xFF1B, 0xFF1F, 0xFF3B, 0xFF3D, 0xFF5B, 0xFF5D,
]
CJK_FULLWIDTH_ASCII = list(range(0xFF01, 0xFF5F)) # 全角 ASCII
def generate_cjk(base_path: str, font_path: str, size: int,
threshold: int, scale: int = 2,
mode: str = 'common', punct: bool = False):
"""生成 CJK 16×16 字库 .c + .h"""
font = ImageFont.truetype(font_path, size)
if mode == 'common':
unicodes = get_gb2312_level1_unicodes()
print(f"CJK 范围: GB2312 一级汉字 ({len(unicodes)} 字)")
elif mode == 'gb2312':
unicodes = get_gb2312_all_unicodes()
print(f"CJK 范围: GB2312 全部汉字 ({len(unicodes)} 字)")
else:
unicodes = []
print("CJK 范围: 无")
if punct:
extra = set(CJK_PUNCTUATION) | set(CJK_FULLWIDTH_ASCII)
unicodes = sorted(set(unicodes) | extra)
print(f"已加入 {len(extra)} 个中文标点/全角字符")
if not unicodes:
print("未指定 CJK 范围,使用默认字符")
unicodes = [ord(c) for c in "你好世界一二三"]
unicodes = sorted(set(unicodes))
N = len(unicodes)
# 渲染
bitmaps = []
for i, u in enumerate(unicodes):
ch = chr(u)
bm = render_char(font, ch, CJK_W, CJK_H, scale, threshold)
bitmaps.append(bm)
if (i + 1) % 500 == 0:
print(f" CJK 进度: {i+1}/{N}")
# ── 写 .c ──
c_path = base_path + ".c"
h_path = base_path + ".h"
name_base = os.path.basename(base_path)
guard = name_base.upper().replace(".", "_").replace("-", "_") + "_H"
with open(c_path, 'w', encoding='utf-8', newline='\n') as f:
f.write(f'/* 16×16 CJK 字库,由 font_gen.py 生成 */\n\n')
f.write(f'#include "{name_base}.h"\n\n')
f.write(f'static const uint8_t cjk_bitmaps[][{CJK_BYTES}] = {{\n')
for u, bm in zip(unicodes, bitmaps):
hex_str = ', '.join(f'0x{x:02X}' for x in bm)
try:
comment = f' /* U+{u:04X} {chr(u)} */'
except:
comment = f' /* U+{u:04X} */'
f.write(f' {{ {hex_str} }},{comment}\n')
f.write('};\n\n')
f.write(f'static const uint16_t cjk_unicodes[{N}] = {{\n')
for i in range(0, N, 16):
chunk = unicodes[i:i+16]
f.write(' ' + ', '.join(f'0x{u:04X}' for u in chunk) + ',\n')
f.write('};\n\n')
f.write(f'const uint8_t* cjk_get_bitmap(uint16_t unicode)\n')
f.write('{\n')
f.write(f' int lo = 0, hi = {N};\n')
f.write(' while (lo < hi) {\n')
f.write(' int mid = (lo + hi) >> 1;\n')
f.write(' if (cjk_unicodes[mid] < unicode) lo = mid + 1;\n')
f.write(' else if (cjk_unicodes[mid] > unicode) hi = mid;\n')
f.write(' else return cjk_bitmaps[mid];\n')
f.write(' }\n')
f.write(' return (const uint8_t*)0;\n')
f.write('}\n')
print(f'已生成: {c_path}')
# ── 写 .h ──
with open(h_path, 'w', encoding='utf-8', newline='\n') as f:
f.write(f'/* 16×16 CJK 字库,由 font_gen.py 生成 */\n\n')
f.write(f'#ifndef {guard}\n#define {guard}\n\n')
f.write(f'#include <stdint.h>\n\n')
f.write(f'#define CJK_BYTES_PER_CHAR {CJK_BYTES}\n')
f.write(f'#define CJK_WIDTH {CJK_W}\n')
f.write(f'#define CJK_HEIGHT {CJK_H}\n')
f.write(f'#define CJK_NUM_CHARS {N}\n\n')
f.write(f'/* 按 Unicode 码点查找 16×16 点阵,返回 {CJK_BYTES} 字节,未找到返回 NULL */\n')
f.write(f'const uint8_t* cjk_get_bitmap(uint16_t unicode);\n\n')
f.write(f'#endif /* {guard} */\n')
print(f'已生成: {h_path}')
def generate_cjk_direct(base_path: str, font_path: str, size: int,
threshold: int, scale: int,
unicodes: list):
"""用指定的 Unicode 列表生成 CJK 字库"""
font = ImageFont.truetype(font_path, size)
N = len(unicodes)
print(f"CJK 自定义字符: {N} 字: {''.join(chr(u) for u in unicodes[:50])}{'...' if N > 50 else ''}")
bitmaps = []
for i, u in enumerate(unicodes):
bm = render_char(font, chr(u), CJK_W, CJK_H, scale, threshold)
bitmaps.append(bm)
# ── 写 .c ──
c_path = base_path + ".c"
h_path = base_path + ".h"
name_base = os.path.basename(base_path)
guard = name_base.upper().replace(".", "_").replace("-", "_") + "_H"
with open(c_path, 'w', encoding='utf-8', newline='\n') as f:
f.write(f'/* 16×16 CJK 字库,由 font_gen.py 生成(自定义) */\n\n')
f.write(f'#include "{name_base}.h"\n\n')
f.write(f'static const uint8_t cjk_bitmaps[][{CJK_BYTES}] = {{\n')
for u, bm in zip(unicodes, bitmaps):
hex_str = ', '.join(f'0x{x:02X}' for x in bm)
f.write(f' {{ {hex_str} }}, /* U+{u:04X} {chr(u)} */\n')
f.write('};\n\n')
f.write(f'static const uint16_t cjk_unicodes[{N}] = {{\n')
for i in range(0, N, 16):
chunk = unicodes[i:i+16]
f.write(' ' + ', '.join(f'0x{u:04X}' for u in chunk) + ',\n')
f.write('};\n\n')
f.write(f'const uint8_t* cjk_get_bitmap(uint16_t unicode)\n')
f.write('{\n')
f.write(f' int lo = 0, hi = {N};\n')
f.write(' while (lo < hi) {\n')
f.write(' int mid = (lo + hi) >> 1;\n')
f.write(' if (cjk_unicodes[mid] < unicode) lo = mid + 1;\n')
f.write(' else if (cjk_unicodes[mid] > unicode) hi = mid;\n')
f.write(' else return cjk_bitmaps[mid];\n')
f.write(' }\n')
f.write(' return (const uint8_t*)0;\n')
f.write('}\n')
print(f'已生成: {c_path}')
# ── 写 .h ──
with open(h_path, 'w', encoding='utf-8', newline='\n') as f:
f.write(f'/* 16×16 CJK 字库,由 font_gen.py 生成(自定义) */\n\n')
f.write(f'#ifndef {guard}\n#define {guard}\n\n')
f.write(f'#include <stdint.h>\n\n')
f.write(f'#define CJK_BYTES_PER_CHAR {CJK_BYTES}\n')
f.write(f'#define CJK_WIDTH {CJK_W}\n')
f.write(f'#define CJK_HEIGHT {CJK_H}\n')
f.write(f'#define CJK_NUM_CHARS {N}\n\n')
f.write(f'const uint8_t* cjk_get_bitmap(uint16_t unicode);\n\n')
f.write(f'#endif /* {guard} */\n')
print(f'已生成: {h_path}')
# ── 主入口 ──
def _resolve_font(name_or_path: str) -> str:
if os.path.isfile(name_or_path):
return name_or_path
font_dir = r'C:\Windows\Fonts'
key = name_or_path.lower()
known = {
'consolas': 'consola.ttf', 'arial': 'arial.ttf',
'tahoma': 'tahoma.ttf', 'simsun': 'simsun.ttc',
'songti': 'simsun.ttc', '宋体': 'simsun.ttc',
'simhei': 'simhei.ttf', '黑体': 'simhei.ttf',
'yahei': 'msyh.ttc', '微软雅黑': 'msyh.ttc',
}
if key in known:
full = os.path.join(font_dir, known[key])
if os.path.isfile(full):
return full
for f in os.listdir(font_dir):
if f.lower().startswith(key) and f.lower().endswith(('.ttf', '.ttc')):
return os.path.join(font_dir, f)
# fallback
fallback = os.path.join(font_dir, 'simsun.ttc')
if os.path.isfile(fallback):
return fallback
return name_or_path
def main():
p = argparse.ArgumentParser(description='字模生成工具')
p.add_argument('--font', default='simsun', help='字体名称或路径')
p.add_argument('--size', type=int, default=64, help='渲染字号')
p.add_argument('--threshold', type=int, default=50, help='二值化阈值默认50')
p.add_argument('--scale', type=int, default=4, help='缩放倍率')
g = p.add_argument_group('ASCII 8×16')
g.add_argument('--ascii', action='store_true', help='生成 ASCII 字模(默认)')
g = p.add_argument_group('CJK 16×16')
g.add_argument('--cjk', action='store_true', help='生成 CJK 汉字字模')
g.add_argument('--common', action='store_true', help='CJK仅常用汉字GB2312 一级)')
g.add_argument('--gb2312', action='store_true', help='CJKGB2312 全部汉字')
g.add_argument('--punct', action='store_true', help='CJK加入中文标点/全角字符')
g.add_argument('--string', type=str, default=None, help='CJK仅生成指定字符串中的字符节省空间')
g.add_argument('--output', '-o', default=None, help='CJK 输出基名(不含扩展名)')
args = p.parse_args()
font_path = _resolve_font(args.font)
print(f"字体: {font_path}")
proj_dir = os.path.abspath(os.path.join(
os.path.dirname(__file__),
'..', 'STM32F103C8T6', 'Drivers', 'BSP', 'LCD'))
if args.cjk:
size = args.size or 48
scale = args.scale or 3
out_base = args.output or os.path.join(proj_dir, 'hz16_data')
if args.string is not None:
unicodes = sorted(set(ord(c) for c in args.string))
generate_cjk_direct(out_base, font_path, size, args.threshold, scale, unicodes)
else:
generate_cjk(out_base, font_path, size, args.threshold, scale,
mode='common' if args.common else ('gb2312' if args.gb2312 else 'common'),
punct=args.punct)
else:
# 默认 ASCII
size = args.size or 56
scale = args.scale or 4
out = os.path.join(proj_dir, 'lcd_data.c')
generate_ascii(out, font_path, size, args.threshold, scale)
if __name__ == '__main__':
main()

10
tools/to_escape.py Normal file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env python3
import sys
def main():
text = sys.argv[1] if len(sys.argv) > 1 else input("Enter Chinese: ")
escaped = ''.join(f'\\x{b:02X}' for b in text.encode('utf-8'))
print(escaped)
if __name__ == '__main__':
main()