Search Unity

USB driver programming

Discussion in 'General Discussion' started by VeganApps, Dec 18, 2007.

  1. VeganApps

    VeganApps

    Joined:
    Jun 30, 2006
    Posts:
    263
    Hello,

    I would like to use some USB devices which don't have Mac OS X drivers available yet.
    Examples for these devices are:
    -USB relay module
    -USB compass (tilt) sensor

    I plan to use xCode and Objective-C to write the driver.. though I never use it.

    Do you know some good tutorials or resources about Mac OS X USB driver programming ?
    What do you think I should take care of ?

    Any hints are welcome.. :)
     
  2. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
    Hi!

    You can avoid writing low-level kernel driver if you use "libusb" C-library:

    http://libusb.sourceforge.net/

    (precompiled for OS X: http://www.ellert.se/twain-sane/)

    I've been using it with some projects in Mac, Windows and Linux environments. Using it, you can do the basic USB transfers like bulk and interrupt transfers in user space. Of course you should know details for transfer, what pipe(s) it uses and how the data is presented (i.e. what is the "protocol").If you don't, reverse engineering the protocol is time consuming and would need USB protocol sniffer program.

    Good link to start your journey in the world of USB:

    http://www.lvr.com/usb.htm


    If your device is a HID (Human Interface Device) type (like Apple Remote, mouse, keyboard, joystics etc.) it is possible to access the device directly without libusb. Good references can be found in Apple Developers site (search "HIDTestTool" and "HID Manager")

    In both cases it is possible to compile your own dynamic library (.dll in Win and .dynlib in Mac) and have C# access to it from Unity (Pro required).

    BR,
    Juha