Sfoglia il codice sorgente

由于擦写flash需要的时间比较久,改成接收完360x360x3的字节数据后再一次性写入flash中,中间不进行flash的读写操作,这样更新头像的时间可以缩减到45s以内
需要临时分配360x360x3+4字节的数据空间,用ui_mem_res_alloc实现,使用完后,用ui_mem_res_free释放空间

robbin 1 settimana fa
parent
commit
35d1789e54
2 ha cambiato i file con 41 aggiunte e 30 eliminazioni
  1. 1 1
      thirdparty/lib/aem/config/aem_project.h
  2. 40 29
      zephyr/drivers/serial/uart2_rec.c

+ 1 - 1
thirdparty/lib/aem/config/aem_project.h

@@ -4,7 +4,7 @@
 #pragma warning(error : 4013)
 #endif
 #define AEM_VERSION "BL_Develop_NOR"
-#define BUILD_TIME "202504271550"
+#define BUILD_TIME "202504291020"
 #define AEM_GUI_FWK_LIB_VER "2.0.0.0"
 #define APP_DOWNLOAD_URL "https://customer.com"
 #define AEM_APP_TRANS_ANIMATION 1

+ 40 - 29
zephyr/drivers/serial/uart2_rec.c

@@ -25,8 +25,8 @@
 // 定义数据区大小
 #define UART_FIFO_MAX        64
 #define REC_DATA_BUFFER_SIZE 512
-#define REC_PIC_BUFFER_SIZE  (1024 * 4)
 #define PHOTO_DATA_MAX_SIZE  (DEF_UI_WIDTH * DEF_UI_HEIGHT * LV_IMG_PX_SIZE_ALPHA_BYTE)  //360*360*3
+#define REC_PIC_BUFFER_SIZE  PHOTO_DATA_MAX_SIZE + 4
 #define DEVICE_ID_SIZE       8
 #define PROJECT_ID_SIZE      4
 #define WRITE_KEY_SIZE       160
@@ -70,8 +70,8 @@ uint8_t bySetTimeStep = 0;
 static bool bSetPhotoReady = false;
 static uint32_t glPhotoDataSize = 0;
 static uint32_t glPhotoDataSizecheck = 0;
-static uint16_t gwRecPhotoDataSize = 0;
-static uint32_t glRecPhotoDataOffset = 0;
+static uint32_t glRecPhotoDataSize = 0;
+//static uint32_t glRecPhotoDataOffset = 0;
 static char *photo_name = "profile_photo_name"; // 文件名
 
 extern uint8_t bySetHour;
@@ -88,6 +88,10 @@ extern bool aem_defender_factory_write_key(uint8_t * data, uint16_t len); // 写
 extern uint16_t aem_factory_get_product_info(uint8_t *data, uint16_t in_len); // 获取产品信息
 extern uint32_t flash_write(const char *name, uint32_t offset, void *data, uint32_t size); // 写入数据到Flash
 extern uint32_t flash_erase(const char *name);  // 擦除Flash
+#ifdef CONFIG_UI_MEMORY_MANAGER
+extern void ui_mem_res_free(void * ptr);
+extern void * ui_mem_res_alloc(size_t size);
+#endif
 
 #if 0
 static __attribute__((aligned(4))) uint8_t ota_img[] =  //卡通表盘图片数据
@@ -610,7 +614,7 @@ static void flash_write_proc_timer_acts_handler(struct k_work *work)
 {
 	uint8_t tx_buff[2] = {0};  // 定义发送缓冲区
 	
-	//x_buff[1] = (sizeof(ota_img) & 0x0000FF);
+	//tx_buff[1] = (sizeof(ota_img) & 0x0000FF);
 	//tx_buff[2] = (sizeof(ota_img) & 0x00FF00) >> 8;
 	//tx_buff[3] = (sizeof(ota_img) & 0xFF0000) >> 16;
 	// 根据接收到的命令,执行不同的操作
@@ -628,14 +632,14 @@ static void flash_write_proc_timer_acts_handler(struct k_work *work)
 				{
 					tx_buff[0] = 0xAA;
 					glPhotoDataSizecheck = 0; // 清零
-					gwRecPhotoDataSize = 3; // index从3开始,前3个字节为图片大小,先设置为0,再由SET_PROFILE_PHOTO_OVER写入
-					glRecPhotoDataOffset = 0; // 偏移量从0开始
+					glRecPhotoDataSize = 3; // index从3开始,前3个字节为图片大小,先设置为0,再由SET_PROFILE_PHOTO_OVER写入
+					//glRecPhotoDataOffset = 0; // 偏移量从0开始
 					bSetPhotoReady = true;  // 设置准备标志
 				}
 
-				str_uart2_rec_data.pic_data = (uint8_t *)lv_mem_alloc(REC_PIC_BUFFER_SIZE);
+				str_uart2_rec_data.pic_data = (uint8_t *)ui_mem_res_alloc(REC_PIC_BUFFER_SIZE);
 				memset(str_uart2_rec_data.pic_data, 0, 3);  // 清零
-				flash_erase(photo_name);  // 清空flash
+				//flash_erase(photo_name);  // 清空flash
 
 				aem_activity_run(AEM_SHOW_ANIMATION, NULL); // 显示动画
 			}
