一、Android Hal层简介
Android基于Linux内核实现,Linux内核是GPL许可,即对源码的修改都必须开源,而Android是ASL许可,即可以随意使用源码,无需开源,因此将原本位于kernel的硬件驱动逻辑转移到Android平台来,就可以不必开源,从而保护了硬件厂家的利益。因此Android就提供了一套访问硬件抽象层动态库的接口,各厂商在Android的硬件抽象层实现特定硬件的操作细节,并编译成so库,以库的形式提供给用户使用。
1、对应数据结构
hw_module_t 模块描述
hw_module_methods_t 模块方法
hw_device_t 设备描述
typedef struct hw_module_t {
/** tag must be initialized to HARDWARE_MODULE_TAG */
uint32_t tag;
uint16_t version_major;
uint16_t version_minor;
const char *id;
const char *name;
const char *author;
struct hw_module_methods_t* methods;
void* dso;
uint32_t reserved[32-7];
} hw_module_t;
typedef struct hw_module_methods_t {
//硬件模块方法列表的定义,这里只定义了一个open函数
/** Open a specific device */
int (*open)(const struct hw_module_t* module, const char* id,
//注意这个open函数明确指出第三个参数的类型为struct hw_device_t** struct hw_device_t** device);
} hw_module_methods_t;
//每一个设备数据结构的第一个成员函数必须是hw_device_t类型,其次才是各个公共方法和属性



