Driver development

601 views
Skip to first unread message

NANDAKUMAR S

unread,
Jun 25, 2020, 11:42:13 AM6/25/20
to android-porting
Hi all,

  Iam working on an android aosp project, in which now i want to develop drivers for UART,I2C communication protocols. But iam new to this LINUX and Android platform.
Can anyone suggest me some resources or a procedure on how to learn this.

Dave McLaughlin

unread,
Jun 30, 2020, 10:20:43 AM6/30/20
to android-porting
UART and I2C are simple enough. The underlying Linux drivers should be part of the kernel and you simply open them from /dev in your Android App. The only issue you may have is not having user rights access to them.

What I did was give user access to GPIO, UART, I2C, and SPI from the init.rc and then wrote a JNI to access the /dev or /sys/class/gpio etc. 

This is assuming you are developing the Android OS build yourself. That certainly makes it easier to set up access rights from init.rc.

Check your /dev directory and see if the tty or i2c devices are already present in your build. If so, you just need to check the access rights and write a JNI to use them from an Android App.

Dave...

NANDAKUMAR S

unread,
Jun 30, 2020, 12:31:00 PM6/30/20
to davemcla...@gmail.com, android-porting
Thanks for your reply,

I have tty in /dev directory. I'll check with permissions. 

Can i get any readily available app for testing.


--
--
unsubscribe: android-porti...@googlegroups.com
website: http://groups.google.com/group/android-porting

---
You received this message because you are subscribed to the Google Groups "android-porting" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-porti...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-porting/f6ab2a50-30fc-4dfe-aee1-c21c67bc5cd9o%40googlegroups.com.

Dave McLaughlin

unread,
Jul 1, 2020, 11:03:54 AM7/1/20
to android-porting
Not likely as Android apps tend to work with phones which don't have the need for I2C or UART comms etc.

I wrote a couple of JNI libraries to handle GPIO, I2C and UART, you can find it here. This can be added to your project.


This is just the library for I2C and UART. This is very basic code for the I2C (I omitted the required exception handling)

Open the I2C device

            fileHandle = i2c.open("/dev/i2c-0");

Read I2C

        i2c.read(fileHandle, slaveAddr, buf, 3);

Write I2C

i2c.write(fileHandle, slaveAddr, 0, buf, 1);

Close the device

i2c.close(fileHandle);

Buf is an int array. slaveAddr is the 7 bit address of the device you want to talk to.

Serial Port is pretty much similar. I used this with a Modbus library. You only need to allocate the file handle to the streams for this to work. Search for modbus4j by Serotonin. This works great with Android. 

I hope this helps?

Ignacio Moya

unread,
Sep 15, 2020, 3:39:25 PM9/15/20
to android-porting
Hi, I was trying to change permissions of the i2c files in /dev/i2c-x (x: from 0 to 3) adding the lines "chmod 777 /dev/i2c-x" inside the "on early-boot"  action. But trying to run i2cdetectx from shell still throws "permission denied".

Could someone show me where should I change permissions inside the init.rc file? Or another way of doing the same but not in "init.rc"? I'm using AOSP 9.

Thanks!
This email and any of its attachments may contain privileged and confidential information and are intended only for the review of the party to whom it is addressed. If you are not the intended addressee of this e-mail or his representative, please be aware that any kind of review, publication, reproduction or retransmission of the content of this e-mail is prohibited and may be unlawful. Furthermore, if you have received this email in error, please notify the sender immediately by reply email and then delete this email. Normal e-mails are not protected against access by third parties and consequently their confidentiality may not be assured in certain circumstances. Should any virus enter your systems in connection with this e-mail despite our use of antivirus software, we cannot be held liable for any possible damages.

Ignacio Moya

unread,
Sep 22, 2020, 11:18:20 AM9/22/20
to android-porting
Hi, I managed to solved it setting selinux enforce policy to "permissive". It is possible to do that from adb shell with the commands "su", then "setenforce 0" and then use "getenforce" to see if your change worked. This setting is only valid until reboot.
Reply all
Reply to author
Forward
0 new messages