1. Introduction to the environment
The RK3588 motherboard is equipped with the Android12 operating system, the kernel is Linux5.10, and uses ST's six-axis sensor LSM6DSR chip.
2. Chip introduction
The LSM6DSR is a six-axis acceleration and angular velocity (gyro) sensor that also has a built-in temperature sensor. This chip can choose I2C, SPI communication, as well as programmable terminals, and can be equipped with rear cameras and other equipment. The functions are very powerful (if you are interested, you can read the data sheet). The original chip manufacturer disclosed input and iio drivers and HAL. I chose the iio driver here, so the HAL also chose the iio driver.
3. Driver transplantation
[android12-linux-5.1][ST chip][RK3588][LSM6DSR] driver transplant__Huahua's blog-CSDN blog
4. HAL transplantation
Source code link: https://github.com/STMicroelectronics/STMems_Android_Sensor_HAL_IIO/tree/STMems_Android_Sensor_HAL_IIO
1. Copy the entire folder to the hardware/ directory
2. Add in /device/rockchip/rk3588/device.mk
PRODUCT_PACKAGES += sensors.rk3588
3. In the HAL directory, execute the generate cofig instruction
source android_data_config
make sensors-defconfig
For error reporting failure, please refer to [android12-linux-5.1] [ST chip] Configuration file generation error reporting after HAL transplantation__Huahua's Blog-CSDN Blog
4. Add permission configuration reference (will get stuck and report error -13 when booting)
[android12-linux-5.1][ST chip] Boot stuck after HAL transplantation__Huahua's Blog-CSDN Blog
5. The HAL reference cannot be adjusted after compilation (the HAL increase log will not appear)
6.Multiple HAL compatible references
7. If the SensorManger still cannot be adjusted during the test, please refer to the configuration.
Solved: Re: Android P can't get LSM6DSM HAL Accelerometer/... - STMicroelectronics Community
5. Test
Just call the system interface SensorManger directly.
1,MainActivity.java
package com.example.sensorsdata;
import static android.hardware.SensorManager.SENSOR_DELAY_GAME;
import static android.hardware.SensorManager.SENSOR_DELAY_NORMAL;
import static android.hardware.SensorManager.SENSOR_DELAY_UI;
import static java.lang.Math.atan2;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import com.google.android.material.snackbar.Snackbar;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Environment;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
public class MainActivityRaw extends Activity implements SensorEventListener {
private SensorManager sensorManager = null;
private Sensor accSensor = null;//加速度传感器
private Sensor gyroSensor = null;//角速度传感器
private Sensor magSensor = null;//磁力传感器
private Sensor stepSensor = null;//计步传感器
private Sensor tempSensor = null;//温度传感器
private Sensor tempSensor2 = null;//温度传感器
private TextView textView_AccName, textView_AccX, textView_AccY, textView_AccZ;//加速度传感器参数
private TextView textView_GyrName, textView_GyrX, textView_GyrY, textView_GyrZ;//角速度传感器参数
private TextView textView_MagName, textView_MagX, textView_MagY, textView_MagZ;//磁力