I am writing a C application that capture video from my webcam.
I am not able to determine which pixel format my webcam is able to process.
lsusb:
Bus 002 Device 003: ID 1e4e:0100 Cubeternet WebCam
dmesg
[ 1064.735472] usb 2-1.4: new high speed USB device using ehci_hcd and address 4
[ 1064.837577] usb 2-1.4: New USB device found, idVendor=1e4e, idProduct=0100
[ 1064.837583] usb 2-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1064.837587] usb 2-1.4: Product: USB2.0 Camera
[ 1064.837589] usb 2-1.4: Manufacturer: Etron Technologies
[ 1064.837715] usb 2-1.4: configuration #1 chosen from 1 choice
[ 1064.838484] uvcvideo: Found UVC 1.00 device USB2.0 Camera (1e4e:0100)
[ 1064.843070] uvcvideo: UVC non compliance - GET_DEF(PROBE) not supported. Enabling workaround.
[ 1064.844229] input: USB2.0 Camera as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.0/input/input7
I was able to determine the image size '640x480' but not the pixel format:
I have tried
YUV420
RGB565
RGB32
with no success. Any help Please.
I am using Debian latest version
Since it is a UVC video, by looking up the wiki here:
http://www.wikiwand.com/en/USB_video_device_class
You will see that UVC supports
Uncompressed YUV formats YUY2, NV12.
Actually YUY2 is also called YUYV which is YUV 4:2:2.
You can find a conversion to RGB here:
https://bitbucket.org/neuralassembly/simplewebcam/src/a940256eda0d/jni/ImageProc.h
You can use:
v4l2-ctl --list-formats
That should give you the supported pixel formats
In addition, you can also use:
v4l2-ctl --list-formats-ext
which should give you the supported pixel formats a resolutions.
Related
I'm try to disable my two USB keyboard on my linux system, the one can unbind long time until I unplug then plugin and the number lock light is off during this time. But the other one can not unbind long time, maybe after 5 seconds, it will reconnect again and the number lock light is on during this time, the other lights will flash once, the log shown below:
[505545.210490] usb 3-3.1: USB disconnect, device number 47
[505547.687005] usb 3-3.1: new low-speed USB device number 49 using xhci_hcd
[505547.984255] usb 3-3.1: New USB device found, idVendor=17ef, idProduct=6099
[505547.984258] usb 3-3.1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[505547.984260] usb 3-3.1: Product: Lenovo Traditional USB Keyboard
[505548.019948] input: Lenovo Traditional USB Keyboard as /devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-3/3-3.1/3-3.1:1.0/input/input40
[505548.071999] hid-generic 0003:17EF:6099.002A: input,hidraw1: USB HID v1.10 Keyboard [Lenovo Traditional USB Keyboard] on usb-0000:03:00.0-3.1/input0
Below is my shell command to disable the keyboard:
echo "3-3.1" > /sys/bus/usb/drivers/usb/unbind
or
echo "0003:17EF:6099.002A" > /sys/bus/hid/drivers/hid-generic/unbind
What is the reason for this difference? Is have a way to disable the second keyboard?
Thank a lot
I read from LDD3 chapter 14 about hotplug drivers.I need to write a usb mouse driver which load when I plug the hardware. Now, doing some experiment I come to know that there is a driver named "hid-generic" which is called when plug-unplug.
[ 6654.232046] usb 3-1: new low-speed USB device number 3 using uhci_hcd
[ 6654.462061] usb 3-1: New USB device found, idVendor=093a, idProduct=2510
[ 6654.462067] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 6654.462071] usb 3-1: Product: USB OPTICAL MOUSE
[ 6654.462074] usb 3-1: Manufacturer: PIXART
[ 6654.489316] input: PIXART USB OPTICAL MOUSE as /devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0/input/input12
[ 6654.489445] hid-generic 0003:093A:2510.0004: input,hidraw0: USB HID v1.10 Mouse [PIXART USB OPTICAL MOUSE] on usb-0000:00:1d.1-1/input0
Also lsmod shows,
Module Size Used by
hid_generic 12541 0
usbhid 47259 0
hid 105241 2 hid_generic,usbhid
psmouse 102541 0
My doubts are as follows,
1) To make my module load (hotplug) when this mouse plugs in, I have to disable these 3 drivers in kernel and build whole kernel with my driver with vendor and device ID in id_table. Right?
2) I also read about USB core drivers and USB device drivers. So these HID drivers are core drivers or device drivers?
3) Which are core drivers and device driver in case of USB mouse? And where can I find them in kernel source?
Thanks,
Sunil.
I'll try to answer your questions one by one :
1) To make my module load (hotplug) when this mouse plugs in, I have to disable these 3 drivers in kernel and build whole kernel with my driver with vendor and device ID in id_table. Right?
Yes, but there are some additional things you need to take care of. First understand how a particular module(driver) gets loaded. The key to this is MODULE_DEVICE_TABLE(usb, &my_id_table); Whenever a particular module is "installed" (using make modules_install), an entry, according to the id table passed in MODULE_DEVICE_TABLE gets created in /lib/modules/<your_kernel>/modules.usbmap and /lib/modules/<your_kernel>/modules.dep file(search for the string "usbhid" in the files). Whenever a new usb device is detected, the kernel reads these files to find the matching parameters. If it is found, the following module is loaded from the corresponding path found in /lib/modules/<your_kernel>/modules.dep which holds the info. about the path where the driver is located and also its dependencies.
So, now even if you unload(rmmod) usbhid from the kernel, it will be loaded again when you re-insert your mouse. To avoid this from happening you need to modify those files, i.e. remove the entries from the files. To do so, "move" the usbhid driver from its original path(generally located at /lib/modules/<your_kernel>/kernel/drivers/hid/usbhid/usbhid.ko to a safe place. Now rebuild the dependencies such that the entries would be removed from the dependency files.
Now you need to create entries of your driver. Just install your driver and you are good to go!
So, to summarize :
$ sudo rmmod usbhid # Unload the usb mouse driver
$ cd /lib/modules/$(uname -r)/ # Move to your current kernel
$ vim modules.usbmap # Check for the "usbhid" string
$ vim modules.dep # Check for "usbhid.ko:" string
$ sudo mv kernel/drivers/hid/usbhid/usbhid.ko ~/Desktop # Take backup of your current
usb mouse driver
$ sudo depmod -a # Rebuild the dependency files
Now check the dependency files for the string "usbhid" again. It shouldn't be there!
$ cd /path/to/your/driver
$ sudo make modules_install # Install your driver into /lib/modules/$(uname -r)/extra
$ sudo depmod -a # Rebuild the dependency files
After this step, search for the string corresponding to your module in the dependency files, and it should be there! From this moment on, whenever you insert the mouse(or from boot itself) your driver will be loaded, instead of the original.
Once your are done playing with your driver, you may copy back the original usbhid file to its original destination and rebuild the dependency files (sudo depmod -a)
Now I also see that you are trying to use vendor and device id to match your device, in which case, the driver would work only for your mouse. The recommended way is to use class ids, which makes your driver work for any usb mouse.
2) I also read about USB core drivers and USB device drivers. So these HID drivers are core drivers or device drivers?
usbhid is basically a "device driver". The classification of drivers could be briefed out as : core drivers, host controller drivers and device drivers :
Device Drivers : This is the software used to control the devices. For example usb mouse, pci based ethernet card, usb pendrive, i2c based accelerometer.
Host Controller Drivers : This is the software written to control the bus controller. For example USB Host Controllers(EHCI, UHCI, OHCI, etc.), PCI Host Controller, I2C Masters, etc.
Core Drivers : These actually glues up the above discussed drivers. Examples are USB core, PCI core, etc. Core drivers provides helper routines(APIs) such that the device and host-controller driver could make use of them(concept of module stacking!). These are the ones, which bind the correct device to its driver. There are many other services provided by the core drivers.
Example code for USB Device Driver :
http://lxr.free-electrons.com/source/drivers/hid/usbhid/usbmouse.c
You may find the USB Host Controller Drivers under :
http://lxr.free-electrons.com/source/drivers/usb/host/
USB Core resides here : http://lxr.free-electrons.com/source/drivers/usb/core/
I think this also answers your third question!
Hope this helped.
The device driver is usbhid.
To prevent it from attaching to your device, add a HID_QUIRK_IGNORE entry to drivers/hid/usbhid/hid-quirks.c, or use the quirks parameter of the usbhid module.
I have a usb mass storage, and today I insert into usb port, the usb can't be open, I using "dmesg" to see infomation
adan#adan-Latitude-D630:~$ dmesg | tail
[ 409.001220] composite sync not supported
[ 616.340074] usb 2-1: new high-speed USB device number 5 using ehci-pci
[ 617.392967] usb 2-1: New USB device found, idVendor=090c, idProduct=3000
[ 617.392979] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 617.392987] usb 2-1: Product: SM3255AA MEMORY BAR
[ 617.392994] usb 2-1: Manufacturer: Silicon Motion,Inc.
[ 617.393558] scsi5 : usb-storage 2-1:1.0
[ 618.393265] scsi 5:0:0:0: Direct-Access USB MEMORY BAR 1000 PQ: 0 ANSI: 0 CCS
[ 618.397967] sd 5:0:0:0: Attached scsi generic sg2 type 0
[ 618.399479] sd 5:0:0:0: [sdb] Attached SCSI removable disk
On windows, the usb mass storage was be detected as USB disk drive, can't open usb in file browser too.
what's wrong with my usb? how to fix it? thank you.
I'm developing a ttyACM device with ST microcontroller, and with the same code, my host could sometimes enumerate it successfully (below) but sometimes it just dump the below message. What does error -32 mean?
[FAIL TO ENUMERATE]
usb 1-2.1: new full speed USB device number 62 using ehci_hcd
usb 1-2.1: device descriptor read/64, error -32
usb 1-2.1: device descriptor read/64, error -32
usb 1-2.1: new full speed USB device number 63 using ehci_hcd
usb 1-2.1: device descriptor read/64, error -32
usb 1-2.1: device descriptor read/64, error -32
usb 1-2.1: new full speed USB device number 64 using ehci_hcd
usb 1-2.1: device not accepting address 64, error -32
usb 1-2.1: new full speed USB device number 65 using ehci_hcd
usb 1-2.1: device not accepting address 65, error -32
hub 1-2:1.0: unable to enumerate USB device on port 1
[SUCCESSFUL RESULT]
usb 1-3.1: new full speed USB device number 45 using ehci_hcd
usb 1-3.1: New USB device found, idVendor=0483, idProduct=5740
usb 1-3.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-3.1: Product: ChibiOS/RT Virtual COM Port
usb 1-3.1: Manufacturer: HelloWord
usb 1-3.1: SerialNumber: 262
usb 1-3.1: configuration #1 chosen from 1 choice
cdc_acm 1-3.1:1.0: This device cannot do calls on its own. It is not a modem.
cdc_acm 1-3.1:1.0: ttyACM0: USB ACM device
Thanks a lot.
AFAIK status -32 means "Broken pipe" (EPIPE). It means that there are problems with usb communication (protocol). For example usb-device doesn't answer correctly for usb-request, and sending some data that are not expected by host or sends not enough data. There may be also other reasons.
The first message tells that there are problems with "get device descriptor" and "set address" requests from host. Those are basic requests sending by host at the very beginning of enumeration process. You can't go further if those requests cannot be succesfully serviced by usb-device.
This error can be caused by clocking the on-chip USB device at the wrong frequency. Check your clock tree configuration. The frequency should be 48MHz. If it's slightly off, it's possible that enumeration would sometimes be successful and sometimes fail. If it's way off, enumeration will always fail. Various errors are possible including the ones you listed.
I have installed the XCP-NG server in one laptop and my system was not booting either due to this error: USB 3-1 device descriptor read/64, error 32
I tried a lot of things. Even disconnecting the USB ports.
Until I recalled that I have removed the default SR repository for Xen. So I went to check the /etc/fstab file
[root#xcpserver2 ~]# cat /etc/fstab
LABEL=root-jvgtod / ext3 defaults,noatime 1 1
LABEL=swap-jvgtod swap swap defaults 0 0
LABEL=logs-jvgtod /var/log ext3 defaults,noatime 0 2
/opt/xensource/packages/iso/XenCenter.iso /var/xen/xc-install iso9660 loop,ro 0 0
The default SR repository was trying to get the content of the last line. I tried to comment it and it worked!! :) I concluded that this error it also showing when there is a problem at the /etc/fstab file. I hope it helps!
So, my /etc/fstab file looks like this now and it solved the issue:
[root#xcpserver2 ~]# cat /etc/fstab
LABEL=root-jvgtod / ext3 defaults,noatime 1 1
LABEL=swap-jvgtod swap swap defaults 0 0
LABEL=logs-jvgtod /var/log ext3 defaults,noatime 0 2
#/opt/xensource/packages/iso/XenCenter.iso /var/xen/xc-install iso9660 loop,ro 0 0
I have a temperature sensor, which is connected using an USB-I2C adapter (http://www.robot-electronics.co.uk/htm/usb_i2c_tech.htm)
I attached this device to my linux computer (suse10).
I typed dmesg and saw
usb 3-3: new full speed USB device using ohci_hcd and address 10
usb 3-3: new device found, idVendor=0403, idProduct=6001
usb 3-3: new device strings: Mfr=1, Product=2, SerialNumber=3
usb 3-3: Product: FT232R USB UART
usb 3-3: Manufacturer: FTDI
usb 3-3: SerialNumber: A7007K93
usb 3-3: configuration #1 chosen from 1 choice
ftdi_sio 3-3:1.0: FTDI USB Serial Device converter detected
drivers/usb/serial/ftdi_sio.c: Detected FT232BM
usb 3-3: FTDI USB Serial Device converter now attached to ttyUSB0
But I have no idea how to read the current temperature.
updated 1: Actually the I2C bus can attach up to 127 sensors. But I have no idea how to list the addresses of available sensors.
Can anybody give me some hints? Thanks in advance
Your adapter allows you to send I2C commands over a virtual serial port. A serial port has been created for you. You need to open it and send commands to it. The commands are specific to the device you are connected to. See the example in the link you provided to get an idea.
It is hard to give you correct instructions without a datasheet. Most probably your device will use one byte address and the read procedure is as follows:
[I2C_AD1] [Device I2C address + Read bit] [Device Address register] [Number of bytes to read]
0x55 0xXX 0x00 0x01
You need to send 4 bytes to the serial port. The first one instructs the USB to I2C converter to send a read command. The second one is the address of the device attached to the I2C bus. I2C devices use 7-bit addresses (0-127). Usually these are given with one bit shifted at the left. Therefore you need to scan these addresses (iterate from 0 to 127, shift left one bit, set bit0 to 1):
([0x00 - 0x7F] << 1) | 1
Since we don't have a datasheet I can't tell anything about the last two bytes. You could try to use dummy values. If a device is attached to the scanned I2C address, it should reply with a NACK to an attempt to read a non-existing register. Read commands sent to an I2C address that doesn't correspond to an actual device should be ignored.