--- work/vid-1.0.1/vid.c-1.0.1 Sat Dec 7 10:25:14 2002 +++ work/vid-1.0.1/vid.c Thu Dec 19 22:47:24 2002 @@ -44,7 +44,7 @@ #define VERSION "1.0.1 (2000-05-07)" static int -ov511_reg_read(int fd, int reg) { +ov511_reg_read(int fd, unsigned char reg) { struct usb_ctl_request ur; unsigned char data[1024]; @@ -79,11 +79,16 @@ } static int -ov511_reg_write(int fd, int reg, int val) { +ov511_reg_write(int fd, unsigned char reg, unsigned char val) { struct usb_ctl_request ur; unsigned char data[1024]; - data[0] = val; + + /* data[0] = val >> 8; */ + data[0] = 0; + data[1] = val && 0xff; + + #if !defined(USB_STACK_VERSION) ||(USB_STACK_VERSION < 2) @@ -115,14 +120,17 @@ } static int -ov511_i2c_read(int fd, int reg) { +ov511_i2c_read(int fd, unsigned char reg) { int status = 0; - int val = 0; + unsigned char val = 0; int retries = OV7610_I2C_RETRIES; - + retries = 10; + printf("i2c reading\n"); while(--retries >= 0) { + printf("retries: %d\n", retries); /* wait until bus idle */ do { + printf(" ** (1) status: %x\n", status); if((status = ov511_reg_read(fd, OV511_REG_I2C_CONTROL)) < 0) return -1; } while((status & 0x01) == 0); @@ -139,17 +147,19 @@ do { if((status = ov511_reg_read(fd, OV511_REG_I2C_CONTROL)) < 0) return -1; + printf(" ** (2) status: %x, %x\n", status, status & 0x01); } while((status & 0x01) == 0); - + printf(" ** (3) status: %x, %x\n", status, status & 0x01); if((status & 0x2) == 0) break; } - + printf(" ** (4) status: %x, %x\n", status, status & 0x01); if(retries < 0) return -1; - + printf(" ** (5) status: %x\n", status); retries = OV7610_I2C_RETRIES; while(--retries >= 0) { + printf("retries: %d\n", retries); /* initiate read */ if(ov511_reg_write(fd, OV511_REG_I2C_CONTROL, 0x05) < 0) return -1; @@ -158,30 +168,31 @@ do { if((status = ov511_reg_read(fd, OV511_REG_I2C_CONTROL)) < 0) return -1; + printf(" ** (6) status: %x\n", status); } while ((status & 0x01) == 0); - + printf(" ** (7) status: %x\n", status); if((status & 0x2) == 0) break; - /* abort I2C bus before retrying */ if(ov511_reg_write(fd, OV511_REG_I2C_CONTROL, 0x10) < 0) return -1; } + printf(" ** (8) status: %x\n", status); if(retries < 0) return -1; - + printf(" ** (9) status: %x\n", status); /* retrieve data */ val = ov511_reg_read(fd, OV511_REG_SDA); - + printf(" ** (10) val: %x\n", val); /* issue another read for some weird reason */ if(ov511_reg_write(fd, OV511_REG_I2C_CONTROL, 0x05) < 0) return -1; - - return val; + printf(" ** (11) val: %x\n", val); + return (int) val; } static int -ov511_i2c_write(int fd, int reg, int val) { +ov511_i2c_write(int fd, unsigned char reg, unsigned char val) { int status = 0; int retries = OV7610_I2C_RETRIES; @@ -302,7 +313,7 @@ exit(1); } } - + printf("(-1)looking for device: %s\n",devname); if(devname) { if((fd = open(devname, O_RDWR)) < 0) { perror(devname); @@ -311,22 +322,28 @@ /* make sure it's an OV511 */ if(ioctl(fd, USB_GET_DEVICEINFO, &udi) < 0) { + printf("(0)looking for device\n"); perror("USB_GET_DEVICEINFO"); exit(1); } - + perror("USB_GET_DEVICEINFO"); + printf("udi.udi_vendorNo: %x\n", udi.udi_vendorNo); + printf("udi.udi_productNo: %x\n",udi.udi_productNo); + printf("USB_STACK_VERSION: %d\n", USB_STACK_VERSION); #if !defined(USB_STACK_VERSION) ||(USB_STACK_VERSION < 2) - - if(udi.vendorNo != 0x05A9 || udi.productNo != 0x0511 && udi.productNo != 0xa511) { + if(udi.vendorNo != 0x05a9 || udi.productNo != 0x0511 && udi.productNo != 0xa511) { #else - if(udi.udi_vendorNo != 0x05A9 || udi.udi_productNo != 0x0511 && udi.udi_productNo != 0xa511) { + if(udi.udi_vendorNo != 0x05a9 || udi.udi_productNo != 0x0511 && udi.udi_productNo != 0xa511) { #endif fprintf(stderr, "device %s is not an OmniVision OV511/OV511+\n", devname); exit(1); } + printf("(1)looking for device\n"); } else { + int i = 0; + printf("(2)looking for device\n"); for(i = 0; i < 15; ++i) { #ifdef __NetBSD__ sprintf(dev, "/dev/ugen%d.00", i); @@ -347,38 +364,49 @@ continue; } else { break; + printf("going on.\n"); } } - + printf("(2)going on.\n"); if(fd < 0) { fprintf(stderr, "vid: couldn't locate an OV511/OV511+ device\n"); exit(1); } + perror("USB_GET_DEVICEINFO"); + printf("udi.udi_vendorNo: %x\n", udi.udi_vendorNo); + printf("udi.udi_productNo: %x\n",udi.udi_productNo); devname = dev; } + printf("(3) looking for device\n"); #if !defined(USB_STACK_VERSION) ||(USB_STACK_VERSION < 2) isplus = udi.productNo == 0xa511; #else isplus = udi.udi_productNo == 0xa511; #endif bufsize = (isplus ? 961 : 993); - + printf("going on: bufsize: %d\n", bufsize); + /* reset the OV511 */ if(ov511_reg_write(fd, OV511_REG_RST, 0x7f) < 0) - exit(1); + {printf("exiting after reg_write 1.\n"); + exit(1);} if(ov511_reg_write(fd, OV511_REG_RST, 0) < 0) - exit(1); + {printf("exiting after reg_write 2.\n"); + exit(1);} /* initialize system */ if(ov511_reg_write(fd, OV511_REG_EN_SYS, 0x1) < 0) - exit(1); + {printf("exiting after reg_write 3.\n"); + exit(1);} /* determine the camera model */ if((cid = ov511_reg_read(fd, OV511_REG_CID)) < 0) - exit(1); + {printf("exiting after reg_write 4.\n"); + exit(1);} + printf("going on: cid: %d\n", cid); switch(cid) { case 0: /* This also means that no custom ID was set */ /* fprintf(stderr, "vid: MediaForte MV300\n"); */ @@ -418,38 +446,59 @@ /* set I2C read slave ID for OV7601 */ if(ov511_reg_write(fd, OV511_REG_SRA, OV7610_I2C_READ_ID) < 0) - exit(1); + {printf("exiting after reg_write 5.\n"); + exit(1);} + if(ov511_reg_write(fd, OV511_REG_PKSZ, 0x1) < 0) - exit(1); + {printf("exiting after reg_write 6.\n"); + exit(1);} + if(ov511_reg_write(fd, OV511_REG_PKFMT, 0x0) < 0) - exit(1); + {printf("exiting after reg_write 7.\n"); + exit(1);} + if(ov511_reg_write(fd, OV511_REG_RST, 0x3d) < 0) - exit(1); + {printf("exiting after reg_write 8.\n"); + exit(1);} + if(ov511_reg_write(fd, OV511_REG_RST, 0x0) < 0) - exit(1); + {printf("exiting after reg_write 9.\n"); + exit(1);} + printf("i2c read.\n"); if(ov511_i2c_read(fd, 0x00) < 0) - exit(1); + {printf("exiting after reg_write 10.\n"); + exit(1);} + printf("set YUV 4:2:0 format, Y channel LPF\n"); /* set YUV 4:2:0 format, Y channel LPF */ if(ov511_reg_write(fd, OV511_REG_M400, 0x01) < 0) - exit(1); + {printf("exiting after reg_write 11.\n"); + exit(1);} + if(ov511_reg_write(fd, OV511_REG_M420_YFIR, 0x03) < 0) - exit(1); + {printf("exiting after reg_write 12.\n"); + exit(1);} - /* disable snapshot */ + printf("disable snapshot\n"); if(ov511_reg_write(fd, OV511_REG_SNAP, 0x0) < 0) - exit(1); + {printf("exiting after reg_write 13.\n"); + exit(1);} + /* disable compression */ if(ov511_reg_write(fd, OV511_REG_CE_EN, 0x0) < 0) - exit(1); + {printf("exiting after reg_write 14.\n"); + exit(1);} + /* This returns 0 if we have an OV7620 sensor */ if((is20 = ov511_i2c_read(fd, OV7610_REG_COMI)) < 0) - exit(1); + {printf("exiting after reg_write 15.\n"); + exit(1);} + printf("set up the OV7610/OV7620\n"); is20 = !is20; /* set up the OV7610/OV7620 */ @@ -519,7 +568,7 @@ ov511_i2c_write(fd, OV7610_REG_COMC, 0x04); ov511_i2c_write(fd, OV7610_REG_COML, 0x1e); } - + printf("set up done\n"); ov511_reg_write(fd, OV511_REG_PXDV, 0x00); ov511_reg_write(fd, OV511_REG_LNDV, 0x00); @@ -528,7 +577,7 @@ exit(1); if(ov511_reg_write(fd, OV511_REG_PKFMT, 0x03) < 0) exit(1); - + printf("select the 993-byte alternative\n"); /* select the 993-byte alternative */ #if !defined(USB_STACK_VERSION) ||(USB_STACK_VERSION < 2) alt.interface_index = 0; @@ -541,8 +590,7 @@ perror("USB_SET_ALTINTERFACE"); exit(1); } - - /* reset the device again */ + printf("reset the device again\n"); if(ov511_reg_write(fd, OV511_REG_RST, 0x3F) < 0) exit(1); @@ -553,7 +601,7 @@ vs.state = SKIPPING; vs.segsize = 384; vs.xels = pnm_allocarray(vs.width, vs.height); - + printf("open the isochronous endpoint (endpoint 1)\n"); /* open the isochronous endpoint (endpoint 1) */ #ifdef __NetBSD__ sprintf(isocdev, "%s.01", strtok(devname,".")); @@ -564,9 +612,10 @@ perror(isocdev); exit(1); } - + printf("isocdev\n"); /* read, looking for start and end frames */ while(vs.state != DONE && (len = read(isoc, &buf, bufsize)) >= 0) { + printf("while %x\n",vs.state); if(buf[0] == 0 && buf[1] == 0 && buf[2] == 0 && buf[3] == 0 && buf[4] == 0 && buf[5] == 0 && buf[6] == 0 && buf[7] == 0 && (buf[8] & 0x80) == 0 && buf[bufsize-1] == 0 && vs.state == SKIPPING) { @@ -581,7 +630,7 @@ vs.state = DONE; } else if(vs.state == READING) { procdata(&vs, buf, bufsize - 1); - + printf("proccata\n"); /* abort the capture and start over if packets come in out-of-order */ if(buf[bufsize-1] != frmnm && buf[bufsize-1] != 1) { vs.state = SKIPPING; @@ -594,14 +643,15 @@ if(frmnm == 256) frmnm = 1; } + printf("proccata...\n"); } - + printf("reset and close the OV511\n"); /* reset and close the OV511 */ ov511_reg_write(fd, OV511_REG_RST, 0x7f); close(isoc); close(fd); - + printf("finishing\n"); /* convert from CIE YCbCr color to RGB */ postproc(&vs);