📄 zc3xx.h
字号:
#ifndef ZC3XXUSB_H#define ZC3XXUSB_H/****************************************************************************# Z-star zc301 zc302 P library ## Copyright (C) 2004 Michel Xhaard mxhaard@magic.fr ## ## 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## #****************************************************************************/#include "tas5130c.h"#include "icm105a.h"#include "hdcs2020.h"#include "hv7131b.h"#include "pb0330.h"#include "hv7131c.h"#include "cs2102.h"#include "pas106b.h"/******************* Camera Interface ***********************/static __u16 zc3xx_getbrightness(struct usb_spca50x *spca50x);static __u16 zc3xx_getcontrast(struct usb_spca50x *spca50x);static void zc3xx_setbrightness(struct usb_spca50x *spca50x);static void zc3xx_setcontrast(struct usb_spca50x *spca50x);static int zc3xx_init(struct usb_spca50x *spca50x );static void zc3xx_start(struct usb_spca50x *spca50x );static void zc3xx_stop(struct usb_spca50x *spca50x );static int zc3xx_config(struct usb_spca50x *spca50x );static void zc3xx_shutdown(struct usb_spca50x *spca50x );static void zc3xx_setAutobright (struct usb_spca50x *spca50x);static void zc3xx_setquality(struct usb_spca50x *spca50x );/******************* Camera Private ***********************/enum {SensorId = 0,reg8d,val8d,SensorReg1,valSreg1L,valSreg1H,SensorReg2,valSreg2L,valSreg2H,totval,};#define VGATOT 8static __u8 zcxxi2cSensor [VGATOT][totval]= {{ 0x00, 0xff, 0xff, 0x01, 0xaa, 0x00, 0xff, 0xff, 0xff}, // HV7131B{ 0x04, 0xff, 0xff, 0x01, 0xaa, 0x00, 0xff, 0xff, 0xff}, // CS2102{ 0x06, 0x8d, 0x08, 0x11, 0xaa, 0x00, 0xff, 0xff, 0xff},{ 0x08, 0xff, 0xff, 0x1c, 0x00, 0x00, 0x15, 0xaa, 0x00}, // HDCS2020 ?{ 0x0a, 0xff, 0xff, 0x07, 0xaa, 0xaa, 0xff, 0xff, 0xff}, // MI330 PB330{ 0x0c, 0xff, 0xff, 0x01, 0xaa, 0x00, 0xff, 0xff, 0xff}, // ICM105{ 0x0e, 0x8d, 0x08, 0x03, 0xaa, 0x00, 0xff, 0xff, 0xff}, // pas102{ 0x02, 0xff, 0xff, 0x01, 0xaa, 0x00, 0xff, 0xff, 0xff},};#define SIFTOT 1static __u8 zcxxi2cSensorSIF [SIFTOT][totval]= {#if 0{ 0x01, 0xff, 0xff, 0x01, 0xaa, 0x00, 0xff, 0xff, 0xff}, // corrupt with 0x00 hv7131b reg 0 return 0x01 readonly{ 0x05, 0xff, 0xff, 0x01, 0xaa, 0x00, 0xff, 0xff, 0xff},{ 0x07, 0x8d, 0x08, 0x11, 0xaa, 0x00, 0xff, 0xff, 0xff},{ 0x09, 0xff, 0xff, 0x1c, 0x00, 0x00, 0x15, 0xaa, 0x00}, // corrupt with 0x08 hdcs2020 reg 0 return 0x18 readonly{ 0x0b, 0xff, 0xff, 0x07, 0xaa, 0xaa, 0xff, 0xff, 0xff},{ 0x0d, 0xff, 0xff, 0x01, 0x11, 0x00, 0xff, 0xff, 0xff}, // corrupt with 0x0c ICM105 reg 0 is writable#endif{ 0x0f, 0x8d, 0x08, 0x03, 0xaa, 0x00, 0xff, 0xff, 0xff}, // PAS106 reg3 did not write with 0x0e !conflict PAS102 };static __u8 zcxx3wrSensor [][5]= {{ 0x8b, 0xb3, 0x11, 0x12, 0xff}, // HV7131R{ 0x8b, 0x91, 0x14, 0x15, 0x16},{ 0x8b, 0xe0, 0x14, 0x15, 0x16},{0,0,0,0,0}};static __u16 zcxx_i2cRead(struct usb_device *dev,__u8 reg ){__u8 retbyte = 0;__u8 retval[] = {0,0}; spca5xxRegWrite(dev,0xa0,reg,0x92,NULL,0); spca5xxRegWrite(dev,0xa0,0x02,0x90,NULL,0); // <-read command spca5xxRegRead(dev,0xa1,0x01,0x0091,&retbyte,1); // read status spca5xxRegRead(dev,0xa1,0x01,0x0095,&retval[0],1); // read Lowbyte spca5xxRegRead(dev,0xa1,0x01,0x0096,&retval[1],1); // read Hightbyte return ( (retval[1] << 8) | retval[0]);}static __u8 zcxx_i2cWrite(struct usb_device *dev,__u8 reg ,__u8 valL,__u8 valH){__u8 retbyte = 0; spca5xxRegWrite(dev,0xa0,reg,0x92,NULL,0); spca5xxRegWrite(dev,0xa0,valL,0x93,NULL,0); spca5xxRegWrite(dev,0xa0,valH,0x94,NULL,0); spca5xxRegWrite(dev,0xa0,0x01,0x90,NULL,0); // <-write command spca5xxRegRead(dev,0xa1,0x01,0x0091,&retbyte,1); // read status return (retbyte);}static int zcxx_probeSensor( struct usb_spca50x *spca50x){ __u8 retbyte = 0;int i,j;/* check i2c *//* check SIF */ for (i= 0; i< SIFTOT; i++) { spca5xxRegWrite(spca50x->dev,0xa0,0x01,0x0000,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,zcxxi2cSensorSIF[i][SensorId],0x0010,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,0x01,0x0001,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,0x03,0x0012,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,0x01,0x0012,NULL,0); wait_ms(2); if (zcxxi2cSensorSIF[i][reg8d] == 0x8d) spca5xxRegWrite(spca50x->dev,0xa0,zcxxi2cSensorSIF[i][val8d],0x008d,NULL,0); retbyte = zcxx_i2cWrite(spca50x->dev,zcxxi2cSensorSIF[i][SensorReg1], zcxxi2cSensorSIF[i][valSreg1L],zcxxi2cSensorSIF[i][valSreg1H]); wait_ms(2); retbyte = ( zcxx_i2cRead (spca50x->dev,zcxxi2cSensorSIF[i][SensorReg1])) & 0xff; wait_ms(2); PDEBUG(1,"sensor answer1 %d ",retbyte ); if (retbyte != zcxxi2cSensorSIF[i][valSreg1L]) continue; if (retbyte == zcxxi2cSensorSIF[i][valSreg1L] && zcxxi2cSensorSIF[i][SensorReg2] == 0xff) return zcxxi2cSensorSIF[i][SensorId]; if(zcxxi2cSensorSIF[i][SensorReg2] != 0xff){ retbyte = zcxx_i2cWrite(spca50x->dev,zcxxi2cSensorSIF[i][SensorReg2], zcxxi2cSensorSIF[i][valSreg2L],zcxxi2cSensorSIF[i][valSreg2H]); retbyte = ( zcxx_i2cRead (spca50x->dev,zcxxi2cSensorSIF[i][SensorReg2])) & 0xff; PDEBUG(1,"sensor answer2 %d ",retbyte ); if (retbyte == zcxxi2cSensorSIF[i][valSreg2L]) return zcxxi2cSensorSIF[i][SensorId]; } }/* check VGA */ for (i= 0; i< VGATOT; i++) { spca5xxRegWrite(spca50x->dev,0xa0,0x01,0x0000,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,zcxxi2cSensor[i][SensorId],0x0010,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,0x01,0x0001,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,0x03,0x0012,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,0x01,0x0012,NULL,0); wait_ms(2); if (zcxxi2cSensor[i][reg8d] == 0x8d) spca5xxRegWrite(spca50x->dev,0xa0,zcxxi2cSensor[i][val8d],0x008d,NULL,0); retbyte = zcxx_i2cWrite(spca50x->dev,zcxxi2cSensor[i][SensorReg1], zcxxi2cSensor[i][valSreg1L],zcxxi2cSensor[i][valSreg1H]); if(zcxxi2cSensor[i][SensorReg2] != 0xff){ retbyte = zcxx_i2cWrite(spca50x->dev,zcxxi2cSensor[i][SensorReg2], zcxxi2cSensor[i][valSreg2L],zcxxi2cSensor[i][valSreg2H]); retbyte = ( zcxx_i2cRead (spca50x->dev,zcxxi2cSensor[i][SensorReg2])) & 0xff; } else { retbyte = ( zcxx_i2cRead (spca50x->dev,zcxxi2cSensor[i][SensorReg1])) & 0xff; } PDEBUG(1,"sensor answervga %d ",retbyte ); if (retbyte != 0) return zcxxi2cSensor[i][SensorId]; }/* check 3 wires bus */ i = 0; while (zcxx3wrSensor [i][0]) { spca5xxRegWrite(spca50x->dev,0xa0,0x02,0x0010,NULL,0); spca5xxRegRead(spca50x->dev,0xa1,0x01,0x0010,&retbyte,1); spca5xxRegWrite(spca50x->dev,0xa0,0x01,0x0000,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,0x00,0x0010,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,0x01,0x0001,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,zcxx3wrSensor[i][1],zcxx3wrSensor[i][0],NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,0x03,0x0012,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,0x01,0x0012,NULL,0); spca5xxRegWrite(spca50x->dev,0xa0,0x05,0x0012,NULL,0); for (j =2 ; j < 5; j++){ if( zcxx3wrSensor[i][j] != 0xff){ retbyte = ( zcxx_i2cRead (spca50x->dev,zcxx3wrSensor[i][j])) & 0xff; if (retbyte != 0) return (i | 0x10); } } i++; } return (-1);}static __u16 zc3xxWriteVector(struct usb_spca50x *spca50x,__u16 data[][3]){ struct usb_device *dev=spca50x->dev; int err = 0; int i = 0; __u8 buffread; while (data[i][0]){ if (data[i][0] == 0xa0){ /* write registers */ spca5xxRegWrite(dev,data[i][0],data[i][1],data[i][2],NULL,0); } else { /* read status */ spca5xxRegRead(dev,data[i][0],data[i][1],data[i][2],&buffread,1); } i++; udelay(1000); }return err;}#define CLAMP(x) (unsigned char)(((x)>0xFF)?0xff:(((x)<1)?1:(x)))static __u8 Tgamma[16]={0x13,0x38,0x59,0x79,0x92,0xa7,0xb9,0xc8,0xd4,0xdf,0xe7,0xee,0xf4,0xf9,0xfc,0xff};static __u8 Tgradient[16]={0x26,0x22,0x20,0x1c,0x16,0x13,0x10,0x0d,0x0b,0x09,0x07,0x06,0x05,0x04,0x03,0x02};//static __u8 Tgamma[16]={0x24,0x44,0x64,0x84,0x9d,0xb2,0xc4,0xd3,0xe0,0xeb,0xf4,0xff,0xff,0xff,0xff,0xff}; //CS2102//static __u8 Tgradient[16]={0x18,0x20,0x20,0x1c,0x16,0x13,0x10,0x0e,0x0b,0x09,0x07,0x00,0x00,0x00,0x00,0x01};static __u16 zc3xx_getbrightness(struct usb_spca50x *spca50x){ spca50x->brightness = 0x80 << 8; spca50x->contrast = 0x80 << 8; return spca50x->brightness;}static __u16 zc3xx_getcontrast(struct usb_spca50x *spca50x){ return spca50x->contrast;}static void zc3xx_setbrightness(struct usb_spca50x *spca50x){ __u8 brightness; brightness = spca50x->brightness >> 8; spca5xxRegWrite(spca50x->dev,0xa0,brightness,0x011d,NULL,0); if(brightness < 0x70){ spca5xxRegWrite(spca50x->dev,0xa0,brightness+0x10,0x018d,NULL,0); } else { spca5xxRegWrite(spca50x->dev,0xa0,0x80,0x018d,NULL,0); } }static void zc3xx_setcontrast(struct usb_spca50x *spca50x){ __u16 contrast; int gm0 =0; int gr0 = 0; int index =0; int i; /* now get the index of gamma table */ contrast=zc3xx_getcontrast(spca50x) ; if((index = contrast >> 13) > 6) index = 6; PDEBUG(2,"starting new table index %d ",index ); for(i=0;i < 16; i++){ gm0= Tgamma[i]*index >> 2; gr0 = Tgradient[i]*index >> 2; spca5xxRegWrite(spca50x->dev,0xa0,CLAMP(gm0),0x0120+i,NULL,0); //brightness spca5xxRegWrite(spca50x->dev,0xa0,CLAMP(gr0),0x0130+i,NULL,0); // contrast //PDEBUG(0,"i %d gamma %d gradient %d",i ,Tgamma[i],Tgradient[i]); }}static int zc3xx_init( struct usb_spca50x *spca50x ){ spca5xxRegWrite(spca50x->dev,0xa0,0x01,0x0000,NULL,0); return 0;}static void set_zc3xxVGA(struct usb_spca50x *spca50x ){ memset (spca50x->mode_cam, 0x00, TOTMODE * sizeof(struct mwebcam)); spca50x->mode_cam[VGA].width = 640; spca50x->mode_cam[VGA].height = 480; spca50x->mode_cam[VGA].t_palette = P_JPEG | P_RAW | P_YUV420 | P_RGB32 | P_RGB24 | P_RGB16; spca50x->mode_cam[VGA].pipe = 1023; spca50x->mode_cam[VGA].method = 0; spca50x->mode_cam[VGA].mode = 0; spca50x->mode_cam[PAL].width = 384; spca50x->mode_cam[PAL].height = 288; spca50x->mode_cam[PAL].t_palette = P_YUV420 | P_RGB32 | P_RGB24 | P_RGB16; spca50x->mode_cam[PAL].pipe = 1023; spca50x->mode_cam[PAL].method = 1; spca50x->mode_cam[PAL].mode = 0; spca50x->mode_cam[SIF].width = 352;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -