Wednesday, December 24, 2008

Getting Gumstix to see Logitech QuickCam E2500

I finally got my Gumstix to recognize the USB Camera. Fairly easy once I got it going :)

E2500 needs the GSPCA driver. No not the German Short-haired pointer club of America http://www.gspca.org/, or the Guyana Society for the Prevention of Cruelty to Animals, but the Generic Software Package for Camera Adapters. The GSPCA is a reverse engineered driver for numerous camera chips deployed in several usb web-cams.

While compiling the gspca driver is, purportedly, fairly trivial for ubuntu 7.10, I did run in to a few kinks with Ubuntu 8.10. Also the camera I bought from Fry's added another twist in the imbroglio: the Logitech QuickCam Connect E2500 web-cam is not supported directly by the gspca driver.. So I had to hunt around with Google till I found the thread that answered my question. Given the fact that my knowledge about Linux drivers is vanishingly small, this was the only option left to me. However, this has been a great learning experience and I definitely spy myself writing a video input device driver in the near future.

The following links were very helpful in getting this to work under Ubuntu 8.1 (I needed to do this to ensure that the camera works)

1. http://nepbabu.livejournal.com/15650.html
2. http://www.actionshrimp.com/2008/08/logitech-quickcam-e2500-on-ubuntu-skype/
3. http://www.nabble.com/CCD-cameras-and-the-Quick-Capture-Interface-td19498519.html

Per the instructions in 1., I downloaded the gspca driver and un-tar-ed it to the appropriate folder (~/work/gspcav1-20071224)
I then downloaded the patch (quickcamE2500.tar.gz) from http://forums.quickcamteam.net/attachment.php?aid=86 and untar to download folder (~/work)
Next, I applied the patch

cd ~/work/gspcav1-20071224
patch -p1 < ../quickcamE2500.diff

Compiled the module

sudo ./gspca_build


And copied over the module (gspca.ko) to the appropriate place. To do this, I first figured out where the current gspca.ko module lived (it existed, but the one that came with the kernel didn't support my web-cam).

bash$> sudo modprobe -v gspca
bash$> sudo mv /lib/modules/2.6.27-9-generic/kernel/drivers/usb/media/gspca.ko /lib/modules/2.6.27-9-generic/kernel/drivers/usb/media/gspca.ko.2008-12-22
bash$> sudo cp gspca.ko /lib/modules/2.6.27-9-generic/kernel/drivers/usb/media/gspca.ko
bash$> sudo rmmod gspca # remove the currently installed module
bash$> sudo modprobe gspca

#check to ensure that it is installed
bash$> lsmod | grep gspca


Next I connected the camera and got /dev/video0. I also checked dmesg | tail for notes about the camera being mounted


[ 4.843394] input: Logitech USB Receiver as /devices/pci0000:00/0000:00:1d.7/usb5/5-5/5-5.2/5-5.2:1.0/input/input1
[ 4.850991] input,hidraw0: USB HID v1.10 Keyboard [Logitech USB Receiver] on usb-0000:00:1d.7-5.2


At this point, I tried to fire up Ekiga because several online forums had mentioned success getting a picture. However, I had no such luck. After trying for a few hours and hunting around, I came across Nep's page above and that mentioned xawtv. A sudo-apt-gets later, I had all i needed and I was able to get a picture of myself. However, it took a really long time (~5 minutes) to start getting a picture. Also, I think some parameters may be off and might need some tuning because the picture in xawtv kept steady if i had my hand blocking almost all of the view (no, no i didn't cover the entire lens), but for almost every other situation, the bottom half of the picture would keep jumping. I suspect it has something to do with the average lighting and auto correction, but I tried turning off the parameters, but it didn't help much.

