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

📄 ov511.c

📁 ov511.c是linux下的wabcam的驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
	if (ov->stop_during_set)		if (ov51x_stop(ov) < 0)			return -EIO;	switch (ov->sensor) {	case SEN_OV7610:	case SEN_OV6620:	{		rc = i2c_w(ov, OV7610_REG_CNT, val >> 8);		if (rc < 0)			goto out;		break;	}	case SEN_OV6630:	{		rc = i2c_w_mask(ov, OV7610_REG_CNT, val >> 12, 0x0f);		if (rc < 0)			goto out;		break;	}	case SEN_OV7620:	{		unsigned char ctab[] = {			0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,			0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff		};		/* Use Y gamma control instead. Bit 0 enables it. */		rc = i2c_w(ov, 0x64, ctab[val>>12]);		if (rc < 0)			goto out;		break;	}	case SEN_SAA7111A:	{		rc = i2c_w(ov, 0x0b, val >> 9);		if (rc < 0)			goto out;		break;	}	default:	{		PDEBUG(3, "Unsupported with this sensor");		rc = -EPERM;		goto out;	}	}	rc = 0;		/* Success */	ov->contrast = val;out:	if (ov51x_restart(ov) < 0)		return -EIO;	return rc;}/* Gets sensor's contrast setting */static intsensor_get_contrast(struct usb_ov511 *ov, unsigned short *val){	int rc;	switch (ov->sensor) {	case SEN_OV7610:	case SEN_OV6620:		rc = i2c_r(ov, OV7610_REG_CNT);		if (rc < 0)			return rc;		else			*val = rc << 8;		break;	case SEN_OV6630:		rc = i2c_r(ov, OV7610_REG_CNT);		if (rc < 0)			return rc;		else			*val = rc << 12;		break;	case SEN_OV7620:		/* Use Y gamma reg instead. Bit 0 is the enable bit. */		rc = i2c_r(ov, 0x64);		if (rc < 0)			return rc;		else			*val = (rc & 0xfe) << 8;		break;	case SEN_SAA7111A:		*val = ov->contrast;		break;	default:		PDEBUG(3, "Unsupported with this sensor");		return -EPERM;	}	PDEBUG(3, "%d", *val);	ov->contrast = *val;	return 0;}/* -------------------------------------------------------------------------- *//* Sets sensor's brightness setting to "val" */static intsensor_set_brightness(struct usb_ov511 *ov, unsigned short val){	int rc;	PDEBUG(4, "%d", val);	if (ov->stop_during_set)		if (ov51x_stop(ov) < 0)			return -EIO;	switch (ov->sensor) {	case SEN_OV7610:	case SEN_OV76BE:	case SEN_OV6620:	case SEN_OV6630:		rc = i2c_w(ov, OV7610_REG_BRT, val >> 8);		if (rc < 0)			goto out;		break;	case SEN_OV7620:		/* 7620 doesn't like manual changes when in auto mode */		if (!ov->auto_brt) {			rc = i2c_w(ov, OV7610_REG_BRT, val >> 8);			if (rc < 0)				goto out;		}		break;	case SEN_SAA7111A:		rc = i2c_w(ov, 0x0a, val >> 8);		if (rc < 0)			goto out;		break;	default:		PDEBUG(3, "Unsupported with this sensor");		rc = -EPERM;		goto out;	}	rc = 0;		/* Success */	ov->brightness = val;out:	if (ov51x_restart(ov) < 0)		return -EIO;	return rc;}/* Gets sensor's brightness setting */static intsensor_get_brightness(struct usb_ov511 *ov, unsigned short *val){	int rc;	switch (ov->sensor) {	case SEN_OV7610:	case SEN_OV76BE:	case SEN_OV7620:	case SEN_OV6620:	case SEN_OV6630:		rc = i2c_r(ov, OV7610_REG_BRT);		if (rc < 0)			return rc;		else			*val = rc << 8;		break;	case SEN_SAA7111A:		*val = ov->brightness;		break;	default:		PDEBUG(3, "Unsupported with this sensor");		return -EPERM;	}	PDEBUG(3, "%d", *val);	ov->brightness = *val;	return 0;}/* -------------------------------------------------------------------------- *//* Sets sensor's saturation (color intensity) setting to "val" */static intsensor_set_saturation(struct usb_ov511 *ov, unsigned short val){	int rc;	PDEBUG(3, "%d", val);	if (ov->stop_during_set)		if (ov51x_stop(ov) < 0)			return -EIO;	switch (ov->sensor) {	case SEN_OV7610:	case SEN_OV76BE:	case SEN_OV6620:	case SEN_OV6630:		rc = i2c_w(ov, OV7610_REG_SAT, val >> 8);		if (rc < 0)			goto out;		break;	case SEN_OV7620://		/* Use UV gamma control instead. Bits 0 & 7 are reserved. *///		rc = ov_i2c_write(ov->dev, 0x62, (val >> 9) & 0x7e);//		if (rc < 0)//			goto out;		rc = i2c_w(ov, OV7610_REG_SAT, val >> 8);		if (rc < 0)			goto out;		break;	case SEN_SAA7111A:		rc = i2c_w(ov, 0x0c, val >> 9);		if (rc < 0)			goto out;		break;	default:		PDEBUG(3, "Unsupported with this sensor");		rc = -EPERM;		goto out;	}	rc = 0;		/* Success */	ov->colour = val;out:	if (ov51x_restart(ov) < 0)		return -EIO;	return rc;}/* Gets sensor's saturation (color intensity) setting */static intsensor_get_saturation(struct usb_ov511 *ov, unsigned short *val){	int rc;	switch (ov->sensor) {	case SEN_OV7610:	case SEN_OV76BE:	case SEN_OV6620:	case SEN_OV6630:		rc = i2c_r(ov, OV7610_REG_SAT);		if (rc < 0)			return rc;		else			*val = rc << 8;		break;	case SEN_OV7620://		/* Use UV gamma reg instead. Bits 0 & 7 are reserved. *///		rc = i2c_r(ov, 0x62);//		if (rc < 0)//			return rc;//		else//			*val = (rc & 0x7e) << 9;		rc = i2c_r(ov, OV7610_REG_SAT);		if (rc < 0)			return rc;		else			*val = rc << 8;		break;	case SEN_SAA7111A:		*val = ov->colour;		break;	default:		PDEBUG(3, "Unsupported with this sensor");		return -EPERM;	}	PDEBUG(3, "%d", *val);	ov->colour = *val;	return 0;}/* -------------------------------------------------------------------------- *//* Sets sensor's hue (red/blue balance) setting to "val" */static intsensor_set_hue(struct usb_ov511 *ov, unsigned short val){	int rc;	PDEBUG(3, "%d", val);	if (ov->stop_during_set)		if (ov51x_stop(ov) < 0)			return -EIO;	switch (ov->sensor) {	case SEN_OV7610:	case SEN_OV6620:	case SEN_OV6630:		rc = i2c_w(ov, OV7610_REG_RED, 0xFF - (val >> 8));		if (rc < 0)			goto out;		rc = i2c_w(ov, OV7610_REG_BLUE, val >> 8);		if (rc < 0)			goto out;		break;	case SEN_OV7620:// Hue control is causing problems. I will enable it once it's fixed.#if 0		rc = i2c_w(ov, 0x7a, (unsigned char)(val >> 8) + 0xb);		if (rc < 0)			goto out;		rc = i2c_w(ov, 0x79, (unsigned char)(val >> 8) + 0xb);		if (rc < 0)			goto out;#endif		break;	case SEN_SAA7111A:		rc = i2c_w(ov, 0x0d, (val + 32768) >> 8);		if (rc < 0)			goto out;		break;	default:		PDEBUG(3, "Unsupported with this sensor");		rc = -EPERM;		goto out;	}	rc = 0;		/* Success */	ov->hue = val;out:	if (ov51x_restart(ov) < 0)		return -EIO;	return rc;}/* Gets sensor's hue (red/blue balance) setting */static intsensor_get_hue(struct usb_ov511 *ov, unsigned short *val){	int rc;	switch (ov->sensor) {	case SEN_OV7610:	case SEN_OV6620:	case SEN_OV6630:		rc = i2c_r(ov, OV7610_REG_BLUE);		if (rc < 0)			return rc;		else			*val = rc << 8;		break;	case SEN_OV7620:		rc = i2c_r(ov, 0x7a);		if (rc < 0)			return rc;		else			*val = rc << 8;		break;	case SEN_SAA7111A:		*val = ov->hue;		break;	default:		PDEBUG(3, "Unsupported with this sensor");		return -EPERM;	}	PDEBUG(3, "%d", *val);	ov->hue = *val;	return 0;}/* -------------------------------------------------------------------------- */static inline intsensor_set_picture(struct usb_ov511 *ov, struct video_picture *p){	int rc;	PDEBUG(4, "sensor_set_picture");	ov->whiteness = p->whiteness;	/* Don't return error if a setting is unsupported, or rest of settings         * will not be performed */	rc = sensor_set_contrast(ov, p->contrast);	if (FATAL_ERROR(rc))		return rc;	rc = sensor_set_brightness(ov, p->brightness);	if (FATAL_ERROR(rc))		return rc;	rc = sensor_set_saturation(ov, p->colour);	if (FATAL_ERROR(rc))		return rc;	rc = sensor_set_hue(ov, p->hue);	if (FATAL_ERROR(rc))		return rc;	return 0;}static inline intsensor_get_picture(struct usb_ov511 *ov, struct video_picture *p){	int rc;	PDEBUG(4, "sensor_get_picture");	/* Don't return error if a setting is unsupported, or rest of settings         * will not be performed */	rc = sensor_get_contrast(ov, &(p->contrast));	if (FATAL_ERROR(rc))		return rc;	rc = sensor_get_brightness(ov, &(p->brightness));	if (FATAL_ERROR(rc))		return rc;	rc = sensor_get_saturation(ov, &(p->colour));	if (FATAL_ERROR(rc))		return rc;	rc = sensor_get_hue(ov, &(p->hue));	if (FATAL_ERROR(rc))		return rc;	p->whiteness = 105 << 8;	return 0;}#if defined(CONFIG_PROC_FS) && defined(CONFIG_VIDEO_PROC_FS)// FIXME: Exposure range is only 0x00-0x7f in interlace mode/* Sets current exposure for sensor. This only has an effect if auto-exposure * is off */static inline intsensor_set_exposure(struct usb_ov511 *ov, unsigned char val){	int rc;	PDEBUG(3, "%d", val);	if (ov->stop_during_set)		if (ov51x_stop(ov) < 0)			return -EIO;	switch (ov->sensor) {	case SEN_OV6620:	case SEN_OV6630:	case SEN_OV7610:	case SEN_OV7620:	case SEN_OV76BE:	case SEN_OV8600:		rc = i2c_w(ov, 0x10, val);		if (rc < 0)			goto out;		break;	case SEN_KS0127:	case SEN_KS0127B:	case SEN_SAA7111A:		PDEBUG(3, "Unsupported with this sensor");		return -EPERM;	default:		err("Sensor not supported for set_exposure");		return -EINVAL;	}	rc = 0;		/* Success */	ov->exposure = val;out:	if (ov51x_restart(ov) < 0)		return -EIO;	return rc;}/* Gets current exposure level from sensor, regardless of whether it is under * manual control. */static intsensor_get_exposure(struct usb_ov511 *ov, unsigned char *val){	int rc;	switch (ov->sensor) {	case SEN_OV7610:	case SEN_OV6620:	case SEN_OV6630:	case SEN_OV7620:	case SEN_OV76BE:	case SEN_OV8600:		rc = i2c_r(ov, 0x10);		if (rc < 0)			return rc;		else			*val = rc;		break;	case SEN_KS0127:	case SEN_KS0127B:	case SEN_SAA7111A:		val = 0;		PDEBUG(3, "Unsupported with this sensor");		return -EPERM;	default:		err("Sensor not supported for get_exposure");		return -EINVAL;	}	PDEBUG(3, "%d", *val);	ov->exposure = *val;	return 0;}#endif /* CONFIG_PROC_FS && CONFIG_VIDEO_PROC_FS *//* Turns on or off the LED. Only has an effect with OV511+/OV518(+) */static inline voidov51x_led_control(struct usb_ov511 *ov, int enable){	PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");	if (ov->bridge == BRG_OV511PLUS)		reg_w(ov, R511_SYS_LED_CTL, enable ? 1 : 0);	else if (ov->bclass == BCL_OV518)		reg_w_mask(ov, R518_GPIO_OUT, enable ? 0x02 : 0x00, 0x02);	return;}

⌨️ 快捷键说明

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