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

📄 cpia.c

📁 cpia usb摄像头的驱动程序源码。需要video4linux和i2c-core支持
💻 C
📖 第 1 页 / 共 5 页
字号:
			command_flags |= COMMAND_SETCOMPRESSIONTARGET;		} else if (MATCH("y_threshold")) {			if (!retval)				val = VALUE;			if (!retval) {				if (val < 32)					new_params.yuvThreshold.yThreshold = val;				else					retval = -EINVAL;			}			command_flags |= COMMAND_SETYUVTHRESH;		} else if (MATCH("uv_threshold")) {			if (!retval)				val = VALUE;			if (!retval) {				if (val < 32)					new_params.yuvThreshold.uvThreshold = val;				else					retval = -EINVAL;			}			command_flags |= COMMAND_SETYUVTHRESH;		} else if (MATCH("hysteresis")) {			if (!retval)				val = VALUE;			if (!retval) {				if (val <= 0xff)					new_params.compressionParams.hysteresis = val;				else					retval = -EINVAL;			}			command_flags |= COMMAND_SETCOMPRESSIONPARAMS;		} else if (MATCH("threshold_max")) {			if (!retval)				val = VALUE;			if (!retval) {				if (val <= 0xff)					new_params.compressionParams.threshMax = val;				else					retval = -EINVAL;			}			command_flags |= COMMAND_SETCOMPRESSIONPARAMS;		} else if (MATCH("small_step")) {			if (!retval)				val = VALUE;			if (!retval) {				if (val <= 0xff)					new_params.compressionParams.smallStep = val;				else					retval = -EINVAL;			}			command_flags |= COMMAND_SETCOMPRESSIONPARAMS;		} else if (MATCH("large_step")) {			if (!retval)				val = VALUE;			if (!retval) {				if (val <= 0xff)					new_params.compressionParams.largeStep = val;				else					retval = -EINVAL;			}			command_flags |= COMMAND_SETCOMPRESSIONPARAMS;		} else if (MATCH("decimation_hysteresis")) {			if (!retval)				val = VALUE;			if (!retval) {				if (val <= 0xff)					new_params.compressionParams.decimationHysteresis = val;				else					retval = -EINVAL;			}			command_flags |= COMMAND_SETCOMPRESSIONPARAMS;		} else if (MATCH("fr_diff_step_thresh")) {			if (!retval)				val = VALUE;			if (!retval) {				if (val <= 0xff)					new_params.compressionParams.frDiffStepThresh = val;				else					retval = -EINVAL;			}			command_flags |= COMMAND_SETCOMPRESSIONPARAMS;		} else if (MATCH("q_diff_step_thresh")) {			if (!retval)				val = VALUE;			if (!retval) {				if (val <= 0xff)					new_params.compressionParams.qDiffStepThresh = val;				else					retval = -EINVAL;			}			command_flags |= COMMAND_SETCOMPRESSIONPARAMS;		} else if (MATCH("decimation_thresh_mod")) {			if (!retval)				val = VALUE;			if (!retval) {				if (val <= 0xff)					new_params.compressionParams.decimationThreshMod = val;				else					retval = -EINVAL;			}			command_flags |= COMMAND_SETCOMPRESSIONPARAMS;		} else if (MATCH("toplight")) {		        if (!retval && MATCH("on"))				new_params.qx3.toplight = 1;			else if (!retval && MATCH("off"))				new_params.qx3.toplight = 0;			else 				retval = -EINVAL;			command_flags |= COMMAND_SETLIGHTS;		} else if (MATCH("bottomlight")) {		        if (!retval && MATCH("on"))				new_params.qx3.bottomlight = 1;			else if (!retval && MATCH("off"))  				new_params.qx3.bottomlight = 0;			else 				retval = -EINVAL;			command_flags |= COMMAND_SETLIGHTS;		} else {			DBG("No match found\n");			retval = -EINVAL;		}		if (!retval) {			while (count && isspace(*buffer) && *buffer != '\n') {				--count;				++buffer;			}			if (count) {				if (*buffer == '\0' && count != 1)					retval = -EINVAL;				else if (*buffer != '\n' && *buffer != ';' &&					 *buffer != '\0')					retval = -EINVAL;				else {					--count;					++buffer;				}			}		}	}#undef MATCH	#undef VALUE#undef FIRMWARE_VERSION	if (!retval) {		if (command_flags & COMMAND_SETCOLOURPARAMS) {			/* Adjust cam->vp to reflect these changes */			cam->vp.brightness =				new_params.colourParams.brightness*65535/100;			cam->vp.contrast =				new_params.colourParams.contrast*65535/100;			cam->vp.colour =				new_params.colourParams.saturation*65535/100;		}		if((command_flags & COMMAND_SETEXPOSURE) &&		   new_params.exposure.expMode == 2)			cam->exposure_status = EXPOSURE_NORMAL;		memcpy(&cam->params, &new_params, sizeof(struct cam_params));		cam->mainsFreq = new_mains;		cam->cmd_queue |= command_flags;		retval = size;	} else		DBG("error: %d\n", retval);		up(&cam->param_lock);	out:	free_page((unsigned long)page);	return retval;}static void create_proc_cpia_cam(struct cam_data *cam){	char name[7];	struct proc_dir_entry *ent;		if (!cpia_proc_root || !cam)		return;	sprintf(name, "video%d", cam->vdev.minor);		ent = create_proc_entry(name, S_IFREG|S_IRUGO|S_IWUSR, cpia_proc_root);	if (!ent)		return;	ent->data = cam;	ent->read_proc = cpia_read_proc;	ent->write_proc = cpia_write_proc;	/* 	   size of the proc entry is 3736 bytes for the standard webcam; 	   the extra features of the QX3 microscope add 189 bytes.	   (we have not yet probed the camera to see which type it is).	*/	ent->size = 3736 + 189;	cam->proc_entry = ent;}static void destroy_proc_cpia_cam(struct cam_data *cam){	char name[7];		if (!cam || !cam->proc_entry)		return;		sprintf(name, "video%d", cam->vdev.minor);	remove_proc_entry(name, cpia_proc_root);	cam->proc_entry = NULL;}static void proc_cpia_create(void){	cpia_proc_root = create_proc_entry("cpia", S_IFDIR, 0);	if (cpia_proc_root)		cpia_proc_root->owner = THIS_MODULE;	else		LOG("Unable to initialise /proc/cpia\n");}#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,70))static void proc_cpia_destroy(void)#elsestatic void __exit proc_cpia_destroy(void)#endif{	remove_proc_entry("cpia", 0);}#endif /* CONFIG_PROC_FS *//* ----------------------- debug functions ---------------------- */#define printstatus(cam) \  DBG("%02x %02x %02x %02x %02x %02x %02x %02x\n",\	cam->params.status.systemState, cam->params.status.grabState, \	cam->params.status.streamState, cam->params.status.fatalError, \	cam->params.status.cmdError, cam->params.status.debugFlags, \	cam->params.status.vpStatus, cam->params.status.errorCode);/* ----------------------- v4l helpers -------------------------- *//* supported frame palettes and depths */static inline int valid_mode(u16 palette, u16 depth){	return (palette == VIDEO_PALETTE_GREY && depth == 8) ||	       (palette == VIDEO_PALETTE_RGB555 && depth == 16) ||	       (palette == VIDEO_PALETTE_RGB565 && depth == 16) ||	       (palette == VIDEO_PALETTE_RGB24 && depth == 24) ||	       (palette == VIDEO_PALETTE_RGB32 && depth == 32) ||	       (palette == VIDEO_PALETTE_YUV422 && depth == 16) ||	       (palette == VIDEO_PALETTE_YUYV && depth == 16) ||	       (palette == VIDEO_PALETTE_UYVY && depth == 16);}static int match_videosize( int width, int height ){	/* return the best match, where 'best' is as always	 * the largest that is not bigger than what is requested. */	if (width>=352 && height>=288)		return VIDEOSIZE_352_288; /* CIF */	if (width>=320 && height>=240)		return VIDEOSIZE_320_240; /* SIF */	if (width>=288 && height>=216)		return VIDEOSIZE_288_216;	if (width>=256 && height>=192)		return VIDEOSIZE_256_192;	if (width>=224 && height>=168)		return VIDEOSIZE_224_168;	if (width>=192 && height>=144)		return VIDEOSIZE_192_144;	if (width>=176 && height>=144)		return VIDEOSIZE_176_144; /* QCIF */	if (width>=160 && height>=120)		return VIDEOSIZE_160_120; /* QSIF */	if (width>=128 && height>=96)		return VIDEOSIZE_128_96;	if (width>=88 && height>=72)		return VIDEOSIZE_88_72;	if (width>=64 && height>=48)		return VIDEOSIZE_64_48;	if (width>=48 && height>=48)		return VIDEOSIZE_48_48;	return -1;}/* these are the capture sizes we support */static void set_vw_size(struct cam_data *cam){	/* the col/row/start/end values are the result of simple math    */	/* study the SetROI-command in cpia developers guide p 2-22      */	/* streamStartLine is set to the recommended value in the cpia   */	/*  developers guide p 3-37                                      */	switch(cam->video_size) {	case VIDEOSIZE_CIF:		cam->vw.width = 352;		cam->vw.height = 288;		cam->params.format.videoSize=VIDEOSIZE_CIF;		cam->params.roi.colStart=0;		cam->params.roi.rowStart=0;		cam->params.streamStartLine = 120;		break;	case VIDEOSIZE_SIF:		cam->vw.width = 320;		cam->vw.height = 240;		cam->params.format.videoSize=VIDEOSIZE_CIF;		cam->params.roi.colStart=2;		cam->params.roi.rowStart=6;		cam->params.streamStartLine = 120;		break;	case VIDEOSIZE_288_216:		cam->vw.width = 288;		cam->vw.height = 216;		cam->params.format.videoSize=VIDEOSIZE_CIF;		cam->params.roi.colStart=4;		cam->params.roi.rowStart=9;		cam->params.streamStartLine = 120;		break;	case VIDEOSIZE_256_192:		cam->vw.width = 256;		cam->vw.height = 192;		cam->params.format.videoSize=VIDEOSIZE_CIF;		cam->params.roi.colStart=6;		cam->params.roi.rowStart=12;		cam->params.streamStartLine = 120;		break;	case VIDEOSIZE_224_168:		cam->vw.width = 224;		cam->vw.height = 168;		cam->params.format.videoSize=VIDEOSIZE_CIF;		cam->params.roi.colStart=8;		cam->params.roi.rowStart=15;		cam->params.streamStartLine = 120;		break;	case VIDEOSIZE_192_144:		cam->vw.width = 192;		cam->vw.height = 144;		cam->params.format.videoSize=VIDEOSIZE_CIF;		cam->params.roi.colStart=10;		cam->params.roi.rowStart=18;		cam->params.streamStartLine = 120;		break;	case VIDEOSIZE_QCIF:		cam->vw.width = 176;		cam->vw.height = 144;		cam->params.format.videoSize=VIDEOSIZE_QCIF;		cam->params.roi.colStart=0;		cam->params.roi.rowStart=0;		cam->params.streamStartLine = 60;		break;	case VIDEOSIZE_QSIF:		cam->vw.width = 160;		cam->vw.height = 120;		cam->params.format.videoSize=VIDEOSIZE_QCIF;		cam->params.roi.colStart=1;		cam->params.roi.rowStart=3;		cam->params.streamStartLine = 60;		break;	case VIDEOSIZE_128_96:		cam->vw.width = 128;		cam->vw.height = 96;		cam->params.format.videoSize=VIDEOSIZE_QCIF;		cam->params.roi.colStart=3;		cam->params.roi.rowStart=6;		cam->params.streamStartLine = 60;		break;	case VIDEOSIZE_88_72:		cam->vw.width = 88;		cam->vw.height = 72;		cam->params.format.videoSize=VIDEOSIZE_QCIF;		cam->params.roi.colStart=5;		cam->params.roi.rowStart=9;		cam->params.streamStartLine = 60;		break;	case VIDEOSIZE_64_48:		cam->vw.width = 64;		cam->vw.height = 48;		cam->params.format.videoSize=VIDEOSIZE_QCIF;		cam->params.roi.colStart=7;		cam->params.roi.rowStart=12;		cam->params.streamStartLine = 60;		break;	case VIDEOSIZE_48_48:		cam->vw.width = 48;		cam->vw.height = 48;		cam->params.format.videoSize=VIDEOSIZE_QCIF;		cam->params.roi.colStart=8;		cam->params.roi.rowStart=6;		cam->params.streamStartLine = 60;		break;	default:		LOG("bad videosize value: %d\n", cam->video_size);		return;	}	if(cam->vc.width == 0)		cam->vc.width = cam->vw.width;	if(cam->vc.height == 0)		cam->vc.height = cam->vw.height;		cam->params.roi.colStart += cam->vc.x >> 3;	cam->params.roi.colEnd = cam->params.roi.colStart +	                         (cam->vc.width >> 3);	cam->params.roi.rowStart += cam->vc.y >> 2;	cam->params.roi.rowEnd = cam->params.roi.rowStart +	                         (cam->vc.height >> 2);	return;}static int allocate_frame_buf(struct cam_data *cam){	int i;	cam->frame_buf = rvmalloc(FRAME_NUM * CPIA_MAX_FRAME_SIZE);	if (!cam->frame_buf)		return -ENOBUFS;	for (i = 0; i < FRAME_NUM; i++)		cam->frame[i].data = cam->frame_buf + i * CPIA_MAX_FRAME_SIZE;	return 0;}

⌨️ 快捷键说明

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