I tried various combinations (didn't exactly do a 2k factorial test here, but hey) of the following parameters, but no luck.

cd /sys/module/gspca/parameters/
sudo echo 0>autoexpo
sudo echo 4>gamma
sudo echo 300>GRed
sudo echo 300>GBlue
sudo echo 300>GGreen


I had to make some modifications to have this run under buidlroot.
I created a gspca folder under gumstix-buildroot/packages, and created two files per instructions found in buildroot/docs/buildroot.htm, viz. Config.in and gspca.mk

Config.in looks as below:

config BR2_PACKAGE_GSPCA
bool "gspca"
default n
help
The GSPCA video driver module. This required to support
Logitech Quickcam E2500 USB Webcam

http://www.nabble.com/CCD-cameras-and-the-Quick-Capture-Interface-td19498519.html
http://www.ithinkthereforeiforget.blogspot.com



gspca.mk is essentially a modified version given by Pete here:


#############################################################
#
# Driver for GSPCA USB web cams.
#
#############################################################

GSPCA_VERSION=20071224
GSPCA_SOURCE:=gspcav1-$(GSPCA_VERSION).tar.gz
GSPCA_SITE:=http://mxhaard.free.fr/spca50x/Download/$(GSPCA_SOURCE)
GSPCA_BUILD_DIR=$(BUILD_DIR)/gspcav1-$(GSPCA_VERSION)
GSPCA_PKG_DIR=$(BASE_DIR)/package/gspca
GSPCA_CAT:=zcat
GSPCA_MODULE=$(GSPCA_BUILD_DIR)/gspca.ko
GSPCA_TARGET_MODULE=$(TARGET_DIR)/lib/modules/2.6.21gum/extra/gspca.ko

GSPCA_CFLAGS := "-DGSPCA_ENABLE_COMPRESSION"
GSPCA_CFLAGS += "-DCONFIG_USB_GSPCA_MODULE=1"
GSPCA_CFLAGS += "-DVID_HARDWARE_GSPCA=0xFF"
GSPCA_CFLAGS += -DGSPCA_VERSION=\\\"01.00.20\\\"

# following are required to make Logitech QuickCam E2500. Change for
# other cameras accordingly
# wget http://forums.quickcamteam.net/attachment.php?aid=86 -O patch.tar.gz
GSPCA_PATCH:=patch
GSPCA_PATCH_OPTIONS:=-p1
GSPCA_PATCH_FILE:=quickcamE2500.diff
GSPCA_PATCH_SOURCE:=$(GSPCA_PATCH_FILE).tar.gz
GSPCA_PATCH_SITE:="http://forums.quickcamteam.net/attachment.php?aid=86"


$(DL_DIR)/$(GSPCA_SOURCE):
$(WGET) -P $(DL_DIR) $(GSPCA_SITE)/$(GSPCA_SOURCE)
#TODO: fix this!
# $(WGET) -P $(DL_DIR) $(GSPCA_PATCH_SITE)/$(GSPCA_PATCH_SOURCE)

gspca-source: $(DL_DIR)/$(GSPCA_SOURCE)

$(GSPCA_BUILD_DIR)/.unpacked: $(DL_DIR)/$(GSPCA_SOURCE)
$(GSPCA_CAT) $(DL_DIR)/$(GSPCA_SOURCE) | \
tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
############ Unpack patches #########
# $(GSPCA_CAT) $(DL_DIR)/$(GSPCA_PATCH_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
# cp $(DL_DIR)/$(GSPCA_PATCH_FILE) $(BUILD_DIR)/gspcav1-$(GSPCA_VERSION)
# TODO: fix this!
# cd $(GSPCA_PATCH) $(GSPCA_PATCH_OPTIONS) < $(BUILD_DIR)/$(GSPCA_PATCH_FILE)
touch $(GSPCA_BUILD_DIR)/.unpacked

$(GSPCA_MODULE): $(BASE_DIR)/uImage $(GSPCA_BUILD_DIR)/.unpacked
$(MAKE) -C "$(LINUX_DIR)" \
CROSS_COMPILE="$(KERNEL_CROSS)" \
ARCH=$(ARCH) \
CC="$(TARGET_CC)" \
EXTRA_CFLAGS="$(TARGET_CFLAGS) $(GSPCA_CFLAGS)" \
SUBDIRS="$(GSPCA_BUILD_DIR)" \
modules
touch $@

$(GSPCA_TARGET_MODULE): $(GSPCA_MODULE)
$(MAKE) -C "$(LINUX_DIR)" \
CROSS_COMPILE="$(KERNEL_CROSS)" \
ARCH=$(ARCH) \
CC="$(TARGET_CC)" \
EXTRA_CFLAGS="$(TARGET_CFLAGS)" \
SUBDIRS="$(GSPCA_BUILD_DIR)" \
INSTALL_MOD_PATH="$(TARGET_DIR)" \
modules_install

gspca: uclibc $(GSPCA_TARGET_MODULE)

gspca-clean:
-$(MAKE) -C $(GSPCA_BUILD_DIR) clean

gspca-dirclean:
rm -rf $(GSPCA_BUILD_DIR)

#############################################################
#
# Toplevel Makefile options
#
#############################################################
ifeq ($(strip $(BR2_PACKAGE_GSPCA)),y)
TARGETS+=gspca
endif


Next I started make menuconfig in and selected gspca from the menu. I still had to go in and patch the source manually for my logitech e2500. A make followed and created and installed the module in the proper location.

I fired up the gumstix, connected the camera and got the following:


[root@gumstix ~]# usb 1-2: new full speed USB device using pxa27x-ohci and address 2
usb 1-2: configuration #1 chosen from 1 choice
Linux video capture interface: v2.00
/home/hypo/gumstix/gumstix-buildroot-1614/build_arm_nofpu/gspcav1-20071224/gspca_core.c: USB GSPCA camera found.(ZC3XX)
usbcore: registered new interface driver gspca
/home/ot-1614/build_arm_nofpu/gspcav1-20071224/gspca_core.c: gspca driver 01.00.20 registered



Woohoo! /dev/video0 exists and is readable! Now on to porting spca-view!

Update (01/25/2009): Google seems to generate different results these days. Came across interesting post on atmel's site dealing with adding packages to buildroot while looking for something else.

http://www.atmel.com/dyn/resources/prod_documents/doc32082.pdf

3 comments:

Larry Martin said...

Great instructions, thanks. I found your blog while looking for instructions on how to use Pete's instructions :)

Caveats:
1. When pasting in the .mk file, you may have to globally replace leading spaces with tabs after pasting in the content.
2. In my buildroot 1642, I had to add the package to packages/Config.in before it would show up in make menuconfig.
3. On my FC9, the system refused to download from free.fr, or even accept a manual copy of the file into dl, so I had to set up a rule to copy the file from Desktop.

kage said...

Thanks for feedback Larry.

I know I've referred to some of my own posts every now and then to remember how i did things, but it's nice to know someone else finds these useful as well. :)

@ space to tabs: good observation. I'm sure it'll save time for others who follow these instructions.

kage said...

@ unable to download from free.fr: i'm confused. i just checked and i can still download the file. Can you please check if the address in the makefile results to the following? http://mxhaard.free.fr/spca50x/Download/gspcav1-20071224.tar.gzPlease feel free to post back any modifications you make. And i'm curious to hear what you're using your setup for!

cheers,
hypo