├── 2.0 ├── AdditionalInfoManager.cpp ├── AdditionalInfoManager.h ├── Android.bp ├── Convert.cpp ├── Convert.h ├── DirectChannel.cpp ├── DirectChannel.h ├── SensorsCallback.cpp ├── SensorsCallback.h ├── SensorsHidlInterface.cpp ├── SensorsHidlInterface.h ├── android.hardware.sensors@2.0-service-stmicroelectronics.rc ├── android.hardware.sensors@2.0-stmicroelectronics.xml ├── readme.org └── service.cpp ├── CONTRIBUTING.md ├── LICENSE.txt ├── OWNERS ├── aidl ├── AdditionalInfoManager.cpp ├── AdditionalInfoManager.h ├── Android.bp ├── Convert.cpp ├── Convert.h ├── DirectChannel.cpp ├── DirectChannel.h ├── SensorsAidlInterface.cpp ├── SensorsAidlInterface.h ├── SensorsCallback.cpp ├── SensorsCallback.h ├── android.hardware.sensors@aidl-service-stmicroelectronics.rc ├── android.hardware.sensors@aidl-stmicroelectronics.xml ├── readme.org └── service.cpp ├── commons ├── Android.bp ├── AndroidPropertiesLoader.cpp ├── AndroidPropertiesLoader.h ├── IConsole.cpp ├── IUtils.cpp ├── SensorPlacement.cpp ├── SensorPlacement.h ├── SensorsDataProxyManager.cpp └── SensorsDataProxyManager.h ├── core ├── Accelerometer.cpp ├── Accelerometer.h ├── AccelerometerLimitedAxes.cpp ├── AccelerometerLimitedAxes.h ├── Android.bp ├── Android.mk ├── CMakeLists.txt ├── ChangeODRTimestampStack.cpp ├── ChangeODRTimestampStack.h ├── CircularBuffer.cpp ├── CircularBuffer.h ├── DeviceOrientation.cpp ├── DeviceOrientation.h ├── FlushBufferStack.cpp ├── FlushBufferStack.h ├── Gesture.cpp ├── Gesture.h ├── Gyroscope.cpp ├── Gyroscope.h ├── GyroscopeLimitedAxes.cpp ├── GyroscopeLimitedAxes.h ├── HWSensorBase.cpp ├── HWSensorBase.h ├── ISTMSensorsCallbackData.cpp ├── ISTMSensorsHAL.cpp ├── IntTemp.cpp ├── IntTemp.h ├── Magnetometer.cpp ├── Magnetometer.h ├── Pressure.cpp ├── Pressure.h ├── PropertiesManager.cpp ├── PropertiesParser.cpp ├── PropertiesParser.h ├── RHumidity.cpp ├── RHumidity.h ├── STMSensor.cpp ├── STMSensorType.cpp ├── STMSensorType.h ├── STMSensorsCallbackData.cpp ├── STMSensorsCallbackData.h ├── STMSensorsHAL.cpp ├── STMSensorsHAL.h ├── STMSensorsList.cpp ├── SWAccelGyroFusion6X.cpp ├── SWAccelGyroFusion6X.h ├── SWAccelMagnGyroFusion9X.cpp ├── SWAccelMagnGyroFusion9X.h ├── SWAccelerometerLimitedAxesUncalibrated.cpp ├── SWAccelerometerLimitedAxesUncalibrated.h ├── SWAccelerometerUncalibrated.cpp ├── SWAccelerometerUncalibrated.h ├── SWGameRotationVector.cpp ├── SWGameRotationVector.h ├── SWGravity.cpp ├── SWGravity.h ├── SWGyroLimitedAxesUncalibrated.cpp ├── SWGyroLimitedAxesUncalibrated.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 ├── SelfTest.cpp ├── SelfTest.h ├── SensorBase.cpp ├── SensorBase.h ├── SensorHAL.cpp ├── SensorHAL.h ├── SensorTypeInternal.h ├── SensorsGraph.h ├── SensorsSupported.cpp ├── SensorsSupported.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 ├── common_data.h ├── configuration.h ├── gTests │ ├── CMakeLists.txt │ ├── Main_TestAll.cpp │ ├── STMSensor_test.cpp │ ├── STMSensorsHAL_test.cpp │ └── STMSensorsList_test.cpp ├── include │ ├── Android.bp │ ├── IConsole.h │ ├── ISTMSensorsCallback.h │ ├── ISTMSensorsCallbackData.h │ ├── ISTMSensorsHAL.h │ ├── IUtils.h │ ├── Matrix.h │ ├── PropertiesManager.h │ ├── STMSensor.h │ ├── STMSensorsList.h │ ├── SensorType.h │ ├── Utils.h │ └── local │ │ ├── sensorhal_iio_types.h │ │ └── stm_iio_types.h ├── libs │ ├── accel-calibration │ │ ├── Android.bp │ │ ├── Android.mk │ │ ├── CMakeLists.txt │ │ ├── STMAccelCalibration.cpp │ │ └── STMAccelCalibration.h │ ├── gyro-calibration │ │ ├── Android.bp │ │ ├── Android.mk │ │ ├── CMakeLists.txt │ │ ├── STMGyroCalibration.cpp │ │ └── STMGyroCalibration.h │ ├── gyro-temperature-calibration │ │ ├── Android.bp │ │ ├── Android.mk │ │ ├── CMakeLists.txt │ │ ├── STMGyroTempCalibration.cpp │ │ └── STMGyroTempCalibration.h │ ├── magn-calibration │ │ ├── Android.bp │ │ ├── Android.mk │ │ ├── CMakeLists.txt │ │ ├── STMMagnCalibration.cpp │ │ └── STMMagnCalibration.h │ ├── sensors-fusion │ │ ├── Android.bp │ │ ├── Android.mk │ │ ├── CMakeLists.txt │ │ ├── STMSensorsFusion.cpp │ │ ├── STMSensorsFusion.h │ │ ├── STMSensorsFusion6Axis.cpp │ │ ├── STMSensorsFusion6Axis.h │ │ ├── STMSensorsFusion9Axis.cpp │ │ └── STMSensorsFusion9Axis.h │ └── timesync │ │ ├── Android.bp │ │ ├── Android.mk │ │ ├── CMakeLists.txt │ │ ├── STMTimesync.cpp │ │ └── STMTimesync.h ├── readme.org ├── sensors_legacy.h ├── temp_struct_porting.h ├── utils.cpp └── utils.h ├── legacy ├── Android.mk ├── Convert.cpp ├── Convert.h ├── IConsole.cpp ├── IUtils.cpp ├── SensorsLegacyInterface.cpp ├── SensorsLegacyInterface.h ├── SensorsModule.cpp ├── halVersion.h └── readme.org ├── linux ├── CMakeLists.txt ├── IConsole.cpp ├── IUtils.cpp ├── LinuxPropertiesLoader.cpp ├── LinuxPropertiesLoader.h ├── SensorsLinuxInterface.cpp ├── SensorsLinuxInterface.h ├── cmake │ ├── toolchain-arm32.cmake │ └── toolchain-arm64.cmake ├── main.cpp └── readme.org ├── multi-hal ├── AdditionalInfoManager.cpp ├── AdditionalInfoManager.h ├── Android.bp ├── Convert.cpp ├── Convert.h ├── DirectChannel.cpp ├── DirectChannel.h ├── HalProxyCallbackWrapper.h ├── IConsole.cpp ├── IUtils.cpp ├── SensorsSubHal.cpp ├── SensorsSubHal.h └── readme.org └── readme.org /2.0/AdditionalInfoManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include "SensorPlacement.h" 25 | 26 | using ::android::hardware::sensors::V1_0::Event; 27 | using stm::core::STMSensorsList; 28 | 29 | struct AdditionalInfoManager { 30 | public: 31 | AdditionalInfoManager(const STMSensorsList &list); 32 | ~AdditionalInfoManager(void) = default; 33 | 34 | const std::vector getPayload(int sensorHandle, int64_t timestamp) const; 35 | 36 | bool isSupported(int sensorHandle) const; 37 | 38 | private: 39 | /** 40 | * Is additional info available for this sensor handle? 41 | */ 42 | std::vector supported; 43 | 44 | /** 45 | * Sensors placement data 46 | */ 47 | std::vector placements; 48 | 49 | Event makeSensorPlacementFrame(int sensorHandle, int serial, int64_t timestamp) const; 50 | 51 | static Event getBeginFrame(int sensorHandle, int64_t timestamp); 52 | 53 | static Event getEndFrame(int sensorHandle, int serial, int64_t timestamp); 54 | }; 55 | -------------------------------------------------------------------------------- /2.0/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2018 The Android Open Source Project 3 | // Copyright (C) 2019-2020 STMicroelectronics 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 | cc_binary { 18 | name: "android.hardware.sensors@2.0-service.stmicroelectronics", 19 | owner: "STMicroelectronics", 20 | relative_install_path: "hw", 21 | vendor: true, 22 | proprietary: true, 23 | init_rc: ["android.hardware.sensors@2.0-service-stmicroelectronics.rc"], 24 | vintf_fragments: ["android.hardware.sensors@2.0-stmicroelectronics.xml"], 25 | srcs: [ 26 | "service.cpp", 27 | "SensorsHidlInterface.cpp", 28 | "SensorsCallback.cpp", 29 | "Convert.cpp", 30 | "DirectChannel.cpp", 31 | "AdditionalInfoManager.cpp", 32 | ], 33 | static_libs: [ 34 | "stmicroelectronics-sensors.commons", 35 | "stmicroelectronics-sensors-core", 36 | "libstm-accel-calibration", 37 | "libstm-gyro-calibration", 38 | "libstm-gyro-temperature-calibration", 39 | "libstm-magn-calibration", 40 | "libstm-sensors-fusion", 41 | "libstm-timesync" 42 | ], 43 | shared_libs: [ 44 | "android.hardware.sensors@2.0", 45 | "android.hardware.sensors@1.0", 46 | "libhidlbase", 47 | "libcutils", 48 | "libpower", 49 | "libutils", 50 | "libfmq", 51 | "liblog", 52 | "libbase", 53 | ], 54 | export_static_lib_headers: [ 55 | "stmicroelectronics-sensors.commons", 56 | "stmicroelectronics-sensors-core" 57 | ], 58 | cflags: [ 59 | "-Wall", 60 | "-Wextra", 61 | "-Wpedantic", 62 | "-DHAL_ENABLE_DIRECT_REPORT_CHANNEL=1", 63 | "-DHAL_ENABLE_SENSOR_ADDITIONAL_INFO=1", 64 | "-DHAL_PRIVATE_DATA_PATH=\"/data/vendor/stm-sensors-hal\"" 65 | ], 66 | } 67 | -------------------------------------------------------------------------------- /2.0/Convert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace android { 25 | namespace hardware { 26 | namespace sensors { 27 | 28 | bool convertFromSTMSensorType(const stm::core::SensorType &type, 29 | V1_0::SensorType &sensorType); 30 | 31 | bool convertFromSTMSensor(const stm::core::STMSensor &src, 32 | V1_0::SensorInfo *dst); 33 | 34 | void convertFromSTMSensorData(const stm::core::ISTMSensorsCallbackData &sensorData, 35 | V1_0::Event &event); 36 | 37 | } // namespace sensors 38 | } // namespace hardware 39 | } // namespace android 40 | -------------------------------------------------------------------------------- /2.0/SensorsCallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include "SensorsCallback.h" 19 | 20 | namespace android { 21 | namespace hardware { 22 | namespace sensors { 23 | namespace V2_0 { 24 | namespace implementation { 25 | 26 | Return 27 | SensorsCallback::onDynamicSensorsConnected(const hidl_vec &sensorInfos) 28 | { 29 | (void) sensorInfos; 30 | // TODO implement 31 | return Void(); 32 | } 33 | 34 | Return 35 | SensorsCallback::onDynamicSensorsDisconnected(const hidl_vec &sensorHandles) 36 | { 37 | (void) sensorHandles; 38 | // TODO implement 39 | return Void(); 40 | } 41 | 42 | } // namespace implementation 43 | } // namespace V2_0 44 | } // namespace sensors 45 | } // namespace hardware 46 | } // namespace android 47 | -------------------------------------------------------------------------------- /2.0/SensorsCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace android { 25 | namespace hardware { 26 | namespace sensors { 27 | namespace V2_0 { 28 | namespace implementation { 29 | 30 | using ::android::hardware::hidl_array; 31 | using ::android::hardware::hidl_memory; 32 | using ::android::hardware::hidl_string; 33 | using ::android::hardware::hidl_vec; 34 | using ::android::hardware::Return; 35 | using ::android::hardware::Void; 36 | using ::android::sp; 37 | 38 | struct SensorsCallback : public ISensorsCallback { 39 | Return onDynamicSensorsConnected(const hidl_vec& sensorInfos) override; 40 | Return onDynamicSensorsDisconnected(const hidl_vec& sensorHandles) override; 41 | }; 42 | 43 | } // namespace implementation 44 | } // namespace V2_0 45 | } // namespace sensors 46 | } // namespace hardware 47 | } // namespace android 48 | -------------------------------------------------------------------------------- /2.0/android.hardware.sensors@2.0-service-stmicroelectronics.rc: -------------------------------------------------------------------------------- 1 | service vendor.sensors-hal-2.0-stmicroelectronics /vendor/bin/hw/android.hardware.sensors@2.0-service.stmicroelectronics 2 | class hal 3 | user system 4 | group system 5 | rlimit rtprio 10 10 6 | -------------------------------------------------------------------------------- /2.0/android.hardware.sensors@2.0-stmicroelectronics.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | android.hardware.sensors 4 | hwbinder 5 | 2.0 6 | 7 | ISensors 8 | default 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /2.0/service.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #define LOG_TAG "android.hardware.sensors@2.0-service" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "SensorsHidlInterface.h" 26 | 27 | using android::hardware::configureRpcThreadpool; 28 | using android::hardware::joinRpcThreadpool; 29 | using android::hardware::sensors::V2_0::ISensors; 30 | using android::hardware::sensors::V2_0::implementation::SensorsHidlInterface; 31 | 32 | int main(int /* argc */, char** /* argv */) 33 | { 34 | android::status_t err; 35 | 36 | configureRpcThreadpool(1, true); 37 | 38 | android::sp sensors = new SensorsHidlInterface(); 39 | err = sensors->registerAsService(); 40 | if (err != android::OK) { 41 | ALOGE("Failed to register STM Sensors-HAL instance"); 42 | return err; 43 | } 44 | 45 | joinRpcThreadpool(); 46 | 47 | return 1; 48 | } 49 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | Denis Ciocca 2 | -------------------------------------------------------------------------------- /aidl/AdditionalInfoManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include "SensorPlacement.h" 25 | 26 | using ::aidl::android::hardware::sensors::Event; 27 | using ::aidl::android::hardware::sensors::AdditionalInfo; 28 | using stm::core::STMSensorsList; 29 | 30 | struct AdditionalInfoManager { 31 | public: 32 | AdditionalInfoManager(const STMSensorsList &list); 33 | ~AdditionalInfoManager(void) = default; 34 | 35 | const std::vector getPayload(int sensorHandle, int64_t timestamp) const; 36 | 37 | bool isSupported(int sensorHandle) const; 38 | 39 | private: 40 | /** 41 | * Is additional info available for this sensor handle? 42 | */ 43 | std::vector supported; 44 | 45 | /** 46 | * Sensors placement data 47 | */ 48 | std::vector placements; 49 | 50 | Event makeSensorPlacementFrame(int sensorHandle, int serial, int64_t timestamp) const; 51 | 52 | static Event getBeginFrame(int sensorHandle, int64_t timestamp); 53 | 54 | static Event getEndFrame(int sensorHandle, int serial, int64_t timestamp); 55 | }; 56 | -------------------------------------------------------------------------------- /aidl/Android.bp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | cc_binary { 18 | name: "android.hardware.sensors@aidl-service.stmicroelectronics", 19 | relative_install_path: "hw", 20 | init_rc: ["android.hardware.sensors@aidl-service-stmicroelectronics.rc"], 21 | vintf_fragments: ["android.hardware.sensors@aidl-stmicroelectronics.xml"], 22 | vendor: true, 23 | enabled: false, 24 | owner: "STMicroelectronics", 25 | shared_libs: [ 26 | "libbase", 27 | "libbinder_ndk", 28 | "libfmq", 29 | "libpower", 30 | "libcutils", 31 | "liblog", 32 | "libutils", 33 | "android.hardware.sensors-V2-ndk", 34 | ], 35 | export_static_lib_headers: [ 36 | "stmicroelectronics-sensors-core", 37 | "stmicroelectronics-sensors.commons", 38 | ], 39 | static_libs: [ 40 | "stmicroelectronics-sensors.commons", 41 | "stmicroelectronics-sensors-core", 42 | "libstm-accel-calibration", 43 | "libstm-gyro-calibration", 44 | "libstm-gyro-temperature-calibration", 45 | "libstm-magn-calibration", 46 | "libstm-sensors-fusion", 47 | "libstm-timesync", 48 | ], 49 | srcs: [ 50 | "service.cpp", 51 | "SensorsAidlInterface.cpp", 52 | "AdditionalInfoManager.cpp", 53 | "Convert.cpp", 54 | "DirectChannel.cpp", 55 | "SensorsCallback.cpp", 56 | ], 57 | cflags: [ 58 | "-Wall", 59 | "-Wextra", 60 | "-DHAL_ENABLE_DIRECT_REPORT_CHANNEL=1", 61 | "-DHAL_ENABLE_SENSOR_ADDITIONAL_INFO=1", 62 | "-DHAL_PRIVATE_DATA_PATH=\"/data/vendor/stm-sensors-hal\"" 63 | ], 64 | } 65 | -------------------------------------------------------------------------------- /aidl/Convert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace android { 25 | namespace hardware { 26 | namespace sensors { 27 | namespace implementation { 28 | 29 | using aidl::android::hardware::sensors::Event; 30 | using aidl::android::hardware::sensors::SensorInfo; 31 | using aidl::android::hardware::sensors::SensorType; 32 | 33 | bool convertFromSTMSensorType(const stm::core::SensorType &type, 34 | SensorType &sensorType); 35 | 36 | bool convertFromSTMSensor(const stm::core::STMSensor &src, 37 | SensorInfo *dst); 38 | 39 | void convertFromSTMSensorData(const stm::core::ISTMSensorsCallbackData &sensorData, 40 | Event &event); 41 | 42 | } // namespace implementation 43 | } // namespace sensors 44 | } // namespace hardware 45 | } // namespace android 46 | 47 | -------------------------------------------------------------------------------- /aidl/SensorsCallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include "SensorsCallback.h" 19 | 20 | namespace aidl { 21 | namespace android { 22 | namespace hardware { 23 | namespace sensors { 24 | 25 | using ::ndk::ScopedAStatus; 26 | using ::aidl::android::hardware::sensors::SensorInfo; 27 | 28 | ScopedAStatus onDynamicSensorsConnected(const std::vector& in_sensorInfos) 29 | { 30 | (void) in_sensorInfos; 31 | 32 | // TODO implement 33 | return ScopedAStatus::ok(); 34 | } 35 | 36 | ScopedAStatus onDynamicSensorsDisconnected(const std::vector& in_sensorHandles) 37 | { 38 | (void) in_sensorHandles; 39 | 40 | // TODO implement 41 | return ScopedAStatus::ok(); 42 | } 43 | 44 | } // namespace sensors 45 | } // namespace hardware 46 | } // namespace android 47 | } // namespace aidl 48 | -------------------------------------------------------------------------------- /aidl/SensorsCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | //#include 22 | //#include 23 | 24 | namespace aidl { 25 | namespace android { 26 | namespace hardware { 27 | namespace sensors { 28 | 29 | using ::ndk::ScopedAStatus; 30 | using ::aidl::android::hardware::sensors::SensorInfo; 31 | 32 | struct SensorsCallback : public ISensorsCallback { 33 | ScopedAStatus onDynamicSensorsConnected(const std::vector& in_sensorInfos) override; 34 | ScopedAStatus onDynamicSensorsDisconnected(const std::vector& in_sensorHandles) override; 35 | }; 36 | 37 | } // namespace sensors 38 | } // namespace hardware 39 | } // namespace android 40 | } // namespace aidl 41 | -------------------------------------------------------------------------------- /aidl/android.hardware.sensors@aidl-service-stmicroelectronics.rc: -------------------------------------------------------------------------------- 1 | service vendor.sensors-hal-aidl-stmicroelectronics /vendor/bin/hw/android.hardware.sensors@aidl-service.stmicroelectronics 2 | class hal 3 | user system 4 | group system 5 | rlimit rtprio 10 10 6 | -------------------------------------------------------------------------------- /aidl/android.hardware.sensors@aidl-stmicroelectronics.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | android.hardware.sensors 4 | 2 5 | ISensors/default 6 | 7 | 8 | -------------------------------------------------------------------------------- /aidl/service.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "SensorsAidlInterface.h" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | using aidl::android::hardware::sensors::SensorsAidlInterface; 24 | 25 | int main() { 26 | ABinderProcess_setThreadPoolMaxThreadCount(0); 27 | 28 | // Make a default sensors service 29 | auto sensor = ndk::SharedRefBase::make(); 30 | const std::string sensorName = std::string() + SensorsAidlInterface::descriptor + "/default"; 31 | binder_status_t status = 32 | AServiceManager_addService(sensor->asBinder().get(), sensorName.c_str()); 33 | CHECK_EQ(status, STATUS_OK); 34 | 35 | ABinderProcess_joinThreadPool(); 36 | return EXIT_FAILURE; // should not reach 37 | } 38 | -------------------------------------------------------------------------------- /commons/Android.bp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | cc_library_static { 18 | name: "stmicroelectronics-sensors.commons", 19 | vendor: true, 20 | export_include_dirs: ["."], 21 | srcs: [ 22 | "IConsole.cpp", 23 | "AndroidPropertiesLoader.cpp", 24 | "SensorsDataProxyManager.cpp", 25 | "SensorPlacement.cpp", 26 | "IUtils.cpp", 27 | ], 28 | header_libs: [ 29 | "stmicroelectronics-sensors-common-includes", 30 | ], 31 | shared_libs: [ 32 | "libcutils", 33 | "liblog", 34 | "libutils", 35 | "libbase", 36 | ], 37 | } 38 | -------------------------------------------------------------------------------- /commons/AndroidPropertiesLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2022 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | 22 | using stm::core::PropertyId; 23 | using stm::core::SensorPropertyId; 24 | using stm::core::SensorType; 25 | 26 | class AndroidPropertiesLoader : public stm::core::PropertiesLoader { 27 | public: 28 | virtual int readInt(PropertyId property) const override; 29 | 30 | virtual std::string readString(SensorPropertyId property, 31 | SensorType sensorType) const override; 32 | 33 | virtual int readInt(SensorPropertyId property, 34 | SensorType sensorType) const override; 35 | }; 36 | -------------------------------------------------------------------------------- /commons/IConsole.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #define LOG_TAG "stm-sensors" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | using stm::core::IConsole; 27 | 28 | class Console : public IConsole { 29 | public: 30 | Console(void) = default; 31 | ~Console(void) = default; 32 | 33 | Console(const Console &) = delete; 34 | Console& operator= (const Console &) = delete; 35 | 36 | void info(const std::string &message) const override; 37 | 38 | void warning(const std::string &message) const override; 39 | 40 | void error(const std::string &message) const override; 41 | 42 | void debug(const std::string &message) const override; 43 | }; 44 | 45 | void Console::info(const std::string &message) const 46 | { 47 | std::string messageToPrint = message + "\n"; 48 | 49 | ALOGI("%s", messageToPrint.c_str()); 50 | } 51 | 52 | void Console::warning(const std::string &message) const 53 | { 54 | std::string messageToPrint = message + "\n"; 55 | 56 | ALOGW("%s", messageToPrint.c_str()); 57 | } 58 | 59 | void Console::error(const std::string &message) const 60 | { 61 | std::string messageToPrint = message + "\n"; 62 | 63 | ALOGE("%s", messageToPrint.c_str()); 64 | } 65 | 66 | void Console::debug(const std::string &message) const 67 | { 68 | std::string messageToPrint = message + "\n"; 69 | 70 | ALOGD("%s", messageToPrint.c_str()); 71 | } 72 | 73 | IConsole& IConsole::getInstance(void) 74 | { 75 | static Console instance; 76 | 77 | return instance; 78 | } 79 | -------------------------------------------------------------------------------- /commons/IUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include 19 | 20 | #include 21 | 22 | using stm::core::IUtils; 23 | 24 | class Utils : public IUtils { 25 | public: 26 | Utils(void) = default; 27 | ~Utils(void) = default; 28 | 29 | Utils(const Utils &) = delete; 30 | Utils& operator= (const Utils &) = delete; 31 | 32 | int64_t getTime(void) const override; 33 | }; 34 | 35 | int64_t Utils::getTime(void) const 36 | { 37 | return android::elapsedRealtimeNano(); 38 | } 39 | 40 | IUtils& IUtils::getInstance(void) 41 | { 42 | static Utils instance; 43 | 44 | return instance; 45 | } 46 | -------------------------------------------------------------------------------- /commons/SensorPlacement.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | struct SensorPlacement { 27 | public: 28 | SensorPlacement(void); 29 | ~SensorPlacement(void) = default; 30 | 31 | const std::array &getPayload(void) const; 32 | 33 | void loadFromProp(stm::core::SensorType sensorType); 34 | 35 | private: 36 | bool invertRotationMatrix(Matrix<3, 3, float>& matrix); 37 | 38 | /** 39 | * Sensor placement payload (4x3 matrix) 40 | */ 41 | std::array data; 42 | 43 | /** 44 | * Print console 45 | */ 46 | stm::core::IConsole &console = stm::core::IConsole::getInstance(); 47 | }; 48 | -------------------------------------------------------------------------------- /core/Accelerometer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | #include 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | /* 28 | * class Accelerometer 29 | */ 30 | class Accelerometer : public HWSensorBaseWithPollrate { 31 | public: 32 | Accelerometer(HWSensorBaseCommonData *data, const char *name, 33 | struct device_iio_sampling_freqs *sfa, int handle, 34 | unsigned int hw_fifo_len, float power_consumption, 35 | bool wakeup, int module); 36 | 37 | int64_t bias_last_pollrate; 38 | 39 | virtual int libsInit(void) override; 40 | 41 | virtual int Enable(int handle, bool enable, bool lock_en_mutex) override; 42 | virtual void ProcessData(SensorBaseData *data) override; 43 | virtual void postSetup(void) override; 44 | 45 | private: 46 | STMAccelCalibration& accelCalibration; 47 | 48 | void saveBiasValues(void) const; 49 | 50 | void loadBiasValues(void); 51 | 52 | Matrix<3, 3, float> rotMatrix; 53 | 54 | std::string biasFileName; 55 | }; 56 | 57 | } // namespace core 58 | } // namespace stm 59 | -------------------------------------------------------------------------------- /core/AccelerometerLimitedAxes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | #include 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | /* 28 | * class AccelerometerLimitedAxes 29 | */ 30 | class AccelerometerLimitedAxes : public HWSensorBaseWithPollrate { 31 | public: 32 | AccelerometerLimitedAxes(HWSensorBaseCommonData *data, const char *name, 33 | struct device_iio_sampling_freqs *sfa, int handle, 34 | unsigned int hw_fifo_len, float power_consumption, 35 | bool wakeup, int module, 36 | bool x_is_supp, bool y_is_supp, bool z_is_supp); 37 | 38 | int64_t bias_last_pollrate; 39 | 40 | virtual int libsInit(void) override; 41 | 42 | virtual int Enable(int handle, bool enable, bool lock_en_mutex) override; 43 | virtual void ProcessData(SensorBaseData *data) override; 44 | virtual void postSetup(void) override; 45 | 46 | private: 47 | STMAccelCalibration& accelCalibration; 48 | 49 | void saveBiasValues(void) const; 50 | 51 | void loadBiasValues(void); 52 | 53 | Matrix<3, 3, float> rotMatrix; 54 | 55 | std::string biasFileName; 56 | }; 57 | 58 | } // namespace core 59 | } // namespace stm 60 | -------------------------------------------------------------------------------- /core/ChangeODRTimestampStack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #define ST_ODR_STACK_MAX_ELEMENTS (20) 28 | 29 | /* 30 | * class ChangeODRTimestampStack 31 | */ 32 | class ChangeODRTimestampStack { 33 | private: 34 | pthread_mutex_t data_mutex; 35 | unsigned int elements_available; 36 | 37 | int64_t new_pollrate[ST_ODR_STACK_MAX_ELEMENTS]; 38 | int64_t timestamps[ST_ODR_STACK_MAX_ELEMENTS]; 39 | 40 | public: 41 | ChangeODRTimestampStack(); 42 | 43 | int writeElement(int64_t timestamp, int64_t newpollrate); 44 | int64_t readLastElement(int64_t *newpollrate); 45 | void removeLastElement(void); 46 | void resetBuffer(); 47 | }; 48 | -------------------------------------------------------------------------------- /core/CircularBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | typedef struct SensorBaseData { 29 | float raw[4]; 30 | float offset[4]; 31 | float processed[5]; 32 | int64_t timestamp; 33 | int64_t hwTimestamp; 34 | int8_t accuracy; 35 | std::array flushEventHandles; 36 | int flushEventsNum; 37 | int64_t pollrate_ns; 38 | bool hasHwTimestamp = false; 39 | } SensorBaseData; 40 | 41 | /* 42 | * class CircularBuffer 43 | */ 44 | class CircularBuffer { 45 | private: 46 | pthread_mutex_t data_mutex; 47 | unsigned int length, elements_available; 48 | 49 | SensorBaseData *data_sensor; 50 | SensorBaseData *first_available_element; 51 | SensorBaseData *first_free_element; 52 | 53 | public: 54 | CircularBuffer(unsigned int num_elements); 55 | ~CircularBuffer(); 56 | 57 | int writeElement(SensorBaseData *data); 58 | int readElement(SensorBaseData *data); 59 | int readSyncElement(SensorBaseData *data, int64_t timestamp_sync); 60 | void resetBuffer(); 61 | }; 62 | -------------------------------------------------------------------------------- /core/DeviceOrientation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2017-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "DeviceOrientation.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | DeviceOrientation::DeviceOrientation(HWSensorBaseCommonData *data, 28 | const char *name, 29 | struct device_iio_sampling_freqs *sfa, 30 | int handle, unsigned int hw_fifo_len, 31 | float power_consumption, bool wakeup, 32 | int module) 33 | : HWSensorBaseWithPollrate(data, name, sfa, handle, 34 | SensorType::DEVICE_ORIENTATION, 35 | hw_fifo_len, power_consumption, module) 36 | { 37 | (void) wakeup; 38 | 39 | sensor_event.data.dataLen = 1; 40 | } 41 | 42 | void DeviceOrientation::ProcessData(SensorBaseData *data) 43 | { 44 | sensor_event.data.data2[0] = data->raw[0]; 45 | sensor_event.timestamp = data->timestamp; 46 | 47 | HWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 48 | HWSensorBaseWithPollrate::ProcessData(data); 49 | } 50 | 51 | } // namespace core 52 | } // namespace stm 53 | -------------------------------------------------------------------------------- /core/DeviceOrientation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2017-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /* 26 | * class DeviceOrientation 27 | */ 28 | class DeviceOrientation : public HWSensorBaseWithPollrate { 29 | public: 30 | DeviceOrientation(HWSensorBaseCommonData *data, const char *name, 31 | struct device_iio_sampling_freqs *sfa, int handle, 32 | unsigned int hw_fifo_len, float power_consumption, 33 | bool wakeup, int module); 34 | 35 | virtual void ProcessData(SensorBaseData *data); 36 | }; 37 | 38 | } // namespace core 39 | } // namespace stm 40 | -------------------------------------------------------------------------------- /core/FlushBufferStack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #define ST_FLUSH_BUFFER_STACK_MAX_ELEMENTS (300) 28 | 29 | /* 30 | * class FlushBufferStack 31 | */ 32 | class FlushBufferStack { 33 | private: 34 | pthread_mutex_t data_mutex; 35 | unsigned int elements_available; 36 | 37 | int64_t flush_timestamps[ST_FLUSH_BUFFER_STACK_MAX_ELEMENTS]; 38 | int flush_handles[ST_FLUSH_BUFFER_STACK_MAX_ELEMENTS]; 39 | 40 | public: 41 | FlushBufferStack(); 42 | 43 | int writeElement(int handle, int64_t timestamp); 44 | int readLastElement(int64_t *timestamp); 45 | unsigned int ElemetsOnStack(); 46 | 47 | void removeLastElement(void); 48 | void resetBuffer(); 49 | }; 50 | -------------------------------------------------------------------------------- /core/Gesture.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2017-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "Gesture.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | Gesture::Gesture(HWSensorBaseCommonData *data, const char *name, int handle, 28 | unsigned int hw_fifo_len, float power_consumption, int module) 29 | : HWSensorBase(data, name, handle, TiltDetectorSensorType, 30 | hw_fifo_len, power_consumption, module) 31 | { 32 | sensor_t_data.resolution = 1.0f; 33 | sensor_t_data.maxRange = 1.0f; 34 | sensor_event.data.dataLen = 1; 35 | } 36 | 37 | void Gesture::ProcessEvent(struct device_iio_events *event_data) 38 | { 39 | sensor_event.data.data2[0] = 1.0f; 40 | sensor_event.timestamp = event_data->event_timestamp; 41 | 42 | HWSensorBase::WriteDataToPipe(0); 43 | HWSensorBase::ProcessEvent(event_data); 44 | } 45 | 46 | /* used to maintain compatibility with lsm6dsm */ 47 | void Gesture::ProcessData(SensorBaseData *data) 48 | { 49 | sensor_event.data.data2[0] = 1.0f; 50 | sensor_event.timestamp = data->timestamp; 51 | 52 | HWSensorBase::WriteDataToPipe(0); 53 | HWSensorBase::ProcessData(data); 54 | } 55 | 56 | } // namespace core 57 | } // namespace stm 58 | -------------------------------------------------------------------------------- /core/Gesture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2017-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /* 26 | * class Gesture 27 | */ 28 | class Gesture : public HWSensorBase { 29 | public: 30 | Gesture(HWSensorBaseCommonData *data, const char *name, int handle, 31 | unsigned int hw_fifo_len, float power_consumption, int module); 32 | 33 | virtual void ProcessEvent(struct device_iio_events *event_data); 34 | /* used to maintain compatibility with lsm6dsm */ 35 | virtual void ProcessData(SensorBaseData *data); 36 | }; 37 | 38 | } // namespace core 39 | } // namespace stm 40 | -------------------------------------------------------------------------------- /core/Gyroscope.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | #include 23 | #include 24 | 25 | namespace stm { 26 | namespace core { 27 | 28 | /* 29 | * class Gyroscope 30 | */ 31 | class Gyroscope : public HWSensorBaseWithPollrate { 32 | public: 33 | Gyroscope(HWSensorBaseCommonData *data, const char *name, 34 | struct device_iio_sampling_freqs *sfa, int handle, 35 | unsigned int hw_fifo_len, float power_consumption, 36 | bool wakeup, int module); 37 | 38 | int64_t bias_last_pollrate; 39 | 40 | virtual int libsInit(void) override; 41 | virtual int Enable(int handle, bool enable, bool lock_en_mutex) override; 42 | virtual void ProcessData(SensorBaseData *data) override; 43 | virtual void postSetup(void) override; 44 | 45 | private: 46 | STMGyroCalibration& gyroCalibration; 47 | STMGyroTempCalibration& gyroTempCalibration; 48 | 49 | void saveBiasValues(void) const; 50 | 51 | void loadBiasValues(void); 52 | 53 | Matrix<3, 3, float> rotMatrix; 54 | 55 | std::string biasFileName; 56 | std::string biasTFileName; 57 | 58 | /* for motion-gt */ 59 | int gyro_decimator; 60 | }; 61 | 62 | } // namespace core 63 | } // namespace stm 64 | -------------------------------------------------------------------------------- /core/GyroscopeLimitedAxes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | #include 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | /* 28 | * class GyroscopeLimitedAxes 29 | */ 30 | class GyroscopeLimitedAxes : public HWSensorBaseWithPollrate { 31 | public: 32 | GyroscopeLimitedAxes(HWSensorBaseCommonData *data, const char *name, 33 | struct device_iio_sampling_freqs *sfa, int handle, 34 | unsigned int hw_fifo_len, float power_consumption, 35 | bool wakeup, int module, 36 | bool x_is_supp, bool y_is_supp, bool z_is_supp); 37 | 38 | int64_t bias_last_pollrate; 39 | 40 | virtual int libsInit(void) override; 41 | virtual int Enable(int handle, bool enable, bool lock_en_mutex) override; 42 | virtual void ProcessData(SensorBaseData *data) override; 43 | virtual void postSetup(void) override; 44 | 45 | private: 46 | STMGyroCalibration& gyroCalibration; 47 | 48 | void saveBiasValues(void) const; 49 | 50 | void loadBiasValues(void); 51 | 52 | Matrix<3, 3, float> rotMatrix; 53 | 54 | std::string biasFileName; 55 | }; 56 | 57 | } // namespace core 58 | } // namespace stm 59 | -------------------------------------------------------------------------------- /core/ISTMSensorsCallbackData.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include 19 | 20 | namespace stm { 21 | namespace core { 22 | 23 | const std::vector& ISTMSensorsCallbackData::getData(void) const 24 | { 25 | return sensorsData; 26 | } 27 | 28 | int64_t ISTMSensorsCallbackData::getTimestamp(void) const 29 | { 30 | return timestamp; 31 | } 32 | 33 | SensorType ISTMSensorsCallbackData::getSensorType(void) const 34 | { 35 | return sensorType; 36 | } 37 | 38 | uint32_t ISTMSensorsCallbackData::getSensorHandle(void) const 39 | { 40 | return sensorHandle; 41 | } 42 | 43 | bool ISTMSensorsCallbackData::isWakeUpSensor(void) const 44 | { 45 | return wakeUpSensor; 46 | } 47 | 48 | } // namespace core 49 | } // namespace stm 50 | -------------------------------------------------------------------------------- /core/ISTMSensorsHAL.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include 19 | #include 20 | 21 | namespace stm { 22 | namespace core { 23 | 24 | ISTMSensorsHAL& ISTMSensorsHAL::getInstance(void) 25 | { 26 | return STMSensorsHAL::getInstance(); 27 | } 28 | 29 | } // namespace core 30 | } // namespace stm 31 | -------------------------------------------------------------------------------- /core/IntTemp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "IntTemp.h" 24 | 25 | namespace stm { 26 | namespace core { 27 | 28 | IntTemp::IntTemp(HWSensorBaseCommonData *data, const char *name, 29 | struct device_iio_sampling_freqs *sfa, 30 | int handle, unsigned int hw_fifo_len, 31 | float power_consumption, bool wakeup, int module) 32 | : HWSensorBaseWithPollrate(data, name, sfa, handle, 33 | IntTemperatureSensorType, 34 | hw_fifo_len, power_consumption, module) 35 | { 36 | (void)wakeup; 37 | 38 | sensor_t_data.resolution = std::fabs(data->channels[0].scale); 39 | sensor_t_data.maxRange = sensor_t_data.resolution * 40 | (std::pow(2, data->channels[0].bits_used) - 1); 41 | sensor_event.data.dataLen = 1; 42 | } 43 | 44 | void IntTemp::ProcessData(SensorBaseData *data) 45 | { 46 | sensor_event.data.data2[0] = data->raw[0]; 47 | sensor_event.timestamp = data->timestamp; 48 | 49 | HWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 50 | HWSensorBaseWithPollrate::ProcessData(data); 51 | } 52 | 53 | } // namespace core 54 | } // namespace stm 55 | -------------------------------------------------------------------------------- /core/IntTemp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /* 26 | * class IntTemp 27 | */ 28 | class IntTemp : public HWSensorBaseWithPollrate { 29 | public: 30 | IntTemp(HWSensorBaseCommonData *data, const char *name, 31 | struct device_iio_sampling_freqs *sfa, int handle, 32 | unsigned int hw_fifo_len, float power_consumption, 33 | bool wakeup, int module); 34 | 35 | virtual void ProcessData(SensorBaseData *data); 36 | }; 37 | 38 | } // namespace core 39 | } // namespace stm 40 | -------------------------------------------------------------------------------- /core/Magnetometer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | #include 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | /* 28 | * class Magnetometer 29 | */ 30 | class Magnetometer : public HWSensorBaseWithPollrate { 31 | public: 32 | Magnetometer(HWSensorBaseCommonData *data, const char *name, 33 | struct device_iio_sampling_freqs *sfa, int handle, 34 | unsigned int hw_fifo_len, float power_consumption, 35 | bool wakeup, int module); 36 | 37 | int64_t bias_last_pollrate; 38 | 39 | virtual int libsInit(void) override; 40 | 41 | virtual int Enable(int handle, bool enable, bool lock_en_mutex) override; 42 | virtual void ProcessData(SensorBaseData *data) override; 43 | virtual void postSetup(void) override; 44 | 45 | private: 46 | STMMagnCalibration& magnCalibration; 47 | 48 | void saveBiasValues(void) const; 49 | 50 | void loadBiasValues(void); 51 | 52 | Matrix<3, 3, float> rotMatrix; 53 | 54 | std::string biasFileName; 55 | }; 56 | 57 | } // namespace core 58 | } // namespace stm 59 | -------------------------------------------------------------------------------- /core/Pressure.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "Pressure.h" 24 | 25 | namespace stm { 26 | namespace core { 27 | 28 | Pressure::Pressure(HWSensorBaseCommonData *data, const char *name, 29 | struct device_iio_sampling_freqs *sfa, int handle, 30 | unsigned int hw_fifo_len, float power_consumption, 31 | bool wakeup, int module) 32 | : HWSensorBaseWithPollrate(data, name, sfa, handle, 33 | PressureSensorType, 34 | hw_fifo_len, power_consumption, module) 35 | { 36 | (void)wakeup; 37 | 38 | sensor_t_data.resolution = data->channels[0].scale; 39 | sensor_t_data.maxRange = sensor_t_data.resolution * (std::pow(2, data->channels[0].bits_used) - 1); 40 | sensor_event.data.dataLen = 1; 41 | } 42 | 43 | void Pressure::ProcessData(SensorBaseData *data) 44 | { 45 | sensor_event.data.data2[0] = data->raw[0]; 46 | sensor_event.timestamp = data->timestamp; 47 | 48 | HWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 49 | HWSensorBaseWithPollrate::ProcessData(data); 50 | } 51 | 52 | } // namespace core 53 | } // namespace stm 54 | -------------------------------------------------------------------------------- /core/Pressure.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /* 26 | * class Pressure 27 | */ 28 | class Pressure : public HWSensorBaseWithPollrate { 29 | public: 30 | Pressure(HWSensorBaseCommonData *data, const char *name, 31 | struct device_iio_sampling_freqs *sfa, int handle, 32 | unsigned int hw_fifo_len, float power_consumption, 33 | bool wakeup, int module); 34 | 35 | virtual void ProcessData(SensorBaseData *data); 36 | }; 37 | 38 | } // namespace core 39 | } // namespace stm 40 | -------------------------------------------------------------------------------- /core/PropertiesParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2022 STMicroelectronics 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 | #include 19 | 20 | #include "PropertiesParser.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | PropertiesParser::PropertiesParser(const std::string& text, int numElements) 26 | : valid(false) 27 | { 28 | const std::regex digitsRegex("[+-]?([0-9]*[.])?[0-9]+\\,*"); 29 | 30 | auto digitsBegin = std::sregex_iterator(text.begin(), 31 | text.end(), 32 | digitsRegex); 33 | 34 | auto digitsEnd = std::sregex_iterator(); 35 | 36 | for (std::sregex_iterator it = digitsBegin; it != digitsEnd; ++it) { 37 | std::smatch match = *it; 38 | std::size_t pos = match.str().find(','); 39 | 40 | if (pos != std::string::npos) { 41 | data.push_back(std::stof(match.str().substr(0, pos))); 42 | } else { 43 | data.push_back(std::stof(match.str())); 44 | } 45 | } 46 | 47 | if (data.size() == (uint)numElements) { 48 | valid = true; 49 | } 50 | } 51 | 52 | PropertiesParser PropertiesParser::makeRotationMatrixParser(std::string text) 53 | { 54 | PropertiesParser parser(text, 9); 55 | 56 | return parser; 57 | } 58 | 59 | PropertiesParser PropertiesParser::makeSensorPlacementParser(std::string text) 60 | { 61 | PropertiesParser parser(text, 3); 62 | 63 | return parser; 64 | } 65 | 66 | bool PropertiesParser::isValid() const 67 | { 68 | return valid; 69 | } 70 | 71 | const std::vector& PropertiesParser::getData() const 72 | { 73 | return data; 74 | } 75 | 76 | } // namespace core 77 | } // namespace stm 78 | -------------------------------------------------------------------------------- /core/PropertiesParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2022 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | namespace stm { 27 | namespace core { 28 | 29 | class PropertiesParser { 30 | public: 31 | static PropertiesParser makeRotationMatrixParser(std::string text); 32 | 33 | static PropertiesParser makeSensorPlacementParser(std::string text); 34 | 35 | bool isValid() const; 36 | 37 | const std::vector& getData() const; 38 | 39 | private: 40 | PropertiesParser() = delete; 41 | 42 | PropertiesParser(const std::string& text, int numElements); 43 | 44 | std::vector data; 45 | 46 | bool valid; 47 | }; 48 | 49 | } // namespace core 50 | } // namespace stm 51 | -------------------------------------------------------------------------------- /core/RHumidity.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2016-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "RHumidity.h" 24 | 25 | namespace stm { 26 | namespace core { 27 | 28 | RHumidity::RHumidity(HWSensorBaseCommonData *data, const char *name, 29 | struct device_iio_sampling_freqs *sfa, 30 | int handle, unsigned int hw_fifo_len, 31 | float power_consumption, bool wakeup, int module) 32 | : HWSensorBaseWithPollrate(data, name, sfa, handle, 33 | HumiditySensorType, 34 | hw_fifo_len, power_consumption, module) 35 | { 36 | (void)wakeup; 37 | 38 | sensor_t_data.resolution = std::fabs(data->channels[0].scale); 39 | sensor_t_data.maxRange = sensor_t_data.resolution * (std::pow(2, data->channels[0].bits_used) - 1); 40 | sensor_event.data.dataLen = 1; 41 | } 42 | 43 | void RHumidity::ProcessData(SensorBaseData *data) 44 | { 45 | sensor_event.data.data2[0] = data->raw[0]; 46 | sensor_event.timestamp = data->timestamp; 47 | 48 | HWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 49 | HWSensorBaseWithPollrate::ProcessData(data); 50 | } 51 | 52 | } // namespace core 53 | } // namespace stm 54 | -------------------------------------------------------------------------------- /core/RHumidity.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2016-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /* 26 | * class RHumidity 27 | */ 28 | class RHumidity : public HWSensorBaseWithPollrate { 29 | public: 30 | RHumidity(HWSensorBaseCommonData *data, const char *name, 31 | struct device_iio_sampling_freqs *sfa, int handle, 32 | unsigned int hw_fifo_len, float power_consumption, 33 | bool wakeup, int module); 34 | 35 | virtual void ProcessData(SensorBaseData *data); 36 | }; 37 | 38 | } // namespace core 39 | } // namespace stm 40 | -------------------------------------------------------------------------------- /core/STMSensorType.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include 19 | 20 | namespace stm { 21 | namespace core { 22 | 23 | STMSensorType::STMSensorType(SensorType type) 24 | : isInternalType(false), sType(type) 25 | { 26 | 27 | } 28 | 29 | STMSensorType::STMSensorType(SensorTypeInternal type) 30 | : isInternalType(true), sTypeInt(type) 31 | { 32 | 33 | } 34 | 35 | bool STMSensorType::isInternal(void) const 36 | { 37 | return isInternalType; 38 | } 39 | 40 | bool STMSensorType::operator==(const STMSensorType &other) const 41 | { 42 | if (other.isInternalType == isInternalType) { 43 | if (isInternalType) { 44 | return other.sTypeInt == sTypeInt; 45 | } else { 46 | return other.sType == sType; 47 | } 48 | } 49 | 50 | return false; 51 | } 52 | 53 | bool STMSensorType::operator!=(const STMSensorType &other) const 54 | { 55 | return !(*this == other); 56 | } 57 | 58 | } // namespace core 59 | } // namespace stm 60 | -------------------------------------------------------------------------------- /core/STMSensorsCallbackData.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include 19 | 20 | namespace stm { 21 | namespace core { 22 | 23 | STMSensorsCallbackData::STMSensorsCallbackData(uint32_t sensorHandle, 24 | SensorType sensorType, 25 | int64_t timestamp, 26 | const std::vector &data) 27 | { 28 | this->sensorHandle = sensorHandle; 29 | this->sensorType = sensorType; 30 | this->timestamp = timestamp; 31 | this->wakeUpSensor = false; 32 | this->sensorsData.assign(data.begin(), data.end()); 33 | } 34 | 35 | } // namespace core 36 | } // namespace stm 37 | -------------------------------------------------------------------------------- /core/STMSensorsCallbackData.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class STMSensorsCallbackData : public ISTMSensorsCallbackData { 26 | public: 27 | STMSensorsCallbackData(uint32_t sensorHandle, 28 | SensorType sensorType, 29 | int64_t timestamp, 30 | const std::vector &data); 31 | 32 | virtual ~STMSensorsCallbackData(void) {}; 33 | }; 34 | 35 | } // namespace core 36 | } // namespace stm 37 | -------------------------------------------------------------------------------- /core/STMSensorsList.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include 19 | #include 20 | 21 | namespace stm { 22 | namespace core { 23 | 24 | /** 25 | * addSensor: add new sensor to the list 26 | * @sensor: sensor reference to add 27 | * 28 | * Return value: true if added successfully, false in case of error. 29 | */ 30 | bool STMSensorsList::addSensor(STMSensor &sensor) 31 | { 32 | if (sensor.getMaxRange() == 0) { 33 | return false; 34 | } 35 | 36 | if ((sensor.getMinRateHz() < 0) || (sensor.getMaxRateHz() < sensor.getMinRateHz())) { 37 | return false; 38 | } 39 | 40 | if (sensor.getFifoMaxCount() < sensor.getFifoRsvdCount()) { 41 | return false; 42 | } 43 | 44 | for (auto &elem : list) { 45 | if (elem.getType() == sensor.getType()) { 46 | if (std::strcmp(elem.getName().c_str(), sensor.getName().c_str()) == 0) { 47 | return false; 48 | } 49 | } 50 | } 51 | 52 | sensor.setHandle(list.size() + 1); 53 | list.push_back(sensor); 54 | 55 | return true; 56 | } 57 | 58 | /** 59 | * getList: return current sensors list 60 | * 61 | * Return value: current sensors list reference. 62 | */ 63 | const std::vector& STMSensorsList::getList(void) const 64 | { 65 | return list; 66 | } 67 | 68 | void STMSensorsList::clear() 69 | { 70 | list.clear(); 71 | } 72 | 73 | } // namespace core 74 | } // namespace stm 75 | -------------------------------------------------------------------------------- /core/SWAccelGyroFusion6X.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include "SWSensorBase.h" 22 | 23 | #include 24 | 25 | namespace stm { 26 | namespace core { 27 | 28 | class SWAccelGyroFusion6X : public SWSensorBaseWithPollrate { 29 | protected: 30 | SensorBaseData outdata; 31 | IUtils &utils { IUtils::getInstance() }; 32 | 33 | public: 34 | SWAccelGyroFusion6X(const char *name, int handle, int module); 35 | 36 | virtual int CustomInit(); 37 | 38 | virtual int libsInit(void) override; 39 | 40 | virtual int Enable(int handle, bool enable, bool lock_en_mutex) override; 41 | virtual int SetDelay(int handle, int64_t period_ns, int64_t timeout, bool lock_en_mutex) override; 42 | virtual void ProcessData(SensorBaseData *data) override; 43 | 44 | private: 45 | STMSensorsFusion6Axis& sensorsFusion; 46 | }; 47 | 48 | } // namespace core 49 | } // namespace stm 50 | -------------------------------------------------------------------------------- /core/SWAccelMagnGyroFusion9X.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "SWSensorBase.h" 21 | 22 | #include 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | class SWAccelMagnGyroFusion9X : public SWSensorBaseWithPollrate { 28 | protected: 29 | SensorBaseData outdata; 30 | 31 | public: 32 | SWAccelMagnGyroFusion9X(const char *name, int handle, int module); 33 | 34 | virtual int CustomInit(); 35 | 36 | virtual int libsInit(void) override; 37 | 38 | virtual int Enable(int handle, bool enable, bool lock_en_mutex) override; 39 | virtual int SetDelay(int handle, int64_t period_ns, int64_t timeout, bool lock_en_mutex) override; 40 | virtual void ProcessData(SensorBaseData *data) override; 41 | 42 | private: 43 | STMSensorsFusion9Axis& sensorsFusion; 44 | }; 45 | 46 | } // namespace core 47 | } // namespace stm 48 | -------------------------------------------------------------------------------- /core/SWAccelerometerLimitedAxesUncalibrated.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2017-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "SWAccelerometerLimitedAxesUncalibrated.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | SWAccelerometerLimitedAxesUncalibrated::SWAccelerometerLimitedAxesUncalibrated(const char *name, int handle, int module) 28 | : SWSensorBaseWithPollrate(name, handle, 29 | AccelSensorLimitedAxisUncalibratedType, 30 | true, true, true, true, 31 | module) 32 | { 33 | dependencies_type_list.push_back(AccelSensorLimitedAxisType); 34 | id_sensor_trigger = SENSOR_DEPENDENCY_ID_0; 35 | 36 | sensor_event.data.dataLen = 9; 37 | } 38 | 39 | void SWAccelerometerLimitedAxesUncalibrated::ProcessData(SensorBaseData *data) 40 | { 41 | int axes; 42 | 43 | memcpy(sensor_event.data.data2, data->raw, SENSOR_DATA_3AXIS * sizeof(float)); 44 | memcpy(sensor_event.data.data2 + 3, data->offset, SENSOR_DATA_3AXIS * sizeof(float)); 45 | 46 | axes = SensorBase::getSupportedAxes(); 47 | 48 | sensor_event.data.data2[6] = (float)(axes & 0x01); 49 | sensor_event.data.data2[7] = (float)((axes >> 1) & 0x01); 50 | sensor_event.data.data2[8] = (float)((axes >> 2) & 0x01); 51 | sensor_event.timestamp = data->timestamp; 52 | 53 | SWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 54 | SWSensorBaseWithPollrate::ProcessData(data); 55 | } 56 | 57 | } // namespace core 58 | } // namespace stm 59 | -------------------------------------------------------------------------------- /core/SWAccelerometerLimitedAxesUncalibrated.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2017-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "SWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class SWAccelerometerLimitedAxesUncalibrated : public SWSensorBaseWithPollrate { 26 | public: 27 | SWAccelerometerLimitedAxesUncalibrated(const char *name, int handle, int module); 28 | 29 | virtual void ProcessData(SensorBaseData *data); 30 | }; 31 | 32 | } // namespace core 33 | } // namespace stm 34 | -------------------------------------------------------------------------------- /core/SWAccelerometerUncalibrated.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2017-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "SWAccelerometerUncalibrated.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | SWAccelerometerUncalibrated::SWAccelerometerUncalibrated(const char *name, int handle, int module) 28 | : SWSensorBaseWithPollrate(name, handle, 29 | AccelUncalibSensorType, 30 | true, true, true, true, 31 | module) 32 | { 33 | dependencies_type_list.push_back(AccelSensorType); 34 | id_sensor_trigger = SENSOR_DEPENDENCY_ID_0; 35 | 36 | sensor_event.data.dataLen = 6; 37 | } 38 | 39 | void SWAccelerometerUncalibrated::ProcessData(SensorBaseData *data) 40 | { 41 | memcpy(sensor_event.data.data2, data->raw, SENSOR_DATA_3AXIS * sizeof(float)); 42 | memcpy(sensor_event.data.data2 + 3, data->offset, SENSOR_DATA_3AXIS * sizeof(float)); 43 | sensor_event.timestamp = data->timestamp; 44 | 45 | SWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 46 | SWSensorBaseWithPollrate::ProcessData(data); 47 | } 48 | 49 | } // namespace core 50 | } // namespace stm 51 | -------------------------------------------------------------------------------- /core/SWAccelerometerUncalibrated.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2017-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "SWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class SWAccelerometerUncalibrated : public SWSensorBaseWithPollrate { 26 | public: 27 | SWAccelerometerUncalibrated(const char *name, int handle, int module); 28 | 29 | virtual void ProcessData(SensorBaseData *data); 30 | }; 31 | 32 | } // namespace core 33 | } // namespace stm 34 | -------------------------------------------------------------------------------- /core/SWGameRotationVector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * STMicroelectronics SW Game Rotation Vector Sensor Class 3 | * 4 | * Copyright 2015-2020 STMicroelectronics Inc. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"). 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "SWGameRotationVector.h" 14 | 15 | namespace stm { 16 | namespace core { 17 | 18 | SWGameRotationVector::SWGameRotationVector(const char *name, int handle, int module) 19 | : SWSensorBaseWithPollrate(name, handle, 20 | GameRotationVecSensorType, 21 | true, true, true, false, module) 22 | { 23 | dependencies_type_list.push_back(AccelGyroFusion6XSensorType); 24 | id_sensor_trigger = SENSOR_DEPENDENCY_ID_0; 25 | sensor_event.data.dataLen = SENSOR_DATA_4AXIS; 26 | } 27 | 28 | void SWGameRotationVector::ProcessData(SensorBaseData *data) 29 | { 30 | memcpy(sensor_event.data.data2, data->processed, SENSOR_DATA_4AXIS_ACCUR * sizeof(float)); 31 | sensor_event.timestamp = data->timestamp; 32 | 33 | SWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 34 | SWSensorBaseWithPollrate::ProcessData(data); 35 | } 36 | 37 | } // namespace core 38 | } // namespace stm 39 | -------------------------------------------------------------------------------- /core/SWGameRotationVector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2020 STMicroelectronics 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "SWSensorBase.h" 20 | 21 | namespace stm { 22 | namespace core { 23 | 24 | class SWGameRotationVector : public SWSensorBaseWithPollrate { 25 | public: 26 | SWGameRotationVector(const char *name, int handle, int module); 27 | 28 | virtual void ProcessData(SensorBaseData *data); 29 | }; 30 | 31 | } // namespace core 32 | } // namespace stm 33 | -------------------------------------------------------------------------------- /core/SWGravity.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "SWGravity.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | SWGravity::SWGravity(const char *name, int handle, int module) 28 | : SWSensorBaseWithPollrate(name, handle, 29 | GravitySensorType, 30 | true, false, true, false, module) 31 | { 32 | sensor_t_data.maxRange = ST_HAL_GRAVITY_MAX_ON_EARTH; 33 | 34 | dependencies_type_list.push_back(AccelGyroFusion6XSensorType); 35 | id_sensor_trigger = SENSOR_DEPENDENCY_ID_0; 36 | sensor_event.data.dataLen = SENSOR_DATA_3AXIS; 37 | } 38 | 39 | void SWGravity::ProcessData(SensorBaseData *data) 40 | { 41 | memcpy(sensor_event.data.data2, data->processed, SENSOR_DATA_3AXIS * sizeof(float)); 42 | sensor_event.timestamp = data->timestamp; 43 | 44 | SWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 45 | SWSensorBaseWithPollrate::ProcessData(data); 46 | } 47 | 48 | } // namespace core 49 | } // namespace stm 50 | -------------------------------------------------------------------------------- /core/SWGravity.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "SWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class SWGravity : public SWSensorBaseWithPollrate { 26 | public: 27 | SWGravity(const char *name, int handle, int module); 28 | 29 | virtual void ProcessData(SensorBaseData *data); 30 | }; 31 | 32 | } // namespace core 33 | } // namespace stm 34 | -------------------------------------------------------------------------------- /core/SWGyroLimitedAxesUncalibrated.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "SWGyroLimitedAxesUncalibrated.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | SWGyroLimitedAxesUncalibrated::SWGyroLimitedAxesUncalibrated(const char *name, int handle, int module) 28 | : SWSensorBaseWithPollrate(name, handle, 29 | GyroSensorLimitedAxisUncalibratedType, 30 | true, true, true, true, module) 31 | { 32 | dependencies_type_list.push_back(GyroSensorLimitedAxisType); 33 | id_sensor_trigger = SENSOR_DEPENDENCY_ID_0; 34 | sensor_event.data.dataLen = 9; 35 | } 36 | 37 | void SWGyroLimitedAxesUncalibrated::ProcessData(SensorBaseData *data) 38 | { 39 | int axes; 40 | 41 | memcpy(sensor_event.data.data2, data->raw, SENSOR_DATA_3AXIS * sizeof(float)); 42 | memcpy(sensor_event.data.data2 + 3, data->offset, SENSOR_DATA_3AXIS * sizeof(float)); 43 | 44 | axes = SensorBase::getSupportedAxes(); 45 | 46 | sensor_event.data.data2[6] = (float)(axes & 0x01); 47 | sensor_event.data.data2[7] = (float)((axes >> 1) & 0x01); 48 | sensor_event.data.data2[8] = (float)((axes >> 2) & 0x01); 49 | sensor_event.timestamp = data->timestamp; 50 | 51 | SWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 52 | SWSensorBaseWithPollrate::ProcessData(data); 53 | } 54 | 55 | } // namespace core 56 | } // namespace stm 57 | -------------------------------------------------------------------------------- /core/SWGyroLimitedAxesUncalibrated.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "SWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class SWGyroLimitedAxesUncalibrated : public SWSensorBaseWithPollrate { 26 | public: 27 | SWGyroLimitedAxesUncalibrated(const char *name, int handle, int module); 28 | 29 | virtual void ProcessData(SensorBaseData *data); 30 | }; 31 | 32 | } // namespace core 33 | } // namespace stm 34 | -------------------------------------------------------------------------------- /core/SWGyroscopeUncalibrated.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "SWGyroscopeUncalibrated.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | SWGyroscopeUncalibrated::SWGyroscopeUncalibrated(const char *name, int handle, int module) 28 | : SWSensorBaseWithPollrate(name, handle, 29 | GyroUncalibSensorType, 30 | true, true, true, true, module) 31 | { 32 | dependencies_type_list.push_back(GyroSensorType); 33 | id_sensor_trigger = SENSOR_DEPENDENCY_ID_0; 34 | sensor_event.data.dataLen = 6; 35 | } 36 | 37 | void SWGyroscopeUncalibrated::ProcessData(SensorBaseData *data) 38 | { 39 | memcpy(sensor_event.data.data2, data->raw, SENSOR_DATA_3AXIS * sizeof(float)); 40 | memcpy(sensor_event.data.data2 + 3, data->offset, SENSOR_DATA_3AXIS * sizeof(float)); 41 | sensor_event.timestamp = data->timestamp; 42 | 43 | SWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 44 | SWSensorBaseWithPollrate::ProcessData(data); 45 | } 46 | 47 | } // namespace core 48 | } // namespace stm 49 | -------------------------------------------------------------------------------- /core/SWGyroscopeUncalibrated.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "SWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class SWGyroscopeUncalibrated : public SWSensorBaseWithPollrate { 26 | public: 27 | SWGyroscopeUncalibrated(const char *name, int handle, int module); 28 | 29 | virtual void ProcessData(SensorBaseData *data); 30 | }; 31 | 32 | } // namespace core 33 | } // namespace stm 34 | -------------------------------------------------------------------------------- /core/SWLinearAccel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "SWLinearAccel.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | SWLinearAccel::SWLinearAccel(const char *name, int handle, int module) 28 | : SWSensorBaseWithPollrate(name, handle, 29 | LinearAccelSensorType, 30 | true, false, true, false, module) 31 | { 32 | sensor_t_data.maxRange = ST_HAL_GRAVITY_MAX_ON_EARTH; 33 | 34 | dependencies_type_list.push_back(AccelGyroFusion6XSensorType); 35 | id_sensor_trigger = SENSOR_DEPENDENCY_ID_0; 36 | sensor_event.data.dataLen = SENSOR_DATA_3AXIS; 37 | } 38 | 39 | int SWLinearAccel::CustomInit() 40 | { 41 | bool valid; 42 | float maxRange = 0; 43 | 44 | valid = GetDependencyMaxRange(AccelSensorType, &maxRange); 45 | if (!valid) { 46 | return -EINVAL; 47 | } 48 | 49 | sensor_t_data.maxRange = maxRange; 50 | 51 | return 0; 52 | } 53 | 54 | void SWLinearAccel::ProcessData(SensorBaseData *data) 55 | { 56 | memcpy(sensor_event.data.data2, data->processed, SENSOR_DATA_3AXIS * sizeof(float)); 57 | sensor_event.timestamp = data->timestamp; 58 | 59 | SWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 60 | SWSensorBaseWithPollrate::ProcessData(data); 61 | } 62 | 63 | } // namespace core 64 | } // namespace stm 65 | -------------------------------------------------------------------------------- /core/SWLinearAccel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "SWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class SWLinearAccel : public SWSensorBaseWithPollrate { 26 | public: 27 | SWLinearAccel(const char *name, int handle, int module); 28 | 29 | virtual int CustomInit(); 30 | virtual void ProcessData(SensorBaseData *data); 31 | }; 32 | 33 | } // namespace core 34 | } // namespace stm 35 | -------------------------------------------------------------------------------- /core/SWMagnetometerUncalibrated.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "SWMagnetometerUncalibrated.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | SWMagnetometerUncalibrated::SWMagnetometerUncalibrated(const char *name, int handle, int module) 28 | : SWSensorBaseWithPollrate(name, handle, 29 | MagnUncalibSensorType, 30 | true, true, true, true, module) 31 | { 32 | dependencies_type_list.push_back(MagnSensorType); 33 | id_sensor_trigger = SENSOR_DEPENDENCY_ID_0; 34 | sensor_event.data.dataLen = 6; 35 | } 36 | 37 | void SWMagnetometerUncalibrated::ProcessData(SensorBaseData *data) 38 | { 39 | memcpy(sensor_event.data.data2, data->raw, SENSOR_DATA_3AXIS * sizeof(float)); 40 | memcpy(sensor_event.data.data2 + 3, data->offset, SENSOR_DATA_3AXIS * sizeof(float)); 41 | sensor_event.timestamp = data->timestamp; 42 | 43 | SWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 44 | SWSensorBaseWithPollrate::ProcessData(data); 45 | } 46 | 47 | } // namespace core 48 | } // namespace stm 49 | -------------------------------------------------------------------------------- /core/SWMagnetometerUncalibrated.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "SWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class SWMagnetometerUncalibrated : public SWSensorBaseWithPollrate { 26 | public: 27 | SWMagnetometerUncalibrated(const char *name, int handle, int module); 28 | 29 | virtual void ProcessData(SensorBaseData *data); 30 | }; 31 | 32 | } // namespace core 33 | } // namespace stm 34 | -------------------------------------------------------------------------------- /core/SWOrientation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "SWOrientation.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | SWOrientation::SWOrientation(const char *name, int handle, int module) 28 | : SWSensorBaseWithPollrate(name, handle, 29 | OrientationSensorType, 30 | true, false, true, false, module) 31 | { 32 | sensor_t_data.maxRange = 360.0f; 33 | 34 | dependencies_type_list.push_back(AccelMagnGyroFusion9XSensorType); 35 | id_sensor_trigger = SENSOR_DEPENDENCY_ID_0; 36 | sensor_event.data.dataLen = SENSOR_DATA_3AXIS; 37 | } 38 | 39 | void SWOrientation::ProcessData(SensorBaseData *data) 40 | { 41 | memcpy(sensor_event.data.data2, data->processed, SENSOR_DATA_3AXIS * sizeof(float)); 42 | //sensor_event.orientation.status = data->accuracy; 43 | sensor_event.timestamp = data->timestamp; 44 | 45 | SWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 46 | SWSensorBaseWithPollrate::ProcessData(data); 47 | } 48 | 49 | } // namespace core 50 | } // namespace stm 51 | -------------------------------------------------------------------------------- /core/SWOrientation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "SWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class SWOrientation : public SWSensorBaseWithPollrate { 26 | public: 27 | SWOrientation(const char *name, int handle, int module); 28 | 29 | virtual void ProcessData(SensorBaseData *data); 30 | }; 31 | 32 | } // namespace core 33 | } // namespace stm 34 | -------------------------------------------------------------------------------- /core/SWRotationVector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "SWRotationVector.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | SWRotationVector::SWRotationVector(const char *name, int handle, int module) 28 | : SWSensorBaseWithPollrate(name, handle, 29 | RotationVecSensorType, 30 | true, true, true, false, module) 31 | { 32 | dependencies_type_list.push_back(AccelMagnGyroFusion9XSensorType); 33 | id_sensor_trigger = SENSOR_DEPENDENCY_ID_0; 34 | sensor_event.data.dataLen = SENSOR_DATA_4AXIS; 35 | } 36 | 37 | void SWRotationVector::ProcessData(SensorBaseData *data) 38 | { 39 | memcpy(sensor_event.data.data2, data->processed, SENSOR_DATA_4AXIS_ACCUR * sizeof(float)); 40 | sensor_event.timestamp = data->timestamp; 41 | 42 | SWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 43 | SWSensorBaseWithPollrate::ProcessData(data); 44 | } 45 | 46 | } // namespace core 47 | } // namespace stm 48 | -------------------------------------------------------------------------------- /core/SWRotationVector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2016 STMicroelectronics 3 | * Author: Denis Ciocca - 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 | #pragma once 19 | 20 | #include "SWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class SWRotationVector : public SWSensorBaseWithPollrate { 26 | public: 27 | SWRotationVector(const char *name, int handle, int module); 28 | 29 | virtual void ProcessData(SensorBaseData *data); 30 | }; 31 | 32 | } // namespace core 33 | } // namespace stm 34 | -------------------------------------------------------------------------------- /core/SelfTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | namespace stm { 21 | namespace core { 22 | 23 | typedef enum { 24 | NOT_AVAILABLE = 0, 25 | GENERIC_ERROR, 26 | FAILURE, 27 | PASS 28 | } selftest_status; 29 | 30 | struct selftest_cmd_t { 31 | int handle; 32 | short mode; 33 | }; 34 | 35 | struct selftest_results_t { 36 | int handle; 37 | selftest_status status; 38 | }; 39 | 40 | /* 41 | * class SelfTest 42 | */ 43 | class SelfTest { 44 | private: 45 | struct STSensorHAL_data *hal_data; 46 | bool valid_class; 47 | int fd_cmd, fd_results; 48 | pthread_t cmd_thread; 49 | 50 | static void *ThreadCmdWork(void *context); 51 | void ThreadCmdTask(); 52 | 53 | public: 54 | SelfTest(struct STSensorHAL_data *ST_hal_data); 55 | virtual ~SelfTest(); 56 | 57 | bool IsValidClass(); 58 | }; 59 | 60 | } // namespace core 61 | } // namespace stm 62 | -------------------------------------------------------------------------------- /core/SensorTypeInternal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /** 26 | * Sensors core internal types 27 | */ 28 | enum class SensorTypeInternal : uint16_t { 29 | ACCEL_GYRO_FUSION_6X, /* ACCEL AND GYRO FUSION */ 30 | ACCEL_MAGN_GYRO_FUSION_9X, /* ACCEL, MAGN AND GYRO FUSION */ 31 | }; 32 | 33 | } // namespace core 34 | } // namespace stm 35 | -------------------------------------------------------------------------------- /core/SignificantMotion.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "SignificantMotion.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | SignMotion::SignMotion(HWSensorBaseCommonData *data, const char *name, int handle, 28 | float power_consumption, int module) 29 | : HWSensorBase(data, name, handle, 30 | SignMotionSensorType, 0, power_consumption, module) 31 | { 32 | sensor_t_data.resolution = 1.0f; 33 | sensor_t_data.maxRange = 1.0f; 34 | sensor_event.data.dataLen = 1; 35 | } 36 | 37 | int SignMotion::FlushData(int __attribute__((unused))handle, bool __attribute__((unused))lock_en_mutex) 38 | { 39 | return -EINVAL; 40 | } 41 | 42 | int SignMotion::SetDelay(int __attribute__((unused))handle, 43 | int64_t __attribute__((unused))period_ns, 44 | int64_t __attribute__((unused))timeout, 45 | bool __attribute__((unused))lock_en_mutex) 46 | { 47 | return 0; 48 | } 49 | 50 | void SignMotion::ProcessEvent(struct device_iio_events *event_data) 51 | { 52 | sensor_event.data.data2[0] = 1.0f; 53 | sensor_event.timestamp = event_data->event_timestamp; 54 | 55 | HWSensorBase::WriteDataToPipe(0); 56 | HWSensorBase::ProcessEvent(event_data); 57 | Enable(sensor_t_data.handle, false, true); 58 | } 59 | 60 | } // namespace core 61 | } // namespace stm 62 | -------------------------------------------------------------------------------- /core/SignificantMotion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /* 26 | * class SignMotion 27 | */ 28 | class SignMotion : public HWSensorBase { 29 | public: 30 | SignMotion(HWSensorBaseCommonData *data, const char *name, int handle, 31 | float power_consumption, int module); 32 | 33 | virtual int FlushData(int handle, bool lock_en_mutex); 34 | virtual int SetDelay(int handle, int64_t period_ns, int64_t timeout, 35 | bool lock_en_mutex); 36 | virtual void ProcessEvent(struct device_iio_events *event_data); 37 | }; 38 | 39 | } // namespace core 40 | } // namespace stm 41 | -------------------------------------------------------------------------------- /core/StepCounter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /* 26 | * class StepCounter 27 | */ 28 | class StepCounter : public HWSensorBase { 29 | public: 30 | StepCounter(HWSensorBaseCommonData *data, const char *name, int handle, 31 | unsigned int hw_fifo_len, float power_consumption, 32 | bool wakeup, int module); 33 | 34 | virtual int Enable(int handle, bool enable, bool lock_en_mutex); 35 | virtual int SetDelay(int handle, int64_t period_ns, int64_t timeout, 36 | bool lock_en_mutex); 37 | virtual void ProcessData(SensorBaseData *data); 38 | }; 39 | 40 | } // namespace core 41 | } // namespace stm 42 | -------------------------------------------------------------------------------- /core/StepDetector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "StepDetector.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | StepDetector::StepDetector(HWSensorBaseCommonData *data, const char *name, 28 | int handle, unsigned int hw_fifo_len, 29 | float power_consumption, bool wakeup, int module) 30 | : HWSensorBase(data, name, handle, 31 | StepDetectorSensorType, hw_fifo_len, power_consumption, module) 32 | { 33 | (void)wakeup; 34 | 35 | sensor_t_data.resolution = 1.0f; 36 | sensor_t_data.maxRange = 1.0f; 37 | sensor_event.data.dataLen = 1; 38 | } 39 | 40 | int StepDetector::SetDelay(int __attribute__((unused))handle, 41 | int64_t __attribute__((unused))period_ns, 42 | int64_t __attribute__((unused))timeout, 43 | bool __attribute__((unused))lock_en_mute) 44 | { 45 | return 0; 46 | } 47 | 48 | void StepDetector::ProcessData(SensorBaseData *data) 49 | { 50 | sensor_event.data.data2[0] = 1.0f; 51 | sensor_event.timestamp = data->timestamp; 52 | 53 | HWSensorBase::WriteDataToPipe(0); 54 | HWSensorBase::ProcessData(data); 55 | } 56 | 57 | void StepDetector::ProcessEvent(struct device_iio_events *event_data) 58 | { 59 | sensor_event.data.data2[0] = 1.0f; 60 | sensor_event.timestamp = event_data->event_timestamp; 61 | 62 | HWSensorBase::WriteDataToPipe(0); 63 | HWSensorBase::ProcessEvent(event_data); 64 | } 65 | 66 | } // namespace core 67 | } // namespace stm 68 | -------------------------------------------------------------------------------- /core/StepDetector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /* 26 | * class StepDetector 27 | */ 28 | class StepDetector : public HWSensorBase { 29 | public: 30 | StepDetector(HWSensorBaseCommonData *data, const char *name, int handle, 31 | unsigned int hw_fifo_len, float power_consumption, 32 | bool wakeup, int module); 33 | 34 | virtual int SetDelay(int handle, int64_t period_ns, int64_t timeout, 35 | bool lock_en_mute); 36 | virtual void ProcessData(SensorBaseData *data); 37 | void ProcessEvent(struct device_iio_events *event_data); 38 | }; 39 | 40 | } // namespace core 41 | } // namespace stm 42 | -------------------------------------------------------------------------------- /core/Temp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "Temp.h" 24 | 25 | namespace stm { 26 | namespace core { 27 | 28 | Temp::Temp(HWSensorBaseCommonData *data, const char *name, 29 | struct device_iio_sampling_freqs *sfa, 30 | int handle, unsigned int hw_fifo_len, 31 | float power_consumption, bool wakeup, int module) 32 | : HWSensorBaseWithPollrate(data, name, sfa, handle, 33 | AmbTemperatureSensorType, 34 | hw_fifo_len, power_consumption, module) 35 | { 36 | (void)wakeup; 37 | 38 | sensor_t_data.resolution = std::fabs(data->channels[0].scale); 39 | sensor_t_data.maxRange = sensor_t_data.resolution * (std::pow(2, data->channels[0].bits_used) - 1); 40 | sensor_event.data.dataLen = 1; 41 | } 42 | 43 | void Temp::ProcessData(SensorBaseData *data) 44 | { 45 | sensor_event.data.data2[0] = data->raw[0]; 46 | sensor_event.timestamp = data->timestamp; 47 | 48 | HWSensorBaseWithPollrate::WriteDataToPipe(data->pollrate_ns); 49 | HWSensorBaseWithPollrate::ProcessData(data); 50 | } 51 | 52 | } // namespace core 53 | } // namespace stm 54 | -------------------------------------------------------------------------------- /core/Temp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /* 26 | * class Temp 27 | */ 28 | class Temp : public HWSensorBaseWithPollrate { 29 | public: 30 | Temp(HWSensorBaseCommonData *data, const char *name, 31 | struct device_iio_sampling_freqs *sfa, int handle, 32 | unsigned int hw_fifo_len, float power_consumption, bool wakeup, int module); 33 | 34 | virtual void ProcessData(SensorBaseData *data); 35 | }; 36 | 37 | } // namespace core 38 | } // namespace stm 39 | -------------------------------------------------------------------------------- /core/TiltSensor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "TiltSensor.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | TiltSensor::TiltSensor(HWSensorBaseCommonData *data, const char *name, int handle, 28 | unsigned int hw_fifo_len, float power_consumption, int module) 29 | : HWSensorBase(data, name, handle, 30 | TiltDetectorSensorType, hw_fifo_len, 31 | power_consumption, module) 32 | { 33 | sensor_t_data.resolution = 1.0f; 34 | sensor_t_data.maxRange = 1.0f; 35 | sensor_event.data.dataLen = 1; 36 | } 37 | 38 | int TiltSensor::SetDelay(int __attribute__((unused))handle, 39 | int64_t __attribute__((unused))period_ns, 40 | int64_t __attribute__((unused))timeout, 41 | bool __attribute__((unused))lock_en_mute) 42 | { 43 | return 0; 44 | } 45 | 46 | void TiltSensor::ProcessData(SensorBaseData *data) 47 | { 48 | sensor_event.data.data2[0] = 1.0f; 49 | sensor_event.timestamp = data->timestamp; 50 | 51 | HWSensorBase::WriteDataToPipe(0); 52 | HWSensorBase::ProcessData(data); 53 | } 54 | 55 | void TiltSensor::ProcessEvent(struct device_iio_events *event_data) 56 | { 57 | sensor_event.data.data2[0] = 1.0f; 58 | sensor_event.timestamp = event_data->event_timestamp; 59 | 60 | HWSensorBase::WriteDataToPipe(0); 61 | HWSensorBase::ProcessEvent(event_data); 62 | } 63 | 64 | } // namespace core 65 | } // namespace stm 66 | -------------------------------------------------------------------------------- /core/TiltSensor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /* 26 | * class TiltSensor 27 | */ 28 | class TiltSensor : public HWSensorBase { 29 | public: 30 | TiltSensor(HWSensorBaseCommonData *data, const char *name, int handle, 31 | unsigned int hw_fifo_len, float power_consumption, int module); 32 | 33 | virtual int SetDelay(int handle, int64_t period_ns, int64_t timeout, bool lock_en_mute); 34 | virtual void ProcessData(SensorBaseData *data); 35 | void ProcessEvent(struct device_iio_events *event_data); 36 | }; 37 | 38 | } // namespace core 39 | } // namespace stm 40 | -------------------------------------------------------------------------------- /core/WristTiltGesture.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2016-2020 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | 22 | #include "WristTiltGesture.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | WristTiltGesture::WristTiltGesture(HWSensorBaseCommonData *data, const char *name, int handle, 28 | unsigned int hw_fifo_len, float power_consumption, int module) 29 | : HWSensorBase(data, name, handle, 30 | WristTiltGestureSensorType, hw_fifo_len, 31 | power_consumption, module) 32 | { 33 | sensor_t_data.resolution = 1.0f; 34 | sensor_t_data.maxRange = 1.0f; 35 | sensor_event.data.dataLen = 1; 36 | } 37 | 38 | int WristTiltGesture::SetDelay(int __attribute__((unused))handle, 39 | int64_t __attribute__((unused))period_ns, 40 | int64_t __attribute__((unused))timeout, 41 | bool __attribute__((unused))lock_en_mute) 42 | { 43 | return 0; 44 | } 45 | 46 | void WristTiltGesture::ProcessData(SensorBaseData *data) 47 | { 48 | sensor_event.data.data2[0] = 1.0f; 49 | sensor_event.timestamp = data->timestamp; 50 | 51 | HWSensorBase::WriteDataToPipe(0); 52 | HWSensorBase::ProcessData(data); 53 | } 54 | 55 | } // namespace core 56 | } // namespace stm 57 | -------------------------------------------------------------------------------- /core/WristTiltGesture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2016-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "HWSensorBase.h" 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | /* 26 | * class WristTiltGesture 27 | */ 28 | class WristTiltGesture : public HWSensorBase { 29 | public: 30 | WristTiltGesture(HWSensorBaseCommonData *data, const char *name, int handle, 31 | unsigned int hw_fifo_len, float power_consumption, int module); 32 | 33 | virtual int SetDelay(int handle, int64_t period_ns, int64_t timeout, bool lock_en_mute); 34 | virtual void ProcessData(SensorBaseData *data); 35 | }; 36 | 37 | } // namespace core 38 | } // namespace stm 39 | -------------------------------------------------------------------------------- /core/common_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2015-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include "configuration.h" 21 | 22 | #define ST_HAL_GRAVITY_MAX_ON_EARTH (10.7f) 23 | 24 | #define CONCATENATE_STRING(x, y) (x y) 25 | 26 | #define ST_HAL_DATA_PATH "/data/STSensorHAL" 27 | #define ST_HAL_PRIVATE_DATA_PATH "/data/STSensorHAL/private_data.dat" 28 | #define ST_HAL_SELFTEST_DATA_PATH "/data/STSensorHAL/selftest" 29 | #define ST_HAL_SELFTEST_CMD_DATA_PATH "/data/STSensorHAL/selftest/cmd" 30 | #define ST_HAL_SELFTEST_RESULTS_DATA_PATH "/data/STSensorHAL/selftest/results" 31 | 32 | #define ST_HAL_IIO_MAX_DEVICES (50) 33 | 34 | #define SENSOR_DATA_X(datax, datay, dataz, x1, y1, z1, x2, y2, z2, x3, y3, z3) \ 35 | ((x1 == 1 ? datax : (x1 == -1 ? -datax : 0)) + \ 36 | (x2 == 1 ? datay : (x2 == -1 ? -datay : 0)) + \ 37 | (x3 == 1 ? dataz : (x3 == -1 ? -dataz : 0))) 38 | 39 | #define SENSOR_DATA_Y(datax, datay, dataz, x1, y1, z1, x2, y2, z2, x3, y3, z3) \ 40 | ((y1 == 1 ? datax : (y1 == -1 ? -datax : 0)) + \ 41 | (y2 == 1 ? datay : (y2 == -1 ? -datay : 0)) + \ 42 | (y3 == 1 ? dataz : (y3 == -1 ? -dataz : 0))) 43 | 44 | #define SENSOR_DATA_Z(datax, datay, dataz, x1, y1, z1, x2, y2, z2, x3, y3, z3) \ 45 | ((z1 == 1 ? datax : (z1 == -1 ? -datax : 0)) + \ 46 | (z2 == 1 ? datay : (z2 == -1 ? -datay : 0)) + \ 47 | (z3 == 1 ? dataz : (z3 == -1 ? -dataz : 0))) 48 | 49 | #define SENSOR_X_DATA(...) SENSOR_DATA_X(__VA_ARGS__) 50 | #define SENSOR_Y_DATA(...) SENSOR_DATA_Y(__VA_ARGS__) 51 | #define SENSOR_Z_DATA(...) SENSOR_DATA_Z(__VA_ARGS__) 52 | -------------------------------------------------------------------------------- /core/configuration.h: -------------------------------------------------------------------------------- 1 | /* configuration.h -- Autogenerated file! Do not edit. */ 2 | 3 | #ifndef __ST_SENSOR_HAL_CONFIG_H 4 | #define __ST_SENSOR_HAL_CONFIG_H 5 | 6 | #define CONFIG_ST_HAL_MIN_FUSION_POLLRATE 50 7 | 8 | #endif /* __ST_SENSOR_HAL_CONFIG_H */ 9 | -------------------------------------------------------------------------------- /core/gTests/Main_TestAll.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include 19 | 20 | int main(int argc, char **argv) 21 | { 22 | ::testing::InitGoogleTest(&argc, argv); 23 | return RUN_ALL_TESTS(); 24 | } 25 | -------------------------------------------------------------------------------- /core/include/Android.bp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | cc_library_headers { 18 | name: "stmicroelectronics-sensors-common-includes", 19 | vendor_available: true, 20 | export_include_dirs: ["."], 21 | } 22 | 23 | -------------------------------------------------------------------------------- /core/include/IConsole.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class IConsole { 26 | protected: 27 | IConsole(void) = default; 28 | virtual ~IConsole(void) = default; 29 | 30 | public: 31 | IConsole(const IConsole &) = delete; 32 | IConsole& operator= (const IConsole &) = delete; 33 | 34 | /** 35 | * getInstance: retrieve console instance 36 | * 37 | * Return value: valid instance of the console. 38 | */ 39 | static IConsole& getInstance(void); 40 | 41 | /** 42 | * info: print info message 43 | * @message: message string to be printed 44 | */ 45 | virtual void info(const std::string &message) const = 0; 46 | 47 | /** 48 | * warning: print warning message 49 | * @message: message string to be printed 50 | */ 51 | virtual void warning(const std::string &message) const = 0; 52 | 53 | /** 54 | * error: print error message 55 | * @message: message string to be printed 56 | */ 57 | virtual void error(const std::string &message) const = 0; 58 | 59 | /** 60 | * debug: print debug message 61 | * @message: message string to be printed 62 | */ 63 | virtual void debug(const std::string &message) const = 0; 64 | }; 65 | 66 | } // namespace core 67 | } // namespace stm 68 | -------------------------------------------------------------------------------- /core/include/ISTMSensorsCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | namespace stm { 26 | namespace core { 27 | 28 | class ISTMSensorsCallback { 29 | public: 30 | virtual ~ISTMSensorsCallback(void) = default; 31 | 32 | /** 33 | * onNewSensorsData: called whenever new data are available for consumers 34 | * @sensorsData: object reference containing all the data. 35 | */ 36 | virtual void onNewSensorsData(const std::vector &sensorsData) = 0; 37 | 38 | /** 39 | * onSaveDataRequest: called whenever a resource needs to be written to disk 40 | * @resourceID: identifier of the resource. 41 | * @data: data pointer. 42 | * @len: data buffer size. 43 | * 44 | * Return value: number of bytes written on success, else a negative error code. 45 | */ 46 | virtual int onSaveDataRequest(const std::string& resourceID, const void *data, ssize_t len) = 0; 47 | 48 | /** 49 | * onLoadDataRequest: called whenever a resource needs to be loaded from disk 50 | * @resourceID: identifier of the resource. 51 | * @data: data pointer. 52 | * @len: data buffer size. 53 | * 54 | * Return value: number of bytes read on success, else a negative error code. 55 | */ 56 | virtual int onLoadDataRequest(const std::string& resourceID, void *data, ssize_t len) = 0; 57 | }; 58 | 59 | } // namespace core 60 | } // namespace stm 61 | -------------------------------------------------------------------------------- /core/include/ISTMSensorsCallbackData.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | namespace stm { 26 | namespace core { 27 | 28 | class ISTMSensorsCallbackData { 29 | public: 30 | virtual ~ISTMSensorsCallbackData(void) = default; 31 | 32 | /** 33 | * Return sensor data vector reference 34 | */ 35 | const std::vector& getData(void) const; 36 | 37 | /** 38 | * Return timestamp value associated with data 39 | */ 40 | int64_t getTimestamp(void) const; 41 | 42 | /** 43 | * Return sensor type 44 | */ 45 | SensorType getSensorType(void) const; 46 | 47 | /** 48 | * Return sensor handle 49 | */ 50 | uint32_t getSensorHandle(void) const; 51 | 52 | /** 53 | * Return true if sensor is a wake up sensor 54 | */ 55 | bool isWakeUpSensor(void) const; 56 | 57 | protected: 58 | /** 59 | * Sensor data vector 60 | */ 61 | std::vector sensorsData; 62 | 63 | /** 64 | * Sensor data timestamp (ns) 65 | */ 66 | int64_t timestamp; 67 | 68 | /** 69 | * Sensor type 70 | */ 71 | SensorType sensorType; 72 | 73 | /** 74 | * Sensor handle 75 | */ 76 | uint32_t sensorHandle; 77 | 78 | /** 79 | * Sensor data may have wake up the AP 80 | */ 81 | bool wakeUpSensor; 82 | }; 83 | 84 | } // namespace core 85 | } // namespace stm 86 | -------------------------------------------------------------------------------- /core/include/IUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | 22 | namespace stm { 23 | namespace core { 24 | 25 | class IUtils { 26 | protected: 27 | IUtils(void) = default; 28 | virtual ~IUtils(void) = default; 29 | 30 | public: 31 | IUtils(const IUtils &) = delete; 32 | IUtils& operator= (const IUtils &) = delete; 33 | 34 | /** 35 | * getInstance: retrieve utils instance 36 | * 37 | * Return value: valid instance of the utils. 38 | */ 39 | static IUtils& getInstance(void); 40 | 41 | /** 42 | * getTime: return the time since the system was booted, and include deep sleep 43 | * 44 | * Return value: nsec since the system was booted. 45 | */ 46 | virtual int64_t getTime(void) const = 0; 47 | }; 48 | 49 | } // namespace core 50 | } // namespace stm 51 | -------------------------------------------------------------------------------- /core/include/STMSensorsList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | class STMSensorsList { 28 | public: 29 | STMSensorsList(void) = default; 30 | 31 | bool addSensor(STMSensor &sensor); 32 | 33 | const std::vector& getList(void) const; 34 | 35 | void clear(); 36 | 37 | private: 38 | /** 39 | * List of available sensors 40 | */ 41 | std::vector list; 42 | }; 43 | 44 | } // namespace core 45 | } // namespace stm 46 | -------------------------------------------------------------------------------- /core/include/local/stm_iio_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * STMicroelectronics IIO default types 3 | * 4 | * MEMS Software Solutions Team 5 | * 6 | * Copyright 2023 STMicroelectronics Inc. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | #ifndef __STM_IIO_DEFAULT_TYPE__ 22 | #define __STM_IIO_DEFAULT_TYPE__ 23 | 24 | /* 25 | * IIO default types doesn't introduce any custom define: 26 | * currently defining default standard IIO defines only, all won't support 27 | * STM CUSTOM IIO defines. 28 | * 29 | * Part of the IIO types that SensorHAL uses are already defined in the types.h 30 | * file of the IIO UAPI interface, while others are custom and are exported by 31 | * the STMicroelectrinics IIO drivers from the repository: 32 | * https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio 33 | * 34 | * This file introduces the define __STM_IIO_DEFAULT_TYPE__ which leads in the 35 | * sensorhal_iio_types.h file to the declaration of the custom types of sensors 36 | * used in the HAL backwards compatible with the previous management. 37 | * 38 | * When this file is replaced with the file exported from: 39 | * https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio/drivers/iio/stm/common/stm_iio_types.h 40 | * it introduces custom sensor type to starting support the kernel 6.1 for the new 41 | * drivers. 42 | */ 43 | 44 | #endif /* __STM_IIO_DEFAULT_TYPE__ */ 45 | 46 | -------------------------------------------------------------------------------- /core/libs/accel-calibration/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2018 The Android Open Source Project 3 | // Copyright (C) 2021 STMicroelectronics 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 | cc_library_static { 18 | name: "libstm-accel-calibration", 19 | owner: "STMicroelectronics", 20 | vendor: true, 21 | proprietary: true, 22 | compile_multilib: "both", 23 | srcs: [ 24 | "STMAccelCalibration.cpp" 25 | ], 26 | shared_libs: [ 27 | "libcutils", 28 | "libutils", 29 | "libc", 30 | ], 31 | header_libs: [ "stmicroelectronics-sensors-common-includes"], 32 | cflags: [ 33 | "-Wall", 34 | "-Wextra", 35 | "-Wpedantic", 36 | ], 37 | } 38 | -------------------------------------------------------------------------------- /core/libs/accel-calibration/Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 The Android Open Source Project 3 | # Copyright (C) 2021 STMicroelectronics 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 | ifneq ($(TARGET_SIMULATOR),true) 18 | 19 | LOCAL_PATH := $(call my-dir) 20 | 21 | include $(CLEAR_VARS) 22 | 23 | LOCAL_MODULE := libstm-accel-calibration-legacy 24 | 25 | LOCAL_MODULE_OWNER := STMicroelectronics 26 | 27 | LOCAL_PROPRIETARY_MODULE := true 28 | 29 | LOCAL_PRELINK_MODULE := false 30 | 31 | LOCAL_CFLAGS += \ 32 | -Wall \ 33 | -Wextra 34 | 35 | LOCAL_SRC_FILES := \ 36 | STMAccelCalibration.cpp 37 | LOCAL_HEADER_LIBRARIES := stmicroelectronics-sensors-common-includes 38 | 39 | LOCAL_MODULE_TAGS := optional 40 | 41 | LOCAL_SHARED_LIBRARIES := \ 42 | libdl \ 43 | libc 44 | 45 | include $(BUILD_STATIC_LIBRARY) 46 | 47 | endif # !TARGET_SIMULATOR 48 | -------------------------------------------------------------------------------- /core/libs/accel-calibration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (C) 2018 The Android Open Source Project 3 | ## Copyright (C) 2021 STMicroelectronics 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 | cmake_minimum_required(VERSION 3.0.2) 18 | 19 | add_compile_options(-Wall -Wextra -pedantic -static) 20 | include_directories(../../include/) 21 | add_library(stm-accel-calibration 22 | STATIC 23 | STMAccelCalibration.cpp) 24 | 25 | target_compile_features(stm-accel-calibration PUBLIC cxx_std_14) 26 | set_target_properties(stm-accel-calibration PROPERTIES CXX_EXTENSIONS OFF) 27 | -------------------------------------------------------------------------------- /core/libs/accel-calibration/STMAccelCalibration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2021 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | struct STMAccelCalibration { 26 | static STMAccelCalibration& getInstance(void); 27 | ~STMAccelCalibration(void) = default; 28 | STMAccelCalibration(const STMAccelCalibration &) = delete; 29 | STMAccelCalibration(STMAccelCalibration &&) = delete; 30 | STMAccelCalibration& operator=(const STMAccelCalibration &) = delete; 31 | STMAccelCalibration& operator=(STMAccelCalibration &&) = delete; 32 | 33 | int init(float accelRange); 34 | 35 | int reset(const Matrix<4, 3, float> &initialBias); 36 | 37 | int setFrequency(int frequencyHz); 38 | 39 | int run(const std::array &accelData, int64_t timestamp); 40 | 41 | int getBias(Matrix<4, 3, float> &bias) const; 42 | 43 | const std::string& getLibVersion(void) const; 44 | 45 | static void resetBiasMatrix(Matrix<4, 3, float> &bias); 46 | 47 | static int getMinFrequencyHz(void); 48 | 49 | static int getMaxFrequencyHz(void); 50 | 51 | private: 52 | Matrix<4, 3, float> outBias; 53 | int64_t lastTimestamp; 54 | 55 | STMAccelCalibration(void); 56 | }; 57 | -------------------------------------------------------------------------------- /core/libs/gyro-calibration/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2018 The Android Open Source Project 3 | // Copyright (C) 2021 STMicroelectronics 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 | cc_library_static { 18 | name: "libstm-gyro-calibration", 19 | owner: "STMicroelectronics", 20 | vendor: true, 21 | proprietary: true, 22 | compile_multilib: "both", 23 | srcs: [ 24 | "STMGyroCalibration.cpp" 25 | ], 26 | shared_libs: [ 27 | "libcutils", 28 | "libutils", 29 | "libc", 30 | ], 31 | header_libs: [ "stmicroelectronics-sensors-common-includes"], 32 | cflags: [ 33 | "-Wall", 34 | "-Wextra", 35 | "-Wpedantic", 36 | ], 37 | } 38 | -------------------------------------------------------------------------------- /core/libs/gyro-calibration/Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 The Android Open Source Project 3 | # Copyright (C) 2021 STMicroelectronics 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 | ifneq ($(TARGET_SIMULATOR),true) 18 | 19 | LOCAL_PATH := $(call my-dir) 20 | 21 | include $(CLEAR_VARS) 22 | 23 | LOCAL_MODULE := libstm-gyro-calibration-legacy 24 | 25 | LOCAL_MODULE_OWNER := STMicroelectronics 26 | 27 | LOCAL_PROPRIETARY_MODULE := true 28 | 29 | LOCAL_PRELINK_MODULE := false 30 | 31 | LOCAL_CFLAGS += \ 32 | -Wall \ 33 | -Wextra 34 | 35 | LOCAL_SRC_FILES := \ 36 | STMGyroCalibration.cpp 37 | LOCAL_HEADER_LIBRARIES := stmicroelectronics-sensors-common-includes 38 | 39 | LOCAL_MODULE_TAGS := optional 40 | 41 | LOCAL_SHARED_LIBRARIES := \ 42 | libdl \ 43 | libc 44 | 45 | include $(BUILD_STATIC_LIBRARY) 46 | 47 | endif # !TARGET_SIMULATOR 48 | -------------------------------------------------------------------------------- /core/libs/gyro-calibration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (C) 2018 The Android Open Source Project 3 | ## Copyright (C) 2021 STMicroelectronics 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 | cmake_minimum_required(VERSION 3.0.2) 18 | 19 | add_compile_options(-Wall -Wextra -pedantic -static) 20 | include_directories(../../include/ .) 21 | add_library(stm-gyro-calibration 22 | STATIC 23 | STMGyroCalibration.cpp) 24 | 25 | target_compile_features(stm-gyro-calibration PUBLIC cxx_std_14) 26 | set_target_properties(stm-gyro-calibration PROPERTIES CXX_EXTENSIONS OFF) 27 | -------------------------------------------------------------------------------- /core/libs/gyro-calibration/STMGyroCalibration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2021 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | struct STMGyroCalibration { 25 | static STMGyroCalibration& getInstance(void); 26 | ~STMGyroCalibration(void) = default; 27 | STMGyroCalibration(const STMGyroCalibration &) = delete; 28 | STMGyroCalibration(STMGyroCalibration &&) = delete; 29 | STMGyroCalibration& operator=(const STMGyroCalibration &) = delete; 30 | STMGyroCalibration& operator=(STMGyroCalibration &&) = delete; 31 | 32 | int init(float accelThreshold, 33 | float gyroThreshold, 34 | float accelRange, 35 | float gyroRange); 36 | 37 | int reset(const Matrix<4, 3, float> &initialBias); 38 | 39 | int setFrequency(int frequencyHz); 40 | 41 | int run(const std::array &accelData, 42 | const std::array &gyroData, 43 | int64_t timestamp); 44 | 45 | int getBias(Matrix<4, 3, float> &bias) const; 46 | 47 | const std::string& getLibVersion(void) const; 48 | 49 | static void resetBiasMatrix(Matrix<4, 3, float> &bias); 50 | 51 | static int getMinFrequencyHz(void); 52 | 53 | static int getMaxFrequencyHz(void); 54 | 55 | private: 56 | Matrix<4, 3, float> outBias; 57 | int64_t lastTimestamp; 58 | 59 | STMGyroCalibration(void); 60 | }; 61 | -------------------------------------------------------------------------------- /core/libs/gyro-temperature-calibration/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2018 The Android Open Source Project 3 | // Copyright (C) 2021 STMicroelectronics 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 | cc_library_static { 18 | name: "libstm-gyro-temperature-calibration", 19 | owner: "STMicroelectronics", 20 | vendor: true, 21 | proprietary: true, 22 | compile_multilib: "both", 23 | srcs: [ 24 | "STMGyroTempCalibration.cpp", 25 | ], 26 | shared_libs: [ 27 | "libcutils", 28 | "libutils", 29 | "libc", 30 | ], 31 | header_libs: [ "stmicroelectronics-sensors-common-includes"], 32 | cflags: [ 33 | "-Wall", 34 | "-Wextra", 35 | "-Wpedantic", 36 | ], 37 | } 38 | 39 | -------------------------------------------------------------------------------- /core/libs/gyro-temperature-calibration/Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 The Android Open Source Project 3 | # Copyright (C) 2019-2021 STMicroelectronics 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 | ifneq ($(TARGET_SIMULATOR),true) 18 | 19 | LOCAL_PATH := $(call my-dir) 20 | 21 | include $(CLEAR_VARS) 22 | 23 | LOCAL_MODULE := libstm-gyro-temperature-calibration-legacy 24 | 25 | LOCAL_MODULE_OWNER := STMicroelectronics 26 | 27 | LOCAL_PROPRIETARY_MODULE := true 28 | 29 | LOCAL_PRELINK_MODULE := false 30 | 31 | LOCAL_CFLAGS += \ 32 | -Wall \ 33 | -Wextra 34 | 35 | LOCAL_SRC_FILES := \ 36 | STMGyroTempCalibration.cpp 37 | 38 | LOCAL_HEADER_LIBRARIES := stmicroelectronics-sensors-common-includes 39 | LOCAL_MODULE_TAGS := optional 40 | 41 | LOCAL_SHARED_LIBRARIES := \ 42 | libdl \ 43 | libc 44 | 45 | include $(BUILD_STATIC_LIBRARY) 46 | 47 | endif # !TARGET_SIMULATOR 48 | -------------------------------------------------------------------------------- /core/libs/gyro-temperature-calibration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (C) 2018 The Android Open Source Project 3 | ## Copyright (C) 2021 STMicroelectronics 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 | cmake_minimum_required(VERSION 3.0.2) 18 | 19 | add_compile_options(-Wall -Wextra -pedantic -static) 20 | include_directories(../../include/ .) 21 | add_library(stm-gyro-temperature-calibration 22 | STATIC 23 | STMGyroTempCalibration.cpp) 24 | 25 | target_compile_features(stm-gyro-temperature-calibration PUBLIC cxx_std_14) 26 | set_target_properties(stm-gyro-temperature-calibration PROPERTIES CXX_EXTENSIONS OFF) 27 | -------------------------------------------------------------------------------- /core/libs/gyro-temperature-calibration/STMGyroTempCalibration.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2024 STMicroelectronics 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 | #include "STMGyroTempCalibration.h" 19 | 20 | STMGyroTempCalibration& STMGyroTempCalibration::getInstance(void) 21 | { 22 | static STMGyroTempCalibration *gyroTempCalib = new STMGyroTempCalibration(); 23 | return *gyroTempCalib; 24 | } 25 | 26 | STMGyroTempCalibration::STMGyroTempCalibration(void) 27 | { 28 | } 29 | 30 | int STMGyroTempCalibration::initialize(void) 31 | { 32 | outBias = { 0 }; 33 | bias_update = 0; 34 | 35 | return 0; 36 | } 37 | 38 | int STMGyroTempCalibration::run(std::array &gyroData, 39 | float temperature, 40 | uint64_t timestamp, 41 | int *b_update) 42 | { 43 | (void) gyroData; 44 | (void) temperature; 45 | 46 | lastUpdateTime = timestamp; 47 | *b_update = bias_update; 48 | 49 | return 0; 50 | } 51 | 52 | int STMGyroTempCalibration::getBias(float *temp, std::array &bias) 53 | { 54 | (void)temp; 55 | bias = outBias; 56 | 57 | return 0; 58 | } 59 | 60 | int STMGyroTempCalibration::getState(void *state) 61 | { 62 | (void)state; 63 | 64 | return 0; 65 | } 66 | 67 | int STMGyroTempCalibration::setState(void *state) 68 | { 69 | (void)state; 70 | 71 | return 0; 72 | } 73 | 74 | const std::string& STMGyroTempCalibration::getLibVersion(void) 75 | { 76 | static const std::string libVersion("stm-motion-gt-lib-mock"); 77 | 78 | return libVersion; 79 | } 80 | -------------------------------------------------------------------------------- /core/libs/gyro-temperature-calibration/STMGyroTempCalibration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2021 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | struct STMGyroTempCalibration { 24 | static STMGyroTempCalibration& getInstance(void); 25 | ~STMGyroTempCalibration(void); 26 | STMGyroTempCalibration(const STMGyroTempCalibration &) = delete; 27 | STMGyroTempCalibration(STMGyroTempCalibration &&) = delete; 28 | STMGyroTempCalibration& operator=(const STMGyroTempCalibration &) = delete; 29 | STMGyroTempCalibration& operator=(STMGyroTempCalibration &&) = delete; 30 | 31 | int initialize(void); 32 | 33 | int run(std::array &gyroData, 34 | float temperature, 35 | uint64_t timestamp, 36 | int *b_update); 37 | int getBias(float *temp, std::array &bias); 38 | int getState(void *state); 39 | int setState(void *state); 40 | const std::string& getLibVersion(void); 41 | static const int STMGyroTempCalibrationStateSize = 40; 42 | 43 | private: 44 | std::array outBias; 45 | int bias_update; 46 | uint64_t lastUpdateTime; 47 | STMGyroTempCalibration(void); 48 | }; 49 | -------------------------------------------------------------------------------- /core/libs/magn-calibration/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2018 The Android Open Source Project 3 | // Copyright (C) 2021 STMicroelectronics 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 | cc_library_static { 18 | name: "libstm-magn-calibration", 19 | owner: "STMicroelectronics", 20 | vendor: true, 21 | proprietary: true, 22 | compile_multilib: "both", 23 | srcs: [ 24 | "STMMagnCalibration.cpp" 25 | ], 26 | shared_libs: [ 27 | "libcutils", 28 | "libutils", 29 | "libc", 30 | ], 31 | header_libs: [ "stmicroelectronics-sensors-common-includes"], 32 | cflags: [ 33 | "-Wall", 34 | "-Wextra", 35 | "-Wpedantic", 36 | ], 37 | } 38 | -------------------------------------------------------------------------------- /core/libs/magn-calibration/Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 The Android Open Source Project 3 | # Copyright (C) 2021 STMicroelectronics 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 | ifneq ($(TARGET_SIMULATOR),true) 18 | 19 | LOCAL_PATH := $(call my-dir) 20 | 21 | include $(CLEAR_VARS) 22 | 23 | LOCAL_MODULE := libstm-magn-calibration-legacy 24 | 25 | LOCAL_MODULE_OWNER := STMicroelectronics 26 | 27 | LOCAL_PROPRIETARY_MODULE := true 28 | 29 | LOCAL_PRELINK_MODULE := false 30 | 31 | LOCAL_CFLAGS += \ 32 | -Wall \ 33 | -Wextra 34 | 35 | LOCAL_SRC_FILES := \ 36 | STMMagnCalibration.cpp 37 | 38 | LOCAL_HEADER_LIBRARIES := stmicroelectronics-sensors-common-includes 39 | LOCAL_MODULE_TAGS := optional 40 | 41 | LOCAL_SHARED_LIBRARIES := \ 42 | libdl \ 43 | libc 44 | 45 | include $(BUILD_STATIC_LIBRARY) 46 | 47 | endif # !TARGET_SIMULATOR 48 | -------------------------------------------------------------------------------- /core/libs/magn-calibration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (C) 2018 The Android Open Source Project 3 | ## Copyright (C) 2021 STMicroelectronics 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 | cmake_minimum_required(VERSION 3.0.2) 18 | 19 | add_compile_options(-Wall -Wextra -pedantic -static) 20 | include_directories(../../include/) 21 | add_library(stm-magn-calibration 22 | STATIC 23 | STMMagnCalibration.cpp) 24 | 25 | target_compile_features(stm-magn-calibration PUBLIC cxx_std_14) 26 | set_target_properties(stm-magn-calibration PROPERTIES CXX_EXTENSIONS OFF) 27 | -------------------------------------------------------------------------------- /core/libs/magn-calibration/STMMagnCalibration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2021 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | struct STMMagnCalibration { 26 | static STMMagnCalibration& getInstance(void); 27 | ~STMMagnCalibration(void) = default; 28 | STMMagnCalibration(const STMMagnCalibration &) = delete; 29 | STMMagnCalibration(STMMagnCalibration &&) = delete; 30 | STMMagnCalibration& operator=(const STMMagnCalibration &) = delete; 31 | STMMagnCalibration& operator=(STMMagnCalibration &&) = delete; 32 | 33 | int init(float magnRange); 34 | 35 | int reset(const Matrix<4, 3, float> &initialBias); 36 | 37 | int setFrequency(int frequencyHz); 38 | 39 | int run(const std::array &magnData, 40 | int64_t timestamp); 41 | 42 | int getBias(Matrix<4, 3, float> &bias) const; 43 | 44 | const std::string& getLibVersion(void) const; 45 | 46 | static void resetBiasMatrix(Matrix<4, 3, float> &bias); 47 | 48 | static int getMinFrequencyHz(void); 49 | 50 | static int getMaxFrequencyHz(void); 51 | 52 | private: 53 | Matrix<4, 3, float> outBias; 54 | int64_t lastTimestamp; 55 | 56 | STMMagnCalibration(void); 57 | }; 58 | -------------------------------------------------------------------------------- /core/libs/sensors-fusion/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2018 The Android Open Source Project 3 | // Copyright (C) 2021 STMicroelectronics 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 | cc_library_static { 18 | name: "libstm-sensors-fusion", 19 | owner: "STMicroelectronics", 20 | vendor: true, 21 | proprietary: true, 22 | compile_multilib: "both", 23 | srcs: [ 24 | "STMSensorsFusion.cpp", 25 | "STMSensorsFusion6Axis.cpp", 26 | "STMSensorsFusion9Axis.cpp", 27 | ], 28 | shared_libs: [ 29 | "libcutils", 30 | "libutils", 31 | "libc", 32 | ], 33 | cflags: [ 34 | "-Wall", 35 | "-Wextra", 36 | "-Wpedantic", 37 | ], 38 | } 39 | -------------------------------------------------------------------------------- /core/libs/sensors-fusion/Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 The Android Open Source Project 3 | # Copyright (C) 2021 STMicroelectronics 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 | ifneq ($(TARGET_SIMULATOR),true) 18 | 19 | LOCAL_PATH := $(call my-dir) 20 | 21 | include $(CLEAR_VARS) 22 | 23 | LOCAL_MODULE := libstm-sensors-fusion-legacy 24 | 25 | LOCAL_MODULE_OWNER := STMicroelectronics 26 | 27 | LOCAL_PROPRIETARY_MODULE := true 28 | 29 | LOCAL_PRELINK_MODULE := false 30 | 31 | LOCAL_CFLAGS += \ 32 | -Wall \ 33 | -Wextra 34 | 35 | LOCAL_SRC_FILES := \ 36 | STMSensorsFusion.cpp \ 37 | STMSensorsFusion6Axis.cpp \ 38 | STMSensorsFusion9Axis.cpp 39 | 40 | LOCAL_MODULE_TAGS := optional 41 | 42 | LOCAL_SHARED_LIBRARIES := \ 43 | libdl \ 44 | libc 45 | 46 | include $(BUILD_STATIC_LIBRARY) 47 | 48 | endif # !TARGET_SIMULATOR 49 | -------------------------------------------------------------------------------- /core/libs/sensors-fusion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (C) 2018 The Android Open Source Project 3 | ## Copyright (C) 2021 STMicroelectronics 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 | cmake_minimum_required(VERSION 3.0.2) 18 | 19 | add_compile_options(-Wall -Wextra -pedantic -static) 20 | 21 | add_library(stm-sensors-fusion 22 | STATIC 23 | STMSensorsFusion.cpp 24 | STMSensorsFusion6Axis.cpp 25 | STMSensorsFusion9Axis.cpp) 26 | 27 | target_compile_features(stm-sensors-fusion PUBLIC cxx_std_14) 28 | set_target_properties(stm-sensors-fusion PROPERTIES CXX_EXTENSIONS OFF) 29 | -------------------------------------------------------------------------------- /core/libs/sensors-fusion/STMSensorsFusion.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2021 STMicroelectronics 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 | #include "STMSensorsFusion.h" 19 | 20 | int STMSensorsFusion::getQuaternion(std::array &data) const 21 | { 22 | (void) data; 23 | 24 | return 0; 25 | } 26 | 27 | int STMSensorsFusion::getEulerAngles(std::array &data) const 28 | { 29 | (void) data; 30 | 31 | return 0; 32 | } 33 | 34 | int STMSensorsFusion::getGravity(std::array &data) const 35 | { 36 | (void) data; 37 | 38 | return 0; 39 | } 40 | 41 | int STMSensorsFusion::getLinearAccel(std::array &data) const 42 | { 43 | (void) data; 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /core/libs/sensors-fusion/STMSensorsFusion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2021 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | struct STMSensorsFusion { 24 | STMSensorsFusion(const STMSensorsFusion &) = delete; 25 | STMSensorsFusion(STMSensorsFusion &&) = delete; 26 | STMSensorsFusion& operator=(const STMSensorsFusion &) = delete; 27 | STMSensorsFusion& operator=(STMSensorsFusion &&) = delete; 28 | 29 | virtual int init(void) = 0; 30 | 31 | virtual int reset(void *data) = 0; 32 | 33 | int getQuaternion(std::array &data) const; 34 | 35 | int getEulerAngles(std::array &data) const; 36 | 37 | int getGravity(std::array &data) const; 38 | 39 | int getLinearAccel(std::array &data) const; 40 | 41 | virtual const std::string& getLibVersion(void) const = 0; 42 | 43 | protected: 44 | STMSensorsFusion(void) = default; 45 | virtual ~STMSensorsFusion(void) = default; 46 | }; 47 | -------------------------------------------------------------------------------- /core/libs/sensors-fusion/STMSensorsFusion6Axis.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2021 STMicroelectronics 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 | #include "STMSensorsFusion6Axis.h" 19 | 20 | STMSensorsFusion6Axis& STMSensorsFusion6Axis::getInstance(void) 21 | { 22 | static STMSensorsFusion6Axis *fusionLib = new STMSensorsFusion6Axis(); 23 | return *fusionLib; 24 | } 25 | 26 | int STMSensorsFusion6Axis::init(void) 27 | { 28 | return 0; 29 | } 30 | 31 | int STMSensorsFusion6Axis::reset(void *data) 32 | { 33 | (void) data; 34 | 35 | return 0; 36 | } 37 | 38 | int STMSensorsFusion6Axis::run(const std::array &accelData, 39 | const std::array &gyroData, 40 | int64_t timestamp) 41 | { 42 | (void) accelData; 43 | (void) gyroData; 44 | (void) timestamp; 45 | 46 | return 0; 47 | } 48 | 49 | const std::string& STMSensorsFusion6Axis::getLibVersion(void) const 50 | { 51 | static const std::string libVersion("stm-sensors-fusion-6X-lib-mock"); 52 | 53 | return libVersion; 54 | } 55 | -------------------------------------------------------------------------------- /core/libs/sensors-fusion/STMSensorsFusion6Axis.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2021 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include "STMSensorsFusion.h" 24 | 25 | struct STMSensorsFusion6Axis: public STMSensorsFusion { 26 | static STMSensorsFusion6Axis& getInstance(void); 27 | virtual ~STMSensorsFusion6Axis(void) = default; 28 | STMSensorsFusion6Axis(const STMSensorsFusion6Axis &) = delete; 29 | STMSensorsFusion6Axis(STMSensorsFusion6Axis &&) = delete; 30 | STMSensorsFusion6Axis& operator=(const STMSensorsFusion6Axis &) = delete; 31 | STMSensorsFusion6Axis& operator=(STMSensorsFusion6Axis &&) = delete; 32 | 33 | virtual int init(void) override; 34 | 35 | virtual int reset(void *data) override; 36 | 37 | int run(const std::array &accelData, 38 | const std::array &gyroData, 39 | int64_t timestamp); 40 | 41 | virtual const std::string& getLibVersion(void) const override; 42 | 43 | private: 44 | STMSensorsFusion6Axis(void) = default; 45 | }; 46 | -------------------------------------------------------------------------------- /core/libs/sensors-fusion/STMSensorsFusion9Axis.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2021 STMicroelectronics 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 | #include "STMSensorsFusion9Axis.h" 19 | 20 | STMSensorsFusion9Axis& STMSensorsFusion9Axis::getInstance(void) 21 | { 22 | static STMSensorsFusion9Axis *fusionLib = new STMSensorsFusion9Axis(); 23 | return *fusionLib; 24 | } 25 | 26 | int STMSensorsFusion9Axis::init(void) 27 | { 28 | return 0; 29 | } 30 | 31 | int STMSensorsFusion9Axis::reset(void *data) 32 | { 33 | (void) data; 34 | 35 | return 0; 36 | } 37 | 38 | int STMSensorsFusion9Axis::run(const std::array &accelData, 39 | const std::array &magnData, 40 | const std::array &gyroData, 41 | int64_t timestamp) 42 | { 43 | (void) accelData; 44 | (void) magnData; 45 | (void) gyroData; 46 | (void) timestamp; 47 | 48 | return 0; 49 | } 50 | 51 | const std::string& STMSensorsFusion9Axis::getLibVersion(void) const 52 | { 53 | static const std::string libVersion("stm-sensors-fusion-9X-lib-mock"); 54 | 55 | return libVersion; 56 | } 57 | -------------------------------------------------------------------------------- /core/libs/sensors-fusion/STMSensorsFusion9Axis.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2021 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include "STMSensorsFusion.h" 24 | 25 | struct STMSensorsFusion9Axis: public STMSensorsFusion { 26 | static STMSensorsFusion9Axis& getInstance(void); 27 | virtual ~STMSensorsFusion9Axis(void) = default; 28 | STMSensorsFusion9Axis(const STMSensorsFusion9Axis &) = delete; 29 | STMSensorsFusion9Axis(STMSensorsFusion9Axis &&) = delete; 30 | STMSensorsFusion9Axis& operator=(const STMSensorsFusion9Axis &) = delete; 31 | STMSensorsFusion9Axis& operator=(STMSensorsFusion9Axis &&) = delete; 32 | 33 | virtual int init(void) override; 34 | 35 | virtual int reset(void *data) override; 36 | 37 | int run(const std::array &accelData, 38 | const std::array &magnData, 39 | const std::array &gyroData, 40 | int64_t timestamp); 41 | 42 | virtual const std::string& getLibVersion(void) const override; 43 | 44 | private: 45 | STMSensorsFusion9Axis(void) = default; 46 | }; 47 | -------------------------------------------------------------------------------- /core/libs/timesync/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2018 The Android Open Source Project 3 | // Copyright (C) 2022 STMicroelectronics 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 | cc_library_static { 18 | name: "libstm-timesync", 19 | owner: "STMicroelectronics", 20 | vendor: true, 21 | proprietary: true, 22 | compile_multilib: "both", 23 | srcs: [ 24 | "STMTimesync.cpp" 25 | ], 26 | shared_libs: [ 27 | "libcutils", 28 | "libutils", 29 | "libc", 30 | ], 31 | cflags: [ 32 | "-Wall", 33 | "-Wextra", 34 | "-Wpedantic", 35 | ], 36 | } 37 | -------------------------------------------------------------------------------- /core/libs/timesync/Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2018 The Android Open Source Project 3 | # Copyright (C) 2022 STMicroelectronics 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 | ifneq ($(TARGET_SIMULATOR),true) 18 | 19 | LOCAL_PATH := $(call my-dir) 20 | 21 | include $(CLEAR_VARS) 22 | 23 | LOCAL_MODULE := libstm-timesync-legacy 24 | 25 | LOCAL_MODULE_OWNER := STMicroelectronics 26 | 27 | LOCAL_PROPRIETARY_MODULE := true 28 | 29 | LOCAL_PRELINK_MODULE := false 30 | 31 | LOCAL_CFLAGS += \ 32 | -Wall \ 33 | -Wextra 34 | 35 | LOCAL_SRC_FILES := \ 36 | STMTimesync.cpp 37 | 38 | LOCAL_MODULE_TAGS := optional 39 | 40 | LOCAL_SHARED_LIBRARIES := \ 41 | libdl \ 42 | libc 43 | 44 | include $(BUILD_STATIC_LIBRARY) 45 | 46 | endif # !TARGET_SIMULATOR 47 | -------------------------------------------------------------------------------- /core/libs/timesync/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (C) 2018 The Android Open Source Project 3 | ## Copyright (C) 2022 STMicroelectronics 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 | cmake_minimum_required(VERSION 3.0.2) 18 | 19 | add_compile_options(-Wall -Wextra -pedantic -static) 20 | 21 | add_library(stm-timesync 22 | STATIC 23 | STMTimesync.cpp) 24 | 25 | target_compile_features(stm-timesync PUBLIC cxx_std_14) 26 | set_target_properties(stm-timesync PROPERTIES CXX_EXTENSIONS OFF) 27 | -------------------------------------------------------------------------------- /core/libs/timesync/STMTimesync.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2022 STMicroelectronics 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 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "STMTimesync.h" 24 | 25 | static const int maxPointsMin = 5; 26 | 27 | int STMTimesync::init(uint8_t maxPoints) 28 | { 29 | if (maxPoints < maxPointsMin) { 30 | return -EINVAL; 31 | } 32 | 33 | return 0; 34 | } 35 | 36 | void STMTimesync::reset(void) 37 | { 38 | 39 | } 40 | 41 | bool STMTimesync::add(int64_t timestamp1, int64_t timestamp2) 42 | { 43 | if ((timestamp1 <= lastTimestamp1) || (timestamp2 <= lastTimestamp2)) { 44 | return false; 45 | } 46 | 47 | lastTimestamp1 = timestamp1; 48 | lastTimestamp2 = timestamp2; 49 | 50 | return true; 51 | } 52 | 53 | bool STMTimesync::estimate(int64_t timestamp2, int64_t ×tamp1) 54 | { 55 | (void) timestamp2; 56 | (void) timestamp1; 57 | 58 | return false; 59 | } 60 | 61 | const std::string& STMTimesync::getLibVersion(void) 62 | { 63 | static const std::string libVersion("stm-timesync-lib-mock"); 64 | 65 | return libVersion; 66 | } 67 | -------------------------------------------------------------------------------- /core/libs/timesync/STMTimesync.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2022 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | 22 | struct STMTimesync { 23 | STMTimesync(void) = default; 24 | ~STMTimesync(void) = default; 25 | STMTimesync(const STMTimesync &) = delete; 26 | STMTimesync(STMTimesync &&) = delete; 27 | STMTimesync& operator=(const STMTimesync &) = delete; 28 | STMTimesync& operator=(STMTimesync &&) = delete; 29 | 30 | int init(uint8_t maxPoints); 31 | 32 | void reset(void); 33 | 34 | bool add(int64_t timestamp1, int64_t timestamp2); 35 | 36 | bool estimate(int64_t timestamp2, int64_t& timestamp1); 37 | 38 | static const std::string& getLibVersion(void); 39 | 40 | private: 41 | int64_t lastTimestamp1; 42 | int64_t lastTimestamp2; 43 | }; 44 | -------------------------------------------------------------------------------- /core/sensors_legacy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include "temp_struct_porting.h" 23 | 24 | namespace stm { 25 | namespace core { 26 | 27 | int st_hal_open_sensors(void **data, STMSensorsList &sensorsList); 28 | 29 | void st_hal_close_sensors(void *data); 30 | 31 | void st_hal_dev_set_callbacks(void *data, const ISTMSensorsCallback &sensorsCallback); 32 | 33 | void st_hal_dev_post_setup(void *data); 34 | 35 | int st_hal_dev_activate(void *data, uint32_t handle, bool enable); 36 | 37 | int st_hal_dev_batch(void *data, int handle, int64_t period_ns, 38 | int64_t timeout); 39 | 40 | int st_hal_dev_flush(void *data, uint32_t handle); 41 | 42 | int st_hal_dev_set_fullscale(void *data, uint32_t handle, float fullscale); 43 | 44 | int st_hal_dev_poll(void *data, sensors_event_t *sdata, int count); 45 | 46 | } // namespace core 47 | } // namespace stm 48 | -------------------------------------------------------------------------------- /legacy/Convert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | bool convertFromSTMSensorType(const stm::core::SensorType &type, 25 | int &sensorType); 26 | 27 | bool convertFromSTMSensor(const stm::core::STMSensor &src, 28 | struct sensor_t *dst); 29 | 30 | void convertFromSTMSensorData(const stm::core::ISTMSensorsCallbackData &sensorData, 31 | struct sensors_event_t *event); 32 | -------------------------------------------------------------------------------- /legacy/IConsole.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #define LOG_TAG "sensors@legacy-stm" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | using stm::core::IConsole; 27 | 28 | class Console : public IConsole { 29 | public: 30 | Console(void) = default; 31 | ~Console(void) = default; 32 | 33 | Console(const Console &) = delete; 34 | Console& operator= (const Console &) = delete; 35 | 36 | void info(const std::string &message) const override; 37 | 38 | void warning(const std::string &message) const override; 39 | 40 | void error(const std::string &message) const override; 41 | 42 | void debug(const std::string &message) const override; 43 | }; 44 | 45 | void Console::info(const std::string &message) const 46 | { 47 | std::string messageToPrint = message + "\n"; 48 | 49 | ALOGI("%s", messageToPrint.c_str()); 50 | } 51 | 52 | void Console::warning(const std::string &message) const 53 | { 54 | std::string messageToPrint = message + "\n"; 55 | 56 | ALOGW("%s", messageToPrint.c_str()); 57 | } 58 | 59 | void Console::error(const std::string &message) const 60 | { 61 | std::string messageToPrint = message + "\n"; 62 | 63 | ALOGE("%s", messageToPrint.c_str()); 64 | } 65 | 66 | void Console::debug(const std::string &message)const 67 | { 68 | std::string messageToPrint = message + "\n"; 69 | 70 | ALOGD("%s", messageToPrint.c_str()); 71 | } 72 | 73 | IConsole& IConsole::getInstance(void) 74 | { 75 | static Console instance; 76 | 77 | return instance; 78 | } 79 | -------------------------------------------------------------------------------- /legacy/IUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include 19 | 20 | #include 21 | 22 | using stm::core::IUtils; 23 | 24 | class Utils : public IUtils { 25 | public: 26 | Utils(void) = default; 27 | ~Utils(void) = default; 28 | 29 | Utils(const Utils &) = delete; 30 | Utils& operator= (const Utils &) = delete; 31 | 32 | int64_t getTime(void) const override; 33 | }; 34 | 35 | int64_t Utils::getTime(void) const 36 | { 37 | return android::elapsedRealtimeNano(); 38 | } 39 | 40 | IUtils& IUtils::getInstance(void) 41 | { 42 | static Utils instance; 43 | 44 | return instance; 45 | } 46 | -------------------------------------------------------------------------------- /legacy/halVersion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #define SENSORS_HAL_DEVICE_API_VERSION SENSORS_DEVICE_API_VERSION_1_4 21 | -------------------------------------------------------------------------------- /linux/IConsole.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include 19 | #include 20 | 21 | #include 22 | 23 | using stm::core::IConsole; 24 | 25 | class Console : public IConsole { 26 | public: 27 | Console(void) = default; 28 | ~Console(void) = default; 29 | 30 | Console(const Console &) = delete; 31 | Console& operator= (const Console &) = delete; 32 | 33 | void info(const std::string &message) const override; 34 | 35 | void warning(const std::string &message) const override; 36 | 37 | void error(const std::string &message) const override; 38 | 39 | void debug(const std::string &message) const override; 40 | }; 41 | 42 | void Console::info(const std::string &message) const 43 | { 44 | std::string messageToPrint = message + "\n"; 45 | 46 | std::cout << messageToPrint; 47 | } 48 | 49 | void Console::warning(const std::string &message) const 50 | { 51 | info(message); 52 | } 53 | 54 | void Console::error(const std::string &message) const 55 | { 56 | std::string messageToPrint = message + "\n"; 57 | 58 | std::cerr << messageToPrint; 59 | } 60 | 61 | void Console::debug(const std::string &message) const 62 | { 63 | info(message); 64 | } 65 | 66 | IConsole& IConsole::getInstance(void) 67 | { 68 | static Console instance; 69 | 70 | return instance; 71 | } 72 | -------------------------------------------------------------------------------- /linux/IUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #include 19 | 20 | #include 21 | 22 | using stm::core::IUtils; 23 | 24 | class Utils : public IUtils { 25 | public: 26 | Utils(void) = default; 27 | ~Utils(void) = default; 28 | 29 | Utils(const Utils &) = delete; 30 | Utils& operator= (const Utils &) = delete; 31 | 32 | int64_t getTime(void) const override; 33 | }; 34 | 35 | int64_t Utils::getTime(void) const 36 | { 37 | struct timespec ts; 38 | 39 | if (clock_gettime(CLOCK_BOOTTIME, &ts)) { 40 | return -1; 41 | } 42 | 43 | return (ts.tv_sec * 1e9) + ts.tv_nsec; 44 | } 45 | 46 | IUtils& IUtils::getInstance(void) 47 | { 48 | static Utils instance; 49 | 50 | return instance; 51 | } 52 | -------------------------------------------------------------------------------- /linux/LinuxPropertiesLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2022 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | using stm::core::PropertyId; 24 | using stm::core::SensorPropertyId; 25 | using stm::core::SensorType; 26 | 27 | class LinuxPropertiesLoader : public stm::core::PropertiesLoader { 28 | private: 29 | stm::core::IConsole& console = stm::core::IConsole::getInstance(); 30 | 31 | std::unordered_map> sensorProperties; 33 | 34 | std::unordered_map properties; 35 | 36 | SensorType getSensorTypeForProperty(const std::string& line); 37 | 38 | void parseConfigLine(std::string& line); 39 | 40 | public: 41 | int loadFromConfigFile(const std::string& filename); 42 | 43 | virtual int readInt(PropertyId property) const override; 44 | 45 | virtual std::string readString(SensorPropertyId property, 46 | SensorType sensorType) const override; 47 | 48 | virtual int readInt(SensorPropertyId property, 49 | SensorType sensorType) const override; 50 | }; 51 | -------------------------------------------------------------------------------- /linux/SensorsLinuxInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | using stm::core::ISTMSensorsHAL; 27 | using stm::core::ISTMSensorsCallback; 28 | using stm::core::ISTMSensorsCallbackData; 29 | using stm::core::STMSensor; 30 | using stm::core::IConsole; 31 | using stm::core::PropertiesManager; 32 | 33 | struct SensorsLinuxInterface : public ISTMSensorsCallback { 34 | public: 35 | SensorsLinuxInterface(void); 36 | ~SensorsLinuxInterface(void) = default; 37 | 38 | int initialize(void); 39 | 40 | const std::vector& getSensorsList(void) const; 41 | 42 | int enable(uint32_t handle, bool enable); 43 | 44 | int setRate(uint32_t handle, 45 | int64_t samplingPeriodNanoSec, 46 | int64_t maxReportLatencyNanoSec); 47 | 48 | int setFullScale(uint32_t handle, float fullscale); 49 | 50 | void onNewSensorsData(const std::vector &sensorsData) override; 51 | 52 | int onSaveDataRequest(const std::string& resourceID, const void *data, ssize_t len) override; 53 | 54 | int onLoadDataRequest(const std::string& resourceID, void *data, ssize_t len) override; 55 | 56 | private: 57 | /** 58 | * Core library object interface 59 | */ 60 | ISTMSensorsHAL &sensorsCore; 61 | 62 | /** 63 | * Print console 64 | */ 65 | IConsole &console; 66 | 67 | PropertiesManager& propertiesManager; 68 | }; 69 | -------------------------------------------------------------------------------- /linux/cmake/toolchain-arm32.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (C) 2018 The Android Open Source Project 3 | ## Copyright (C) 2020 STMicroelectronics 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 | set(CMAKE_SYSTEM_NAME Linux) 18 | set(CMAKE_SYSTEM_PROCESSOR arm) 19 | 20 | set(triple arm-linux-gnueabihf) 21 | 22 | set(CMAKE_C_COMPILER ${triple}-gcc) 23 | set(CMAKE_CXX_COMPILER ${triple}-g++) 24 | 25 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 27 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 28 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 29 | -------------------------------------------------------------------------------- /linux/cmake/toolchain-arm64.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (C) 2018 The Android Open Source Project 3 | ## Copyright (C) 2020 STMicroelectronics 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 | set(CMAKE_SYSTEM_NAME Linux) 18 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 19 | 20 | set(triple aarch64-linux-gnu) 21 | 22 | set(CMAKE_C_COMPILER ${triple}-gcc) 23 | set(CMAKE_CXX_COMPILER ${triple}-g++) 24 | 25 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 27 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 28 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 29 | -------------------------------------------------------------------------------- /linux/readme.org: -------------------------------------------------------------------------------- 1 | #+TITLE: sensors-hal-iio Linux 2 | #+SUBTITLE: notes 3 | #+AUTHOR: MEMS Software Solutions Team 4 | 5 | * Introduction 6 | 7 | This is the documentation page for the Linux components of the sensors-hal iio. 8 | 9 | * Configuration 10 | ** runtime configuration (startup) 11 | 12 | Configuration file can be used to set parameters at runtime (during init). 13 | If a parameter is set in the configuration file, default value for that parameter will be discarded. 14 | 15 | Here a list of possible parameters: 16 | 17 | - max-odr 18 | - rot-matrix-1.SENSORTYPE 19 | - rot-matrix-2.SENSORTYPE 20 | - placement-1.SENSORTYPE 21 | - placement-2.SENSORTYPE 22 | - max-range.SENSORTYPE 23 | 24 | where SENSORTYPE can be one of these values: 25 | 26 | - accel 27 | - magn 28 | - gyro 29 | 30 | Example of configuration file usage (default /etc/stm-sensors-hal/config): 31 | 32 | #+begin_src conf 33 | #max odr that can be used is 250Hz 34 | max-odr = 250 35 | 36 | #accel rotation matrix 37 | rot-matrix-1.accel = "1.0,0,0,0,1.0,0,0,0,1.0" 38 | #accel position in mm 39 | placement-1.accel = "10,20,30" 40 | 41 | #accel full-scale to support reading of at least 70m/s^2 42 | max-range.accel = 70 43 | #magn full-scale to support reading of at least 2000uT 44 | max-range.magn = 2000 45 | #gyro full-scale to support reading of at least 8rad/s 46 | max-range.gyro = 8 47 | #+end_src 48 | 49 | ** Default settings 50 | 51 | Default parameters can be set at compile time by changing the CMakeLists.txt cflags (under core, see core documentation). 52 | 53 | * Build instructions 54 | 55 | 1> clone this repository into desired folder: 56 | 57 | #+begin_src shell 58 | git clone https://github.com/STMicroelectronics/st-mems-android-linux-sensors-hal.git 59 | #+end_src 60 | 61 | ** release build 62 | 63 | #+begin_src shell 64 | cmake -DCMAKE_BUILD_TYPE=Release ${PROJECT_SOURCE_PATH} 65 | #+end_src 66 | 67 | ** debug build 68 | 69 | #+begin_src shell 70 | cmake -DCMAKE_BUILD_TYPE=Debug ${PROJECT_SOURCE_PATH} 71 | #+end_src 72 | 73 | ** export compile commands 74 | 75 | #+begin_src shell 76 | cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ${PROJECT_SOURCE_PATH} 77 | #+end_src 78 | 79 | ** cross-compile 80 | 81 | - arm64 82 | 83 | #+begin_src shell 84 | cmake -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm64.cmake ${PROJECT_SOURCE_PATH} 85 | #+end_src 86 | 87 | - arm32 88 | 89 | #+begin_src shell 90 | cmake -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm32.cmake ${PROJECT_SOURCE_PATH} 91 | #+end_src 92 | 93 | ** ninja build 94 | 95 | #+begin_src shell 96 | cmake -GNinja ${PROJECT_SOURCE_PATH} 97 | #+end_src 98 | -------------------------------------------------------------------------------- /multi-hal/AdditionalInfoManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2020 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include "SensorPlacement.h" 26 | 27 | using ::android::hardware::sensors::V2_1::Event; 28 | using stm::core::STMSensorsList; 29 | 30 | struct AdditionalInfoManager { 31 | public: 32 | AdditionalInfoManager(const STMSensorsList &list); 33 | ~AdditionalInfoManager(void) = default; 34 | 35 | const std::vector getPayload(int sensorHandle, int64_t timestamp) const; 36 | 37 | bool isSupported(int sensorHandle) const; 38 | 39 | private: 40 | /** 41 | * Is additional info available for this sensor handle? 42 | */ 43 | std::vector supported; 44 | 45 | /** 46 | * Sensors placement data 47 | */ 48 | std::vector placements; 49 | 50 | Event makeSensorPlacementFrame(int sensorHandle, int serial, int64_t timestamp) const; 51 | 52 | static Event getBeginFrame(int sensorHandle, int64_t timestamp); 53 | 54 | static Event getEndFrame(int sensorHandle, int serial, int64_t timestamp); 55 | }; 56 | -------------------------------------------------------------------------------- /multi-hal/Convert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2022 STMicroelectronics 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 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace android { 25 | namespace hardware { 26 | namespace sensors { 27 | namespace stm { 28 | namespace multihal { 29 | 30 | bool convertFromSTMSensorType(const ::stm::core::SensorType& type, 31 | V2_1::SensorType& sensorType); 32 | 33 | bool convertFromSTMSensor(const ::stm::core::STMSensor& src, 34 | V2_1::SensorInfo *dst); 35 | 36 | void convertFromSTMSensorData(const ::stm::core::ISTMSensorsCallbackData& sensorData, 37 | V2_1::Event& event); 38 | 39 | } // namespace multihal 40 | } // namespace stm 41 | } // namespace sensors 42 | } // namespace hardware 43 | } // namespace android 44 | -------------------------------------------------------------------------------- /multi-hal/IUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * Copyright (C) 2019-2022 STMicroelectronics 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 | #include 19 | 20 | #include 21 | 22 | namespace android { 23 | namespace hardware { 24 | namespace sensors { 25 | namespace stm { 26 | namespace multihal { 27 | 28 | class Utils : public ::stm::core::IUtils { 29 | public: 30 | Utils(void) = default; 31 | ~Utils(void) = default; 32 | 33 | Utils(const Utils&) = delete; 34 | Utils& operator= (const Utils&) = delete; 35 | 36 | int64_t getTime(void) const override; 37 | }; 38 | 39 | int64_t Utils::getTime(void) const 40 | { 41 | return android::elapsedRealtimeNano(); 42 | } 43 | 44 | } // namespace multihal 45 | } // namespace stm 46 | } // namespace sensors 47 | } // namespace hardware 48 | } // namespace android 49 | 50 | namespace stm { 51 | namespace core { 52 | 53 | using android::hardware::sensors::stm::multihal::Utils; 54 | 55 | IUtils& IUtils::getInstance(void) 56 | { 57 | static Utils instance; 58 | 59 | return instance; 60 | } 61 | 62 | } // namespace core 63 | } // namespace stm 64 | --------------------------------------------------------------------------------