/* This code is (c) Ian Molton. It is GPL, however I *must be asked for permission to use it* should you desire to use it in your own project. */ #include #include #include #include //#include typedef unsigned char __u8; typedef unsigned short __u16; struct usb_dev_handle { int fd; struct usb_bus *bus; struct usb_device *device; int config; int interface; int altsetting; /* Added by RMT so implementations can store other per-open-device data */ void *impl_info; }; #define TimeOut 1000 static void sonixRegRead(usb_dev_handle *handle, __u16 reg, __u16 value, __u16 index, __u8 * buffer, __u16 length) { // int rc; __u8 *kbuffer = NULL; __u16 RegType; if (length > 0) { kbuffer = (__u8 *) malloc(length); memcpy(kbuffer, buffer, length); } RegType = USB_ENDPOINT_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE; /*rc = */usb_control_msg(handle, RegType, reg, (__u16) value, (__u16) index, kbuffer, length, TimeOut); if (length > 0) { memcpy(buffer, kbuffer, length); free(kbuffer); } if (buffer) { printf("reg read: 0x%02X, 0x%02X, 0x%02X, 0x%02X: 0x%04X\n", RegType, reg, value, index, (int) *buffer); } else { printf("reg read: 0x%02X, 0x%02X,0x%02X, 0x%02X\n", RegType, reg, value, index); } return; } static void sonixRegWrite(usb_dev_handle *handle, __u16 reg, __u16 value, __u16 index, __u8 * buffer, __u16 length) { // int rc; __u16 RegType; __u8 *kbuffer = NULL; if (length > 0) { kbuffer = (__u8 *) malloc(length); memcpy(kbuffer, buffer, length); } RegType = USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE; /*rc = */usb_control_msg(handle, RegType, reg, (__u16) value, (__u16) index, kbuffer, length, TimeOut); if (length > 0) { memcpy(buffer, kbuffer, length); free(kbuffer); } if (buffer) { printf("reg write: 0x%02X, 0x%02X, 0x%02X, 0x%02X: 0x%04X\n", RegType, reg, value, index, (int) *buffer); } else { printf("reg write: 0x%02X, 0x%02X,0x%02X, 0x%02X\n", RegType, reg, value, index); } return; } struct usbdevfs_iso_packet_desc { unsigned int length; unsigned int actual_length; unsigned int status; }; struct usbdevfs_urb { unsigned char type; unsigned char endpoint; int status; unsigned int flags; void *buffer; int buffer_length; int actual_length; int start_frame; int number_of_packets; int error_count; unsigned int signr; /* signal to be sent on error, -1 if none should be sent */ void *usercontext; // struct usbdevfs_iso_packet_desc iso_frame_desc[0]; }; struct usbthing { struct usbdevfs_urb urb; struct usbdevfs_iso_packet_desc iso[32]; }; #define USBDEVFS_URB_TYPE_ISO 0 #define USBDEVFS_SUBMITURB _IOR('U', 10, struct usbdevfs_urb) static __u8 sn_mi0360[] = { 0x12, 0x23, 0x60, 0x00, 0x1A, 0x00, 0x00, 0x00, 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, //reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 reg9 rega regb regc regd rege regf reg10 reg11 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x25, 0x39, 0x4b, //reg12 reg13 reg14 reg15 reg16 reg17 reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f reg20 reg21 reg22 reg23 0x5c, 0x6b, 0x79, 0x87, 0x95, 0xa2, 0xaf, 0xbb, 0xc7, 0xd3, 0xdf, 0xea, 0xf5 }; /*Data from sn9c102p+hv71331r */ static __u8 sn_hv7131[] = { 0x00, 0x03, 0x64, 0x00, 0x1A, 0x20, 0x20, 0x20, 0xA1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, //00 //reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 reg8 reg9 rega regb regc regd rege regf reg10 reg11 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 //reg12 reg13 reg14 reg15 reg16 reg17 reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f reg20 reg21 reg22 reg23 }; static __u8 reg9a[] = { 0x08, 0x40, 0x20, 0x00, 0x00, 0x00 }; static __u8 regsn20[] = { 0x00, 0x2D, 0x46, 0x5A, 0x6C, 0x7C, 0x8B, 0x99, 0xA6, 0xB2, 0xBF, 0xCA, 0xD5, 0xE0, 0xEB, 0xF5, 0xFF }; static __u8 reg84[] = { 0x13, 0x00, 0x25, 0x00, 0x07, 0x00, 0xEf, 0x0F, 0xE4, 0x0F, 0x33, 0x00, 0x38, 0x00, 0xd1, 0x0F, 0xf7, 0x0f, 0x0f, 0x00, 0x00 }; static __u8 mi0360_sensor_init[][8] = { {0xB1, 0x5D, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, {0xB1, 0x5D, 0x0D, 0x00, 0x01, 0x00, 0x00, 0x10}, {0xB1, 0x5D, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10}, {0xD1, 0x5D, 0x03, 0x01, 0xE2, 0x02, 0x82, 0x10}, {0xD1, 0x5D, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10}, {0xB1, 0x5D, 0x0D, 0x00, 0x02, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xB1, 0x5D, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10}, {0xD1, 0x5D, 0x2F, 0xF7, 0xB0, 0x00, 0x04, 0x10}, {0xD1, 0x5D, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10}, {0xB1, 0x5D, 0x3D, 0x06, 0x8F, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x40, 0x01, 0xE0, 0x00, 0xD1, 0x10}, {0xB1, 0x5D, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10}, {0xD1, 0x5D, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x5C, 0x00, 0x00, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x5E, 0x00, 0x00, 0xA3, 0x1D, 0x10}, {0xB1, 0x5D, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10}, {0xB1, 0x5D, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10}, {0xB1, 0x5D, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10}, {0xB1, 0x5D, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10}, {0xD1, 0x5D, 0x2B, 0x00, 0xA0, 0x00, 0xB0, 0x10}, {0xD1, 0x5D, 0x2D, 0x00, 0xA0, 0x00, 0xA0, 0x10}, {0xB1, 0x5D, 0x0A, 0x00, 0x02, 0x00, 0x00, 0x10}, //sensor clck ?2 {0xB1, 0x5D, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10}, {0xB1, 0x5D, 0x05, 0x00, 0x0A, 0x00, 0x00, 0x10}, {0xB1, 0x5D, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, // exposure 2 {0xD1, 0x5D, 0x2B, 0x00, 0xB9, 0x00, 0xE3, 0x10}, {0xD1, 0x5D, 0x2D, 0x00, 0x5f, 0x00, 0xB9, 0x10}, //42 //{0xB1, 0x5D, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, //gain orig //{0xB1, 0x5D, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, //gain {0xB1, 0x5D, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, //update {0xB1, 0x5D, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, //sensor on {0, 0, 0, 0, 0, 0, 0, 0} }; static __u8 qtable1[] = { 0x0B, 0x07, 0x07, 0x0B, 0x07, 0x07, 0x0B, 0x0B, 0x0B, 0x0B, 0x0E, 0x0B, 0x0B, 0x0E, 0x12, 0x1D, 0x12, 0x12, 0x0E, 0x0E, 0x12, 0x24, 0x19, 0x19, 0x15, 0x1D, 0x2B, 0x24, 0x2B, 0x2B, 0x27, 0x24, 0x27, 0x27, 0x2F, 0x32, 0x40, 0x39, 0x2F, 0x32, 0x3D, 0x32, 0x27, 0x27, 0x39, 0x4F, 0x39, 0x3D, 0x44, 0x48, 0x4B, 0x4B, 0x4B, 0x2B, 0x36, 0x52, 0x56, 0x4F, 0x48, 0x56, 0x40, 0x48, 0x4B, 0x48, 0x0B, 0x0E, 0x0E, 0x12, 0x0E, 0x12, 0x20, 0x12, 0x12, 0x20, 0x48, 0x2F, 0x27, 0x2F, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48 }; static __u8 qtable2[] = { 0x09, 0x06, 0x06, 0x09, 0x06, 0x06, 0x09, 0x09, 0x09, 0x09, 0x0C, 0x09, 0x09, 0x0C, 0x0F, 0x18, 0x0F, 0x0F, 0x0C, 0x0C, 0x0F, 0x1E, 0x15, 0x15, 0x12, 0x18, 0x24, 0x1E, 0x24, 0x24, 0x21, 0x1E, 0x21, 0x21, 0x27, 0x2A, 0x36, 0x30, 0x27, 0x2A, 0x33, 0x2A, 0x21, 0x21, 0x30, 0x42, 0x30, 0x33, 0x39, 0x3C, 0x3F, 0x3F, 0x3F, 0x24, 0x2D, 0x45, 0x48, 0x42, 0x3C, 0x48, 0x36, 0x3C, 0x3F, 0x3C, 0x09, 0x0C, 0x0C, 0x0F, 0x0C, 0x0F, 0x1B, 0x0F, 0x0F, 0x1B, 0x3C, 0x27, 0x21, 0x27, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C }; static __u8 qtable3[] = { 0x07, 0x05, 0x05, 0x07, 0x05, 0x05, 0x07, 0x07, 0x07, 0x07, 0x0A, 0x07, 0x07, 0x0A, 0x0C, 0x14, 0x0C, 0x0C, 0x0A, 0x0A, 0x0C, 0x19, 0x11, 0x11, 0x0F, 0x14, 0x1E, 0x19, 0x1E, 0x1E, 0x1B, 0x19, 0x1B, 0x1B, 0x20, 0x23, 0x2D, 0x28, 0x20, 0x23, 0x2A, 0x23, 0x1B, 0x1B, 0x28, 0x37, 0x28, 0x2A, 0x2F, 0x32, 0x34, 0x34, 0x34, 0x1E, 0x25, 0x39, 0x3C, 0x37, 0x32, 0x3C, 0x2D, 0x32, 0x34, 0x32, 0x07, 0x0A, 0x0A, 0x0C, 0x0A, 0x0C, 0x16, 0x0C, 0x0C, 0x16, 0x32, 0x20, 0x1B, 0x20, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32 }; static __u8 qtable4[] = { 0x06, 0x04, 0x04, 0x06, 0x04, 0x04, 0x06, 0x06, 0x06, 0x06, 0x08, 0x06, 0x06, 0x08, 0x0A, 0x11, 0x0A, 0x0A, 0x08, 0x08, 0x0A, 0x15, 0x0F, 0x0F, 0x0C, 0x11, 0x19, 0x15, 0x19, 0x19, 0x17, 0x15, 0x17, 0x17, 0x1B, 0x1D, 0x25, 0x21, 0x1B, 0x1D, 0x23, 0x1D, 0x17, 0x17, 0x21, 0x2E, 0x21, 0x23, 0x27, 0x29, 0x2C, 0x2C, 0x2C, 0x19, 0x1F, 0x30, 0x32, 0x2E, 0x29, 0x32, 0x25, 0x29, 0x2C, 0x29, 0x06, 0x08, 0x08, 0x0A, 0x08, 0x0A, 0x13, 0x0A, 0x0A, 0x13, 0x29, 0x1B, 0x17, 0x1B, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29 }; static __u8 qtable5[] = { 0x05, 0x03, 0x03, 0x05, 0x03, 0x03, 0x05, 0x05, 0x05, 0x05, 0x07, 0x05, 0x05, 0x07, 0x09, 0x0E, 0x09, 0x09, 0x07, 0x07, 0x09, 0x11, 0x0C, 0x0C, 0x0A, 0x0E, 0x15, 0x11, 0x15, 0x15, 0x13, 0x11, 0x13, 0x13, 0x16, 0x18, 0x1F, 0x1C, 0x16, 0x18, 0x1D, 0x18, 0x13, 0x13, 0x1C, 0x26, 0x1C, 0x1D, 0x21, 0x23, 0x24, 0x24, 0x24, 0x15, 0x1A, 0x28, 0x29, 0x26, 0x23, 0x29, 0x1F, 0x23, 0x24, 0x23, 0x05, 0x07, 0x07, 0x09, 0x07, 0x09, 0x10, 0x09, 0x09, 0x10, 0x23, 0x16, 0x13, 0x16, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23 }; static __u8 qtable6[] = { 0x04, 0x03, 0x03, 0x04, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x06, 0x04, 0x04, 0x06, 0x07, 0x0C, 0x07, 0x07, 0x06, 0x06, 0x07, 0x0E, 0x0A, 0x0A, 0x09, 0x0C, 0x11, 0x0E, 0x11, 0x11, 0x10, 0x0E, 0x10, 0x10, 0x13, 0x14, 0x1A, 0x17, 0x13, 0x14, 0x18, 0x14, 0x10, 0x10, 0x17, 0x20, 0x17, 0x18, 0x1B, 0x1D, 0x1E, 0x1E, 0x1E, 0x11, 0x16, 0x21, 0x23, 0x20, 0x1D, 0x23, 0x1A, 0x1D, 0x1E, 0x1D, 0x04, 0x06, 0x06, 0x07, 0x06, 0x07, 0x0D, 0x07, 0x07, 0x0D, 0x1D, 0x13, 0x10, 0x13, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D }; static __u8 qtable7[] = { 0x04, 0x02, 0x02, 0x04, 0x02, 0x02, 0x04, 0x04, 0x04, 0x04, 0x05, 0x04, 0x04, 0x05, 0x06, 0x0A, 0x06, 0x06, 0x05, 0x05, 0x06, 0x0C, 0x08, 0x08, 0x07, 0x0A, 0x0E, 0x0C, 0x0E, 0x0E, 0x0D, 0x0C, 0x0D, 0x0D, 0x10, 0x11, 0x16, 0x13, 0x10, 0x11, 0x14, 0x11, 0x0D, 0x0D, 0x13, 0x1A, 0x13, 0x14, 0x17, 0x18, 0x19, 0x19, 0x19, 0x0E, 0x12, 0x1C, 0x1D, 0x1A, 0x18, 0x1D, 0x16, 0x18, 0x19, 0x18, 0x04, 0x05, 0x05, 0x06, 0x05, 0x06, 0x0B, 0x06, 0x06, 0x0B, 0x18, 0x10, 0x0D, 0x10, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 }; static __u8 qtable8[] = { 0x03, 0x02, 0x02, 0x03, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x03, 0x03, 0x04, 0x05, 0x08, 0x05, 0x05, 0x04, 0x04, 0x05, 0x0A, 0x07, 0x07, 0x06, 0x08, 0x0C, 0x0A, 0x0C, 0x0C, 0x0B, 0x0A, 0x0B, 0x0B, 0x0D, 0x0E, 0x12, 0x10, 0x0D, 0x0E, 0x11, 0x0E, 0x0B, 0x0B, 0x10, 0x16, 0x10, 0x11, 0x13, 0x14, 0x15, 0x15, 0x15, 0x0C, 0x0F, 0x17, 0x18, 0x16, 0x14, 0x18, 0x12, 0x14, 0x15, 0x14, 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x09, 0x05, 0x05, 0x09, 0x14, 0x0D, 0x0B, 0x0D, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 }; static int sn9c102p_i2cwrite(usb_dev_handle *handle, __u8 * buffer, __u16 length) { __u8 mode[] = { 0x81, 0x11, 0, 0, 0, 0, 0, 0x10 }; /* is i2c ready */ __u8 i2cbase = 0x81; // = spca50x->i2c_base; __u8 i2cCtrl = 0x21; // = spca50x->i2c_ctrl_reg; mode[0] = i2cCtrl; mode[1] = i2cbase; if (length > 5 || !buffer) return -1; mode[0] = mode[0] | length << 4; memcpy(&mode[2], buffer, length); sonixRegWrite(handle, 0x08, 0x08, 0x0000, mode, 8); return 0; } static void sn9c102p_i2cwritebuf(usb_dev_handle *handle, __u8 * buffer) { sonixRegWrite(handle, 0x08, 0x08, 0x0000, buffer, 8); Sleep(1); } static int sn9c102p_i2cread(usb_dev_handle *handle, __u8 reg, __u8 * buffer, __u16 length) { __u8 i2cbase = 0x81; //= spca50x->i2c_base; __u8 i2cCtrl = 0x21; //= spca50x->i2c_ctrl_reg; int err = 0; __u8 mode[] = { 0x91, 0x11, 0, 0, 0, 0, 0, 0x10 }; __u8 result[] = { 0, 0, 0, 0, 0 }; mode[0] = i2cCtrl | 0x10; mode[1] = i2cbase; if (length > 5 || !buffer) return -1; mode[2] = reg; sonixRegWrite(handle, 0x08, 0x08, 0x0000, mode, 8); Sleep(1); mode[2] = 0; mode[0] = i2cCtrl | length << 4 | 0x02; sonixRegWrite(handle, 0x08, 0x08, 0x0000, mode, 8); Sleep(1); sonixRegRead(handle, 0x00, 0x0a, 0x0000, result, 5); memcpy(buffer, result, length); return err; } static int sn9cxxx_probesensor(usb_dev_handle *handle) { 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(handle, datasend, 2); //should write 0xa1 0x11 0x02 0x00 0x00 0x00 0x00 the 0x10 is add by i2cw Sleep(10); sonixRegWrite(handle, 0x08, 0x02, 0x0000, ®02, 1); //Gpio on Sleep(10); err += sn9c102p_i2cread(handle, 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) { printf("Find Sensor sn9c102P HV7131R"); //spca50x->sensor = SENSOR_HV7131R; return 1; } printf("Find Sensor %d %d %d", datarecd[0], datarecd[1], datarecd[2]); printf("Sensor sn9c102P Not found Contact mxhaard@free.fr "); return -1; errors: printf("Sensor sn9c102P too many errors Contact mxhaard@free.fr "); return -1; } static int sn9cxxx_init(usb_dev_handle *handle) { unsigned char *sn9c1xx = NULL; unsigned char regF1 = 0x01; unsigned char regGpio[] = { 0x29, 0x74 }; unsigned char data = 0x00; printf("%d\n", handle); printf("set_config: %d\n", usb_set_configuration(handle, 1)); printf("claim: %d\n", usb_claim_interface(handle, 0)); printf("set_alt: %d\n", usb_set_altinterface(handle, 8)); /* 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 -1; sonixRegWrite(handle, 0x08, 0xf1, 0x0000, ®F1, 1); sonixRegRead(handle, 0x00, 0x00, 0x0000, ®F1, 1); sonixRegWrite(handle, 0x08, 0xf1, 0x0000, ®F1, 1); sonixRegRead(handle, 0x00, 0x00, 0x0000, ®F1, 1); if (regF1 != 0x12) return -1; //regGpio[1] = 0x73; // light on regGpio[1] = 0x62; sonixRegWrite(handle, 0x08, 0x02, 0x0000, ®Gpio[1], 1); regF1 = 0x01; sonixRegWrite(handle, 0x08, 0xf1, 0x0000, ®F1, 1); regF1 = 0x00; sonixRegWrite(handle, 0x08, 0xf1, 0x0000, ®F1, 1); //sonixRegWrite(handle, 0x08, 0x01, 0x0000, &sn9c1xx[1], 1); // configure gpio // 006732 ms 41 08 01 00 00 00 02 00 >>> 23 60 sonixRegWrite(handle, 0x08, 0x01, 0x0000, &sn9c1xx[1], 2); // 006736 ms 41 08 08 00 00 00 02 00 >>> 81 21 sonixRegWrite(handle, 0x08, 0x08, 0x0000, &sn9c1xx[8], 2); // 006741 ms 41 08 17 00 00 00 05 00 >>> 40 08 00 00 00 sonixRegWrite(handle, 0x08, 0x017, 0x0000, &sn9c1xx[17], 5); // 006745 ms 41 08 9a 00 00 00 06 00 >>> 00 40 20 00 00 00 sonixRegWrite(handle, 0x08, 0x9a, 0x0000, reg9a, 6); // 006749 ms 41 08 d4 00 00 00 03 00 >>> 60 00 00 data = 0x60; sonixRegWrite(handle, 0x08, 0xD4, 0x0000, &data, 1); // 006753 ms 41 08 03 00 00 00 0f 00 >>> 00 1a 00 00 00 81 21 00 00 00 00 00 00 03 00 sonixRegWrite(handle, 0x08, 0x03, 0x0000, &sn9c1xx[3], 0x0f); // 006757 ms 41 08 01 00 00 00 01 00 >>> 63 data = 0x63; sonixRegWrite(handle, 0x08, 0x01, 0x0000, &data, 1); // 006761 ms 41 08 17 00 00 00 01 00 >>> 60 data = 0x60; sonixRegWrite(handle, 0x08, 0x17, 0x0000, &data, 1); // 006765 ms 41 08 01 00 00 00 01 00 >>> 62 // 006769 ms 41 08 01 00 00 00 01 00 >>> 42 data = 0x42; sonixRegWrite(handle, 0x08, 0x01, 0x0000, &data, 1); // switch (spca50x->sensor) { // case SENSOR_HV7131R: // probe sensor // if ((/*err = */sn9cxxx_probesensor(handle)) < 0) // return -1; // break; // } return 0; } static void mi0360_InitSensor(usb_dev_handle *handle) { int i = 0; while (mi0360_sensor_init[i][0]) { sn9c102p_i2cwritebuf(handle, mi0360_sensor_init[i]); i++; } } static void sn9cxxx_start(usb_dev_handle *handle) { 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[] = { 0x32, 0xdd, 0x2d, 0xdd }; //MI0360 __u8 CE[] = { 0x1e, 0xdd, 0x2d, 0xe7 }; __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; //000004 ms 006716 ms 41 08 f1 00 00 00 01 00 >>> 00 sonixRegWrite(handle, 0x08, 0xf1, 0x0000, ®F1, 1); //000004 ms 006720 ms 41 08 01 00 00 00 01 00 >>> 00 sonixRegWrite(handle, 0x08, 0x01, 0x0000, &sn9c1xx[1], 1); //000004 ms 006724 ms c1 00 00 00 00 00 01 00 <<< 12 //000004 ms 006728 ms c1 00 01 00 00 00 01 00 <<< 00 //000004 ms 006732 ms 41 08 01 00 00 00 02 00 >>> 23 60 sonixRegWrite(handle, 0x08, 0x01, 0x0000, &sn9c1xx[1], 2); //000005 ms 006736 ms 41 08 08 00 00 00 02 00 >>> 81 21 sonixRegWrite(handle, 0x08, 0x08, 0x0000, &sn9c1xx[8], 2); //000004 ms 006741 ms 41 08 17 00 00 00 05 00 >>> 40 08 00 00 00 sonixRegWrite(handle, 0x08, 0x17, 0x0000, &sn9c1xx[0x17], 5); //000004 ms 006745 ms 41 08 9a 00 00 00 06 00 >>> 00 40 20 00 00 00 sonixRegWrite(handle, 0x08, 0x9a, 0x0000, reg9a, 6); //000004 ms 006749 ms 41 08 d4 00 00 00 03 00 >>> 60 00 00 data = 0x60; sonixRegWrite(handle, 0x08, 0xD4, 0x0000, &data, 1); //000004 ms 006753 ms 41 08 03 00 00 00 0f 00 >>> 00 1a 00 00 00 81 21 00 00 00 00 00 00 03 00 sonixRegWrite(handle, 0x08, 0x03, 0x0000, &sn9c1xx[3], 0x0f); //000004 ms 006757 ms 41 08 01 00 00 00 01 00 >>> 63 data = 0x43; sonixRegWrite(handle, 0x08, 0x01, 0x0000, &data, 1); //000004 ms 006761 ms 41 08 17 00 00 00 01 00 >>> 60 data = 0x61; sonixRegWrite(handle, 0x08, 0x17, 0x0000, &data, 1); //000004 ms 006765 ms 41 08 01 00 00 00 01 00 >>> 62 //000004 ms 006769 ms 41 08 01 00 00 00 01 00 >>> 42 data = 0x42; sonixRegWrite(handle, 0x08, 0x01, 0x0000, &data, 1); // switch (spca50x->sensor) { // case SENSOR_HV7131R: // if ((err = sn9cxxx_probesensor(spca50x)) < 0) // return; // break; // } //000016 ms 006773 ms 41 08 08 00 00 00 08 00 >>> a1 21 06 00 00 00 00 10 //000004 ms 006789 ms 41 08 02 00 00 00 01 00 >>> 62 //000005 ms 006793 ms 41 08 08 00 00 00 08 00 >>> a1 21 01 00 00 00 00 10 //000005 ms 006798 ms 41 08 08 00 00 00 08 00 >>> a1 21 02 00 00 00 00 10 //000006 ms 006803 ms 41 08 08 00 00 00 08 00 >>> a1 21 03 00 00 00 00 10 //000005 ms 006809 ms 41 08 08 00 00 00 08 00 >>> a1 21 04 00 00 00 00 10 //000005 ms 006814 ms 41 08 08 00 00 00 08 00 >>> a1 21 05 00 00 00 00 10 //000005 ms 006819 ms 41 08 08 00 00 00 08 00 >>> a1 21 05 00 00 00 00 10 //000005 ms 006824 ms 41 08 08 00 00 00 08 00 >>> a1 21 05 00 00 00 00 10 //000005 ms 006829 ms 41 08 08 00 00 00 08 00 >>> a1 21 05 00 00 00 00 10 //000005 ms 006834 ms 41 08 08 00 00 00 08 00 >>> a1 21 05 04 00 00 00 10 //000005 ms 006839 ms 41 08 08 00 00 00 08 00 >>> a1 21 05 04 00 00 00 10 //000006 ms 006844 ms 41 08 08 00 00 00 08 00 >>> a1 21 05 04 00 00 00 10 //000005 ms 006850 ms 41 08 08 00 00 00 08 00 >>> a1 21 06 80 00 00 00 10 //000005 ms 006855 ms 41 08 08 00 00 00 08 00 >>> a1 21 06 80 00 00 00 10 //000005 ms 006860 ms 41 08 08 00 00 00 08 00 >>> a1 21 06 80 00 00 00 10 //000005 ms 006865 ms 41 08 08 00 00 00 08 00 >>> a1 21 06 80 00 00 00 10 //000005 ms 006870 ms 41 08 08 00 00 00 08 00 >>> a1 21 06 80 00 00 00 10 //000005 ms 006875 ms 41 08 08 00 00 00 08 00 >>> a1 21 06 80 00 00 00 10 //000005 ms 006880 ms 41 08 08 00 00 00 08 00 >>> a1 21 06 81 00 00 00 10 //000005 ms 006885 ms 41 08 08 00 00 00 08 00 >>> a1 21 0e 00 00 00 00 10 //000005 ms 006890 ms 41 08 08 00 00 00 08 00 >>> a1 21 11 00 00 00 00 10 //000005 ms 006895 ms 41 08 08 00 00 00 08 00 >>> a1 21 11 20 00 00 00 10 //000005 ms 006900 ms 41 08 08 00 00 00 08 00 >>> a1 21 11 30 00 00 00 10 //000005 ms 006905 ms 41 08 08 00 00 00 08 00 >>> a1 21 11 38 00 00 00 10 //000005 ms 006910 ms 41 08 08 00 00 00 08 00 >>> a1 21 11 38 00 00 00 10 //000005 ms 006915 ms 41 08 08 00 00 00 08 00 >>> a1 21 12 00 00 00 00 10 //000004 ms 006920 ms 41 08 02 00 00 00 01 00 >>> 72 //000004 ms 006924 ms 41 08 02 00 00 00 01 00 >>> 72 //000004 ms 006928 ms 41 08 15 00 00 00 01 00 >>> 28 sonixRegWrite(handle, 0x08, 0x15, 0x0000, &sn9c1xx[0x15], 1); //000004 ms 006932 ms 41 08 16 00 00 00 01 00 >>> 1e sonixRegWrite(handle, 0x08, 0x16, 0x0000, &sn9c1xx[0x16], 1); //000004 ms 006936 ms 41 08 12 00 00 00 01 00 >>> 0b sonixRegWrite(handle, 0x08, 0x12, 0x0000, &sn9c1xx[0x12], 1); //000004 ms 006940 ms 41 08 13 00 00 00 01 00 >>> 0f sonixRegWrite(handle, 0x08, 0x13, 0x0000, &sn9c1xx[0x13], 1); //000004 ms 006944 ms 41 08 18 00 00 00 01 00 >>> 08 sonixRegWrite(handle, 0x08, 0x18, 0x0000, &sn9c1xx[0x18], 1); //000004 ms 006948 ms 41 08 d2 00 00 00 01 00 >>> 6a sonixRegWrite(handle, 0x08, 0xd2, 0x0000, &DC29[0], 1); //000004 ms 006952 ms 41 08 d3 00 00 00 01 00 >>> 50 sonixRegWrite(handle, 0x08, 0xd3, 0x0000, &DC29[1], 1); //000004 ms 006956 ms 41 08 c6 00 00 00 01 00 >>> 00 sonixRegWrite(handle, 0x08, 0xc6, 0x0000, &DC29[2], 1); //000004 ms 006960 ms 41 08 c7 00 00 00 01 00 >>> 00 sonixRegWrite(handle, 0x08, 0xc7, 0x0000, &DC29[3], 1); //000004 ms 006964 ms 41 08 c8 00 00 00 01 00 >>> 50 sonixRegWrite(handle, 0x08, 0xc8, 0x0000, &DC29[4], 1); //000004 ms 006968 ms 41 08 c9 00 00 00 01 00 >>> 3c sonixRegWrite(handle, 0x08, 0xc9, 0x0000, &DC29[5], 1); //000004 ms 006972 ms 41 08 18 00 00 00 01 00 >>> 08 sonixRegWrite(handle, 0x08, 0x18, 0x0000, &sn9c1xx[0x18], 1); //000004 ms 006976 ms 41 08 17 00 00 00 01 00 >>> 60 data = 0x60; sonixRegWrite(handle, 0x08, 0x17, 0x0000, &data, 1); //000004 ms 006980 ms 41 08 05 00 00 00 01 00 >>> 00 sonixRegWrite(handle, 0x08, 0x05, 0x0000, &sn9c1xx[5], 1); //000004 ms 006984 ms 41 08 07 00 00 00 01 00 >>> 00 sonixRegWrite(handle, 0x08, 0x07, 0x0000, &sn9c1xx[7], 1); //000004 ms 006988 ms 41 08 06 00 00 00 01 00 >>> 00 sonixRegWrite(handle, 0x08, 0x06, 0x0000, &sn9c1xx[6], 1); //000004 ms 006992 ms 41 08 14 00 00 00 01 00 >>> 14 sonixRegWrite(handle, 0x08, 0x14, 0x0000, &sn9c1xx[0x14], 1); //000004 ms 006996 ms 41 08 20 00 00 00 11 00 >>> 08 25 39 4b 5c 6b 79 87 95 a2 af bb c7 d3 df ea f5 sonixRegWrite(handle, 0x08, 0x20, 0x0000, regsn20, 0x11); //000004 ms 007000 ms 41 08 84 00 00 00 15 00 >>> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 00 00 //000004 ms 007004 ms 41 08 84 00 00 00 15 00 >>> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 00 00 //000004 ms 007008 ms 41 08 84 00 00 00 15 00 >>> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 00 00 //000004 ms 007012 ms 41 08 84 00 00 00 15 00 >>> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 00 00 //000004 ms 007016 ms 41 08 84 00 00 00 15 00 >>> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 00 00 //000004 ms 007020 ms 41 08 84 00 00 00 15 00 >>> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 00 00 //000004 ms 007024 ms 41 08 84 00 00 00 15 00 >>> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 00 00 //000004 ms 007028 ms 41 08 84 00 00 00 15 00 >>> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 00 00 //000004 ms 007032 ms 41 08 84 00 00 00 15 00 >>> 13 00 25 00 07 00 ef 0f df 0f 33 00 38 00 d1 0f f7 0f 0f 00 00 for (i = 0; i < 8; i++) sonixRegWrite(handle, 0x08, 0x84, 0x0000, reg84, 0x15); //000004 ms 007036 ms 41 08 9a 00 00 00 01 00 >>> 08 data = 0x08; sonixRegWrite(handle, 0x08, 0x9a, 0x0000, &data, 1); //000004 ms 007040 ms 41 08 99 00 00 00 01 00 >>> 60 data = 0x60; sonixRegWrite(handle, 0x08, 0x99, 0x0000, &data, 1); //000004 ms 007044 ms 41 08 84 00 00 00 15 00 >>> 13 00 25 00 07 00 ef 0f df 0f 33 00 38 00 d1 0f f7 0f 0f 00 00 //000004 ms 007048 ms 41 08 05 00 00 00 01 00 >>> 20 //000004 ms 007052 ms 41 08 07 00 00 00 01 00 >>> 20 //000004 ms 007056 ms 41 08 06 00 00 00 01 00 >>> 20 //000004 ms 007060 ms 41 08 20 00 00 00 11 00 >>> 08 25 39 4b 5c 6b 79 87 95 a2 af bb c7 d3 df ea f5 //000005 ms 007064 ms 41 08 08 00 00 00 08 00 >>> a1 21 12 00 00 00 00 10 //000005 ms 007069 ms 41 08 08 00 00 00 08 00 >>> a1 21 12 00 00 00 00 10 //000004 ms 007074 ms 41 08 13 00 00 00 01 00 >>> 0f //000005 ms 007078 ms 41 08 08 00 00 00 08 00 >>> a1 21 10 00 00 00 00 10 //000005 ms 007083 ms 41 08 08 00 00 00 08 00 >>> a1 21 0f 20 00 00 00 10 //000005 ms 007088 ms 41 08 08 00 00 00 08 00 >>> a1 21 10 20 00 00 00 10 //000006 ms 007093 ms 41 08 08 00 00 00 08 00 >>> a1 21 00 00 00 00 00 10 //000004 ms 007099 ms 41 08 05 00 00 00 01 00 >>> 20 //000004 ms 007103 ms 41 08 07 00 00 00 01 00 >>> 20 //000004 ms 007107 ms 41 08 06 00 00 00 01 00 >>> 20 // switch (spca50x->sensor) { // case SENSOR_HV7131R: // hv7131R_InitSensor(spca50x); // break; // case SENSOR_MI0360: mi0360_InitSensor(handle); // break; // } //000004 ms 007111 ms 41 08 c0 00 00 00 06 00 >>> 2d 2d 3a 05 04 3f sonixRegWrite(handle, 0x08, 0xc0, 0x0000, C0, 6); //000004 ms 007115 ms 41 08 ca 00 00 00 04 00 >>> 28 d8 14 ec sonixRegWrite(handle, 0x08, 0xca, 0x0000, CA, 4); //000004 ms 007119 ms 41 08 ce 00 00 00 04 00 >>> 1e dd 2d e7 sonixRegWrite(handle, 0x08, 0xce, 0x0000, CE, 4); //?? {0x1e,0xdd,0x2d,0xe7} //000004 ms 007123 ms 41 08 01 00 00 00 01 00 >>> 42 //000004 ms 007127 ms 41 08 17 00 00 00 01 00 >>> 62 //000005 ms 007131 ms 41 08 08 00 00 00 08 00 >>> a1 21 11 38 00 00 00 10 //000004 ms 007136 ms 41 08 05 00 00 00 01 00 >>> 20 //000004 ms 007140 ms 41 08 07 00 00 00 01 00 >>> 20 //000004 ms 007144 ms 41 08 06 00 00 00 01 00 >>> 20 //000004 ms 007148 ms 41 08 18 00 00 00 01 00 >>> 48 // here change size mode 0 -> VGA; 1 -> CIF data = 0x40 | sn9c1xx[0x18] /*| (spca50x->mode << 4)*/; sonixRegWrite(handle, 0x08, 0x18, 0x0000, &data, 1); //000004 ms 007152 ms 41 08 00 01 00 00 40 00 >>> 06 04 04 06 04 04 06 06 06 06 08 06 06 08 0a 10 0a 0a 08 08 0a 13 0e 0e 0c 10 17 13 17 17 15 13 15 15 19 1b 23 1f 19 1b 21 1b 15 15 1f 2b 1f 21 25 27 29 29 29 17 1d 2d 2f 2b 27 2f 23 27 29 27 sonixRegWrite(handle, 0x08, 0x100, 0x0000, qtable4, 0x40); //000004 ms 007156 ms 41 08 40 01 00 00 40 00 >>> 06 08 08 0a 08 0a 12 0a 0a 12 27 19 15 19 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 sonixRegWrite(handle, 0x08, 0x140, 0x0000, qtable4 + 0x40, 0x40); //000004 ms 007160 ms 41 08 18 00 00 00 01 00 >>> 08 data = sn9c1xx[0x18] /*| (spca50x->mode << 4)*/; sonixRegWrite(handle, 0x08, 0x18, 0x0000, &data, 1); //000004 ms 007164 ms 41 08 02 00 00 00 01 00 >>> 72 //000004 ms 007168 ms 41 08 02 00 00 00 01 00 >>> 72 //000004 ms 007172 ms 41 08 01 00 00 00 01 00 >>> 42 data = 0x02; //0x42 sonixRegWrite(handle, 0x08, 0x01, 0x0000, &data, 1); //000004 ms 007176 ms 41 08 17 00 00 00 01 00 >>> 62 data = 0x62; //0x61 sonixRegWrite(handle, 0x08, 0x17, 0x0000, &data, 1); //002123 ms 007180 ms 41 08 08 00 00 00 08 00 >>> a1 21 11 38 00 00 00 10 // OUT -02121 ms 009303 ms >>> //Function reset pipe (look at the logs) //ISOCH_TRANSFER - (not parsed) //ISOCH_TRANSFER - (not parsed) //000004 ms 007186 ms 41 08 01 00 00 00 01 00 >>> 46 // if (spca50x->mode) // data = 0x46; //320 clk 48Mhz // else { data = 0x06; //640 clk 24Mz // } // enable video on sonixRegWrite(handle, 0x08, 0x01, 0x0000, &data, 1); //000004 ms 007190 ms 41 08 15 00 00 00 01 00 >>> 28 //000003 ms 007194 ms 41 08 16 00 00 00 01 00 >>> 1e //000003 ms 007197 ms 41 08 12 00 00 00 01 00 >>> 0b //000003 ms 007200 ms 41 08 13 00 00 00 01 00 >>> 0f //000003 ms 007203 ms 41 08 18 00 00 00 01 00 >>> 08 //000003 ms 007206 ms 41 08 d2 00 00 00 01 00 >>> 6a //000003 ms 007209 ms 41 08 d3 00 00 00 01 00 >>> 50 //000003 ms 007212 ms 41 08 c6 00 00 00 01 00 >>> 00 //000003 ms 007215 ms 41 08 c7 00 00 00 01 00 >>> 00 //000003 ms 007218 ms 41 08 c8 00 00 00 01 00 >>> 50 //000062 ms 007221 ms 41 08 c9 00 00 00 01 00 >>> 3c // sn9cxxx_setbrightness(spca50x); // sn9cxxx_setcontrast(spca50x); } int do_stuff(usb_dev_handle *handle){ unsigned char str[64000]; int q, p, j, i; FILE *file; // int err = 0; // 006773 ms 41 08 08 00 00 00 08 00 >>> a1 21 06 00 00 00 00 10 // 006789 ms 41 08 02 00 00 00 01 00 >>> 62 // usb_resetep(handle, 0x83); // usb_resetep(handle, 0x81); // usb_resetep(handle, 0x82); Sleep(1); //while(1) // submit_iso(handle, 0x81); // return; file = fopen("cam_in.raw", "wb"); // while(1) { memset(str, 0, 1023); sonixRegRead(handle,0,0x0a,0,str,5); // send_ctrl(handle, 0xc1, 0, 0x0a, 0, str, 5); q = usb_bulk_read(handle, USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_IN, str, 64000, 1000); j = 0; if(q >= 0){ fwrite(str, q, 1, file); for(i = 0 ; i < q ; i++) j += str[i]; printf("%d : %08x\n",q, j); } /*else{ usb_resetep(handle, 0x83); usb_resetep(handle, 0x81); }*/ } printf("\n"); return 0; } int main(void){ struct usb_bus *busses; struct usb_bus *bus; usb_dev_handle *handle; usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for (bus = busses; bus; bus = bus->next) { struct usb_device *dev; for (dev = bus->devices; dev; dev = dev->next) { if (dev->descriptor.idVendor == 0x0c45 && dev->descriptor.idProduct == 0x612e) { // printf("%d\n", dev->config[0].bConfigurationValue); handle = usb_open(dev); sn9cxxx_init(handle); sn9cxxx_start(handle); do_stuff(handle); usb_close(handle); exit(0); } } } return 0; }