📄 camif.c
字号:
break;
case CAM_S5X532:
rCIGCTRL|= (1<<31)|(1<<30)|(1<<29); //camera I/F soft reset
Delay(1);
rCIGCTRL&= ~(1<<31);
rCIGCTRL&=~(1<<30); //external camera reset assertion (S5X433,AU70H=low active)
Delay(1000);
rCIGCTRL|=(1<<30); //external camera reset deassertion
rCIGCTRL|=(1<<26); // XciPCLK Polarity setting
break;
default:
break;
}
}
void SetCAMClockDivider(int divn)
{
rCLKDIVN= (rCLKDIVN & ~(0xf<<16))|(divn<<16);
}
/* 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(U32 CoDstWidth, U32 CoDstHeight, U32 WinHorOffset, U32 WinVerOffset, U32 CoFrameBuffer)
{
U32 WinOfsEn;
U32 divisor, multiplier;
U32 MainBurstSizeY, RemainedBurstSizeY, MainBurstSizeC, RemainedBurstSizeC, MainBurstSizeRGB, RemainedBurstSizeRGB;
U32 H_Shift, V_Shift, PreHorRatio, PreVerRatio, MainHorRatio, MainVerRatio;
U32 SrcWidth, SrcHeight;
U32 OrgSrcWidth, OrgSrcHeight;
U32 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==CAM_RGB24B)
multiplier=4;
else if(camCodecOutput==CAM_RGB16B)
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 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;
printf("SrcWidth:%d, SrcHeight:%d\n", SrcWidth, SrcHeight);
if(SrcWidth<=CoDstWidth) ScaleUp_H_Co=1;
else ScaleUp_H_Co=0;
if(SrcHeight<=CoDstHeight) ScaleUp_V_Co=1;
else ScaleUp_V_Co=0;
rCIGCTRL = (rCIGCTRL & ~(0x3<<27))|(1<<26);
//rCIGCTRL |= (0x1<<27)|(1<<26);
rCISRCFMT=(CAM_ITU601<<31)|(0<<30)|(CAM_ITU601_8B<<29)|(OrgSrcWidth<<16)|(CAM_ORDER_YCRYCB<<14)|(OrgSrcHeight);
rCIWDOFST=(WinOfsEn<<31)|(WinHorOffset<<16)|(WinVerOffset);
rCIDOWSFT2=(WinHorOffset<<16)|(WinVerOffset);
if(CAM_CODEC_PINGPONG) {
rCICOYSA1=CoFrameBuffer;
rCICOYSA2=rCICOYSA1+CoDstWidth*CoDstHeight*multiplier;
rCICOYSA3=rCICOYSA2+CoDstWidth*CoDstHeight*multiplier;
rCICOYSA4=rCICOYSA3+CoDstWidth*CoDstHeight*multiplier;
/*
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=(1<<31)|(1<<30)|(1<<29)|(CoDstWidth<<16)|(CAM_FLIP_NORMAL<<14)|(CoDstHeight);
CalculateBurstSize(CoDstWidth, &MainBurstSizeY, &RemainedBurstSizeY);
CalculateBurstSize(CoDstWidth/2, &MainBurstSizeC, &RemainedBurstSizeC);
printf("main:%d, remain:%d\n", MainBurstSizeY, RemainedBurstSizeY);
//rCICOCTRL=(MainBurstSizeY<<19)|(RemainedBurstSizeY<<14)|(MainBurstSizeC<<9)|(RemainedBurstSizeC<<4);
rCICOCTRL=(8<<19)|(4<<14)|(4<<9)|(2<<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;
rCIIMGCPT=(1<<26)|(0<<25)|(1<<24)|(0<<18);
rCICOCPTSEQ=0xffffffff;
rCICOSCOS=0x0;
//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(U32 hSize,U32 *mainBurstSize,U32 *remainedBurstSize)
{
U32 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(U32 SrcSize, U32 DstSize, U32 *ratio,U32 *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_CamCodecPreviewQVGADisplay(void)
{
U32 mode;
camTestMode=CAM_TEST_MODE_CODEC_POST;
camCodecCaptureCount=0;
camPviewCaptureCount=0;
camPviewStatus=CAM_STOPPED;
camCodecStatus=CAM_STOPPED;
mode=0;
InitLDI_LTS222();
camCodecInput=CAM_CCIR420;
camCodecOutput=CAM_RGB16B;
Lcd_Port_Init();
Lcd_PowerEnable(0, 1);
Lcd_Init(MODE_TFT_16BIT_240320);
Glib_Init(MODE_TFT_16BIT_240320);
Glib_ClearScr(0, MODE_TFT_16BIT_240320);
Lcd_EnvidOnOff(1);
//Camera I/F initialization
if(CAMTYPE==CAM_S5X532)
CamInit(240, 320, 112, 40, 0x33800000);
else
CamInit(240, 320, 0, 0, 0x33800000);
pISR_CAM=(U32)CamCodecIsr;
rINTMSK&=~(BIT_CAM);
printf("Camera preview for codec will be started!\n");
printf("Press Enter to continue!\n");
if(rCICOSTATUS&0xe0000000) {
rCIWDOFST|=(1<<30|1<<15|1<<14);
rCIWDOFST&=~(1<<30|1<<15|1<<14);
}
CamCaptureStart(CAM_CODEC_SCALER_CAPTURE_ENABLE_BIT);
if(camCodecOutput==CAM_CCIR422) {
while(1) {
if(camCodecDataValid==1) {
camCodecDataValid=0;
//Display_Cam_Image(PQVGA_XSIZE, PQVGA_YSIZE);
}
if(Uart_GetKey()=='\r') break;
}
}
else GetIntNum();
CamCaptureStop();
printf("Wait until the current frame capture is completed.\n");
while(!( camCodecStatus==CAM_STOPPED));
printf("camCodecCaptureCount:%d\n",camCodecCaptureCount);
printf("codec Status register:0x%x\n", rCICOSTATUS);
rINTMSK|=BIT_CAM;
}
void CamPortInit(void)
{
rGPEDN |= (0x3<<14);
rGPECON = (rGPECON & ~(0xf<<28))|(0xa<<28);
rGPJDN = 0x1fff;
rGPJCON = 0x2aaaaaa;
}
void CamClockInit(void)
{
SetUPLL( 64, 7, 0); // 96MHz UPLL
rCLKSRC = (rCLKSRC & ~(1<<11))|(1<<5); //USYSCLK = FOUTupll
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -