📄 camif.c
字号:
/************************************************************
File Name : camif.c
Descriptions
-S3C2440 camera test routines & basic libraries
History
- July 23, 2003. Draft Version 0.0 by purnnamu
- Janualy 15, 2004. Modifed by Boaz
Copyright (c) 2004 SAMSUNG Electronics.
# However, Anybody can use this code without our permission.
// 1600*1200 的输入问题。
// 解码的问题。
// CAM_SCALER_BYPASS_OFF
*************************************************************/
#include <ctype.h>
#include "def.h"
#include "2440addr.h"
#include "2440lib.h"
#include "camif.h"
#include "lcdlib.h"
#include "glib.h"
//
// Detect timing to send commands on the IIC bus
//
void IicSync(void)
{
static const int dt = FCLK / 10000 / 1000 * 12 * (4 - 1); // for 4ms
int t;
// Detect the rising edge of VSYNC
while (rGPJDAT & (1 << 9)) continue;
while (!(rGPJDAT & (1 << 9))) continue;
// Wait for 4ms
for (t = 0; t < dt; ++t) continue;
}
void Wr_CamIICx(char i,char j,char k)
{
;
}
// Sample of capture sequence.
//
// Note that the transmit clock value must be fPCLK / 512 or faster for this sequence.
// IICCON register should be configured by 0xE0.
//
void capture(void)
{
// Send capture command to camera module.
IicSync();
Wr_CamIICx(0xfa, 1, 70); // 1024
Wr_CamIICx(0xfa, 1, 120);
Wr_CamIICx(0xfa, 1, 111);
//rCIPRSCPRERATIO=((10-2-2)<<28)|(4<<16)|(4); //1024
while(1)
{
//while (rGPJDAT & (1 << 9)) continue;
while (!(rGPJDAT & (1 << 9))) continue;
// count the camsync low time
rWTCON = ((PCLK/1000000-1)<<8)|(2<<3);
rWTDAT = 0xffff; //for first update
rWTCNT = 0xffff; //resolution=64us @any PCLK
rWTCON = ((PCLK/1000000-1)<<8)|(2<<3)|(1<<5); //Watch-dog timer start
//while (!(rGPJDAT & (1 << 9))) continue;
while (rGPJDAT & (1 << 9)) continue;
rWTCON = ((PCLK/1000000-1)<<8)|(2<<3); //Watch-dog timer stop
// ???? 0xfd00 not ok sometime.
// when rWTCNT < 0xfd00 ,i will think the next frame is capture frame
// because i see when camera is work in live view mode .the rWTCNT is
// 0xfdbb . but afterward,i find when live view ,the rWTCNT not always
// is oxfdbb.it will get short when my hand close to the camera.the
// rWTCNT is short than 0xfd00 in live view ,i will think the next frame is capture wrongly
// how i should to??????!!!!
if (rWTCNT < 0xfe00)
{
rCIPRSCPRERATIO=((10-2-2)<<28)|(4<<16)|(4); //set for capture
rCIGCTRL |= (1<<31);
//Delay(8); // 100 -- 200
rCIGCTRL &= ~(1<<31);
while (rGPJDAT & (1 << 9)) continue;
while (!(rGPJDAT & (1 << 9))) continue;
// while (rGPJDAT & (1 << 9)) continue;
rCIIMGCPT&=~(CAM_CAMIF_GLOBAL_CAPTURE_ENABLE_BIT);
break;
}
Uart_Printf("[stop aaaaaaaaaaa rWTCNT:0x%x \n]",rWTCNT);
}
rCIGCTRL |= (1<<31);
Delay(8); // 100 -- 200
rCIGCTRL &= ~(1<<31);
#if 0
{ // Wait the capturing frame.
U8 state[2];
do { // Read the current state of seq. driver on SOC.
IicSync();
Wr_CamIICx(0xba, 3, 240, 0, 1);
Wr_CamIICx(0xba, 3, 198, 0xa1, 4);
Rd_CamIICx(0xba, 200, 2, state);
} while (state[1] != 7); // Until state becomes to "Capture(7)".
}
#endif
rCIIMGCPT &= ~CAM_CAMIF_GLOBAL_CAPTURE_ENABLE_BIT;
Uart_Getch();
// Now the current is the capturing frame!!
rCIPRSCPRERATIO=((10-1-1)<<28)|(2<<16)|(2); //set for live view
// reset
rCIGCTRL |= (1<<31);
Delay(8); // 100 -- 200
rCIGCTRL &= ~(1<<31);
rCIIMGCPT |=CAM_CAMIF_GLOBAL_CAPTURE_ENABLE_BIT;
}
void Camera_Test(void)
{
Uart_Printf("\n====== Camera Interface Test Start ======\n");
initialize();
IicSync();
//del by xm.hu
// Wr_CamIICx(0xfa, 2, 254, 2); // Setup Camera PLL.
// Wr_CamIICx(0xfa, 1, 132); // 30FPS fixed
for (;;) {
for (;;) {
Uart_Printf("1: AF start(20)\n");
Uart_Printf("2: AF finish(23)\n");
Uart_Printf("3: WB (83)\n");
Uart_Printf("4: WB (81)\n");
Uart_Printf("5: picture size full (70)\n");
Uart_Printf("6: picture size SVGA (71)\n");
Uart_Printf("7: data output YUV\n");
Uart_Printf("8: capture...\n");
Uart_Printf("9: 241\n");
Uart_Printf("--\n0: MCL test\n");
switch (Uart_GetIntNum()) {
case 0:
for (;;) {
int t;
for (t = 0; t < 12; ++t) {
IicSync();
Wr_CamIICx(0xfa, 1, 50 + t);
Delay(t * 7);
if (Uart_GetKey()) goto break_mcl_test_loop;
}
}
break_mcl_test_loop:
break;
case 1:
IicSync();
Wr_CamIICx(0xfa, 1, 20);
Uart_Printf(" AF START 1 !!!!!!\n");
break;
case 2:
IicSync();
Wr_CamIICx(0xfa, 1, 23);
Uart_Printf(" AF FINISH 2 !!!!!!\n");
break;
case 3:
IicSync();
Wr_CamIICx(0xfa, 1, 83);
Uart_Printf(" WHITE BALANCE 83 !!!!!!\n");
break;
case 4:
IicSync();
Wr_CamIICx(0xfa, 1, 81);
Uart_Printf(" WHITE BALANCE 81 !!!!!!\n");
break;
case 5:
IicSync();
Wr_CamIICx(0xfa, 1, 70);
Uart_Printf(" picture size 1600x1200 !!!!!!\n");
break;
case 6:
IicSync();
Wr_CamIICx(0xfa, 1, 71);
Uart_Printf(" picture size 800x600 !!!!!!\n");
break;
case 7:
IicSync();
Wr_CamIICx(0xfa, 1, 120);
Uart_Printf(" data output YUV !!!!!!\n");
break;
case 8:
capture();
break;
case 9:
IicSync();
Wr_CamIICx(0xfa, 1, 241);
Uart_Printf(" 60cm adjust !!!!!!\n");
break;
default:
Uart_Printf("command no. is not valid...\n");
break;
}
}
}
}
/******************************************************************************
* *
* camera interface interrupts & controls *
* *
******************************************************************************/
#define LCD_SIZE (LCD_XSIZE_TFT_240320 * LCD_YSIZE_TFT_240320)
void CamReset(void)
{
rCIGCTRL |= (1<<31); //camera I/F soft reset
Delay(10);
rCIGCTRL &= ~(1<<31);
}
// 0:48MHz, 1:24MHz, 2:16MHz, 3:12MHz...
// Camera clock = UPLL/[(CAMCLK_DIV+1)X2]
void SetCAMClockDivider(int divn)
{
rCAMDIVN = (rCAMDIVN & ~(0xf))|(1<<4)|(divn); // CAMCLK is divided..
}
/* 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 PrDstWidth, U32 PrDstHeight,
U32 WinHorOffset, U32 WinVerOffset, U32 CoFrameBuffer, U32 PrFrameBuffer)
{
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 ScaleUp_H_Co, ScaleUp_V_Co, ScaleUp_H_Pr, ScaleUp_V_Pr;
if(CAM_CODEC_OUTPUT)
divisor=2; //CCIR-422
else
divisor=4; //CCIR-420
//constant for calculating preview dma address
if(CAM_PVIEW_OUTPUT)
multiplier=4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -