平台 MTK6573
Android 振动器系统架构
一、驱动层
Android修改、新增Linux内核文件
/kernel/drivers/staging/android/timed_output.h /kernel/drivers/staging/android/timed_output.c
timed_output.h 定义了timed_output_dev 结构体
- struct timed_output_dev {
- const char *name;
- /* enable the output and set the timer */
- void (*enable)(struct timed_output_dev *sdev, int timeout);
- /* returns the current number of milliseconds remaining on the timer */
- int (*get_time)(struct timed_output_dev *sdev);
- /* private data */
- struct device *dev;
- int index;
- int state;
- };
timed_output.c 实现了该结构体,使用函数timed_output_dev_register实现注册,使用timed_output_dev_unregister实现注销。
- int timed_output_dev_register(struct timed_output_dev *tdev)
- {
- int ret;
- if (!tdev || !tdev->name || !tdev->enable || !tdev->get_time)
- return -EINVAL;
- ret = create_timed_output_class();
- if (ret < 0)
- return ret;
- tdev->index = atomic_inc_return(&device_count);
- tdev->dev = device_create(timed_output_class, NULL,
- MKDEV(0, tdev->index), NULL, tdev->name);
- if (IS_ERR(tdev->dev))
- return PTR_ERR(tdev->dev);
- ret = device_create_file(tdev->dev, &dev_attr_enable);
- if (ret < 0)
- goto err_create_file;
- dev_set_drvdata(tdev->dev, tdev);
- tdev->state = 0;
- return 0;
- err_create_file:
- device_destroy(timed_output_class, MKDEV(0, tdev->index));
- printk(KERN_ERR "timed_output: Failed to register driver %s\n",
- tdev->name);
- return ret;
- }
- EXPORT_SYMBOL_GPL(timed_output_dev_register);
- void timed_output_dev_unregister(struct timed_output_dev *tdev)
- {
- device_remove_file(tdev->dev, &dev_attr_enable);
- device_destroy(timed_output_class, MKDEV(0, tdev->index));
- dev_set_drvdata(tdev->dev, NULL);
- }
- EXPORT_SYMBOL_GPL(timed_output_dev_unregister);
驱动实现移植
以MTK 6573平台为例
./mediatek/platform/mt6573/kernel/drivers/vibrator/vibrator.c
操作设备
首先打开手机调试,连接USB,执行adb shell,进入/sys/devices/timed_output/vibrator/
执行 echo "10000" enable 发现手机在震动
- # echo "10000" enable
- echo "10000" enable
- 10000 enable
执行 cat enable 可以查看当前震动时间剩余数:
- # cat enable
- cat enable
- 0
二、硬件抽象层
Android 封装了对底层驱动的调用,成为硬件抽象层。
/hardware/libhardware_legacy/vibrator/vibrator.c
- int vibrator_on(int timeout_ms)
- {
- /* constant on, up to maximum allowed time */
- return sendit(timeout_ms);
- }
- int vibrator_off()
- {
- return sendit(0);
- }
三、 JNI框架层
Android JNI框架层是方便Java调用C/C++方法。
./frameworks/base/services/jni/com_android_server_VibratorService.cpp
- namespace android
- {
- static void vibratorOn(JNIEnv *env, jobject clazz, jlong timeout_ms)
- {
- // LOGI("vibratorOn\n");
- vibrator_on(timeout_ms);
- }
- static void vibratorOff(JNIEnv *env, jobject clazz)
- {
- // LOGI("vibratorOff\n");
- vibrator_off();
- }
- static JNINativeMethod method_table[] = {
- { "vibratorOn", "(J)V", (void*)vibratorOn },
- { "vibratorOff", "()V", (void*)vibratorOff }
- };
- int register_android_server_VibratorService(JNIEnv *env)
- {
- return jniRegisterNativeMethods(env, "com/android/server/VibratorService",
- method_table, NELEM(method_table));
- }
- };
四、Java应用层
这层包括Java 应用的调用,Android系统服务Java层
./frameworks/base/services/java/com/android/server/VibratorService.java
新闻标题:Android振动器(Vibrator)系统详解
标题网址:http://www.shufengxianlan.com/qtweb/news20/388470.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联