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))

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值