diff --git a/Power_Pico/BSP/BL24C02/BL24C02.c b/Power_Pico/BSP/BL24C02/BL24C02.c index b3174f2..b841536 100644 --- a/Power_Pico/BSP/BL24C02/BL24C02.c +++ b/Power_Pico/BSP/BL24C02/BL24C02.c @@ -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); diff --git a/Power_Pico/BSP/BL24C02/BL24C02.h b/Power_Pico/BSP/BL24C02/BL24C02.h index f722e97..ddce89e 100644 --- a/Power_Pico/BSP/BL24C02/BL24C02.h +++ b/Power_Pico/BSP/BL24C02/BL24C02.h @@ -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); diff --git a/Power_Pico/BSP/LCD/lcd.c b/Power_Pico/BSP/LCD/lcd.c index fd528d7..9cc3a3a 100644 --- a/Power_Pico/BSP/LCD/lcd.c +++ b/Power_Pico/BSP/LCD/lcd.c @@ -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;iCR1|=SPI_CR1_DFF; diff --git a/Power_Pico/BSP/LCD/lcd_init.c b/Power_Pico/BSP/LCD/lcd_init.c index e914f76..dcfb97b 100644 --- a/Power_Pico/BSP/LCD/lcd_init.c +++ b/Power_Pico/BSP/LCD/lcd_init.c @@ -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; } diff --git a/Power_Pico/BSP/LCD/lcd_init.h b/Power_Pico/BSP/LCD/lcd_init.h index 88117bc..5b8fd90 100644 --- a/Power_Pico/BSP/LCD/lcd_init.h +++ b/Power_Pico/BSP/LCD/lcd_init.h @@ -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 diff --git a/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c b/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c index 2fd34ff..2086765 100644 --- a/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c +++ b/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c @@ -134,10 +134,12 @@ void disp_disable_update(void) *'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) { - 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; - if(rotation != LV_DISPLAY_ROTATION_0) { - LCD_SetRotation(rotation * 90); + if (current_rotation != last_rotation) { + LCD_SetRotation(current_rotation * 90); // 仅在旋转状态改变时调用 + last_rotation = current_rotation; // 更新上次状态 } if(disp_flush_enabled) { LCD_Color_Render(area->x1,area->y1,area->x2,area->y2, (uint16_t *)px_map); diff --git a/Power_Pico/User/GUI/ui.c b/Power_Pico/User/GUI/ui.c index 2dbe5ac..43d8eab 100644 --- a/Power_Pico/User/GUI/ui.c +++ b/Power_Pico/User/GUI/ui.c @@ -1,6 +1,7 @@ // LVGL version: 9.2 // Project name: PowerPico +#include "BL24C02.h" // system settings #include "./ui.h" #include "./screens/ui_mainPage.h" #include "./screens/ui_chartPage.h" @@ -61,7 +62,7 @@ void ui_init(void) PageManager_register(&pages[i]); } PageManager_load_init_screen(); - lv_display_set_rotation(dispp, LV_DISP_ROTATION_180); + lv_display_set_rotation(dispp, sys_settings.rotation / 90); //timer // lv_timer_t * ui_MainTimer = lv_timer_create(main_timer, 1000, NULL); diff --git a/Power_Pico/User/Tasks/Src/user_HardwareInitTask.c b/Power_Pico/User/Tasks/Src/user_HardwareInitTask.c index a9f3cb0..fc86491 100644 --- a/Power_Pico/User/Tasks/Src/user_HardwareInitTask.c +++ b/Power_Pico/User/Tasks/Src/user_HardwareInitTask.c @@ -18,6 +18,7 @@ #include "gate.h" #include "data_queue.h" #include "fusb302_dev.h" +#include "BL24C02.h" // settings // ui #include "lvgl.h" @@ -82,6 +83,12 @@ void HardwareInitTask(void *argument) // key 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 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET);