If I connect an I2C device to one of the available I2C ports (for example, an ADXL345 accelerometer), how would I then access the device from within Linux and/or Android.
For example, mobile phones must use something like an accelerometer to determine the orientation of the phone and then use this information to decide when to rotate the screen – is something like this possible on the iMX6 Rex module? How would Android know that there is an I2C device attached?
the simplest way is to use I2c-tools. There are basic commands to read and write an I2C device. You can find some examples here: http://www.imx6rex.com/software/imx6-rex-basic-hw-verification-tests/#i2c
The proper way is to use a driver. You have three options:
- use a device already supported (recommended) – The best way is to check if other iMX6 boards have the I2C you need (that means, it is probably supported in Linux). Possibly, you may want to run “make menuconfig”, and check what devices are supported. Use one of them.
- modify an existing driver – this may be an option if a very similar device is already supported or if you have a new silicon id
- write the driver by yourself – If you understand how Linux works, you may try to write a driver by yourself. Maybe start here (a nice article about I2C driver): http://www.embedded-bits.co.uk/2009/i2c-in-the-2632-linux-kernel/
- Guest answered 937 days ago
Thank you for your super-quick response.
I don’t know if this is a suitable question to ask but, how would the I2C driver then interface to Android. Is it possible that it can integrate properly into the Android sub-system and through the Android API – i.e. the TYPE_ACCELEROMETER definition?
I guess what I’m asking is, would the Linux system post a “message” or “event” which the Android framework picks up on and decodes as a TYPE_ACCELEROMETER event?
I apologise if this is not a simple question. I’ve done a bit of Googling on this subject but I’m struggling to find answers…
Please login first to submit.