Gyros landscape axle inverted

1,075 views
Skip to first unread message

Pajn

unread,
Jan 25, 2011, 11:41:05 AM1/25/11
to android-porting
I'm porting 2.1 to my 1.5 device and when I copied the gyro driver
from 1.5 to 2.1 it works somewhat.
Portrait (normal + upside down) is correct but in landscape it's
always upside down (if I turn the device clockwise it will turn the
picture counter clockwise and vise versa)

Is it possible to fix this without rewriting the driver?

Chinmay S

unread,
Jan 25, 2011, 10:54:32 PM1/25/11
to pie.o...@gmail.com, android-porting
Hi,

Looks like you are referring to the auto-rotate feature of android.

It is dependent on the accelerometer values. (NOT gyroscope).

As it so very often happens, the accelerometer-IC is mounted in
different position/orientation on different devices.
This introduces the need to remap the axes.

You can download a sensor test app (which reports the sensor data values)
http://www.appbrain.com/app/sensor-test/ctsr.android.SensorTest
and then rotate the device in different directions and observe the Accel X Y Z values.

Then comparing the observed behavior with the expected one in the Accel examples section below,
http://developer.android.com/reference/android/hardware/SensorEvent.html
should give you a good idea as to the change required.

According to your description, the Y axes values are as expected but X seems to be inverted.
So, you will have to report accel.X = -accel.X in your sensor data-path.

This can be done either in the Kernel-driver or in the Sensor-HAL in android (data_poll in sensors.c)


Regards
CVS

Pajn

unread,
Jan 26, 2011, 9:27:24 AM1/26/11
to android-porting
Thanks.
You'r right, it's probably a accelerometer (But Quick System Info
reported it as a gyro)

From Sensor test:
Portrait
X:~12
Y:~0.5
Landscape CCW:
X:~-0.5
Y:~12
Landscape CW:
X:~-0.5
Y:~-11

For me it looks like it's Y that is inverted?
Is it possible to build just sensors.c and include it as a module or
something?

On Jan 26, 4:54 am, Chinmay S <cvs...@gmail.com> wrote:
> Hi,
>
> Looks like you are referring to the auto-rotate feature of android.
>
> It is dependent on the accelerometer values. (NOT gyroscope).
>
> As it so very often happens, the accelerometer-IC is mounted in
> different position/orientation on different devices.
> This introduces the need to remap the axes.
>
> You can download a sensor test app (which reports the sensor data values)http://www.appbrain.com/app/sensor-test/ctsr.android.SensorTest
> and then rotate the device in different directions and observe the Accel X Y
> Z values.
>
> Then comparing the observed behavior with the expected one in the Accel
> examples section below,http://developer.android.com/reference/android/hardware/SensorEvent.html

Chinmay S

unread,
Jan 26, 2011, 9:36:27 AM1/26/11
to pie.o...@gmail.com, android-porting
Hi,

To quickly build just the sensors.c, you can run the mm command in the sensors directory.

The target executable (sensors.<product-name>.so) in the out directory then
needs to be pushed onto the device at the path
/system/lib/hw/sensors.<product-name>.so and device rebooted once.

But, you will still need the complete Android source code for this.

Regards
CVS

Pajn

unread,
Jan 26, 2011, 2:05:45 PM1/26/11
to android-porting
Sorry for beeing noobish.
I have no sensors.c in the eclair source?
Some more information:
The sensor is called gs_mma7660 and it's a rockchip platform.
The file from 1.5 is called sensors.rk28board.so

On Jan 26, 3:36 pm, Chinmay S <cvs...@gmail.com> wrote:
> Hi,
>
> To quickly build just the *sensors.c*, you can run the *mm* command in the
> sensors directory.
>
> The target executable (sensors.<product-name>.so) in the *out* directory
> then
> needs to be pushed onto the device at the path
> */system/lib/hw/sensors.<product-name>.so* and device rebooted once.

Chinmay S

unread,
Jan 26, 2011, 2:21:59 PM1/26/11
to pie.o...@gmail.com, android-porting
Hi,

If the file sensors.rk28board.so is generated then it indicates that the sensors-HAL exists.

The common implementation of the sensor-HAL (before and until FroYo) is using a single sensors.c file.

