增加LCD动态翻转的函数

This commit is contained in:
不吃油炸鸡
2025-10-09 19:55:18 +08:00
parent 9527dd21ce
commit 92db314c84
4 changed files with 36 additions and 25 deletions

View File

@@ -4,17 +4,6 @@
#include "spi.h"
#include "cmsis_os.h"
#if USE_HORIZONTAL == 0
#define OFFSET_Y 0
#define OFFSET_X 0
#elif USE_HORIZONTAL == 1
#define OFFSET_Y 80
#define OFFSET_X 0
#else
#define OFFSET_Y 0
#define OFFSET_X 0
#endif
extern osSemaphoreId_t DMA_SemaphoreHandle;
/******************************************************************************
函数说明:在指定区域填充颜色

View File

@@ -2,6 +2,10 @@
#include "spi.h"
#include "tim.h"
uint8_t LCD_ROTATION = 0; // 0, 90, 180, 270
uint8_t OFFSET_X = 0;
uint8_t OFFSET_Y = 0;
/******************************************************************************
函数说明LCD端口初始化
入口数据:无
@@ -175,6 +179,33 @@ void LCD_ST7789_SleepOut(void)
HAL_Delay(100);
}
/******************************************************************************
函数说明:设置屏幕旋转方向
入口数据rotation 0, 90, 180, 270
返回值: 无
******************************************************************************/
void LCD_SetRotation(uint8_t rotation) {
LCD_WR_REG(0x36); // Memory Data Access Control
switch(rotation) {
case 0:
OFFSET_Y = 0;
LCD_WR_DATA8(0x00);
break;
case 180:
OFFSET_Y = 80;
LCD_WR_DATA8(0xC0);
break;
case 90:
LCD_WR_DATA8(0x70);
break;
case 270:
LCD_WR_DATA8(0xA0);
break;
default:
LCD_WR_DATA8(0x00);
break;
}
}
/******************************************************************************
函数说明LCD初始化
@@ -194,10 +225,7 @@ void LCD_Init(void)
LCD_WR_REG(0x11);
HAL_Delay(120);
LCD_WR_REG(0x36);
if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x00);
else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC0);
else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x70);
else LCD_WR_DATA8(0xA0);
LCD_SetRotation(LCD_ROTATION);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x05);

View File

@@ -3,19 +3,13 @@
#include "sys.h"
#define USE_HORIZONTAL 1 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏
extern uint8_t LCD_ROTATION;
extern uint8_t OFFSET_X;
extern uint8_t OFFSET_Y;
#if USE_HORIZONTAL==0||USE_HORIZONTAL==1
#define LCD_W 240
#define LCD_H 240
#else
#define LCD_W 240
#define LCD_H 240
#endif
//-----------------LCD端口定义----------------
#define SCLK_PORT GPIOB
#define SCLK_PIN GPIO_PIN_13

View File

@@ -75,7 +75,7 @@ int main(void)
/* USER CODE BEGIN 1 */
//this must set same as keil setting
SCB->VTOR = 0x00000000U;
SCB->VTOR = FLASH_BASE + 0x00000000;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/