1 /* 2 * Copyright (c) 2023 Andreas Kilian 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_VEML7700_H_ 8 #define ZEPHYR_INCLUDE_DRIVERS_SENSOR_VEML7700_H_ 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 /** 15 * @brief Number of enumerators in enum veml7700_als_gain. 16 */ 17 #define VEML7700_ALS_GAIN_ELEM_COUNT 4 18 /** 19 * @brief Number of enumerators in enum veml7700_als_it. 20 */ 21 #define VEML7700_ALS_IT_ELEM_COUNT 6 22 23 /** 24 * @brief Bit mask to check for the low threshold interrupt flag. 25 * 26 * See <tt>SENSOR_ATTR_VEML7700_INT_MODE</tt> 27 * and <tt>SENSOR_CHAN_VEML7700_INTERRUPT</tt> 28 */ 29 #define VEML7700_ALS_INT_LOW_MASK BIT(15) 30 /** 31 * @brief Bit mask to check for the high threshold interrupt flag. 32 * 33 * See <tt>SENSOR_ATTR_VEML7700_INT_MODE</tt> 34 * and <tt>SENSOR_CHAN_VEML7700_INTERRUPT</tt> 35 */ 36 #define VEML7700_ALS_INT_HIGH_MASK BIT(14) 37 38 /** 39 * @brief VEML7700 gain options for ambient light measurements. 40 */ 41 enum veml7700_als_gain { 42 VEML7700_ALS_GAIN_1 = 0x00, /* 0b00 */ 43 VEML7700_ALS_GAIN_2 = 0x01, /* 0b01 */ 44 VEML7700_ALS_GAIN_1_8 = 0x02, /* 0b10 */ 45 VEML7700_ALS_GAIN_1_4 = 0x03, /* 0b11 */ 46 }; 47 48 /** 49 * @brief VEML7700 integration time options for ambient light measurements. 50 */ 51 enum veml7700_als_it { 52 VEML7700_ALS_IT_25, 53 VEML7700_ALS_IT_50, 54 VEML7700_ALS_IT_100, 55 VEML7700_ALS_IT_200, 56 VEML7700_ALS_IT_400, 57 VEML7700_ALS_IT_800 58 }; 59 60 /** 61 * @brief VEML7700 ALS interrupt persistence protect number options. 62 */ 63 enum veml7700_int_mode { 64 VEML7700_INT_DISABLED = 0xFF, 65 VEML7700_ALS_PERS_1 = 0x00, /* 0b00 */ 66 VEML7700_ALS_PERS_2 = 0x01, /* 0b01 */ 67 VEML7700_ALS_PERS_4 = 0x02, /* 0b10 */ 68 VEML7700_ALS_PERS_8 = 0x03, /* 0b11 */ 69 }; 70 71 /** 72 * @brief VEML7700 specific sensor attributes. 73 * 74 * For high and low threshold window settings (ALS_WH and ALS_WL) 75 * use the generic attributes <tt>SENSOR_ATTR_UPPER_THRESH</tt> and 76 * <tt>SENSOR_ATTR_LOWER_THRESH</tt> with 16-bit unsigned integer 77 * values. Both threshold settings are in lux and converted by the 78 * driver to a value compatible with the sensor. This conversion 79 * depends on the current gain and integration time settings. So a 80 * change in gain or integration time usually requires an update of 81 * threshold window settings. To get the correct threshold values 82 * into the sensor update the thresholds -after- a change of gain 83 * or integration time. 84 * 85 * All attributes must be set for the <tt>SENSOR_CHAN_LIGHT</tt> channel. 86 */ 87 enum sensor_attribute_veml7700 { 88 /** 89 * @brief Gain setting for ALS measurements (ALS_GAIN). 90 * 91 * Use enum veml7700_als_gain for attribute values. 92 */ 93 SENSOR_ATTR_VEML7700_GAIN = SENSOR_ATTR_PRIV_START, 94 /** 95 * @brief Integration time setting for ALS measurements (ALS_IT). 96 * 97 * Use enum veml7700_als_it for attribute values. 98 */ 99 SENSOR_ATTR_VEML7700_ITIME, 100 /** 101 * @brief Enable or disable use of ALS interrupt 102 * (ALS_INT_EN and ALS_PERS). 103 * 104 * Please mind that the VEML7700 does not have an interrupt pin. 105 * That's why this driver does not implement any asynchronous 106 * notification mechanism. Such notifications would require to 107 * periodically query the sensor for it's interrupt state and then 108 * trigger an event based on that state. It's up to the user to 109 * query the interrupt state manually using 110 * <tt>sensor_channel_fetch_chan()</tt> on the 111 * <tt>SENSOR_CHAN_VEML7700_INTERRUPT</tt> channel or using 112 * <tt>sensor_channel_fetch()</tt>. 113 * 114 * Use enum veml7700_int_mode for attribute values. 115 */ 116 SENSOR_ATTR_VEML7700_INT_MODE, 117 }; 118 119 /** 120 * @brief VEML7700 specific sensor channels. 121 */ 122 enum sensor_channel_veml7700 { 123 /** 124 * @brief Channel for raw ALS sensor values. 125 * 126 * This channel represents the raw measurement counts provided by the 127 * sensors ALS register. It is useful for estimating the high/low 128 * threshold window attributes for the sensors interrupt handling. 129 * 130 * You cannot fetch this channel explicitly. Instead, this channel's 131 * value is fetched implicitly using <tt>SENSOR_CHAN_LIGHT</tt>. 132 * Trying to call <tt>sensor_channel_fetch_chan()</tt> with this 133 * enumerator as an argument will result in a <tt>-ENOTSUP</tt>. 134 */ 135 SENSOR_CHAN_VEML7700_RAW_COUNTS = SENSOR_CHAN_PRIV_START, 136 137 /** 138 * @brief This channel is used to query the ALS interrupt state (ALS_INT). 139 * 140 * In order for this channel to provide any meaningful data you need 141 * to enable the ALS interrupt mode using the 142 * <tt>SENSOR_ATTR_VEML7700_INT_MODE</tt> custom sensor attribute. 143 * 144 * It's important to note that the sensor resets it's interrupt state 145 * after retrieving it. 146 */ 147 SENSOR_CHAN_VEML7700_INTERRUPT, 148 }; 149 150 #ifdef __cplusplus 151 } 152 #endif 153 154 #endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_VEML7700_H_ */ 155