📄 sn9cxxx.h
字号:
{ int i = 0; struct usb_device *dev = spca50x->dev; while (mi0360_sensor_init[i][0]){ sn9c102p_i2cwritebuf (dev,hv7131r_sensor_init[i]); i++; } } static int sn9cxxx_init(struct usb_spca50x *spca50x){ struct usb_device *dev = spca50x->dev; int err = 0; __u8 *sn9c1xx= NULL; __u8 regF1 = 0x01; __u8 regGpio[] = {0x29,0x74}; __u8 data = 0x00; /* setup a selector by customid */ switch(spca50x->sensor){ case SENSOR_HV7131R: sn9c1xx= sn_hv7131; break; case SENSOR_MI0360: sn9c1xx=sn_mi0360; break; } if (sn9c1xx == NULL) return -ENODEV; sonixRegWrite(dev,0x08,0xf1,0x0000,®F1,1); sonixRegRead(dev,0x00,0x00,0x0000,®F1,1); sonixRegWrite(dev,0x08,0xf1,0x0000,®F1,1); sonixRegRead(dev,0x00,0x00,0x0000,®F1,1); switch (spca50x->customid) { case SN9C102P: if (regF1 != 0x11) return -ENODEV; sonixRegWrite(dev,0x08,0x02,0x0000,®Gpio[1],1); case SN9C105: if (regF1 != 0x11) return -ENODEV; sonixRegWrite(dev,0x08,0x02,0x0000,regGpio,2); break; case SN9C120: if (regF1 != 0x12) return -ENODEV; regGpio[1] = 0x70; sonixRegWrite(dev,0x08,0x02,0x0000,regGpio,2); break; } regF1 = 0x01; sonixRegWrite(dev,0x08,0xf1,0x0000,®F1,1); regF1 = 0x00; sonixRegWrite(dev,0x08,0xf1,0x0000,®F1,1); sonixRegWrite(dev,0x08,0x01,0x0000,&sn9c1xx[1],1); // configure gpio sonixRegWrite(dev,0x08,0x01,0x0000,&sn9c1xx[1],2); sonixRegWrite(dev,0x08,0x08,0x0000,&sn9c1xx[8],2); sonixRegWrite(dev,0x08,0x017,0x0000,&sn9c1xx[0x17],3); sonixRegWrite(dev,0x08,0x9a,0x0000,reg9a,6); data= 0x60; sonixRegWrite(dev,0x08,0xD4,0x0000,&data,1); sonixRegWrite(dev,0x08,0x03,0x0000,&sn9c1xx[3],0x0f); data= 0x43; sonixRegWrite(dev,0x08,0x01,0x0000,&data,1); data= 0x61; sonixRegWrite(dev,0x08,0x17,0x0000,&data,1); data= 0x42; sonixRegWrite(dev,0x08,0x01,0x0000,&data,1); switch(spca50x->sensor){ case SENSOR_HV7131R: // probe sensor if((err = sn9cxxx_probesensor(spca50x)) < 0) return -ENODEV; break; } return 0;}static void sn9cxxx_stop(struct usb_spca50x *spca50x){ struct usb_device *dev = spca50x->dev; __u8 stophv7131[] = { 0xA1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 }; __u8 stopmi0360[] = { 0xB1, 0x5D, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 }; __u8 regF1 = 0x01; __u8 data = 0x0b; __u8 *sn9c1xx=NULL; switch(spca50x->sensor){ case SENSOR_HV7131R: sn9c1xx= sn_hv7131; data = 0x2b; sn9c102p_i2cwritebuf (dev,stophv7131); break; case SENSOR_MI0360: sn9c1xx=sn_mi0360; data = 0x29; sn9c102p_i2cwritebuf (dev,stopmi0360); break; } if (sn9c1xx == NULL) return; sonixRegWrite(dev,0x08,0x01,0x0000,&sn9c1xx[1],1); sonixRegWrite(dev,0x08,0x17,0x0000,&sn9c1xx[0x17],1); sonixRegWrite(dev,0x08,0x01,0x0000,&sn9c1xx[1],1); sonixRegWrite(dev,0x08,0x01,0x0000,&data,1); sonixRegWrite(dev,0x08,0xf1,0x0000,®F1,1);}static void sn9cxxx_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 }; //HV7131 __u8 CE[]={0x28, 0xec, 0x1e, 0xec }; __u8 CE[]={0x32, 0xdd, 0x2d, 0xdd };//MI0360 __u8 gain[] = { 0xB1,0x5D,0x35,0x00,0x67,0x00,0x00,0x10 }; //gain __u8 doit[] = { 0xB1,0x5D,0x07,0x00,0x03,0x00,0x00,0x10 }; //update sensor __u8 sensorgo[] ={ 0xB1,0x5D,0x07,0x00,0x02,0x00,0x00,0x10 }; //sensor on //__u8 expo[]={ 0xB1,0x5D,0x09,0x06,0x35,0x00,0x00,0x10 };// exposure 0x0635 -> 4 fp/s __u8 data = 0; __u8 regF1 = 0x00; int err = 0; __u8 *sn9c1xx = NULL; switch(spca50x->sensor){ case SENSOR_HV7131R: sn9c1xx= sn_hv7131; break; case SENSOR_MI0360: sn9c1xx=sn_mi0360; break; } if (sn9c1xx == NULL) return; sonixRegWrite(dev,0x08,0xf1,0x0000,®F1,1); sonixRegWrite(dev,0x08,0x01,0x0000,&sn9c1xx[1],1); sonixRegWrite(dev,0x08,0x01,0x0000,&sn9c1xx[1],2); sonixRegWrite(dev,0x08,0x08,0x0000,&sn9c1xx[8],2); sonixRegWrite(dev,0x08,0x17,0x0000,&sn9c1xx[0x17],3); sonixRegWrite(dev,0x08,0x9a,0x0000,reg9a,6); data= 0x60; sonixRegWrite(dev,0x08,0xD4,0x0000,&data,1); sonixRegWrite(dev,0x08,0x03,0x0000,&sn9c1xx[3],0x0f); data= 0x43; sonixRegWrite(dev,0x08,0x01,0x0000,&data,1); data= 0x61; sonixRegWrite(dev,0x08,0x17,0x0000,&data,1); data= 0x42; sonixRegWrite(dev,0x08,0x01,0x0000,&data,1); switch(spca50x->sensor){ case SENSOR_HV7131R: if((err = sn9cxxx_probesensor(spca50x)) < 0) return ; break; } sonixRegWrite(dev,0x08,0x15,0x0000,&sn9c1xx[0x15],1); sonixRegWrite(dev,0x08,0x16,0x0000,&sn9c1xx[0x16],1); sonixRegWrite(dev,0x08,0x12,0x0000,&sn9c1xx[0x12],1); sonixRegWrite(dev,0x08,0x13,0x0000,&sn9c1xx[0x13],1); sonixRegWrite(dev,0x08,0x18,0x0000,&sn9c1xx[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,&sn9c1xx[0x18],1); data = 0x60; sonixRegWrite(dev,0x08,0x17,0x0000,&data,1); sonixRegWrite(dev,0x08,0x05,0x0000,&sn9c1xx[5],1); sonixRegWrite(dev,0x08,0x07,0x0000,&sn9c1xx[7],1); sonixRegWrite(dev,0x08,0x06,0x0000,&sn9c1xx[6],1); sonixRegWrite(dev,0x08,0x14,0x0000,&sn9c1xx[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); switch(spca50x->sensor){ case SENSOR_HV7131R: hv7131R_InitSensor(spca50x); break; case SENSOR_MI0360: mi0360_InitSensor(spca50x); break; } sonixRegWrite(dev,0x08,0xc0,0x0000,C0,6); sonixRegWrite(dev,0x08,0xca,0x0000,CA,4); sonixRegWrite(dev,0x08,0xce,0x0000,CE,4);//?? {0x1e,0xdd,0x2d,0xe7} // here change size mode 0 -> VGA; 1 -> CIF data = 0x40 | sn9c1xx[0x18] | (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 = sn9c1xx[0x18] |(spca50x->mode << 4 ); sonixRegWrite(dev,0x08,0x18,0x0000,&data,1); data = 0x02;//0x42 sonixRegWrite(dev,0x08,0x01,0x0000,&data,1); data = 0x61;//0x61 sonixRegWrite(dev,0x08,0x17,0x0000,&data,1); if (spca50x->mode) data = 0x06; //320 06clk 12Mhz else { if(spca50x->sensor == SENSOR_MI0360){ data = 0x65;//0x61 sonixRegWrite(dev,0x08,0x17,0x0000,&data,1); } data = 0x46; //640 clk 24Mz 46 } // enable video on sonixRegWrite(dev,0x08,0x01,0x0000,&data,1); err = sn9cxxx_setbrightness(spca50x); if(spca50x->sensor == SENSOR_MI0360){ /*FIXME Need to be in the brightness exposure setting */ sn9c102p_i2cwritebuf (dev,gain); // sn9c102p_i2cwritebuf (dev,expo); sn9c102p_i2cwritebuf (dev,doit); sn9c102p_i2cwritebuf (dev,sensorgo); } //sn9c102p_i2cwritebuf (dev,PreAInit); //sn9c102p_i2cwritebuf (dev,RInit);}static unsigned int sn9cxxx_getexposure(struct usb_spca50x *spca50x){ __u8 expo[] = {0,0,0,0,0}; int err = 0; switch (spca50x->sensor){ case SENSOR_HV7131R: err += sn9c102p_i2cread (spca50x,0x25, expo ,5); //read sensor exposure return (unsigned int) (expo[0] << 16 | expo[1] << 8 | expo[2]); break; case SENSOR_MI0360: err += sn9c102p_i2cread (spca50x,0x09, expo ,5); //read sensor exposure return (unsigned int) (expo[0] << 8 | expo[1] ); break; } return 0;}static unsigned int sn9cxxx_setexposure(struct usb_spca50x *spca50x,unsigned int expo){ __u8 Expodoit[] = { 0xc1, 0x11, 0x25, 0x07, 0x27, 0xc0, 0x00, 0x16 }; __u8 doit[] = { 0xB1,0x5D,0x07,0x00,0x03,0x00,0x00,0x10 }; //update sensor __u8 sensorgo[] ={ 0xB1,0x5D,0x07,0x00,0x02,0x00,0x00,0x10 }; //sensor on __u8 expoMi[]={ 0xB1,0x5D,0x09,0x06,0x35,0x00,0x00,0x10 };// exposure 0x0635 -> 4 fp/s unsigned int expotimes = expo; unsigned int expotimesret = 0; switch(spca50x->sensor){ case SENSOR_HV7131R: Expodoit[3] = (expotimes >> 16) & 0xff; Expodoit[4] = (expotimes >> 8) & 0xff; Expodoit[5] = (expotimes & 0xff) ; sn9c102p_i2cwritebuf (spca50x->dev,Expodoit); wait_ms(10); expotimesret = sn9cxxx_getexposure(spca50x); PDEBUG(3,"Exposure set %d ret %d ", expotimes,expotimesret); return expotimesret; break; case SENSOR_MI0360: if ( expo > 0x0635) expo = 0x0635; if ( expo < 0x0100) expo = 0x0100; expoMi[3]= (expo >> 8) & 0xFF; expoMi[4] = expo & 0xff; sn9c102p_i2cwritebuf (spca50x->dev,expoMi); sn9c102p_i2cwritebuf (spca50x->dev,doit); sn9c102p_i2cwritebuf (spca50x->dev,sensorgo); expotimesret = sn9cxxx_getexposure(spca50x); PDEBUG(3,"Exposure set %d ret %d ", expotimes,expotimesret); return expotimesret; break; } return 0;} static __u16 sn9cxxx_setbrightness(struct usb_spca50x *spca50x){ unsigned int expo,expotimesret ; __u8 k2; switch(spca50x->sensor){ case SENSOR_HV7131R: expo = spca50x->brightness << 4; if (expo > 0x002dc6c0) expo = 0x002dc6c0; if (expo < 0x02a0) expo = 0x02a0; expotimesret = sn9cxxx_setexposure(spca50x,expo); break; case SENSOR_MI0360: expo = spca50x->brightness >> 4; expotimesret = sn9cxxx_setexposure(spca50x,expo); break; } k2 = spca50x->brightness >> 10; sonixRegWrite(spca50x->dev,0x08,0x96,0x0000,&k2,1);return 0;}static __u16 sn9cxxx_getbrightness(struct usb_spca50x *spca50x){ /* hardcoded registers seem not readable */ spca50x->brightness = 0x7fff; return 0;}static __u16 sn9cxxx_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 sn9cxxx_getcontrast(struct usb_spca50x *spca50x){ /* hardcoded registers seem not readable */ spca50x->contrast = 0x28 << 8;return 0;}#if 0static void sn9cxxx_setAutobright (struct usb_spca50x *spca50x){ // GRR avg_lum from the header seem wrong set exposure on brightness instead // FIXME where is the avg luma value ?? 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; spin_lock_irq(&spca50x->v4l_lock); delta = spca50x->avg_lum ; spin_unlock_irq(&spca50x->v4l_lock); //PDEBUG(0,"Error setting exposure delta %d",delta); if((delta < (luma_mean - luma_delta)) || (delta > (luma_mean + luma_delta))){ expotimes = sn9cxxx_getexposure(spca50x); expotimes += ((luma_mean - delta) >> spring); expotimesret = sn9cxxx_setexposure(spca50x,expotimes); if (expotimes != expotimesret) PDEBUG(0,"Error setting exposure !"); } }static void sn9cxxx_shutdown(struct usb_spca50x *spca50x){}#endif#endif //SONIXJPGUSB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -