1 /* 2 * Copyright (C) 2020 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 #ifndef ANDROID_SENSORS_IIO_UTILS_H 17 #define ANDROID_SENSORS_IIO_UTILS_H 18 19 #include <android/hardware/sensors/1.0/types.h> 20 #include <dirent.h> 21 #include <linux/ioctl.h> 22 #include <linux/types.h> 23 #include <stdint.h> 24 #include <sys/ioctl.h> 25 26 namespace android { 27 namespace hardware { 28 namespace sensors { 29 namespace V2_0 { 30 namespace subhal { 31 namespace implementation { 32 33 using ::android::hardware::sensors::V1_0::SensorType; 34 35 static constexpr auto DEFAULT_IIO_BUFFER_LEN = 2; 36 static constexpr auto DISABLE_CHANNEL = 0; 37 static constexpr auto ENABLE_CHANNEL = 1; 38 39 struct sensors_supported_hal { 40 std::string name; 41 SensorType type; 42 }; 43 44 struct iio_info_channel { 45 std::string name; 46 uint8_t index; 47 uint8_t storage_bytes; 48 uint8_t bits_used; 49 uint8_t shift; 50 bool big_endian; 51 bool sign; 52 }; 53 54 struct iio_device_data { 55 std::string name; 56 std::string sysfspath; 57 float resolution; 58 SensorType type; 59 std::vector<iio_info_channel> channelInfo; 60 std::vector<double> sampling_freq_avl; 61 uint8_t iio_dev_num; 62 unsigned int power_microwatts; 63 int64_t max_range; 64 }; 65 66 int load_iio_devices(std::vector<iio_device_data>* iio_data, 67 const std::vector<sensors_supported_hal>& supported_sensors); 68 int scan_elements(const std::string& device_dir, struct iio_device_data* iio_data); 69 int enable_sensor(const std::string& name, const bool flag); 70 int set_sampling_frequency(const std::string& name, const double frequency); 71 } // namespace implementation 72 } // namespace subhal 73 } // namespace V2_0 74 } // namespace sensors 75 } // namespace hardware 76 } // namespace android 77 #endif 78