3, HAL接口层
所有的HAL moudle需要涉及如下三个关键结构体:
struct hw_module_t;
struct hw_module_methods_t;
struct hw_device_t;
用户一般需要基于上面这些结构体设计如下两个结构体:
struct xxx_module_t {
struct hw_module_t common;
.
};
自定义一个模块结构,HAL 规定不能直接使用hw_module_t结构,因此需要做这么一个继承。
struct xxx_device_t {
struct hw_device_t common;
/* attributes */
int fd;
/* supporting control APIs go here */
int (*xxx)(struct xxx_device_t *dev, int32_t x);
int (*yyy)(struct xxx_device_t *dev, int32_t x);
};
自定义一个模块硬件接口,包含hw_device_t和支持的API操作,fd 表示设备文件描述符;
用户还需要定一个如下的MODULE_ID,HAL层可以根据这个ID 找到并加载这个HAL模块 ;
#define LED_HARDWARE_MODULE_ID "xxx"
最后用户需要定义一个如下的xxx_module_t变量:
static struct hw_module_methods_t xxx_module_methods =