How to Use vibrator to transplant android4.0.3 source code with cainiao

Source: Internet
Author: User


Mobile phones have the effect of vibration. The day before yesterday, the flying knife removed a vibrator from the mobile phone, and asked me to tune it next week. Yesterday, I came to the company for a test and got it done. Let's talk about the process below.


In fact, the underlying driver has been completed in Android, that is, timed_gpio, which combines the timing function with the gpio function. vibration is a small DC motor, when the gpio port is high, the motor turns. When the gpio port is low, the motor does not turn, and time is the time for controlling the conversion, that is, the time when the gpio port is at a high level.


The specific code is in/Drivers/staging/Android/timed_gpio.c.


Add platform device to platform. C on the platform.

 

Static struct timed_gpio vibrator = {. name = "vibrator ",. gpio = 61, // corresponding to the gpio number of your own platform. max_timeout = 100000 ,. active_low = 0 ;}; static struct timed_gpio_platform_data timed_gpio_data = {. num_gpios = 1 ,. gpios = & vibrator,}; static struct platform_device my_timed_gpio = {. name = "timed-gpio ",. id =-1 ,. dev = {. platform_data = & timed_gpio_data ,},};

 

In make menuconfig, select related options in Android under staging under device.

 


Then you can run the kernel. After the kernel runs, you can test it.


Because the timed gpio driver creates a child for each device in the/sys/class/timed_output/directory

The enable file in the sub-directory of the device controls the Time of the device. Because the name in platform is called vibrator,

Therefore, use the following command to test:

echo 10000 > /sys/class/timed_output/vibrator/enable 

Then you can see that the vibrator is being switched, or you can use an oscilloscope or A multimeter to verify it.

Then you can

cat /sys/class/timed_output/vibrator/enable

It is found that the value of enable is decreasing until it is 0.

Okay, the underlying driver is good, so the android upper layer is much easier to handle, because the android upper layer has little to do with the platform, and few things need to be changed.

For the Android hardware abstraction layer, go to the hardware/libhardware_legacy/include/hardware_legacy/vibrator directory.

 

#include 

 

See it.

#define THE_DEVICE "/sys/class/timed_output/vibrator/enable"

That is where we want to operate the underlying driver. As long as this is matched with the driver, the rest will be done.

In fact, she also writes data here, so the Java layer of Android doesn't care about her anymore. Now, you can set an alarm clock after Android is started to test the function. We can see that android vibrator has been successfully transplanted.

I suddenly discovered something that I thought was rare and hard to understand. After a while, I suddenly realized it. Learning is a long process. It is a process of accumulating knowledge slowly. In one breath, it is impossible to eat fat people.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.