@@ -666,13 +670,14 @@ static void flash_write_proc_timer_acts_handler(struct k_work *work)
 			if (bSetPhotoReady && (str_uart2_rec_data.rec_data[3] > 0))
 			{
 				tx_buff[0] = 0xAA;
-				if ((gwRecPhotoDataSize + str_uart2_rec_data.rec_data[3]) > REC_PIC_BUFFER_SIZE)
+                /*
+				if ((glRecPhotoDataSize + str_uart2_rec_data.rec_data[3]) > REC_PIC_BUFFER_SIZE)
 				{
-					if (flash_write(photo_name, glRecPhotoDataOffset, str_uart2_rec_data.pic_data, gwRecPhotoDataSize) == 0)
+					if (flash_write(photo_name, glRecPhotoDataOffset, str_uart2_rec_data.pic_data, glRecPhotoDataSize) == 0)
 					//if (flash_write(photo_name, 3, ota_img, sizeof(ota_img)) == 0)
 					{
-						glRecPhotoDataOffset += gwRecPhotoDataSize;  // 更新偏移量
-						gwRecPhotoDataSize = 0;  // 重新计数
+						glRecPhotoDataOffset += glRecPhotoDataSize;  // 更新偏移量
+						glRecPhotoDataSize = 0;  // 重新计数
 					}
 					else
 					{
@@ -681,10 +686,11 @@ static void flash_write_proc_timer_acts_handler(struct k_work *work)
 				}
 
 				if (tx_buff[0] == 0xAA)
+                */
 				{
 					for (uint16_t i = 0; i < str_uart2_rec_data.rec_data[3]; i++)
 					{
-						str_uart2_rec_data.pic_data[gwRecPhotoDataSize++] = str_uart2_rec_data.rec_data[4 + i];
+						str_uart2_rec_data.pic_data[glRecPhotoDataSize++] = str_uart2_rec_data.rec_data[4 + i];
 					}
 
 					glPhotoDataSizecheck += str_uart2_rec_data.rec_data[3];  // 累加数据长度
@@ -698,36 +704,41 @@ static void flash_write_proc_timer_acts_handler(struct k_work *work)
 			tx_buff[0] = 0;
 			if (glPhotoDataSizecheck == glPhotoDataSize)  //头像照片数据长度校验
 			{
-				if (flash_write(photo_name, glRecPhotoDataOffset, str_uart2_rec_data.pic_data, gwRecPhotoDataSize) == 0)
+                tx_buff[0] = 0xAA;
+                send_frame(SET_PROFILE_PHOTO_OVER, tx_buff, 1);
+
+				if (flash_write(photo_name, 0, str_uart2_rec_data.pic_data, glRecPhotoDataSize) == 0)
 				{
-					str_uart2_rec_data.pic_data[0] = (glPhotoDataSize & 0x0000FF);
-					str_uart2_rec_data.pic_data[1] = (glPhotoDataSize & 0x00FF00) >> 8;
-					str_uart2_rec_data.pic_data[2] = (glPhotoDataSize & 0xFF0000) >> 16;
-					if (flash_write(photo_name, 0, str_uart2_rec_data.pic_data, 3) == 0)  // 最后写入图片大小
-					{
-						glRecPhotoDataOffset = 3;  // 更新偏移量
-						gwRecPhotoDataSize = 0;  // 重新计数
+                    str_uart2_rec_data.pic_data[0] = (glPhotoDataSize & 0x0000FF);
+                    str_uart2_rec_data.pic_data[1] = (glPhotoDataSize & 0x00FF00) >> 8;
+                    str_uart2_rec_data.pic_data[2] = (glPhotoDataSize & 0xFF0000) >> 16;
 
-						glPhotoDataSize = 0;
-						glPhotoDataSizecheck = 0;
-						bSetPhotoReady = false;
-						tx_buff[0] = 0xAA;
+					if (flash_write(photo_name, 0, str_uart2_rec_data.pic_data, 3))  // 最后写入图片大小
+					{
+						flash_erase(photo_name);  // 写入失败则清空flash
 					}
 				}
+                //glRecPhotoDataOffset = 0;  // 更新偏移量
+                glRecPhotoDataSize = 3;  // 重新计数
+
+                glPhotoDataSize = 0;
+                glPhotoDataSizecheck = 0;
+                bSetPhotoReady = false;
 			}
 			else if (!bSetPhotoReady)
 			{
 				tx_buff[0] = 0xAA;
+                send_frame(SET_PROFILE_PHOTO_OVER, tx_buff, 1);
 			}
 			else
 			{
 				tx_buff[0] = 0x55;
+                send_frame(SET_PROFILE_PHOTO_OVER, tx_buff, 1);
 				flash_erase(photo_name);  // 清空flash
 			}
-			memset(str_uart2_rec_data.rec_data, 0, REC_DATA_BUFFER_SIZE);
-			send_frame(SET_PROFILE_PHOTO_OVER, tx_buff, 1);
 
-			lv_mem_free(str_uart2_rec_data.pic_data);
+			memset(str_uart2_rec_data.rec_data, 0, REC_DATA_BUFFER_SIZE);
+			ui_mem_res_free(str_uart2_rec_data.pic_data);
 			str_uart2_rec_data.pic_data = NULL;
 
 			aem_power_onoff_t on_off = { 0 };
@@ -956,7 +967,7 @@ static void uart_fifo_callback(const struct device *dev, void *user_data)
 			else
 			{
 				tx_buff[0] = 0x55;
-				send_frame(0xCB, tx_buff, 1);
+				send_frame(str_uart2_rec_data.rec_data[2], tx_buff, 1);
 			}
 
 			bReceiveFrameDone = false;