?? camif.c
字號:
camCodecCaptureCount++;
}
else
{
//Uart_Printf("[P]");
rGPFDAT ^= 1 << 4; //hzh
CamPreviewIntMask();
rSUBSRCPND |= BIT_SUB_CAM_P;
ClearPending( BIT_CAM ) ;
switch ( camPviewStatus )
{
case CAM_STOP_ISSUED:
_CamPviewStopHw();
camPviewStatus = CAM_LAST_CAPTURING;
Uart_Printf( "pr=%x\n" , rCIPRCTRL );
//Uart_Printf("pS1\n");
break;
case CAM_LAST_CAPTURING:
camPviewStatus = CAM_STOPPED;
CamPreviewIntMask();
//Uart_Printf("pS2\n");
return;
case CAM_STARTED:
flagCaptured_P = 1;
if ( camTestMode & CAM_TEST_MODE_PVIEW )
{
if ( camPviewCaptureCount > 0 )
completedFrameIndex = ( ( ( rCIPRSTATUS >> 26 ) & 0x3 ) + 4 - 2 ) % 4;
//Uart_Printf("FrameIndex:%d\n",completedFrameIndex);
}
else
{
//Uart_Printf("Preview Image Captured\n");
}
default:
break;
}
CamPreviewIntUnmask();
camPviewCaptureCount++;
}
}
/******************************************************************************
* *
* camera interface interrupts & controls *
* *
******************************************************************************/
U32 Conv_YCbCr_Rgb( U8 y0 , U8 y1 , U8 cb0 , U8 cr0 ) // second solution... by junon
{
// 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 // 4 frames/s @192MHz, 12MHz ; 6 frames/s @450MHz, 12MHz
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;
U8 y0, y1, cb0, cr0;
int r0, r1, g0, g1, b0, b1;
U32 rgb_data0, rgb_data1;
U32 x, y;
int temp;
if ( CAM_CODEC_4PP )
temp = ( ( ( rCICOSTATUS >> 26 ) & 0x3 ) + 4 - 2 ) % 4; // current frame memory block
else
temp = 4;
//Uart_Printf("Current Frame memory %d\n", temp);
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;
}
//Uart_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 CAM_CODEC_OUTPUT==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;
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
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++ );
//frameBuffer16BitTft240320[y][x/2] = rgb_data0;
LCD_BUFFER_CAM[y][x / 2] = rgb_data0;
//Uart_Printf("%08x\n", rgb_data0);
//---
}
}
#endif
// memcpy((unsigned char*)0x30100000, frameBuffer16BitTft240320, 320*240*2); // QCIF=178*144*2
#if 0
rGPGDAT &= ~(1<<11);
Delay(30);
rGPGDAT |=(1<<11);
rGPGCON = (rGPGCON&~(1<<22))|(1<<23); // GPG11 output -> EINT19
#endif
}
#if 0
void Display_Cam_Image(int offset_x, int offset_y, int size_x, int size_y)
{
U8* CamFrameAddr, LcdFrameAddr;
int i, temp;
Lcd_MoveViewPort(offset_x, offset_y, USED_LCD_TYPE);
switch(camPviewCaptureCount%4)
{
case 2 :
temp = rCIPRCLRSA1;
break;
case 3 :
temp = rCIPRCLRSA2;
break;
case 0 :
temp = rCIPRCLRSA3;
break;
case 1 :
default:
temp = rCIPRCLRSA4;
break;
}
*CamFrameAddr = temp;
*LcdFrameAddr = LCD_BUFFER_CAM;
for(i=0;i<size_y;i++)
{
memcpy(LcdFrameAddr, CamFrameAddr, size_x*2);
*LcdFrameAddr += size_x*4; // added virtual screen
*CamFrameAddr += size_x*2;
}
}
#endif
void Test_CamPreview( void )
{
U8 flag;
U32 i, j, k, value;
Uart_Printf( "\nNow Start Camera Preview\n" );
//camera global variables
camTestMode = CAM_TEST_MODE_PVIEW;
camCodecCaptureCount = 0;
camPviewCaptureCount = 0;
camPviewStatus = CAM_STOPPED;
camCodecStatus = CAM_STOPPED;
flagCaptured_P = 0;
#if( DISP_TYPE == 1 )
LCD_LTS350Q1_PE1_Init() ; //
#elif( DISP_TYPE == 2 )
Lcd_V16C6448AC_Init() ; //Modufied by GongJun
#endif
//Uart_Printf( "Any key to continue...\n" ) ; Uart_Getch() ;
#if( DISP_TYPE == 1 )
for ( i = 0 ; i < SCR_YSIZE_TFT_240320 ; i++ )
{
for ( j = 0 ; j < SCR_XSIZE_TFT_240320 ; j++ )
{
if ( j < 80 )
LCD_BUFFER_CAM[i][j] = 0x001f ; //blue
else if ( ( j > 79 ) && ( j < 160 ) )
LCD_BUFFER_CAM[i][j] = 0x07e0; //green
else if ( j > 159 )
LCD_BUFFER_CAM[i][j] = 0xf800; //red
}
}
#elif( DISP_TYPE == 2 ) //Modufied by GongJun
for ( i = 0 ; i < SCR_YSIZE_TFT_640480 ; i++ )
{
for ( j = 0 ; j < SCR_XSIZE_TFT_640480 ; j++ )
{
if ( j < 80 )
LCD_BUFFER_CAM[i][j] = 0xffff ; //black
else if ( ( j > 79 ) && ( j < 160 ) )
LCD_BUFFER_CAM[i][j] = 0x0000; //white
else if ( ( j > 159 ) && ( j < 240 ) )
LCD_BUFFER_CAM[i][j] = 0x0001f; //blue
else if ( ( j > 239 ) && ( j < 320 ) )
LCD_BUFFER_CAM[i][j] = 0x07e0; //green
else if ( ( j > 319 ) && ( j < 400 ) )
LCD_BUFFER_CAM[i][j] = 0xf800; //red
else if ( ( j > 399 ) && ( j < 480 ) )
LCD_BUFFER_CAM[i][j] = 0xffe0; //
else if ( ( j > 479 ) && ( j < 560 ) )
LCD_BUFFER_CAM[i][j] = 0x07ff; //
else if ( j > 559 )
LCD_BUFFER_CAM[i][j] = 0xf81f; //
}
}
#endif
Uart_Printf( "preview sc control = %x\n" , rCIPRSCCTRL ) ;
// Initialize Camera interface
switch ( USED_CAM_TYPE )
{
case CAM_S5X532 :
// defualt for test : data-falling edge, ITU601, YCbCr
CamInit( 640 , 480 , 240 , 320 , 112 , 20 , CAM_FRAMEBUFFER_C , CAM_FRAMEBUFFER_P );
break;
case CAM_S5X3A1 :
// defualt for test : data-falling edge, YCbCr
CamInit( 640 , 480 , 240 , 320 , 120 , 100 , CAM_FRAMEBUFFER_C , CAM_FRAMEBUFFER_P );
rCISRCFMT = rCISRCFMT & ~( 1 << 31 ); // ITU656
// rCIGCTRL &= ~(1<<26); // inverse PCLK, test pattern
break;
default :
CamInit( 640 , 480 , 240 , 320 , 0 , 0 , CAM_FRAMEBUFFER_C , CAM_FRAMEBUFFER_P );
break;
}
Uart_Printf( "preview sc control = %x\n" , rCIPRSCCTRL );
// Start Capture
rSUBSRCPND |= BIT_SUB_CAM_C | BIT_SUB_CAM_P;
ClearPending( BIT_CAM );
pISR_CAM = ( U32 ) CamIsr;
CamPreviewIntUnmask();
CamCaptureStart( CAM_PVIEW_SCALER_CAPTURE_ENABLE_BIT );
Uart_Printf( "Press 'ESC' key to exit!\n" );
while ( 1 )
{
if ( flagCaptured_P )
{
flagCaptured_P = 0;
//Uart_Printf("Enter Cam A port, count = %d\n",camCodecCaptureCount);
}
if ( Uart_GetKey() == ESC_KEY )
break;
}
CamCaptureStop();
Uart_Printf( "\nWait until the current frame capture is completed.\n" );
while ( camPviewStatus != CAM_STOPPED )
if ( Uart_GetKey() == '\r' )
break;
Uart_Printf( "CIS format = %x\n" , rCISRCFMT );
Uart_Printf( "image cap = %x\n" , rCIIMGCPT );
Uart_Printf( "preview sc control = %x\n" , rCIPRSCCTRL );
Uart_Printf( "preview control = %x\n" , rCIPRCTRL );
Uart_Printf( "codec sc control = %x\n" , rCICOSCCTRL );
Uart_Printf( "codec control = %x\n" , rCICOCTRL );
Uart_Printf( "pr addr1 = %x\n" , rCIPRCLRSA1 );
Uart_Printf( "pr addr2 = %x\n" , rCIPRCLRSA2 );
Uart_Printf( "camCodecCaptureCount=%d\n" , camCodecCaptureCount );
Uart_Printf( "camPviewCaptureCount=%d\n" , camPviewCaptureCount );
// CamPreviewIntMask();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -