Interfacing native code to hardware functions

349 views
Skip to first unread message

Schell, Jon

unread,
Nov 17, 2010, 1:01:23 PM11/17/10
to andro...@googlegroups.com
I am trying to create a simple app for testing that will toggle an LED
on the phone as needed. I have the NDK set up and my c code compiles,
but I don't know how to link it to the actual hardware function that
would set the LED. I'm using the actual source code for the hardware,
it's not in an exposed library. Do I need to create a static library
for it to use? Would it maybe be easier to add an android API for this
somehow rather than using the NDK?

For reference, this is Android 2.1 on a Qualcomm MSM7627.

Jonathan


David Turner

unread,
Nov 18, 2010, 10:28:19 AM11/18/10
to andro...@googlegroups.com
Applications typically don't have permissions to access the hardware devices under /dev/<something>.

Usually, this access is reserved for a system daemon / service, which provides an API usable by normal applications and controls what they can do with it.
You should try asking android-porting for more, android-ndk is strictly for developing applications.



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Glenn Kasten

unread,
Nov 18, 2010, 10:31:05 AM11/18/10
to android-ndk
Since this LED hardware capability is apparently not exposed by the
standard Android platform APIs in SDK or NDK, you may want to post
your question to one of the platform groups; see http://source.android.com/community/
Of those listed, android-porting looks like it might be closest.

mic _

unread,
Nov 18, 2010, 11:01:29 AM11/18/10
to andro...@googlegroups.com
Depends on which LED you're talking about. One or more of them might be controllable through /sys/class/leds/ (e.g. echo 255 > /sys/class/leds/red/brightness). But it's not really NDK-related, so you'll have to find more details elsewhere.

/Michael

jon.schell

unread,
Nov 19, 2010, 1:26:21 PM11/19/10
to android-ndk
Ok, I tested this with adb and it is the correct led. So, how would I
set this from my application?

Jonathan
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr­oups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-ndk?hl=en.- Hide quoted text -
>
> - Show quoted text -

Chris Stratton

unread,
Nov 19, 2010, 9:50:49 PM11/19/10
to android-ndk
Barring permissions issues, do what echo does - just open the special
file, write to it, and close it again.

But the adb shell has some permissions to things that applications do
not, so this might not work programmatically on an unrooted device.
Try the same test in connectbot's local terminal shell (which has
ordinary application privileges) for comparison.
> > >http://groups.google.com/group/android-ndk?hl=en.-Hide quoted text -
Reply all
Reply to author
Forward
0 new messages