📄 camif.c
字号:
case CAM_LAST_CAPTURING:
camPviewStatus=CAM_STOPPED;
return;
case CAM_STARTED:
if(camTestMode&CAM_TEST_MODE_PVIEW_POST) {
if(camPviewCaptureCount >0) {
camPviewDataValid=1;
if(postProcessingDone==0 && camPviewCaptureCount>1) {
printf("ERROR:Post not completed yet.\n");
}
completedFrameIndex=(((rCIPRSTATUS>>26)&0x3)+4-2)%4;
PostStartProcessing(completedFrameIndex);
}
}
else {
if(camPviewCaptureCount>0) camPviewDataValid=1;
}
break;
default:
printf("dummy\n");
break;
}
camPviewCaptureCount++;
}
rINTSUBMSK2 &= ~(BIT_SUB_CAMIF_C|BIT_SUB_CAMIF_P|BIT_SUB_POST);
rINTMSK &= ~BIT_CAMIF_BLOCK_POST;
}
/* Description of Parameters
CoDstWidth: Destination Width of Codec Path
CoDstHeight: Destination Height of Codec Path
PrDstWidth: Destination Width of Preview Path
PrDstHeight: Destination Height of Preview Path
WinHorOffset: Size of Window Offset for Horizontal Direction
WinVerOffset: Size of Window Offset for Vertical Direction
CoFrameBuffer: Start Address for Codec DMA
PrFrameBuffer: Start Address for Previe DMA
*/
void CamInit(unsigned int CoDstWidth, unsigned int CoDstHeight, unsigned int PrDstWidth, unsigned int PrDstHeight,
unsigned int WinHorOffset, unsigned int WinVerOffset, unsigned int CoFrameBuffer, unsigned int PrFrameBuffer)
{
unsigned int WinOfsEn;
unsigned int divisor, multiplier;
unsigned int MainBurstSizeY, RemainedBurstSizeY, MainBurstSizeC, RemainedBurstSizeC, MainBurstSizeRGB, RemainedBurstSizeRGB;
unsigned int H_Shift, V_Shift, PreHorRatio, PreVerRatio, MainHorRatio, MainVerRatio;
unsigned int SrcWidth, SrcHeight;
unsigned int OrgSrcWidth, OrgSrcHeight;
unsigned int ScaleUp_H_Co, ScaleUp_V_Co, ScaleUp_H_Pr, ScaleUp_V_Pr;
//constraint for size setting is checked here.........
//constant for calculating codec dma address
if(camCodecOutput)
divisor=2; //CCIR-422
else
divisor=4; //CCIR-420
//constant for calculating preview dma address
if(camPviewOutput)
multiplier=4;
else
multiplier=2;
if(WinHorOffset==0 && WinVerOffset==0)
WinOfsEn=0;
else
WinOfsEn=1;
switch(CAMSIZE) {
case VGA_XSIZE:
OrgSrcWidth=VGA_XSIZE;
OrgSrcHeight=VGA_YSIZE;
break;
case SXGA_XSIZE:
OrgSrcWidth=SXGA_XSIZE;
OrgSrcHeight=SXGA_YSIZE;
break;
case MEGA1_XSIZE:
OrgSrcWidth=MEGA1_XSIZE;
OrgSrcHeight=MEGA1_YSIZE;
break;
case MEGA2_XSIZE:
OrgSrcWidth=MEGA2_XSIZE;
OrgSrcHeight=MEGA2_YSIZE;
break;
default:
OrgSrcWidth=VGA_XSIZE;
OrgSrcHeight=VGA_YSIZE;
break;
}
SrcWidth=OrgSrcWidth-2*WinHorOffset;
SrcHeight=OrgSrcHeight-2*WinVerOffset;
if(SrcWidth<=CoDstWidth) ScaleUp_H_Co=1;
else ScaleUp_H_Co=0;
if(SrcHeight<=CoDstHeight) ScaleUp_V_Co=1;
else ScaleUp_V_Co=0;
if(SrcWidth<=PrDstWidth) ScaleUp_H_Pr=1;
else ScaleUp_H_Pr=0;
if(SrcHeight<=PrDstHeight) ScaleUp_V_Pr=1;
else ScaleUp_V_Pr=0;
if (CAMTYPE==CAM_S5K3AA)
rCISRCFMT=(CAM_ITU601<<31)|(0<<30)|(CAM_ITU601_8B<<29)|(OrgSrcWidth<<16)|(CAM_ORDER_CRYCBY<<14)|(OrgSrcHeight);
else
rCISRCFMT=(CAM_ITU601<<31)|(0<<30)|(CAM_ITU601_8B<<29)|(OrgSrcWidth<<16)|(CAM_ORDER_YCBYCR<<14)|(OrgSrcHeight);
rCIWDOFST=(WinOfsEn<<31)|(WinHorOffset<<16)|(WinVerOffset);
if(CAM_CODEC_PINGPONG) {
rCICOYSA1=CoFrameBuffer;
rCICOYSA2=rCICOYSA1+CoDstWidth*CoDstHeight+2*CoDstWidth*CoDstHeight/divisor;
rCICOYSA3=rCICOYSA2+CoDstWidth*CoDstHeight+2*CoDstWidth*CoDstHeight/divisor;
rCICOYSA4=rCICOYSA3+CoDstWidth*CoDstHeight+2*CoDstWidth*CoDstHeight/divisor;
rCICOCBSA1=rCICOYSA1+CoDstWidth*CoDstHeight;
rCICOCBSA2=rCICOYSA2+CoDstWidth*CoDstHeight;
rCICOCBSA3=rCICOYSA3+CoDstWidth*CoDstHeight;
rCICOCBSA4=rCICOYSA4+CoDstWidth*CoDstHeight;
rCICOCRSA1=rCICOCBSA1+CoDstWidth*CoDstHeight/divisor;
rCICOCRSA2=rCICOCBSA2+CoDstWidth*CoDstHeight/divisor;
rCICOCRSA3=rCICOCBSA3+CoDstWidth*CoDstHeight/divisor;
rCICOCRSA4=rCICOCBSA4+CoDstWidth*CoDstHeight/divisor;
}
else {
rCICOYSA1=CoFrameBuffer;
rCICOYSA2=rCICOYSA1;
rCICOYSA3=rCICOYSA1;
rCICOYSA4=rCICOYSA1;
rCICOCBSA1=rCICOYSA1+CoDstWidth*CoDstHeight;
rCICOCBSA2=rCICOCBSA1;
rCICOCBSA3=rCICOCBSA1;
rCICOCBSA4=rCICOCBSA1;
rCICOCRSA1=rCICOCBSA1+CoDstWidth*CoDstHeight/divisor;
rCICOCRSA2=rCICOCRSA1;
rCICOCRSA3=rCICOCRSA1;
rCICOCRSA4=rCICOCRSA1;
}
rCICOTRGFMT=(camCodecInput<<31)|(camCodecOutput<<30)|(CoDstWidth<<16)|(CAM_FLIP_NORMAL<<14)|(CoDstHeight);
CalculateBurstSize(CoDstWidth, &MainBurstSizeY, &RemainedBurstSizeY);
CalculateBurstSize(CoDstWidth/2, &MainBurstSizeC, &RemainedBurstSizeC);
rCICOCTRL=(MainBurstSizeY<<19)|(RemainedBurstSizeY<<14)|(MainBurstSizeC<<9)|(RemainedBurstSizeC<<4);
CalculatePrescalerRatioShift(SrcWidth, CoDstWidth, &PreHorRatio, &H_Shift);
CalculatePrescalerRatioShift(SrcHeight, CoDstHeight, &PreVerRatio, &V_Shift);
MainHorRatio=(SrcWidth<<8)/(CoDstWidth<<H_Shift);
MainVerRatio=(SrcHeight<<8)/(CoDstHeight<<V_Shift);
rCICOSCPRERATIO=((10-H_Shift-V_Shift)<<28)|(PreHorRatio<<16)|(PreVerRatio<<0);
rCICOSCPREDST=((SrcWidth/PreHorRatio)<<16)|(SrcHeight/PreVerRatio);
rCICOSCCTRL=(CAM_SCALER_BYPASS_OFF<<31)|(ScaleUp_H_Co<<30)|(ScaleUp_V_Co<<29)|(MainHorRatio<<16)|(MainVerRatio);
rCICOTAREA=CoDstWidth*CoDstHeight;
if(CAM_PVIEW_PINGPONG) {
rCIPRCLRSA1=PrFrameBuffer;
rCIPRCLRSA2=rCIPRCLRSA1+PrDstWidth*PrDstHeight*multiplier;
rCIPRCLRSA3=rCIPRCLRSA2+PrDstWidth*PrDstHeight*multiplier;
rCIPRCLRSA4=rCIPRCLRSA3+PrDstWidth*PrDstHeight*multiplier;
}
else {
rCIPRCLRSA1=PrFrameBuffer;
rCIPRCLRSA2=PrFrameBuffer;
rCIPRCLRSA3=PrFrameBuffer;
rCIPRCLRSA4=PrFrameBuffer;
}
rCIPRTRGFMT=(PrDstWidth<<16)|(CAM_FLIP_NORMAL<<14)|(PrDstHeight);
CalculateBurstSize(PrDstWidth*multiplier, &MainBurstSizeRGB, &RemainedBurstSizeRGB);
rCIPRCTRL=(MainBurstSizeRGB<<19)|(RemainedBurstSizeRGB<<14);
CalculatePrescalerRatioShift(SrcWidth, PrDstWidth, &PreHorRatio, &H_Shift);
CalculatePrescalerRatioShift(SrcHeight, PrDstHeight, &PreVerRatio, &V_Shift);
MainHorRatio=(SrcWidth<<8)/(PrDstWidth<<H_Shift);
MainVerRatio=(SrcHeight<<8)/(PrDstHeight<<V_Shift);
rCIPRSCPRERATIO=((10-H_Shift-V_Shift)<<28)|(PreHorRatio<<16)|(PreVerRatio);
rCIPRSCPREDST=((SrcWidth/PreHorRatio)<<16)|(SrcHeight/PreVerRatio);
rCIPRSCCTRL=(1<<31)|(camPviewOutput<<30)|(ScaleUp_H_Pr<<29)|(ScaleUp_V_Pr<<28)|(MainHorRatio<<16)|(MainVerRatio);
rCIPRTAREA= PrDstWidth*PrDstHeight;
//clear overflow because unintentional overflow may be existed...
rCIWDOFST|=(1<<30)|(0xf<<12);
rCIWDOFST&=~((1<<30)|(0xf<<12));
}
/********************************************************
CalculateBurstSize - Calculate the busrt lengths
Description:
- dstHSize: the number of the byte of H Size.
*/
void CalculateBurstSize(unsigned int hSize,unsigned int *mainBurstSize,unsigned int *remainedBurstSize)
{
unsigned int tmp;
tmp=(hSize/4)%16;
switch(tmp) {
case 0:
*mainBurstSize=16;
*remainedBurstSize=16;
break;
case 4:
*mainBurstSize=16;
*remainedBurstSize=4;
break;
case 8:
*mainBurstSize=16;
*remainedBurstSize=8;
break;
default:
tmp=(hSize/4)%8;
switch(tmp) {
case 0:
*mainBurstSize=8;
*remainedBurstSize=8;
break;
case 4:
*mainBurstSize=8;
*remainedBurstSize=4;
default:
*mainBurstSize=4;
tmp=(hSize/4)%4;
*remainedBurstSize= (tmp) ? tmp: 4;
break;
}
break;
}
}
/********************************************************
CalculatePrescalerRatioShift - none
Description:
- none
*/
void CalculatePrescalerRatioShift(unsigned int SrcSize, unsigned int DstSize, unsigned int *ratio,unsigned int *shift)
{
if(SrcSize>=64*DstSize) {
printf("ERROR: out of the prescaler range: SrcSize/DstSize = %d(< 64)\n",SrcSize/DstSize);
// while(1);
}
else if(SrcSize>=32*DstSize) {
*ratio=32;
*shift=5;
}
else if(SrcSize>=16*DstSize) {
*ratio=16;
*shift=4;
}
else if(SrcSize>=8*DstSize) {
*ratio=8;
*shift=3;
}
else if(SrcSize>=4*DstSize) {
*ratio=4;
*shift=2;
}
else if(SrcSize>=2*DstSize) {
*ratio=2;
*shift=1;
}
else {
*ratio=1;
*shift=0;
}
}
void Test_CamPreviewTestQVGADisplay(void)
{
unsigned int dispX, dispY;
int i;
camTestMode=CAM_TEST_MODE_PVIEW;
camCodecCaptureCount=0;
camPviewCaptureCount=0;
camPviewStatus=CAM_STOPPED;
camCodecStatus=CAM_STOPPED;
#if TEST_DETAIL_EN
printf("Select bpp of LCD\n");
printf("0: 16bpp SLCD(D), 1:24bpp SLCD, 2:16bpp PLCD, 3:24bpp PLCD\n");
printf("Select one:");
i=GetIntNum();
switch(i) {
case 1:
Init_240X320_AMLCD();
LcdBGInit(MODE_SER_24BIT_240320|MODE_NO_VIRTUAL_24B);
GlibInit(MODE_SER_24BIT_240320, BGBUFFER1);
camCodecOutput=CAM_CCIR420;
camPviewOutput=CAM_RGB24B;
break;
case 2:
LcdBGInit(MODE_PAR_16BIT565_240320|MODE_NO_VIRTUAL_16B);
GlibInit(MODE_PAR_16BIT565_240320, BGBUFFER1);
camCodecOutput=CAM_CCIR420;
camPviewOutput=CAM_RGB16B;
break;
case 3:
LcdBGInit(MODE_PAR_24BIT_240320|MODE_NO_VIRTUAL_24B);
GlibInit(MODE_PAR_24BIT_240320, BGBUFFER1);
camCodecOutput=CAM_CCIR420;
camPviewOutput=CAM_RGB24B;
break;
default: // 0
Init_240X320_AMLCD();
LcdBGInit(MODE_SER_16BIT565_240320|MODE_NO_VIRTUAL_16B);
GlibInit(MODE_SER_16BIT565_240320, BGBUFFER1);
camCodecOutput=CAM_CCIR420;
camPviewOutput=CAM_RGB16B;
break;
}
LcdEnvidOnOff(1); // Enable ENVID Bit
#else
Init_240X320_AMLCD();
LcdBGInit(MODE_SER_16BIT565_240320|MODE_NO_VIRTUAL_16B);
GlibInit(MODE_SER_16BIT565_240320, BGBUFFER1);
LcdEnvidOnOff(1); // Enable ENVID Bit
camCodecOutput=CAM_CCIR420;
camPviewOutput=CAM_RGB16B;
#endif
//Camera I/F initialization
if(CAMTYPE==CAM_S5X532)
CamInit(640, 480, camPviewDispX, camPviewDispY, 112, 40, (_NONCACHE_STARTADDRESS+0), (_NONCACHE_STARTADDRESS+0x00300000));
else
CamInit(640, 480, camPviewDispX, camPviewDispY, 0, 0, (_NONCACHE_STARTADDRESS+0), (_NONCACHE_STARTADDRESS+0x00300000));
#if TEST_DETAIL_EN
printf("Select Shape of Test Pattern\n");
printf("0:camera input, 1:color bar, 2:horizontal increment, 3:vertical increment\n");
printf("Select One:");
i=GetIntNum();
rCIGCTRL&=~(0x3<<27);
switch(i) {
case 0:
rCIGCTRL|=(0<<27);
break;
case 1:
rCIGCTRL|=(1<<27);
break;
case 2:
rCIGCTRL|=(2<<27);
break;
case 3:
rCIGCTRL|=(3<<27);
break;
default:
break;
}
printf("Select Flip mode\n");
printf("0:normal, 1:X-axis mirror, 2:Y-axis mirror, 3:180 rotation\n");
printf("Select One:");
i=GetIntNum();
rCIPRTRGFMT&=~(0x3<<14);
switch(i) {
case 0:
rCIPRTRGFMT|=(0<<14);
break;
case 1:
rCIPRTRGFMT|=(1<<14);
break;
case 2:
rCIPRTRGFMT|=(2<<14);
break;
case 3:
rCIPRTRGFMT|=(3<<14);
break;
default:
break;
}
#endif
rCIGCTRL|=(1<<26); // Signals of Synchronization are not inverted
// rCIPRCTRL = (1<<23) | (1<<18);
if(CAMTYPE==CAM_OV7620_16) {
printf("16bit YCbYCr is enabled\n");
rCISRCFMT|=(1<<29);
}
pISR_CAMIF_BLOCK_POST=(unsigned int)Camif_Post_Isr;
rINTMSK &= ~(BIT_CAMIF_BLOCK_POST);
rINTSUBMSK2 &= ~(BIT_SUB_CAMIF_P);
printf("Camera preview for preview will be started!\n");
printf("Press any key to continue\n");
CamCaptureStart(CAM_PVIEW_SCALER_CAPTURE_ENABLE_BIT);
while (1)
{
if (camPviewDataValid)
{
camPviewDataValid = 0;
Display_Prv_Image(camPviewDispX, camPviewDispY);
// Uart_Printf("Enter Cam A port, count = %d\n",camCodecCaptureCount);
}
if (Uart_GetKey()== '\r') break;
}
CamCaptureStop();
while(!(camPviewStatus==CAM_STOPPED ));
printf("camPviewCaptureCount=%d\n",camPviewCaptureCount);
printf("codec Status register:0x%x\n", rCICOSTATUS);
printf("preview Status register:0x%x\n", rCIPRSTATUS);
rINTSUBMSK2 |= (BIT_SUB_CAMIF_P);
rINTMSK|=(BIT_CAMIF_BLOCK_POST);
}
void Test_CamCodecPostTestQVGADisplay(void)
{
unsigned int dispX, dispY;
int i;
camTestMode=CAM_TEST_MODE_CODEC_POST;
camCodecCaptureCount=0;
camPviewCaptureCount=0;
camPviewStatus=CAM_STOPPED;
camCodecStatus=CAM_STOPPED;
postMode = 0;
#if TEST_DETAIL_EN
printf("Select input format of Camera Scaler\n");
printf("0:420, 1:422\n");
printf("Select one:");
i=GetIntNum();
switch(i) {
case 0:
camCodecInput=CAM_CCIR420;
break;
case 1:
camCodecInput=CAM_CCIR422;
break;
default:
camCodecInput=CAM_CCIR420;
break;
}
printf("Select output format of Camera Scaler\n");
printf("0:420, 1:422\n");
printf("Select one:");
i=GetIntNum();
switch(i) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -