1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef SENSOR_GYRO_DRIVER_H 10 #define SENSOR_GYRO_DRIVER_H 11 12 #include "hdf_workqueue.h" 13 #include "osal_mutex.h" 14 #include "osal_timer.h" 15 #include "sensor_config_parser.h" 16 #include "sensor_platform_if.h" 17 18 #define GYRO_DEFAULT_SAMPLING_200_MS 200000000 19 #define GYRO_CHIP_NAME_BMI160 "bmi160" 20 21 enum GyroAxisNum { 22 GYRO_X_AXIS = 0, 23 GYRO_Y_AXIS = 1, 24 GYRO_Z_AXIS = 2, 25 GYRO_AXIS_NUM = 3, 26 }; 27 28 enum GyroAxisPart { 29 GYRO_X_AXIS_LSB = 0, 30 GYRO_X_AXIS_MSB = 1, 31 GYRO_Y_AXIS_LSB = 2, 32 GYRO_Y_AXIS_MSB = 3, 33 GYRO_Z_AXIS_LSB = 4, 34 GYRO_Z_AXIS_MSB = 5, 35 GYRO_AXIS_BUTT, 36 }; 37 38 struct GyroData { 39 int32_t x; 40 int32_t y; 41 int32_t z; 42 }; 43 44 struct GyroDetectIfList { 45 char *chipName; 46 int32_t (*DetectChip)(struct SensorCfgData *data); 47 }; 48 49 struct GyroOpsCall { 50 int32_t (*Init)(struct SensorCfgData *data); 51 int32_t (*ReadData)(struct SensorCfgData *data); 52 }; 53 54 struct GyroDrvData { 55 struct IDeviceIoService ioService; 56 struct HdfDeviceObject *device; 57 HdfWorkQueue gyroWorkQueue; 58 HdfWork gyroWork; 59 OsalTimer gyroTimer; 60 bool detectFlag; 61 bool enable; 62 bool initStatus; 63 int64_t interval; 64 struct SensorCfgData *gyroCfg; 65 struct GyroOpsCall ops; 66 }; 67 68 int32_t RegisterGyroChipOps(const struct GyroOpsCall *ops); 69 70 #endif /* SENSOR_GYRO_DRIVER_H */ 71