Pārlūkot izejas kodu

update:不需要Y分量调整,调整的是摄像头配置,取消时间片轮转调度,休眠时关闭rom和usb供电,尝试得到最低的功耗

alienwalker 4 gadi atpakaļ
vecāks
revīzija
730c557f6c

+ 3 - 6
Third_Party/jpeg_encode/tiny_jpeg.c

@@ -1016,10 +1016,8 @@ typedef struct
     // Bit stack
     uint32_t bitbuffer;
     uint32_t location;
-
-    int32_t y_diff;
 }TJE_ContextStruct;
-void *jpeg_encode_init(tje_write_func* func, void* context, uint8_t quality, uint32_t width, uint32_t height, uint8_t src_num_components, int32_t y_diff)
+void *jpeg_encode_init(tje_write_func* func, void* context, uint8_t quality, uint32_t width, uint32_t height, uint8_t src_num_components)
 {
     if (quality < 1 || quality > 3) {
         tje_log("Valid 'quality' %d values are 1 (lowest), 2, or 3 (highest)", quality);
@@ -1181,7 +1179,6 @@ void *jpeg_encode_init(tje_write_func* func, void* context, uint8_t quality, uin
         tjei_write(state, &header, sizeof(TJEScanHeader), 1);
 
     }
-    ctx->y_diff = y_diff;
     return ctx;
 }
 
@@ -1208,7 +1205,7 @@ void jpeg_encode_run(void *ctx, uint8_t *src_data, uint8_t is_rgb)
 					r = src_data[src_index + 0];
 					g = src_data[src_index + 1];
 					b = src_data[src_index + 2];
-					du_y[block_index] = 0.299f   * r + 0.587f    * g + 0.114f    * b + handle->y_diff;
+					du_y[block_index] = 0.299f   * r + 0.587f    * g + 0.114f    * b - 128;
 					du_b[block_index] = -0.1687f * r - 0.3313f   * g + 0.5f      * b;
 					du_r[block_index] = 0.5f     * r - 0.4187f   * g - 0.0813f   * b;
 				}
@@ -1217,7 +1214,7 @@ void jpeg_encode_run(void *ctx, uint8_t *src_data, uint8_t is_rgb)
 					du_y[block_index] = src_data[src_index + 0];
 					du_b[block_index] = src_data[src_index + 1];
 					du_r[block_index] = src_data[src_index + 2];
-					du_y[block_index] += handle->y_diff;
+					du_y[block_index] -= 128;
 					du_b[block_index] -= 128;
 					du_r[block_index] -= 128;
 				}

+ 1 - 1
Third_Party/jpeg_encode/tiny_jpeg.h

@@ -51,7 +51,7 @@ extern "C"
 //  to free the data.
 
 typedef void tje_write_func(void* context, void* data, int size);
-void *jpeg_encode_init(tje_write_func* func, void* context, uint8_t quality, uint32_t width, uint32_t height, uint8_t src_num_components, int32_t y_diff);
+void *jpeg_encode_init(tje_write_func* func, void* context, uint8_t quality, uint32_t width, uint32_t height, uint8_t src_num_components);
 void jpeg_encode_run(void *ctx, uint8_t *src_data, uint8_t IsRGB);
 void jpeg_encode_end(void *ctx);
 // ============================================================

+ 2 - 4
application/src/luat_camera_air105.c

@@ -45,7 +45,6 @@ typedef struct
 	uint32_t CurSize;
 	uint32_t VLen;
 	uint32_t drawVLen;
-	int32_t YDiff;
 	uint16_t Width;
 	uint16_t Height;
 	uint8_t DataBytes;
@@ -174,7 +173,7 @@ static int32_t prvCamera_DCMICB(void *pData, void *pParam){
     		{
     			prvCamera.CaptureWait = 0;
     			prvCamera.JPEGEncodeDone = 0;
-    			Core_EncodeJPEGStart(prvCamera.Width, prvCamera.Height, prvCamera.JPEGQuality, prvCamera.YDiff);
+    			Core_EncodeJPEGStart(prvCamera.Width, prvCamera.Height, prvCamera.JPEGQuality);
     		}
     		else if (!prvCamera.CaptureWait)
     		{
@@ -340,7 +339,7 @@ int luat_camera_start(int id)
     return 0;
 }
 
-int luat_camera_capture(int id, int y_diff, uint8_t quality, const char *path)
+int luat_camera_capture(int id, uint8_t quality, const char *path)
 {
 	DCMI_CaptureSwitch(0, 0, 0, 0, 0, NULL);
 	if (prvCamera.DataCache)
@@ -357,7 +356,6 @@ int luat_camera_capture(int id, int y_diff, uint8_t quality, const char *path)
 	OS_ReInitBuffer(&prvCamera.FileBuffer, 16 * 1024);
 	Core_EncodeJPEGSetup(Camera_SaveJPEGData, &prvCamera);
 	luat_camera_start(id);
-	prvCamera.YDiff = y_diff;
 	prvCamera.JPEGQuality = quality;
 	prvCamera.CaptureMode = 1;
 	prvCamera.CaptureWait = 1;

+ 4 - 1
bsp/air105/hal/core_pm.c

@@ -16,6 +16,7 @@ void PM_Init(void)
 	GPIO->WAKE_P0_EN = 0;
 	GPIO->WAKE_P1_EN = 0;
 	GPIO->WAKE_P2_EN = 0;
+	SYSCTRL->ANA_CTRL |= 0x00f0;
 }
 
 void PM_SetHardwareRunFlag(uint32_t PmHWSn, uint32_t OnOff)
@@ -47,18 +48,20 @@ void PM_Print(void)
 	DBG("%x,%x", prvPM.HWFlagBit, prvPM.DrvFlagBit);
 }
 
