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

📄 sonix.h

📁 ARM8008光盘linux-kernel
💻 H
字号:
 #ifndef SONIXUSB_H#define SONIXUSB_H/****************************************************************************#	 	sonix sn9c102 library                                       ## 		Copyright (C) 2003 2004 Michel Xhaard   mxhaard@magic.fr    ## Add Pas106 Stefano Mozzi (C) 2004 	 				    ##                                                                           ## 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 ##                                                                           #****************************************************************************/#define COMP 0xC7 //0x87 //0x07#define COMP1 0xC9 //0x89 //0x09#define MCK_INIT 0x63#define MCK_INIT1 0x20#define SYS_CLK 0x04static __u8initTas5130[]={   SYS_CLK,0x03,0x00,0x00,0x00,0x00,0x00,0x20,0x11,0x00,0x00,0x00,0x00,0x00,  // 0x00,0x01,0x00,0x68,0x0c,0x0a,  //0x00,0x01,0x00,0x67,0x0c,0x0a,  0x00,0x01,0x00,0x69,0x0c,0x0a,   0x28,0x1e,0x60,COMP,MCK_INIT,   0x18,0x10,0x04,0x03,0x11,0x0c };   static __u8initPas106[]={   SYS_CLK,0x03,0x00,0x00,0x00,0x00,0x00,0x81,0x40,0x00,0x00,0x00,0x00,0x00,  // 0x00,0x00,0x00,0x04,0x01,0x00,  //0x00,0x00,0x00,0x03,0x01,0x00,  0x00,0x00,0x00,0x05,0x01,0x00,   0x16,0x12,0x28,COMP1,MCK_INIT1,   0x18,0x10,0x04,0x03,0x11,0x0c };      static int sonix_i2cwrite (struct usb_device *dev,__u8 *buffer,__u16 length){	int retry = 60;	__u8 ByteReceive=0x00;	/* is i2c ready */	if (length > 8 || !buffer) return -1;	sonixRegWrite(dev,0x08,0x08,0x0000,buffer,length);	while (retry--) {	wait_ms (10);	sonixRegRead(dev,0x00,0x08,0x0000,&ByteReceive,1);	if(ByteReceive == 4) return 0;	}	return -1;}static __u16 sonix_getbrightness(struct usb_spca50x *spca50x){	/*FIXME hardcoded as we need to read register of the tasc */	spca50x->brightness = 0x80 << 8;	spca50x->contrast =0x80 << 8 ;	return (0x80 << 8);}static __u16 sonix_setbrightness(struct usb_spca50x *spca50x){	__u8 value;	__u8 i2c[]= { 0x30,0x11,0x02,0x20,0x70,0x00,0x00,0x10 };	__u8 i2c1[]=  { 0xA1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14 };	if (spca50x->sensor == SENSOR_TAS5130C) {		value = (0xFF - (spca50x->brightness >> 8));		i2c[4] = value & 0xFF;		PDEBUG(0,"brightness %d :%d ",value,i2c[4]);		if(sonix_i2cwrite(spca50x->dev,i2c,8) < 0) PDEBUG(0,"i2c error brightness");	} else if (spca50x->sensor == SENSOR_PAS106) {		i2c1[3] = spca50x->brightness >> 11;		i2c1[2] = 0x0e;;		if(sonix_i2cwrite(spca50x->dev,i2c1,8) < 0) PDEBUG(0,"i2c error brightness");		i2c1[3] = 0x01;		i2c1[2] = 0x13;;		if(sonix_i2cwrite(spca50x->dev,i2c1,8) < 0) PDEBUG(0,"i2c error brightness");	}	return 0;}static __u16 sonix_setcontrast(struct usb_spca50x *spca50x){	__u8 gain = 0;	__u8 rgb_value = 0;	gain = (spca50x->contrast >> 13) & 0x0F;	/* red and blue gain */	rgb_value = gain << 4 | gain;	sonixRegWrite(spca50x->dev,0x08,0x10,0x0000,&rgb_value,1);	/* green gain*/	rgb_value = gain;	sonixRegWrite(spca50x->dev,0x08,0x11,0x0000,&rgb_value,1);	return 0;}static int sonix_init(	struct usb_spca50x *spca50x ){	__u8 ByteReceive=0x00;	sonixRegRead(spca50x->dev,0x00,0x00,0x0000,&ByteReceive,1);	if(ByteReceive != 0x10) return -ENODEV;	return 0;}static int tas5130_I2cinit(struct usb_spca50x *spca50x ){		//__u8 i2c10[]= { 0x30,0x11,0x00,0x40,0x47,0x00,0x00,0x10 }; // shutter value?	__u8 i2c10[]= { 0x30,0x11,0x00,0x40,0x07,0x00,0x00,0x10 };	__u8 i2c2[]=  { 0x30,0x11,0x02,0x20,0x70,0x00,0x00,0x10 };		if(sonix_i2cwrite(spca50x->dev,i2c10,8) < 0) PDEBUG(0,"i2c error i2c10");		if(sonix_i2cwrite(spca50x->dev,i2c2,8) < 0) PDEBUG(0,"i2c error i2c2");		return 0;}static __u8 pas106_data[][2]={	{ 0x02, 0x06}, /* Pixel Clock Divider */	{ 0x03, 0x13}, /* Frame Time MSB */		{ 0x04, 0x06}, /* Frame Time LSB */		{ 0x05, 0x65}, /* Shutter Time Line Offset */		{ 0x06, 0xB1}, /* Shutter Time Pixel Offset */			{ 0x07, 0xC1}, /* Black Level Subtract Sign */		{ 0x08, 0x06}, /* Black Level Subtract Level */		{ 0x09, 0x0a}, /* Color Gain B Pixel 5 */	{ 0x0A, 0x05}, /* Color Gain G1 Pixel 1 */	{ 0x0B, 0x05}, /* Color Gain G2 Pixel 1 0 */	{ 0x0C, 0x01}, /* Color Gain R Pixel 3 */	{ 0x0D, 0x00}, /* Color GainH  Pixel */	{ 0x0E, 0x0E}, /* Global Gain */	{ 0x0F, 0x00}, /* Contrast */	{ 0x10, 0x06}, /* H&V synchro polarity */	{ 0x11, 0x06}, /* ?default */	{ 0x12, 0x06}, /* DAC scale */	{ 0x14, 0x02}, /* ?default */	{ 0x13, 0x01}, /* Validate Settings */	{ 0, 0 }	/* The end */};static int pas106_I2cinit(struct usb_spca50x *spca50x ){	__u8 i2c1[]=  { 0xA1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14 };	int i = 0;	while (pas106_data[i][0]){		memcpy(&i2c1[2],&pas106_data[i++][0],2); //copy 2 bytes from the template		if(sonix_i2cwrite(spca50x->dev,i2c1,8) < 0) PDEBUG(0,"i2c error pas106");	}	return 0;}static void sonix_start(struct usb_spca50x *spca50x ){		__u8 compress = 0;	__u8 MCK_SIZE = 0x33;	__u8 frmult = 0x28;	__u8 *sn9c10x = NULL;	 __u8 CompressCtrl[]= { 0,0};	 int err =0;	switch (spca50x->sensor){ 	 case SENSOR_TAS5130C:		sn9c10x = initTas5130 ; 		compress = spca50x->mode << 4 | COMP;		CompressCtrl[0] = compress;		frmult = 0x60;		switch (spca50x->mode){		case 0: /* 640x480 3fp/s */			CompressCtrl[1] = 0x43;//0xA3 3fp/s ;// 0xF3;			MCK_SIZE = 0x43; // 0xA3;//0xF3;			break;		case 1: /* 320x240 0x33 10fp/s */			CompressCtrl[1] = 0x23;			MCK_SIZE = 0x23;			break;		case 2: /* 160x120 15fp/s */			CompressCtrl[1] = 0x23;			MCK_SIZE = 0x23;			break;		default:		break;		}		break;	 case SENSOR_PAS106:		sn9c10x = initPas106; ; 		compress = spca50x->mode << 4 | COMP1;		CompressCtrl[0] = compress;		frmult = 0x28;		switch (spca50x->mode){		case 0: /* 352x288 7fp/s */			CompressCtrl[1] = 0x20; //0xF3;			MCK_SIZE = 0x20; //0xF3;			frmult = 0x24; //12 Mhz 14 fp/s; 0x28 24 Mhz ; 0x20 Fsys/Mck 7 fp/s Fsys = 12 Mz			break;		case 1: /* 176x144 30fp/s */			CompressCtrl[1] = 0x20;			MCK_SIZE = 0x20;			break;		case 2: /* 88x72 30fp/s */			CompressCtrl[1] = 0x20;			MCK_SIZE = 0x20;			break;		default:		break;		}		break;	}	/* reg 0x01 bit 2 video transfert on */		sonixRegWrite(spca50x->dev,0x08,0x01,0x0000,&sn9c10x[0],1);	/* reg 0x17 SensorClk enable inv Clk 0x60 */		sonixRegWrite(spca50x->dev,0x08,0x17,0x0000,&sn9c10x[0x17 -1],1);	/* Set the whole registers from the template */		sonixRegWrite(spca50x->dev,0x08,0x01,0x0000,sn9c10x,0x1f);	if(spca50x->sensor == SENSOR_TAS5130C){		err = tas5130_I2cinit(spca50x );	} else {		err = pas106_I2cinit( spca50x);	}	/* H_size V_size  0x28,0x1e maybe 640x480 */		sonixRegWrite(spca50x->dev,0x08,0x15,0x0000,&sn9c10x[0x15 -1],0x02);		/* compression register */		sonixRegWrite(spca50x->dev,0x08,0x18,0x0000,&compress,1);	// H_start		sonixRegWrite(spca50x->dev,0x08,0x12,0x0000,&sn9c10x[0x12 -1],1);	// V_START		sonixRegWrite(spca50x->dev,0x08,0x13,0x0000,&sn9c10x[0x13 -1],1);	/* re set 0x17 SensorClk enable inv Clk 0x60 */		sonixRegWrite(spca50x->dev,0x08,0x17,0x0000,&frmult,1);	/*MCKSIZE ->3*/		sonixRegWrite(spca50x->dev,0x08,0x19,0x0000,&MCK_SIZE,1);	/* AE_STRX AE_STRY AE_ENDX AE_ENDY */	sonixRegWrite(spca50x->dev,0x08,0x1c,0x0000,&sn9c10x[0x1c -1],4);	/* Enable video transfert */		sonixRegWrite(spca50x->dev,0x08,0x01,0x0000,&sn9c10x[0],1);	/* Compression */	sonixRegWrite(spca50x->dev,0x08,0x18,0x0000,CompressCtrl,2);		sonix_setcontrast(spca50x);	sonix_setbrightness(spca50x);}static void sonix_stop(struct usb_spca50x *spca50x ){  	__u8 ByteSend =0;		ByteSend=0x00;	sonixRegWrite(spca50x->dev,0x08,0x01,0x0000,&ByteSend,1);}#endif /* SONIXUSB_H */

⌨️ 快捷键说明

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