📄 sn9cxxx.h
字号:
__u8 DC29[] = { 0x6a, 0x50, 0x00, 0x00, 0x50, 0x3c }; __u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f }; __u8 CA[] = { 0x28, 0xd8, 0x14, 0xec }; __u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; //MI0360 __u8 data = 0; __u8 regF1 = 0x00; __u8 reg17 = 0x61; __u8 reg1 = 0x02; int err = 0; __u8 *sn9c1xx = NULL; switch (spca50x->sensor) { case SENSOR_HV7131R: sn9c1xx = sn_hv7131; break; case SENSOR_MI0360: sn9c1xx = sn_mi0360; break; case SENSOR_MO4000: sn9c1xx = sn_mo4000; break; case SENSOR_OV7660: sn9c1xx = sn_ov7660; 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); if (spca50x->mode) reg1 = 0x46; //320 clk 48Mhz else { reg1 = 0x06; //640 clk 24Mz } break; case SENSOR_MI0360: mi0360_InitSensor(spca50x); if (spca50x->mode) reg1 = 0x46; //320 clk 48Mhz else { reg1 = 0x06; //640 clk 24Mz } break; case SENSOR_MO4000: mo4000_InitSensor(spca50x); if (spca50x->mode) reg1 = 0x46; //320 clk 48Mhz else { reg1 = 0x06; //640 clk 24Mz } break; case SENSOR_OV7660: //reg1 = 0x44; reg1 = 0x46; ov7660_InitSensor(spca50x); if (spca50x->mode){ //reg17 = 0x21; //320 reg1 = 0x46; } else { reg17 = 0x22; //640 MCKSIZE reg1 = 0x06; } 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, qtable4, 0x40); sonixRegWrite(dev, 0x08, 0x140, 0x0000, qtable4 + 0x40, 0x40); data = sn9c1xx[0x18] | (spca50x->mode << 4); sonixRegWrite(dev, 0x08, 0x18, 0x0000, &data, 1); sonixRegWrite(dev, 0x08, 0x17, 0x0000, ®17, 1); sonixRegWrite(dev, 0x08, 0x01, 0x0000, ®1, 1); sn9cxxx_setbrightness(spca50x); sn9cxxx_setcontrast(spca50x);}static unsigned intsn9cxxx_getexposure(struct usb_spca50x *spca50x){ __u8 hexpo,mexpo,lexpo; __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; case SENSOR_OV7660: case SENSOR_OV7630: err += sn9c102p_i2cread(spca50x, 0x04, expo, 5); //read sensor exposure hexpo = expo[3] & 0x2f; lexpo = expo[0] & 0x02; err += sn9c102p_i2cread(spca50x, 0x08, expo, 5); mexpo = expo[2]; return (unsigned int) ((hexpo << 10) | (mexpo << 2) | (lexpo)); break; } return 0;}static unsigned intsn9cxxx_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, 0x16 }; // exposure 0x0635 -> 4 fp/s 0x10 unsigned int expotimes = expo; 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); break; case SENSOR_MI0360: if (expo > 0x0635) expo = 0x0635; if (expo < 0x0001) expo = 0x0001; expoMi[3] = (expo >> 8) & 0xFF; expoMi[4] = expo & 0xff; sn9c102p_i2cwritebuf(spca50x->dev, expoMi); sn9c102p_i2cwritebuf(spca50x->dev, doit); sn9c102p_i2cwritebuf(spca50x->dev, sensorgo); break; } return expo;}static voidsn9cxxx_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); spca50x->exposure = expotimesret; break; case SENSOR_MI0360: expo = spca50x->brightness >> 4; expotimesret = sn9cxxx_setexposure(spca50x, expo); spca50x->exposure = expotimesret; break; } k2 = spca50x->brightness >> 10; sonixRegWrite(spca50x->dev, 0x08, 0x96, 0x0000, &k2, 1);}static __u16sn9cxxx_getbrightness(struct usb_spca50x *spca50x){ /* hardcoded registers seem not readable */ switch (spca50x->sensor) { case SENSOR_HV7131R: //spca50x->brightness = 0x7fff; spca50x->brightness = sn9cxxx_getexposure(spca50x) >> 4; break; case SENSOR_MI0360: //spca50x->brightness = 0x1fff; spca50x->brightness = sn9cxxx_getexposure(spca50x) << 4; break; } return spca50x->brightness;}static voidsn9cxxx_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);}static __u16sn9cxxx_getcontrast(struct usb_spca50x *spca50x){ /* hardcoded registers seem not readable */ spca50x->contrast = 0x3f << 8; //0x28 return spca50x->contrast;}static intsn9cxxx_sofdetect(struct usb_spca50x *spca50x, struct spca50x_frame *frame, unsigned char *cdata, int *iPix, int seqnum, int *datalength){ int sof; sof = *datalength - 64; if (sof < 0) { *iPix = 0; return (seqnum + 1); } else if (cdata[sof] == 0xff && cdata[sof + 1] == 0xd9) { // copy the end of data frame memcpy(frame->highwater, cdata, sof + 2); frame->highwater += (sof + 2); // totlen += (sof + 2);// w1 w2 w3// w4 w5 w6// w7 w8 spin_lock(&spca50x->v4l_lock); spca50x->avg_lum = ((cdata[sof + 29] << 8) | cdata[sof + 30]) >> 6; //w4 spca50x->avg_lum += ((cdata[sof + 33] << 8) | cdata[sof + 34]) >> 6; //w6 spca50x->avg_lum += ((cdata[sof + 25] << 8) | cdata[sof + 26]) >> 6; //w2 spca50x->avg_lum += ((cdata[sof + 37] << 8) | cdata[sof + 38]) >> 6; //w8 spca50x->avg_lum += ((cdata[sof + 31] << 8) | cdata[sof + 32]) >> 4; //w5 spca50x->avg_lum = spca50x->avg_lum >> 4; spin_unlock(&spca50x->v4l_lock); PDEBUG(4,"mean luma %d", spca50x->avg_lum); // setting to skip the rest of the packet *iPix = *datalength; *datalength = 0; return 0; //start of frame } else *iPix = 0; return (seqnum + 1);}static __u16sn9cxxx_getcolors(struct usb_spca50x *spca50x){//__u8 red,green,blue;//sonixRegRead(spca50x->dev, 0x00, 0x05, 0x0000, &red, 1);//sonixRegRead(spca50x->dev, 0x00, 0x06, 0x0000, &blue, 1);//sonixRegRead(spca50x->dev, 0x00, 0x07, 0x0000, &green, 1);//PDEBUG(0,"Colors gain red %d green %d blue %d", red & 0x7f,green & 0x7f,blue & 0x7f); spca50x->colour = (0x80) << 8; return spca50x->colour;}static voidsn9cxxx_setcolors(struct usb_spca50x *spca50x){ __u8 red, blue; int colour; colour = (spca50x->colour >> 8) - 128; if (colour > 0) { blue = (colour + 32) & 0x7f; sonixRegWrite(spca50x->dev, 0x08, 0x06, 0x0000, &blue, 1); } else { red = (-colour + 32) & 0x7f; sonixRegWrite(spca50x->dev, 0x08, 0x05, 0x0000, &red, 1); }}static voidsn9cxxx_setAutobright(struct usb_spca50x *spca50x){ // Thanks S., without your advice, autobright should not work :) int delta; int expotimes = 0; unsigned int expotimesret = 0; __u8 luma_mean = 130; __u8 luma_delta = 20; spin_lock_irq(&spca50x->v4l_lock); delta = spca50x->avg_lum; spin_unlock_irq(&spca50x->v4l_lock); if ((delta < (luma_mean - luma_delta)) || (delta > (luma_mean + luma_delta))) { switch (spca50x->sensor) { case SENSOR_HV7131R: expotimes = spca50x->exposure >> 8; expotimes += ((luma_mean - delta) >> 4); if (expotimes < 0) expotimes = 0; expotimesret = sn9cxxx_setexposure(spca50x, (unsigned int) (expotimes << 8)); spca50x->exposure = expotimes << 8; break; case SENSOR_MI0360: expotimes = spca50x->exposure; expotimes += ((luma_mean - delta) >> 6); if (expotimes < 0) expotimes = 0; expotimesret = sn9cxxx_setexposure(spca50x, (unsigned int) expotimes); spca50x->exposure = expotimes; sn9cxxx_setcolors(spca50x); break; } }}#endif //SONIXJPGUSB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -