1 /* 2 * Copyright (c) 2024 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_GAS_DRIVER_H 10 #define SENSOR_GAS_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 GasIAQPart { 19 GAS_PART_IAQ = 0, 20 GAS_PART_SUM, 21 }; 22 23 enum GasClaPart { 24 GAS_PART_GASRES = 0, 25 GAS_PART_HEAT = 1, 26 GAS_PART_TEMP = 2, 27 GAS_PART_HUMI = 3, 28 GAS_PART_PRE = 4, 29 GAS_DEP_PART_SUM, 30 }; 31 32 struct GasData { 33 union { 34 struct { 35 uint32_t gasResitance; 36 uint32_t heatSource; 37 int16_t temperature; 38 uint32_t humidity; 39 uint32_t pressure; 40 }; 41 float iaq; 42 }; 43 }; 44 45 struct GasFieldData { 46 uint8_t status; /*! Contains new_data, gasm_valid & heat_stab */ 47 uint8_t gas_index; /*! The index of the heater profile used */ 48 uint8_t meas_index; /*! Measurement index to track order */ 49 uint8_t res_heat; /*! Heater resistance */ 50 uint8_t idac; /*! Current DAC */ 51 uint8_t gas_wait; /*! Gas wait period */ 52 int16_t temperature; /*! Temperature in degree celsius */ 53 uint32_t pressure; /*! Pressure in Pascal */ 54 uint32_t humidity; /*! Humidity in % relative humidity x1000 */ 55 uint32_t gas_resistance; /*! Gas resistance in Ohms */ 56 }; 57 58 struct GasCfg { 59 uint8_t humOs; 60 uint8_t tempOs; 61 uint8_t presOs; 62 uint8_t filter; 63 uint8_t odr; 64 }; 65 66 struct GasOpsCall { 67 int32_t (*Init)(struct SensorCfgData *data); 68 int32_t (*ReadData)(struct SensorCfgData *data, struct SensorReportEvent *event); 69 }; 70 71 struct GasDrvData { 72 struct IDeviceIoService ioService; 73 struct HdfDeviceObject *device; 74 HdfWorkQueue gasWorkQueue; 75 HdfWork gasWork; 76 OsalTimer gasTimer; 77 bool detectFlag; 78 bool enable; 79 int64_t interval; 80 struct SensorCfgData *gasCfg; 81 struct GasOpsCall ops; 82 }; 83 84 int32_t GasRegisterChipOps(const struct GasOpsCall *ops); 85 struct SensorCfgData *GasCreateCfgData(const struct DeviceResourceNode *node); 86 void GasReleaseCfgData(struct SensorCfgData *gasCfg); 87 88 #endif /* SENSOR_GAS_DRIVER_H*/