-int32_t PM_Sleep(void)
+int32_t __FUNC_IN_RAM__ PM_Sleep(void)
 {
 	uint64_t StartTick;
 	uint32_t Temp;
 	if (prvPM.HWFlagBit || prvPM.DrvFlagBit) return -ERROR_DEVICE_BUSY;
 	__disable_irq();
 	StartTick = RTC_GetUTC();
+	SYSCTRL->CG_CTRL1 = SYSCTRL_APBPeriph_KBD|SYSCTRL_APBPeriph_GPIO;
 	SYSCTRL->FREQ_SEL = (SYSCTRL->FREQ_SEL & ~(SYSCTRL_FREQ_SEL_POWERMODE_Mask)) | SYSCTRL_FREQ_SEL_POWERMODE_CLOSE_CPU_MEM;
 	Temp = TRNG->RNG_ANA;
 	TRNG->RNG_ANA = Temp | TRNG_RNG_AMA_PD_ALL_Mask;
 	__WFI();
 	TRNG->RNG_ANA = Temp;
+	SYSCTRL->CG_CTRL1 = SYSCTRL_APBPeriph_ALL;
 	WDT_Feed();
 	SysTickAddSleepTime((RTC_GetUTC() - StartTick) * CORE_TICK_1S);
 	Timer_WakeupRun();

+ 21 - 8
bsp/air105/hal/core_spi.c

@@ -773,7 +773,7 @@ static int32_t prvSPI_BlockTransfer(uint8_t SpiID, const uint8_t *TxData, uint8_
 int32_t SPI_BlockTransfer(uint8_t SpiID, const uint8_t *TxData, uint8_t *RxData, uint32_t Len)
 {
 #ifdef __BUILD_OS__
-	if ( (prvSPI[SpiID].DMARxStream == 0xff) || (prvSPI[SpiID].DMATxStream == 0xff) || OS_CheckInIrq() || ((prvSPI[SpiID].Speed >> 3) >= (Len * 100000)))
+	if (  OS_CheckInIrq() || ((prvSPI[SpiID].Speed >> 3) >= (Len * 100000)))
 	{
 		prvSPI[SpiID].IsBlockMode = 0;
 #endif
@@ -781,15 +781,24 @@ int32_t SPI_BlockTransfer(uint8_t SpiID, const uint8_t *TxData, uint8_t *RxData,
 #ifdef __BUILD_OS__
 	}
 	int32_t Result;
+	uint8_t DMAMode;
 	uint32_t Time = (Len * 1000) / (prvSPI[SpiID].Speed >> 3);
 	prvSPI[SpiID].IsBlockMode = 1;
+	if ( (prvSPI[SpiID].DMARxStream == 0xff) || (prvSPI[SpiID].DMATxStream == 0xff) )
+	{
+		DMAMode = 0;
+	}
+	else
+	{
+		DMAMode = 1;
+	}
 	if (TxData)
 	{
-		Result = SPI_Transfer(SpiID, TxData, RxData, Len, 1);
+		Result = SPI_Transfer(SpiID, TxData, RxData, Len, DMAMode);
 	}
 	else
 	{
-		Result = SPI_Transfer(SpiID, RxData, RxData, Len, 1);
+		Result = SPI_Transfer(SpiID, RxData, RxData, Len, DMAMode);
 	}
 	if (Result)
 	{
@@ -954,19 +963,23 @@ int32_t SPI_FlashBlockTransfer(uint8_t SpiID, const uint8_t *TxData, uint32_t WL
 #ifdef __BUILD_OS__
 	}
 	int32_t Result;
+	uint8_t DMAMode;
 	uint32_t Time = ((WLen + RLen) * 1000) / (prvSPI[SpiID].Speed >> 3);
 	uint8_t *Temp = malloc(WLen + RLen);
-	memcpy(Temp, TxData, WLen);
-	prvSPI[SpiID].IsBlockMode = 1;
-
 	if (TxData)
 	{
-		Result = SPI_Transfer(SpiID, Temp, Temp, WLen + RLen, 1);
+		memcpy(Temp, TxData, WLen);
+	}
+	prvSPI[SpiID].IsBlockMode = 1;
+	if ( (prvSPI[SpiID].DMARxStream == 0xff) || (prvSPI[SpiID].DMATxStream == 0xff) )
+	{
+		DMAMode = 0;
 	}
 	else
 	{
-		Result = SPI_Transfer(SpiID, Temp, Temp, WLen + RLen, 1);
+		DMAMode = 1;
 	}
+	Result = SPI_Transfer(SpiID, Temp, Temp, WLen + RLen, DMAMode);
 	if (Result)
 	{
 		prvSPI[SpiID].IsBlockMode = 0;

+ 2 - 1
bsp/air105/include/FreeRTOSConfig.h

@@ -77,7 +77,7 @@
 /* #define configMAX_PRIORITIES					( 56 ) */
 #define configUSE_PREEMPTION              1
 #define configUSE_IDLE_HOOK               1
-#define configUSE_TICK_HOOK               1
+#define configUSE_TICK_HOOK               0
 #define configMAX_PRIORITIES              (7)
 #define configSUPPORT_STATIC_ALLOCATION   0
 #define configCPU_CLOCK_HZ                (SystemCoreClock)
@@ -195,5 +195,6 @@ header file. */
  */
 #define xPortSysTickHandler SysTick_Handler
 #define traceTASK_SWITCHED_IN OS_SetStartFlag
+#define configUSE_TIME_SLICING 0
 #endif /* FREERTOS_CONFIG_H */
 

+ 8 - 0
bsp/air105/test/test_pm.c

@@ -8,8 +8,16 @@ static int32_t test_done(void *pData, void *pParam)
 
 void prvPM_Test(void *p)
 {
+	int i;
+
 	DBG("测试在1秒后开始,休眠60秒后RTC唤醒恢复");
+	for(i = GPIOA_02; i < GPIO_NONE; i++)
+	{
+		GPIO_PullConfig(i, 0, 0);
+		GPIO_Config(i, 0, 0);
+	}
 	Task_DelayMS(1000);
+
 	PM_SetDriverRunFlag(PM_DRV_DBG, 0);	//DBG是开机就打开的,如果没有其他外设使用,关闭这个就可以进入低功耗
 	RTC_SetAlarm(60, test_done, 1);	//开个RTC唤醒一下,或者键盘,或者GPIO
 	while(1)

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

@@ -53,7 +53,7 @@ void Core_USBAction(uint8_t USB_ID, uint8_t Action, void *pParam);
 void Core_ScanKeyBoard(void);
 void Core_SetRGB565FixValue(uint8_t R, uint8_t G, uint8_t B);
 void Core_EncodeJPEGSetup(HANDLE Fun, void *pParam);
-void Core_EncodeJPEGStart(uint32_t Width, uint32_t Height, uint8_t Quality, int32_t YDiff);
+void Core_EncodeJPEGStart(uint32_t Width, uint32_t Height, uint8_t Quality);
 void Core_EncodeJPEGRun(uint8_t *Data, uint32_t Len, uint8_t ColorMode);
 void Core_EncodeJPEGEnd(CBFuncEx_t CB, void *pParam);
 void Core_PrintMemInfo(void);

+ 3 - 3
bsp/common/src/core_service.c

@@ -285,7 +285,7 @@ static void prvService_Task(void* params)
 			}
 			break;
 		case SERVICE_ENCODE_JPEG_START:
-			JPEGEncodeHandle = jpeg_encode_init(prvService.JPEGEncodeWriteFun, prvService.JPEGEncodeWriteParam, Event.Param2, Event.Param1 >> 16, Event.Param1 & 0x0000ffff, 3, (int32_t)Event.Param3);
+			JPEGEncodeHandle = jpeg_encode_init(prvService.JPEGEncodeWriteFun, prvService.JPEGEncodeWriteParam, Event.Param2, Event.Param1 >> 16, Event.Param1 & 0x0000ffff, 3);
 			break;
 		case SERVICE_ENCODE_JPEG_RUN:
 			if (JPEGEncodeHandle)
@@ -478,9 +478,9 @@ void Core_EncodeJPEGSetup(HANDLE Fun, void *pParam)
 	prvService.JPEGEncodeWriteParam = pParam;
 }
 
-void Core_EncodeJPEGStart(uint32_t Width, uint32_t Height, uint8_t Quality, int32_t YDiff)
+void Core_EncodeJPEGStart(uint32_t Width, uint32_t Height, uint8_t Quality)
 {
-	Task_SendEvent(prvService.ServiceHandle, SERVICE_ENCODE_JPEG_START, (Width << 16 | Height), Quality, YDiff);
+	Task_SendEvent(prvService.ServiceHandle, SERVICE_ENCODE_JPEG_START, (Width << 16 | Height), Quality, 0);
 }
 
 void Core_EncodeJPEGRun(uint8_t *Data, uint32_t Len, uint8_t ColorMode)

+ 7 - 0
project/air105/app.ld

@@ -35,9 +35,16 @@ SECTIONS
     } >FLASH
 
     /* The program code and other data into "FLASH" Rom type memory */
+    .start :
+    {
+        . = ALIGN(4);
+        *startup_full.o(.text .text.*)
+    } >FLASH
+    
     .text :
     {
         . = ALIGN(4);
+        *start_full.o(.text .text.*)
         *(.text)           /* .text sections (code) */
         *(.text*)          /* .text* sections (code) */
         *(.glue_7)         /* glue arm to thumb code */

+ 5 - 0
project/air105/bl.ld

@@ -27,6 +27,11 @@ SECTIONS
     } >FLASH
 
     /* The program code and other data into "FLASH" Rom type memory */
+    .start :
+    {
+        . = ALIGN(4);
+        *startup_full.o(.text .text.*)
+    } >FLASH
     .text :
     {
         . = ALIGN(4);