/************************************************************
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 2004 SAMSUNG Electronics.
However, Anybody can use this code without our permission.
*************************************************************/
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "camif.h"
#include "camproset.h" // for camera setting
extern unsigned char ucdragon_240_100[];
extern unsigned char xyx_240_320[];
//*****************************************************************************
#define MVAL (13)
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
#define INVVDEN (1) //0=normal 1=inverted
#define BSWP (0) //Byte swap control
#define HWSWP (1) //Half word swap control
#define M5D(n) ((n) & 0x1fffff) // To get lower 21bits
//TFT 240320
#define LCD_XSIZE_TFT_240320 (240)
#define LCD_YSIZE_TFT_240320 (320)
//TFT 240320
#define SCR_XSIZE_TFT_240320 (240)
#define SCR_YSIZE_TFT_240320 (320)
//#define SCR_XSIZE_TFT_240320 (320)
//#define SCR_YSIZE_TFT_240320 (240)
//TFT240320
#define HOZVAL_TFT_240320 (LCD_XSIZE_TFT_240320-1)
#define LINEVAL_TFT_240320 (LCD_YSIZE_TFT_240320-1)
//Timing parameter for LCD LQ035Q7DB02
#define VBPD_240320 (4) //垂直同步信号的后肩
#define VFPD_240320 (4) //垂直同步信号的前肩
#define VSPW_240320 (4) //垂直同步信号的脉宽
#define HBPD_240320 (13) //水平同步信号的后肩
#define HFPD_240320 (4) //水平同步信号的前肩
#define HSPW_240320 (18) //水平同步信号的脉宽
#define CLKVAL_TFT_240320 (7)
//FCLK=180MHz,HCLK=90MHz,VCLK=6.5MHz
// GPB1/TOUT1 for Backlight control(PWM)
#define GPB1_TO_OUT() (rGPBUP &= 0xfffd, rGPBCON &= 0xfffffff3, rGPBCON |= 0x00000004)
#define GPB1_TO_1() (rGPBDAT |= 0x0002)
#define GPB1_TO_0() (rGPBDAT &= 0xfffd)
volatile static unsigned short LCD_BUFFER_CAM[SCR_YSIZE_TFT_240320][SCR_XSIZE_TFT_240320];
//*****************************************************************************
volatile U32 camTestMode;
volatile U32 camCodecCaptureCount;
volatile U32 camPviewCaptureCount;
volatile U32 camCodecStatus;
volatile U32 camPviewStatus;
volatile U32 amount;
U32 save_GPJCON, save_GPJDAT, save_GPJUP;
U8 flagCaptured_P = 0;
U8 flagCaptured_C = 0;
int Test_OV9650(void); //hzh
void Display_Cam_Image(U32 size_x, U32 size_y);
/**************************************************************
LCD视频和控制信号输出或者停止,1开启视频输出
**************************************************************/
static void Lcd_EnvidOnOff(int onoff)
{
if(onoff==1)
rLCDCON1|=1; // ENVID=ON
else
rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
}
/**************************************************************
320×240 8Bpp TFT LCD 电源控制引脚使能
**************************************************************/
static void Lcd_PowerEnable(int invpwren,int pwren)
{
//GPG4 is setted as LCD_PWREN
rGPGUP=rGPGUP&(~(1<<4))|(1<<4); // Pull-up disable
rGPGCON=rGPGCON&(~(3<<8))|(3<<8); //GPG4=LCD_PWREN
rGPGDAT = rGPGDAT | (1<<4) ;
// invpwren=pwren;
//Enable LCD POWER ENABLE Function
rLCDCON5=rLCDCON5&(~(1<<3))|(pwren<<3); // PWREN
rLCDCON5=rLCDCON5&(~(1<<5))|(invpwren<<5); // INVPWREN
}
//*****************************************************************************
static void LCD_LTS350Q1_PE1_Init(void)
{
//qjy: turn on the blacklight!
GPB1_TO_OUT();
GPB1_TO_1();
// rGPCUP=0xffffffff; // Disable Pull-up register
rGPCUP = 0x00000000;
// rGPCCON=0xaaaa56a9; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND
rGPCCON = 0xaaaa02a9;
// rGPDUP=0xffffffff; // Disable Pull-up register
rGPDUP = 0x00000000;
rGPDCON=0xaaaaaaaa; //Initialize VD[15:8]
rLCDCON1=(CLKVAL_TFT_240320<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;
// TFT LCD panel,12bpp TFT,ENVID=off
rLCDCON2=(VBPD_240320<<24)|(LINEVAL_TFT_240320<<14)|(VFPD_240320<<6)|(VSPW_240320);
rLCDCON3=(HBPD_240320<<19)|(HOZVAL_TFT_240320<<8)|(HFPD_240320);
rLCDCON4=(MVAL<<8)|(HSPW_240320);
// rLCDCON5=(1<<11)|(0<<9)|(0<<8)|(0<<6)|(BSWP<<1)|(HWSWP); //FRM5:6:5,HSYNC and VSYNC are inverted
rLCDCON5 = (1<<11) | (1<<10) | (1<<9) | (1<<8) | (0<<7) | (0<<6)
| (1<<3) |(BSWP<<1) | (HWSWP);
rLCDSADDR1=(((U32)LCD_BUFFER_CAM>>22)<<21)|M5D((U32)LCD_BUFFER_CAM>>1);
rLCDSADDR2=M5D( ((U32)LCD_BUFFER_CAM+(SCR_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*2))>>1 );
rLCDSADDR3=(((SCR_XSIZE_TFT_240320-LCD_XSIZE_TFT_240320)/1)<<11)|(LCD_XSIZE_TFT_240320/1);
rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
rTCONSEL &= (~7) ; // Disable LPC3480
// rTCONSEL&=~((1<<4)|1); // Disable LCC3600, LPC3600
rTPAL=0; // Disable Temp Palette
//LcdBkLtSet( 70 ) ;
Lcd_PowerEnable(0, 1);
Lcd_EnvidOnOff(1); //turn on vedio
}
//*****************************************************************************
static void Paint_Bmp(int x0,int y0,int h,int l,unsigned char bmp[])
{
int x,y;
U32 c;
int p = 0;
for( y = y0 ; y < l ; y++ )
{
for( x = x0 ; x < h ; x++ )
{
c = bmp[p+1] | (bmp[p]<<8) ;
if ( ( (x0+x) < SCR_XSIZE_TFT_240320) && ( (y0+y) < SCR_YSIZE_TFT_240320) )
LCD_BUFFER_CAM[y0+y][x0+x] = c ;
p = p + 2 ;
}
}
}
void Camera_Test(void)
{
int i;
Uart_Printf("\nCamera Preview Test\n");
CamPortSet();
CamReset();
// Initializing camif
rCLKCON |= (1<<19); // enable camclk
ChangeUPllValue(56, 2, 1); // UPLL clock = 96MHz, PLL input 12MHz
rCLKDIVN|=(1<<3); // UCLK 48MHz setting for UPLL 96MHz
// 0:48MHz, 1:24MHz, 2:16MHz, 3:12MHz...
// Camera clock = UPLL/[(CAMCLK_DIV+1)X2]
switch(USED_CAM_TYPE)
{
case CAM_AU70H :
if (AU70H_VIDEO_SIZE==1152)
SetCAMClockDivider(CAMCLK24000000); //Set Camera Clock for SXGA
if (AU70H_VIDEO_SIZE==640)
SetCAMClockDivider(CAMCLK16000000); //Set Camera Clock for VGA
break;
case CAM_S5X3A1 :
SetCAMClockDivider(CAMCLK24000000); //Set Camera Clock for SXGA
break;
default : // 24MHz
SetCAMClockDivider(CAMCLK24000000); //Set Camera Clock 24MHz s5x532, ov7620
break;
}
#if (USED_CAM_TYPE==CAM_OV7620)
i = Test_OV9650();
if( i )
{
Uart_Printf("\nTest is failed!!!\n");
return ;
}
#else
// Initializing camera module
CamModuleReset(); // s5x532 must do this..
Delay(100); // ready time of s5x433, s5x532 IIC interface. needed...
CameraModuleSetting();
#endif
Uart_Printf("Initializing end...\n");
Test_CamPreview() ;
Uart_Printf("\nCamera Preview Test End\n");
rCLKCON &= ~(1<<19); // disable camclk
LCD_LTS350Q1_PE1_Init(); //
}
void CamPortSet(void)
{
save_GPJCON = rGPJCON;
save_GPJDAT = rGPJDAT;
save_GPJUP = rGPJUP;
rGPJCON = 0x2aaaaaa;
rGPJDAT = 0;
rGPJUP = 0;
}
void CamPortReturn(void)
{
rGPJCON = save_GPJCON;
rGPJDAT = save_GPJDAT;
rGPJUP = save_GPJUP;
}
void CamPreviewIntUnmask(void)
{
rINTSUBMSK &= ~(BIT_SUB_CAM_P);//INT CAMERA Port A ENABLE
rINTMSK &= ~(BIT_CAM);
}
void CamCodecIntUnmask(void)
{
rINTSUBMSK &= ~(BIT_SUB_CAM_C);//INT CAMERA Port B ENABLE
rINTMSK &= ~(BIT_CAM);
}
void CamPreviewIntMask(void)
{
rINTSUBMSK |= BIT_SUB_CAM_P;//INT CAMERA Port A ENABLE
rINTMSK |= (BIT_CAM);
}
void CamCodecIntMask(void)
{
rINTSUBMSK |= BIT_SUB_CAM_C;//INT CAMERA Port B ENABLE
rINTMSK |= (BIT_CAM);
}
/******************************************************
* *
* camera interface initialization *
* *
*********************