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_ALS_DRIVER_H 10 #define SENSOR_ALS_DRIVER_H 11 12 #include "hdf_workqueue.h" 13 #include "osal_timer.h" 14 #include "sensor_config_parser.h" 15 #include "sensor_platform_if.h" 16 17 #define ALS_DEFAULT_SAMPLING_200_MS 200000000 18 #define ALS_CHIP_NAME_BH1745 "bh1745" 19 #define INVALID_VALUE (-1) 20 21 enum ExtendedAlsRegGroupType { 22 EXTENDED_ALS_TIME_GROUP = 0, 23 EXTENDED_ALS_GAIN_GROUP, 24 EXTENDED_ALS_GROUP_MAX, 25 }; 26 27 enum AlsLightNum { 28 ALS_R = 0, 29 ALS_G = 1, 30 ALS_B = 2, 31 ALS_C = 3, 32 ALS_LIGHT_NUM = 4, 33 }; 34 35 enum AlsLightPart { 36 ALS_R_LSB = 0, 37 ALS_R_MSB = 1, 38 ALS_G_LSB = 2, 39 ALS_G_MSB = 3, 40 ALS_B_LSB = 4, 41 ALS_B_MSB = 5, 42 ALS_C_LSB = 6, 43 ALS_C_MSB = 7, 44 ALS_LIGHT_BUTT = 8, 45 }; 46 47 struct AlsReportData { 48 int32_t als; 49 int32_t cct; 50 int32_t irData; 51 }; 52 53 struct TimeRegAddrValueMap { 54 uint8_t timeRegKey; 55 uint32_t timeValue; 56 }; 57 58 struct GainRegAddrValueMap { 59 uint8_t gainRegKey; 60 uint32_t gainValue; 61 }; 62 63 struct AlsData { 64 int32_t red; 65 int32_t green; 66 int32_t blue; 67 int32_t clear; 68 }; 69 70 struct AlsOpsCall { 71 int32_t (*Init)(struct SensorCfgData *data); 72 int32_t (*ReadData)(struct SensorCfgData *data, struct SensorReportEvent *event); 73 }; 74 75 struct AlsDrvData { 76 struct IDeviceIoService ioService; 77 struct HdfDeviceObject *device; 78 HdfWorkQueue alsWorkQueue; 79 HdfWork alsWork; 80 OsalTimer alsTimer; 81 bool detectFlag; 82 bool enable; 83 int64_t interval; 84 struct SensorCfgData *alsCfg; 85 struct AlsOpsCall ops; 86 }; 87 88 int32_t AlsRegisterChipOps(const struct AlsOpsCall *ops); 89 struct SensorCfgData *AlsCreateCfgData(const struct DeviceResourceNode *node); 90 void AlsReleaseCfgData(struct SensorCfgData *alsCfg); 91 int32_t GetTimeByRegValue(uint8_t regValue, struct TimeRegAddrValueMap *map, int32_t itemNum); 92 int32_t GetRegGroupIndexByTime(uint32_t timeValue, struct TimeRegAddrValueMap *map, int32_t itemNum); 93 int32_t GetGainByRegValue(uint8_t regValue, struct GainRegAddrValueMap *map, int32_t itemNum); 94 #endif /* SENSOR_ALS_DRIVER_H */ 95