Przeglądaj źródła

update: 并入spi/keyboard/camera的修改

Wendal Chen 4 lat temu
rodzic
commit
f1c5ee8eb9

+ 1 - 1
application/include/luat_conf_bsp.h

@@ -2,7 +2,7 @@
 #ifndef LUAT_CONF_BSP
 #define LUAT_CONF_BSP
 
-#define LUAT_BSP_VERSION "V0002"
+#define LUAT_BSP_VERSION "V0003"
 
 
 #define LUAT_USE_FS_VFS 1

+ 154 - 139
application/src/luat_camera_air105.c

@@ -7,7 +7,7 @@
 #include "luat_spi.h"
 #include "luat_gpio.h"
 
-#include "user.h"
+#include "app_interface.h"
 #include "zbar.h"
 #include "symbol.h"
 #include "image.h"
@@ -15,59 +15,64 @@
 #define LUAT_LOG_TAG "camera"
 #include "luat_log.h"
 
-static luat_lcd_conf_t* lcd_conf;
-
-#define DECODE_DONE (USER_EVENT_ID_START + 100)
-
 typedef struct
 {
-	HANDLE NotifyTaskHandler;
-	uint8_t TestBuf[4096];
 	uint8_t *DataCache;
 	uint32_t TotalSize;
 	uint32_t CurSize;
+	uint32_t VLen;
+	uint32_t drawVLen;
 	uint16_t Width;
 	uint16_t Height;
 	uint8_t DataBytes;
 	uint8_t IsDecode;
 	uint8_t BufferFull;
-}QR_DecodeCtrlStruct;
+}Camera_CtrlStruct;
 
-static QR_DecodeCtrlStruct prvDecodeQR;
+static Camera_CtrlStruct prvCamera;
 
-static uint32_t prvVLen;
-static uint32_t drawVLen;
+static struct luat_camera_conf camera_conf;
 
