"Turn" Android (4.2) Sensors learn--g-sensor,gyroscope Drive porting

Source: Internet
Author: User

Original URL: http://blog.csdn.net/nxh_love/article/details/11804841

I am the driver is a little understand, given that the company's current high-powered manpower is not enough, so I can only two eyes a smear the original Android 4.1 on the normal use of the drive full porting to Android 4.2. This document tells the record oneself step by step the transplant process, has been prepared for a rainy day. Before porting, first come to high understanding Android support those sensors, namely sensors kind and function.

Sensors types and functions

From the official Android API you can find the following types of sensor supported by Android:

type description
accelerometer  (acceleration sensing  &NBSP, aka G-sersor, detects the acceleration of an object, uses the two capacitance points configured within the device, and places a conductive and sloshing substance between the capacitance points, changing the voltage between the capacitance points by detecting the movement of the conductive material This calculates the state of the sensor.
 gravity
(Gravity sensor)
aka Gv-sensor .
   gyroscope
  (gyroscope sensor)
also known as gyro-sensor angular velocity, which detects the angular velocity of an object's rotation using an internal vibrating mechanical structure To calculate the angle of movement of the object. Detects the state of the level change, but cannot calculate the intensity of the movement.
    light
(light sensor)
detect the strength of light
Magnetic_fi ELD
(magnetic sensor)
also known as M-sensor.
pressure
(pressure sensor)
returns the current pressure.
PROXIMITY
(distance sensor)
detects the distance between the object and the sensor.
Humidity
(Humidity sensor)
Returns the current humidity
ROTATION
(Direction sensor)
aka O-sensor
Temperature
(Temperature sensor)
Returns the current temperature

The above accelerometer, gravity sensor, gyroscope sensor, and light sensor are the longest sensors in Android. The following is an introduction to the migration of the G-sensor,gyroscope drive.

G-sensor Driver Code

By consulting hardware colleagues, know that our current use of G-sensor is Lsm303d,gyroscope is L3GD2. Next follow these two key grep lookups. Results found the following driver-related files:

[HTML]View Plaincopy
    1. Kernal_path/drivers/misc/lsm303d.c
    2. Kernal_path/drivers/misc/l3gd20_gyr.c
    3. Kernal_path/include/linux/i2c/l3gd20.h
    4. Kernal/include/linux/input/lsm303d.h

Limited to the company responsible attitude, give the relative file path. Next, be sure to modify the makefile:

Kernal_path/drivers/misc/makefile:

[HTML]View Plaincopy
    1. obj-$ (config_sensors_lsm303d) + = LSM303D.O
    2. obj-$ (config_st_l3gd20_gyr) + = L3GD20_GYR.O

Modify Kconfig:

Kernal_path/drivers/misc/kconfig:

[HTML]View Plaincopy
  1. Config sensors_lsm303d
  2. TriState "LSM303 Sensor driver"
  3. Depends on i2c=y
  4. Help
  5. Say Yes the sensor
  6. Config St_l3gd20_gyr
  7. TriState "L3gd20_gyr Gyroscope sensor support"
  8. Depends on i2c=y
  9. Help
  10. If you say yes, here's get support for ST ' s
  11. Gyroscope sensors L3gd20_gyr.

About Makefile in Config_sensors_lsm303d,config_st_l3gd20_gyr it is compiled to generate. CONFIG read. For Makefile,kconfig,.config see Kconfig,makefile and. config. Locate the original configuration file defconfig. config generated by the compilation.
Modify Defconfig:

Kernal_path/configs/xxx_defconfig:

[HTML]View Plaincopy
    1. config_sensors_lsm303d=y
    2. config_st_l3gd20_gyr=y

Register I²C:

Above Kconfig mentioned depends on I²c =y, since it relies on the i²c, it is sure to let i²c know its existence, now to the I²C register LSM303D,L3GD2 information.

[HTML]View Plaincopy
    1. #ifdef config_sensors_lsm303d
    2. {
    3. I2c_board_info ("lsm303d", 0x1d),
    4. },
    5. #endif
    6. #ifdef Config_st_l3gd20_gyr
    7. {
    8. I2c_board_info ("L3gd20_gyr", 0x6a),
    9. },
    10. #endif

The 0x1d,0x6a in this is the node registered in I²c. In this regard, we are in the following detail (note 1-1).

G-sensor HAL

This section is directly from android4.1 copy to Android 4.2, where the path is placed in hardware/sensors/st_lsm303d/, View its makefile found it finally compiles a sensor.so file that exists in SYSTEM/LIB/HW for Upper bar. To include this sensor.so in an IMG file, you need to

[HTML]View Plaincopy
    1. Product_packages + = \
    2. Sensors.amlogic

The following two files are presented here:

Hardware/sensors/st_lsm303d/accsensor.cpp

Hardware/sensors/st_lsm303d/gyrosensor.cpp

After opening, there is a macro definition:

[HTML]View Plaincopy
    1. <pre name="code" class="html"> #define INPUT_SYSFS_PATH_ACC "/sys/devices/i2c-1/ 1-001d/accelerometer/"
    2. #define Input_sysfs_path_gyro "/sys/devices/i2c-1/1-006a/"</pre>

There are 1-001d,1-006a here, and we are following in detail on this point (note 1-2).
Sensor permissions

From the above two macro definitions can be seen, it to access the sys/devices/i2c-1/file, then you need to give it a permission. To change the permissions of these two files in init.rc:

[HTML]View Plaincopy
  1. chmod 0666/dev/mpu
  2. chmod 0666/DEV/MPUIRQ
  3. chmod 0666/DEV/TIMERIRQ
  4. Chown System System/sys/devices/i2c-1/1-001d/magnetometer/pollrate_us
  5. Chown System System/sys/devices/i2c-1/1-001d/accelerometer/enable_device
  6. Chown System System/sys/devices/i2c-1/1-001d/accelerometer/pollrate_us
  7. Chown System System/sys/devices/i2c-1/1-001d/magnetometer/enable_device
  8. Chown System System/sys/devices/i2c-1/1-006a/pollrate_ms
  9. Chown System System/sys/devices/i2c-1/1-006a/enable_device
  10. Chown System System/sys/devices/i2c-1/1-006a/range
  11. Chown System system/sys/devices/i2c-1/1-006a/enable_polling

1-001D,1-006A is also mentioned here, which is followed in detail (note 1-3).

During the Android CTS test, there will be a features project for the sensor. You also need to configure some files:

[HTML]View Plaincopy
    1. Product_copy_files + = \
    2. frameworks/native/data/etc/android.hardware.sensor.accelerometer.xml:system/etc/permissions/ Android.hardware.sensor.accelerometer.xml
    3. frameworks/native/data/etc/android.hardware.sensor.compass.xml:system/etc/permissions/ Android.hardware.sensor.compass.xml \
    4. frameworks/native/data/etc/android.hardware.sensor.gyroscope.xml:system/etc/permissions/ Android.hardware.sensor.gyroscope.xml \

It is not only the Android CTS feature, but also determines whether apps that run on this platform have these related permissions. Open File Android.hardware.sensor.accelerometer.xml:

[HTML]View Plaincopy
    1. <!--Feature for devices with an accelerometer sensor. -
    2. <permissions>
    3. <feature name="Android.hardware.sensor.accelerometer" />
    4. </Permissions>
Note 1-1, note 1-2, note 1-3

The 1-001d,1-006a of these three places must be the same. Otherwise the sensor does not function. As for the 1-001d,1-006a this value is how to come, for the moment do not know.

"Turn" Android (4.2) Sensors learn--g-sensor,gyroscope Drive porting

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.