-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9cd75d
commit 73ee3c8
Showing
6 changed files
with
207 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright (C) 2012 The Android Open Source Project | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
LOCAL_PATH := $(call my-dir) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_MODULE := led.default | ||
|
||
# HAL module implementation stored in | ||
# hw/<VIBRATOR_HARDWARE_MODULE_ID>.default.so | ||
LOCAL_MODULE_RELATIVE_PATH := hw | ||
LOCAL_C_INCLUDES := hardware/libhardware | ||
LOCAL_SRC_FILES := led_hal.c | ||
LOCAL_SHARED_LIBRARIES := liblog | ||
LOCAL_MODULE_TAGS := eng | ||
|
||
include $(BUILD_SHARED_LIBRARY) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
#define LOG_TAG "LedHal" | ||
|
||
|
||
/* 1. 实现一个名为HMI的hw_module_t结构体 */ | ||
|
||
/* 2. 实现一个open函数, 它返回led_device_t结构体 */ | ||
|
||
/* 3. 实现led_device_t结构体 */ | ||
|
||
/* 参考 hardware\libhardware\modules\vibrator\vibrator.c | ||
*/ | ||
|
||
#include <hardware/vibrator.h> | ||
#include <hardware/hardware.h> | ||
|
||
#include <cutils/log.h> | ||
|
||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <errno.h> | ||
|
||
#include <hardware/led_hal.h> | ||
|
||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <sys/ioctl.h> | ||
#include <utils/Log.h> | ||
|
||
|
||
static int fd; | ||
|
||
|
||
/** Close this device */ | ||
static int led_close(struct hw_device_t* device) | ||
{ | ||
close(fd); | ||
return 0; | ||
} | ||
|
||
static int led_open(struct led_device_t* dev) | ||
{ | ||
fd = open("/dev/leds", O_RDWR); | ||
ALOGI("led_open : %d", fd); | ||
if (fd >= 0) | ||
return 0; | ||
else | ||
return -1; | ||
} | ||
|
||
static int led_ctrl(struct led_device_t* dev, int which, int status) | ||
{ | ||
int ret = ioctl(fd, status, which); | ||
ALOGI("led_ctrl : %d, %d, %d", which, status, ret); | ||
return ret; | ||
} | ||
|
||
|
||
|
||
|
||
static struct led_device_t led_dev = { | ||
.common = { | ||
.close = led_close, | ||
}, | ||
.led_open = led_open, | ||
.led_ctrl = led_ctrl, | ||
}; | ||
|
||
static int led_device_open(const struct hw_module_t* module, const char* id, | ||
struct hw_device_t** device) | ||
{ | ||
*device = &led_dev; | ||
return 0; | ||
} | ||
|
||
|
||
static struct hw_module_methods_t led_module_methods = { | ||
.open = led_device_open, | ||
}; | ||
|
||
struct hw_module_t HAL_MODULE_INFO_SYM = { | ||
.id = "led", | ||
.methods = &led_module_methods, | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
|
||
#ifndef ANDROID_LED_INTERFACE_H | ||
#define ANDROID_LED_INTERFACE_H | ||
|
||
#include <stdint.h> | ||
#include <sys/cdefs.h> | ||
#include <sys/types.h> | ||
|
||
#include <hardware/hardware.h> | ||
|
||
__BEGIN_DECLS | ||
|
||
struct led_device_t { | ||
struct hw_device_t common; | ||
|
||
int (*led_open)(struct led_device_t* dev); | ||
int (*led_ctrl)(struct led_device_t* dev, int which, int status); | ||
}; | ||
|
||
|
||
__END_DECLS | ||
|
||
#endif // ANDROID_LED_INTERFACE_H | ||
|
||
|
||
|