Create Android Application project: Create Android project using Eclipse's Android plugin ADT, project name Gpio, copy the project catalog to the packages/apps/folder after creation is complete, and delete the Gen folder under the project directory, without deleting the words will cause the class to repeat the error.
Src/com/android/gpio/gpio.java:
Package Com.android.gpio; Import COM.ANDROID.GPIO.R; Import android.app.Activity; Import Android.os.ServiceManager; Import Android.os.Bundle; Import Android.os.IGpioService; Import android.os.RemoteException; Import Android.util.Log; Import Android.view.View; Import Android.view.View.OnClickListener; Import Android.widget.Button; public class Gpio extends Activity implements Onclicklistener {private final static String Log_tag = "Com.android.Gpio"; Private Igpioservice gpioservice = null; Private Button Setbutton = null; Private Button Clearbutton = null; /** called when the activity is first created. */@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); Gpioservice = IGpioService.Stub.asInterface (Servicemanager.getservice ("Gpio")); Setbutton = (Button) Findviewbyid (R.id.button_set); Clearbutton = (Button) Findviewbyid (r.id.button_clear); Setbutton.setonclicklistener (this); ClearbuttOn.setonclicklistener (this); } @Override public void OnClick (View v) {if (V.equals (Setbutton)) {try{int val= ' 1 '; Gpioservice.setval (val);} catch (RemoteException e) {LOG.E (Log_tag, "setting value");}} else if (v.equals (Clearbutton)) {try{int val= ' 0 '; Gpioservice.setval (Val); } catch (RemoteException e) {log.e (Log_tag, "setting value"); } } } }
Layout res/layout/main.xml:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/ Res/android " android:orientation=" vertical " android:layout_width=" fill_parent " android:layout_ height= "Fill_parent" > <button android:id= "@+id/button_clear" android:layout_width= "Match_ Parent " android:layout_height=" wrap_content " android:text=" @string/clear " android:textstyle=" bold " android:layout_margintop= "140DP"/> <button android:id= "@+id/button_set" android: Layout_width= "Match_parent" android:layout_height= "wrap_content" android:text= "@string/set" Android:textstyle= "Bold" android:layout_margintop= "0DP"/></linearlayout>
String Res/values/strings.xml:
<?xml version= "1.0" encoding= "Utf-8"?> <resources> <string name= "App_name" >gpio</ string> <string name= "set" >Set</string> <string name= "Clear" >Clear</string> </resources>
Androidmanifest.xml:
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android= "http://schemas.android.com/apk/res/ Android " package=" Com.android.gpio " android:versioncode=" 1 " android:versionname=" 1.0 "> < Application android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" > <activity android: Name= ". Gpio " android:label=" @string/app_name "> <intent-filter> <action android:name=" Android.intent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filter> </activity> </application> </manifest>
Edit project directory under Android.mk:
Local_path:= $ (call My-dir) include $ (clear_vars) Local_module_tags: = Optionallocal_src_files: = $ (call All-subdir-java-files) Local_package_name: = gpiolocal_certificate: = Platforminclude $ (BUILD_PACKAGE) include $ (call all-makefiles-under,$ (Local_path))
Edit build/target/product/generic_no_telephony.mk:
In product_packages: = \ after adding GPIO \
Compiling the project will generate gpio.apk
In this step, everything is ready to start updating the filesystem of the target board AM335EVM: (left host, EVM right)
out/target/product/am335xevm_sk/system/app/gpio.apk ==> rootfs/out/target/product/am335xevm_sk/ System/framework/services.jar ==> rootfs/system/framework/out/target/product/am335xevm_sk/system/ Framework/framework.jar ==> rootfs/system/framework/out/target/product/am335xevm_sk/obj/lib/ libandroid_servers.so ==> rootfs/system/lib/out/target/product/am335xevm_sk/obj/lib/gpio.default.so ==> rootfs/system/lib/hw/
Make sure the Rootfs under Ueventd.rc has been added: (Android from hardware to app: Step up 3--Hardware abstraction layer access hardware driver mentioned)
/dev/adrio 0666 root root
Start, install gpio.apk, open Gpio:
Phenomenon:
Click on the "Set" button: D1 light Click on the "Clear" button: D1 light off
It can be seen that the written app has successfully operated the AM335 register by invoking the hardware service, changing the am335x_gpio_led4 level, and controlling the light-off of the LED D1 through n-Groove MOS devices.
Android from hardware to application: Step by Step 6--write app test framework layer Hardware service (end)