📄 camif.c
字号:
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)
{
camTestMode=CAM_TEST_MODE_PVIEW;
camCodecCaptureCount=0;
camCodecStatus=CAM_STOPPED;
InitLDI_LTS222();
camCodecInput=CAM_CCIR420;
camCodecOutput=CAM_CCIR420;
camRgbOutput=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);
// No Virtual Screen, Half word Swap
rLCDSADDR1=((LCDFRAMEBUFFER>>22)<<21)|(0x1fffff & (LCDFRAMEBUFFER>>1));
rLCDSADDR2=(0x1fffff & ((LCDFRAMEBUFFER+(LCD_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*2))>>1));
rLCDSADDR3=(LCD_XSIZE_TFT_240320/1);
rLCDCON5 |= 1;
Lcd_EnvidOnOff(1);
//Camera I/F initialization
if(CAMTYPE >= CAM_S5K3BAFB_VGA)
CamInit(240, 320, 0, 0, 0x33800000);
else
CamInit(240, 320, 8, 8, 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);
while(1) {
while(camCodecDataValid!=1);
camCodecDataValid=0;
if(Uart_GetKey()=='\r') break;
}
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 Test_CamCodecQVGADisplay(void)
{
U32 scalermode;
U32 SrcWidth, SrcHeight;
camTestMode=CAM_TEST_MODE_CODEC;
camCodecCaptureCount=0;
camCodecStatus=CAM_STOPPED;
scalermode=CAM_SCALER_BYPASS_OFF;
InitLDI_LTS222();
camCodecInput=CAM_CCIR420;
camCodecOutput=CAM_CCIR420;
if(scalermode==CAM_SCALER_BYPASS_ON)
{
camCodecInput=CAM_CCIR422;
camCodecOutput=CAM_CCIR422;
}
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);
// No Virtual Screen, Half word Swap
rLCDSADDR1=((LCDFRAMEBUFFER>>22)<<21)|(0x1fffff & (LCDFRAMEBUFFER>>1));
rLCDSADDR2=(0x1fffff & ((LCDFRAMEBUFFER+(LCD_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*2))>>1));
rLCDSADDR3=(LCD_XSIZE_TFT_240320/1);
Lcd_EnvidOnOff(1);
//Camera I/F initialization
switch(CAMSIZE) {
case VGA_XSIZE:
SrcWidth=VGA_XSIZE;
SrcHeight=VGA_YSIZE;
break;
case SXGA_XSIZE:
SrcWidth=SXGA_XSIZE;
SrcHeight=SXGA_YSIZE;
break;
case UXGA_XSIZE:
SrcWidth=UXGA_XSIZE;
SrcHeight=UXGA_YSIZE;
break;
default:
SrcWidth=VGA_XSIZE;
SrcHeight=VGA_YSIZE;
break;
}
if(CAMTYPE >= CAM_S5K3BAFB_VGA)
CamInit(240, 320, 0, 0, 0x31000000);
else
CamInit(240, 320, 8, 8, 0x31000000);
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);
}
if(scalermode==CAM_SCALER_BYPASS_OFF)
{
CamCaptureStart(CAM_CODEC_SCALER_CAPTURE_ENABLE_BIT);
}
else if(scalermode==CAM_SCALER_BYPASS_ON)
{
rCICOSCCTRL |= (1<<31);
CamCaptureStart(CAM_CAMIF_GLOBAL_CAPTURE_ENABLE_BIT);
}
while(1) {
if(camCodecDataValid==1) {
camCodecDataValid=0;
Display_Cam_Image(240,320);
}
if(Uart_GetKey()=='\r') break;
}
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 Test_CamCodecQVGA(void)
{
U32 scalermode;
U32 SrcWidth, SrcHeight;
camTestMode=CAM_TEST_MODE_CODEC;
camCodecCaptureCount=0;
camCodecStatus=CAM_STOPPED;
scalermode=CAM_SCALER_BYPASS_OFF;
InitLDI_LTS222();
camCodecInput=CAM_CCIR422;
camCodecOutput=CAM_CCIR422;
if(scalermode==CAM_SCALER_BYPASS_ON)
{
camCodecInput=CAM_CCIR422;
camCodecOutput=CAM_CCIR422;
}
//Camera I/F initialization
switch(CAMSIZE) {
case VGA_XSIZE:
SrcWidth=VGA_XSIZE;
SrcHeight=VGA_YSIZE;
break;
case SXGA_XSIZE:
SrcWidth=SXGA_XSIZE;
SrcHeight=SXGA_YSIZE;
break;
case UXGA_XSIZE:
SrcWidth=UXGA_XSIZE;
SrcHeight=UXGA_YSIZE;
break;
default:
SrcWidth=VGA_XSIZE;
SrcHeight=VGA_YSIZE;
break;
}
if(CAMTYPE >= CAM_S5K3BAFB_VGA)
CamInit(SrcWidth, SrcHeight, 0, 0, 0x31000000);
else
CamInit(SrcWidth, SrcHeight, 8, 8, 0x31000000);
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);
}
if(scalermode==CAM_SCALER_BYPASS_OFF)
{
CamCaptureStart(CAM_CODEC_SCALER_CAPTURE_ENABLE_BIT);
}
else if(scalermode==CAM_SCALER_BYPASS_ON)
{
rCICOSCCTRL |= (1<<31);
CamCaptureStart(CAM_CAMIF_GLOBAL_CAPTURE_ENABLE_BIT);
}
if(camCodecOutput==CAM_CCIR422) {
while(1) {
if(camCodecDataValid==1) {
camCodecDataValid=0;
}
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);
printf("Captured data is stored at 0x31000000\n");
rINTMSK|=BIT_CAM;
}
U32 Conv_YCbCr_Rgb(U8 y0, U8 y1, U8 cb0, U8 cr0)
{
// bit order is
// YCbCr = [Cr0 Y1 Cb0 Y0], RGB=[R1,G1,B1,R0,G0,B0].
int r0, g0, b0, r1, g1, b1;
U32 rgb0, rgb1, rgb;
#if 1
r0 = YCbCrtoR(y0, cb0, cr0);
g0 = YCbCrtoG(y0, cb0, cr0);
b0 = YCbCrtoB(y0, cb0, cr0);
r1 = YCbCrtoR(y1, cb0, cr0);
g1 = YCbCrtoG(y1, cb0, cr0);
b1 = YCbCrtoB(y1, cb0, cr0);
#endif
if (r0>255 ) r0 = 255;
if (r0<0) r0 = 0;
if (g0>255 ) g0 = 255;
if (g0<0) g0 = 0;
if (b0>255 ) b0 = 255;
if (b0<0) b0 = 0;
if (r1>255 ) r1 = 255;
if (r1<0) r1 = 0;
if (g1>255 ) g1 = 255;
if (g1<0) g1 = 0;
if (b1>255 ) b1 = 255;
if (b1<0) b1 = 0;
// 5:6:5 16bit format
rgb0 = (((U16)r0>>3)<<11) | (((U16)g0>>2)<<5) | (((U16)b0>>3)<<0); //RGB565.
rgb1 = (((U16)r1>>3)<<11) | (((U16)g1>>2)<<5) | (((U16)b1>>3)<<0); //RGB565.
rgb = (rgb1<<16) | rgb0;
return(rgb);
}
void Display_Cam_Image(U32 size_x, U32 size_y)
{
U8 *buffer_y, *buffer_cb, *buffer_cr;
U32 rgb_data0;
U32 x, y;
int temp;
U32 *lcdframebuffer;
temp = (((rCICOSTATUS>>26)&0x3)+4-2)%4; // current frame memory block
switch (temp) // current frame mem - 2
{
case 0:
buffer_y = (U8 *)rCICOYSA1;
buffer_cb = (U8 *)rCICOCBSA1;
buffer_cr = (U8 *)rCICOCRSA1;
break;
case 1:
buffer_y = (U8 *)rCICOYSA2;
buffer_cb = (U8 *)rCICOCBSA2;
buffer_cr = (U8 *)rCICOCRSA2;
break;
case 2:
buffer_y = (U8 *)rCICOYSA3;
buffer_cb = (U8 *)rCICOCBSA3;
buffer_cr = (U8 *)rCICOCRSA3;
break;
case 3:
buffer_y = (U8 *)rCICOYSA4;
buffer_cb = (U8 *)rCICOCBSA4;
buffer_cr = (U8 *)rCICOCRSA4;
break;
default :
buffer_y = (U8 *)rCICOYSA1;
buffer_cb = (U8 *)rCICOCBSA1;
buffer_cr = (U8 *)rCICOCRSA1;
break;
}
lcdframebuffer=(U32 *)LCDFRAMEBUFFER;
//printf("End setting : Y-0x%x, Cb-0x%x, Cr-0x%x\n", buffer_y, buffer_cb, buffer_cr);
#if 0
// for checking converting time
rGPGCON = (rGPGCON&~(1<<23))|(1<<22); //EINT19 -> GPG11 output
rGPGUP |= (1<<11);
rGPGDAT &= ~(1<<11);
Delay(90);
rGPGDAT |=(1<<11);
rgb_data0 = 0;
#endif
if(camCodecOutput==CAM_CCIR420)
for (y=0;y<size_y;y++) // YCbCr 4:2:0 format
{
for (x=0;x<size_x;x+=2)
{
rgb_data0 = Conv_YCbCr_Rgb(*buffer_y++, *buffer_y++, *buffer_cb++, *buffer_cr++);
//frameBuffer16BitTft240320[y][x/2] = rgb_data0;
*(lcdframebuffer++) = rgb_data0;
if ( (x==(size_x-2)) && ((y%2)==0) ) // when x is last pixel & y is even number
{
buffer_cb -= size_x/2;
buffer_cr -= size_x/2;
}
}
}
else if(camCodecOutput==CAM_CCIR422)
for (y=0;y<size_y;y++) // YCbCr 4:2:2 format
{
for (x=0;x<size_x;x+=2)
{
rgb_data0 = Conv_YCbCr_Rgb(*buffer_y++, *buffer_y++, *buffer_cb++, *buffer_cr++);
*(lcdframebuffer++) = rgb_data0;
}
}
#if 0
rGPGDAT &= ~(1<<11);
Delay(30);
rGPGDAT |=(1<<11);
rGPGCON = (rGPGCON&~(1<<22))|(1<<23); // GPG11 output -> EINT19
#endif
}
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 + -