1 /* 2 * Copyright (c) 2021-2022 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 ALS_BH1745_H 10 #define ALS_BH1745_H 11 12 #include "sensor_als_driver.h" 13 #include "sensor_config_parser.h" 14 15 /* ALS DATA REGISTERS ADDR */ 16 #define BH1745_ALS_R_LSB_ADDR 0X50 17 #define BH1745_ALS_R_MSB_ADDR 0X51 18 #define BH1745_ALS_G_LSB_ADDR 0X52 19 #define BH1745_ALS_G_MSB_ADDR 0X53 20 #define BH1745_ALS_B_LSB_ADDR 0X54 21 #define BH1745_ALS_B_MSB_ADDR 0X55 22 #define BH1745_ALS_C_LSB_ADDR 0X56 23 #define BH1745_ALS_C_MSB_ADDR 0X57 24 #define BH1745_MODECONTROL3_ADDR 0X44 25 26 /* ALS DATA READY */ 27 #define BH1745_ALS_DATA_READY_MASK 0X02 28 29 /* ALS MULTIPLE */ 30 #define BH1745_MULTIPLE_100 100 31 32 /* ALS COEFFICIENT */ 33 #define BH1745_COEFFICIENT_RED 2 34 #define BH1745_COEFFICIENT_GREEN 2 35 #define BH1745_COEFFICIENT_RED_LEVEL_0 7730 // 7.73 * 1000 36 #define BH1745_COEFFICIENT_RED_LEVEL_1 9271 // 9.2715 * 1000 37 #define BH1745_COEFFICIENT_GREEN_LEVEL_0 13192 // 1.3192 * 1000 38 #define BH1745_COEFFICIENT_GREEN_LEVEL_1 21477 // 2.1477 * 1000 39 #define BH1745_COEFFICIENT_JUDGE 78 // 0.78*100 40 41 /* ALS TIME */ 42 #define BH1745_TIME_160MSEC 160 43 #define BH1745_TIME_320MSEC 320 44 #define BH1745_TIME_640MSEC 640 45 #define BH1745_TIME_1280MSEC 1280 46 #define BH1745_TIME_2560MSEC 2560 47 #define BH1745_TIME_5120MSEC 5120 48 #define BH1745_TIME_MAX 5570475 // 65535*0.85*100 49 #define BH1745_TIME_MIN 1638375 // 65535*0.25*100 50 51 /* ALS GAIN */ 52 #define BH1745_GAIN_1X 1 53 #define BH1745_GAIN_2X 2 54 #define BH1745_GAIN_16X 16 55 56 /* ALS TIME REG VALUE */ 57 #define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_0 0x00 58 #define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_1 0x01 59 #define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_2 0x02 60 #define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_3 0x03 61 #define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_4 0x04 62 #define EXTENDED_ALS_TIME_GROUP_ATTR_VALUE_5 0x05 63 64 /* ALS GAIN REG VALUE */ 65 #define EXTENDED_ALS_GAIN_GROUP_ATTR_VALUE_0 0x00 66 #define EXTENDED_ALS_GAIN_GROUP_ATTR_VALUE_1 0x01 67 #define EXTENDED_ALS_GAIN_GROUP_ATTR_VALUE_2 0x02 68 69 enum ExtendedAlsTimeRegGroupIndex { 70 EXTENDED_ALS_TIME_GROUP_INDEX_0 = 0, 71 EXTENDED_ALS_TIME_GROUP_INDEX_1, 72 EXTENDED_ALS_TIME_GROUP_INDEX_2, 73 EXTENDED_ALS_TIME_GROUP_INDEX_3, 74 EXTENDED_ALS_TIME_GROUP_INDEX_4, 75 EXTENDED_ALS_TIME_GROUP_INDEX_5, 76 EXTENDED_ALS_TIME_GROUP_INDEX_MAX, 77 }; 78 79 enum ExtendedAlsGainRegGroupIndex { 80 EXTENDED_ALS_GAIN_GROUP_INDEX_0 = 0, 81 EXTENDED_ALS_GAIN_GROUP_INDEX_1, 82 EXTENDED_ALS_GAIN_GROUP_INDEX_2, 83 EXTENDED_ALS_GAIN_GROUP_INDEX_MAX, 84 }; 85 86 int32_t DetectAlsBim160Chip(struct SensorCfgData *data); 87 int32_t ReadBh1745Data(struct SensorCfgData *data, struct SensorReportEvent *event); 88 89 struct Bh1745DrvData { 90 struct IDeviceIoService ioService; 91 struct HdfDeviceObject *device; 92 struct SensorCfgData *sensorCfg; 93 }; 94 95 #endif /* ALS_BH1745_H */ 96