Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing USB driver for Android

I am developing an android application in which I need to connect to a USB device.

I have developed a similar application on windows and I have driver written in c.

I want to develop an USB driver for my android application. I want to know what things are neccessary to develop USB driver for android.

or

Can I reuse the code written in c by using ndk.

Thanks,

like image 504
NK- Avatar asked Oct 05 '12 07:10

NK-


People also ask

How can I get USB driver for Android?

In the Hardware Update wizard, select Browse my computer for driver software and click Next. Click Browse and then locate the USB driver folder. For example, the Google USB Driver is located in android_sdk \extras\google\usb_driver\ . Click Next to install the driver.

What is a USB driver for Android?

The Android USB driver on your machine will make it easy for you to transfer files from an Android phone to your computer. However, you'll need to keep the driver properly updated, which is best achieved through software solutions like Driver Support.


1 Answers

First, Android is actually just Linux, so if you are talking about "writing a USB driver for my Android application" you should rather say "writing a linux USB driver for your specific device".

Next, you will have to access your device in some way. What you will get when you have written the USB driver for linux is probably some file node in /dev/. I'm guessing you want to create a driver for a non-standard USB device (like a mouse/joystick/mass storage) for which Android does not provide a nice JAVA api? In that case you will have to write a native library (probably based on the c code you already have) and compile it with the NDK. The .so file you will get out of it can be packaged in you Android application, which can then use it to talk to your USB device.

So to sum it up:

usb device driver -> create a kernel module or embed a driver into your linux kernel: this is linux usb driver programming stuff, for which you should be able to find enough guides on the web. You should be able to reuse parts of your c code if you really created a windows usb driver.

native wrapper library to access your device (.so file, or .dll if you are used to windows terminology) -> create an NDK project that opens the right device node and correctly reads from/writes to your device.

android app -> include the .so file and access its native (c) methods through jni. You may be able to use tools like javah or swig to generate the jni code from your library's header files.

like image 65
baske Avatar answered Sep 20 '22 04:09

baske