SI1133 light sensor

Committer:
brunnobbco
Date:
Wed Nov 06 20:10:47 2019 +0000
Revision:
0:fe6c4edd0ecc
Light sensor to NRF52840

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brunnobbco 0:fe6c4edd0ecc 1 /***************************************************************************//**
brunnobbco 0:fe6c4edd0ecc 2 * @file Si1133.h
brunnobbco 0:fe6c4edd0ecc 3 *******************************************************************************
brunnobbco 0:fe6c4edd0ecc 4 * @section License
brunnobbco 0:fe6c4edd0ecc 5 * <b>(C) Copyright 2017 Silicon Labs, http://www.silabs.com</b>
brunnobbco 0:fe6c4edd0ecc 6 *******************************************************************************
brunnobbco 0:fe6c4edd0ecc 7 *
brunnobbco 0:fe6c4edd0ecc 8 * SPDX-License-Identifier: Apache-2.0
brunnobbco 0:fe6c4edd0ecc 9 *
brunnobbco 0:fe6c4edd0ecc 10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
brunnobbco 0:fe6c4edd0ecc 11 * not use this file except in compliance with the License.
brunnobbco 0:fe6c4edd0ecc 12 * You may obtain a copy of the License at
brunnobbco 0:fe6c4edd0ecc 13 *
brunnobbco 0:fe6c4edd0ecc 14 * http://www.apache.org/licenses/LICENSE-2.0
brunnobbco 0:fe6c4edd0ecc 15 *
brunnobbco 0:fe6c4edd0ecc 16 * Unless required by applicable law or agreed to in writing, software
brunnobbco 0:fe6c4edd0ecc 17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
brunnobbco 0:fe6c4edd0ecc 18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
brunnobbco 0:fe6c4edd0ecc 19 * See the License for the specific language governing permissions and
brunnobbco 0:fe6c4edd0ecc 20 * limitations under the License.
brunnobbco 0:fe6c4edd0ecc 21 *
brunnobbco 0:fe6c4edd0ecc 22 ******************************************************************************/
brunnobbco 0:fe6c4edd0ecc 23
brunnobbco 0:fe6c4edd0ecc 24 #ifndef SI1133_H
brunnobbco 0:fe6c4edd0ecc 25 #define SI1133_H
brunnobbco 0:fe6c4edd0ecc 26
brunnobbco 0:fe6c4edd0ecc 27 #include "mbed.h"
brunnobbco 0:fe6c4edd0ecc 28
brunnobbco 0:fe6c4edd0ecc 29 /** Si1133 class.
brunnobbco 0:fe6c4edd0ecc 30 * Used for taking Light level and UV index measurements.
brunnobbco 0:fe6c4edd0ecc 31 *
brunnobbco 0:fe6c4edd0ecc 32 * Example:
brunnobbco 0:fe6c4edd0ecc 33 * @code
brunnobbco 0:fe6c4edd0ecc 34 * #include "mbed.h"
brunnobbco 0:fe6c4edd0ecc 35 * #include "Si1133.h"
brunnobbco 0:fe6c4edd0ecc 36 *
brunnobbco 0:fe6c4edd0ecc 37 * //Create an Si1133 object
brunnobbco 0:fe6c4edd0ecc 38 * Si1133 sensor(PC4, PC5);
brunnobbco 0:fe6c4edd0ecc 39 *
brunnobbco 0:fe6c4edd0ecc 40 * int main()
brunnobbco 0:fe6c4edd0ecc 41 * {
brunnobbco 0:fe6c4edd0ecc 42 * //Try to open the Si1133
brunnobbco 0:fe6c4edd0ecc 43 * if (sensor.open()) {
brunnobbco 0:fe6c4edd0ecc 44 * printf("Device detected!\n");
brunnobbco 0:fe6c4edd0ecc 45 *
brunnobbco 0:fe6c4edd0ecc 46 * while (1) {
brunnobbco 0:fe6c4edd0ecc 47 * //Print the current light level
brunnobbco 0:fe6c4edd0ecc 48 * printf("Lux = %.3f\n", (float)sensor.get_light_level());
brunnobbco 0:fe6c4edd0ecc 49 * //Print the current UV index
brunnobbco 0:fe6c4edd0ecc 50 * printf("UV index = %.3f\n", (float)sensor.get_uv_index());
brunnobbco 0:fe6c4edd0ecc 51 *
brunnobbco 0:fe6c4edd0ecc 52 * //Sleep for 0.5 seconds
brunnobbco 0:fe6c4edd0ecc 53 * wait(0.5);
brunnobbco 0:fe6c4edd0ecc 54 * }
brunnobbco 0:fe6c4edd0ecc 55 * } else {
brunnobbco 0:fe6c4edd0ecc 56 * error("Device not detected!\n");
brunnobbco 0:fe6c4edd0ecc 57 * }
brunnobbco 0:fe6c4edd0ecc 58 * }
brunnobbco 0:fe6c4edd0ecc 59 * @endcode
brunnobbco 0:fe6c4edd0ecc 60 */
brunnobbco 0:fe6c4edd0ecc 61 class Si1133
brunnobbco 0:fe6c4edd0ecc 62 {
brunnobbco 0:fe6c4edd0ecc 63 public:
brunnobbco 0:fe6c4edd0ecc 64
brunnobbco 0:fe6c4edd0ecc 65 /** Create an Si1133 object connected to the specified I2C pins with the specified I2C slave address
brunnobbco 0:fe6c4edd0ecc 66 *
brunnobbco 0:fe6c4edd0ecc 67 * @param sda The I2C data pin.
brunnobbco 0:fe6c4edd0ecc 68 * @param scl The I2C clock pin.
brunnobbco 0:fe6c4edd0ecc 69 * @param hz The I2C bus frequency (defaults to 400kHz).
brunnobbco 0:fe6c4edd0ecc 70 */
brunnobbco 0:fe6c4edd0ecc 71 Si1133(PinName sda, PinName scl, int hz = 400000);
brunnobbco 0:fe6c4edd0ecc 72
brunnobbco 0:fe6c4edd0ecc 73 /**
brunnobbco 0:fe6c4edd0ecc 74 * Si1133 destructor
brunnobbco 0:fe6c4edd0ecc 75 */
brunnobbco 0:fe6c4edd0ecc 76 ~Si1133(void);
brunnobbco 0:fe6c4edd0ecc 77
brunnobbco 0:fe6c4edd0ecc 78 /** Probe for the Si1133 and try to initialize the sensor
brunnobbco 0:fe6c4edd0ecc 79 *
brunnobbco 0:fe6c4edd0ecc 80 * @returns
brunnobbco 0:fe6c4edd0ecc 81 * 'true' if the device exists on the bus,
brunnobbco 0:fe6c4edd0ecc 82 * 'false' if the device doesn't exist on the bus.
brunnobbco 0:fe6c4edd0ecc 83 */
brunnobbco 0:fe6c4edd0ecc 84 bool open();
brunnobbco 0:fe6c4edd0ecc 85
brunnobbco 0:fe6c4edd0ecc 86 /** Measure the current light level (in lux) on the Si1133
brunnobbco 0:fe6c4edd0ecc 87 *
brunnobbco 0:fe6c4edd0ecc 88 * @returns The current temperature measurement in Lux.
brunnobbco 0:fe6c4edd0ecc 89 */
brunnobbco 0:fe6c4edd0ecc 90 float get_light_level();
brunnobbco 0:fe6c4edd0ecc 91
brunnobbco 0:fe6c4edd0ecc 92 /** Measure the current UV Index on the Si1133
brunnobbco 0:fe6c4edd0ecc 93 *
brunnobbco 0:fe6c4edd0ecc 94 * @returns The current UV index measurement.
brunnobbco 0:fe6c4edd0ecc 95 */
brunnobbco 0:fe6c4edd0ecc 96 float get_uv_index();
brunnobbco 0:fe6c4edd0ecc 97
brunnobbco 0:fe6c4edd0ecc 98 /** Do a combined measurement and return both the light level and UV index
brunnobbco 0:fe6c4edd0ecc 99 *
brunnobbco 0:fe6c4edd0ecc 100 * @param[out] light_level Measured light level in Lux
brunnobbco 0:fe6c4edd0ecc 101 * @param[out] uv_index Measured UV index
brunnobbco 0:fe6c4edd0ecc 102 *
brunnobbco 0:fe6c4edd0ecc 103 * @returns true if measurement was successful
brunnobbco 0:fe6c4edd0ecc 104 */
brunnobbco 0:fe6c4edd0ecc 105 bool get_light_and_uv(float *light_level, float *uv_index);
brunnobbco 0:fe6c4edd0ecc 106
brunnobbco 0:fe6c4edd0ecc 107 #ifdef MBED_OPERATORS
brunnobbco 0:fe6c4edd0ecc 108 /** A shorthand for get_light_level()
brunnobbco 0:fe6c4edd0ecc 109 *
brunnobbco 0:fe6c4edd0ecc 110 * @returns The current temperature measurement in Lux.
brunnobbco 0:fe6c4edd0ecc 111 */
brunnobbco 0:fe6c4edd0ecc 112 operator float();
brunnobbco 0:fe6c4edd0ecc 113 #endif
brunnobbco 0:fe6c4edd0ecc 114
brunnobbco 0:fe6c4edd0ecc 115 private:
brunnobbco 0:fe6c4edd0ecc 116 /**
brunnobbco 0:fe6c4edd0ecc 117 * @name I2C Registers
brunnobbco 0:fe6c4edd0ecc 118 * @{
brunnobbco 0:fe6c4edd0ecc 119 */
brunnobbco 0:fe6c4edd0ecc 120 enum Register {
brunnobbco 0:fe6c4edd0ecc 121 REG_PART_ID = 0x00, /**< Part ID */
brunnobbco 0:fe6c4edd0ecc 122 REG_HW_ID = 0x01, /**< Hardware ID */
brunnobbco 0:fe6c4edd0ecc 123 REG_REV_ID = 0x02, /**< Hardware revision */
brunnobbco 0:fe6c4edd0ecc 124 REG_HOSTIN0 = 0x0A, /**< Data for parameter table on PARAM_SET write to COMMAND register */
brunnobbco 0:fe6c4edd0ecc 125 REG_COMMAND = 0x0B, /**< Initiated action in Sensor when specific codes written here */
brunnobbco 0:fe6c4edd0ecc 126 REG_IRQ_ENABLE = 0x0F, /**< Interrupt enable */
brunnobbco 0:fe6c4edd0ecc 127 REG_RESPONSE1 = 0x10, /**< Contains the readback value from a query or a set command */
brunnobbco 0:fe6c4edd0ecc 128 REG_RESPONSE0 = 0x11, /**< Chip state and error status */
brunnobbco 0:fe6c4edd0ecc 129 REG_IRQ_STATUS = 0x12, /**< Interrupt status */
brunnobbco 0:fe6c4edd0ecc 130 REG_HOSTOUT0 = 0x13, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 131 REG_HOSTOUT1 = 0x14, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 132 REG_HOSTOUT2 = 0x15, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 133 REG_HOSTOUT3 = 0x16, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 134 REG_HOSTOUT4 = 0x17, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 135 REG_HOSTOUT5 = 0x18, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 136 REG_HOSTOUT6 = 0x19, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 137 REG_HOSTOUT7 = 0x1A, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 138 REG_HOSTOUT8 = 0x1B, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 139 REG_HOSTOUT9 = 0x1C, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 140 REG_HOSTOUT10 = 0x1D, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 141 REG_HOSTOUT11 = 0x1E, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 142 REG_HOSTOUT12 = 0x1F, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 143 REG_HOSTOUT13 = 0x20, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 144 REG_HOSTOUT14 = 0x21, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 145 REG_HOSTOUT15 = 0x22, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 146 REG_HOSTOUT16 = 0x23, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 147 REG_HOSTOUT17 = 0x24, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 148 REG_HOSTOUT18 = 0x25, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 149 REG_HOSTOUT19 = 0x26, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 150 REG_HOSTOUT20 = 0x27, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 151 REG_HOSTOUT21 = 0x28, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 152 REG_HOSTOUT22 = 0x29, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 153 REG_HOSTOUT23 = 0x2A, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 154 REG_HOSTOUT24 = 0x2B, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 155 REG_HOSTOUT25 = 0x2C, /**< Captured Sensor Data */
brunnobbco 0:fe6c4edd0ecc 156 };
brunnobbco 0:fe6c4edd0ecc 157 /**@}*/
brunnobbco 0:fe6c4edd0ecc 158
brunnobbco 0:fe6c4edd0ecc 159 /**
brunnobbco 0:fe6c4edd0ecc 160 * @name Parameters
brunnobbco 0:fe6c4edd0ecc 161 * @{
brunnobbco 0:fe6c4edd0ecc 162 */
brunnobbco 0:fe6c4edd0ecc 163 enum Parameter {
brunnobbco 0:fe6c4edd0ecc 164 PARAM_I2C_ADDR = 0x00, /**< I2C address */
brunnobbco 0:fe6c4edd0ecc 165 PARAM_CH_LIST = 0x01, /**< Channel list */
brunnobbco 0:fe6c4edd0ecc 166 PARAM_ADCCONFIG0 = 0x02, /**< ADC config for Channel 0 */
brunnobbco 0:fe6c4edd0ecc 167 PARAM_ADCSENS0 = 0x03, /**< ADC sensitivity setting for Channel 0 */
brunnobbco 0:fe6c4edd0ecc 168 PARAM_ADCPOST0 = 0x04, /**< ADC resolution, shift and threshold settings for Channel 0 */
brunnobbco 0:fe6c4edd0ecc 169 PARAM_MEASCONFIG0 = 0x05, /**< ADC measurement counter selection for Channel 0 */
brunnobbco 0:fe6c4edd0ecc 170 PARAM_ADCCONFIG1 = 0x06, /**< ADC config for Channel 1 */
brunnobbco 0:fe6c4edd0ecc 171 PARAM_ADCSENS1 = 0x07, /**< ADC sensitivity setting for Channel 1 */
brunnobbco 0:fe6c4edd0ecc 172 PARAM_ADCPOST1 = 0x08, /**< ADC resolution, shift and threshold settings for Channel 1 */
brunnobbco 0:fe6c4edd0ecc 173 PARAM_MEASCONFIG1 = 0x09, /**< ADC measurement counter selection for Channel 1 */
brunnobbco 0:fe6c4edd0ecc 174 PARAM_ADCCONFIG2 = 0x0A, /**< ADC config for Channel 2 */
brunnobbco 0:fe6c4edd0ecc 175 PARAM_ADCSENS2 = 0x0B, /**< ADC sensitivity setting for Channel 2 */
brunnobbco 0:fe6c4edd0ecc 176 PARAM_ADCPOST2 = 0x0C, /**< ADC resolution, shift and threshold settings for Channel 2 */
brunnobbco 0:fe6c4edd0ecc 177 PARAM_MEASCONFIG2 = 0x0D, /**< ADC measurement counter selection for Channel 2 */
brunnobbco 0:fe6c4edd0ecc 178 PARAM_ADCCONFIG3 = 0x0E, /**< ADC config for Channel 3 */
brunnobbco 0:fe6c4edd0ecc 179 PARAM_ADCSENS3 = 0x0F, /**< ADC sensitivity setting for Channel 3 */
brunnobbco 0:fe6c4edd0ecc 180 PARAM_ADCPOST3 = 0x10, /**< ADC resolution, shift and threshold settings for Channel 3 */
brunnobbco 0:fe6c4edd0ecc 181 PARAM_MEASCONFIG3 = 0x11, /**< ADC measurement counter selection for Channel 3 */
brunnobbco 0:fe6c4edd0ecc 182 PARAM_ADCCONFIG4 = 0x12, /**< ADC config for Channel 4 */
brunnobbco 0:fe6c4edd0ecc 183 PARAM_ADCSENS4 = 0x13, /**< ADC sensitivity setting for Channel 4 */
brunnobbco 0:fe6c4edd0ecc 184 PARAM_ADCPOST4 = 0x14, /**< ADC resolution, shift and threshold settings for Channel 4 */
brunnobbco 0:fe6c4edd0ecc 185 PARAM_MEASCONFIG4 = 0x15, /**< ADC measurement counter selection for Channel 4 */
brunnobbco 0:fe6c4edd0ecc 186 PARAM_ADCCONFIG5 = 0x16, /**< ADC config for Channel 5 */
brunnobbco 0:fe6c4edd0ecc 187 PARAM_ADCSENS5 = 0x17, /**< ADC sensitivity setting for Channel 5 */
brunnobbco 0:fe6c4edd0ecc 188 PARAM_ADCPOST5 = 0x18, /**< ADC resolution, shift and threshold settings for Channel 5 */
brunnobbco 0:fe6c4edd0ecc 189 PARAM_MEASCONFIG5 = 0x19, /**< ADC measurement counter selection for Channel 5 */
brunnobbco 0:fe6c4edd0ecc 190 PARAM_MEASRATE_H = 0x1A, /**< Main measurement rate counter MSB */
brunnobbco 0:fe6c4edd0ecc 191 PARAM_MEASRATE_L = 0x1B, /**< Main measurement rate counter LSB */
brunnobbco 0:fe6c4edd0ecc 192 PARAM_MEASCOUNT0 = 0x1C, /**< Measurement rate extension counter 0 */
brunnobbco 0:fe6c4edd0ecc 193 PARAM_MEASCOUNT1 = 0x1D, /**< Measurement rate extension counter 1 */
brunnobbco 0:fe6c4edd0ecc 194 PARAM_MEASCOUNT2 = 0x1E, /**< Measurement rate extension counter 2 */
brunnobbco 0:fe6c4edd0ecc 195 PARAM_THRESHOLD0_H = 0x25, /**< Threshold level 0 MSB */
brunnobbco 0:fe6c4edd0ecc 196 PARAM_THRESHOLD0_L = 0x26, /**< Threshold level 0 LSB */
brunnobbco 0:fe6c4edd0ecc 197 PARAM_THRESHOLD1_H = 0x27, /**< Threshold level 1 MSB */
brunnobbco 0:fe6c4edd0ecc 198 PARAM_THRESHOLD1_L = 0x28, /**< Threshold level 1 LSB */
brunnobbco 0:fe6c4edd0ecc 199 PARAM_THRESHOLD2_H = 0x29, /**< Threshold level 2 MSB */
brunnobbco 0:fe6c4edd0ecc 200 PARAM_THRESHOLD2_L = 0x2A, /**< Threshold level 2 LSB */
brunnobbco 0:fe6c4edd0ecc 201 PARAM_BURST = 0x2B, /**< Burst enable and burst count */
brunnobbco 0:fe6c4edd0ecc 202 };
brunnobbco 0:fe6c4edd0ecc 203 /**@}*/
brunnobbco 0:fe6c4edd0ecc 204
brunnobbco 0:fe6c4edd0ecc 205 /**
brunnobbco 0:fe6c4edd0ecc 206 * @name Commands
brunnobbco 0:fe6c4edd0ecc 207 * @{
brunnobbco 0:fe6c4edd0ecc 208 */
brunnobbco 0:fe6c4edd0ecc 209 enum Command {
brunnobbco 0:fe6c4edd0ecc 210 CMD_RESET_CMD_CTR = 0x00, /**< Resets the command counter */
brunnobbco 0:fe6c4edd0ecc 211 CMD_RESET = 0x01, /**< Forces a Reset */
brunnobbco 0:fe6c4edd0ecc 212 CMD_NEW_ADDR = 0x02, /**< Stores the new I2C address */
brunnobbco 0:fe6c4edd0ecc 213 CMD_FORCE_CH = 0x11, /**< Initiates a set of measurements specified in CHAN_LIST parameter */
brunnobbco 0:fe6c4edd0ecc 214 CMD_PAUSE_CH = 0x12, /**< Pauses autonomous measurements */
brunnobbco 0:fe6c4edd0ecc 215 CMD_START = 0x13, /**< Starts autonomous measurements */
brunnobbco 0:fe6c4edd0ecc 216 CMD_PARAM_SET = 0x80, /**< Sets a parameter */
brunnobbco 0:fe6c4edd0ecc 217 CMD_PARAM_QUERY = 0x40, /**< Reads a parameter */
brunnobbco 0:fe6c4edd0ecc 218 };
brunnobbco 0:fe6c4edd0ecc 219 /**@}*/
brunnobbco 0:fe6c4edd0ecc 220
brunnobbco 0:fe6c4edd0ecc 221 /**
brunnobbco 0:fe6c4edd0ecc 222 * @name Responses
brunnobbco 0:fe6c4edd0ecc 223 * @{
brunnobbco 0:fe6c4edd0ecc 224 */
brunnobbco 0:fe6c4edd0ecc 225 enum Response {
brunnobbco 0:fe6c4edd0ecc 226 RSP0_CHIPSTAT_MASK = 0xE0, /**< Chip state mask in Response0 register */
brunnobbco 0:fe6c4edd0ecc 227 RSP0_COUNTER_MASK = 0x1F, /**< Command counter and error indicator mask in Response0 register */
brunnobbco 0:fe6c4edd0ecc 228 RSP0_SLEEP = 0x20, /**< Sleep state indicator bit mask in Response0 register */
brunnobbco 0:fe6c4edd0ecc 229 };
brunnobbco 0:fe6c4edd0ecc 230 /**@}*/
brunnobbco 0:fe6c4edd0ecc 231
brunnobbco 0:fe6c4edd0ecc 232 /**
brunnobbco 0:fe6c4edd0ecc 233 * @brief
brunnobbco 0:fe6c4edd0ecc 234 * Structure to store the data measured by the Si1133
brunnobbco 0:fe6c4edd0ecc 235 */
brunnobbco 0:fe6c4edd0ecc 236 typedef struct {
brunnobbco 0:fe6c4edd0ecc 237 uint8_t irq_status; /**< Interrupt status of the device */
brunnobbco 0:fe6c4edd0ecc 238 int32_t ch0; /**< Channel 0 measurement data */
brunnobbco 0:fe6c4edd0ecc 239 int32_t ch1; /**< Channel 1 measurement data */
brunnobbco 0:fe6c4edd0ecc 240 int32_t ch2; /**< Channel 2 measurement data */
brunnobbco 0:fe6c4edd0ecc 241 int32_t ch3; /**< Channel 3 measurement data */
brunnobbco 0:fe6c4edd0ecc 242 } Samples_t;
brunnobbco 0:fe6c4edd0ecc 243
brunnobbco 0:fe6c4edd0ecc 244 /**
brunnobbco 0:fe6c4edd0ecc 245 * @brief
brunnobbco 0:fe6c4edd0ecc 246 * Structure to store the calculation coefficients
brunnobbco 0:fe6c4edd0ecc 247 */
brunnobbco 0:fe6c4edd0ecc 248 typedef struct {
brunnobbco 0:fe6c4edd0ecc 249 int16_t info; /**< Info */
brunnobbco 0:fe6c4edd0ecc 250 uint16_t mag; /**< Magnitude */
brunnobbco 0:fe6c4edd0ecc 251 } Coeff_t;
brunnobbco 0:fe6c4edd0ecc 252
brunnobbco 0:fe6c4edd0ecc 253 /**
brunnobbco 0:fe6c4edd0ecc 254 * @brief
brunnobbco 0:fe6c4edd0ecc 255 * Structure to store the coefficients used for Lux calculation
brunnobbco 0:fe6c4edd0ecc 256 */
brunnobbco 0:fe6c4edd0ecc 257 typedef struct {
brunnobbco 0:fe6c4edd0ecc 258 Coeff_t coeff_high[4]; /**< High amplitude coeffs */
brunnobbco 0:fe6c4edd0ecc 259 Coeff_t coeff_low[9]; /**< Low amplitude coeffs */
brunnobbco 0:fe6c4edd0ecc 260 } LuxCoeff_t;
brunnobbco 0:fe6c4edd0ecc 261
brunnobbco 0:fe6c4edd0ecc 262 /* Forward-declare constant coefficient table */
brunnobbco 0:fe6c4edd0ecc 263 static const LuxCoeff_t lk;
brunnobbco 0:fe6c4edd0ecc 264 static const Coeff_t uk[];
brunnobbco 0:fe6c4edd0ecc 265
brunnobbco 0:fe6c4edd0ecc 266 /* Private functions */
brunnobbco 0:fe6c4edd0ecc 267 uint32_t read_register(enum Register reg, uint8_t *data);
brunnobbco 0:fe6c4edd0ecc 268 uint32_t write_register(enum Register reg, uint8_t data);
brunnobbco 0:fe6c4edd0ecc 269 uint32_t write_register_block(enum Register reg, uint8_t length, uint8_t *data);
brunnobbco 0:fe6c4edd0ecc 270 uint32_t read_register_block(enum Register reg, uint8_t length, uint8_t *data);
brunnobbco 0:fe6c4edd0ecc 271 uint32_t get_irq_status(uint8_t *irq_status);
brunnobbco 0:fe6c4edd0ecc 272 uint32_t wait_until_sleep(void);
brunnobbco 0:fe6c4edd0ecc 273 uint32_t reset(void);
brunnobbco 0:fe6c4edd0ecc 274 uint32_t reset_cmd_counter (void);
brunnobbco 0:fe6c4edd0ecc 275 uint32_t send_cmd(enum Command command);
brunnobbco 0:fe6c4edd0ecc 276 uint32_t force_measurement (void);
brunnobbco 0:fe6c4edd0ecc 277 uint32_t pause_measurement (void);
brunnobbco 0:fe6c4edd0ecc 278 uint32_t start_measurement (void);
brunnobbco 0:fe6c4edd0ecc 279 uint32_t set_parameter (enum Parameter address, uint8_t value);
brunnobbco 0:fe6c4edd0ecc 280 uint32_t read_parameter (enum Parameter address);
brunnobbco 0:fe6c4edd0ecc 281 uint32_t init (void);
brunnobbco 0:fe6c4edd0ecc 282 uint32_t deinit (void);
brunnobbco 0:fe6c4edd0ecc 283 uint32_t measure (Samples_t *samples);
brunnobbco 0:fe6c4edd0ecc 284 int32_t get_uv (int32_t uv);
brunnobbco 0:fe6c4edd0ecc 285 int32_t get_lux (int32_t vis_high, int32_t vis_low, int32_t ir);
brunnobbco 0:fe6c4edd0ecc 286 uint32_t measure_lux_uv (float *lux, float *uvi);
brunnobbco 0:fe6c4edd0ecc 287 uint32_t get_measurement (float *lux, float *uvi);
brunnobbco 0:fe6c4edd0ecc 288 uint32_t get_hardware_id (uint8_t *hardware_id);
brunnobbco 0:fe6c4edd0ecc 289
brunnobbco 0:fe6c4edd0ecc 290 int32_t calculate_polynomial_helper (int32_t input, int8_t fraction, uint16_t mag, int8_t shift);
brunnobbco 0:fe6c4edd0ecc 291 int32_t calculate_polynomial (int32_t x, int32_t y, uint8_t input_fraction, uint8_t output_fraction, uint8_t num_coeff, const Coeff_t *kp);
brunnobbco 0:fe6c4edd0ecc 292
brunnobbco 0:fe6c4edd0ecc 293 /* Member variables */
brunnobbco 0:fe6c4edd0ecc 294 I2C m_I2C;
brunnobbco 0:fe6c4edd0ecc 295 };
brunnobbco 0:fe6c4edd0ecc 296
brunnobbco 0:fe6c4edd0ecc 297 #endif