📄 ov2640.c
字号:
}
/*
ovcamerachip_reg8_write(0xff,00);
regval = width/4;
ovcamerachip_reg8_write(0x5A,regval);
regval = height/4;
ovcamerachip_reg8_write(0x5B,regval);
regval = (width>>10) & 0x03;
regval += (u8) (height >>8) & 0x04;
ovcamerachip_reg8_write(0x5C,regval);
*/
g_ovcamerachip.width = width;
g_ovcamerachip.height = height;
ov2640print("camerasize( - )\n");
return 0;
}
void zoomscale(u8 zoom)
{
unsigned int inwidth,inheight;
unsigned int xoff,yoff;
unsigned int cropwidth,cropheight;
u8 izoom,regval;
inwidth =800;
inheight =600;
ov2640print("zoomscale( + )\n");
if( zoom >5 )
{
izoom = zoom+5;
}
else
{
izoom =zoom *2;
}
xoff = 8 * izoom;
yoff = 6 * izoom;
cropwidth = inwidth - xoff * 2;
cropheight = inheight -yoff *2;
if(g_ovcamerachip.stream)
{
xoff*=2;
yoff*=2;
cropwidth*=2;
cropheight*=2;
}
regval = cropwidth / 4;
ovcamerachip_reg8_write ( 0x51, regval );
regval = cropheight / 4;
ovcamerachip_reg8_write ( 0x52, regval );
regval = xoff & 0xff;
ovcamerachip_reg8_write ( 0x53, regval );
regval = yoff & 0xff;
ovcamerachip_reg8_write ( 0x54, regval );
regval = (cropheight >>3 ) & 0x80;
regval += (cropwidth >>7 ) & 0x08;
regval += ( xoff >>8 ) & 0x07;
regval += ( yoff >>4 ) & 0x70;
ovcamerachip_reg8_write ( 0x55, regval );
regval = 0;
inwidth = g_ovcamerachip.width;
inheight = g_ovcamerachip.height;
while ( 2 * inheight < cropheight )
{
regval++;
cropheight /= 2;
}
regval <<= 3;
while ( 2* inwidth < cropwidth )
{
regval++;
cropwidth /=2;
}
if( regval >0 )
{
regval += 0x80;
}
ovcamerachip_reg8_write ( 0x50, regval );
u8 camclock = 0x04;
if (g_ovcamerachip.format != OVCAMERACHIP_SFT_JPEG)
{
if(regval & 0x80)
{
camclock = ( regval >>3 ) & 0x07;
regval = regval & 0x07;
if(regval > camclock)
{
camclock = regval;
}
camclock = 0x01 <<camclock;
}
if( camclock > 0x08 )
{
camclock = 0x08;
}
}
ovcamerachip_reg8_write ( 0xd3, camclock );
ov2640print("zoomscale( - )\n");
return;
}
//still image
static void stillimage( void ) //version 1.01
{
u8 reg,frames;
u32 expgain;
u8 pels=3;
ov2640print("stillimage( + )\n");
/* agcaecswitch(0);
expgain = getVideoExposureGain();
g_ovcamerachip.exposure = expgain;
table_write( OV_REGS_STILLIMAGE );
zoomscale( g_ovcamerachip.zoom );
ovcamerachip_reg8_write(0xc3,0xed);
ovcamerachip_reg8_write(0x7f,0x00);
setStillimageExposure(expgain, REG11A_UXGA);
ovcamerachip_reg8_write(0xff,0x00);
ovcamerachip_reg8_write(0xeb,0x30);
expgain = 0;
frames = 0;
ovcamerachip_reg8_write(0xdd,0x73);
ovcamerachip_reg8_write(0xe0,0x00);
ovcamerachip_reg8_write(0xe9,0x3F);
do
{
ovcamerachip_reg8_read(0xe9,®);
if(reg & 0x04)
{
ovcamerachip_reg8_write(0xe9,0x3F);
frames++;
}
mdelay(1);
expgain++;
} while ((frames < 3)&&~expgain);
ovcamerachip_reg8_write(0xdd,0x7f);
ovcamerachip_reg8_write(0xeb,0x30);
mdelay(10);
*/
ov2640print("setting width is %d\n",g_ovcamerachip.width);
switch(g_ovcamerachip.width)
{
case QCIF:pels=0;
ov2640print("This is QCIF:176*144 MODULE\n");
break;
case QVGA:pels=1;
ov2640print("This is QVGA:320*240 MODULE\n");
break;
case CIF:pels=2;
ov2640print("This is CIF:325*288 MODULE\n");
break;
case VGA:pels=3;
ov2640print("This is VGA:640*480 MODULE\n");
break;
case SVGA:pels=4;
ov2640print("This is SVGA:800*600 MODULE\n");
break;
case XGA:pels=5;
ov2640print("This is XGA:1024*768 MODULE\n");
break;
case SXGA:pels=6;
ov2640print("This is SXGA:1280*1024 MODULE\n");
break;
default:ov2640print("this camera does not support this size\n");
return -1;
break;
}
table_write(OV2640_SETTING_PELS[pels]);
ov2640print("stillimage( - )\n");
}
static void preview_start( void )
{
u8 reg;
u8 pels=3;
ov2640print("preview_start( + )\n");
//agcaecswitch(1);
//ovcamerachip_reg8_write(0xe0,0x14);
ov2640print("setting width is %d\n",g_ovcamerachip.width);
switch(g_ovcamerachip.width)
{
case QCIF:pels=0;
ov2640print("This is QCIF:176*144 MODULE\n");
break;
case QVGA:pels=1;
ov2640print("This is QVGA:320*240 MODULE\n");
break;
case CIF:pels=2;
ov2640print("This is CIF:325*288 MODULE\n");
break;
case VGA:pels=3;
ov2640print("This is VGA:640*480 MODULE\n");
break;
case SVGA:pels=4;
ov2640print("This is SVGA:800*600 MODULE\n");
break;
case XGA:pels=5;
ov2640print("This is XGA:1024*768 MODULE\n");
break;
case SXGA:pels=6;
ov2640print("This is SXGA:1280*1024 MODULE\n");
break;
default:ov2640print("this camera does not support this size\n");
return -1;
break;
}
table_write(OV2640_SETTING_PELS[pels]);
//table_write(OV_REGS_PREVIEW);
//zoomscale( g_ovcamerachip.zoom );
/* reg = g_ovcamerachip.framerate;
ovcamerachip_reg8_write(0xff,0x01);
ovcamerachip_reg8_write(0x11,reg);
*/
/* setBandingFilter(g_ovcamerachip.lightfrequency);
ovcamerachip_reg8_write(0xff,0x00);
ovcamerachip_reg8_write(0xdd,0x7f);
mdelay(1);
ovcamerachip_reg8_write(0xe0,0x00);
mdelay(1);
ovcamerachip_reg8_write(0xeb,0x31);*/
ov2640print("preview_start( - )\n");
}
static void stream_start( void )
{
/*
.
.
.
*/
mdelay(1);
}
static void stream_stop( void )
{
u8 reg;
u32 i=0;
ovcamerachip_reg8_write(0xff,0x00);
ovcamerachip_reg8_read(0xeb,®);
if( (reg & 0x10) == 0x00)
{
return;
}
ovcamerachip_reg8_write(0xeb,0x20);
ovcamerachip_reg8_write(0xe9,0x02);
do
{
ovcamerachip_reg8_read(0xe9,®);
if ( ( reg & 0x02 ) ==0 )
{
break;
}
i++;
}while(i < 100000);
mdelay(1);
}
int camerachip_ip_init( void )
{
//使能TABLE13
ovcamerachip_reg8_write(0xff,0x01);
//复位进入UXGA模式 不允许缩放颜色条测试模式关闭
ovcamerachip_reg8_write(0x12,0x80);
//延时1秒
mdelay(1);
//写入UXGA的配置
table_write(OV_REGS_INITIALIZE);
/*此为以前的代码*/
//****************************
g_ovcamerachip.width = 176;
g_ovcamerachip.height = 144;
g_ovcamerachip.framerate = 0x01;
g_ovcamerachip.exposure = 20000;
g_ovcamerachip.lightfrequency = 50;
g_ovcamerachip.format = OVCAMERACHIP_SFT_YUV422 ;
g_ovcamerachip.saturation = -1;
g_ovcamerachip.brightness = -1;
g_ovcamerachip.sharpness = -1;
g_ovcamerachip.contrast = -1;
g_ovcamerachip.whitebalance = -1;
g_ovcamerachip.specialeffect = -1;
g_ovcamerachip.zoom = 0;
g_ovcamerachip.flip =0;
g_ovcamerachip.mirror =0;
// ***********************************/
/* mdelay(1);
ovcamerachip_reg8_write(0xff,0x00);
ovcamerachip_reg8_write(0xdd,0x73);
ovcamerachip_reg8_write(0xe0,0x14);
*/
return 0;
}
int camerachip_ip_set_format(unsigned int width, unsigned int height, int format)
{
int ret;
ov2640print("camerachip_ip_set_format( + )\n");
if ( ( width > OV2640_MAX_WIDTH ) || ( height > OV2640_MAX_HEIGHT ) )
{
return -1;
}
ret = camerasize( width, height );
if(ret)
{
return -1;
}
ret = videoformat ( format );
if(ret)
{
return ret;
}
ov2640print("camerachip_ip_set_format( - )\n");
return 0;
}
int camerachip_ip_zoom(u8 zoom)
{
if( zoom>OV2640_MAXLEVEL_ZOOM )
{
return -1;
}
ovcamerachip_reg8_write(0xeb,0x20);
zoomscale( zoom );
ovcamerachip_reg8_write(0xeb,0x31);
g_ovcamerachip.zoom = zoom;
return 0;
}
int camerachip_ip_flip(int flip)
{
int ret;
u8 reg04;
ret = ovcamerachip_reg8_write(0xff,0x01);
ovcamerachip_reg8_read( 0x04, ®04);
if( flip == 0 )
{
reg04 &= 0xAF;
}
else
{
reg04 |= 0x50;
}
ovcamerachip_reg8_write(0x04,reg04);
return 0;
}
int camerachip_ip_mirror(int mirror)
{
int ret;
u8 reg04;
ret = ovcamerachip_reg8_write(0xff,0x01);
ovcamerachip_reg8_read( 0x04, ®04);
if( mirror == 0 )
{
reg04 &= 0x7F;
}
else
{
reg04 |= 0x80;
}
ovcamerachip_reg8_write(0x04,reg04);
return 0;
}
int camerachip_ip_lightfrequency(int lightfrequency)
{
if( ( lightfrequency!=50 ) && ( lightfrequency !=60 ) )
{
return -1;
}
setBandingFilter (lightfrequency);
g_ovcamerachip.lightfrequency = lightfrequency;
return 0;
}
int camerachip_ip_framerate(int framerate)
{
u8 reg;
int lightfrequency;
if(( framerate < 0 ) || ( framerate > OV2640_MAXLEVEL_FRAMERATE ))
{
return -1;
}
reg = framerate;
ovcamerachip_reg8_write(0xff,0x01);
ovcamerachip_reg8_write(0x11,reg);
g_ovcamerachip.framerate = framerate;
lightfrequency = g_ovcamerachip.lightfrequency;
setBandingFilter ( lightfrequency );
return 0;
}
int camerachip_ip_specialeffect( int specialeffect )
{
if( specialeffect > OV2640_MAXLEVEL_SPECIALEFFECT )
{
return -1;
}
if( specialeffect < 0 )
{
table_mask_write(OV2640_SPECIALEFFECT_DISABLE);
}
else
{
table_mask_write(OV_SETTING_SPECIALEFFECT[specialeffect]);
}
g_ovcamerachip.specialeffect = specialeffect;
return 0;
}
int camerachip_ip_brightness( int brightness )
{
if( brightness > OV2640_MAXLEVEL_BRIGHTNESS )
{
return -1;
}
if( brightness <0 )
{
table_mask_write(OV2640_BRIGHTNESS_DISABLE);
}
else
{
table_mask_write(OV_SETTING_BRIGHTNESS[brightness]);
table_mask_write(OV2640_BRIGHTNESS_ENABLE);
}
g_ovcamerachip.brightness = brightness;
return 0;
}
int camerachip_ip_sharpness( int sharpness )
{
if ( sharpness > OV2640_MAXLEVEL_SHARPNESS)
{
return -1;
}
if( sharpness <0 )
{
table_mask_write(OV2640_SHARPNESS_AUTO);
}
else
{
table_mask_write(OV2640_SHARPNESS_MANUAL);
table_mask_write(OV_SETTING_SHARPNESS[sharpness]);
}
g_ovcamerachip.sharpness = sharpness;
return 0;
}
int camerachip_ip_hue( int hue )
{
if( hue > OV2640_MAXLEVEL_HUE)
{
return -1;
}
if( hue <0 )
{
table_mask_write(OV2640_HUE_DISABLE);
}
else
{
table_mask_write(OV_SETTING_HUE[hue]);
table_mask_write(OV2640_HUE_ENABLE);
}
g_ovcamerachip.hue = hue;
return 0;
}
int camerachip_ip_saturation( int saturation )
{
if( saturation > OV2640_MAXLEVEL_SATURATION)
{
return -1;
}
if( saturation <0 )
{
table_mask_write(OV2640_SATURATION_DISABLE);
}
else
{
table_mask_write(OV_SETTING_SATURATION[saturation]);
table_mask_write(OV2640_SATURATION_ENABLE);
}
g_ovcamerachip.saturation = saturation;
return 0;
}
int camerachip_ip_contrast( int contrast )
{
if( contrast > OV2640_MAXLEVEL_CONTRAST)
{
return -1;
}
if (contrast < 0 )
{
table_mask_write(OV2640_CONTRAST_DISABLE);
}
else
{
table_mask_write(OV_SETTING_CONTRAST[contrast]);
table_mask_write(OV2640_CONTRAST_ENABLE);
}
g_ovcamerachip.contrast = contrast;
return 0;
}
int camerachip_ip_whitebalance( int whitebalance )
{
if( whitebalance > OV2640_MAXLEVEL_WHITEBALANCE )
{
return -1;
}
if( whitebalance < 0 )
{
table_mask_write(OV2640_WHITEBALANCE_AUTO);
}
else
{
table_mask_write(OV_SETTING_WHITEBALANCE[whitebalance]);
}
g_ovcamerachip.whitebalance = whitebalance;
return 0;
}
int camerachip_ip_gamma( int gamma )
{
return 0;
}
int camerachip_ip_stream_on()
{
if(g_ovcamerachip.stream)
{
stillimage();
}
else
{
preview_start();
}
return 0;
}
int camerachip_ip_stream_off( void )
{
//stream_stop();
return 0;
}
int camerachip_ip_debug( void )
{
//table_write(OV_REGS_DEBUG);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -