ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

AndroidϵͳHAL²ã¿ª·¢,±àÒë¹ý³Ì(hello)(Ò»)
2014-11-24 07:34:57 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:4´Î
Tags£ºAndroid ϵͳ HAL ¿ª·¢ ±àÒë ¹ý³Ì hello


Ó²¼þÇý¶¯³ÌÐò¿ÉÒÔ¿´×öÊÇÔÚkeinel²ã£¬HAL·â×°ÁËÓ²¼þÇý¶¯£¬È»ºóÔÙ¾­¹ýJNI½Ó¿ÚµÄ·â×°²ÅÄܸøJavaÓ¦ÓóÌÐòµ÷Óá£


HAL²ã½Ó¿Ú·â×°µÄ¾ßÌåÁ÷³ÌÈçÏ£º

1£©ÔÚ../Android-2.3.1/hardware/libhardware/include/hardwareÕâ¸öĿ¼ÏÂÌí¼Óhello.hÍ·Îļþ£¬¾ßÌå¿ÉÒԲ蝹±Ç°Ä¿Â¼ÏµÄoverlay.h£¬

/***************************************************

*android_hal_hello_demo

*hello.h

***************************************************/

#ifndef ANDROID_HELLO_INTERFACE_H

#define ANDROID_HELLO_INTERFACE_H

#include

__BEGIN_DECLS

#define HELLO_HARDWARE_MODULE_ID "hello"

struct hello_module_t {

struct hw_module_t common;

};

struct hello_device_t {

struct hw_device_t common;

int fd;

int (*get_val)(struct hello_device_t *dev,int val);

int (*set_val)(struct hello_device_t *dev,int val);

};

__END_DECLS;

#endif

2£©ÔÚ../Android-2.3.1/hardware/libhardware/modulesÕâ¸öĿ¼ÏÂн¨helloÎļþ¼Ð£¬²¢ÔÚ´ËÎļþ¼ÐÖÐÌí¼Óhello.cºÍAndroid.mkÎļþ£¬¾ßÌå¿ÉÒԲο¼modulesĿ¼ÏÂoverlayÎļþ¼ÐÖеÄÄÚÈÝ¡£

/******************************************************************************

*android_hal_hello_demo

*hello.c

*****************************************************************************/

#include

#include

#include

#include

#include

#include

#define LOG_TAG "hello_stub"

#define DEVICE_NAME "/dev/hello"

#define MODULE_NAME "Hello"

#define MODULE_AUTHOR "pwzhgx@163.com"

static int hello_device_open(const struct hw_module_t *module,const char *name,struct hw_device_t** device);

static int hello_device_close(struct hw_device_t* device);

static int hello_set_val(struct hello_device_t*dev,int val);

static int hello_get_val(struct hello_device_t *dev,int *val);

static struct hw_module_methods_t hello_module_methods = {

open : hello_device_open

};

struct hello_module_t HAL_MODULE_INFO_SYM = {

common: {

tag: HARDWARE_MODULE_TAG,

version_major: 1,

version_minor: 0,

id: HELLO_HARDWARE_MODULE_ID,

name: MODULE_NAME,

author: MODULE_AUTHOR,

methods: &hello_module_methods,

}

};

static int hello_device_open(const struct hw_module_t* module, const char* name, struct hw_device_t** device) {

struct hello_device_t* dev;

dev = (struct hello_device_t*)malloc(sizeof(struct hello_device_t));

if(!dev) {

LOGE("Hello Stub: failed to alloc space");

return -EFAULT;

}

memset(dev, 0, sizeof(struct hello_device_t));

dev->common.tag = HARDWARE_DEVICE_TAG;

dev->common.version = 0;

dev->common.module = (hw_module_t*)module;

dev->common.close = hello_device_close;

dev->set_val = hello_set_val;

dev->get_val = hello_get_val;

if((dev->fd = open(DEVICE_NAME, O_RDWR)) == -1) {

LOGE("Hello Stub: failed to open /dev/hello -- %s.", strerror(errno));free(dev);

return -EFAULT;

}

*device = &(dev->common);

LOGI("Hello Stub: open /dev/hello successfully.");

return 0;

}

static int hello_device_close(struct hw_device_t* device) {

struct hello_device_t* hello_device = (struct hello_device_t*)device;

if(hello_device) {

close(hello_device->fd);

free(hello_device);

}

return 0;

}

static int hello_set_val(struct hello_device_t* dev, int val) {

LOGI("Hello Stub: set value %d to device.", val);

write(dev->fd, &val, sizeof(val));

return 0;

}

static int hello_get_val(struct hello_device_t* dev, int* val) {

if(!val) {

LOGE("Hello Stub: error val pointer");

return -EFAULT;

}

read(dev->fd, val, sizeof(*val));

LOGI("Hello Stub: get value %d from device", *v

Ê×Ò³ ÉÏÒ»Ò³ 1 2 ÏÂÒ»Ò³ βҳ 1/2/2
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºAndroid Gallery 3DЧ¹û ÏÂһƪ£ºAndroid¿ª·¢¹¤¿ØÈí¼þ--À¶ÑÀ¿ØÖÆ

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Linuxϵͳ¼ò½é (2025-12-25 21:55:25)
¡¤Linux°²×°MySQL¹ý³Ì (2025-12-25 21:55:22)
¡¤Linuxϵͳ°²×°½Ì³Ì£¨ (2025-12-25 21:55:20)
¡¤HTTP Åc HTTPS µÄ²î„ (2025-12-25 21:19:45)
¡¤ÍøÕ¾°²È«±ØÐ޿ΣºÍ¼ (2025-12-25 21:19:42)