I recently started experimenting with pic32 as it has a USB OTG host mode that can be used to connect cheap peripherals. First peripheral i tried was a 4 yrs old USB camera that was lying around unused. However getting documentation for it was a problem as most of the cheap webcams vendors don't even have a website. The only documentation i could find about it was from http://mxhaard.free.fr/spca5xx.html. Since I knew that webcam worked with my laptop (running linux) so i was sure that this driver is already incorporated into linux kernel source tree. Only approach left now was to go through the driver code and port it to pic32.
Finding source code for driver didn't took long. Basically, hook up camera to laptop and note down the vendor & product id in output of "lsusb". For my camera vendor id was : 0x04fc and product id was : 0x0561. Download linux kernel source code and grep with product id in drivers/media/video. It throws up a file names for sunplus driver. Cross check it with the driver in the output of "lsmod" output and voila we have the original sources for the driver.
However, driver source had lot of linux specific stuff for video and v4l support so next step was to write a new bare bone driver in linux from the original source. This new driver was to dump more USB specific information about cam like interfaces, end-points and alternate configs to use and also the steps required to configure the webcam.
Webcam USB interface details:
Webcam exposed few i2c and reg read/write interfaces through the control end-point. These were used for writing the initial startup-code, configuring various params like brightness etc. and also reading auto-gain settings. It also presented iso end-points with different buffer size in different alternate config to meeting the bandwidth requirements. For my purpose i used the alternate config 0x07 with end-point buffer size of 1024. There are other end-point with smaller buffer-size like 256 also. Camera streaming is initiated by writing few config setting through i2c interface and once started frames are received on iso endpoints. A single image is broken down into multiple frames of 1024 size and sent through iso end-point. Frames are of different types (FIRST_FRAME, INTER_FRAME, LAST_FRAME, DISCARD_FRAME) and driver on host is responsible for stitching up all the frames together to form a complete image. The image transferred by camera is in a propitiatory format and needs to be converted before a imaging software can be used to display it.
A user-application to read frame grabbed by the driver and dump it in a bmp format was also required. This however posed a problem as camera frame format wasn't documented much. Little fiddling in the original source code and googling threw a possible solution to use a open-source library libv4lconvert. It was a smooth ride from there-on to dumping the bitmap. So finally we had the code & more importantly initialization and configuration steps for reading a image from camera.
Porting it to pic32 with microchip usb library didn't took much time except for few things like setting desired alternate configs to use in pic32 USB library.
Image captured from webcam:
Complete source code for user-application & pic32 firmware are available for download.
Source code is embedded into the following image files using OpenStego availabe at http://openstego.sourceforge.net.
For detail procedure on how to recover the source file take a look at http://bytewerx.blogspot.com/2009/07/uploading-files-to-blogger.html.
Do make sure to check the md5sum of recovered source files.
application_zip.png : 708548fb26119aeec77c0dc7cce3ac02
firmware_tar_gz.png : da76ba3bf1394be861690bb11c7cc22e
image_grabber_hex.png : 25cb132b3c45cd06a5ed6dc827c4dcda
application.zip : c6876b534fb98c222eebc01a1af8ba7c
firmware.tar.gz : d01cae86832a4e87fa50e92df783bef5
image_grabber.hex : 0656b15fecd78c5f7662c9bc3c18513c
You can alternatively download the applications from my dropbox (www.dropbox.com) public folders :