Android 從硬體到應用: 編寫APP測試架構層硬體服務(完)

來源:互聯網
上載者:User

Android 從硬體到應用: 編寫APP測試架構層硬體服務(完)

建立Android Application工程:使用Eclipse的Android外掛程式ADT建立Android工程,工程名稱為Gpio,建立完成後將工程目錄拷貝到packages/apps/檔案夾下,並刪除工程目錄下的gen檔案夾,不刪除的話會造成類重複的錯誤。

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");   }   }  }  }  
布局res/layout/main.xml:

 

 

  
字串res/values/strings.xml:

 

 

       GPIO     Set     Clear    
AndroidManifest.xml:

 

 

                                                                           
編輯工程目錄下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))
編輯build/target/product/generic_no_telephony.mk:

 

在PRODUCT_PACKAGES := \ 後加入Gpio \

編譯工程會產生Gpio.apk

 

make TARGET_PRODUCT=am335xevm_sk -j8 OMAPES=4.x 
到這一步一切準備工作都已就緒,開始更新目標板am335evm的檔案系統:(左為host,右為evm)

 

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/

確保rootfs下 ueventd.rc 已經添加:(Android 從硬體到應用:一步一步向上爬 3 -- 硬體抽象層訪問硬體驅動 提到)

 

/dev/AdrIO                0666   root       root
啟動,安裝Gpio.apk,開啟GPIO:

 

現象:

點擊"Set"按鈕:     D1燈亮    點擊"Clear"按鈕:   D1燈滅

可見編寫的APP通過調用硬體服務已經成功操作了AM335寄存器,改變AM335X_GPIO_LED4的電平,通過N溝MOS器件控制LED D1的亮滅。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.