├── Android.mk ├── CONTRIBUTING.md ├── Documentation ├── README ├── factory_calibration │ ├── BoardConfig.mk │ ├── STSensors.te │ ├── file.te │ ├── file_contexts │ └── init.example.rc └── ueventd.example.rc ├── Kconfig ├── Kconfig_menu ├── Kconfig_calibration ├── Kconfig_common ├── Kconfig_drivers ├── Kconfig_enable_sensors └── Kconfig_fusion_config ├── LICENSE.txt ├── Makefile ├── NOTICE.txt ├── README.md ├── README_hal ├── calibration_service ├── Android.mk └── calibration_daemon.c ├── lib └── Android.mk ├── selftest_tool ├── Android.mk └── selftest_tool.cpp ├── src ├── Accelerometer.cpp ├── Accelerometer.h ├── Android.mk ├── ChangeODRTimestampStack.cpp ├── ChangeODRTimestampStack.h ├── CircularBuffer.cpp ├── CircularBuffer.h ├── DeviceOrientation.cpp ├── DeviceOrientation.h ├── DynamicSensorProxy.cpp ├── DynamicSensorProxy.h ├── FlushBufferStack.cpp ├── FlushBufferStack.h ├── FlushRequested.cpp ├── FlushRequested.h ├── Gesture.cpp ├── Gesture.h ├── Gyroscope.cpp ├── Gyroscope.h ├── HWSensorBase.cpp ├── HWSensorBase.h ├── Magnetometer.cpp ├── Magnetometer.h ├── Pressure.cpp ├── Pressure.h ├── RHumidity.cpp ├── RHumidity.h ├── RingBuffer.cpp ├── RingBuffer.h ├── SWAccelGyroFusion6X.cpp ├── SWAccelGyroFusion6X.h ├── SWAccelMagnFusion6X.cpp ├── SWAccelMagnFusion6X.h ├── SWAccelMagnGyroFusion9X.cpp ├── SWAccelMagnGyroFusion9X.h ├── SWAccelerometerUncalibrated.cpp ├── SWAccelerometerUncalibrated.h ├── SWGameRotationVector.cpp ├── SWGameRotationVector.h ├── SWGeoMagRotationVector.cpp ├── SWGeoMagRotationVector.h ├── SWGravity.cpp ├── SWGravity.h ├── SWGyroscopeUncalibrated.cpp ├── SWGyroscopeUncalibrated.h ├── SWLinearAccel.cpp ├── SWLinearAccel.h ├── SWMagnetometerUncalibrated.cpp ├── SWMagnetometerUncalibrated.h ├── SWOrientation.cpp ├── SWOrientation.h ├── SWRotationVector.cpp ├── SWRotationVector.h ├── SWSensorBase.cpp ├── SWSensorBase.h ├── SWVirtualGyroscope.cpp ├── SWVirtualGyroscope.h ├── SelfTest.cpp ├── SelfTest.h ├── SensorAdditionalInfo.cpp ├── SensorAdditionalInfo.h ├── SensorBase.cpp ├── SensorBase.h ├── SensorHAL.cpp ├── SensorHAL.h ├── SignificantMotion.cpp ├── SignificantMotion.h ├── StepCounter.cpp ├── StepCounter.h ├── StepDetector.cpp ├── StepDetector.h ├── Temp.cpp ├── Temp.h ├── TiltSensor.cpp ├── TiltSensor.h ├── WristTiltGesture.cpp ├── WristTiltGesture.h ├── android_KK_defconfig ├── android_L_defconfig ├── android_M_defconfig ├── android_N_defconfig ├── android_O_defconfig ├── android_P_defconfig ├── android_Q_defconfig ├── android_R_defconfig ├── common_data.h ├── utils.cpp └── utils.h └── tools ├── kconfig-language.txt ├── kconfig-mconf └── mkconfig /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing guide 2 | This document serves as a checklist before contributing to this repository. It includes links to additional information if topics are unclear to you. 3 | 4 | This guide mainly focuses on the proper use of Git. 5 | 6 | ### 1. Before opening an issue 7 | To report a bug/request please enter the issue in the right repository. 8 | 9 | Please check the following boxes before posting an issue: 10 | - [ ] `Make sure you are using the latest commit (major releases are Tagged, but corrections are available as new commits).` 11 | - [ ] `Make sure your issue is a question/feedback/suggestion RELATED TO the software provided in this repository.` Otherwise, it should be discussed on the [ST Community forum](https://community.st.com/s/). 12 | - [ ] `Make sure your issue is not already reported/fixed on GitHub or discussed in a previous issue.` Please refer to the tab issue for the list of issues and pull-requests. Do not forget to browse to the **closed** issues. 13 | 14 | ### 2. Posting the issue 15 | When you have checked the previous boxes, you will find two templates (Bug Report or Other Issue) available in the **Issues** tab of the repository. 16 | 17 | ### 3. Pull Requests 18 | STMicroelectronics is happy to receive contributions from the community, based on an initial Contributor License Agreement (CLA) procedure. 19 | 20 | * If you are an individual writing original source code and you are sure **you own the intellectual property**, then you need to sign an Individual CLA (https://cla.st.com). 21 | * If you work for a company that wants also to allow you to contribute with your work, your company needs to provide a Corporate CLA (https://cla.st.com) mentioning your GitHub account name. 22 | * If you are not sure that a CLA (Individual or Corporate) has been signed for your GitHub account, you can check here (https://cla.st.com). 23 | 24 | Please note that: 25 | * The Corporate CLA will always take precedence over the Individual CLA. 26 | * One CLA submission is sufficient for any project proposed by STMicroelectronics. 27 | 28 | #### How to proceed 29 | 30 | * We recommend to engage first a communication through an issue, in order to present your proposal and just to confirm that it corresponds to a STMicroelectronics domain or scope. 31 | * Then fork the project to your GitHub account to further develop your contribution. Please use the latest commit version. 32 | * Please submit one Pull Request for one new feature or proposal. This will facilitate the analysis and the final merge if accepted. 33 | 34 | -------------------------------------------------------------------------------- /Documentation/README: -------------------------------------------------------------------------------- 1 | Android STMicroelectronics SensorHAL Documentation 2 | 3 | In order to correctly use Android SensorHAL, modifications at Android code 4 | are necessaries. 5 | 6 | Linux device drivers permissions: 7 | First at all, SensorHAL needs to read/write sysfs files and char devices 8 | of IIO drivers. 9 | device/{vendor}/{product}/uevent.{board}.rc file modification is mandatory, 10 | you can find an example in this folder with 'uevent.example.rc'. 11 | 12 | Factory calibration option: 13 | If you build the HAL using Factory calibration option, modifications of 14 | SELinux policy are necessary in order to read/write /persist and 15 | /data filesystem. 16 | You can find an example of modifications into the folder factory_calibration. 17 | Those modifications will touch: 18 | - device/{vendor}/{product}/BoardConfig.mk (modification) 19 | - device/{vendor}/{product}/init.{board}.rc (modification) 20 | - device/{vendor}/{product}/sepolicy/file.te (modification) 21 | - device/{vendor}/{product}/sepolicy/file_contexts (modification) 22 | - device/{vendor}/{product}/sepolicy/STSensors.te (add) 23 | 24 | Selftest tool manual: 25 | If you build HAL enabling Selftest functions, an executable will be 26 | available and installed into /system/bin/STSensor_selftest. 27 | Using this binary you will be able to easly execute selftest, 28 | based only on Android sensor handle. No information about device 29 | driver will be used. 30 | You can run binary directly in your device using adb shell. All sensors 31 | must be switched off in order to execute the test. 32 | 33 | NOTE: Selftest tool is maintained for compatibility with the past Android 34 | version (last successfully tested version was 8.0) but will soon be removed 35 | and no longer supported. 36 | 37 | -------------------------------------------------------------------------------- /Documentation/factory_calibration/BoardConfig.mk: -------------------------------------------------------------------------------- 1 | # Add STSensors.te SELinux policy 2 | BOARD_SEPOLICY_UNION += \ 3 | STSensors.te 4 | -------------------------------------------------------------------------------- /Documentation/factory_calibration/STSensors.te: -------------------------------------------------------------------------------- 1 | type STSensors, domain; 2 | type STSensors_exec, exec_type, file_type; 3 | 4 | # Started by init 5 | init_daemon_domain(STSensors) 6 | 7 | # Access to /persist/STSensors 8 | allow STSensors persist_file:dir r_dir_perms; 9 | allow STSensors persist_STSensors_file:dir rw_dir_perms; 10 | allow STSensors persist_STSensors_file:file create_file_perms; 11 | 12 | # Access to /data/STSensorHAL 13 | allow STSensors system_data_file:dir { create_dir_perms getattr }; 14 | allow STSensors system_data_file:file create_file_perms; 15 | 16 | # This part is to be used if APK is used to get calibration data 17 | allow STSensors app_data_file:dir { rw_dir_perms getattr }; 18 | allow STSensors app_data_file:file rw_file_perms; 19 | -------------------------------------------------------------------------------- /Documentation/factory_calibration/file.te: -------------------------------------------------------------------------------- 1 | # Persist STSensors calibration file types 2 | type persist_STSensors_file, file_type; 3 | -------------------------------------------------------------------------------- /Documentation/factory_calibration/file_contexts: -------------------------------------------------------------------------------- 1 | # Persist STSensors calibration filesystem 2 | /persist/STCalibration(/.*)? u:object_r:persist_STSensors_file:s0 3 | 4 | # STSensors_deamon 5 | /system/bin/STSensors_daemon u:object_r:STSensors_exec:s0 6 | -------------------------------------------------------------------------------- /Documentation/factory_calibration/init.example.rc: -------------------------------------------------------------------------------- 1 | # Add STSensors service 2 | service STSensors /system/bin/STSensors_daemon 3 | class late_start 4 | user system 5 | group system 6 | -------------------------------------------------------------------------------- /Documentation/ueventd.example.rc: -------------------------------------------------------------------------------- 1 | #common iio char devices 2 | /dev/iio:device* 0666 system system 3 | 4 | #common sensors files 5 | /sys/devices/iio:device* buffer/enable 0666 system system 6 | /sys/devices/iio:device* buffer/length 0666 system system 7 | /sys/devices/iio:device* sampling_frequency 0666 system system 8 | /sys/devices/iio:device* scan_elements/in_timestamp_en 0666 system system 9 | /sys/devices/iio:device* hwfifo_flush 0666 system system 10 | /sys/devices/iio:device* hwfifo_enabled 0666 system system 11 | /sys/devices/iio:device* hwfifo_watermark 0666 system system 12 | /sys/devices/iio:device* injection_mode 0666 system system 13 | 14 | #accelerometer sensor 15 | /sys/devices/iio:device* scan_elements/in_accel_x_en 0666 system system 16 | /sys/devices/iio:device* scan_elements/in_accel_y_en 0666 system system 17 | /sys/devices/iio:device* scan_elements/in_accel_z_en 0666 system system 18 | /sys/devices/iio:device* in_accel_x_scale 0666 system system 19 | /sys/devices/iio:device* in_accel_y_scale 0666 system system 20 | /sys/devices/iio:device* in_accel_z_scale 0666 system system 21 | /sys/devices/iio:device* in_accel_injection_raw 0666 system system 22 | 23 | #magnetometer sensor 24 | /sys/devices/iio:device* scan_elements/in_magn_x_en 0666 system system 25 | /sys/devices/iio:device* scan_elements/in_magn_y_en 0666 system system 26 | /sys/devices/iio:device* scan_elements/in_magn_z_en 0666 system system 27 | /sys/devices/iio:device* in_magn_x_scale 0666 system system 28 | /sys/devices/iio:device* in_magn_y_scale 0666 system system 29 | /sys/devices/iio:device* in_magn_z_scale 0666 system system 30 | 31 | #gyroscope sensor 32 | /sys/devices/iio:device* scan_elements/in_anglvel_x_en 0666 system system 33 | /sys/devices/iio:device* scan_elements/in_anglvel_y_en 0666 system system 34 | /sys/devices/iio:device* scan_elements/in_anglvel_z_en 0666 system system 35 | /sys/devices/iio:device* in_anglvel_x_scale 0666 system system 36 | /sys/devices/iio:device* in_anglvel_y_scale 0666 system system 37 | /sys/devices/iio:device* in_anglvel_z_scale 0666 system system 38 | 39 | #pressure sensor 40 | /sys/devices/iio:device* scan_elements/in_pressure_en 0666 system system 41 | /sys/devices/iio:device* scan_elements/in_temp_en 0666 system system 42 | /sys/devices/iio:device* in_pressure_scale 0666 system system 43 | 44 | #step counter sensor 45 | /sys/devices/iio:device* max_delivery_rate 0666 system system 46 | /sys/devices/iio:device* reset_counter 0666 system system 47 | /sys/devices/iio:device* scan_elements/in_step_counter_en 0666 system system 48 | 49 | #significant motion sensor 50 | /sys/devices/iio:device* scan_elements/in_sign_motion_en 0666 system system 51 | 52 | #step detector sensor 53 | /sys/devices/iio:device* scan_elements/in_step_detector_en 0666 system system 54 | 55 | #tilt sensor 56 | /sys/devices/iio:device* scan_elements/in_tilt_en 0666 system system 57 | -------------------------------------------------------------------------------- /Kconfig: -------------------------------------------------------------------------------- 1 | # 2 | # For a description of the syntax of this configuration file, 3 | # see tools/kconfig-language.txt. 4 | # 5 | 6 | mainmenu "SensorHAL IIO Configuration" 7 | 8 | config ST_HAL_PATH 9 | string 10 | default "$(ST_HAL_PATH)" 11 | 12 | config ST_HAL_ANDROID_VERSION 13 | int 14 | default "$(ST_HAL_ANDROID_VERSION)" 15 | 16 | config ST_HAL_HAS_6AX_FUSION_CHECK 17 | bool 18 | default "$(ST_HAL_HAS_9X_6X_LIB)" 19 | 20 | config ST_HAL_HAS_9AX_FUSION_CHECK 21 | bool 22 | default "$(ST_HAL_HAS_9X_6X_LIB)" 23 | 24 | config ST_HAL_HAS_GEOMAG_FUSION_CHECK 25 | bool 26 | default "$(ST_HAL_HAS_GEOMAG_LIB)" 27 | 28 | config ST_HAL_HAS_MAGN_CALIB_CHECK 29 | bool 30 | default "$(ST_HAL_HAS_MAGN_CALIB_LIB)" 31 | 32 | config ST_HAL_HAS_ACCEL_CALIB_CHECK 33 | bool 34 | default "$(ST_HAL_HAS_ACCEL_CALIB_LIB)" 35 | 36 | config ST_HAL_HAS_GYRO_GBIAS_ESTIMATION_CHECK 37 | bool 38 | default "$(ST_HAL_HAS_GBIAS_LIB)" 39 | 40 | config ST_HAL_HAS_6AX_FUSION 41 | bool 42 | default ST_HAL_HAS_6AX_FUSION_CHECK 43 | 44 | config ST_HAL_HAS_9AX_FUSION 45 | bool 46 | default ST_HAL_HAS_9AX_FUSION_CHECK 47 | 48 | config ST_HAL_HAS_GEOMAG_FUSION 49 | bool 50 | default ST_HAL_HAS_GEOMAG_FUSION_CHECK 51 | 52 | config ST_HAL_HAS_MAGN_CALIB 53 | bool 54 | default ST_HAL_HAS_MAGN_CALIB_CHECK 55 | 56 | config ST_HAL_HAS_ACCEL_CALIB 57 | bool 58 | default ST_HAL_HAS_ACCEL_CALIB_CHECK 59 | 60 | config ST_HAL_HAS_GYRO_GBIAS_ESTIMATION 61 | bool 62 | default ST_HAL_HAS_GYRO_GBIAS_ESTIMATION_CHECK 63 | 64 | source "$(ST_HAL_PATH)/Kconfig_menu/Kconfig_enable_sensors" 65 | source "$(ST_HAL_PATH)/Kconfig_menu/Kconfig_common" 66 | source "$(ST_HAL_PATH)/Kconfig_menu/Kconfig_fusion_config" 67 | source "$(ST_HAL_PATH)/Kconfig_menu/Kconfig_drivers" 68 | source "$(ST_HAL_PATH)/Kconfig_menu/Kconfig_calibration" 69 | 70 | -------------------------------------------------------------------------------- /Kconfig_menu/Kconfig_calibration: -------------------------------------------------------------------------------- 1 | # 2 | # Calibration configuration 3 | # 4 | 5 | menu "Factory calibration & Self-Test" 6 | config ST_HAL_FACTORY_CALIBRATION 7 | bool "Apply factory calibration from /persist filesystem" 8 | default n 9 | help 10 | SensorHAL during boot read factory calibration files from 11 | /data filesystem and load calibration values. 12 | 13 | This option enable also a service in order to check if new calibration 14 | files are available into /persist/STSensors_calibration/ folder and copy 15 | to /data filesystem. 16 | 17 | This option require /persist/STSensors_calibration/ folder is 18 | available and factory calibration files are available into it. 19 | 20 | config ST_HAL_FACTORY_CALIBRATION_USING_APK 21 | bool "Use ST APK to calibrate sensors" 22 | depends on ST_HAL_FACTORY_CALIBRATION 23 | default n 24 | help 25 | SensorHAL use STSensor_daemon service in order to get factory 26 | calibration data from APK and store it to /persist filesystem.a 27 | 28 | With this option you do not need to have /persist/STSensors_calibration/ 29 | folder but service will create it. 30 | 31 | config ST_HAL_HAS_SELFTEST_FUNCTIONS 32 | bool "Integrate self-test functions" 33 | default n 34 | help 35 | SensorHAL integrate functions to run self-test on devices that support it. 36 | The macro also enable to build an executable in order to execute SensorHAL 37 | functions. 38 | 39 | endmenu # Calibration configuration 40 | -------------------------------------------------------------------------------- /Kconfig_menu/Kconfig_common: -------------------------------------------------------------------------------- 1 | # 2 | # Common configuration 3 | # 4 | 5 | menu "Common configuration" 6 | config ST_HAL_MAX_SAMPLING_FREQUENCY 7 | int "Max sampling frequency selectable [Hz]" 8 | range 50 2000 9 | default 2000 10 | help 11 | Maximium value of sampling frequency that can be used in IIO driver. 12 | 13 | config ST_HAL_DEBUG_LEVEL 14 | int "Logcat Debug level" 15 | range 0 3 16 | default 0 17 | help 18 | Debugging information level. [0 - 3] 19 | 0: disabled (error only); 20 | 1: info messages; 21 | 2: verbose; 22 | 3: extra-verbose; 23 | 24 | if ST_HAL_ACCEL_ENABLED 25 | config ST_HAL_ACCEL_ROT_MATRIX 26 | string "Accelerometer Rotation matrix" 27 | default "1,0,0,0,1,0,0,0,1" 28 | help 29 | The rotation matrix is used to rotate the accelerometer axis data. 30 | 31 | The default matrix is: 1,0,0,0,1,0,0,0,1 (Identity Matrix). 32 | 33 | The mathematical computation is: 34 | 35 | [1,0,0] 36 | [x', y', z'] = [x, y, z,] * [0,1,0] = [x*1 + y*0 + z*0, x*0 + y*1 + z*0, x*0 + y*0 + z*1] = [x, y, z] 37 | [0,0,1] 38 | 39 | where: 40 | x', y', z' are the final values. 41 | x, y, z are the input values (from IIO driver). 42 | 43 | 44 | config ST_HAL_ACCEL_RANGE 45 | int "Accelerometer Max Range (m/s^2)" 46 | default 17 47 | help 48 | This parameter is used to configure the accelerometer full-scale 49 | during boot. 50 | 51 | Due to approximations please calculate the full-scale value and 52 | substract 2.x, example: 53 | 54 | 2 G = 19.6 m/s^2 => 19.6 - 2.x = 17. 55 | 4 G = 39.2 m/s^2 => 39.2 - 2.x = 37. 56 | 16 G = 156.8 m/s^2 => 156.8 - 2.x = 154. 57 | 58 | DEFAULT value: 17 (19.6 m/s^s) 59 | 60 | endif 61 | 62 | if ST_HAL_MAGN_ENABLED || ST_HAL_MAGN_UNCALIB_HW_ENABLED 63 | config ST_HAL_MAGN_ROT_MATRIX 64 | string "Magnetometer Rotation matrix" 65 | default "1,0,0,0,1,0,0,0,1" 66 | help 67 | The rotation matrix is used to rotate the magnetometer axis data. 68 | 69 | The default matrix is: 1,0,0,0,1,0,0,0,1 (Identity Matrix). 70 | 71 | The mathematical computation is: 72 | 73 | [1,0,0] 74 | [x', y', z'] = [x, y, z,] * [0,1,0] = [x*1 + y*0 + z*0, x*0 + y*1 + z*0, x*0 + y*0 + z*1] = [x, y, z] 75 | [0,0,1] 76 | 77 | where: 78 | x', y', z' are the final values. 79 | x, y, z are the input values (from IIO driver). 80 | 81 | config ST_HAL_MAGN_RANGE 82 | int "Magnetometer Max Range (uTesla)" 83 | default 1150 84 | help 85 | This parameter is used to configure the magnetometer full-scale 86 | during boot. 87 | 88 | Due to approximations please calculate the full-scale value and 89 | substract 50.x, example: 90 | 91 | 4 Gauss = 400 uT => 400 - 50.x = 350. 92 | 12 Gauss = 1200 uT => 1200 - 50.x = 1150. 93 | 16 Gauss = 1600 uT => 1600 - 50.x = 1550. 94 | 95 | DEFAULT value: 1150 (1200 uT) 96 | 97 | endif 98 | 99 | if ST_HAL_GYRO_ENABLED || ST_HAL_GYRO_UNCALIB_HW_ENABLED 100 | config ST_HAL_GYRO_ROT_MATRIX 101 | string "Gyroscope Rotation matrix" 102 | default "1,0,0,0,1,0,0,0,1" 103 | help 104 | The rotation matrix is used to rotate the gyroscope axis data. 105 | 106 | The default matrix is: 1,0,0,0,1,0,0,0,1 (Identity Matrix). 107 | 108 | The mathematical computation is: 109 | 110 | [1,0,0] 111 | [x', y', z'] = [x, y, z,] * [0,1,0] = [x*1 + y*0 + z*0, x*0 + y*1 + z*0, x*0 + y*0 + z*1] = [x, y, z] 112 | [0,0,1] 113 | 114 | where: 115 | x', y', z' are the final values. 116 | x, y, z are the input values (from IIO driver). 117 | 118 | config ST_HAL_GYRO_RANGE 119 | int "Gyroscope Max Range (rad/sec)" 120 | default 33 121 | help 122 | This parameter is used to configure the gyroscope full-scale 123 | during boot. 124 | 125 | Due to approximations please calculate the full-scale value and 126 | substract 1.x, example: 127 | 128 | 245 dps = 4.27 rad/sec => 4.27 - 1.x = 3 129 | 500 dps = 8.72 rad/sec => 8.72 - 1.x = 7. 130 | 2000 dps = 34.9 rad/sec => 34.9 - 1.x = 33. 131 | 132 | DEFAULT value: 33 (34.9 rad/sec) 133 | 134 | endif 135 | 136 | endmenu # Common configuration 137 | -------------------------------------------------------------------------------- /Kconfig_menu/Kconfig_fusion_config: -------------------------------------------------------------------------------- 1 | # 2 | # SensorFusion configuration 3 | # 4 | 5 | if ST_HAL_HAS_6AX_FUSION || ST_HAL_HAS_9AX_FUSION || ST_HAL_HAS_GEOMAG_FUSION 6 | menu "SensorFusion configuration" 7 | 8 | config ST_HAL_MIN_FUSION_POLLRATE 9 | int "Min SensorFusion run frequency [Hz]" 10 | range 20 ST_HAL_MAX_SAMPLING_FREQUENCY 11 | default 50 12 | 13 | config ST_HAL_INEMO_GBIAS_THRESOLD_ACCEL 14 | string "Accelerometer Gbias thresold" 15 | default "86999e-9" 16 | 17 | if ST_HAL_HAS_9AX_FUSION || ST_HAL_HAS_GEOMAG_FUSION 18 | config ST_HAL_INEMO_GBIAS_THRESOLD_MAGN 19 | string "Magnetometer Gbias thresold" 20 | default "599999e-9" 21 | 22 | endif 23 | 24 | if ST_HAL_HAS_6AX_FUSION || ST_HAL_HAS_9AX_FUSION 25 | config ST_HAL_INEMO_GBIAS_THRESOLD_GYRO 26 | string "Gyroscope Gbias thresold" 27 | default "114999e-9" 28 | 29 | endif 30 | endmenu # Sensor Fusion configuration 31 | endif 32 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2017 STMicroelectronics 3 | # Denis Ciocca - Motion MEMS Product Div. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | .PHONY: sensors-defconfig sensors-menuconfig sensors-cleanconf 19 | 20 | CURRENT_DIRECTORY := $(shell pwd) 21 | 22 | # Check AOSP version 23 | ifeq ($(PLATFORM_VERSION),) 24 | # ANDROID_BUILD_TOP is deprecated 25 | ifeq ($(ANDROID_BUILD_TOP),) 26 | VERSION_DEFAULT := $(.)/build/core/version_defaults.mk 27 | else # ANDROID_BUILD_TOP 28 | VERSION_DEFAULT := $(ANDROID_BUILD_TOP)/build/core/version_defaults.mk 29 | endif # ANDROID_BUILD_TOP 30 | PLATFORM_COMMAND_VERSION := $(shell grep "PLATFORM_VERSION := " $(VERSION_DEFAULT)) 31 | PLATFORM_VERSION := $(shell echo $(PLATFORM_COMMAND_VERSION) | awk -F':= ' '{print $$2}') 32 | endif # PLATFORM_VERSION 33 | 34 | MAJOR_VERSION := $(shell echo $(PLATFORM_VERSION) | cut -f1 -d.) 35 | MINOR_VERSION := $(shell echo $(PLATFORM_VERSION) | cut -f2 -d.) 36 | 37 | VERSION_KK := $(shell test $(MAJOR_VERSION) -eq 4 -a $(MINOR_VERSION) -eq 4 && echo true) 38 | VERSION_L := $(shell test $(MAJOR_VERSION) -eq 5 && echo true) 39 | VERSION_M := $(shell test $(MAJOR_VERSION) -eq 6 && echo true) 40 | VERSION_N := $(shell test $(MAJOR_VERSION) -eq 7 && echo true) 41 | VERSION_O := $(shell test $(MAJOR_VERSION) -eq 8 && echo true) 42 | VERSION_P := $(shell test $(MAJOR_VERSION) -eq 9 && echo true) 43 | VERSION_Q := $(shell test $(MAJOR_VERSION) -eq 10 && echo true) 44 | VERSION_R := $(shell test $(MAJOR_VERSION) -eq 11 && echo true) 45 | 46 | ifeq ($(VERSION_KK),true) 47 | ST_HAL_ANDROID_VERSION=0 48 | DEFCONFIG := android_KK_defconfig 49 | endif # VERSION_KK 50 | 51 | ifeq ($(VERSION_L),true) 52 | ST_HAL_ANDROID_VERSION=1 53 | DEFCONFIG := android_L_defconfig 54 | endif # VERSION_L 55 | 56 | ifeq ($(VERSION_M),true) 57 | ST_HAL_ANDROID_VERSION=2 58 | DEFCONFIG := android_M_defconfig 59 | endif # VERSION_M 60 | 61 | ifeq ($(VERSION_N),true) 62 | ST_HAL_ANDROID_VERSION=3 63 | DEFCONFIG := android_N_defconfig 64 | endif # VERSION_N 65 | 66 | ifeq ($(VERSION_O),true) 67 | ST_HAL_ANDROID_VERSION=4 68 | DEFCONFIG := android_O_defconfig 69 | endif # VERSION_O 70 | 71 | ifeq ($(VERSION_P),true) 72 | ST_HAL_ANDROID_VERSION=5 73 | DEFCONFIG := android_P_defconfig 74 | endif # VERSION_P 75 | 76 | ifeq ($(VERSION_Q),true) 77 | ST_HAL_ANDROID_VERSION=6 78 | DEFCONFIG := android_Q_defconfig 79 | endif # VERSION_Q 80 | 81 | ifeq ($(VERSION_R),true) 82 | ST_HAL_ANDROID_VERSION=7 83 | DEFCONFIG := android_R_defconfig 84 | endif # VERSION_R 85 | 86 | ifeq ($(DEFCONFIG),) 87 | $(error ${\n}${\n}${\space}${\n}AOSP Version Unknown${\n}) 88 | endif # DEFCONFIG 89 | 90 | ifneq ("$(wildcard $(CURRENT_DIRECTORY)/lib/FUFD_CustomTilt/FUFD_CustomTilt*)","") 91 | ST_HAL_HAS_FDFD_LIB=y 92 | else 93 | ST_HAL_HAS_FDFD_LIB=n 94 | endif 95 | 96 | ifneq ("$(wildcard $(CURRENT_DIRECTORY)/lib/iNemoEngine_gbias_Estimation/iNemoEngine_gbias_Estimation*)","") 97 | ST_HAL_HAS_GBIAS_LIB=y 98 | else 99 | ST_HAL_HAS_GBIAS_LIB=n 100 | endif 101 | 102 | ifneq ("$(wildcard $(CURRENT_DIRECTORY)/lib/iNemoEngine_GeoMag_Fusion/iNemoEngine_GeoMag*)","") 103 | ST_HAL_HAS_GEOMAG_LIB=y 104 | else 105 | ST_HAL_HAS_GEOMAG_LIB=n 106 | endif 107 | 108 | ifneq ("$(wildcard $(CURRENT_DIRECTORY)/lib/iNemoEnginePRO/iNemoEnginePRO*)","") 109 | ST_HAL_HAS_9X_6X_LIB=y 110 | else 111 | ST_HAL_HAS_9X_6X_LIB=n 112 | endif 113 | 114 | ifneq ("$(wildcard $(CURRENT_DIRECTORY)/lib/STMagCalibration/STMagCalibration*)","") 115 | ST_HAL_HAS_MAGN_CALIB_LIB=y 116 | else 117 | ST_HAL_HAS_MAGN_CALIB_LIB=n 118 | endif 119 | 120 | ifneq ("$(wildcard $(CURRENT_DIRECTORY)/lib/STAccCalibration/STAccCalibration*)","") 121 | ST_HAL_HAS_ACCEL_CALIB_LIB=y 122 | else 123 | ST_HAL_HAS_ACCEL_CALIB_LIB=n 124 | endif 125 | 126 | # Export to config tools 127 | export ST_HAL_HAS_ACCEL_CALIB_LIB ST_HAL_HAS_MAGN_CALIB_LIB ST_HAL_HAS_9X_6X_LIB ST_HAL_HAS_GEOMAG_LIB ST_HAL_HAS_GBIAS_LIB ST_HAL_HAS_FDFD_LIB 128 | export ST_HAL_ANDROID_VERSION 129 | export DEFCONFIG 130 | export KCONFIG_CONFIG_HAL=$(CURRENT_DIRECTORY)/hal_config 131 | export ST_HAL_PATH=$(CURRENT_DIRECTORY) 132 | 133 | configfile: 134 | $(if $(wildcard $(KCONFIG_CONFIG_HAL)), , $(warning ${\n}${\n}${\space}${\n}defconfig file not found. Used default one: `$(DEFCONFIG)`.${\n}${\space}${\n}) @$(MAKE) sensors-defconfig > /dev/null) 135 | 136 | sensors-defconfig: 137 | cp $(CURRENT_DIRECTORY)/src/$(DEFCONFIG) $(KCONFIG_CONFIG_HAL) 138 | $(CURRENT_DIRECTORY)/tools/mkconfig $(CURRENT_DIRECTORY)/ > $(CURRENT_DIRECTORY)/configuration.h 139 | 140 | sensors-menuconfig: configfile 141 | $(CURRENT_DIRECTORY)/tools/kconfig-mconf $(CURRENT_DIRECTORY)/Kconfig 142 | $(CURRENT_DIRECTORY)/tools/mkconfig $(CURRENT_DIRECTORY)/ > $(CURRENT_DIRECTORY)/configuration.h 143 | 144 | sensors-cleanconf: 145 | $(if $(wildcard $(KCONFIG_CONFIG_HAL)), rm $(KCONFIG_CONFIG_HAL), ) 146 | $(if $(wildcard $(KCONFIG_CONFIG_HAL).old), rm $(KCONFIG_CONFIG_HAL).old, ) 147 | $(if $(wildcard $(CURRENT_DIRECTORY)/configuration.h), rm $(CURRENT_DIRECTORY)/configuration.h, ) 148 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | STMicroelectronics SensorHAL-IIO Project 2 | 3 | STMicroelectronics licenses this file to you under the Apache License, 4 | version 2.0 (the "License"); you may not use this file except in compliance 5 | with the License. You may obtain a copy of the License at: 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | License for the specific language governing permissions and limitations 13 | under the License. 14 | 15 | ------------------------------------------------------------------------------- 16 | 17 | This project may contains proprietary librares under lib/ folder. Different 18 | LICENSES are applied on binary files. 19 | 20 | * LICENSE: 21 | * PROPRIETARY - CUSTOM 22 | * FILE: 23 | * lib/* 24 | 25 | 26 | All other files are considered under Apache License version 2.0. 27 | Check LICENSE.txt to get information about the license. 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Important Notice 2 | ================== 3 | 4 | DISCONTINUED (October 2022): the maintenance for this repository has been discontinued. 5 | 6 | Please refer to: 7 | 8 | https://github.com/STMicroelectronics/st-mems-android-linux-sensors-hal 9 | 10 | for the up-to-date HAL repository. 11 | 12 | Index 13 | ===== 14 | * Introduction 15 | * Software architecture and Integration details 16 | * STM proprietary libraries 17 | * More information 18 | * Copyright 19 | 20 | 21 | Introduction 22 | ========= 23 | The STM Android sensor Hardware Abstraction Layer (*HAL*) defines a standard interface for STM sensors allowing Android to be agnostic about [lower-level driver implementations](https://github.com/STMicroelectronics/STMems_Linux_IIO_drivers/tree/linux-4.4.y-gh) . The HAL library is packaged into modules (.so) file and loaded by the Android system at the appropriate time. For more information see [AOSP HAL Interface](https://source.android.com/devices/sensors/hal-interface.html) 24 | 25 | STM Sensor HAL is leaning on [Linux IIO framework](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/iio) to gather data from sensor device drivers and to forward samples to the Android Framework 26 | 27 | Currently supported sensors are: 28 | 29 | ### Inertial Module Unit (IMU): 30 | 31 | > LSM330, LSM330DLC, LSM6DS3, LSM6DS3H, LSM6DSM, LSM6DSL, LSM6DS0, LSM9DS0, LSM9DS1, LSM330D, LSM330DL, ISM330DLC, LSM6DSO, ASM330LHH, LSM6DSR, LSM6DSO32, 32 | > LSM6DSOX, LSM6DSRX, LSM6DSO32X, ISM330DHCX, ASM330LHHX 33 | 34 | ### eCompass: 35 | 36 | > LSM303AGR, LSM303AH, LSM303DLHC, LSM303DLH, LSM303DLM, ISM303DAC 37 | 38 | ### Accelerometer: 39 | 40 | > LIS2DS12, LIS2HH12, LIS3DH, LIS3DHH, LIS2DW12, LIS331DLH, LIS2DG, LIS2DH, LIS2DH12, IIS2DH, IIS3DHHC, AIS2IH 41 | 42 | ### Gyroscope: 43 | 44 | > L3GD20, L3GD20H, L3G4200D 45 | 46 | ### Magnetometer: 47 | 48 | > LIS3MDL, LIS2MDL, IIS2MDC 49 | 50 | ### Pressure and Temperature: 51 | 52 | > LPS22HB, LPS22HD, LPS25H, LPS331AP, LPS33HW, LPS35HW, LPS22HH, LPS27HHW 53 | 54 | ### Humidity and Temperature: 55 | 56 | > HTS221 57 | 58 | Software architecture and Integration details 59 | ============= 60 | 61 | STM Sensor HAL is written in *C++* language using object-oriented design. For each hw sensor there is a custom class file 62 | (*Accelerometer.cpp*, *Magnetometer.cpp*, *Gyroscope.cpp*, *Pressure.cpp*, *Temp.cpp* and *RHumidity.cpp*) which extends the common base class (*SensorBase.cpp*). 63 | 64 | Copy the HAL source code into */hardware/STMicroelectronics/SensorHAL_IIO* folder. During building process Android will include automatically the SensorHAL Android.mk. 65 | In */device///device.mk* add package build information: 66 | 67 | PRODUCT_PACKAGES += sensors.{TARGET_BOARD_PLATFORM} 68 | 69 | Note: device.mk can not read $(TARGET_BOARD_PLATFORM) variable, read and replace the value from your BoardConfig.mk (e.g. PRODUCT_PACKAGES += sensors.msm8974 for Nexus 5) 70 | 71 | To compile the SensorHAL_IIO just build AOSP source code from *$TOP* folder 72 | 73 | $ cd 74 | $ source build/envsetup.sh 75 | $ lunch