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

📄 sn9c102p.h

📁 凌阳SPCA5XX解码芯片USB驱动源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
static int sn9c102p_probesensor(struct usb_spca50x *spca50x){       struct usb_device *dev = spca50x->dev;	int err = 0;	__u8 reg02 = 0x66;	/* reg val1 val2 val3 val4 */	__u8 datasend[] = {0,0,0,0,0};	__u8 datarecd[] = {0,0,0,0,0};	datasend[0] = 2; //sensor wakeup	err = sn9c102p_i2cwrite (dev, datasend ,2);	sonixRegWrite(dev,0x08,0x02,0x0000,&reg02,1); //Gpio on	err += sn9c102p_i2cread (dev,0, datarecd ,5); //read sensor id	if (err) goto errors;	if(datarecd[0] == 0x02 && datarecd[1] == 0x09 && datarecd[2] == 0x01 		&& datarecd[3] == 0x00 && datarecd[4] == 0x00){		PDEBUG(0,"Find Sensor sn9c102P HV7131R");		spca50x->sensor = SENSOR_HV7131R;		return SENSOR_HV7131R;		}	PDEBUG(0,"Sensor sn9c102P Not found Contact mxhaard@free.fr ");		return -ENODEV;	errors:	PDEBUG(0,"Sensor sn9c102P too many errors Contact mxhaard@free.fr ");return -ENODEV;	}static void hv7131R_InitSensor(struct usb_spca50x *spca50x){	int i = 0;	struct usb_device *dev = spca50x->dev;	while (hv7131r_sensor_init[i][0]){	sn9c102p_i2cwritebuf (dev,hv7131r_sensor_init[i]);	i++;	}	}static void hv7131R_ConfigSensor(struct usb_spca50x *spca50x){	int i = 0;	struct usb_device *dev = spca50x->dev;	while (hv7131r_sensor_config[i][0]){	sn9c102p_i2cwritebuf (dev,hv7131r_sensor_config[i]);	i++;	}	}static void hv7131R_StartSensor(struct usb_spca50x *spca50x){	int i = 0;	struct usb_device *dev = spca50x->dev;	__u8 CtrlA320[] = { 0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10 }; //Mclk	//__u8 CtrlA640[] = { 0xA1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 };//Mclk/2	__u8 CtrlA640[] = { 0xA1, 0x11, 0x01, 0x28, 0x00, 0x00, 0x00, 0x10 }; //Mckl/4	while (hv7131r_sensor_start[i][0]){	sn9c102p_i2cwritebuf (dev,hv7131r_sensor_start[i]);	i++;	}	if(spca50x->mode)	 sn9c102p_i2cwritebuf (dev,CtrlA320);	else	 sn9c102p_i2cwritebuf (dev,CtrlA640);	}static void sn9c102p_start(struct usb_spca50x *spca50x){		struct usb_device *dev = spca50x->dev;	int i;	__u8 DC29[]={0x6a, 0x50, 0x00, 0x00, 0x50, 0x3c};	__u8 C0[]={0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f};	__u8 CA[]={0x28, 0xd8, 0x14, 0xec };	__u8 CE[]={0x28, 0xec, 0x1e, 0xec };	__u8 ExpoInit[] = { 0xc1, 0x11, 0x25, 0x03, 0x27, 0xc0, 0x00, 0x16 };	__u8 PreAInit[] = { 0xa1, 0x11, 0x30, 0x1a, 0x00, 0x00, 0x00, 0x1d };	__u8 RInit[] = { 0xa1, 0x11, 0x31, 0x26, 0x00, 0x00, 0x00, 0x18 };	__u8 data = 0;	__u8 regF1 = 0x00;	int err = 0;			sonixRegWrite(dev,0x08,0xf1,0x0000,&regF1,1);	//{ 0x41, 0x08, 0x00F1, 0x0000, 0x0001, 0x0001, "\x00" },	sonixRegWrite(dev,0x08,0x01,0x0000,&sn9c102p[1],1);	//{ 0x41, 0x08, 0x0001, 0x0000, 0x0001, 0x0001, "\x03" },	// verify the sonix chips id and registers 0x01 access	//{ 0xC1, 0x00, 0x0000, 0x0000, 0x0001, 0x0001, "\x11" },	//{ 0xC1, 0x00, 0x0001, 0x0000, 0x0001, 0x0001, "\x03" },	// configure gpio 	sonixRegWrite(dev,0x08,0x01,0x0000,&sn9c102p[1],2);	//{ 0x41, 0x08, 0x0001, 0x0000, 0x0002, 0x0002, "\x03\x64" },	sonixRegWrite(dev,0x08,0x08,0x0000,&sn9c102p[8],2);	//{ 0x41, 0x08, 0x0008, 0x0000, 0x0002, 0x0002, "\xA1\x11" },	sonixRegWrite(dev,0x08,0x17,0x0000,&sn9c102p[0x17],3);	//{ 0x41, 0x08, 0x0017, 0x0000, 0x0003, 0x0003, "\x41\x1A\x00" },	sonixRegWrite(dev,0x08,0x9a,0x0000,reg9a,6);	//{ 0x41, 0x08, 0x009A, 0x0000, 0x0006, 0x0006, "\x08\x40\x20\x10\x00\x04" },	data= 0x60;	sonixRegWrite(dev,0x08,0xD4,0x0000,&data,1);	//{ 0x41, 0x08, 0x00D4, 0x0000, 0x0001, 0x0001, "\x60" },	sonixRegWrite(dev,0x08,0x03,0x0000,&sn9c102p[3],0x0f);	//{ 0x41, 0x08, 0x0003, 0x0000, 0x000F, 0x000F, "\x00\x1A\x20\x20\x20\xA1\x11\x02\x09\x00\x00\x00\x10\x03\x00" },	data= 0x43;	sonixRegWrite(dev,0x08,0x01,0x0000,&data,1);	//{ 0x41, 0x08, 0x0001, 0x0000, 0x0001, 0x0001, "\x43" },	data= 0x61;	sonixRegWrite(dev,0x08,0x17,0x0000,&data,1);	//{ 0x41, 0x08, 0x0017, 0x0000, 0x0001, 0x0001, "\x61" },	data= 0x42;	sonixRegWrite(dev,0x08,0x01,0x0000,&data,1);	if((err = sn9c102p_probesensor(spca50x)) < 0)		return ; 	hv7131R_InitSensor(spca50x);		sonixRegWrite(dev,0x08,0x15,0x0000,&sn9c102p[0x15],1);	sonixRegWrite(dev,0x08,0x16,0x0000,&sn9c102p[0x16],1);	sonixRegWrite(dev,0x08,0x12,0x0000,&sn9c102p[0x12],1);	sonixRegWrite(dev,0x08,0x13,0x0000,&sn9c102p[0x13],1);	sonixRegWrite(dev,0x08,0x18,0x0000,&sn9c102p[0x18],1);	sonixRegWrite(dev,0x08,0xd2,0x0000,&DC29[0],1);	sonixRegWrite(dev,0x08,0xd3,0x0000,&DC29[1],1);	sonixRegWrite(dev,0x08,0xc6,0x0000,&DC29[2],1);	sonixRegWrite(dev,0x08,0xc7,0x0000,&DC29[3],1);	sonixRegWrite(dev,0x08,0xc8,0x0000,&DC29[4],1);	sonixRegWrite(dev,0x08,0xc9,0x0000,&DC29[5],1);	sonixRegWrite(dev,0x08,0x18,0x0000,&sn9c102p[0x18],1);	data = 0x60;	sonixRegWrite(dev,0x08,0x17,0x0000,&data,1);	sonixRegWrite(dev,0x08,0x05,0x0000,&sn9c102p[5],1);	sonixRegWrite(dev,0x08,0x07,0x0000,&sn9c102p[7],1);	sonixRegWrite(dev,0x08,0x06,0x0000,&sn9c102p[6],1);	sonixRegWrite(dev,0x08,0x14,0x0000,&sn9c102p[0x14],1);	sonixRegWrite(dev,0x08,0x20,0x0000,regsn20,0x11);	for (i=0; i<8;i++)		sonixRegWrite(dev,0x08,0x84,0x0000,reg84,0x15);	data = 0x08;	sonixRegWrite(dev,0x08,0x9a,0x0000,&data,1);	data = 0x59;	sonixRegWrite(dev,0x08,0x99,0x0000,&data,1);	sonixRegWrite(dev,0x08,0x05,0x0000,&sn9c102p[5],1);	sonixRegWrite(dev,0x08,0x07,0x0000,&sn9c102p[7],1);	sonixRegWrite(dev,0x08,0x06,0x0000,&sn9c102p[6],1);	hv7131R_ConfigSensor(spca50x);	sonixRegWrite(dev,0x08,0xc0,0x0000,C0,6);	sonixRegWrite(dev,0x08,0xca,0x0000,CA,4);	sonixRegWrite(dev,0x08,0xce,0x0000,CE,4);	data = 0x02;	sonixRegWrite(dev,0x08,0x01,0x0000,&data,1); // sensor on video on	data = 0x61;	sonixRegWrite(dev,0x08,0x17,0x0000,&data,1);	// here change size mode 0 -> VGA; 1 -> CIF	data = 0x4A | (spca50x->mode << 4 );	sonixRegWrite(dev,0x08,0x18,0x0000,&data,1);	sonixRegWrite(dev,0x08,0x100,0x0000,qtable3,0x40);	sonixRegWrite(dev,0x08,0x140,0x0000,qtable3+0x40,0x40);	data = 0x0A |(spca50x->mode << 4 );	sonixRegWrite(dev,0x08,0x18,0x0000,&data,1);	data = 0x02;	sonixRegWrite(dev,0x08,0x01,0x0000,&data,1);	data = 0x61;	sonixRegWrite(dev,0x08,0x17,0x0000,&data,1);	hv7131R_StartSensor(spca50x);	if (spca50x->mode)		data = 0x06; //320 clk 12Mhz	else		data = 0x46; //640 clk 24Mz		// enable video on	sonixRegWrite(dev,0x08,0x01,0x0000,&data,1);	 sn9c102p_i2cwritebuf (dev,ExpoInit);	 sn9c102p_i2cwritebuf (dev,PreAInit);	 sn9c102p_i2cwritebuf (dev,RInit);}	static __u16 sn9c102p_setbrightness(struct usb_spca50x *spca50x){			__u8 k2;	k2 = spca50x->brightness >> 10;	sonixRegWrite(spca50x->dev,0x08,0x96,0x0000,&k2,1);return 0;}static __u16 sn9c102p_getbrightness(struct usb_spca50x *spca50x){		/* hardcoded registers seem not readable */	spca50x->brightness = 20 << 8;	return 0;}static __u16 sn9c102p_setcontrast(struct usb_spca50x *spca50x){	__u8 k2;	__u8 contrast[] = {0x14,0x00,0x28,0x00,0x07,0x00};	k2 = spca50x->contrast >> 8;	if (k2 > 0x7f) k2 = 0x7f;	contrast[2] = k2;	contrast[0] = (k2+1) >> 1;	contrast[4] = (k2+1) / 5 ;	sonixRegWrite(spca50x->dev,0x08,0x84,0x0000,contrast,6);	return 0;}static __u16 sn9c102p_getcontrast(struct usb_spca50x *spca50x){		/* hardcoded registers seem not readable */	spca50x->contrast = 0x28 << 8;return 0;}#if 0static unsigned int sn9c102p_getexposure(struct usb_spca50x *spca50x){	__u8 expo[] = {0,0,0,0,0};	int err = 0;	err += sn9c102p_i2cread (spca50x->dev,0x25, expo ,5); //read sensor exposure	return (unsigned int) (expo[0] << 16 | expo[1] << 8 | expo[2]);}static unsigned int sn9c102p_setexposure(struct usb_spca50x *spca50x,unsigned int expo){	__u8 exporet[] = {0,0,0,0,0};	__u8 Expodoit[] = { 0xc1, 0x11, 0x25, 0x07, 0x27, 0xc0, 0x00, 0x16 };	unsigned int expotimes = expo;	unsigned int expotimesret = 0;	int err =0;		Expodoit[3] = (expotimes >> 16) & 0xff;	Expodoit[4] = (expotimes >> 8) & 0xff;	Expodoit[5] = (expotimes & 0xff) ;	sn9c102p_i2cwritebuf (spca50x->dev,Expodoit);	err += sn9c102p_i2cread (spca50x->dev,0x25, exporet ,5); //read sensor exposure	expotimesret = exporet[0] << 16 | exporet[1] << 8 | exporet[2];	PDEBUG(5,"Exposure set %d ret %d ", expotimes,expotimesret);	return 	expotimesret;}static void sn9c102p_setAutobright (struct usb_spca50x *spca50x){ // GRR avg_lum from the header seem wrong set exposure on brightness instead		unsigned int expotimes=0;	unsigned int expotimesret = 0;		__u8 luma_mean = 110;	__u8 luma_delta = 20;	__u8 spring = 4; // 4 choice so the gain registers follow with a little retard	int delta;		delta = spca50x->avg_lum >> 2;	if((delta < (luma_mean - luma_delta)) ||		(delta > (luma_mean + luma_delta))){	expotimes = sn9c102p_getexposure(spca50x);	expotimes += ((luma_mean - delta) >> spring); 	expotimesret = sn9c102p_setexposure(spca50x,expotimes);	if (expotimes != expotimesret)		PDEBUG(0,"Error setting exposure !");	}	}static void sn9c102p_shutdown(struct usb_spca50x *spca50x){}#endif

⌨️ 快捷键说明

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