加入屏幕翻转的功能

This commit is contained in:
不吃油炸鸡
2025-10-18 19:23:22 +08:00
parent 5e4040aad4
commit cc3f9d243c
8 changed files with 43 additions and 7 deletions

View File

@@ -1,6 +1,13 @@
#include "BL24C02.h"
#include "i2c.h"
SysSettings_T sys_settings = {
.backlight_level = 80,
.key_sound_enable = 1,
.language_select = 0,
.rotation = 0
};
static void BL24C02_Write(uint8_t addr, uint16_t length, uint8_t buff[])
{
HAL_I2C_Mem_Write(&hi2c1, BL24C02_ADDRESS<<1, addr, I2C_MEMADD_SIZE_8BIT, buff, length, 10);

View File

@@ -5,6 +5,15 @@
#define BL24C02_ADDRESS 0x50
typedef struct {
uint8_t backlight_level; // 0-100
uint8_t key_sound_enable; // 0:disable, 1:enable
uint8_t language_select; // 0:English, 1:Chinese
uint16_t rotation; // 0, 90, 180, 270
} SysSettings_T;
extern SysSettings_T sys_settings;
uint8_t EEPROM_Check(void);
uint8_t SettingSave(uint8_t *buf, uint8_t addr, uint8_t lenth);
uint8_t SettingGet(uint8_t *buf, uint8_t addr, uint8_t lenth);

View File

@@ -15,7 +15,7 @@ extern osSemaphoreId_t DMA_SemaphoreHandle;
void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color)
{
u16 i,j;
LCD_Address_Set(xsta,ysta+OFFSET_Y,xend-1,yend-1+OFFSET_Y);//设置显示范围
LCD_Address_Set(xsta+OFFSET_X, ysta+OFFSET_Y,xend-1+OFFSET_X, yend-1+OFFSET_Y);//设置显示范围
for(i=ysta;i<yend;i++)
{
for(j=xsta;j<xend;j++)
@@ -39,7 +39,7 @@ void LCD_Color_Render(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 *color_p)
height = yend-ysta+1;
uint32_t size = width * height;
LCD_Address_Set(xsta,ysta+OFFSET_Y,xend,yend+OFFSET_Y);
LCD_Address_Set(xsta+OFFSET_X, ysta+OFFSET_Y, xend+OFFSET_X, yend+OFFSET_Y);
hspi2.Init.DataSize = SPI_DATASIZE_16BIT;
hspi2.Instance->CR1|=SPI_CR1_DFF;

View File

@@ -184,24 +184,32 @@ void LCD_ST7789_SleepOut(void)
入口数据rotation 0, 90, 180, 270
返回值: 无
******************************************************************************/
void LCD_SetRotation(uint8_t rotation) {
void LCD_SetRotation(uint16_t rotation) {
LCD_WR_REG(0x36); // Memory Data Access Control
switch(rotation) {
case 0:
OFFSET_X = 0;
OFFSET_Y = 0;
LCD_WR_DATA8(0x00);
break;
case 180:
OFFSET_X = 0;
OFFSET_Y = 80;
LCD_WR_DATA8(0xC0);
break;
case 90:
OFFSET_X = 0;
OFFSET_Y = 0;
LCD_WR_DATA8(0x70);
break;
case 270:
OFFSET_X = 80;
OFFSET_Y = 0;
LCD_WR_DATA8(0xA0);
break;
default:
OFFSET_X = 0;
OFFSET_Y = 0;
LCD_WR_DATA8(0x00);
break;
}

View File

@@ -59,6 +59,8 @@ void LCD_Close_Light(void);
void LCD_ST7789_SleepIn(void);
void LCD_ST7789_SleepOut(void);
void LCD_Open_Light(void);
void LCD_SetRotation(uint16_t rotation);
#endif