From b8c62c06de700e3fc5e1e2f2c4972d37d6005ca6 Mon Sep 17 00:00:00 2001 From: "rick.chan" Date: Wed, 10 Jun 2020 15:35:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E9=99=A4=E7=BC=96=E8=AF=91=E9=94=99?= =?UTF-8?q?=E8=AF=AF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rick.chan --- Android/HAL/HalDriver/Android.mk | 4 +++- Android/HAL/HalDriver/demo_hal_driver.c | 32 ++++++++++++++----------- Android/HAL/HalDriver/demo_hal_driver.h | 6 ++--- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Android/HAL/HalDriver/Android.mk b/Android/HAL/HalDriver/Android.mk index 15a13c8..b8ed7e5 100644 --- a/Android/HAL/HalDriver/Android.mk +++ b/Android/HAL/HalDriver/Android.mk @@ -6,7 +6,9 @@ LOCAL_MODULE := miccom.default LOCAL_MODULE_RELATIVE_PATH := $(TARGET_OUT_SHARED_LIBRARIIES)/hw LOCAL_MODULE_TAGS := optional LOCAL_PRELINK_MODULE := false -LOCAL_SHARED_LIBRARIES := liblog +LOCAL_VENDOR_MODULE := true +LOCAL_LDLIBS := -llog +LOCAL_SHARED_LIBRARIES := libhardware libcutils libutils LOCAL_SRC_FILES := miccom.c include $(BUILD_SHARED_LIBRARY) diff --git a/Android/HAL/HalDriver/demo_hal_driver.c b/Android/HAL/HalDriver/demo_hal_driver.c index b2b6f35..79ad1a9 100644 --- a/Android/HAL/HalDriver/demo_hal_driver.c +++ b/Android/HAL/HalDriver/demo_hal_driver.c @@ -10,31 +10,34 @@ */ #define LOG_TAG "MiccomStub" -#include +#include +#include #include #include #include #include +#include +#include #include "miccom.h" #define DEVICE_NAME "/dev/miccom" #define MODULE_NAME "Miccom" -#define MODULE_AUTHOR "cy187lion@sina.com" +#define MODULE_AUTHOR "chenyang@auotai.com" static int miccom_device_open(const struct hw_module_t* module, const char* name, struct hw_device_t** device); static int miccom_device_close(struct hw_device_t* device); static int miccom_set_reg(struct miccom_device_t* dev, char reg, unsigned char num); static int miccom_get_reg(struct miccom_device_t* dev, char* reg, unsigned char num); -static struct hw_modult_methods_t miccom_module_methods = { +static struct hw_module_methods_t miccom_module_methods = { .open = miccom_device_open }; struct miccom_module_t HAL_MODULE_INFO_SYM = { .common = { .tag = HARDWARE_MODULE_TAG, - .version_major: 1, - .version_minor: 0, + .version_major = 1, + .version_minor = 0, .id = MICCOM_HARDWARE_MODULE_ID, .name = MODULE_NAME, .author = MODULE_AUTHOR, @@ -48,26 +51,26 @@ static int miccom_device_open(const struct hw_module_t* module, const char* name dev = (struct hw_device_t*)malloc(sizeof(*dev)); if(!dev) { - LOGE("Miccom stub: failed to alloc space."); + ALOGE("Miccom stub: failed to alloc space."); return -EFAULT; } memset(dev, 0, sizeof(*dev)); dev->common.tag = HARDWARE_DEVICE_TAG; dev->common.version = 0; - dev->common.module = const_cast(module); + dev->common.module = (hw_module_t*)(module); dev->common.close = miccom_device_close; dev->set_reg = miccom_set_reg; dev->get_reg = miccom_get_reg; if(dev->fd = open(DEVICE_NAME, O_RDWR) == -1) { - LOGE("Miccom stub: failed to open "DEVICE_NAME" -- %s.", strerror(errno)); + ALOGE("Miccom stub: failed to open "DEVICE_NAME" -- %s.", strerror(errno)); free(dev); return -EFAULT; } *device = &(dev->common); - LOGI("Miccom stub: Open "DEVICE_NAME" successfully."); + ALOGI("Miccom stub: Open "DEVICE_NAME" successfully."); return 0; } @@ -85,16 +88,17 @@ static int miccom_device_close(struct hw_device_t* device) static int miccom_set_reg(struct miccom_device_t* dev, char reg, unsigned char num) { - LOGI("Miccom stub: set value %d to device reg.", reg); - // write(dev->fd, ®, num); + ALOGI("Miccom stub: set value %d to device reg.", reg); + write(dev->fd, ®, num); + return 0; } static int miccom_get_reg(struct miccom_device_t* dev, char* reg, unsigned char num) { if(!reg) { - LOGE("Miccom stub: error reg pointer."); + ALOGE("Miccom stub: error reg pointer."); } - // read(dev->fd, reg, num); - LOGI("Miccom stub: get value %d from device reg.", *reg); + read(dev->fd, reg, num); + ALOGI("Miccom stub: get value %d from device reg.", *reg); return 0; } diff --git a/Android/HAL/HalDriver/demo_hal_driver.h b/Android/HAL/HalDriver/demo_hal_driver.h index bed75c8..e82dc00 100644 --- a/Android/HAL/HalDriver/demo_hal_driver.h +++ b/Android/HAL/HalDriver/demo_hal_driver.h @@ -18,7 +18,7 @@ __BEGIN_DECLS #define MICCOM_HARDWARE_MODULE_ID "miccom" struct miccom_module_t { - struct hw_modult_t common; + struct hw_module_t common; }; struct miccom_device_t { @@ -26,8 +26,8 @@ struct miccom_device_t { int fd; int (*set_reg)(struct miccom_device_t* dev, char reg, unsigned char num); int (*get_reg)(struct miccom_device_t* dev, char* reg, unsigned char num); -} +}; -_END_DECLS +__END_DECLS #endif // _ANDROID_DEMO_HAL_DRIVER_INTERFACE_H_ \ No newline at end of file