📄 usbcam.c
字号:
DEBUGMSG(1, (TEXT("Sensor is an OV6620\r\n")));
break;
case 2:
ov.sensor = SEN_OV6630;
DEBUGMSG(1, (TEXT("Sensor is an OV6630AE\r\n")));
break;
case 3:
ov.sensor = SEN_OV6630;
DEBUGMSG(1, (TEXT("Sensor is an OV6630AF\r\n")));
break;
default:
break;
}
/* Set sensor-specific vars */
ov.maxwidth = 352;
ov.maxheight = 288;
ov.minwidth = 64;
ov.minheight = 48;
// FIXME: These do not match the actual settings yet
ov.brightness = 0x80 << 8;
ov.contrast = 0x80 << 8;
ov.colour = 0x80 << 8;
ov.hue = 0x80 << 8;
if (ov.sensor == SEN_OV6620) {
DEBUGMSG(1, (TEXT("Writing 6x20 registers\r\n")));
bRc = WriteRegisters(pDrv, aRegvalsNorm6x20);
if (bRc = FALSE)
return bRc;
}
else {
DEBUGMSG(1, (TEXT("Writing 6x30 registers\r\n")));
bRc = WriteRegisters(pDrv, aRegvalsNorm6x30);
if (bRc == FALSE)
return bRc;
}
return TRUE;
}
DWORD OV511Configure(PDRVCONTEXT pDrv)
{
OV511REGVALS aRegvalsInit511[] = {
{ OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
{ OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
{ OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
{ OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
{ OV511_REG_BUS, R51x_SYS_RESET, 0x3f },
{ OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
{ OV511_REG_BUS, R51x_SYS_RESET, 0x3d },
{ OV511_DONE_BUS, 0x0, 0x00},
};
OV511REGVALS aRegvalsNorm511[] = {
{ OV511_REG_BUS, R511_DRAM_FLOW_CTL, 0x01 },
{ OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
{ OV511_REG_BUS, R51x_SYS_SNAP, 0x02 },
{ OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
{ OV511_REG_BUS, R511_FIFO_OPTS, 0x1f },
{ OV511_REG_BUS, R511_COMP_EN, 0x00 },
{ OV511_REG_BUS, R511_COMP_LUT_EN, 0x03 },
{ OV511_DONE_BUS, 0x0, 0x00 },
};
OV511REGVALS aRegvalsNorm511Plus[] = {
{ OV511_REG_BUS, R511_DRAM_FLOW_CTL, 0xff },
{ OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
{ OV511_REG_BUS, R51x_SYS_SNAP, 0x02 },
{ OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
{ OV511_REG_BUS, R511_FIFO_OPTS, 0xff },
{ OV511_REG_BUS, R511_COMP_EN, 0x00 },
{ OV511_REG_BUS, R511_COMP_LUT_EN, 0x03 },
{ OV511_DONE_BUS, 0x0, 0x00 },
};
BYTE customid;
BOOL bRc;
bRc = RegisterRead(pDrv, R511_SYS_CUST_ID, &customid);
if (bRc == FALSE) {
DEBUGMSG(1, (TEXT("Unable to read camera bridge registers\r\n")));
}
DEBUGMSG (1, (TEXT("CustomID = %d"), customid));
if (customid == 70) /* USB Life TV (PAL/SECAM) */
ov.pal = 1;
//初始化摄像头状态
ov.led_policy = led;
ov.compress = compress;
ov.lightfreq = lightfreq;
ov.num_inputs = 1; /* Video decoder init functs. change this */
ov.backlight = backlight;
ov.mirror = mirror;
ov.auto_brt = autobright;
ov.auto_gain = autogain;
ov.auto_exp = autoexp;
ov.bridge = BRG_OV511;
ov.bclass = BCL_OV511;
bRc = WriteRegisters(pDrv, aRegvalsInit511);
if(bRc == FALSE)
return bRc;
//给OV511寄存器赋初始值
if (ov.led_policy == LED_OFF || ov.led_policy == LED_AUTO)
OV51XLedControl(pDrv, FALSE);
/* The OV511+ has undocumented bits in the flow control register.
* Setting it to 0xff fixes the corruption with moving objects. */
switch(ov.bridge)
{
case BRG_OV511:
bRc = WriteRegisters(pDrv, aRegvalsNorm511);
break;
case BRG_OV511PLUS:
bRc = WriteRegisters(pDrv, aRegvalsNorm511Plus);
break;
default:
break;
DEBUGMSG(1, (TEXT("Invalide Chip!\r\n")));
}
if(bRc == FALSE)
{
return bRc;
}
bRc = OV511InitCompression(pDrv);
if (bRc == FALSE)
return bRc;
ov.packet_numbering = 1;
OV511SetPacketSize(pDrv, 0);
ov.snap_enabled = snapshot;
/* Test for 7xx0 */
DEBUGMSG(1, (TEXT("Testing for 0V7xx0\r\n")));
ov.primary_i2c_slave = OV7xx0_SID;
if (OV511SetSlaveIds(pDrv, OV7xx0_SID) == FALSE)
goto error;
if (OV511IICWrite(pDrv, 0x12, 0x80) == FALSE) {
/* Test for 6xx0 */
DEBUGMSG(1, (TEXT("Testing for 0V6xx0\r\n")));
ov.primary_i2c_slave = OV6xx0_SID;
if (OV511SetSlaveIds(pDrv, OV6xx0_SID) == FALSE)
goto error;
if (OV511IICWrite(pDrv, 0x12, 0x80) == FALSE) {
/* Test for 8xx0 */
DEBUGMSG(1, (TEXT("Testing for 0V8xx0\r\n")));
ov.primary_i2c_slave = OV8xx0_SID;
if (OV511SetSlaveIds(pDrv, OV8xx0_SID) == FALSE)
goto error;
if (OV511IICWrite(pDrv, 0x12, 0x80) == FALSE) {
/* Test for SAA7111A */
DEBUGMSG(1, (TEXT("Testing for SAA7111A\r\n")));
ov.primary_i2c_slave = SAA7111A_SID;
if (OV511SetSlaveIds(pDrv, SAA7111A_SID) == FALSE)
goto error;
if (OV511IICWrite(pDrv, 0x0d, 0x00) == FALSE) {
/* Test for KS0127 */
DEBUGMSG(1, (TEXT("Testing for KS0127\r\n")));
ov.primary_i2c_slave = KS0127_SID;
if (OV511SetSlaveIds(pDrv, KS0127_SID) == FALSE)
goto error;
if (OV511IICWrite(pDrv, 0x10, 0x00) == FALSE) {
DEBUGMSG(1, (TEXT("err: Can't determine sensor slave IDs\r\n")));
goto error;
}
else
{
//if (ks0127_configure(pDrv) == FALSE) {
DEBUGMSG(1, (TEXT("Failed to configure KS0127\r\n")));
goto error;
//}
}
}
else
{
//if (saa7111a_configure(pDrv) == FALSE) {
DEBUGMSG(1, (TEXT("Failed to configure SAA7111A\r\n")));
goto error;
//}
}
} else {
DEBUGMSG(1, (TEXT("Detected unsupported OV8xx0 sensor\r\n")));
goto error;
}
} else {
if (OV6XX0Configure(pDrv) == FALSE) {
DEBUGMSG(1, (TEXT("Failed to configure OV6xx0\r\n")));
goto error;
}
}
}
else
{
if (OV7XX0Configure(pDrv) == FALSE) {
DEBUGMSG(1, (TEXT("Failed to configure OV7xx0\r\n")));
goto error;
}
}
return TRUE;
error:
DEBUGMSG(1, (TEXT("OV511 Config failed")));
return FALSE;
}
BOOL
ModeInitRegs(PDRVCONTEXT pDrv,
int width,
int height,
int mode,
int sub_flag)
{
BOOL bRc = FALSE;
if (pDrv == NULL)
return FALSE;
if (ov.bclass == BCL_OV518) {
//bRc = OV518ModeInitRegs(pDrv, width, height, mode, sub_flag);
} else {
bRc = OV511ModeInitRegs(pDrv, width, height, mode, sub_flag);
}
if (bRc == FALSE)
return bRc;
switch (ov.sensor) {
case SEN_OV7610:
case SEN_OV7620:
case SEN_OV76BE:
case SEN_OV8600:
case SEN_OV6620:
case SEN_OV6630:
bRc = SetOVSensorWindow(pDrv, width, height, mode, sub_flag);
break;
case SEN_KS0127:
case SEN_KS0127B:
bRc = FALSE;
break;
case SEN_SAA7111A:
// rc = mode_init_saa_sensor_regs(ov, width, height, mode,
// sub_flag);
break;
default:
bRc = FALSE;
}
if (bRc == FALSE)
return bRc;
/* Sensor-independent settings */
SensorSetAutoBrightness(pDrv);
SensorSetAutoExposure(pDrv);
SensorSetBandingFilter(pDrv);
SensorSetLightFreq(pDrv);
SensorSetMirror(pDrv);
return TRUE;
}
BOOL OV511ModeInitRegs(PDRVCONTEXT pDrv,
int width,
int height,
int mode,
int sub_flag)
{
int hsegs, vsegs;
if (OV51xStop(pDrv) == FALSE)
{
return FALSE;
}
RegisterWrite(pDrv, R511_CAM_UV_EN, 0x01);
RegisterWrite(pDrv, R511_SNAP_UV_EN, 0x01);
RegisterWrite(pDrv, R511_SNAP_OPTS, 0x03);
/* Here I'm assuming that snapshot size == image size.
* I hope that's always true. --claudio
*/
hsegs = (width >> 3) - 1;
vsegs = (height >> 3) - 1;
RegisterWrite(pDrv, R511_CAM_PXCNT, hsegs);
RegisterWrite(pDrv, R511_CAM_LNCNT, vsegs);
RegisterWrite(pDrv, R511_CAM_PXDIV, 0x00);
RegisterWrite(pDrv, R511_CAM_LNDIV, 0x00);
/* YUV420, low pass filter on */
RegisterWrite(pDrv, R511_CAM_OPTS, 0x03);
/* Snapshot additions */
RegisterWrite(pDrv, R511_SNAP_PXCNT, hsegs);
RegisterWrite(pDrv, R511_SNAP_LNCNT, vsegs);
RegisterWrite(pDrv, R511_SNAP_PXDIV, 0x00);
RegisterWrite(pDrv, R511_SNAP_LNDIV, 0x00);
/*
if (ov->compress) {
/* Enable Y and UV quantization and compression */
/*RegisterWrite(pDrv, R511_COMP_EN, 0x07);
RegisterWrite(pDrv, R511_COMP_LUT_EN, 0x03);
ov51x_reset(ov, OV511_RESET_OMNICE);
}*/
if (OV51xRestart(pDrv) == FALSE)
{
return FALSE;
}
return TRUE;
}
BOOL OV51xSetDefaultParams(PDRVCONTEXT pDrv)
{
int size;
/* Initialize to max width/height, YUV420 or RGB24 (if supported) */
if (ModeInitRegs(pDrv, 320, 240, 0, 0) == FALSE)
{
return FALSE;
}
//这里硬编码为使用第7套设置,包大小为961
size = 961;
if(OV511SetPacketSize(pDrv,size) == FALSE)
{
DEBUGMSG(1,(TEXT("Set Packet Size Failed!\r\n")));
return FALSE;
}
return TRUE;
}
int WriteRegvals(PDRVCONTEXT pDrv)
{
RegisterWrite(pDrv,R51x_SYS_RESET,0x7f);
RegisterWrite(pDrv,R51x_SYS_INIT,0x01);
RegisterWrite(pDrv,R51x_SYS_RESET,0x7f);
RegisterWrite(pDrv,R51x_SYS_INIT,0x01);
RegisterWrite(pDrv,R51x_SYS_RESET,0x3f);
RegisterWrite(pDrv,R51x_SYS_INIT,0x01);
RegisterWrite(pDrv,R51x_SYS_RESET,0x3d);
return TRUE;
}
BOOL SensorSetAutoBrightness(PDRVCONTEXT pDrv)
{
DEBUGMSG(1, (TEXT("Config Sensor auto brightness!\r\n")));
return OV511IICWriteMask(pDrv, 0x2d, 0x10, 0x10);;
}
BOOL SensorSetMirror(PDRVCONTEXT pDrv)
{
DEBUGMSG(1, (TEXT("Config Sensor Mirror!\r\n")));
return OV511IICWriteMask(pDrv, 0x12, 0x40, 0x40);
}
BOOL SensorSetAutoExposure(PDRVCONTEXT pDrv)
{
DEBUGMSG(1, (TEXT("Config Sensor Auto Exposure!\r\n")));
return OV511IICWriteMask(pDrv, 0x13, 0x01, 0x01);
}
BOOL SensorSetBandingFilter(PDRVCONTEXT pDrv)
{
DEBUGMSG(1, (TEXT("Config Sensor Auto Exposure!\r\n")));
return OV511IICWriteMask(pDrv, 0x2d, 0x04, 0x04);
}
BOOL SensorSetLightFreq(PDRVCONTEXT pDrv)
{
int sixty = 1;
DEBUGMSG(1, (TEXT("Config Sensor Light Frequency to 60Hz!\r\n")));
OV511IICWriteMask(pDrv, 0x2a, sixty?0x00:0x80, 0x80);
OV511IICWrite(pDrv, 0x2b, sixty?0x00:0xac);
OV511IICWriteMask(pDrv, 0x76, 0x01, 0x01);
return TRUE;
}
BOOL SensorSetBacklight(PDRVCONTEXT pDrv)
{
DEBUGMSG(1, (TEXT("Config Sensor BackLight!\r\n")));
OV511IICWriteMask(pDrv, 0x68, 1?0xe0:0xc0, 0xe0);
OV511IICWriteMask(pDrv, 0x29, 1?0x08:0x00, 0x08);
OV511IICWriteMask(pDrv, 0x28, 1?0x02:0x00, 0x02);
return TRUE;
}
BOOL ParseStreamInterfaces(LPCUSB_DEVICE lpUsbDev, BYTE bIFStrm, BYTE bIFSubStrm, DWORD *pdwContext)
{
DWORD i;
LPCUSB_INTERFACE lpIF;
DWORD nStreamAlts = 0;
DWORD nOtherStreams = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -