完成文本阅读器,改进按键机制

This commit is contained in:
lxbpxylps@126.com 2021-09-28 14:24:41 +08:00
parent 77aa3c0ae6
commit 4316843201
30 changed files with 1240 additions and 10218 deletions

View File

@ -31,8 +31,8 @@
; </h>
;Stack_Size EQU 0x00000400
;栈大小设置为 262144 Bytes
Stack_Size EQU 0x00040000
;栈大小设置为 131072 Bytes
Stack_Size EQU 0x00020000
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
@ -44,8 +44,8 @@ __initial_sp
; </h>
;Heap_Size EQU 0x00000200
;堆大小设置为 262144 Bytes
Heap_Size EQU 0x00040000
;堆大小设置为 393216 Bytes
Heap_Size EQU 0x00060000
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base

View File

@ -151,11 +151,11 @@ void PendSV_Handler(void)
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
HAL_IncTick();
// void SysTick_Handler(void)
// {
// HAL_IncTick();
}
// }
/******************************************************************************/

View File

@ -1,68 +1,348 @@
//按键操作
//按键 FIFO 库
#include "delay.h"
#include "gpio.h"
#include "adc.h"
#include "key.h"
#define DIGITAL_KEY_NUM 3 //数字信号按键个数
#define ADC_KEY_NUM 4 //模拟信号按键个数
#define KEY_COUNT (DIGITAL_KEY_NUM + ADC_KEY_NUM)
//使能 GPIO 时钟
#define ALL_KEY_GPIO_CLK_ENABLE() \
{ \
__HAL_RCC_GPIOE_CLK_ENABLE(); \
__HAL_RCC_GPIOC_CLK_ENABLE(); \
__HAL_RCC_GPIOD_CLK_ENABLE(); \
};
typedef struct
{
GPIO_TypeDef *gpio;
uint16_t pin;
} X_GPIO_T;
static const X_GPIO_T s_gpio_list[DIGITAL_KEY_NUM] = {
{GPIOE, GPIO_PIN_3}, //KEY1
{GPIOC, GPIO_PIN_5}, //KEY2
{GPIOD, GPIO_PIN_10} //JOY_OK
};
static volatile KEY_T s_tBtn[KEY_COUNT] = {0};
static volatile KEY_FIFO_T s_tKey; //按键 FIFO 变量
static volatile is_key_clear = 1;
static void InitKeyVar(void);
static void InitKeyDigital(void);
static void DetectKey(uint8_t i);
static uint8_t KeyPinActive(uint8_t _id)
{
if (_id < DIGITAL_KEY_NUM)
{
uint8_t level;
if ((s_gpio_list[_id].gpio->IDR & s_gpio_list[_id].pin) == 0)
return 1;
else
return 0;
}
else if (_id < DIGITAL_KEY_NUM + ADC_KEY_NUM)
{
switch (_id)
{
case JOY_U:
{
if (ADC_Get_PC0() < 0.01)
return 1;
else
return 0;
}
break;
case JOY_D:
{
if (ADC_Get_PC0() > 3.20)
return 1;
else
return 0;
}
break;
case JOY_L:
{
if (ADC_Get_PC1() < 0.01)
return 1;
else
return 0;
}
break;
case JOY_R:
{
if (ADC_Get_PC1() > 3.20)
return 1;
else
return 0;
}
}
}
}
static uint8_t IsKeyDownFunc(uint8_t _id)
{
uint8_t count = 0;
uint8_t save = UINT8_MAX;
//判断有几个键按下
for (uint8_t i = 0; i < KEY_COUNT; i++)
{
if (KeyPinActive(i))
{
count++;
save = i;
}
}
if (count == 1 && save == _id)
return 1; //只有单个键按下时才有效
return 0;
}
/**
* @brief KEY1 KEY2
* @brief
*/
void KEY_Init(void)
{
GPIO_E3_C5_Init();
InitKeyVar(); //初始化按键变量
InitKeyDigital(); //初始化数字按键
}
static void InitKeyDigital(void)
{
GPIO_InitTypeDef gpio_init;
ALL_KEY_GPIO_CLK_ENABLE();
gpio_init.Mode = GPIO_MODE_INPUT;
gpio_init.Pull = GPIO_PULLUP;
gpio_init.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
for (uint8_t i = 0; i < DIGITAL_KEY_NUM; i++)
{
gpio_init.Pin = s_gpio_list[i].pin;
HAL_GPIO_Init(s_gpio_list[i].gpio, &gpio_init);
}
}
static void InitKeyVar(void)
{
s_tKey.Read = 0;
s_tKey.Write = 0;
//缺省值
for (uint8_t i = 0; i < KEY_COUNT; i++)
{
s_tBtn[i].LongTime = KEY_LONG_TIME; //若设置为 0 表示不检测长按键事件
s_tBtn[i].Count = KEY_FILTER_TIME / 2; //计数器设置为滤波时间的一半
s_tBtn[i].State = 0; //按键缺省状态0 为未按下
s_tBtn[i].RepeatSpeed = 0; //按键连发的速度0 表示不支持连发
s_tBtn[i].RepeatCount = 0; //连发计数器
}
//摇杆上下左右,支持长按 1 秒后,自动连发
KEY_SetKeyParam(JOY_U, 100, 6);
KEY_SetKeyParam(JOY_D, 100, 6);
KEY_SetKeyParam(JOY_L, 100, 6);
KEY_SetKeyParam(JOY_R, 100, 6);
}
/**
* @brief
* @retval NO_KEY KEY1 KEY2
* @brief FIFO
* @param _KeyCode:
*/
void KEY_PutKey(uint8_t _KeyCode)
{
s_tKey.Buf[s_tKey.Write] = _KeyCode;
if (++s_tKey.Write >= KEY_FIFO_SIZE)
{
s_tKey.Write = 0;
}
}
/**
* @brief FIFO
* @retval
*/
uint8_t KEY_GetKey(void)
{
if (KEY1_Val == 0)
if (s_tKey.Read == s_tKey.Write)
{
Delay_ms(10);
if (KEY1_Val == 0)
return KEY_NONE;
}
else
{
while (KEY1_Val == 0)
;
uint8_t ret = s_tKey.Buf[s_tKey.Read];
return KEY1;
if (++s_tKey.Read >= KEY_FIFO_SIZE)
s_tKey.Read = 0;
if (
ret == KEY1_UP ||
ret == KEY2_UP ||
ret == JOY_OK_UP ||
ret == JOY_U_UP ||
ret == JOY_D_UP ||
ret == JOY_L_UP ||
ret == JOY_R_UP)
{
if (is_key_clear)
{
is_key_clear = 0;
return KEY_NONE;
}
}
else if (KEY2_Val == 0)
{
Delay_ms(10);
if (KEY2_Val == 0)
is_key_clear = 0;
return ret;
}
}
/**
* @brief FIFO
* @retval
*/
uint8_t KEY_GetKeyWait(void)
{
while (KEY2_Val == 0)
uint8_t key = KEY_NONE;
while (key == KEY_NONE)
key = KEY_GetKey();
return key;
}
/**
* @brief
* @param _ucKeyID: ID
* @retval 1 0
*/
uint8_t KEY_GetKeyState(KEY_ID_E _ucKeyID)
{
return s_tBtn[_ucKeyID].State;
}
/**
* @brief
* @param _ucKeyID: ID
*/
void KEY_WaitKey(KEY_ID_E _ucKeyID)
{
while (KEY_GetKeyState(_ucKeyID) != 1)
;
}
return KEY2;
/**
* @brief
* @param _ucKeyID: ID
* @param _LongTime:
* @param _RepeatSpeed:
*/
void KEY_SetKeyParam(uint8_t _ucKeyID, uint16_t _LongTime, uint8_t _RepeatSpeed)
{
s_tBtn[_ucKeyID].LongTime = _LongTime; //长按时间 0 表示不检测长按键事件
s_tBtn[_ucKeyID].RepeatSpeed = _RepeatSpeed; //按键连发的速度0 表示不支持连发
s_tBtn[_ucKeyID].RepeatCount = 0;
}
/**
* @brief FIFO
*/
void KEY_ClearKey(void)
{
s_tKey.Read = s_tKey.Write;
is_key_clear = 1;
}
static void DetectKey(uint8_t i)
{
KEY_T *pBtn;
pBtn = &s_tBtn[i];
if (IsKeyDownFunc(i))
{
if (pBtn->Count < KEY_FILTER_TIME)
{
pBtn->Count = KEY_FILTER_TIME;
}
else if (pBtn->Count < 2 * KEY_FILTER_TIME)
{
pBtn->Count++;
}
else
{
if (pBtn->State == 0)
{
pBtn->State = 1;
KEY_PutKey((uint8_t)(3 * i + 1));
}
if (pBtn->LongTime > 0)
{
if (pBtn->LongCount < pBtn->LongTime)
{
if (++pBtn->LongCount == pBtn->LongTime)
{
KEY_PutKey((uint8_t)(3 * i + 3));
}
}
else
{
return NO_KEY;
if (pBtn->RepeatSpeed > 0)
{
if (++pBtn->RepeatCount >= pBtn->RepeatSpeed)
{
pBtn->RepeatCount = 0;
KEY_PutKey((uint8_t)(3 * i + 1));
}
}
}
}
}
}
else
{
if (pBtn->Count > KEY_FILTER_TIME)
{
pBtn->Count = KEY_FILTER_TIME;
}
else if (pBtn->Count != 0)
{
pBtn->Count--;
}
else
{
if (pBtn->State == 1)
{
pBtn->State = 0;
KEY_PutKey((uint8_t)(3 * i + 2));
}
}
return NO_KEY;
pBtn->LongCount = 0;
pBtn->RepeatCount = 0;
}
}
/**
* @brief
* @retval KEY1 KEY2
* @brief SysTick 10ms
*/
uint8_t KEY_GetKeyWait(void)
void KEY_Scan10ms(void)
{
uint8_t key = NO_KEY;
while (key == NO_KEY)
{
key = KEY_GetKey();
}
return key;
for (uint8_t i = 0; i < KEY_COUNT; i++)
DetectKey(i);
}

View File

@ -1,21 +1,117 @@
//°´¼ü²Ù×÷
//按键 FIFO 库
#ifndef __KEY_H
#define __KEY_H
#include "sys.h"
#define NO_KEY 0
#define KEY1 1
#define KEY2 2
#define KEY3 3
#define KEY4 4
//按键事件别名
#define KEY1_Val HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_3)
#define KEY2_Val HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_5)
#define KEY1_DOWN KEY_1_DOWN
#define KEY1_UP KEY_1_UP
#define KEY1_LONG KEY_1_LONG
#define KEY2_DOWN KEY_2_DOWN
#define KEY2_UP KEY_2_UP
#define KEY2_LONG KEY_2_LONG
#define JOY_OK_DOWN KEY_3_DOWN //OK
#define JOY_OK_UP KEY_3_UP
#define JOY_OK_LONG KEY_3_LONG
#define JOY_U_DOWN KEY_4_DOWN //上
#define JOY_U_UP KEY_4_UP
#define JOY_U_LONG KEY_4_LONG
#define JOY_D_DOWN KEY_5_DOWN //下
#define JOY_D_UP KEY_5_UP
#define JOY_D_LONG KEY_5_LONG
#define JOY_L_DOWN KEY_6_DOWN //左
#define JOY_L_UP KEY_6_UP
#define JOY_L_LONG KEY_6_LONG
#define JOY_R_DOWN KEY_7_DOWN //右
#define JOY_R_UP KEY_7_UP
#define JOY_R_LONG KEY_7_LONG
//按键 ID
typedef enum
{
KEY1 = 0,
KEY2,
JOY_OK,
JOY_U,
JOY_D,
JOY_L,
JOY_R
} KEY_ID_E;
#define KEY_FILTER_TIME 5 //按键滤波时间 50ms单位 10ms
#define KEY_LONG_TIME 100 //持续 1 秒,长按事件
typedef struct
{
uint8_t (*IsKeyDownFunc)(void); //按键按下的判断函数1 表示按下
uint8_t Count; //滤波器计数器
uint16_t LongCount; //长按计数器
uint16_t LongTime; //按键按下持续时间0 表示不检测长按
uint8_t State; //按键当前状态(按下还是弹起)
uint8_t RepeatSpeed; //连续按键周期
uint8_t RepeatCount; //连续按键计数器
} KEY_T;
typedef enum
{
KEY_NONE = 0,
KEY_1_DOWN, //1 键按下
KEY_1_UP, //1 键弹起
KEY_1_LONG, //1 键长按
KEY_2_DOWN, //2 键按下
KEY_2_UP, //2 键弹起
KEY_2_LONG, //2 键长按
KEY_3_DOWN, //3 键按下
KEY_3_UP, //3 键弹起
KEY_3_LONG, //3 键长按
KEY_4_DOWN, //4 键按下
KEY_4_UP, //4 键弹起
KEY_4_LONG, //4 键长按
KEY_5_DOWN, //5 键按下
KEY_5_UP, //5 键弹起
KEY_5_LONG, //5 键长按
KEY_6_DOWN, //6 键按下
KEY_6_UP, //6 键弹起
KEY_6_LONG, //6 键长按
KEY_7_DOWN, //7 键按下
KEY_7_UP, //7 键弹起
KEY_7_LONG, //7 键长按
} KEY_ENUM;
//按键 FIFO 变量
#define KEY_FIFO_SIZE 10
typedef struct
{
uint8_t Buf[KEY_FIFO_SIZE]; //键值缓冲区
uint8_t Read; //缓冲区读指针
uint8_t Write; //缓冲区写指针
} KEY_FIFO_T;
void KEY_Init(void);
void KEY_Scan10ms(void);
void KEY_PutKey(uint8_t _KeyCode);
uint8_t KEY_GetKey(void);
uint8_t KEY_GetKeyWait(void);
uint8_t KEY_GetKeyState(KEY_ID_E _ucKeyID);
void KEY_WaitKey(KEY_ID_E _ucKeyID);
void KEY_SetKeyParam(uint8_t _ucKeyID, uint16_t _LongTime, uint8_t _RepeatSpeed);
void KEY_ClearKey(void);
#endif

View File

@ -1,12 +1,12 @@
#include "delay.h"
//LCD 库ILI9431 及字库)
#include "systick.h"
#include "spi.h"
#include "lcd.h"
/**************************************** 私有函数 ****************************************/
void LCD_SetWin(uint16_t x, uint16_t y, uint16_t width, uint16_t height);
/*****************************************************************************************/
/**
@ -116,7 +116,15 @@ void LCD_SendCmdDataBytes(uint8_t cmd, uint8_t *pData, uint32_t Count)
void LCD_Init(void)
{
//初始化 ILI9431
GPIO_B0_B1_B12_Init(); //³õʼ»¯ PB0 PB1 PB12
//初始化 PB0 PB1 PB12
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_GPIOB_CLK_ENABLE(); //开启 PB 时钟
GPIO_Initure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_12; //PB0 PB1 PB12
GPIO_Initure.Mode = GPIO_MODE_OUTPUT_PP; //推挽输出
GPIO_Initure.Pull = GPIO_PULLUP; //上拉
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; //高速
HAL_GPIO_Init(GPIOB, &GPIO_Initure); //初始化 PB0 PB1 PB12
LCD_Stop_Send;
LCD_Data_Mode_On;

View File

@ -1,3 +1,5 @@
//LCD ¿â£¨ILI9431 ¼°×ֿ⣩
#ifndef __LCD_H
#define __LCD_H
@ -155,6 +157,7 @@
#define LCD_Reverse_Off LCD_SendCmd(LCD_CMD_DINVOFF) //关全局反色模式
#define LCD_RAM_Wr LCD_SendCmd(LCD_CMD_RAMWR) //开始写显存
#define LCD_RAM_Rd LCD_SendCmd(LCD_CMD_RAMRD) //¿ªÊ¼¶ÁÏÔ´æ
/**************************************** 通讯函数 ****************************************/
@ -173,6 +176,7 @@ void LCD_SendCmdDataBytes(uint8_t cmd, uint8_t *pData, uint32_t Count);
/**************************************** 操作函数 ****************************************/
void LCD_Init(void);
void LCD_SetWin(uint16_t x, uint16_t y, uint16_t width, uint16_t height);
void LCD_Font_ReadAddr(uint8_t *pData, uint32_t addr, uint16_t Count);

View File

@ -1,4 +1,6 @@
#include "gpio.h"
//LED 库
#include "sys.h"
#include "led.h"
@ -7,6 +9,34 @@
*/
void LED_Init(void)
{
GPIO_A1_Init();
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_GPIOA_CLK_ENABLE(); //开启 PA 时钟
GPIO_Initure.Pin = GPIO_PIN_1; //PA1
GPIO_Initure.Mode = GPIO_MODE_OUTPUT_PP; //推挽输出
GPIO_Initure.Pull = GPIO_PULLUP; //上拉
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; //高速
HAL_GPIO_Init(GPIOA, &GPIO_Initure); //初始化 PA1
LED2_Off;
SysTick_StartTimer(LED2_SYSTICK_TIMER_ID, 50);
}
/**
* @brief LED2
* @param led_num:
*/
void LED_Slow_Toggle(uint8_t led_num)
{
switch (led_num)
{
case 2:
{
if (SysTick_CheckTimer(LED2_SYSTICK_TIMER_ID))
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1);
SysTick_StartTimer(LED2_SYSTICK_TIMER_ID, 50);
}
}
}
}

View File

@ -1,3 +1,5 @@
//LED 库
#ifndef _LED_H
#define _LED_H
@ -6,8 +8,11 @@
#define LED2(n) (n ? HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET) : HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET))
#define LED2_On LED2(0)
#define LED2_Off LED2(1)
#define LED2_Toggle (HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1)) //LED2 ·­×ª
#define LED2_Toggle HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1) //LED2 翻转
#define LED2_SYSTICK_TIMER_ID 0
#define LED2_Slow_Toggle LED_Slow_Toggle(2) //LED2 慢速翻转,无阻塞,防止因调用过快导致无法观察
void LED_Init(void);
void LED_Slow_Toggle(uint8_t led_num);
#endif

View File

@ -80,73 +80,18 @@
#include "stm32h7xx_hal.h"
#include "sdio.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H743I_EVAL
* @{
*/
/** @addtogroup STM32H743I_EVAL_SD
* @{
*/
/** @defgroup STM32H743I_EVAL_SD_Private_TypesDefinitions SD Private TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup STM32H743I_EVAL_SD_Private_Defines SD Private Defines
* @{
*/
/* 卡插入引脚 : PG9 */
//#define SD_DETECT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
//#define SD_DETECT_GPIO_PORT GPIOG
//#define SD_DETECT_PIN GPIO_PIN_9
/* PG9 == 0 表示卡插入 */
//#define SD_IS_INSERTED() ((SD_DETECT_GPIO_PORT->IDR & SD_DETECT_PIN) == 0)
#define SD_IS_INSERTED() 1
/**
* @}
*/
/** @defgroup STM32H743I_EVAL_SD_Private_Macros SD Private Macros
* @{
*/
/**
* @}
*/
/** @defgroup STM32H743I_EVAL_SD_Private_Variables SD Private Variables
* @{
*/
SD_HandleTypeDef uSdHandle;
//static uint8_t UseExtiModeDetection = 0;
/**
* @}
*/
/** @defgroup STM32H743I_EVAL_SD_Private_FunctionPrototypes SD Private FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @addtogroup STM32H743I_EVAL_SD_Exported_Functions
* @{
*/
/**
* @brief Initializes the SD card device.
* @retval SD status
@ -563,14 +508,6 @@ void HAL_SD_DriveTransciver_1_8V_Callback(FlagStatus status)
BSP_SD_DriveTransciver_1_8V_Callback(status);
}
/*
*********************************************************************************************************
* : SDIO_IRQHandler
* : SDIO中断
* :
* :
*********************************************************************************************************
*/
void SDMMC1_IRQHandler(void)
{
HAL_SD_IRQHandler(&uSdHandle);

View File

@ -251,7 +251,7 @@
/ buffer in the file system object (FATFS) is used for the file data transfer. */
#define _FS_EXFAT 0
#define _FS_EXFAT 1
/* This option switches support of exFAT file system. (0:Disable or 1:Enable)
/ When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1)
/ Note that enabling exFAT discards C89 compatibility. */

View File

@ -339,7 +339,7 @@
<MiscControls></MiscControls>
<Define>USE_HAL_DRIVER, STM32H743xx</Define>
<Undefine></Undefine>
<IncludePath>..\Core;..\Hardware\led;..\Hardware\key;..\Hardware\lcd;..\Hardware\sdio;..\Libraries\HAL_Lib\Inc;..\Libraries\FatFs;..\Libraries\FatFs\drivers;..\System\delay;..\System\sys;..\System\spi;..\System\gpio;..\User\Main;..\User\GameEngine;..\User\Picture;..\User\SD;..\User\APP_Reader</IncludePath>
<IncludePath>..\User\Main;..\Core;..\Libraries\HAL_Lib\Inc;..\Libraries\FatFs;..\Libraries\FatFs\drivers;..\System\systick;..\System\sys;..\System\spi;..\System\gpio;..\System\tim;..\System\usart;..\System\adc;..\Hardware\led;..\Hardware\key;..\Hardware\lcd;..\Hardware\sdio;..\Hardware\hc25;..\User\GameEngine;..\User\Picture;..\User\SD;..\User\WLAN;..\User\Clock;..\User\APP_Reader;..\User\APP_Video;..\User\APP_Plane;..\User\APP_Weather;..\User\APP_Setting;..\User\FxLib</IncludePath>
</VariousControls>
</Cads>
<Aads>
@ -425,31 +425,6 @@
</File>
</Files>
</Group>
<Group>
<GroupName>System</GroupName>
<Files>
<File>
<FileName>delay.c</FileName>
<FileType>1</FileType>
<FilePath>..\System\delay\delay.c</FilePath>
</File>
<File>
<FileName>sys.c</FileName>
<FileType>1</FileType>
<FilePath>..\System\sys\sys.c</FilePath>
</File>
<File>
<FileName>spi.c</FileName>
<FileType>1</FileType>
<FilePath>..\System\spi\spi.c</FilePath>
</File>
<File>
<FileName>gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\System\gpio\gpio.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>HAL_Lib</GroupName>
<Files>
@ -578,6 +553,61 @@
<FileType>1</FileType>
<FilePath>..\Libraries\HAL_Lib\Src\stm32h7xx_hal_spi_ex.c</FilePath>
</File>
<File>
<FileName>stm32h7xx_hal_uart.c</FileName>
<FileType>1</FileType>
<FilePath>..\Libraries\HAL_Lib\Src\stm32h7xx_hal_uart.c</FilePath>
</File>
<File>
<FileName>stm32h7xx_hal_uart_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\Libraries\HAL_Lib\Src\stm32h7xx_hal_uart_ex.c</FilePath>
</File>
<File>
<FileName>stm32h7xx_hal_usart.c</FileName>
<FileType>1</FileType>
<FilePath>..\Libraries\HAL_Lib\Src\stm32h7xx_hal_usart.c</FilePath>
</File>
<File>
<FileName>stm32h7xx_hal_usart_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\Libraries\HAL_Lib\Src\stm32h7xx_hal_usart_ex.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>System</GroupName>
<Files>
<File>
<FileName>sys.c</FileName>
<FileType>1</FileType>
<FilePath>..\System\sys\sys.c</FilePath>
</File>
<File>
<FileName>spi.c</FileName>
<FileType>1</FileType>
<FilePath>..\System\spi\spi.c</FilePath>
</File>
<File>
<FileName>tim.c</FileName>
<FileType>1</FileType>
<FilePath>..\System\tim\tim.c</FilePath>
</File>
<File>
<FileName>uart.c</FileName>
<FileType>1</FileType>
<FilePath>..\System\usart\uart.c</FilePath>
</File>
<File>
<FileName>systick.c</FileName>
<FileType>1</FileType>
<FilePath>..\System\systick\systick.c</FilePath>
</File>
<File>
<FileName>adc.c</FileName>
<FileType>1</FileType>
<FilePath>..\System\adc\adc.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -603,6 +633,11 @@
<FileType>1</FileType>
<FilePath>..\Hardware\sdio\sdio.c</FilePath>
</File>
<File>
<FileName>hc25.c</FileName>
<FileType>1</FileType>
<FilePath>..\Hardware\hc25\hc25.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -669,9 +704,9 @@
<GroupName>Picture</GroupName>
<Files>
<File>
<FileName>pic_minecraft.c</FileName>
<FileName>Picture.c</FileName>
<FileType>1</FileType>
<FilePath>..\User\Picture\pic_minecraft.c</FilePath>
<FilePath>..\User\Picture\Picture.c</FilePath>
</File>
</Files>
</Group>
@ -685,6 +720,26 @@
</File>
</Files>
</Group>
<Group>
<GroupName>WLAN</GroupName>
<Files>
<File>
<FileName>WLAN.c</FileName>
<FileType>1</FileType>
<FilePath>..\User\WLAN\WLAN.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Clock</GroupName>
<Files>
<File>
<FileName>Clock.c</FileName>
<FileType>1</FileType>
<FilePath>..\User\Clock\Clock.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>APP_Reader</GroupName>
<Files>
@ -695,6 +750,56 @@
</File>
</Files>
</Group>
<Group>
<GroupName>APP_Video</GroupName>
<Files>
<File>
<FileName>APP_Video.c</FileName>
<FileType>1</FileType>
<FilePath>..\User\APP_Video\APP_Video.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>APP_Plane</GroupName>
<Files>
<File>
<FileName>APP_Plane.c</FileName>
<FileType>1</FileType>
<FilePath>..\User\APP_Plane\APP_Plane.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>APP_Weather</GroupName>
<Files>
<File>
<FileName>APP_Weather.c</FileName>
<FileType>1</FileType>
<FilePath>..\User\APP_Weather\APP_Weather.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>APP_Setting</GroupName>
<Files>
<File>
<FileName>APP_Setting.c</FileName>
<FileType>1</FileType>
<FilePath>..\User\APP_Setting\APP_Setting.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Fxlib</GroupName>
<Files>
<File>
<FileName>fxlib.c</FileName>
<FileType>1</FileType>
<FilePath>..\User\FxLib\fxlib.c</FilePath>
</File>
</Files>
</Group>
</Groups>
</Target>
</Targets>

View File

@ -1,55 +0,0 @@
//SYSCLK 初始化及延时函数
#include "delay.h"
static uint32_t fac_us = 0; //us 延时倍乘数
/**
* @brief
* @param SYSCLK:
*/
void SYSCLK_Init(uint16_t SYSCLK)
{
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
fac_us = SYSCLK;
}
/**
* @brief us
* @param nus: us 1000
*/
void Delay_us(uint32_t nus)
{
uint32_t ticks, told, tnow;
uint32_t tcnt = 0;
uint32_t reload = SysTick->LOAD; //LOAD 的值
ticks = nus * fac_us; //需要的节拍数
told = SysTick->VAL; //当前计数器值
while (1)
{
tnow = SysTick->VAL;
if (tnow != told)
{
if (tnow < told)
tcnt += told - tnow;
else
tcnt += reload - tnow + told;
told = tnow;
if (tcnt >= ticks)
break;
}
};
}
/**
* @brief ms
* @param nms: ms
*/
void Delay_ms(uint16_t nms)
{
uint32_t i;
for (i = 0; i < nms; i++)
Delay_us(1000);
}

View File

@ -1,12 +0,0 @@
//SYSCLK 初始化及延时函数
#ifndef __DELAY_H
#define __DELAY_H
#include "sys.h"
void SYSCLK_Init(uint16_t SYSCLK);
void Delay_us(uint32_t nus);
void Delay_ms(uint16_t nms);
#endif

View File

@ -1,4 +1,4 @@
//管理所有 GPIO 的初始化
//管理 GPIO 的初始化
#include "sys.h"
@ -26,26 +26,33 @@ void GPIO_A1_Init(void)
/************************************** GPIO E3 C5 **************************************/
/**
* @brief PE3 PC5 KEY1 KEY2
* @brief PE3 PC5 PD10 KEY1 KEY2 KEY3
*/
void GPIO_E3_C5_Init(void)
void GPIO_E3_C5_D10_Init(void)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_GPIOC_CLK_ENABLE(); //开启 PC 时钟
__HAL_RCC_GPIOE_CLK_ENABLE(); //开启 PE 时钟
__HAL_RCC_GPIOD_CLK_ENABLE(); //开启 PD 时钟
GPIO_Initure.Pin = GPIO_PIN_3; //PE3对应 K1
GPIO_Initure.Pin = GPIO_PIN_3; //PE3对应 KEY1
GPIO_Initure.Mode = GPIO_MODE_INPUT; //输入
GPIO_Initure.Pull = GPIO_PULLUP; //上拉
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; //高速
HAL_GPIO_Init(GPIOE, &GPIO_Initure); //初始化 PE3
GPIO_Initure.Pin = GPIO_PIN_5; //PC5对应 K2
GPIO_Initure.Pin = GPIO_PIN_5; //PC5对应 KEY2
GPIO_Initure.Mode = GPIO_MODE_INPUT; //输入
GPIO_Initure.Pull = GPIO_PULLUP; //上拉
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; //高速
HAL_GPIO_Init(GPIOC, &GPIO_Initure); //初始化 PC5
GPIO_Initure.Pin = GPIO_PIN_10; //PC5对应 KEY3
GPIO_Initure.Mode = GPIO_MODE_INPUT; //输入
GPIO_Initure.Pull = GPIO_PULLUP; //上拉
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; //高速
HAL_GPIO_Init(GPIOD, &GPIO_Initure); //初始化 PD10
}
/****************************************************************************************/

View File

@ -1,10 +1,10 @@
//管理所有 GPIO 的初始化
//管理 GPIO 的初始化
#ifndef __GPIO_H
#define __GPIO_H
void GPIO_A1_Init(void);
void GPIO_E3_C5_Init(void);
void GPIO_E3_C5_D10_Init(void);
void GPIO_B0_B1_B12_Init(void);
#endif

View File

@ -1,4 +1,4 @@
//系统初始化
//系统常用调用
#include "sys.h"
@ -73,25 +73,23 @@ void Cache_Enable(void)
/**
* @brief ³õʼ»¯ÏµÍ³Ê±ÖÓ
* @param plln: PLL1 PLL倍频4~512
* @param pllm: PLL1 PLL之前的分频2~63
* @param pllp: PLL1 p PLL之后的分频2~128 2
* @param pllq: PLL1 q PLL之后的分频1~128.
* @retval 0 1
*/
uint8_t Clock_Init(uint32_t plln, uint32_t pllm, uint32_t pllp, uint32_t pllq)
void SystemClock_Init(void)
{
HAL_StatusTypeDef ret = HAL_OK;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
HAL_StatusTypeDef ret = HAL_OK;
//锁住SCU (Supply configuration update)
MODIFY_REG(PWR->CR3, PWR_CR3_SCUEN, 0);
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
while ((PWR->D3CR & (PWR_D3CR_VOSRDY)) != PWR_D3CR_VOSRDY)
while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY))
{
}
//使能 HSE并选择 HSE 作为 PLL 时钟源
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
@ -99,42 +97,47 @@ uint8_t Clock_Init(uint32_t plln, uint32_t pllm, uint32_t pllp, uint32_t pllq)
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLN = plln;
RCC_OscInitStruct.PLL.PLLM = pllm;
RCC_OscInitStruct.PLL.PLLP = pllp;
RCC_OscInitStruct.PLL.PLLQ = pllq;
RCC_OscInitStruct.PLL.PLLM = 5;
RCC_OscInitStruct.PLL.PLLN = 160;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLQ = 4;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
if (ret != HAL_OK)
return 1;
// QSPI_Enable_Memmapmode(); //QSPI内存映射模式,需要在时钟初始化之前开启,否则会有各种问题
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK |
RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_D1PCLK1 |
RCC_CLOCKTYPE_PCLK1 |
RCC_CLOCKTYPE_PCLK2 |
RCC_CLOCKTYPE_D3PCLK1);
/*
PLL
RCC_CLOCKTYPE_SYSCLK
RCC_CLOCKTYPE_HCLK AHB1 AHB2 AHB3 AHB4 线
RCC_CLOCKTYPE_PCLK1 APB1 线
RCC_CLOCKTYPE_PCLK2 APB2 线
RCC_CLOCKTYPE_D1PCLK1 APB3 线
RCC_CLOCKTYPE_D3PCLK1 APB4 线
*/
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_D1PCLK1 | RCC_CLOCKTYPE_PCLK1 |
RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_D3PCLK1);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV4;
ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
if (ret != HAL_OK)
return 1;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
__HAL_RCC_CSI_ENABLE();
__HAL_RCC_SYSCFG_CLK_ENABLE();
HAL_EnableCompensationCell();
return 0;
__HAL_RCC_D2SRAM1_CLK_ENABLE();
__HAL_RCC_D2SRAM2_CLK_ENABLE();
__HAL_RCC_D2SRAM3_CLK_ENABLE();
}
/**
@ -159,163 +162,13 @@ uint8_t Get_DCacheSta(void)
return sta;
}
/**
* @brief QSPI
*/
void QSPI_Enable_Memmapmode(void)
void Error_Handler(char *file, uint32_t line)
{
uint32_t tempreg = 0;
volatile uint32_t *data_reg = &QUADSPI->DR;
GPIO_InitTypeDef qspi_gpio;
printf("Wrong parameters value: file %s on line %d\r\n", file, line);
RCC->AHB4ENR |= 1 << 1; //使能 PORTB 时钟
RCC->AHB4ENR |= 1 << 5; //使能 PORTF 时钟
RCC->AHB3ENR |= 1 << 14; //QSPI 时钟使能
if (line == 0)
return;
qspi_gpio.Pin = GPIO_PIN_6; //PB6 AF10
qspi_gpio.Mode = GPIO_MODE_AF_PP;
qspi_gpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
qspi_gpio.Pull = GPIO_NOPULL;
qspi_gpio.Alternate = GPIO_AF10_QUADSPI;
HAL_GPIO_Init(GPIOB, &qspi_gpio);
qspi_gpio.Pin = GPIO_PIN_2; //PB2 AF9
qspi_gpio.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOB, &qspi_gpio);
qspi_gpio.Pin = GPIO_PIN_6 | GPIO_PIN_7; //PF6 7 AF9
qspi_gpio.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOF, &qspi_gpio);
qspi_gpio.Pin = GPIO_PIN_8 | GPIO_PIN_9; //PF8 9 AF10
qspi_gpio.Alternate = GPIO_AF10_QUADSPI;
HAL_GPIO_Init(GPIOF, &qspi_gpio);
//QSPI 设置,参考 QSPI 实验的 QSPI_Init 函数
RCC->AHB3RSTR |= 1 << 14; //复位 QSPI
RCC->AHB3RSTR &= ~(1 << 14); //停止复位 QSPI
while (QUADSPI->SR & (1 << 5))
; //等待 BUSY 位清零
QUADSPI->CR = 0X01000310; //设置 CR 寄存器
QUADSPI->DCR = 0X00160401; //设置 DCR 寄存器
QUADSPI->CR |= 1 << 0; //使能 QSPI
//注意QSPI QE 位的使能,在 QSPI 烧写算法里面,就已经设置了
//所以,这里可以不用设置 QE 位,否则需要加入对 QE 位置 1 的代码
//不过,代码必须通过仿真器下载,直接烧录到外部 QSPI FLASH是不可用的
//如果想直接烧录到外部 QSPI FLASH 也可以用,则需要在这里添加 QE 位置 1 的代码
//W25QXX 进入 QPI 模式0X38指令
while (QUADSPI->SR & (1 << 5))
; //等待 BUSY 位清零
QUADSPI->CCR = 0X00000138; //发送 0X38 指令W25QXX 进入 QPI 模式
while ((QUADSPI->SR & (1 << 1)) == 0)
; //等待指令发送完成
QUADSPI->FCR |= 1 << 1; //清除发送完成标志位
//W25QXX 写使能0X06指令
while (QUADSPI->SR & (1 << 5))
; //等待 BUSY 位清零
QUADSPI->CCR = 0X00000106; //发送 0X06 指令W25QXX 写使能
while ((QUADSPI->SR & (1 << 1)) == 0)
; //等待指令发送完成
QUADSPI->FCR |= 1 << 1; //清除发送完成标志位
//W25QXX 设置 QPI 相关读参数0XC0
while (QUADSPI->SR & (1 << 5))
; //等待 BUSY 位清零
QUADSPI->CCR = 0X030003C0; //发送 0XC0 指令W25QXX 读参数设置
QUADSPI->DLR = 0;
while ((QUADSPI->SR & (1 << 2)) == 0)
; //等待 FTF
*(volatile uint8_t *)data_reg = 3 << 4; //设置 P4&P5=118 个 dummy clocks104M
QUADSPI->CR |= 1 << 2; //终止传输
while ((QUADSPI->SR & (1 << 1)) == 0)
; //等待数据发送完成
QUADSPI->FCR |= 1 << 1; //清除发送完成标志位
while (QUADSPI->SR & (1 << 5))
; //等待 BUSY 位清零
//MemroyMap 模式设置
while (QUADSPI->SR & (1 << 5))
; //等待 BUSY 位清零
QUADSPI->ABR = 0; //交替字节设置为 0实际上就是 W25Q 0XEB 指令的 M0~M7=0
tempreg = 0XEB; //INSTRUCTION[7:0]=0XEB发送 0XEB 指令Fast Read QUAD I/O
tempreg |= 3 << 8; //IMODE[1:0]=3四线传输指令
tempreg |= 3 << 10; //ADDRESS[1:0]=3四线传输地址
tempreg |= 2 << 12; //ADSIZE[1:0]=224位地址长度
tempreg |= 3 << 14; //ABMODE[1:0]=3四线传输交替字节
tempreg |= 0 << 16; //ABSIZE[1:0]=08位交替字节 (M0~M7)
tempreg |= 6 << 18; //DCYC[4:0]=66个dummy周期
tempreg |= 3 << 24; //DMODE[1:0]=3四线传输数据
tempreg |= 3 << 26; //FMODE[1:0]=3内存映射模式
QUADSPI->CCR = tempreg; //设置CCR寄存器
//设置 QSPI FLASH 空间的MPU保护
SCB->SHCSR &= ~(1 << 16); //禁止 MemManage
MPU->CTRL &= ~(1 << 0); //禁止 MPU
MPU->RNR = 0; //设置保护区域编号为 0 (1~7 可以给其他内存用)
MPU->RBAR = 0X90000000; //基地址为 0X9000 000即 QSPI 的起始地址
MPU->RASR = 0X0303002D; //设置相关保护参数(禁止共用,允许 cache允许缓冲)
MPU->CTRL = (1 << 2) | (1 << 0); //使能 PRIVDEFENA使能 MPU
SCB->SHCSR |= 1 << 16; //使能 MemManage
while (1)
;
}
#if defined(__clang__) //使用V6编译器(clang)
//THUMB指令不支持汇编内联
//采用如下方法实现执行汇编指令WFI
void __attribute__((noinline)) WFI_SET(void)
{
__asm__("wfi");
}
//关闭所有中断(但是不包括fault和NMI中断)
void __attribute__((noinline)) INTX_DISABLE(void)
{
__asm__("cpsid i \t\n"
"bx lr");
}
//开启所有中断
void __attribute__((noinline)) INTX_ENABLE(void)
{
__asm__("cpsie i \t\n"
"bx lr");
}
//设置栈顶地址
//addr:栈顶地址
void __attribute__((noinline)) MSR_MSP(uint32_t addr)
{
__asm__("msr msp, r0 \t\n"
"bx r14");
}
#elif defined(__CC_ARM) //使用V5编译器(ARMCC)
//THUMB指令不支持汇编内联
//采用如下方法实现执行汇编指令WFI
__asm void WFI_SET(void)
{
WFI;
}
//关闭所有中断(但是不包括fault和NMI中断)
__asm void INTX_DISABLE(void)
{
CPSID I
BX LR
}
//开启所有中断
__asm void INTX_ENABLE(void)
{
CPSIE I
BX LR
}
//设置栈顶地址
//addr:栈顶地址
__asm void MSR_MSP(uint32_t addr)
{
MSR MSP, r0 //set Main Stack value
BX r14
}
#endif

View File

@ -1,4 +1,4 @@
//ϵͳ³õʼ»¯
//系统常用调用
#ifndef __SYS_H
#define __SYS_H
@ -7,25 +7,16 @@
#include "core_cm7.h"
#include "stm32h7xx_hal.h"
#define Write_Through() (*(__IO uint32_t *)0XE000EF9C = 1UL << 2) //Cache ͸дģʽ
//开关全局中断的宏
#define ENABLE_INT() __set_PRIMASK(0) //使能全局中断
#define DISABLE_INT() __set_PRIMASK(1) //禁止全局中断
void MPU_Config(void);
void Cache_Enable(void);
uint8_t Clock_Init(uint32_t plln, uint32_t pllm, uint32_t pllp, uint32_t pllq);
void SystemClock_Init(void);
uint8_t Get_ICacheSta(void);
uint8_t Get_DCacheSta(void);
void QSPI_Enable_Memmapmode(void);
#if defined(__clang__)
void __attribute__((noinline)) WFI_SET(void);
void __attribute__((noinline)) INTX_DISABLE(void);
void __attribute__((noinline)) INTX_ENABLE(void);
void __attribute__((noinline)) MSR_MSP(uint32_t addr);
#elif defined(__CC_ARM)
void WFI_SET(void);
void INTX_DISABLE(void);
void INTX_ENABLE(void);
void MSR_MSP(uint32_t addr);
#endif
void Error_Handler(char *file, uint32_t line);
#endif

View File

@ -1,7 +1,9 @@
//阅读器应用
#include "stdio.h"
#include "sys.h"
#include "delay.h"
#include "systick.h"
#include "key.h"
#include "lcd.h"
@ -56,6 +58,7 @@ uint8_t APP_Reader_Menu(void);
uint8_t APP_Reader_SaveWrite(void);
uint8_t APP_Reader_SaveRead(void);
void APP_Reader_Msg(uint8_t *head, uint8_t *content);
void APP_Reader_Msg_NoBlock(uint8_t *head, uint8_t *content);
/*****************************************************************************************/
@ -65,8 +68,10 @@ void APP_Reader_Msg(uint8_t *head, uint8_t *content);
void APP_Reader_Launcher(void)
{
//GUI 选取文件
if (SD_SelectFile(filename, "txt") != SD_OK)
uint8_t ret;
if ((ret = SD_SelectFile(filename, "txt")) != SD_OK)
{
if (ret == SD_ERROR)
APP_Reader_Msg("警告", "选取文件出错!\n\n请按任意键返回");
return;
@ -104,28 +109,26 @@ void APP_Reader_Launcher(void)
f_open(&page_file, page_filepath, FA_OPEN_EXISTING | FA_READ); //打开分页文件
while (1)
{
LCD_Disp_Off;
GE_Draw_ClrAll(WHITE);
if (APP_Reader_ReadPage(current_font_size, current_page) != 0)
{
GE_Draw_ClrAll(WHITE);
LCD_Disp_On;
APP_Reader_Msg("警告", "发生错误!\n\n请按任意键返回");
return;
}
LCD_Disp_On;
switch (KEY_GetKeyWait())
{
case KEY1: //设置菜单
case JOY_L_UP: //设置菜单
{
if (APP_Reader_Menu() != 0)
return;
}
break;
case KEY2: //向后翻页
case JOY_D_DOWN: //向后翻页
{
if (current_page == page_amount)
APP_Reader_Msg("提示", "已到最后一页!");
@ -133,17 +136,14 @@ void APP_Reader_Launcher(void)
current_page++;
}
break;
case KEY3: //目前不存在此键
case JOY_U_DOWN: //向前翻页
{
if (current_page == 1)
APP_Reader_Msg("提示", "已到第一页!");
else
current_page--;
}
break;
case KEY4: //目前不存在此键
{
}
}
}
}
@ -176,16 +176,23 @@ uint8_t APP_Reader_ReadPage(uint8_t font_size, uint32_t page_num)
*((uint8_t *)buffer + page.page_size) = '\0';
if (font_size == FONT_16)
ge_font_print_set.font_size = FONT_16;
else
ge_font_print_set.font_size = FONT_24;
GE_Font_Print(0, 0, BORDER_MAX, BORDER_MAX, font_size, BLACK, WHITE, TRUE, buffer);
GE_Font_Print_WithSet(0, 0, BORDER_MAX, BORDER_MAX, buffer);
GE_Font_Print(
1,
223,
BORDER_MAX,
BORDER_MAX,
FONT_16,
BLUE,
WHITE,
TRUE,
"页数:%d/%d %.1f%%",
page_num,
page_amount,
(float)page_num / (float)page_amount * 100.0);
char temp_str[15];
sprintf(temp_str, "页数:%d/%d %.1f%%", page_num, page_amount, (float)page_num / (float)page_amount * 100.0);
GE_Font_Print(1, 223, BORDER_MAX, BORDER_MAX, FONT_16, BLUE, WHITE, TRUE, temp_str);
GE_Draw_Disp();
return 0;
}
@ -197,6 +204,8 @@ uint8_t APP_Reader_ReadPage(uint8_t font_size, uint32_t page_num)
*/
uint8_t APP_Reader_SplitPages(uint8_t font_size)
{
APP_Reader_Msg_NoBlock("提示", "正在分页中...\n\n请稍等");
uint32_t br;
FRESULT f_res;
char ch;
@ -314,12 +323,18 @@ uint8_t APP_Reader_SplitPages(uint8_t font_size)
*/
uint8_t APP_Reader_Menu(void)
{
uint8_t content[2][GE_GUI_MENUBOX_CONTENT_LEN] = {"字体设置", "退出"};
uint8_t content[3][GE_GUI_MENUBOX_CONTENT_LEN] = {"字体设置", "退出阅读器", "返回"};
GE_Draw_Fill(50, 50, 220, 140, WHITE);
switch (GE_GUI_MenuBox(50, 50, 220, 140, "菜单", 2, content, NULL))
switch (GE_GUI_MenuBox(50, 50, 220, 140, "菜单", 3, content, NULL))
{
case 1:
case 0: //返回
{
KEY_ClearKey();
}
break;
case 1: //字体设置
{
GE_Draw_Fill(50, 50, 220, 140, WHITE);
@ -361,7 +376,7 @@ uint8_t APP_Reader_Menu(void)
}
break;
case 2:
case 2: //退出
{
//关闭文件
f_close(&page_file);
@ -372,6 +387,10 @@ uint8_t APP_Reader_Menu(void)
return 1;
}
break;
case 3: //返回
{
}
}
return 0;
@ -447,5 +466,16 @@ void APP_Reader_Msg(uint8_t *head, uint8_t *content)
{
GE_Draw_Fill(60, 75, 200, 90, WHITE);
GE_GUI_MsgBox(60, 75, 200, 90, head, content, NULL);
KEY_GetKeyWait();
KEY_WaitKey(JOY_L);
}
/**
* @brief 退
* @param head:
* @param content:
*/
void APP_Reader_Msg_NoBlock(uint8_t *head, uint8_t *content)
{
GE_Draw_Fill(60, 75, 200, 90, WHITE);
GE_GUI_MsgBox(60, 75, 200, 90, head, content, NULL);
}

View File

@ -1,3 +1,5 @@
//阅读器应用
#ifndef __APP_READER
#define __APP_READER

View File

@ -1,8 +1,8 @@
//游戏引擎图像绘制库
#include "stdlib.h"
#include "string.h"
#include "sys.h"
#include "spi.h"
#include "lcd.h"
@ -10,81 +10,40 @@
#include "GE_Draw.h"
/**************************************** 私有函数 ****************************************/
/**************************************** 显存 ****************************************/
void GE_Draw_SetWinAbs(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end);
void GE_Draw_SetWin(uint16_t x, uint16_t y, uint16_t width, uint16_t height);
uint8_t GE_Draw_VRam[153600];
/*****************************************************************************************/
_ge_draw_set_private ge_draw_set_private;
_ge_draw_pic_set ge_draw_pic_set;
_ge_draw_mono_set ge_draw_mono_set;
/**
* @brief GE_Draw
*/
void GE_Draw_Init(void)
{
//私有变量
ge_draw_set_private.x_start = 0;
ge_draw_set_private.y_start = 0;
ge_draw_set_private.x_end = LCD_WIDTH - 1;
ge_draw_set_private.y_end = LCD_HEIGHT - 1;
//绘制图片设置
ge_draw_pic_set.is_reverse = FALSE;
ge_draw_pic_set.pos_mode = UP_LEFT;
//绘制单色图设置
ge_draw_mono_set.draw_mode = MONO_OR;
ge_draw_mono_set.pos_mode = UP_LEFT;
ge_draw_mono_set.mono_color = BLACK;
ge_draw_mono_set.back_color = WHITE;
GE_Draw_ClrAll(WHITE);
}
/**
* @brief 使
* @param x_start: 0~319
* @param y_start: 0~239
* @param x_end: 0~319
* @param y_end: 0~239
* @brief
*/
void GE_Draw_SetWinAbs(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end)
void GE_Draw_Disp(void)
{
if (x_end == ge_draw_set_private.x_end && y_end == ge_draw_set_private.y_end)
{
if (x_start == ge_draw_set_private.x_start && y_start == ge_draw_set_private.y_start)
{
return;
}
else
{
ge_draw_set_private.x_start = x_start;
ge_draw_set_private.y_start = y_start;
LCD_SendCmdData16Bits(LCD_CMD_CASET, x_start);
LCD_SendCmdData16Bits(LCD_CMD_PASET, y_start);
}
}
else
{
ge_draw_set_private.x_start = x_start;
ge_draw_set_private.y_start = y_start;
ge_draw_set_private.x_end = x_end;
ge_draw_set_private.y_end = y_end;
LCD_SendCmdData32Bits(LCD_CMD_CASET, (x_start << 16) | x_end);
LCD_SendCmdData32Bits(LCD_CMD_PASET, (y_start << 16) | y_end);
}
}
/**
* @brief 使
* @param x: 0~319
* @param y: 0~239x y
* @param width: 0
* @param height: 0
*/
void GE_Draw_SetWin(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
{
GE_Draw_SetWinAbs(x, y, x + width - 1, y + height - 1);
LCD_SetWin(0, 0, LCD_WIDTH, LCD_HEIGHT);
LCD_SendCmdDataBytes(LCD_CMD_RAMWR, GE_Draw_VRam, 153600);
}
/**
@ -104,17 +63,21 @@ void GE_Draw_ClrAll(uint16_t color)
* @param height:
* @param color:
*/
void GE_Draw_Fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color)
void GE_Draw_Fill(int16_t x, int16_t y, uint16_t width, uint16_t height, uint16_t color)
{
GE_Draw_SetWin(x, y, width, height);
uint32_t point_num = width * height;
int16_t x0 = x, y0 = y;
uint32_t data16_count = width * height;
for (uint32_t i = 0; i < point_num; i++)
{
GE_Draw_Point(x++, y, color);
LCD_RAM_Wr;
LCD_Data_Mode_On;
for (uint32_t i = 0; i < data16_count; i++)
SPI2_Write16Bits(color);
if (x == x0 + width)
{
y++;
x = x0;
}
}
}
/**
@ -123,13 +86,26 @@ void GE_Draw_Fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint1
* @param y: 0~239
* @param color:
*/
void GE_Draw_Point(uint16_t x, uint16_t y, uint16_t color)
void GE_Draw_Point(int16_t x, int16_t y, uint16_t color)
{
if (x < 0 || x > LCD_WIDTH - 1 || y < 0 || y > LCD_HEIGHT - 1)
return;
GE_Draw_SetWinAbs(x, y, LCD_WIDTH - 1, LCD_HEIGHT - 1);
LCD_SendCmdData16Bits(LCD_CMD_RAMWR, color);
GE_Draw_VRam[(x + y * 320) * 2] = color >> 8;
GE_Draw_VRam[(x + y * 320) * 2 + 1] = color;
}
/**
* @brief
* @param x: 0~319
* @param y: 0~239
*/
uint16_t GE_Draw_GetPoint(int16_t x, int16_t y)
{
if (x < 0 || x > LCD_WIDTH - 1 || y < 0 || y > LCD_HEIGHT - 1)
return WHITE;
return ((uint16_t)GE_Draw_VRam[(x + y * 320) * 2] << 8) | GE_Draw_VRam[(x + y * 320) * 2 + 1];
}
/**
@ -140,7 +116,7 @@ void GE_Draw_Point(uint16_t x, uint16_t y, uint16_t color)
* @param y3: 0~239
* @param color:
*/
void GE_Draw_Line(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color)
void GE_Draw_Line(int16_t x0, int16_t y0, uint16_t x1, uint16_t y1, uint16_t color)
{
//使用 Bresenham 算法
int16_t dx = abs(x1 - x0);
@ -177,7 +153,7 @@ void GE_Draw_Line(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t c
* @param height:
* @param color:
*/
void GE_Draw_Rectangle(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color)
void GE_Draw_Rectangle(int16_t x, int16_t y, uint16_t width, uint16_t height, uint16_t color)
{
uint16_t i;
@ -201,7 +177,7 @@ void GE_Draw_Rectangle(uint16_t x, uint16_t y, uint16_t width, uint16_t height,
* @param r:
* @param color:
*/
void GE_Draw_Circle(uint16_t xm, uint16_t ym, uint16_t r, uint16_t color)
void GE_Draw_Circle(int16_t xm, int16_t ym, uint16_t r, uint16_t color)
{
int16_t x = -r, y = 0, err = 2 - 2 * r, rm = r;
@ -220,7 +196,8 @@ void GE_Draw_Circle(uint16_t xm, uint16_t ym, uint16_t r, uint16_t color)
}
/**
* @brief const unsigned char 4096
* @brief const unsigned char 4096
*
* @param x: 0~319
* @param y: 0~239
* @param is_reverse: TRUE
@ -230,36 +207,54 @@ void GE_Draw_Circle(uint16_t xm, uint16_t ym, uint16_t r, uint16_t color)
* @param height:
*/
void GE_Draw_Pic(
uint16_t x,
uint16_t y,
int16_t x,
int16_t y,
uint8_t is_reverse,
uint8_t pos_mode,
const unsigned char *pic,
uint16_t width,
uint16_t height)
{
if (pos_mode == UP_LEFT)
GE_Draw_SetWin(x, y, width, height);
else
GE_Draw_SetWin(x - width / 2, y - height / 2, width, height);
if (pos_mode == MID)
{
x = x - width / 2;
y = y - height / 2;
}
if (x == 0 && y == 0 && width == LCD_WIDTH && height == LCD_HEIGHT)
memcpy(GE_Draw_VRam, pic, 153600);
uint32_t point_num = width * height;
int16_t x0 = x, y0 = y;
uint16_t color;
if (is_reverse == TRUE) //反色模式
{
uint16_t data16_temp;
uint32_t data8_count = width * height * 2;
LCD_RAM_Wr;
LCD_Data_Mode_On;
for (uint32_t i = 0; i < data8_count; i += 2)
for (uint32_t i = 0; i < point_num; i++)
{
data16_temp = 0xffff - (((uint16_t)pic[i] << 8) | pic[i + 1]); //反色
SPI2_Write16Bits(data16_temp);
color = 0xffff - (((uint16_t)pic[2 * i] << 8) | pic[2 * i + 1]);
GE_Draw_Point(x++, y, color);
if (x == x0 + width)
{
y++;
x = x0;
}
}
}
else //非反色模式
{
LCD_SendCmdDataBytes(LCD_CMD_RAMWR, (uint8_t *)pic, width * height * 2);
for (uint32_t i = 0; i < point_num; i++)
{
color = ((uint16_t)pic[2 * i] << 8) | pic[2 * i + 1];
GE_Draw_Point(x++, y, color);
if (x == x0 + width)
{
y++;
x = x0;
}
}
}
}
@ -271,7 +266,7 @@ void GE_Draw_Pic(
* @param width:
* @param height:
*/
void GE_Draw_Pic_WithSet(uint16_t x, uint16_t y, const unsigned char *pic, uint16_t width, uint16_t height)
void GE_Draw_Pic_WithSet(int16_t x, int16_t y, const unsigned char *pic, uint16_t width, uint16_t height)
{
GE_Draw_Pic(
x,
@ -282,3 +277,106 @@ void GE_Draw_Pic_WithSet(uint16_t x, uint16_t y, const unsigned char *pic, uint1
width,
height);
}
/**
* @brief const unsigned char
*
* @param x: 0~319
* @param y: 0~239
* @param draw_mode: MONO_OR MONO_AND MONO_XOR MONO_COVER
* @param pos_mode: UP_LEFT MID
* @param mono_color:
* @param back_color: MONO_COVER
* @param pic:
* @param width:
* @param height:
*/
void GE_Draw_Mono(
int16_t x,
int16_t y,
uint8_t draw_mode,
uint8_t pos_mode,
uint16_t mono_color,
uint16_t back_color,
const unsigned char *pic,
uint16_t width,
uint16_t height)
{
if (pos_mode == MID)
{
x = x - width / 2;
y = y - height / 2;
}
uint8_t temp8;
int16_t x0 = x, y0 = y;
//循环横向输出
for (uint16_t i = 0; y - y0 < height; i++)
{
temp8 = pic[i];
for (uint16_t j = 0; j < 8; j++)
{
if (temp8 & 0x80)
{
if (
(draw_mode == MONO_OR) ||
(draw_mode == MONO_AND && GE_Draw_GetPoint(x, y) == mono_color) ||
(draw_mode == MONO_XOR && GE_Draw_GetPoint(x, y) != mono_color) ||
(draw_mode == MONO_COVER))
{
GE_Draw_Point(x, y, mono_color);
}
}
else
{
if (
(draw_mode == MONO_AND && GE_Draw_GetPoint(x, y) != mono_color) ||
(draw_mode == MONO_XOR && GE_Draw_GetPoint(x, y) == mono_color) ||
(draw_mode == MONO_COVER))
{
GE_Draw_Point(x, y, back_color);
}
}
temp8 <<= 1;
x++;
if (x - x0 == width)
{
x = x0;
y++;
break;
}
}
}
}
/**
* @brief 使 const unsigned char
*
* @param x: 0~319
* @param y: 0~239
* @param pic:
* @param width:
* @param height:
*/
void GE_Draw_Mono_WithSet(
int16_t x,
int16_t y,
const unsigned char *pic,
uint16_t width,
uint16_t height)
{
GE_Draw_Mono(
x,
y,
ge_draw_mono_set.draw_mode,
ge_draw_mono_set.pos_mode,
ge_draw_mono_set.mono_color,
ge_draw_mono_set.back_color,
pic,
width,
height);
}

View File

@ -3,7 +3,9 @@
#ifndef __GE_DRAW_H
#define __GE_DRAW_H
//ÑÕÉ«
#include "sys.h"
//颜色宏定义
#define BLACK 0x0000
#define NAVY 0x000f
#define DARK_GREEN 0x03e0
@ -21,14 +23,9 @@
#define YELLOW 0xffe0
#define WHITE 0xffff
/**************************************** ˽ÓбäÁ¿ ****************************************/
typedef struct
{
uint16_t x_start;
uint16_t y_start;
uint16_t x_end;
uint16_t y_end;
} _ge_draw_set_private;
/**************************************** 显存 ****************************************/
extern uint8_t GE_Draw_VRam[153600];
/*****************************************************************************************/
@ -38,6 +35,12 @@ void GE_Draw_Init(void);
/*****************************************************************************************/
/**************************************** 刷新屏幕 ****************************************/
void GE_Draw_Disp(void);
/*****************************************************************************************/
/**************************************** 清空屏幕 ****************************************/
void GE_Draw_ClrAll(uint16_t color);
@ -46,11 +49,14 @@ void GE_Draw_ClrAll(uint16_t color);
/**************************************** 绘图函数 ****************************************/
void GE_Draw_Fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
void GE_Draw_Point(uint16_t x, uint16_t y, uint16_t color);
void GE_Draw_Line(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
void GE_Draw_Rectangle(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
void GE_Draw_Circle(uint16_t xm, uint16_t ym, uint16_t r, uint16_t color);
void GE_Draw_Fill(int16_t x, int16_t y, uint16_t width, uint16_t height, uint16_t color);
void GE_Draw_Point(int16_t x, int16_t y, uint16_t color);
uint16_t GE_Draw_GetPoint(int16_t x, int16_t y);
void GE_Draw_Line(int16_t x0, int16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
void GE_Draw_Rectangle(int16_t x, int16_t y, uint16_t width, uint16_t height, uint16_t color);
void GE_Draw_Circle(int16_t xm, int16_t ym, uint16_t r, uint16_t color);
/*****************************************************************************************/
/**************************************** 绘制图片 ****************************************/
//显示位置
@ -66,14 +72,51 @@ typedef struct
extern _ge_draw_pic_set ge_draw_pic_set;
void GE_Draw_Pic(
uint16_t x,
uint16_t y,
int16_t x,
int16_t y,
uint8_t is_reverse,
uint8_t pos_mode,
const unsigned char *pic,
uint16_t width,
uint16_t height);
void GE_Draw_Pic_WithSet(uint16_t x, uint16_t y, const unsigned char *pic, uint16_t width, uint16_t height);
void GE_Draw_Pic_WithSet(int16_t x, int16_t y, const unsigned char *pic, uint16_t width, uint16_t height);
/*****************************************************************************************/
/************************************** 绘制单色位图 **************************************/
//是否绘制背景色
#define MONO_OR 0
#define MONO_AND 1
#define MONO_XOR 2
#define MONO_COVER 3
void GE_Draw_Mono(
int16_t x,
int16_t y,
uint8_t draw_mode,
uint8_t pos_mode,
uint16_t mono_color,
uint16_t back_color,
const unsigned char *pic,
uint16_t width,
uint16_t height);
typedef struct
{
uint8_t draw_mode; //绘制方式
uint8_t pos_mode; //显示位置
uint16_t mono_color; //颜色
uint16_t back_color; //背景颜色
} _ge_draw_mono_set;
extern _ge_draw_mono_set ge_draw_mono_set;
void GE_Draw_Mono_WithSet(
int16_t x,
int16_t y,
const unsigned char *pic,
uint16_t width,
uint16_t height);
/*****************************************************************************************/

View File

@ -1,13 +1,19 @@
//游戏引擎文字显示库
#include "stdio.h"
#include "sys.h"
#include "lcd.h"
#include "GameEngine.h"
#include "GE_Font.h"
#define GE_Font_GetACSIIDataSize(__FONT_SIZE__) ((__FONT_SIZE__ / 8 + ((__FONT_SIZE__ % 8) ? 1 : 0)) * (__FONT_SIZE__ / 2))
#define GE_Font_GetGBKDataSize(__FONT_SIZE__) ((__FONT_SIZE__ / 8 + ((__FONT_SIZE__ % 8) ? 1 : 0)) * (__FONT_SIZE__))
/**************************************** 私有定义 ****************************************/
#define GE_Font_GetACSIIDataSize(__font_size__) ((__font_size__ / 8 + ((__font_size__ % 8) ? 1 : 0)) * (__font_size__ / 2))
#define GE_Font_GetGBKDataSize(__font_size__) ((__font_size__ / 8 + ((__font_size__ % 8) ? 1 : 0)) * (__font_size__))
/*****************************************************************************************/
/**************************************** 私有函数 ****************************************/
@ -213,27 +219,30 @@ uint8_t GE_Font_PrintGBK(uint16_t x, uint16_t y, uint8_t *ch, uint8_t font_size,
* @param y_start
* @param width:
* @param height:
* @param font_size: 使 FONT_12 24 32 48
* @param font_size: 使 FONT_12 16 24 32
* @param font_color:
* @param back_color:
* @param is_transparent:
* @param str: uint8_t *
* @param format:
* @param arg:
* @retval 10
*/
uint8_t GE_Font_Print(
uint16_t x_start,
uint16_t y_start,
uint8_t GE_Font_Print_Va(
int16_t x_start,
int16_t y_start,
uint16_t width,
uint16_t height,
uint8_t font_size,
uint16_t font_color,
uint16_t back_color,
uint8_t is_transparent,
uint8_t *str)
uint8_t *format,
va_list arg)
{
uint16_t x_end_plus_1;
uint16_t y_end_plus_1;
uint16_t x = x_start;
uint16_t y = y_start;
int16_t x_end_plus_1;
int16_t y_end_plus_1;
int16_t x = x_start;
int16_t y = y_start;
if (width == BORDER_MAX)
x_end_plus_1 = LCD_WIDTH;
@ -247,6 +256,11 @@ uint8_t GE_Font_Print(
uint8_t is_print_all = FALSE;
uint8_t temp_str[1040];
uint8_t *str = temp_str;
vsprintf(str, format, arg);
while (1)
{
if (*(str) <= 0x80) //ASCII 字符
@ -301,17 +315,70 @@ uint8_t GE_Font_Print(
return is_print_all;
}
/**
* @brief ASCIIGBK
* @param x_start
* @param y_start
* @param width:
* @param height:
* @param font_size: 使 FONT_12 16 24 32
* @param font_color:
* @param back_color:
* @param is_transparent:
* @param format: printf
* @param ...
* @retval 10
*/
uint8_t GE_Font_Print(
int16_t x_start,
int16_t y_start,
uint16_t width,
uint16_t height,
uint8_t font_size,
uint16_t font_color,
uint16_t back_color,
uint8_t is_transparent,
uint8_t *format,
...)
{
va_list aptr;
va_start(aptr, format);
uint8_t ret = GE_Font_Print_Va(
x_start,
y_start,
width,
height,
font_size,
font_color,
back_color,
is_transparent,
format,
aptr);
va_end(aptr);
return ret;
}
/**
* @brief 使 ASCIIGBK
* @param x_start
* @param y_start
* @param width:
* @param height:
* @param str: uint8_t *
* @param format:
* @param arg:
* @retval 10
*/
uint8_t GE_Font_Print_WithSet(uint16_t x_start, uint16_t y_start, uint16_t width, uint16_t height, uint8_t *str)
uint8_t GE_Font_Print_WithSet_Va(
int16_t x_start,
int16_t y_start,
uint16_t width,
uint16_t height,
uint8_t *format,
va_list arg)
{
return GE_Font_Print(
return GE_Font_Print_Va(
x_start,
y_start,
width,
@ -320,5 +387,39 @@ uint8_t GE_Font_Print_WithSet(uint16_t x_start, uint16_t y_start, uint16_t width
ge_font_print_set.font_color,
ge_font_print_set.back_color,
ge_font_print_set.is_transparent,
str);
format,
arg);
}
/**
* @brief 使 ASCIIGBK
* @param x_start
* @param y_start
* @param width:
* @param height:
* @param format: printf
* @param ...
* @retval 10
*/
uint8_t GE_Font_Print_WithSet(
int16_t x_start,
int16_t y_start,
uint16_t width,
uint16_t height,
uint8_t *format,
...)
{
va_list aptr;
va_start(aptr, format);
uint8_t ret = GE_Font_Print_WithSet_Va(
x_start,
y_start,
width,
height,
format,
aptr);
va_end(aptr);
return ret;
}

View File

@ -3,6 +3,8 @@
#ifndef __GE_FONT_H
#define __GE_FONT_H
#include "stdarg.h"
void GE_FontInit(void);
/**************************************** »æÖƺº×Ö ****************************************/
@ -27,18 +29,45 @@ typedef struct
extern _ge_font_print_set ge_font_print_set;
uint8_t GE_Font_Print(
uint16_t x_start,
uint16_t y_start,
uint8_t GE_Font_Print_Va(
int16_t x_start,
int16_t y_start,
uint16_t width,
uint16_t height,
uint8_t font_size,
uint16_t font_color,
uint16_t back_color,
uint8_t is_transparent,
uint8_t *str);
uint8_t *format,
va_list arg);
uint8_t GE_Font_Print_WithSet(uint16_t x_start, uint16_t y_start, uint16_t width, uint16_t height, uint8_t *str);
uint8_t GE_Font_Print(
int16_t x_start,
int16_t y_start,
uint16_t width,
uint16_t height,
uint8_t font_size,
uint16_t font_color,
uint16_t back_color,
uint8_t is_transparent,
uint8_t *format,
...);
uint8_t GE_Font_Print_WithSet_Va(
int16_t x_start,
int16_t y_start,
uint16_t width,
uint16_t height,
uint8_t *format,
va_list arg);
uint8_t GE_Font_Print_WithSet(
int16_t x_start,
int16_t y_start,
uint16_t width,
uint16_t height,
uint8_t *format,
...);
/*****************************************************************************************/

View File

@ -74,7 +74,7 @@ void GE_GUI_DoubleThickRectangle(uint16_t x, uint16_t y, uint16_t width, uint16_
}
/**
* @brief
* @brief
* @param x
* @param y
* @param width:
@ -97,13 +97,17 @@ void GE_GUI_MsgBox(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint
//内容
GE_Font_Print(x + 6, y + FONT_16 + 10, width - 12, BORDER_MAX, FONT_16, BLACK, WHITE, FALSE, content);
GE_Draw_Disp();
KEY_ClearKey();
//调用回调函数
if (handler_func != NULL)
handler_func();
}
/**
* @brief
* @brief
* @param x
* @param y
* @param width:
@ -112,7 +116,7 @@ void GE_GUI_MsgBox(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint
* @param content_amount:
* @param content:
* @param handler_func: NULL
* @retval 1
* @retval 1 0 JOY_L_DOWN
*/
uint8_t GE_GUI_MenuBox(
uint16_t x,
@ -144,25 +148,37 @@ uint8_t GE_GUI_MenuBox(
GE_GUI_TextBox(x + 4, y + FONT_16 + 8 + i * (FONT_16 + 3), width - 8, FONT_16 + 4, BLACK, WHITE, BLACK, 1, content[i]);
}
GE_Draw_Disp();
KEY_ClearKey();
while (1)
{
uint8_t key = KEY_GetKeyWait();
if (key == KEY2)
if (key == JOY_OK_UP)
{
break;
}
else if (key == KEY3 && choice_num > 1)
else if (key == JOY_L_DOWN)
{
return 0;
}
else if (key == JOY_U_DOWN && choice_num > 1)
{
GE_GUI_TextBox(x + 4, y + FONT_16 + 8 + (choice_num - 1) * (FONT_16 + 3), width - 8, FONT_16 + 4, BLACK, WHITE, BLACK, 1, content[choice_num - 1]);
choice_num--;
GE_GUI_TextBox(x + 4, y + FONT_16 + 8 + (choice_num - 1) * (FONT_16 + 3), width - 8, FONT_16 + 4, WHITE, BLUE, BLACK, 1, content[choice_num - 1]);
GE_Draw_Disp();
}
else if (key == KEY1 && choice_num < content_amount)
else if (key == JOY_D_DOWN && choice_num < content_amount)
{
GE_GUI_TextBox(x + 4, y + FONT_16 + 8 + (choice_num - 1) * (FONT_16 + 3), width - 8, FONT_16 + 4, BLACK, WHITE, BLACK, 1, content[choice_num - 1]);
choice_num++;
GE_GUI_TextBox(x + 4, y + FONT_16 + 8 + (choice_num - 1) * (FONT_16 + 3), width - 8, FONT_16 + 4, WHITE, BLUE, BLACK, 1, content[choice_num - 1]);
GE_Draw_Disp();
}
}

View File

@ -9,17 +9,6 @@ typedef void (*MenuBoxHandler)(uint8_t choice_num);
void GE_GUI_Init(void);
void GE_GUI_TextBox(
uint16_t x,
uint16_t y,
uint16_t width,
uint16_t height,
uint16_t font_color,
uint16_t fill_color,
uint16_t rectangle_color,
uint16_t thickness,
uint8_t *str);
void GE_GUI_MsgBox(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t *head, uint8_t *content, MsgBoxHandler func);
#define GE_GUI_MENUBOX_MAX_CONTENT_NUM 10 //适用参数 5, 5, 310, 230

View File

@ -1,7 +1,7 @@
//ÓÎÏ·ÒýÇæ
#include "sys.h"
#include "delay.h"
#include "systick.h"
#include "led.h"
#include "lcd.h"

View File

@ -1,21 +1,38 @@
#include "stdio.h"
#include "sys.h"
#include "delay.h"
#include "systick.h"
#include "led.h"
#include "key.h"
#include "lcd.h"
#include "uart.h"
#include "adc.h"
#include "hc25.h"
#include "GameEngine.h"
#include "SD.h"
#include "WLAN.h"
#include "Clock.h"
#include "APP_Reader.h"
#include "APP_Video.h"
#include "APP_Plane.h"
#include "APP_Setting.h"
#include "APP_Weather.h"
int main(void)
{
MPU_Config(); //ÅäÖÃ MPU
Cache_Enable(); //´ò¿ª L1-Cache
HAL_Init(); //³õʼ»¯ HAL ¿â
Clock_Init(160, 5, 2, 4); //设置时钟为 400MHz
SYSCLK_Init(400); //延时初始化
SystemClock_Init(); //设置时钟
Uart_Init(); //初始化串口
SysTick_Init(); //配置 SysTick 中断,并初始化软件定时器
ADC_Init(); //初始化 ADC
Uart_SetprintfCom(COM1); //设置 printf 输出到 COM1
Uart_SetgetcharCom(COM1); //设置 getchar 从 COM1 输入
//³õʼ»¯ÍâÉè
LED_Init();
@ -24,17 +41,58 @@ int main(void)
//³õʼ»¯Ä£¿é
GE_Init();
if (SD_Init() == SD_OK)
{
APP_Reader_Launcher();
SD_DeInit();
SD_Init();
GE_Draw_ClrAll(WHITE);
GE_Draw_Pic_WithSet(0, 0, BORDER_MAX, BORDER_MAX, "阅读器运行结束,请重置!");
}
GE_Draw_Disp();
SD_Init();
printf("完成系统初始化\n");
HC25_Init();
Clock_Init();
uint8_t content[5][GE_GUI_MENUBOX_CONTENT_LEN] = {"阅读器", "视频播放器", "飞机大战", "天气", "设置"};
while (1)
{
GE_Draw_ClrAll(WHITE);
switch (GE_GUI_MenuBox(5, 5, 310, 230, "STM32Player", 5, content, NULL))
{
case 1:
{
GE_Draw_ClrAll(WHITE);
APP_Reader_Launcher();
}
break;
case 2:
{
GE_Draw_ClrAll(WHITE);
APP_Video_Launcher();
}
break;
case 3:
{
GE_Draw_ClrAll(WHITE);
APP_Plane_Launcher();
}
break;
case 4:
{
GE_Draw_ClrAll(WHITE);
APP_Weather_Launcher();
}
break;
case 5:
{
GE_Draw_ClrAll(WHITE);
APP_Setting_Launcher();
}
}
}
}

View File

@ -1 +1,9 @@
extern const unsigned char pic_minecraft[153600];
//ͼƬ
#ifndef __PICTURE_H
#define __PICTURE_H
extern const unsigned char test_pic[8850];
extern const unsigned char mono_testpic[590];
#endif

File diff suppressed because it is too large Load Diff

View File

@ -91,7 +91,7 @@ uint8_t SD_GetPath(uint8_t *filepath, uint8_t *filename)
* @brief SD GUI
* @param filepath:
* @param filesuffix: NULL
* @retval 0 1
* @retval 0 1 JOY_L 2
*/
uint8_t SD_SelectFile(uint8_t *filename, uint8_t *filesuffix)
{
@ -134,6 +134,9 @@ uint8_t SD_SelectFile(uint8_t *filename, uint8_t *filesuffix)
uint8_t choice = GE_GUI_MenuBox(5, 5, 310, 230, "请选择文件:", num, content, NULL);
if (choice == 0)
return 2;
strcpy(filename, content[choice - 1]);
return SD_OK;
}