Most of the times it can be found in one of these directories:
- android-root/device/<vendor-name>/<product-name>
- android-root/vendor/<product-name>
- android-root/hardware/sensors/

One sure-shot way to determine where the file exists is to grep for the keyword "sensors".
since the library sensors.rk28board.so is being generated, an Android.mk file MUST refer to it.

Grep-ing for "sensors" will show you that file and
the sensor HAL implementation will exist in that directory.

Since you are working on eclair code-base,
the sensor-HAL implementation will contain a data_poll function.

You can modify the ACCEL values (swap/calibrate axes) in data_poll function accordingly.
Also, mma7660 is a standard 3-axis accelerometer and should be fine for use in android.

regards
CVS

Pajn

unread,
Jan 26, 2011, 2:38:42 PM1/26/11
to android-porting
The problem it that it won't generate a sensors.rk28board.so I stole
it from 1.5 wich the device comes with.
And a search for sensors don't give anything related :(

On Jan 26, 8:21 pm, Chinmay S <cvs...@gmail.com> wrote:
> Hi,
>
> If the file *sensors.rk28board.so* is generated then it indicates that the
> sensors-HAL exists.
>
> The common implementation of the sensor-HAL (before and until FroYo) is
> using a single sensors.c file.
>
> Most of the times it can be found in one of these directories:
> - android-root/device/<vendor-name>/<product-name>
> - android-root/vendor/<product-name>
> - android-root/hardware/sensors/
>
> One sure-shot way to determine where the file exists is to grep for the
> keyword "sensors".
> since the library *sensors.rk28board.so* is being generated, an Android.mk

Chinmay S

unread,
Jan 26, 2011, 2:46:33 PM1/26/11
to pie.o...@gmail.com, android-porting
Hi,

Just a note: The sensor-HAL is NOT part of the default android-source.
It is left to the vendor to implement the necessary functionality of the sensor-HAL.

The interfaces, which the sensor-HAL needs to implement,
are defined in android-root/hardware/libhardware/include/sensors.h

If you find that your new code does NOT contain the sensor HAL, then you can
[1] Integrate it from old codebase into new codebase.
[2] Implement it yourself from scratch.

In case you do not have access to the original codebase,
You might find this a good reference to start with:
http://android.git.kernel.org/?p=device/htc/passion-common.git;a=tree;f=libsensors;

Alternately, if you have access to the Kernel code,
then you might want to put in a hack in the mma7660-accel Kernel-driver itself.

Just invert the value (y = -y) of one of the axis (as reqd.) before reporting it to the userspace.
This should fix the inverted-rotation issue in landscape-mode on your device.

Regards
CVS

Pajn

unread,
Jan 26, 2011, 4:21:00 PM1/26/11
to android-porting
Thank you very mutch! Will have to read more to be able to fix this,
but now I now what it is about.
I have kernelsource for the Archos tablet which is built on the same
platform, but I guess it's easier to implement sensor HAL from scratch
than get the kernel and all it's drivers to work.

On Jan 26, 8:46 pm, Chinmay S <cvs...@gmail.com> wrote:
> Hi,
>
> *Just a note:* The sensor-HAL is NOT part of the default android-source.
> It is left to the vendor to implement the necessary functionality of the
> sensor-HAL.
>
> The interfaces, which the sensor-HAL needs to implement,
> are defined in *android-root/hardware/libhardware/include/sensors.h
> **
> *If you find that your new code does NOT contain the sensor HAL, then you
> can
> [1] Integrate it from old codebase into new codebase.
>  [2] Implement it yourself from scratch.
>
> In case you do not have access to the original codebase,
> You might find this a good reference to start with:http://android.git.kernel.org/?p=device/htc/passion-common.git;a=tree...
> *
> *Alternately, if you have access to the Kernel code,
> then you might want to put in a hack in the mma7660-accel Kernel-driver
> itself.
>
> Just invert the value (y = -y) of one of the axis (as reqd.) before
> reporting it to the userspace.
> This should fix the inverted-rotation issue in landscape-mode on your
> device.
>
> Regards
> CVS*
> *
Reply all
Reply to author
Forward
0 new messages