📄 qcamvc.h
字号:
/* * * Connectix USB QuickCam VC Video Camera driver * * (C) Copyright 2001 De Marchi Daniele * (C) Copyright 2004 Terry Mohan * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Jan 2001 This driver develop started on the linux * kernel 2.4.0. * *//*#ifdef MODVERSIONS#include <linux/modversions.h>#endif*/#include <linux/version.h>#include <linux/init.h>#include <linux/module.h>#include <linux/videodev.h>//#include <media/video-buf.h>#if LINUX_VERSION_CODE >= 0x020407#include <linux/slab.h>#else#include <linux/malloc.h>#endif#ifndef QCAMVCVERSION#define QCAMVCVERSION "1.0.generic"#endif#define QCAMVC_VERSION_CODE KERNEL_VERSION(0,1,0)#define BIGBUFFER_SIZE 0x20000#define MAX_CAMS 0x04#define CAM_DEBUG#undef V4L_DEBUG#undef USB_DEBUG#undef PP_DEBUG#define MAX_WIDTH 352#define MAX_HEIGHT 288#define MIN_WIDTH 80#define MIN_HEIGHT 60#define QCAMVC_NUMFRAMES 2#define MAX_FRAME_SIZE_UNALIGNED (MAX_WIDTH * MAX_HEIGHT * 4) /* CIF at RGB32 */#define MAX_FRAME_SIZE ((MAX_FRAME_SIZE_UNALIGNED + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) /* align to PAGE_SIZE */#define MAX_PACKET_LENGTH ((MAX_WIDTH * MAX_HEIGHT) + 64) /* Plus 2 header bytes, 62 padding bytes */#define MAX_RAW_IMAGE_SIZE (MAX_PACKET_LENGTH + 4) /* plus 4 for 6bit->8bit conversion */#define DEBUG/* Addresses */#define QCAM_VC_SET_LIGHTSENS_LO 0x02 /* Light Sensitivity decrease */#define QCAM_VC_SET_LIGHTSENS_HI 0x03 /* Light Sensitivity increase */#define QCAM_VC_SET_EXPOSURE 0x04#define QCAM_VC_SET_CCD_AREA 0x06#define QCAM_VC_SET_LEFT_COLUMN 0x06#define QCAM_VC_SET_RIGHT_COLUMN 0x07#define QCAM_VC_SET_TOP_ROW 0x08#define QCAM_VC_SET_BOTTOM_ROW 0x09#define QCAM_VC_SET_MISC 0x0a#define QCAM_VC_GET_FRAME 0x0d#define QCAM_VC_SET_BRIGHTNESS 0x0f/* QCAM_VC_SET_MISC Address... Bit 0 = Config Mode; Bit 1 = Image Mult. Factor; Bit 2 = compression?? Bit 3 = UNKNOWN Set to 0; Bit 4 = Enable Video Stream; Bit 5-6 UNKNOWN set to 0; Bit 7 = Frame Ready*/struct qcamvc_camera_ops { int (*qcamvc_open)(void *privdata); int (*qcamvc_close)(void *privdata); int (*qcamvc_write)(void *privdata, void *buffer, size_t len); size_t (*qcamvc_read)(void *privdata, void *buffer, size_t len); int (*qcamvc_set_reg)(void *privdata, unsigned char reg, void *buffer, size_t len); size_t (*qcamvc_get_reg)(void *privdata, unsigned char reg, void *buffer, size_t len); int (*qcamvc_stream_start)(void *privdata); int (*qcamvc_stream_stop)(void *privdata); size_t (*qcamvc_stream_read)(void *privdata, void *buffer, size_t len); /* * Used to maintain lowlevel module usage counts */ struct module *owner;};/* Frame buffering status */enum{ FRAME_READY, /* Ready to grab into */ FRAME_GRABBING, /* In the process of being grabbed into */ FRAME_DONE, /* Finished grabbing, but not sync'd yet */ FRAME_UNUSED, /* Unused (no MCAPTURE) */};/* an mmap frame */struct qcamvc_frame{ u8 *data; volatile int state;};/* CCD settings */struct qcamvc_ccd_area{ unsigned char first_col; unsigned char last_col; unsigned char first_row; unsigned char last_row; unsigned char multiplier; unsigned int width; unsigned int height;};/* 0x0A MISC address bit fields */struct qcamvc_misc{ unsigned char config : 1; /* config mode bit? */ unsigned char multiplier : 1; /* mult factor bit. 1 = 1x, 0 = 2x */ unsigned char compression : 1; /* ...looks like compression? (looks worse anyway) */ unsigned char bit4 : 1; unsigned char video_enable : 1; /* enable/disable video streaming */ unsigned char bit6 : 1; unsigned char bit7 : 1; unsigned char frame_ready : 1; /* set by camera when frame has been captured */};struct qcamvc_data{ /* locking */ struct list_head cam_data_list; struct semaphore busy_lock; /* guard against SMP multithreading */ /* QcamVC ops */ struct video_device *vdev; void *lowlevel_data; struct qcamvc_camera_ops *ops; struct proc_dir_entry *proc_entry; int open_count; int camera_init; int transfer_rate; /* transfer rate from camera in kB/s */ struct qcamvc_ccd_area ccd_area; /* the current CCD row/col values */ u8 *raw_frame; /* buffer for raw image data */ u8 *raw_frame_temp; /* buffer for 6bit conversion */ size_t packet_len; /* actual size of packet being received */ size_t packet_len_bpc8; /* 8bit size of the packet */ /* Video structure */ char camtypedesc[20]; __u32 pixelformat; int colordepth; int flip_bgr; /* mmap interface */ int curframe; /* the current frame to grab into */ u8 *frame_buf; struct qcamvc_frame frame[QCAMVC_NUMFRAMES]; unsigned char frame_count; /* 0x0D grab command, frame count */ unsigned char frame_waiting; /* frames waiting to send 0x0D command */ struct qcamvc_misc misc_reg; /* 0x0A misc address bit field */ /* General camera */ unsigned char camera_model; unsigned char camera_type; /* Video configuration */ int width; int height; int bpc; int compression; int light_sens; unsigned char brightness; unsigned char exposure; /* Codec */ int contrast; int hue; int saturation; unsigned char gamma_done; unsigned char gamma_table[256]; /* Table of gamma values */};/* some functions for our other modules to use */extern struct qcamvc_data *qcamvc_register_camera(struct qcamvc_camera_ops *ops, void *lowlevel, char *camtype);extern void qcamvc_unregister_camera(struct qcamvc_data *qcamvc);/*enum { R88x72, R160x120, R176x144, R320x240, R352x288 };#define FIRST_ROW unsigned char firstrow[5]= { 3, 13, 1, 14, 2 }#define LAST_ROW unsigned char lastrow[5]= { 75, 133, 145, 134, 146 }#define FIRST_COL unsigned char firstcol[5]= { 6, 14, 6, 14, 4 }#define LAST_COL unsigned char lastcol[5]= { 94, 174, 182, 174, 180 }#define MUL_FACTOR unsigned char mulfactor[5]= { 0, 0, 0, 1, 1 }*/#define DUMP_BUFFER(buffer) \ {\ unsigned long cnta,cntb;\ if (buffer!=NULL)\ { \ for (cnta=0,cntb=0; cnta<((sizeof(buffer)<0x60)?sizeof(buffer):0x60);cnta++,cntb++) \ {\ if(cntb == 0x10) {printk("\n"); cntb=0;}\ printk (" %02x ", *((unsigned char *)buffer + cnta ));\ }\ printk("\n");\ } \ } #define ADD_TO_LIST(l, drv) \ {\ lock_kernel();\ (drv)->next = l;\ (drv)->previous = &(l);\ (l) = drv;\ unlock_kernel();\ } while(0)#define REMOVE_FROM_LIST(drv) \ {\ if ((drv)->previous != NULL) {\ lock_kernel();\ if ((drv)->next != NULL)\ (drv)->next->previous = (drv)->previous;\ *((drv)->previous) = (drv)->next;\ (drv)->previous = NULL;\ (drv)->next = NULL;\ unlock_kernel();\ }\ } while (0)#define ALOG(fmt,args...) printk(fmt, ##args)#define LOG(fmt,args...) ALOG(KERN_INFO __FILE__ ":%s(%d):" fmt, __FUNCTION__ , __LINE__ , ##args)#ifdef CAM_DEBUG#define CAM__DBG(lineno,fmt,args...) printk(fmt, jiffies, lineno, ##args)#define CAM_DBG(fmt,args...) CAM__DBG((__LINE__),KERN_DEBUG __FILE__"(%ld):"__FUNCTION__"(%d):"fmt,##args)#else#define CAM_DBG(fmn,args...) do {} while(0)#endif#ifdef PP_DEBUG#define PP__DBG(lineno,fmt,args...) printk(fmt, jiffies, lineno, ##args)#define PP_DBG(fmt,args...) PP__DBG((__LINE__),KERN_DEBUG __FILE__"(%ld):"__FUNCTION__"(%d):"fmt,##args)#else#define PP_DBG(fmn,args...) do {} while(0)#endif#ifdef USB_DEBUG#define USB__DBG(lineno,fmt,args...) printk(fmt, jiffies, lineno, ##args)#define USB_DBG(fmt,args...) USB__DBG((__LINE__),KERN_DEBUG __FILE__"(%ld):"__FUNCTION__"(%d):"fmt,##args)#else#define USB_DBG(fmn,args...) do {} while(0)#endif#ifdef V4L_DEBUG#define V4L__DBG(lineno,fmt,args...) printk(fmt, jiffies, lineno, ##args)#define V4L_DBG(fmt,args...) V4L__DBG((__LINE__),KERN_DEBUG __FILE__"(%ld):"__FUNCTION__"(%d):"fmt,##args)#else#define V4L_DBG(fmn,args...) do {} while(0)#endif#ifdef _QCAMVC_DEBUG_#define ADBG(fmt,args...) printk(fmt, jiffies, ##args)#define DBG(fmt,args...) ADBG(KERN_DEBUG __FILE__" (%ld):%s(%d):" fmt, __FUNCTION__, __LINE__ , ##args)#else#define DBG(fmn,args...) do {} while(0)#endif#define DEB_BYTE(p)\ DBG("%1d %1d %1d %1d %1d %1d %1d %1d \n",\ (p)&0x80?1:0, (p)&0x40?1:0, (p)&0x20?1:0, (p)&0x10?1:0,\ (p)&0x08?1:0, (p)&0x04?1:0, (p)&0x02?1:0, (p)&0x01?1:0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -