⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 camif.c

📁 wince bsp 原文件, 在s3c2442上使用
💻 C
📖 第 1 页 / 共 2 页
字号:
  else
    multiplier=2;
	
  if(WinHorOffset==0 && WinVerOffset==0)
    WinOfsEn=0;
  else
    WinOfsEn=1;

  SrcWidth=CAM_SRC_HSIZE-WinHorOffset*2;
  SrcHeight=CAM_SRC_VSIZE-WinVerOffset*2;

  if(SrcWidth>=CoDstWidth) ScaleUp_H_Co=0; //down
  else ScaleUp_H_Co=1;		//up

  if(SrcHeight>=CoDstHeight) ScaleUp_V_Co=0;
  else ScaleUp_V_Co=1;		

  if(SrcWidth>=PrDstWidth) ScaleUp_H_Pr=0; //down
  else ScaleUp_H_Pr=1;		//up

  if(SrcHeight>=PrDstHeight) ScaleUp_V_Pr=0;   // edited 040225
  else ScaleUp_V_Pr=1;		

  ////////////////// common control setting
  //	rCIGCTRL |= (1<<26)|(0<<27); // inverse PCLK, test pattern
  // xm.h 22:15 9.15
  rCIGCTRL |= (0<<26)|(0<<27)|(1<<25)|(0<<24);//|(0<<28); // inverse PCLK, test pattern --1->0 @@@@2
  //	rCIGCTRL &= ~(1<<25);
	
  rCIWDOFST = (1<<30)|(0xf<<12); // clear overflow 
  rCIWDOFST = 0;
  rCIWDOFST = (WinOfsEn << 31) | (WinHorOffset << 16) | WinVerOffset;
  rCISRCFMT=(CAM_ITU601<<31)|(0<<30)|(0<<29)|(CAM_SRC_HSIZE<<16)|(CAM_ORDER_YCBYCR<<14)|(CAM_SRC_VSIZE);
                                                                 // CAM_ORDER_CBYCRY
  ////////////////// codec port setting
  rCICOYSA1=0x32000000;//CoFrameBuffer; 9.15 xm.h
  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=(CAM_CODEC_IN_422<<31)|(CAM_CODEC_OUTPUT<<30)|(CoDstWidth<<16)|(CAM_FLIP_NORMAL<<14)|(CoDstHeight);

  CalculateBurstSize(CoDstWidth, &MainBurstSizeY, &RemainedBurstSizeY);
  CalculateBurstSize(CoDstWidth/2, &MainBurstSizeC, &RemainedBurstSizeC);
  rCICOCTRL=(MainBurstSizeY<<19)|(RemainedBurstSizeY<<14)|(MainBurstSizeC<<9)|(RemainedBurstSizeC<<4);
	// xm.h 9.15
  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);
  rCICOSCPREDST=((SrcWidth/PreHorRatio)<<16)|(SrcHeight/PreVerRatio); 
  rCICOSCCTRL=(CAM_SCALER_BYPASS_OFF<<31)|(ScaleUp_H_Co<<30)|(ScaleUp_V_Co<<29)|(MainHorRatio<<16)|(MainVerRatio);
  //	rCICOSCCTRL=(CAM_SCALER_BYPASS_OFF<<31)|(1<<30)|(1<<29)|(MainHorRatio<<16)|(MainVerRatio);
                 // xm.h  9.8  

  rCICOTAREA=CoDstWidth*CoDstHeight;

  ///////////////// preview port setting
  // direct preview mode
  rCIPRCLRSA1 = (U32)LCDFRAMEBUFFER + (240*140);
  rCIPRCLRSA2 = rCIPRCLRSA1;
  rCIPRCLRSA3 = rCIPRCLRSA2;
  rCIPRCLRSA4 = rCIPRCLRSA3;

  rCIPRTRGFMT=(PrDstWidth<<16)|(CAM_FLIP_NORMAL<<14)|(PrDstHeight);

  // RGB16B
  CalculateBurstSize(PrDstWidth*2, &MainBurstSizeRGB, &RemainedBurstSizeRGB);
  rCIPRCTRL=(MainBurstSizeRGB<<19)|(RemainedBurstSizeRGB<<14);

  CalculatePrescalerRatioShift(SrcWidth, PrDstWidth, &PreHorRatio, &H_Shift);
  CalculatePrescalerRatioShift(SrcHeight, PrDstHeight, &PreVerRatio, &V_Shift);
  MainHorRatio=(SrcWidth<<8)/(PrDstWidth<<H_Shift);
  MainVerRatio=(SrcHeight<<8)/(PrDstHeight<<V_Shift);
  
  // rCIPRSCPRERATIO=((10-1-1)<<28)|(2<<16)|(2);
  rCIPRSCPRERATIO=((10-H_Shift-V_Shift)<<28)|(PreHorRatio<<16)|(PreVerRatio);
  
  rCIPRSCPREDST=((SrcWidth/PreHorRatio)<<16)|(SrcHeight/PreVerRatio);
  rCIPRSCCTRL=(1<<31)|(CAM_PVIEW_OUTPUT<<30)|(ScaleUp_H_Pr<<29)|(ScaleUp_V_Pr<<28)|(MainHorRatio<<16)|(MainVerRatio);
    
  // 16B               // 9.15 xm.h
  rCIPRTAREA= PrDstWidth*PrDstHeight;
  //rCIPRTAREA= SrcWidth*SrcHeight;  //9.15  hxm
}

/********************************************************
 CalculateBurstSize - Calculate the busrt lengths
 
 Description:	
 - dstHSize: the number of the byte of H Size.
 
*/
void CalculateBurstSize(U32 hSize,U32 *mainBurstSize,U32 *remainedBurstSize)
{
  U32 h = hSize / 4;

  switch (h % 16) {
  case 0:
    *mainBurstSize = 16;
    *remainedBurstSize = 16;
    break;
  case 4:
    *mainBurstSize = 16;
    *remainedBurstSize = 4;
    break;
  case 8:
    *mainBurstSize = 16;
    *remainedBurstSize = 8;
    break;
  case 12:
    *mainBurstSize = 8;
    *remainedBurstSize = 4;
  default:
    *mainBurstSize = 4;
    *remainedBurstSize = h % 4 ? h % 4 : 4;
    break;
  }
}

/********************************************************
 CalculatePrescalerRatioShift - none
 
 Description:	
 - none
 
*/
void CalculatePrescalerRatioShift(U32 SrcSize, U32 DstSize, U32 *ratio,U32 *shift)
{
  if(SrcSize>=64*DstSize) {
    Uart_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;
  }    	
}

/********************************************************
 CamCaptureStart - Start camera capture operation.
 
 Description:	
 - mode= CAM_CODEC_CAPTURE_ENABLE_BIT or CAM_PVIEW_CAPTURE_ENABLE_BIT or both
  
*/
void CamCaptureStart(U32 mode)
{ 
  if(mode & CAM_CODEC_SCALER_CAPTURE_ENABLE_BIT) {
    rCICOSCCTRL |= CAM_CODEC_SACLER_START_BIT;
  }
  if(mode & CAM_PVIEW_SCALER_CAPTURE_ENABLE_BIT) {
    rCIPRSCCTRL |= CAM_PVIEW_SACLER_START_BIT;
  }
  if(mode & CAM_CAMIF_GLOBAL_CAPTURE_ENABLE_BIT) {
    rCICOSCCTRL |= CAM_CAMIF_GLOBAL_CAPTURE_ENABLE_BIT;
  }
  rCIIMGCPT |= CAM_CAMIF_GLOBAL_CAPTURE_ENABLE_BIT | mode;
}

void bpp16(void)
{
  Lcd_Port_Init();
  My_bit16(); //  Lcd_Init(MODE_TFT_16BIT_240320);
  rLCDCON5 |= 1; // halfword swap enable -> Camera data is halfword swap type, 16bit
  Glib_Init(MODE_TFT_16BIT_240320);

  Uart_Printf("[TFT 256K COLOR(16bit/1pixel) LCD TEST]\n");
  Lcd_TconDisable();
  Lcd_PowerEnable(1, 1);
  Lcd_EnvidOnOff(1);
}

#define S2440FCLK (400000000)
static void Delay1(USHORT count)
{
  volatile int i, j = 0;
  volatile static int loop = S2440FCLK/100000;

  for(;count > 0;count--)
    for(i=0;i < loop; i++) j++; 
}

int
initialize(void)
{
  U32 i, *data;

  rGPJCON = 0x2aaaaaa;
  rGPJDAT = 0x0;
  rGPJUP =  0x1fff;  // 9.15 xm.h
  CamReset();
  //rGPJCON = 0x0aaaaaa;
  //rGPJDAT = 0;
  //rGPJUP = 0x1fff;
  rGPJCON = 0x1aaaaaa;
  rGPJDAT = 0x1000;
  rGPJUP = 0x1fff;

 // IicPortSet();
 // Delay1(300);

  rCLKCON |= (1<<19); // enable camclk
  ChangeUPllValue(60, 4, 1);		// UPLL clock = 96MHz, PLL input 16.9344MHz
  rIICCON = 0xe0;   // 0xaf 
  rCLKDIVN|=(1<<3); // UCLK 48MHz setting for UPLL 96MHz
  rCLKDIVN|=0x7;
  Uart_Printf("1...\n");
  SetCAMClockDivider(CAMCLK24000000); //Set Camera Clock 24MHz s5x532, ov7620
  Uart_Printf("2...\n");
//  Delay1(200);//---------- // ready time of s5x433, s5x532 IIC interface. needed...
  Uart_Printf("Initializing end...\n");

  //Initialize LCD
  // RGB16B 
  bpp16();
  data = (U32*)LCDFRAMEBUFFER;
  for (i = 0; i < LCD_SIZE / 8 * 1; ++i) *data++ = 0x001f001f; // blue
  for (; i < LCD_SIZE / 8 * 2; ++i) *data++ = 0x07e007e0; //green
  for (; i < LCD_SIZE / 8 * 3; ++i) *data++ = 0xf800f800; //red
  for (; i < LCD_SIZE / 8 * 4; ++i) *data++ = 0xf800001f; // blue & red
//  Test_Iic();
 // Test_Iic();
 // Test_Iic();
//  Test_Iic();
//  Test_Iic();
//  Test_Iic();
  CAM_WriteBlock();
  
  // Initialize Camera interface
  CamInit(240, 180, 240, 180, 0, 0, CAM_FRAMEBUFFER_C, CAM_FRAMEBUFFER_P);
  Uart_Printf("\n preview sc control = %x\n", rCIPRSCCTRL);

  CamCaptureStart(CAM_PVIEW_SCALER_CAPTURE_ENABLE_BIT);
  CamCaptureStart(CAM_CODEC_SCALER_CAPTURE_ENABLE_BIT); // xm.h 12.04

  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -