本文主要是介绍Android 振动器系统架构,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
平台 MTK6573
Android 振动器系统架构
- 驱动层
- 硬件抽象层
- JNI框架层
- Java应用层
一、驱动层
Android修改、新增Linux内核文件
- /kernel/drivers/staging/android/timed_output.h
- /kernel/drivers/staging/android/timed_output.c
- 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;
- };
- 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);
- # echo "10000" enable
- echo "10000" enable
- 10000 enable
- # cat enable
- cat enable
- 0
- int vibrator_on(int timeout_ms)
- {
- /* constant on, up to maximum allowed time */
- return sendit(timeout_ms);
- }
- int vibrator_off()
- {
- return sendit(0);
- }
- 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));
- }
- };
这篇关于Android 振动器系统架构的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!