Using SPI/PWM/I2C/GPIO with Android on BBB

Well, all the kernel drivers are there…have you downloaded the source? You can look in /kernel/drivers/ and find directories for SPI, GPIO, PWM, I2C, etc. It would appear that…aha! If you look in /kernel/Documentation/, i think you will find the information you are looking for. Below is an excerpt from /kernel/Documentation/i2c/dev-interface:

C example

Thanks bmfc187 for your in depth response. It was very helpful. Since I am a bit new to this, I know Android apps are written in JAVA and the code you posted is for C. Does that mean I need to use the Android NDK to access the SPI bus?

Not necessarily. The code snippet i posted is an EXAMPLE of how you would access the functionality of the driver from within a C program. These instructions are from the Linux kernel source documentation, and so they do not take into account that you are programming for Android. This is why the example is given in C and not Java. So since, presumably, you would be writing an android app to interface with the kernel driver, you would be writing the equivalent functionality in Java. If you WANT to use C/C++, then you CAN use the NDK and write your code in C/C++. But you don’t HAVE to.

I only have a minute or two for a quick response, so I’m afraid that I can’t go super in-depth with what you need to do. For accessing device drivers under Android, you’ll have a native code component that will interface with the driver by opening the driver device file in the fileystem and then interacting with it via ioctl() calls. bmfc187 explained this part. This native component will then be called from your app’s Java code via JNI. Take a look at the following to get an idea of what I mean:


Accoding to your guidelines i downloaded the source from following webpage TI_Android_DevKit TI_Android_JB_4_2_2_DevKit_4_1_1 -

and downloaded source link from there

the source successfully gets executed and a directory is created in same folder.

chmod a+x [filename]


in a terminal, or by right-clicking on the file in nautilus and going to properties>permissions> and check “allow executing fils as program”. Then open up a terminal, and cd to the directory you saved the file to, and type in the name of the file to execute it. This will bring up a user agreement, you must scroll to the bottom by pressing enter to scroll to the next line, then type “I ACCEPT” at the end. Careful, if you scroll too fast, you will be pressing enter when the “I ACCEPT” prompt comes up and the terminal will exit without doing anything. After you type “I ACCEPT” and press enter, the downloader will start and you will find your source directory in the same directory you downloaded your file to.

But when i open the created folder its empty so I am unable to navigate to th said folder. I am working on beaglebone and will be using SPI interface. I will be workin on android.

After you have the source navigate to /kernel/Documentation/ and you will see directories for ACPI, SPI, I2C, etc, (I dont see directories for PWM or GPIO but there is a gpio.txt and pwm.txt that seem to have the information for those interfaces, respectively). For SPI the file you want appears to be /kernel/Documentation/spi/spi-summary.

hope this helps…

Please do provide a feedback on the same I have attached the image of the open directory below