Author Topic: Can libusb library take place with the device driver?(and other confuse of USB)  (Read 13095 times)

Xinxin

  • Member
  • ***
  • Posts: 4
Hello,Jan and hello to everyone here.
I have quite a lot of confuse of USB(under OS Linux)

The things I want to do is that——
Communication via the USB,and not for PC,but a ARM beagleboard.and the OS runs on it is Linux.We want it fast as possible.(Of course,12M,USB2.0 would be very pleased.)


I ve worked for it last three weeks——Yeah,I m newbie.

Firstly,I try to achieve it by DEVICE DRIVER compiled from usb_skeleton.c
I stoped because when I insert the USB device,but the PROBE didnt called.

Later I got to know that a API library called libusb.
Via these API,I ve success to detach the system driver to attach the USB keyboard,so that I can re-claim a new interface...which the reason I thought that why my device modules cant detect the inserted USB device.

en ,however,even though I ve read several pieces of USB protocol ,I didnt know exactly THE PROCESS a USB device working along.
I ve find some example codes as much as I can,include some of yours.But I can't get the useful help till now.Would you please show me the way for me?Thank you!


In my task,one more request is ,I want to make the stand USB device such keyboard,mice and mass storage cannot response to my beagleboard.and I want to make my own specified devices response to my system only.

I ve ask for help in the mailing list of Libusb_Dev.
a kindest Miss(or Madam) called Xiao Fang helps me a lot,and she supposed that as far as for my FINAL TASK(as I described just before.)
She supposed that for this purpose,maybe both libusb and device driver won't be the solve way.

While I believe that a driver must be can,although I haven got success.
But I would like to prefer to chose libusb,if it can replace the device driver.
So I want to ask a question follows: can libusb do things equal to a USB device driver?


Thank you!




Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Device drivers exist to make it easier to communicate. Use the provided driver unless you have a good reason not to.

I have three BeagleBoard libusb examples here:

http://www.janaxelson.com/beagleboard.htm

One uses libusb with hidapi, which is the recommended way to access HID-class devices that have vendor-defined functions. For other HIDs such as keyboards, use the class driver.

What are you trying to accomplish that requires libusb?

Jan
« Last Edit: June 27, 2015, 09:45:27 am by Jan Axelson »

Xinxin

  • Member
  • ***
  • Posts: 4
Thank you for your three examples,Jan.
I will learned it carefully.

1)what I want to do.
en,I want to write a program/device driver for a new USB device made by ourselves,which not compatible with the standard class,such keyboard,mice and mass storage.
our USB device is designed to be transfer data,in and out,and maybe quite a big num of the data.we want it transfer fast.(12M with USB2.0 would be pleased.)
In addition ,I want to make the standard class won't be responsed valid by my beagleboard when we finish the product.

So,I try to make sure that whether a user space program with libusb could generally replace a USB device driver.

2)Why not device driver
Well,I am a newbie to Linux.I have not much knowledge and confidence to do something relation with the kernel,I m afraid that my driver would cause some problem I cannot find at first,but finally crack the whole system.
One more reason I ve write in the first post.Yeah ,I got the problem when the USB insert,but the PROBE just didnt called.
then I got the news about libusb,so I try to use it.

3)about HID
at first,I just though that HID is something like keyboard and mice,it may not suitable for my application,so I just not care much about it.
So,in your net,Lakeview,I found your sample,quite a lot is relation to HID,so I dont pay much attention about it.
(Others like in WIN,because I work for Linux,so not much attention,too.)

However,later,I got a pdf about HID class,I got to know that HID are used widely than I thought,so I would pay more attention about it.

thanks a lot for your reply!

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
If you don't want the OS to assign a class driver to the device, use the vendor-specific class code (FFh) in the device descriptor or an interface descriptor.

HIDs support only control and interrupt transfers. For high throughput, you'll probably want to use bulk.

Jan

Xinxin

  • Member
  • ***
  • Posts: 4
I think I was too lack of experience.I didnt ensure my task,and now I ve know that I didnt need to transfer a large bulk data.just HID 64B maybe OK.and the maxmimum maybe 256B is enough.

But,I got the problem with the function usb_control_msg I use.
I call the function like this:

send_len = usb_control_msg(udev,USB_ENDPOINT_IN+USB_TYPE_CLASS+USB_RECIP_INTERFACE,HID_REPORT_GET,0X300,0,send_data,72,1);

HID_REPORT_GET is a macro defined by myself(I got it via a example online),is equall to 0x09

it return -110 or -32,but I cant get the error code defined in the headfile.
could you show me where to get it?or just tell me what they are mean?Thank you!

and I think even though the function return error,but it did works with the keyboard.
because when I set the TIMEOUT as 0,the program would wait there until I press the keyboard.but for twice press,once didnt effect.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Is usb_control_msg a libusb 0.1 function? Why not use libusb 1.0?

http://www.libusb.org

Jan

Xinxin

  • Member
  • ***
  • Posts: 4
Well,I 've try your HID example code.
It seems better.
I have a little wonder is that:
a USB keyboard work as a USB device.using interrupt ways to transfer.
But whatever I press,it just read in
00h 00h 00h 00h 10h bdh 0ah 40h


I get the example code from here:
http://www.lvr.com/code/generic_hid.c.
It is using libusb-1.0.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Are you sure you're reading from the correct device and interface? A hardware-based protocol analyzer will show what is transferring on the bus. If you don't have a hardware analyzer, you can view host traffic with usbmon and v-usb-analzyer:

http://www.mjmwired.net/kernel/Documentation/usb/usbmon.txt
http://vusb-analyzer.sourceforge.net/

Jan