[android12-linux-5.1] [ST chip] Data direction is abnormal after driver and HAL transplantation

After ST's sensor driver and HAL have been successful, the data can be obtained, but the device is in landscape orientation and the system defaults to portrait orientation. There will be a situation where the screen automatically rotates in the wrong direction. When the device is held horizontally, the screen is displayed vertically, and when the device is held upright, the screen is displayed horizontally.

This is caused by the inconsistency between the sensor patch direction designed on the PCB and the horizontal screen. You only need to rotate the matrix on the HAL layer. Taking advantage of the fact that the earth's gravity acceleration is 9.8g, the required rotation matrix can be calculated by synchronously comparing the mobile phone and the device when placed flat, vertically, and horizontally.

Modify the file path to:/hardware/STMicroelectronics/SensorHAL_IIO/configuration.h

The default data before modification is:

#define CONFIG_ST_HAL_ACCEL_ROT_MATRIX 1,0,0,0,1,0,0,0,1
#define CONFIG_ST_HAL_MAGN_ROT_MATRIX 1,0,0,0,1,0,0,0,1
#define CONFIG_ST_HAL_GYRO_ROT_MATRIX 1,0,0,0,1,0,0,0,1

The modified data is:

#define CONFIG_ST_HAL_ACCEL_ROT_MATRIX 0,1,0,-1,0,0,0,0,1
#define CONFIG_ST_HAL_MAGN_ROT_MATRIX 0,1,0,-1,0,0,0,0,1
#define CONFIG_ST_HAL_GYRO_ROT_MATRIX 0,1,0,-1,0,0,0,0,1

 

 

It is easy to understand by the name definition, they are acceleration rotation matrix, magnetic rotation matrix, and gyroscope rotation matrix. This paragraph is easy to understand even with some basic mathematics. [x,y,z] is the original sampling data, [X,Y,Z] is the data finally sent to the app, and the rotation matrix data is [a1,a2,a3,a4,a5,a6,a7,a8,a9 ] Then there are:

\begin{bmatrix} X \\ Y \\ Z \end{bmatrix} = \begin{bmatrix} x \\ y \\ z \end{bmatrix}\begin{bmatrix} a1 &a2 &a3 \\ a4 &a5 &a6 \\ a7&a8 &a9 \end{bmatrix}=\begin{bmatrix} x*a1+y*a2+z*a3 \\ x*a4+y*a5+z*a6 \\ x*a7+y*a8+z*a9 \end{bmatrix}

—>

\left\{\begin{matrix} X = x*a1+y*a2+z*a3 \\ Y=x*a4+y*a5+z*a6 \\ Z=x*a7+y*a8+z*a9 \end{matrix}\right.

Bringing in the original data: [a1,a2,a3,a4,a5,a6,a7,a8,a9] = [1,0,0,0,1,0,0,0,1] then there is:

\left\{\begin{matrix} X=x \\ Y=y \\ Z=z \end{matrix}\right.

That is to say, the data is sent up.

Bringing in the modified data [a1,a2,a3,a4,a5,a6,a7,a8,a9] = [0,1,0,-1,0,0,0,0,1] then there is:

\left\{\begin{matrix} X=y \\ Y=-x \\ Z=z \end{matrix}\right.

This rotates the coordinate system 90 degrees and changes the default vertical screen to the default horizontal screen. If you don't understand it, draw the XY coordinate system on a piece of paper and rotate it, and practice it to gain true knowledge.

This paragraph is introduced in the readme. Write down your own memo here. Please don’t criticize me!

New to the industry, share your experience. If there are any mistakes, please point them out~

 Copyright belongs to: Shenzhen Qizhi Technology Co., Ltd.-Huahua

Guess you like

Origin blog.csdn.net/lsh670660992/article/details/132503031