1 /* 2 * Copyright (c) 2020-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 enum GyroAxisNum { 19 GYRO_X_AXIS = 0, 20 GYRO_Y_AXIS = 1, 21 GYRO_Z_AXIS = 2, 22 GYRO_AXIS_NUM = 3, 23 }; 24 25 enum GyroAxisPart { 26 GYRO_X_AXIS_LSB = 0, 27 GYRO_X_AXIS_MSB = 1, 28 GYRO_Y_AXIS_LSB = 2, 29 GYRO_Y_AXIS_MSB = 3, 30 GYRO_Z_AXIS_LSB = 4, 31 GYRO_Z_AXIS_MSB = 5, 32 GYRO_AXIS_BUTT, 33 }; 34 35 struct GyroData { 36 int32_t x; 37 int32_t y; 38 int32_t z; 39 }; 40 41 struct GyroOpsCall { 42 int32_t (*Init)(struct SensorCfgData *data); 43 int32_t (*ReadData)(struct SensorCfgData *data); 44 }; 45 46 struct GyroDrvData { 47 struct IDeviceIoService ioService; 48 struct HdfDeviceObject *device; 49 HdfWorkQueue gyroWorkQueue; 50 HdfWork gyroWork; 51 OsalTimer gyroTimer; 52 bool detectFlag; 53 bool enable; 54 int64_t interval; 55 struct SensorCfgData *gyroCfg; 56 struct GyroOpsCall ops; 57 }; 58 59 int32_t GyroRegisterChipOps(const struct GyroOpsCall *ops); 60 struct SensorCfgData *GyroCreateCfgData(const struct DeviceResourceNode *node); 61 void GyroReleaseCfgData(struct SensorCfgData *gyroCfg); 62 63 #endif /* SENSOR_GYRO_DRIVER_H */ 64