Android 从上到下写一个例子 HAL

Posted we1less

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 从上到下写一个例子 HAL相关的知识,希望对你有一定的参考价值。

本文继上一篇文章继续写代码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))

以上是关于Android 从上到下写一个例子 HAL的主要内容,如果未能解决你的问题,请参考以下文章

Android 从上到下写一个例子 本地服务

Android 从上到下写一个例子

如何在Android中给出从上到下的动画?

Android Camera open 从上到下代码流程

使活动从上到下动画

不分行从上到下打印二叉树