-static int32_t prvCamera_DCMICB(void *pData, void *pParam){
-    uint8_t zbar_scan = (uint8_t)pParam;
-    if (zbar_scan == 0){
-        Buffer_Struct *RxBuf = (Buffer_Struct *)pData;
-        if (!pData){
-            prvVLen = 0;
-            return 0;
-        }
-        LCD_DrawStruct *draw = OS_Malloc(sizeof(LCD_DrawStruct));
-        if (!draw){
-            DBG("lcd flush no memory");
-            return -1;
-        }
-        uint8_t CPHA = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.CPHA;
-        uint8_t CPOL = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.CPOL;
-        draw->Mode = SPI_MODE_0;
-        if(CPHA&&CPOL)draw->Mode = SPI_MODE_3;
-        else if(CPOL)draw->Mode = SPI_MODE_1;
-        else if(CPHA)draw->Mode = SPI_MODE_2;
-		draw->Speed = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.bandrate;
-        if (((luat_spi_device_t*)(lcd_conf->userdata))->bus_id == 5) draw->SpiID = HSPI_ID0;
-        else draw->SpiID = ((luat_spi_device_t*)(lcd_conf->userdata))->bus_id;
-		draw->CSPin = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.cs;
-		draw->DCPin = lcd_conf->pin_dc;
+static luat_lcd_conf_t* lcd_conf;
+static uint8_t draw_lcd = 0;
+
+void DecodeQR_CBDataFun(uint8_t *Data, uint32_t Len){
+    prvCamera.IsDecode = 0;
+    rtos_msg_t msg = {0};
+	if (Data){
+        msg.handler = l_camera_handler;
+        msg.ptr = Data;
+        msg.arg1 = 0;
+        msg.arg2 = Len;
+        luat_msgbus_put(&msg, 1);
+	}
+}
+
+static int32_t Camera_DrawLcd(void *DrawData, uint8_t Scan){
+    LCD_DrawStruct *draw = OS_Malloc(sizeof(LCD_DrawStruct));
+    if (!draw){
+        DBG("lcd flush no memory");
+        return -1;
+    }
+    uint8_t CPHA = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.CPHA;
+    uint8_t CPOL = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.CPOL;
+    draw->DCDelay = lcd_conf->dc_delay_us;
+    draw->Mode = SPI_MODE_0;
+    if(CPHA&&CPOL)draw->Mode = SPI_MODE_3;
+    else if(CPOL)draw->Mode = SPI_MODE_1;
+    else if(CPHA)draw->Mode = SPI_MODE_2;
+    draw->Speed = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.bandrate;
+    if (((luat_spi_device_t*)(lcd_conf->userdata))->bus_id == 5) draw->SpiID = HSPI_ID0;
+    else draw->SpiID = ((luat_spi_device_t*)(lcd_conf->userdata))->bus_id;
+    draw->CSPin = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.cs;
+    draw->DCPin = lcd_conf->pin_dc;
+    draw->xoffset = lcd_conf->xoffset;
+    draw->yoffset = lcd_conf->yoffset;
+    if (Scan == 0){
         draw->x1 = 0;
-        draw->x2 = 239;
-        draw->y1 = prvVLen;
-        draw->y2 = prvVLen + drawVLen -1;
-        draw->xoffset = lcd_conf->xoffset;
-		draw->yoffset = lcd_conf->yoffset;
+        draw->x2 = lcd_conf->w -1;
+        draw->y1 = prvCamera.VLen;
+        draw->y2 = prvCamera.VLen + prvCamera.drawVLen -1;
         draw->Size = (draw->x2 - draw->x1 + 1) * (draw->y2 - draw->y1 + 1) * 2;
         draw->ColorMode = COLOR_MODE_RGB_565;
         draw->Data = OS_Malloc(draw->Size);
@@ -76,51 +81,82 @@ static int32_t prvCamera_DCMICB(void *pData, void *pParam){
             OS_Free(draw);
             return -1;
         }
-    //	DBG_HexPrintf(RxBuf->Data, 8);
-        memcpy(draw->Data, RxBuf->Data, draw->Size);
+        memcpy(draw->Data, DrawData, draw->Size);
         Core_LCDDraw(draw);
-        prvVLen += drawVLen;
+    }else if(Scan == 1){
+        draw->x1 = 0;
+        draw->x2 = prvCamera.Width - 1;
+        draw->y1 = 0;
+        draw->y2 = prvCamera.Height - 1;
+        draw->Size = prvCamera.TotalSize;
+        draw->ColorMode = COLOR_MODE_GRAY;
+        draw->Data = DrawData;
+        Core_CameraDraw(draw);
+    }else{
+        DBG("Scan error");
+        OS_Free(draw);
+        return -1;
+    }
+}
+
+static int32_t prvCamera_DCMICB(void *pData, void *pParam){
+
+    uint8_t zbar_scan = (uint8_t)pParam;
+    if (zbar_scan == 0){
+        Buffer_Struct *RxBuf = (Buffer_Struct *)pData;
+        if (!pData){
+            prvCamera.VLen = 0;
+            return 0;
+        }
+        if (draw_lcd)
+            Camera_DrawLcd(RxBuf->Data, zbar_scan);
+
+        prvCamera.VLen += prvCamera.drawVLen;
         return 0;
     }else if (zbar_scan == 1){
         Buffer_Struct *RxBuf = (Buffer_Struct *)pData;
         if (!pData)
         {
-            if (!prvDecodeQR.DataCache)
+            if (!prvCamera.DataCache)
             {
-                prvDecodeQR.DataCache = malloc(prvDecodeQR.TotalSize);
-                prvDecodeQR.BufferFull = 0;
+                prvCamera.DataCache = malloc(prvCamera.TotalSize);
+                prvCamera.BufferFull = 0;
             }
             else
             {
-                if (prvDecodeQR.TotalSize != prvDecodeQR.CurSize)
+                if (prvCamera.TotalSize != prvCamera.CurSize)
                 {
-    //				DBG_ERR("%d, %d", prvDecodeQR.CurSize, prvDecodeQR.TotalSize);
+    //				DBG_ERR("%d, %d", prvCamera.CurSize, prvCamera.TotalSize);
                 }
-                else if (!prvDecodeQR.IsDecode)
+                else if (!prvCamera.IsDecode)
                 {
-                    prvDecodeQR.IsDecode = 1;
-                    Task_SendEvent(prvDecodeQR.NotifyTaskHandler, DECODE_DONE, prvDecodeQR.DataCache, 0, 0);
-                    prvDecodeQR.DataCache = malloc(prvDecodeQR.TotalSize);
-                    prvDecodeQR.BufferFull = 0;
+                    prvCamera.IsDecode = 1;
+                    if (draw_lcd)
+                        Camera_DrawLcd(prvCamera.DataCache, zbar_scan);
+                    Core_DecodeQR(prvCamera.DataCache, prvCamera.Width, prvCamera.Height,  DecodeQR_CBDataFun);
+                    prvCamera.DataCache = malloc(prvCamera.TotalSize);
+                    prvCamera.BufferFull = 0;
                 }
                 else
                 {
-                    prvDecodeQR.BufferFull = 1;
+                    prvCamera.BufferFull = 1;
                 }
             }
-            prvDecodeQR.CurSize = 0;
+            prvCamera.CurSize = 0;
             return 0;
         }
-        if (prvDecodeQR.DataCache)
+        if (prvCamera.DataCache)
         {
-            if (prvDecodeQR.BufferFull)
+            if (prvCamera.BufferFull)
             {
-                if (!prvDecodeQR.IsDecode){
-                    prvDecodeQR.IsDecode = 1;
-                    Task_SendEvent(prvDecodeQR.NotifyTaskHandler, DECODE_DONE, prvDecodeQR.DataCache, 0, 0);
-                    prvDecodeQR.DataCache = malloc(prvDecodeQR.TotalSize);
-                    prvDecodeQR.BufferFull = 0;
-                    prvDecodeQR.CurSize = 0;
+                if (!prvCamera.IsDecode){
+                    prvCamera.IsDecode = 1;
+                    if (draw_lcd)
+                        Camera_DrawLcd(prvCamera.DataCache, zbar_scan);
+                    Core_DecodeQR(prvCamera.DataCache, prvCamera.Width, prvCamera.Height,  DecodeQR_CBDataFun);
+                    prvCamera.DataCache = malloc(prvCamera.TotalSize);
+                    prvCamera.BufferFull = 0;
+                    prvCamera.CurSize = 0;
                 }else{
                     return 0;
                 }
@@ -128,72 +164,23 @@ static int32_t prvCamera_DCMICB(void *pData, void *pParam){
         }
         else
         {
-            prvDecodeQR.DataCache = malloc(prvDecodeQR.TotalSize);
-            prvDecodeQR.BufferFull = 0;
-            prvDecodeQR.CurSize = 0;
+            prvCamera.DataCache = malloc(prvCamera.TotalSize);
+            prvCamera.BufferFull = 0;
+            prvCamera.CurSize = 0;
+            prvCamera.IsDecode = 0;
         }
-        memcpy(&prvDecodeQR.DataCache[prvDecodeQR.CurSize], RxBuf->Data, RxBuf->MaxLen * 4);
-        prvDecodeQR.CurSize += RxBuf->MaxLen * 4;
-        if (prvDecodeQR.TotalSize < prvDecodeQR.CurSize){
-            DBG_ERR("%d,%d", prvDecodeQR.TotalSize, prvDecodeQR.CurSize);
-            prvDecodeQR.CurSize = 0;
+        memcpy(&prvCamera.DataCache[prvCamera.CurSize], RxBuf->Data, RxBuf->MaxLen * 4);
+        prvCamera.CurSize += RxBuf->MaxLen * 4;
+        if (prvCamera.TotalSize < prvCamera.CurSize){
+            DBG_ERR("%d,%d", prvCamera.TotalSize, prvCamera.CurSize);
+            prvCamera.CurSize = 0;
         }
         return 0;
     }
 }
 
-static void zbar_task(void *pData){
-    rtos_msg_t msg = {0};
-	OS_EVENT Event;
-	unsigned int len;
-	int ret;
-	char *string;
-	zbar_t *zbar;
-	LCD_DrawStruct *draw;
-	while (1) {
-		Task_GetEvent(prvDecodeQR.NotifyTaskHandler, DECODE_DONE, &Event, NULL, 0);
-		draw = malloc(sizeof(LCD_DrawStruct));
-        uint8_t CPHA = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.CPHA;
-        uint8_t CPOL = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.CPOL;
-        draw->Mode = SPI_MODE_0;
-        if(CPHA&&CPOL)draw->Mode = SPI_MODE_3;
-        else if(CPOL)draw->Mode = SPI_MODE_1;
-        else if(CPHA)draw->Mode = SPI_MODE_2;
-		draw->Speed = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.bandrate;
-        if (((luat_spi_device_t*)(lcd_conf->userdata))->bus_id == 5) draw->SpiID = HSPI_ID0;
-        else draw->SpiID = ((luat_spi_device_t*)(lcd_conf->userdata))->bus_id;
-		draw->CSPin = ((luat_spi_device_t*)(lcd_conf->userdata))->spi_config.cs;
-		draw->DCPin = lcd_conf->pin_dc;
-		draw->x1 = 0;
-		draw->x2 = prvDecodeQR.Width - 1;
-		draw->y1 = 0;
-		draw->y2 = prvDecodeQR.Height - 1;
-		draw->xoffset = lcd_conf->xoffset;
-		draw->yoffset = lcd_conf->yoffset;
-		draw->Size = prvDecodeQR.TotalSize;
-		draw->ColorMode = COLOR_MODE_GRAY;
-		draw->Data = Event.Param1;
-		Core_CameraDraw(draw);
-		zbar = zbar_create();
-		ret = zbar_run(zbar, prvDecodeQR.Width, prvDecodeQR.Height, Event.Param1);
-		if (ret > 0){
-			string = zbar_get_data_ptr(zbar, &len);
-            msg.handler = l_camera_handler;
-            msg.ptr = string;
-            msg.arg1 = 0;
-            msg.arg2 = len;
-            luat_msgbus_put(&msg, 1);
-		}
-		zbar_destory(zbar);
-		free(Event.Param1);
-		prvDecodeQR.IsDecode = 0;
-	}
-}
-
-
 int luat_camera_init(luat_camera_conf_t *conf){
-    lcd_conf = conf->lcd_conf;
-
+    
 	GPIO_Iomux(GPIOD_01, 3);
 	GPIO_Iomux(GPIOD_02, 3);
 	GPIO_Iomux(GPIOD_03, 3);
@@ -206,24 +193,22 @@ int luat_camera_init(luat_camera_conf_t *conf){
 	GPIO_Iomux(GPIOE_02, 3);
 	GPIO_Iomux(GPIOE_03, 3);
 
-    luat_i2c_setup(conf->i2c_id,1,NULL);
-	
+    camera_conf = *conf;
+    lcd_conf = conf->lcd_conf;
+    draw_lcd = conf->draw_lcd;
+
     if (conf->zbar_scan == 1){
-        prvDecodeQR.DataCache = NULL;
-        prvDecodeQR.Width = lcd_conf->w;
-        prvDecodeQR.Height = lcd_conf->h;
-        prvDecodeQR.TotalSize = prvDecodeQR.Width * prvDecodeQR.Height;
-        prvDecodeQR.DataBytes = 1;
-        prvDecodeQR.NotifyTaskHandler = Task_Create(zbar_task, NULL, 8 * 1024, 1, "test zbar");
+        prvCamera.DataCache = NULL;
+        prvCamera.Width = lcd_conf->w;
+        prvCamera.Height = lcd_conf->h;
+        prvCamera.TotalSize = prvCamera.Width * prvCamera.Height;
+        prvCamera.DataBytes = 1;
     }
+
     GPIO_Iomux(GPIOA_05, 2);
     HWTimer_SetPWM(conf->pwm_id, conf->pwm_period, conf->pwm_pulse, 0);
 
-    luat_gpio_mode(conf->camera_pwdn, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH);
-    luat_gpio_mode(conf->camera_rst, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH);
-	luat_timer_us_delay(10);
-    luat_gpio_set(conf->camera_rst, Luat_GPIO_LOW);
-
+    luat_i2c_setup(conf->i2c_id,1,NULL);
     for(size_t i = 0; i < conf->init_cmd_size; i++){
         luat_i2c_send(conf->i2c_id, conf->i2c_addr, &(conf->init_cmd[i]), 2);
         i++;
@@ -234,10 +219,40 @@ int luat_camera_init(luat_camera_conf_t *conf){
 
     if (conf->zbar_scan == 0){
         DCMI_SetCROPConfig(1, (conf->sensor_height-lcd_conf->h)/2, ((conf->sensor_width-lcd_conf->w)/2)*2, lcd_conf->h - 1, 2*lcd_conf->w - 1);
-        DCMI_CaptureSwitch(1, 0,lcd_conf->w, lcd_conf->h, 2, &drawVLen);	
-        prvVLen = 0;
+        DCMI_CaptureSwitch(1, 0,lcd_conf->w, lcd_conf->h, 2, &prvCamera.drawVLen);
+        prvCamera.VLen = 0;
     }else if(conf->zbar_scan == 1){
-        DCMI_SetCROPConfig(1, (conf->sensor_height-prvDecodeQR.Height)/2, ((conf->sensor_width-prvDecodeQR.Width)/2)*prvDecodeQR.DataBytes, prvDecodeQR.Height - 1, prvDecodeQR.DataBytes*prvDecodeQR.Width - 1);
-        DCMI_CaptureSwitch(1, 0,lcd_conf->w, lcd_conf->h, prvDecodeQR.DataBytes, &drawVLen);	
+        DCMI_SetCROPConfig(1, (conf->sensor_height-prvCamera.Height)/2, ((conf->sensor_width-prvCamera.Width)/2)*prvCamera.DataBytes, prvCamera.Height - 1, prvCamera.DataBytes*prvCamera.Width - 1);
+        DCMI_CaptureSwitch(1, 0,lcd_conf->w, lcd_conf->h, prvCamera.DataBytes, &prvCamera.drawVLen);
     }
+    return 0;
+}
+
+int luat_camera_start(int id)
+{
+	if (prvCamera.DataCache)
+	{
+		DCMI_CaptureSwitch(0, 0, 0, 0, 0, NULL);
+		free(prvCamera.DataCache);
+		prvCamera.IsDecode = 0;
+	}
+    if (camera_conf.zbar_scan == 0){
+        DCMI_SetCROPConfig(1, (camera_conf.sensor_height-lcd_conf->h)/2, ((camera_conf.sensor_width-lcd_conf->w)/2)*2, lcd_conf->h - 1, 2*lcd_conf->w - 1);
+        DCMI_CaptureSwitch(1, 0,lcd_conf->w, lcd_conf->h, 2, &prvCamera.drawVLen);
+        prvCamera.VLen = 0;
+    }else if(camera_conf.zbar_scan == 1){
+        DCMI_SetCROPConfig(1, (camera_conf.sensor_height-prvCamera.Height)/2, ((camera_conf.sensor_width-prvCamera.Width)/2)*prvCamera.DataBytes, prvCamera.Height - 1, prvCamera.DataBytes*prvCamera.Width - 1);
+        DCMI_CaptureSwitch(1, 0,lcd_conf->w, lcd_conf->h, prvCamera.DataBytes, &prvCamera.drawVLen);
+    }
+    return 0;
+}
+
+int luat_camera_stop(int id)
+{
+	DCMI_CaptureSwitch(0, 0, 0, 0, 0, NULL);
+	if (prvCamera.DataCache)
+	{
+		free(prvCamera.DataCache);
+	}
+    return 0;
 }

+ 3 - 4
application/src/luat_keyboard_air105.c

@@ -6,15 +6,15 @@
 #define LUAT_LOG_TAG "keyboard"
 #include "luat_log.h"
 
-static luat_keyboard_irq_cb cb = NULL;
 
 static int32_t kb_cb(void *pData, void *pParam) {
+	luat_keyboard_irq_cb cb = (luat_keyboard_irq_cb)pParam;
     if (cb) {
         luat_keyboard_ctx_t ctx;
         ctx.port = 0;
         ctx.pin_data = (uint16_t) pData;
         ctx.state = (((uint32_t)pData) >> 16) & 0x1;
-        //cb(&ctx);
+        cb(&ctx);
     }
 }
 
@@ -39,8 +39,7 @@ int luat_keyboard_init(luat_keyboard_conf_t *conf) {
     if (conf->pin_conf & (1 << 8))
         GPIO_Iomux(GPIOD_11, 2); // keyboard8
     //---------------------------
-    cb = conf->cb;
-    KB_Setup(conf->pin_map, 7, kb_cb, NULL);
+    KB_Setup(conf->pin_map, 7, kb_cb, conf->cb);
     return 0;
 }
 

+ 2 - 2
application/src/luat_spi_air105.c

@@ -186,7 +186,7 @@ int luat_lcd_draw_no_block(luat_lcd_conf_t* conf, uint16_t x1, uint16_t y1, uint
 		{
 			LLOGD("lcd flush delay %ums, status %u,%u,%u,%d", retry_cnt, cache_len, x2-x1+1, y2-y1+1, last_flush);
 		}
-		LCD_DrawStruct *draw = OS_Malloc(sizeof(LCD_DrawStruct));
+		LCD_DrawStruct *draw = OS_Zalloc(sizeof(LCD_DrawStruct));
 		if (!draw)
 		{
 			LLOGE("lcd flush no memory");
@@ -198,7 +198,7 @@ int luat_lcd_draw_no_block(luat_lcd_conf_t* conf, uint16_t x1, uint16_t y1, uint
 	    if(spi_dev->spi_config.CPHA&&spi_dev->spi_config.CPOL)spi_mode = SPI_MODE_3;
 	    else if(spi_dev->spi_config.CPOL)spi_mode = SPI_MODE_1;
 	    else if(spi_dev->spi_config.CPHA)spi_mode = SPI_MODE_2;
-
+	    draw->DCDelay = conf->dc_delay_us;
 	    draw->Mode = spi_mode;
 	    draw->Speed = spi_dev->spi_config.bandrate;
 	    draw->SpiID = luat_spi[spi_id].id;

+ 4 - 4
bsp/air105/hal/core_dcmi.c

@@ -43,7 +43,7 @@ static void prvDCMI_IrqHandler(int32_t Line, void *pData)
 	uint32_t SR = DCMI->RISR;
 
 	DCMI->ICR = 0xff;
-	if (SR & DCMI_IER_FRAME_IE)
+	if (SR & DCMI_IER_VSYNC_IE)
 	{
 		prvDCMI.RxDMASn = (prvDCMI.RxDMASn + 1)%DCMI_RXBUF_BAND;
 		DMA_ClearStreamFlag(DCMI_RX_DMA_STREAM);
@@ -75,7 +75,7 @@ void DCMI_Setup(uint8_t VsyncLevel, uint8_t HsyncLevel, uint8_t PclkPOL, uint8_t
 	Ctrl |= (FrameRate & 0x03 ) << 8;
 	SYSCTRL->DBG_CR |= DCMI_FROM_OUT;
 	DCMI->CR = Ctrl | (1 << 21);
-	DCMI->IER = DCMI_IER_FRAME_IE|DCMI_IER_OVF_IE|DCMI_IER_ERR_IE;
+	DCMI->IER = DCMI_IER_VSYNC_IE|DCMI_IER_OVF_IE|DCMI_IER_ERR_IE;
 	DCMI->ICR = 0xff;
 	ISR_OnOff(DCMI_IRQn, 0);
 	ISR_SetHandler(DCMI_IRQn, prvDCMI_IrqHandler, NULL);
@@ -157,9 +157,9 @@ void DCMI_CaptureSwitch(uint8_t OnOff, uint32_t BufLen, uint32_t ImageW, uint32_
 			{
 				HLen = ImageH >> 1;
 			}
-			while( (WDataLen * HLen) < 2048)
+			while( (WDataLen * HLen) > 2048)
 			{
-				HLen *= 2;
+				HLen >>= 1;
 			}
 			BufLen = WDataLen * HLen;
 			DBG("buf %u, H %u", BufLen, HLen);

+ 3 - 3
bsp/air105/hal/core_spi.c

@@ -786,7 +786,7 @@ int32_t SPI_BlockTransfer(uint8_t SpiID, const uint8_t *TxData, uint8_t *RxData,
 		DBG("!");
 		return Result;
 	}
-	if (OS_MutexLockWtihTime(prvSPI[SpiID].Sem, 2 * Time + 10))
+	if (OS_MutexLockWtihTime(prvSPI[SpiID].Sem, Time + 10))
 	{
 		DBG("!!!");
 		DMA_StopStream(prvSPI[SpiID].DMATxStream);
@@ -964,7 +964,7 @@ int32_t SPI_FlashBlockTransfer(uint8_t SpiID, const uint8_t *TxData, uint32_t WL
 		free(Temp);
 		return Result;
 	}
-	if (OS_MutexLockWtihTime(prvSPI[SpiID].Sem, 2 * Time + 10))
+	if (OS_MutexLockWtihTime(prvSPI[SpiID].Sem, Time + 10))
 	{
 		free(Temp);
 		DBG("!!!");
@@ -1026,7 +1026,7 @@ void SPI_DMARxInit(uint8_t SpiID, uint8_t Stream, uint32_t Channel)
 	DMA_InitTypeDef DMA_InitStruct;
 	DMA_BaseConfig(&DMA_InitStruct);
 	DMA_InitStruct.DMA_Peripheral = prvSPI[SpiID].DMARxChannel;
-	DMA_InitStruct.DMA_Priority = DMA_Priority_3;
+	DMA_InitStruct.DMA_Priority = DMA_Priority_2;
 	prvSPI[SpiID].DMARxStream = Stream;
 	switch(SpiID)
 	{

+ 1 - 1
bsp/air105/platform/app_main.c

@@ -28,7 +28,7 @@ extern const uint32_t __os_heap_start;
 extern const uint32_t __ram_end;
 
 const uint32_t __attribute__((section (".app_info")))
-    g_CAppInfo[32] =
+    g_CAppInfo[256] =
 {
 	__APP_START_MAGIC__,
 	sizeof(g_CAppInfo),

+ 1 - 1
bsp/air105/test/test_camera.c

@@ -665,7 +665,7 @@ static int32_t prvCamera_DCMICB(void *pData, void *pParam)
 		prvVLen = 0;
 		return 0;
 	}
-	LCD_DrawStruct *draw = OS_Malloc(sizeof(LCD_DrawStruct));
+	LCD_DrawStruct *draw = zalloc(sizeof(LCD_DrawStruct));
 	if (!draw)
 	{
 		DBG("lcd flush no memory");

+ 1 - 1
bsp/air105/test/test_zbar.c

@@ -464,7 +464,7 @@ static void zbar_task(void *pData)
 	Core_VHIDInit(USB_ID0, prvTest_VHIDCB);
 	while (1) {
 		Task_GetEvent(prvDecodeQR.NotifyTaskHandler, DECODE_DONE, &Event, NULL, 0);
-		draw = malloc(sizeof(LCD_DrawStruct));
+		draw = zalloc(sizeof(LCD_DrawStruct));
 		draw->Mode = SPI_MODE_0;
 		draw->Speed = 48000000;
 		draw->SpiID = HSPI_ID0;

+ 1 - 0
bsp/common/include/core_service.h

@@ -33,6 +33,7 @@ typedef struct
 	uint32_t xoffset;
 	uint32_t yoffset;
 	uint32_t Size;
+	uint32_t DCDelay;
 	uint8_t *Data;
 	uint8_t SpiID;
 	uint8_t Mode;

+ 32 - 17
bsp/common/src/core_service.c

@@ -1129,7 +1129,10 @@ void Core_VHIDUploadStop(uint8_t USB_ID)
 static void prvCore_LCDCmd(LCD_DrawStruct *Draw, uint8_t Cmd)
 {
     GPIO_Output(Draw->DCPin, 0);
-    SysTickDelay(300);
+    if (Draw->DCDelay)
+    {
+    	SysTickDelay(Draw->DCDelay * CORE_TICK_1US);
+    }
     GPIO_Output(Draw->CSPin, 0);
     SPI_BlockTransfer(Draw->SpiID, &Cmd, NULL, 1);
     GPIO_Output(Draw->CSPin, 1);
@@ -1178,7 +1181,10 @@ static void prvHW_Task(void* params)
 		case SERVICE_LCD_DRAW:
 
 			Draw = (LCD_DrawStruct *)Event.Param1;
-			SPI_SetTxOnlyFlag(Draw->SpiID, 1);
+			if (Draw->Speed > 30000000)
+			{
+				SPI_SetTxOnlyFlag(Draw->SpiID, 1);
+			}
 			SPI_SetNewConfig(Draw->SpiID, Draw->Speed, Draw->Mode);
 			SPI_DMATxInit(Draw->SpiID, LCD_SPI_TX_DMA_STREAM, 0);
 			SPI_DMARxInit(Draw->SpiID, LCD_SPI_RX_DMA_STREAM, 0);
@@ -1282,25 +1288,34 @@ static void prvService_Task(void* params)
 			}
 			break;
 		case SERVICE_DECODE_QR:
-			uPV.u32 = Event.Param2;
-			zbar_scanner = zbar_image_scanner_create();
-			zbar_image_scanner_set_config(zbar_scanner, 0, ZBAR_CFG_ENABLE, 1);
-			zbar_image = zbar_image_create();
-			zbar_image_set_format(zbar_image, *(int*)"Y800");
-			zbar_image_set_size(zbar_image, uPV.u16[0], uPV.u16[1]);
-			zbar_image_set_data(zbar_image, Event.Param1, uPV.u16[0] * uPV.u16[1], zbar_image_free_data);
-			if (zbar_scan_image(zbar_scanner, zbar_image) > 0)
-			{
-				zbar_symbol = (zbar_symbol_t *)zbar_image_first_symbol(zbar_image);
-			}
 			if (Event.Param3)
 			{
 				CBDataFun = (CBDataFun_t)(Event.Param3);
-				CBDataFun(zbar_symbol->data, zbar_symbol->datalen);
+				uPV.u32 = Event.Param2;
+				zbar_scanner = zbar_image_scanner_create();
+				zbar_image_scanner_set_config(zbar_scanner, 0, ZBAR_CFG_ENABLE, 1);
+				zbar_image = zbar_image_create();
+				zbar_image_set_format(zbar_image, *(int*)"Y800");
+				zbar_image_set_size(zbar_image, uPV.u16[0], uPV.u16[1]);
+				zbar_image_set_data(zbar_image, Event.Param1, uPV.u16[0] * uPV.u16[1], zbar_image_free_data);
+				if (zbar_scan_image(zbar_scanner, zbar_image) > 0)
+				{
+					zbar_symbol = (zbar_symbol_t *)zbar_image_first_symbol(zbar_image);
+					free(Event.Param1);
+					CBDataFun(zbar_symbol->data, zbar_symbol->datalen);
+				}
+				else
+				{
+					free(Event.Param1);
+					CBDataFun(NULL, 0);
+				}
+				zbar_image_destroy(zbar_image);
+				zbar_image_scanner_destroy(zbar_scanner);
+			}
+			else
+			{
+				free(Event.Param1);
 			}
-			free(zbar_image);
-			free(zbar_scanner);
-			free(Event.Param1);
 			break;
 		}
 	}

+ 2 - 2
project/air105/app.ld

@@ -22,9 +22,9 @@ SECTIONS
     /* The startup code into "FLASH" Rom type memory */
     .app_info :
     {
-        . = ALIGN(128);
+        . = ALIGN(512);
         KEEP(*(.app_info)) /* Startup code */
-        . = ALIGN(128);
+        . = ALIGN(512);
     } >FLASH
     .isr_vector :
     {