本文繼上一篇文章繼續寫代碼https://blog.csdn.net/we1less/article/details/120147281
hal層代碼放置路徑 hardware/libhardware/modules/godvled
mk檔案
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:=godvled.default
#不指定預設 system/lib
#LOCAL_MODULE_PATH:=$(LOCAL_PATH) 目前路徑下
#system/lib/hw
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES:=hal.c
LOCAL_SHARED_LIBRARIES:= liblog
#eng 工程版 user使用者版
LOCAL_MODULE_TAGS := optional eng
include $(BUILD_SHARED_LIBRARY)
C檔案
#define LOG_TAG "godv"
#include <cutils/log.h>
#include <hardware/hardware.h>
#include "hal.h"
int led_hal_open()
{
ALOGI("this is led_hal_open");
return 0;
}
int led_hal_ioctl(int which,int status)
{
ALOGI("this is led_hal_ioctl");
ALOGI("which = %d, status = %d",which,status);
return 0;
}
int led_hal_close()
{
ALOGI("this is led_hal_close");
return 0;
}
struct led_device_t led_device = {
.commn = {},
.hal_open = led_hal_open,
.hal_ioctl = led_hal_ioctl,
.hal_close = led_hal_close,
};
int led_open(const struct hw_module_t* module, const char* id,
struct hw_device_t** device)
{
*device = (struct hw_device_t *)&led_device;
return 0;
}
hw_module_methods_t method = {
.open = led_open,
};
hw_module_t HMI={
.id = "godvled",
.methods = &method,
};
h檔案
#ifndef __HAL_H__
#define __HAL_H__
struct led_device_t
{
hw_device_t commn;
int (*hal_open)();
int (*hal_ioctl)(int which,int status);
int (*hal_close)();
};
#endif
修改mk檔案 使之編譯自己的 ledhal 路徑hardware/libhardware/modules/Android.mk
hardware_modules := \
audio_remote_submix \
...
godvled
include $(call all-named-subdir-makefiles,$(hardware_modules))