Android from hardware to application: Compile the hardware service at the APP testing framework layer (complete)
Create an Android Application Project: Use the Android plug-in ADT of Eclipse to create an Android project named Gpio. After the project is created, copy the project directory to the packages/apps/folder, and delete the gen folder under the project directory. If you do not delete it, duplicate class errors will occur.
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:
String res/values/strings. xml:
GPIO
Set
Clear
AndroidManifest. xml:
Edit Android. mk in the project directory:
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:
Add Gpio \ After PRODUCT_PACKAGES := \
The compilation project will generate gpio.apk
make TARGET_PRODUCT=am335xevm_sk -j8 OMAPES=4.x
At this step, all preparations are ready. Start to update the file system of the target board am335evm: (host on the left and evm on the 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 that ueventd. rc under rootfs has been added: (Android from hardware to application: Step by Step climb 3 -- Hardware Abstraction Layer access hardware driver mentioned)
/dev/AdrIO 0666 root root
Start, install gpio.apk, and enable GPIO:
Symptom:
Click "Set" button: D1 light on and click "Clear" button: D1 light off
It can be seen that the written APP has successfully operated the AM335 register by calling the hardware service, changed the AM335X_GPIO_LED4 level, and controlled the LED D1 light-off through the ngou MOS device.