Android HAL 分析
2010-05-26 06:40:00 来源:WEB开发网struct hw_device_t** device)
{
struct led_control_device_t *dev;
dev = (struct led_control_device_t *)malloc(sizeof(*dev));
memset(dev, 0, sizeof(*dev));
dev->common.tag = HARDWARE_DEVICE_TAG;
dev->common.version = 0;
dev->common.module = module;
dev->common.close = led_device_close;
dev->set_on = led_on;
dev->set_off = led_off;
*device = &dev->common;
/*
* Initialize Led hardware here.
*/
dev->fd = open(LED_DEVICE, O_RDONLY);
if (dev->fd < 0)
return -1;
led_off(dev, LED_C608);
led_off(dev, LED_C609);
success:
return 0;
}
(2.4)填充具体API操作代码
int led_on(struct led_control_device_t *dev, int32_t led)
{
int fd;
LOGI("LED Stub: set %d on.", led);
fd = dev->fd;
switch (led) {
case LED_C608:
ioctl(fd, 1, &led);
break;
case LED_C609:
ioctl(fd, 1, &led);
break;
default:
return -1;
}
return 0;
}
int led_off(struct led_control_device_t *dev, int32_t led)
{
int fd;
LOGI("LED Stub: set %d off.", led);
fd = dev->fd;
switch (led) {
case LED_C608:
ioctl(fd, 2, &led);
break;
case LED_C609:
ioctl(fd, 2, &led);
break;
default:
return -1;
}
return 0;
}
更多精彩
赞助商链接