加入屏幕翻转的功能

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 "BL24C02.h"
#include "i2c.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[]) 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); 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 #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 EEPROM_Check(void);
uint8_t SettingSave(uint8_t *buf, uint8_t addr, uint8_t lenth); uint8_t SettingSave(uint8_t *buf, uint8_t addr, uint8_t lenth);
uint8_t SettingGet(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) void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color)
{ {
u16 i,j; 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(i=ysta;i<yend;i++)
{ {
for(j=xsta;j<xend;j++) 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; height = yend-ysta+1;
uint32_t size = width * height; 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.Init.DataSize = SPI_DATASIZE_16BIT;
hspi2.Instance->CR1|=SPI_CR1_DFF; hspi2.Instance->CR1|=SPI_CR1_DFF;

View File

@@ -184,24 +184,32 @@ void LCD_ST7789_SleepOut(void)
入口数据rotation 0, 90, 180, 270 入口数据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 LCD_WR_REG(0x36); // Memory Data Access Control
switch(rotation) { switch(rotation) {
case 0: case 0:
OFFSET_X = 0;
OFFSET_Y = 0; OFFSET_Y = 0;
LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00);
break; break;
case 180: case 180:
OFFSET_X = 0;
OFFSET_Y = 80; OFFSET_Y = 80;
LCD_WR_DATA8(0xC0); LCD_WR_DATA8(0xC0);
break; break;
case 90: case 90:
OFFSET_X = 0;
OFFSET_Y = 0;
LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x70);
break; break;
case 270: case 270:
OFFSET_X = 80;
OFFSET_Y = 0;
LCD_WR_DATA8(0xA0); LCD_WR_DATA8(0xA0);
break; break;
default: default:
OFFSET_X = 0;
OFFSET_Y = 0;
LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00);
break; break;
} }

View File

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

View File

@@ -134,10 +134,12 @@ void disp_disable_update(void)
*'lv_display_flush_ready()' has to be called when it's finished.*/ *'lv_display_flush_ready()' has to be called when it's finished.*/
static void disp_flush(lv_display_t * disp_drv, const lv_area_t * area, uint8_t * px_map) static void disp_flush(lv_display_t * disp_drv, const lv_area_t * area, uint8_t * px_map)
{ {
lv_display_rotation_t rotation = lv_display_get_rotation(disp_drv); static lv_display_rotation_t last_rotation = LV_DISPLAY_ROTATION_0;
lv_display_rotation_t current_rotation = lv_display_get_rotation(disp_drv);
lv_area_t rotated_area; lv_area_t rotated_area;
if(rotation != LV_DISPLAY_ROTATION_0) { if (current_rotation != last_rotation) {
LCD_SetRotation(rotation * 90); LCD_SetRotation(current_rotation * 90); // 仅在旋转状态改变时调用
last_rotation = current_rotation; // 更新上次状态
} }
if(disp_flush_enabled) { if(disp_flush_enabled) {
LCD_Color_Render(area->x1,area->y1,area->x2,area->y2, (uint16_t *)px_map); LCD_Color_Render(area->x1,area->y1,area->x2,area->y2, (uint16_t *)px_map);

View File

@@ -1,6 +1,7 @@
// LVGL version: 9.2 // LVGL version: 9.2
// Project name: PowerPico // Project name: PowerPico
#include "BL24C02.h" // system settings
#include "./ui.h" #include "./ui.h"
#include "./screens/ui_mainPage.h" #include "./screens/ui_mainPage.h"
#include "./screens/ui_chartPage.h" #include "./screens/ui_chartPage.h"
@@ -61,7 +62,7 @@ void ui_init(void)
PageManager_register(&pages[i]); PageManager_register(&pages[i]);
} }
PageManager_load_init_screen(); PageManager_load_init_screen();
lv_display_set_rotation(dispp, LV_DISP_ROTATION_180); lv_display_set_rotation(dispp, sys_settings.rotation / 90);
//timer //timer
// lv_timer_t * ui_MainTimer = lv_timer_create(main_timer, 1000, NULL); // lv_timer_t * ui_MainTimer = lv_timer_create(main_timer, 1000, NULL);

View File

@@ -18,6 +18,7 @@
#include "gate.h" #include "gate.h"
#include "data_queue.h" #include "data_queue.h"
#include "fusb302_dev.h" #include "fusb302_dev.h"
#include "BL24C02.h" // settings
// ui // ui
#include "lvgl.h" #include "lvgl.h"
@@ -82,6 +83,12 @@ void HardwareInitTask(void *argument)
// key // key
Key_Port_Init(); Key_Port_Init();
// system settings from eeprom
sys_settings.backlight_level = 80;
sys_settings.key_sound_enable = 0;
sys_settings.language_select = 0;
sys_settings.rotation = 270;
// FUSB CC pin dis connect // FUSB CC pin dis connect
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET);