Hi all,I am planning to run Android on a BBB when the image is released (to the best of my knowledge this is not the case yet). Since I am familiar with Android development this is the approach I would like to take. I am planning to replace the launcher application with my own so that Android will boot in to it automatically. I would like to read various sensors (temp, CO2, air quality etc.), set LEDs and communicate with another ARM chip via SPI or I2C from my app.My question is, from an Android application how can I access the GPIO, PWM, SPI and I2C interfaces on the BBB?Thanks,Ryan R.
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
=========
So let's say you want to access an i2c adapter from a C program. The
first thing to do is "#include <linux/i2c-dev.h>". Please note that
there are two files named "i2c-dev.h" out there, one is distributed
with the Linux kernel and is meant to be included from kernel
driver code, the other one is distributed with i2c-tools and is
meant to be included from user-space programs. You obviously want
the second one here.
Now, you have to decide which adapter you want to access. You should
inspect /sys/class/i2c-dev/ or run "i2cdetect -l" to decide this.
Adapter numbers are assigned somewhat dynamically, so you can not
assume much about them. They can even change from one boot to the next.
Next thing, open the device file, as follows:
int file;
int adapter_nr = 2; /* probably dynamically determined */
char filename[20];
snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
file = open(filename, O_RDWR);
if (file < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
When you have opened the device, you must specify with what device
address you want to communicate:
int addr = 0x40; /* The I2C address */
if (ioctl(file, I2C_SLAVE, addr) < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
Well, you are all set up now. You can now use SMBus commands or plain
I2C to communicate with your device. SMBus commands are preferred if
the device supports them. Both are illustrated below.
END EXCERPT
The sources I downloaded came from here. (if you already have the sources you can ignore this, just putting it out there for reference) Just scroll down the table to the heading "TI Andorid JB 4.1.2 AM335x Sources" and select the first item, TI Android JB 4.1.2 DevKitV4.0.1 AM335x Sources. This link will download a TI-**********.bin to your computer. SImply rename the file and remove the ".bin" suffix from the filename. You can also change the name to something shorter if you don't want to type all that stuff in, I just changed it to "TI-Android". You will have to set the file as executable either by doing
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.
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...
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to a topic in the Google Groups "BeagleBoard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beagleboard/gHR-1fvezjI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
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?
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.
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...
chmod a+x [filename]