Now you can use NC as InterruptIn

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Committer:
licio.mapelli@st.com
Date:
Tue Sep 29 14:50:15 2015 +0200
Revision:
8:f943a1fca15f
Parent:
4:a5abf7757947
Child:
10:4954b09b72d8
fixed i2c functions and code cleanup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gallonm 1:1de1ea2994d9 1 /*******************************************************************************
gallonm 1:1de1ea2994d9 2 Copyright © 2014, STMicroelectronics International N.V.
gallonm 1:1de1ea2994d9 3 All rights reserved.
gallonm 1:1de1ea2994d9 4
gallonm 1:1de1ea2994d9 5 Redistribution and use in source and binary forms, with or without
gallonm 1:1de1ea2994d9 6 modification, are permitted provided that the following conditions are met:
gallonm 1:1de1ea2994d9 7 * Redistributions of source code must retain the above copyright
gallonm 1:1de1ea2994d9 8 notice, this list of conditions and the following disclaimer.
gallonm 1:1de1ea2994d9 9 * Redistributions in binary form must reproduce the above copyright
gallonm 1:1de1ea2994d9 10 notice, this list of conditions and the following disclaimer in the
gallonm 1:1de1ea2994d9 11 documentation and/or other materials provided with the distribution.
gallonm 1:1de1ea2994d9 12 * Neither the name of STMicroelectronics nor the
gallonm 1:1de1ea2994d9 13 names of its contributors may be used to endorse or promote products
gallonm 1:1de1ea2994d9 14 derived from this software without specific prior written permission.
gallonm 1:1de1ea2994d9 15
gallonm 1:1de1ea2994d9 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
gallonm 1:1de1ea2994d9 17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
gallonm 1:1de1ea2994d9 18 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
gallonm 1:1de1ea2994d9 19 NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
gallonm 1:1de1ea2994d9 20 IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
gallonm 1:1de1ea2994d9 21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
gallonm 1:1de1ea2994d9 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
gallonm 1:1de1ea2994d9 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
gallonm 1:1de1ea2994d9 24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
gallonm 1:1de1ea2994d9 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
gallonm 1:1de1ea2994d9 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
gallonm 1:1de1ea2994d9 27 ********************************************************************************/
gallonm 1:1de1ea2994d9 28
gallonm 1:1de1ea2994d9 29 /*
gallonm 1:1de1ea2994d9 30 * $Date: 2015-05-13 14:12:05 +0200 (Wed, 13 May 2015) $
gallonm 1:1de1ea2994d9 31 * $Revision: 2290 $
gallonm 1:1de1ea2994d9 32 */
gallonm 1:1de1ea2994d9 33
gallonm 1:1de1ea2994d9 34 /**
gallonm 1:1de1ea2994d9 35 * @file VL6180x_def.h
gallonm 1:1de1ea2994d9 36 *
gallonm 1:1de1ea2994d9 37 * @brief Type definitions for vl6180x api.
gallonm 1:1de1ea2994d9 38 *
gallonm 1:1de1ea2994d9 39 */
gallonm 1:1de1ea2994d9 40
gallonm 1:1de1ea2994d9 41
gallonm 1:1de1ea2994d9 42 #ifndef _VL6180x_DEF
gallonm 1:1de1ea2994d9 43 #define _VL6180x_DEF
gallonm 1:1de1ea2994d9 44
gallonm 1:1de1ea2994d9 45 /** API major version */
gallonm 1:1de1ea2994d9 46 #define VL6180x_API_REV_MAJOR 3
gallonm 1:1de1ea2994d9 47 /** API minor version */
gallonm 1:1de1ea2994d9 48 #define VL6180x_API_REV_MINOR 0
gallonm 1:1de1ea2994d9 49 /** API sub version */
gallonm 1:1de1ea2994d9 50 #define VL6180x_API_REV_SUB 1
gallonm 1:1de1ea2994d9 51
gallonm 1:1de1ea2994d9 52 #define VL6180X_STR_HELPER(x) #x
gallonm 1:1de1ea2994d9 53 #define VL6180X_STR(x) VL6180X_STR_HELPER(x)
gallonm 1:1de1ea2994d9 54
gallonm 1:1de1ea2994d9 55 #include "vl6180x_cfg.h"
gallonm 1:1de1ea2994d9 56 #include "vl6180x_types.h"
gallonm 1:1de1ea2994d9 57
gallonm 1:1de1ea2994d9 58 /*
gallonm 1:1de1ea2994d9 59 * check configuration macro raise error or warning and suggest a default value
gallonm 1:1de1ea2994d9 60 */
gallonm 1:1de1ea2994d9 61
gallonm 1:1de1ea2994d9 62 #ifndef VL6180x_UPSCALE_SUPPORT
gallonm 1:1de1ea2994d9 63 #error "VL6180x_UPSCALE_SUPPORT not defined"
gallonm 1:1de1ea2994d9 64 /* TODO you must define value for upscale support in your vl6180x_cfg.h */
gallonm 1:1de1ea2994d9 65 #endif
gallonm 1:1de1ea2994d9 66
gallonm 1:1de1ea2994d9 67 #ifndef VL6180x_ALS_SUPPORT
gallonm 1:1de1ea2994d9 68 #error "VL6180x_ALS_SUPPORT not defined"
gallonm 1:1de1ea2994d9 69 /* TODO you must define VL6180x_ALS_SUPPORT with a value in your vl6180x_cfg.h set to 0 do disable*/
gallonm 1:1de1ea2994d9 70 #endif
gallonm 1:1de1ea2994d9 71
gallonm 1:1de1ea2994d9 72 #ifndef VL6180x_HAVE_DMAX_RANGING
gallonm 1:1de1ea2994d9 73 #error "VL6180x_HAVE_DMAX_RANGING not defined"
gallonm 1:1de1ea2994d9 74 /* TODO you may remove or comment these #error and keep the default below or update your vl6180x_cfg.h .h file */
gallonm 1:1de1ea2994d9 75 /**
gallonm 1:1de1ea2994d9 76 * force VL6180x_HAVE_DMAX_RANGING to not supported when not part of cfg file
gallonm 1:1de1ea2994d9 77 */
gallonm 1:1de1ea2994d9 78 #define VL6180x_HAVE_DMAX_RANGING 0
gallonm 1:1de1ea2994d9 79 #endif
gallonm 1:1de1ea2994d9 80
gallonm 1:1de1ea2994d9 81 #ifndef VL6180x_EXTENDED_RANGE
gallonm 1:1de1ea2994d9 82 #define VL6180x_EXTENDED_RANGE 0
gallonm 1:1de1ea2994d9 83 #endif
gallonm 1:1de1ea2994d9 84
gallonm 1:1de1ea2994d9 85 #ifndef VL6180x_WRAP_AROUND_FILTER_SUPPORT
gallonm 1:1de1ea2994d9 86 #error "VL6180x_WRAP_AROUND_FILTER_SUPPORT not defined ?"
gallonm 1:1de1ea2994d9 87 /* TODO you may remove or comment these #error and keep the default below or update vl6180x_cfg.h file */
gallonm 1:1de1ea2994d9 88 /**
gallonm 1:1de1ea2994d9 89 * force VL6180x_WRAP_AROUND_FILTER_SUPPORT to not supported when not part of cfg file
gallonm 1:1de1ea2994d9 90 */
gallonm 1:1de1ea2994d9 91 #define VL6180x_WRAP_AROUND_FILTER_SUPPORT 0
gallonm 1:1de1ea2994d9 92 #endif
gallonm 1:1de1ea2994d9 93
gallonm 1:1de1ea2994d9 94
gallonm 1:1de1ea2994d9 95
gallonm 1:1de1ea2994d9 96
gallonm 1:1de1ea2994d9 97 /****************************************
gallonm 1:1de1ea2994d9 98 * PRIVATE define do not edit
gallonm 1:1de1ea2994d9 99 ****************************************/
gallonm 1:1de1ea2994d9 100
gallonm 1:1de1ea2994d9 101 /** Maximal buffer size ever use in i2c */
gallonm 1:1de1ea2994d9 102 #define VL6180x_MAX_I2C_XFER_SIZE 8 /* At present time it 6 byte max but that can change */
gallonm 1:1de1ea2994d9 103
gallonm 1:1de1ea2994d9 104 #if VL6180x_UPSCALE_SUPPORT < 0
gallonm 1:1de1ea2994d9 105 /**
gallonm 1:1de1ea2994d9 106 * @def VL6180x_HAVE_UPSCALE_DATA
gallonm 1:1de1ea2994d9 107 * @brief is defined if device data structure has data so when user configurable up-scale is active
gallonm 1:1de1ea2994d9 108 */
gallonm 1:1de1ea2994d9 109 #define VL6180x_HAVE_UPSCALE_DATA /* have data only for user configurable up-scale config */
gallonm 1:1de1ea2994d9 110 #endif
gallonm 1:1de1ea2994d9 111
gallonm 1:1de1ea2994d9 112 #if VL6180x_WRAP_AROUND_FILTER_SUPPORT
gallonm 1:1de1ea2994d9 113 /**
gallonm 1:1de1ea2994d9 114 * @def VL6180x_HAVE_WRAP_AROUND_DATA
gallonm 1:1de1ea2994d9 115 * @brief is defined if device data structure has filter data so when active in cfg file
gallonm 1:1de1ea2994d9 116 */
gallonm 1:1de1ea2994d9 117 #define VL6180x_HAVE_WRAP_AROUND_DATA
gallonm 1:1de1ea2994d9 118 #endif
gallonm 1:1de1ea2994d9 119
gallonm 1:1de1ea2994d9 120 #if VL6180x_ALS_SUPPORT != 0
gallonm 1:1de1ea2994d9 121 /**
gallonm 1:1de1ea2994d9 122 * @def VL6180x_HAVE_ALS_DATA
gallonm 1:1de1ea2994d9 123 * @brief is defined when als data are include in device data structure so when als suport if configured
gallonm 1:1de1ea2994d9 124 */
gallonm 1:1de1ea2994d9 125 #define VL6180x_HAVE_ALS_DATA
gallonm 1:1de1ea2994d9 126 #endif
gallonm 1:1de1ea2994d9 127
gallonm 1:1de1ea2994d9 128
gallonm 1:1de1ea2994d9 129 #if VL6180x_WRAP_AROUND_FILTER_SUPPORT || VL6180x_HAVE_DMAX_RANGING
gallonm 1:1de1ea2994d9 130 #define VL6180x_HAVE_RATE_DATA
gallonm 1:1de1ea2994d9 131 #endif
gallonm 1:1de1ea2994d9 132
gallonm 1:1de1ea2994d9 133 /** Error and warning code returned by API
gallonm 1:1de1ea2994d9 134 *
gallonm 1:1de1ea2994d9 135 * negative value are true error mostly fatal\n
gallonm 1:1de1ea2994d9 136 * positive value are warning most of time it's ok to continue\n
gallonm 1:1de1ea2994d9 137 */
gallonm 1:1de1ea2994d9 138 enum VL6180x_ErrCode_t{
gallonm 1:1de1ea2994d9 139 API_NO_ERROR = 0,
gallonm 1:1de1ea2994d9 140 CALIBRATION_WARNING = 1, /*!< warning invalid calibration data may be in used \a VL6180x_InitData() \a VL6180x_GetOffsetCalibrationData \a VL6180x_SetOffsetCalibrationData*/
gallonm 1:1de1ea2994d9 141 MIN_CLIPED = 2, /*!< warning parameter passed was clipped to min before to be applied */
gallonm 1:1de1ea2994d9 142 NOT_GUARANTEED = 3, /*!< Correct operation is not guaranteed typically using extended ranging on vl6180x */
gallonm 1:1de1ea2994d9 143 NOT_READY = 4, /*!< the data is not ready retry */
gallonm 1:1de1ea2994d9 144
gallonm 1:1de1ea2994d9 145 API_ERROR = -1, /*!< Unqualified error */
gallonm 1:1de1ea2994d9 146 INVALID_PARAMS = -2, /*!< parameter passed is invalid or out of range */
gallonm 1:1de1ea2994d9 147 NOT_SUPPORTED = -3, /*!< function is not supported in current mode or configuration */
gallonm 1:1de1ea2994d9 148 RANGE_ERROR = -4, /*!< device report a ranging error interrupt status */
gallonm 1:1de1ea2994d9 149 TIME_OUT = -5, /*!< aborted due to time out */
gallonm 1:1de1ea2994d9 150 };
gallonm 1:1de1ea2994d9 151
gallonm 1:1de1ea2994d9 152 /**
gallonm 1:1de1ea2994d9 153 * Filtered result data structure range data is to be used
gallonm 1:1de1ea2994d9 154 */
gallonm 1:1de1ea2994d9 155 typedef struct RangeFilterResult_tag {
gallonm 1:1de1ea2994d9 156 uint16_t range_mm; /*!< Filtered ranging value */
gallonm 1:1de1ea2994d9 157 uint16_t rawRange_mm; /*!< raw range value (scaled) */
gallonm 1:1de1ea2994d9 158 } RangeFilterResult_t;
gallonm 1:1de1ea2994d9 159
gallonm 1:1de1ea2994d9 160 /**
gallonm 1:1de1ea2994d9 161 * "small" unsigned data type used in filter
gallonm 1:1de1ea2994d9 162 *
gallonm 1:1de1ea2994d9 163 * if data space saving is not a concern it can be change to platform native unsigned int
gallonm 1:1de1ea2994d9 164 */
gallonm 1:1de1ea2994d9 165 typedef uint8_t FilterType1_t;
gallonm 1:1de1ea2994d9 166
gallonm 1:1de1ea2994d9 167 /**
gallonm 1:1de1ea2994d9 168 * @def FILTER_NBOF_SAMPLES
gallonm 1:1de1ea2994d9 169 * @brief sample history len used for wrap around filtering
gallonm 1:1de1ea2994d9 170 */
gallonm 1:1de1ea2994d9 171 #define FILTER_NBOF_SAMPLES 10
gallonm 1:1de1ea2994d9 172 /**
gallonm 1:1de1ea2994d9 173 * Wrap around filter internal data
gallonm 1:1de1ea2994d9 174 */
gallonm 1:1de1ea2994d9 175 struct FilterData_t {
gallonm 1:1de1ea2994d9 176 uint32_t MeasurementIndex; /*!< current measurement index */
gallonm 1:1de1ea2994d9 177 uint16_t LastTrueRange[FILTER_NBOF_SAMPLES]; /*!< filtered/corrected distance history */
gallonm 1:1de1ea2994d9 178 uint32_t LastReturnRates[FILTER_NBOF_SAMPLES]; /*!< Return rate history */
gallonm 1:1de1ea2994d9 179 uint16_t StdFilteredReads; /*!< internal use */
gallonm 1:1de1ea2994d9 180 FilterType1_t Default_ZeroVal; /*!< internal use */
gallonm 1:1de1ea2994d9 181 FilterType1_t Default_VAVGVal; /*!< internal use */
gallonm 1:1de1ea2994d9 182 FilterType1_t NoDelay_ZeroVal; /*!< internal use */
gallonm 1:1de1ea2994d9 183 FilterType1_t NoDelay_VAVGVal; /*!< internal use */
gallonm 1:1de1ea2994d9 184 FilterType1_t Previous_VAVGDiff; /*!< internal use */
gallonm 1:1de1ea2994d9 185 };
gallonm 1:1de1ea2994d9 186
gallonm 1:1de1ea2994d9 187 #if VL6180x_HAVE_DMAX_RANGING
gallonm 1:1de1ea2994d9 188 typedef int32_t DMaxFix_t;
gallonm 1:1de1ea2994d9 189 struct DMaxData_t {
gallonm 1:1de1ea2994d9 190 uint32_t ambTuningWindowFactor_K; /*!< internal algo tuning (*1000) */
gallonm 1:1de1ea2994d9 191
gallonm 1:1de1ea2994d9 192 DMaxFix_t retSignalAt400mm; /*!< intermediate dmax computation value caching @a #SYSRANGE_CROSSTALK_COMPENSATION_RATE and private reg 0x02A */
gallonm 1:1de1ea2994d9 193 //int32_t RegB8; /*!< register 0xB8 cached to speed reduce i2c traffic for dmax computation */
gallonm 1:1de1ea2994d9 194 /* place all word data below to optimize struct packing */
gallonm 1:1de1ea2994d9 195 //int32_t minSignalNeeded; /*!< optimized computation intermediate base on register cached value */
gallonm 1:1de1ea2994d9 196 int32_t snrLimit_K; /*!< cached and optimized computation intermediate from @a #SYSRANGE_MAX_AMBIENT_LEVEL_MULT */
gallonm 1:1de1ea2994d9 197 uint16_t ClipSnrLimit; /*!< Max value for snr limit */
gallonm 1:1de1ea2994d9 198 /* place all byte data below to optimize packing */
gallonm 1:1de1ea2994d9 199 //uint8_t MaxConvTime; /*!< cached max convergence time @a #SYSRANGE_MAX_CONVERGENCE_TIME*/
gallonm 1:1de1ea2994d9 200 };
gallonm 1:1de1ea2994d9 201 #endif
gallonm 1:1de1ea2994d9 202
gallonm 1:1de1ea2994d9 203 /**
gallonm 1:1de1ea2994d9 204 * @struct VL6180xDevData_t
gallonm 1:1de1ea2994d9 205 *
gallonm 1:1de1ea2994d9 206 * @brief Per VL6180x device St private data structure \n
gallonm 1:1de1ea2994d9 207 * End user should never access any of these field directly
gallonm 1:1de1ea2994d9 208 *
gallonm 1:1de1ea2994d9 209 * These must never access directly but only via VL6180xDev/SetData(dev, field) macro
gallonm 1:1de1ea2994d9 210 */
gallonm 1:1de1ea2994d9 211 struct VL6180xDevData_t {
gallonm 1:1de1ea2994d9 212
gallonm 1:1de1ea2994d9 213 uint32_t Part2PartAmbNVM; /*!< backed up NVM value */
gallonm 1:1de1ea2994d9 214 uint32_t XTalkCompRate_KCps; /*! Cached XTlak Compensation Rate */
gallonm 1:1de1ea2994d9 215
gallonm 1:1de1ea2994d9 216 uint16_t EceFactorM; /*!< Ece Factor M numerator */
gallonm 1:1de1ea2994d9 217 uint16_t EceFactorD; /*!< Ece Factor D denominator*/
gallonm 1:1de1ea2994d9 218
gallonm 1:1de1ea2994d9 219 #ifdef VL6180x_HAVE_ALS_DATA
gallonm 1:1de1ea2994d9 220 uint16_t IntegrationPeriod; /*!< cached als Integration period avoid slow read from device at each measure */
gallonm 1:1de1ea2994d9 221 uint16_t AlsGainCode; /*!< cached Als gain avoid slow read from device at each measure */
gallonm 1:1de1ea2994d9 222 uint16_t AlsScaler; /*!< cached Als scaler avoid slow read from device at each measure */
gallonm 1:1de1ea2994d9 223 #endif
gallonm 1:1de1ea2994d9 224
gallonm 1:1de1ea2994d9 225 #ifdef VL6180x_HAVE_UPSCALE_DATA
gallonm 1:1de1ea2994d9 226 uint8_t UpscaleFactor; /*!< up-scaling factor*/
gallonm 1:1de1ea2994d9 227 #endif
gallonm 1:1de1ea2994d9 228
gallonm 1:1de1ea2994d9 229 #ifdef VL6180x_HAVE_WRAP_AROUND_DATA
gallonm 1:1de1ea2994d9 230 uint8_t WrapAroundFilterActive; /*!< Filter on/off */
gallonm 1:1de1ea2994d9 231 struct FilterData_t FilterData; /*!< Filter internal data state history ... */
gallonm 1:1de1ea2994d9 232 #endif
gallonm 1:1de1ea2994d9 233
gallonm 1:1de1ea2994d9 234 #if VL6180x_HAVE_DMAX_RANGING
gallonm 1:1de1ea2994d9 235 struct DMaxData_t DMaxData;
gallonm 1:1de1ea2994d9 236 uint8_t DMaxEnable;
gallonm 1:1de1ea2994d9 237 #endif
gallonm 1:1de1ea2994d9 238 int8_t Part2PartOffsetNVM; /*!< backed up NVM value */
gallonm 1:1de1ea2994d9 239 };
gallonm 1:1de1ea2994d9 240
gallonm 1:1de1ea2994d9 241
gallonm 1:1de1ea2994d9 242 /**
gallonm 1:1de1ea2994d9 243 * @struct VL6180x_RangeData_t
gallonm 1:1de1ea2994d9 244 * @brief Range and any optional measurement data.
gallonm 1:1de1ea2994d9 245 */
gallonm 1:1de1ea2994d9 246 typedef struct {
gallonm 1:1de1ea2994d9 247 int32_t range_mm; /*!< range distance in mm. */
gallonm 1:1de1ea2994d9 248 int32_t signalRate_mcps; /*!< signal rate (MCPS)\n these is a 9.7 fix point value, which is effectively a measure of target reflectance.*/
gallonm 1:1de1ea2994d9 249 uint32_t errorStatus; /*!< Error status of the current measurement. \n
gallonm 1:1de1ea2994d9 250 see @a ::RangeError_u @a VL6180x_GetRangeStatusErrString() */
gallonm 1:1de1ea2994d9 251
gallonm 1:1de1ea2994d9 252
gallonm 1:1de1ea2994d9 253 #ifdef VL6180x_HAVE_RATE_DATA
gallonm 1:1de1ea2994d9 254 uint32_t rtnAmbRate; /*!< Return Ambient rate in KCount per sec related to \a RESULT_RANGE_RETURN_AMB_COUNT */
gallonm 1:1de1ea2994d9 255 uint32_t rtnRate; /*!< Return rate in KCount per sec related to \a RESULT_RANGE_RETURN_SIGNAL_COUNT */
gallonm 1:1de1ea2994d9 256 uint32_t rtnConvTime; /*!< Return Convergence time \a RESULT_RANGE_RETURN_CONV_TIME */
gallonm 1:1de1ea2994d9 257 uint32_t refConvTime; /*!< Reference convergence time \a RESULT_RANGE_REFERENCE_CONV_TIME */
gallonm 1:1de1ea2994d9 258 #endif
gallonm 1:1de1ea2994d9 259
gallonm 1:1de1ea2994d9 260
gallonm 1:1de1ea2994d9 261 #if VL6180x_HAVE_DMAX_RANGING
gallonm 1:1de1ea2994d9 262 uint32_t DMax; /*!< DMax when applicable */
gallonm 1:1de1ea2994d9 263 #endif
gallonm 1:1de1ea2994d9 264
gallonm 1:1de1ea2994d9 265 #ifdef VL6180x_HAVE_WRAP_AROUND_DATA
gallonm 1:1de1ea2994d9 266 RangeFilterResult_t FilteredData; /*!< Filter result main range_mm is updated */
gallonm 1:1de1ea2994d9 267 #endif
gallonm 1:1de1ea2994d9 268 }VL6180x_RangeData_t;
gallonm 1:1de1ea2994d9 269
gallonm 1:1de1ea2994d9 270
gallonm 1:1de1ea2994d9 271 /** use where fix point 9.7 bit values are expected
gallonm 1:1de1ea2994d9 272 *
gallonm 1:1de1ea2994d9 273 * given a floating point value f it's .7 bit point is (int)(f*(1<<7))*/
gallonm 1:1de1ea2994d9 274 typedef uint16_t FixPoint97_t;
gallonm 1:1de1ea2994d9 275
gallonm 1:1de1ea2994d9 276 /** lux data type */
gallonm 1:1de1ea2994d9 277 typedef uint32_t lux_t;
gallonm 1:1de1ea2994d9 278
gallonm 1:1de1ea2994d9 279 /**
gallonm 1:1de1ea2994d9 280 * @brief This data type defines als measurement data.
gallonm 1:1de1ea2994d9 281 */
gallonm 1:1de1ea2994d9 282 typedef struct VL6180x_AlsData_st{
gallonm 1:1de1ea2994d9 283 lux_t lux; /**< Light measurement (Lux) */
gallonm 1:1de1ea2994d9 284 uint32_t errorStatus; /**< Error status of the current measurement. \n
gallonm 1:1de1ea2994d9 285 * No Error := 0. \n
gallonm 1:1de1ea2994d9 286 * Refer to product sheets for other error codes. */
gallonm 1:1de1ea2994d9 287 }VL6180x_AlsData_t;
gallonm 1:1de1ea2994d9 288
gallonm 1:1de1ea2994d9 289 /**
gallonm 1:1de1ea2994d9 290 * @brief Range status Error code
gallonm 1:1de1ea2994d9 291 *
gallonm 1:1de1ea2994d9 292 * @a VL6180x_GetRangeStatusErrString() if configured ( @a #VL6180x_RANGE_STATUS_ERRSTRING )
gallonm 1:1de1ea2994d9 293 * related to register @a #RESULT_RANGE_STATUS and additional post processing
gallonm 1:1de1ea2994d9 294 */
gallonm 1:1de1ea2994d9 295 typedef enum {
gallonm 1:1de1ea2994d9 296 NoError_=0, /*!< 0 0b0000 NoError */
gallonm 1:1de1ea2994d9 297 VCSEL_Continuity_Test, /*!< 1 0b0001 VCSEL_Continuity_Test */
gallonm 1:1de1ea2994d9 298 VCSEL_Watchdog_Test, /*!< 2 0b0010 VCSEL_Watchdog_Test */
gallonm 1:1de1ea2994d9 299 VCSEL_Watchdog, /*!< 3 0b0011 VCSEL_Watchdog */
gallonm 1:1de1ea2994d9 300 PLL1_Lock, /*!< 4 0b0100 PLL1_Lock */
gallonm 1:1de1ea2994d9 301 PLL2_Lock, /*!< 5 0b0101 PLL2_Lock */
gallonm 1:1de1ea2994d9 302 Early_Convergence_Estimate,/*!< 6 0b0110 Early_Convergence_Estimate */
gallonm 1:1de1ea2994d9 303 Max_Convergence, /*!< 7 0b0111 Max_Convergence */
gallonm 1:1de1ea2994d9 304 No_Target_Ignore, /*!< 8 0b1000 No_Target_Ignore */
gallonm 1:1de1ea2994d9 305 Not_used_9, /*!< 9 0b1001 Not_used */
gallonm 1:1de1ea2994d9 306 Not_used_10, /*!< 10 0b1010 Not_used_ */
gallonm 1:1de1ea2994d9 307 Max_Signal_To_Noise_Ratio, /*!< 11 0b1011 Max_Signal_To_Noise_Ratio*/
gallonm 1:1de1ea2994d9 308 Raw_Ranging_Algo_Underflow,/*!< 12 0b1100 Raw_Ranging_Algo_Underflow*/
gallonm 1:1de1ea2994d9 309 Raw_Ranging_Algo_Overflow, /*!< 13 0b1101 Raw_Ranging_Algo_Overflow */
gallonm 1:1de1ea2994d9 310 Ranging_Algo_Underflow, /*!< 14 0b1110 Ranging_Algo_Underflow */
gallonm 1:1de1ea2994d9 311 Ranging_Algo_Overflow, /*!< 15 0b1111 Ranging_Algo_Overflow */
gallonm 1:1de1ea2994d9 312
gallonm 1:1de1ea2994d9 313 /* code below are addition for API/software side they are not hardware*/
gallonm 1:1de1ea2994d9 314 RangingFiltered =0x10, /*!< 16 0b10000 filtered by post processing*/
gallonm 1:1de1ea2994d9 315
gallonm 1:1de1ea2994d9 316 } RangeError_u;
gallonm 1:1de1ea2994d9 317
gallonm 1:1de1ea2994d9 318
gallonm 1:1de1ea2994d9 319 /** @defgroup device_regdef Device registers & masks definitions
gallonm 1:1de1ea2994d9 320 * @brief Device registers and masks definitions
gallonm 1:1de1ea2994d9 321 */
gallonm 1:1de1ea2994d9 322
gallonm 1:1de1ea2994d9 323
gallonm 1:1de1ea2994d9 324 /** @ingroup device_regdef
gallonm 1:1de1ea2994d9 325 * @{*/
gallonm 1:1de1ea2994d9 326
gallonm 1:1de1ea2994d9 327 /**
gallonm 1:1de1ea2994d9 328 * The device model ID
gallonm 1:1de1ea2994d9 329 */
gallonm 4:a5abf7757947 330 #define IDENTIFICATION_MODEL_ID (uint16_t) 0x000
gallonm 1:1de1ea2994d9 331 /**
gallonm 1:1de1ea2994d9 332 * Revision identifier of the Device for major change.
gallonm 1:1de1ea2994d9 333 */
gallonm 4:a5abf7757947 334 #define IDENTIFICATION_MODULE_REV_MAJOR (uint16_t) 0x003
gallonm 1:1de1ea2994d9 335 /**
gallonm 1:1de1ea2994d9 336 * Revision identifier of the Device for minor change.
gallonm 1:1de1ea2994d9 337 */
gallonm 4:a5abf7757947 338 #define IDENTIFICATION_MODULE_REV_MINOR (uint16_t) 0x004
gallonm 1:1de1ea2994d9 339
gallonm 1:1de1ea2994d9 340
gallonm 1:1de1ea2994d9 341 /**
gallonm 1:1de1ea2994d9 342 * @def SYSTEM_MODE_GPIO0
gallonm 1:1de1ea2994d9 343 * @brief Configures polarity and select which function gpio 0 serves.
gallonm 1:1de1ea2994d9 344 * Gpio0 is chip enable at power up ! Be aware of all h/w implication of turning it to output.
gallonm 1:1de1ea2994d9 345 * Same definition as #SYSTEM_MODE_GPIO1
gallonm 1:1de1ea2994d9 346 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 347 */
gallonm 4:a5abf7757947 348 #define SYSTEM_MODE_GPIO0 (uint16_t) 0x010
gallonm 1:1de1ea2994d9 349 /**
gallonm 1:1de1ea2994d9 350 * @def SYSTEM_MODE_GPIO1
gallonm 1:1de1ea2994d9 351 * @brief Configures polarity and select what als or ranging functionality gpio pin serves.
gallonm 1:1de1ea2994d9 352 *
gallonm 1:1de1ea2994d9 353 * Function can be #GPIOx_SELECT_OFF #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT.\n
gallonm 1:1de1ea2994d9 354 * Same definition apply to register GPIO0 that is used as chip enable at power up.
gallonm 1:1de1ea2994d9 355 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 356 */
gallonm 4:a5abf7757947 357 #define SYSTEM_MODE_GPIO1 (uint16_t) 0x011
gallonm 1:1de1ea2994d9 358 /** gpio pad POLARITY mask in #SYSTEM_MODE_GPIO1 (and/or 0) write 1 to set active high polarity (positive edge) */
gallonm 1:1de1ea2994d9 359 #define GPIOx_POLARITY_SELECT_MASK 0x20
gallonm 1:1de1ea2994d9 360 /** gpio pad Function select shift in #SYSTEM_MODE_GPIO1 or 0 */
gallonm 1:1de1ea2994d9 361 #define GPIOx_FUNCTIONALITY_SELECT_SHIFT 1
gallonm 1:1de1ea2994d9 362 /** gpio pad Function select mask in #SYSTEM_MODE_GPIO1 or 0 */
gallonm 1:1de1ea2994d9 363 #define GPIOx_FUNCTIONALITY_SELECT_MASK (0xF<<GPIOx_FUNCTIONALITY_SELECT_SHIFT)
gallonm 1:1de1ea2994d9 364 /** select no interrupt in #SYSTEM_MODE_GPIO1 pad is put in Hi-Z*/
gallonm 1:1de1ea2994d9 365 #define GPIOx_SELECT_OFF 0x00
gallonm 1:1de1ea2994d9 366 /** select gpiox as interrupt output in #SYSTEM_MODE_GPIO1 */
gallonm 1:1de1ea2994d9 367 #define GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT 0x08
gallonm 1:1de1ea2994d9 368 /** select range as source for interrupt on in #SYSTEM_MODE_GPIO1 */
gallonm 1:1de1ea2994d9 369 #define GPIOx_MODE_SELECT_RANGING 0x00
gallonm 1:1de1ea2994d9 370 /** select als as source for interrupt on in #SYSTEM_MODE_GPIO1 */
gallonm 1:1de1ea2994d9 371 #define GPIOx_MODE_SELECT_ALS 0x01
gallonm 1:1de1ea2994d9 372
gallonm 1:1de1ea2994d9 373
gallonm 1:1de1ea2994d9 374 /**
gallonm 1:1de1ea2994d9 375 * @def SYSTEM_INTERRUPT_CONFIG_GPIO
gallonm 1:1de1ea2994d9 376 *
gallonm 1:1de1ea2994d9 377 * @brief Configure Als and Ranging interrupt reporting
gallonm 1:1de1ea2994d9 378 *
gallonm 1:1de1ea2994d9 379 * Possible values for Range and ALS are\n
gallonm 1:1de1ea2994d9 380 *
gallonm 1:1de1ea2994d9 381 * #CONFIG_GPIO_INTERRUPT_DISABLED\n
gallonm 1:1de1ea2994d9 382 * #CONFIG_GPIO_INTERRUPT_LEVEL_LOW\n
gallonm 1:1de1ea2994d9 383 * #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH\n
gallonm 1:1de1ea2994d9 384 * #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW\n
gallonm 1:1de1ea2994d9 385 * #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY\n
gallonm 1:1de1ea2994d9 386 * Apply respective rang/als shift and mask \n
gallonm 1:1de1ea2994d9 387 * #CONFIG_GPIO_RANGE_SHIFT and full reg mask #CONFIG_GPIO_RANGE_MASK\n
gallonm 1:1de1ea2994d9 388 * #CONFIG_GPIO_ALS_SHIFT and full reg mask #CONFIG_GPIO_ALS_MASK\n
gallonm 1:1de1ea2994d9 389 *
gallonm 1:1de1ea2994d9 390 * \sa GPIO use for interrupt #SYSTEM_MODE_GPIO0 or #SYSTEM_MODE_GPIO1\n
gallonm 1:1de1ea2994d9 391 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 392 */
gallonm 4:a5abf7757947 393 #define SYSTEM_INTERRUPT_CONFIG_GPIO (uint16_t) 0x014
gallonm 1:1de1ea2994d9 394 /** RANGE bits shift in #SYSTEM_INTERRUPT_CONFIG_GPIO */
gallonm 1:1de1ea2994d9 395 #define CONFIG_GPIO_RANGE_SHIFT 0
gallonm 1:1de1ea2994d9 396 /** RANGE bits mask in #SYSTEM_INTERRUPT_CONFIG_GPIO (unshifted)*/
gallonm 1:1de1ea2994d9 397 #define CONFIG_GPIO_RANGE_MASK (0x7<<CONFIG_GPIO_RANGE_SHIFT)
gallonm 1:1de1ea2994d9 398 /** ALS bits shift in #SYSTEM_INTERRUPT_CONFIG_GPIO */
gallonm 1:1de1ea2994d9 399 #define CONFIG_GPIO_ALS_SHIFT 3
gallonm 1:1de1ea2994d9 400 /** ALS bits mask in #SYSTEM_INTERRUPT_CONFIG_GPIO (unshifted)*/
gallonm 1:1de1ea2994d9 401 #define CONFIG_GPIO_ALS_MASK (0x7<<CONFIG_GPIO_ALS_SHIFT)
gallonm 1:1de1ea2994d9 402 /** interrupt is disabled */
gallonm 1:1de1ea2994d9 403 #define CONFIG_GPIO_INTERRUPT_DISABLED 0x00
gallonm 1:1de1ea2994d9 404 /** trigger when value < low threshold */
gallonm 1:1de1ea2994d9 405 #define CONFIG_GPIO_INTERRUPT_LEVEL_LOW 0x01
gallonm 1:1de1ea2994d9 406 /** trigger when value < low threshold */
gallonm 1:1de1ea2994d9 407 #define CONFIG_GPIO_INTERRUPT_LEVEL_HIGH 0x02
gallonm 1:1de1ea2994d9 408 /** trigger when outside range defined by high low threshold */
gallonm 1:1de1ea2994d9 409 #define CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW 0x03
gallonm 1:1de1ea2994d9 410 /** trigger when new sample are ready */
gallonm 1:1de1ea2994d9 411 #define CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY 0x04
gallonm 1:1de1ea2994d9 412
gallonm 1:1de1ea2994d9 413 /**
gallonm 1:1de1ea2994d9 414 * @def SYSTEM_INTERRUPT_CLEAR
gallonm 1:1de1ea2994d9 415 * @brief Writing to this register will clear interrupt source
gallonm 1:1de1ea2994d9 416 *
gallonm 1:1de1ea2994d9 417 * Use or combination of any #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ALS , #INTERRUPT_CLEAR_ERROR
gallonm 1:1de1ea2994d9 418 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 419 */
gallonm 4:a5abf7757947 420 #define SYSTEM_INTERRUPT_CLEAR (uint16_t) 0x015
gallonm 1:1de1ea2994d9 421 /** clear ranging interrupt in write to #SYSTEM_INTERRUPT_CLEAR */
gallonm 1:1de1ea2994d9 422 #define INTERRUPT_CLEAR_RANGING 0x01
gallonm 1:1de1ea2994d9 423 /** clear als interrupt in write to #SYSTEM_INTERRUPT_CLEAR */
gallonm 1:1de1ea2994d9 424 #define INTERRUPT_CLEAR_ALS 0x02
gallonm 1:1de1ea2994d9 425 /** clear error interrupt in write to #SYSTEM_INTERRUPT_CLEAR */
gallonm 1:1de1ea2994d9 426 #define INTERRUPT_CLEAR_ERROR 0x04
gallonm 1:1de1ea2994d9 427
gallonm 1:1de1ea2994d9 428 /** After power up or reset this register will start reading 1 when device is ready */
gallonm 4:a5abf7757947 429 #define SYSTEM_FRESH_OUT_OF_RESET (uint16_t) 0x016
gallonm 1:1de1ea2994d9 430
gallonm 1:1de1ea2994d9 431 /**
gallonm 1:1de1ea2994d9 432 * @def SYSTEM_GROUPED_PARAMETER_HOLD
gallonm 1:1de1ea2994d9 433 * @brief Writing 1/0 activate/deactivate safe host update of multiple register in critical group \n
gallonm 1:1de1ea2994d9 434 * rather use \a VL6180x_SetGroupParamHold()
gallonm 1:1de1ea2994d9 435 *
gallonm 1:1de1ea2994d9 436 * The critical register group is made of: \n
gallonm 1:1de1ea2994d9 437 * #SYSTEM_INTERRUPT_CONFIG_GPIO \n
gallonm 1:1de1ea2994d9 438 * #SYSRANGE_THRESH_HIGH \n
gallonm 1:1de1ea2994d9 439 * #SYSRANGE_THRESH_LOW \n
gallonm 1:1de1ea2994d9 440 * #SYSALS_INTEGRATION_PERIOD \n
gallonm 1:1de1ea2994d9 441 * #SYSALS_ANALOGUE_GAIN \n
gallonm 1:1de1ea2994d9 442 * #SYSALS_THRESH_HIGH \n
gallonm 1:1de1ea2994d9 443 * #SYSALS_THRESH_LOW
gallonm 1:1de1ea2994d9 444 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 445 */
gallonm 4:a5abf7757947 446 #define SYSTEM_GROUPED_PARAMETER_HOLD (uint16_t) 0x017
gallonm 1:1de1ea2994d9 447
gallonm 1:1de1ea2994d9 448
gallonm 1:1de1ea2994d9 449 /**
gallonm 1:1de1ea2994d9 450 * @def SYSRANGE_START
gallonm 1:1de1ea2994d9 451 * @brief Start/stop and set operating range mode
gallonm 1:1de1ea2994d9 452 *
gallonm 1:1de1ea2994d9 453 * Write Combination of #MODE_START_STOP and #MODE_CONTINUOUS to select and start desired operation.
gallonm 1:1de1ea2994d9 454 *
gallonm 1:1de1ea2994d9 455 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 456 */
gallonm 4:a5abf7757947 457 #define SYSRANGE_START (uint16_t) 0x018
gallonm 1:1de1ea2994d9 458 /** mask existing bit in #SYSRANGE_START*/
gallonm 1:1de1ea2994d9 459 #define MODE_MASK 0x03
gallonm 1:1de1ea2994d9 460 /** bit 0 in #SYSRANGE_START write 1 toggle state in continuous mode and arm next shot in single shot mode */
gallonm 1:1de1ea2994d9 461 #define MODE_START_STOP 0x01
gallonm 1:1de1ea2994d9 462 /** bit 1 write 1 in #SYSRANGE_START set continuous operation mode */
gallonm 1:1de1ea2994d9 463 #define MODE_CONTINUOUS 0x02
gallonm 1:1de1ea2994d9 464 /** bit 1 write 0 in #SYSRANGE_START set single shot mode */
gallonm 1:1de1ea2994d9 465 #define MODE_SINGLESHOT 0x00
gallonm 1:1de1ea2994d9 466
gallonm 1:1de1ea2994d9 467 /**
gallonm 1:1de1ea2994d9 468 * @def SYSRANGE_THRESH_HIGH
gallonm 1:1de1ea2994d9 469 * High level range threshold (must be scaled)
gallonm 1:1de1ea2994d9 470 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 471 */
gallonm 4:a5abf7757947 472 #define SYSRANGE_THRESH_HIGH (uint16_t) 0x019
gallonm 1:1de1ea2994d9 473
gallonm 1:1de1ea2994d9 474 /**
gallonm 1:1de1ea2994d9 475 * @def SYSRANGE_THRESH_LOW
gallonm 1:1de1ea2994d9 476 * Low level range threshold (must be scaled)
gallonm 1:1de1ea2994d9 477 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 478 */
gallonm 4:a5abf7757947 479 #define SYSRANGE_THRESH_LOW (uint16_t) 0x01A
gallonm 1:1de1ea2994d9 480
gallonm 1:1de1ea2994d9 481 /**
gallonm 1:1de1ea2994d9 482 * @def SYSRANGE_INTERMEASUREMENT_PERIOD
gallonm 1:1de1ea2994d9 483 * @brief Continuous mode intermeasurement delay \a VL6180x_RangeSetInterMeasPeriod()
gallonm 1:1de1ea2994d9 484 *
gallonm 1:1de1ea2994d9 485 * Time delay between measurements in Ranging continuous mode.\n
gallonm 1:1de1ea2994d9 486 * Range 0-254 (0 = 10ms).\n Step size = 10ms.
gallonm 1:1de1ea2994d9 487 *
gallonm 1:1de1ea2994d9 488 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 489 */
gallonm 4:a5abf7757947 490 #define SYSRANGE_INTERMEASUREMENT_PERIOD (uint16_t) 0x01B
gallonm 1:1de1ea2994d9 491
gallonm 1:1de1ea2994d9 492 /**
gallonm 1:1de1ea2994d9 493 * @brief Maximum time to run measurement in Ranging modes.
gallonm 1:1de1ea2994d9 494 * Range 1 - 63 ms (1 code = 1 ms);
gallonm 1:1de1ea2994d9 495 *
gallonm 1:1de1ea2994d9 496 * Measurement aborted when limit reached to aid power reduction.\
gallonm 1:1de1ea2994d9 497 * For example, 0x01 = 1ms, 0x0a = 10ms.\
gallonm 1:1de1ea2994d9 498 * Note: Effective max_convergence_time depends on readout_averaging_sample_period setting.
gallonm 1:1de1ea2994d9 499 *
gallonm 1:1de1ea2994d9 500 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 501 */
gallonm 4:a5abf7757947 502 #define SYSRANGE_MAX_CONVERGENCE_TIME (uint16_t) 0x01C
gallonm 1:1de1ea2994d9 503 /**@brief Cross talk compensation rate
gallonm 1:1de1ea2994d9 504 * @warning never write register directly use @a VL6180x_SetXTalkCompensationRate()
gallonm 1:1de1ea2994d9 505 * refer to manual for calibration procedure and computation
gallonm 1:1de1ea2994d9 506 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 507 */
gallonm 4:a5abf7757947 508 #define SYSRANGE_CROSSTALK_COMPENSATION_RATE (uint16_t) 0x01E
gallonm 1:1de1ea2994d9 509 /**
gallonm 1:1de1ea2994d9 510 * @brief Minimum range value in mm to qualify for crosstalk compensation
gallonm 1:1de1ea2994d9 511 */
gallonm 4:a5abf7757947 512 #define SYSRANGE_CROSSTALK_VALID_HEIGHT (uint16_t) 0x021
gallonm 4:a5abf7757947 513 #define SYSRANGE_EARLY_CONVERGENCE_ESTIMATE (uint16_t) 0x022
gallonm 4:a5abf7757947 514 #define SYSRANGE_PART_TO_PART_RANGE_OFFSET (uint16_t) 0x024
gallonm 4:a5abf7757947 515 #define SYSRANGE_RANGE_IGNORE_VALID_HEIGHT (uint16_t) 0x025
gallonm 4:a5abf7757947 516 #define SYSRANGE_RANGE_IGNORE_THRESHOLD (uint16_t) 0x026
gallonm 4:a5abf7757947 517 #define SYSRANGE_EMITTER_BLOCK_THRESHOLD (uint16_t) 0x028
gallonm 4:a5abf7757947 518 #define SYSRANGE_MAX_AMBIENT_LEVEL_THRESH (uint16_t) 0x02A
gallonm 4:a5abf7757947 519 #define SYSRANGE_MAX_AMBIENT_LEVEL_MULT (uint16_t) 0x02C
gallonm 1:1de1ea2994d9 520 /** @brief various Enable check enabel register
gallonm 1:1de1ea2994d9 521 * @a VL6180x_RangeSetEceState()
gallonm 1:1de1ea2994d9 522 */
gallonm 4:a5abf7757947 523 #define SYSRANGE_RANGE_CHECK_ENABLES (uint16_t) 0x02D
gallonm 1:1de1ea2994d9 524 #define RANGE_CHECK_ECE_ENABLE_MASK 0x01
gallonm 1:1de1ea2994d9 525 #define RANGE_CHECK_RANGE_ENABLE_MASK 0x02
gallonm 1:1de1ea2994d9 526 #define RANGE_CHECK_SNR_ENABLKE 0x10
gallonm 1:1de1ea2994d9 527
gallonm 4:a5abf7757947 528 #define SYSRANGE_VHV_RECALIBRATE (uint16_t) 0x02E
gallonm 1:1de1ea2994d9 529 #define SYSRANGE_VHV_REPEAT_RATE 0x031
gallonm 1:1de1ea2994d9 530
gallonm 1:1de1ea2994d9 531 /**
gallonm 1:1de1ea2994d9 532 * @def SYSALS_START
gallonm 1:1de1ea2994d9 533 * @brief Start/stop and set operating als mode
gallonm 1:1de1ea2994d9 534 *
gallonm 1:1de1ea2994d9 535 * same bit definition as range \a #SYSRANGE_START \n
gallonm 1:1de1ea2994d9 536 */
gallonm 4:a5abf7757947 537 #define SYSALS_START (uint16_t) 0x038
gallonm 1:1de1ea2994d9 538
gallonm 1:1de1ea2994d9 539 /** ALS low Threshold high */
gallonm 4:a5abf7757947 540 #define SYSALS_THRESH_HIGH (uint16_t) 0x03A
gallonm 1:1de1ea2994d9 541 /** ALS low Threshold low */
gallonm 4:a5abf7757947 542 #define SYSALS_THRESH_LOW (uint16_t) 0x03C
gallonm 1:1de1ea2994d9 543 /** ALS intermeasurement period */
gallonm 4:a5abf7757947 544 #define SYSALS_INTERMEASUREMENT_PERIOD (uint16_t) 0x03E
gallonm 1:1de1ea2994d9 545 /**
gallonm 1:1de1ea2994d9 546 * @warning or value with 0x40 when writing to these register*/
gallonm 4:a5abf7757947 547 #define SYSALS_ANALOGUE_GAIN (uint16_t) 0x03F
gallonm 1:1de1ea2994d9 548 /** ALS integration period */
gallonm 4:a5abf7757947 549 #define SYSALS_INTEGRATION_PERIOD (uint16_t) 0x040
gallonm 1:1de1ea2994d9 550
gallonm 1:1de1ea2994d9 551 /**
gallonm 1:1de1ea2994d9 552 * @brief Result range status
gallonm 1:1de1ea2994d9 553 *
gallonm 1:1de1ea2994d9 554 * Hold the various range interrupt flags and error Specific error codes
gallonm 1:1de1ea2994d9 555 */
gallonm 4:a5abf7757947 556 #define RESULT_RANGE_STATUS (uint16_t) 0x04D
gallonm 1:1de1ea2994d9 557 /** Device ready for new command bit 0*/
gallonm 1:1de1ea2994d9 558 #define RANGE_DEVICE_READY_MASK 0x01
gallonm 1:1de1ea2994d9 559 /** mask for error status covers bits [7:4] in #RESULT_RANGE_STATUS @a ::RangeError_u */
gallonm 1:1de1ea2994d9 560 #define RANGE_ERROR_CODE_MASK 0xF0 /* */
gallonm 1:1de1ea2994d9 561 /** range error bit position in #RESULT_RANGE_STATUS */
gallonm 1:1de1ea2994d9 562 #define RANGE_ERROR_CODE_SHIFT 4
gallonm 1:1de1ea2994d9 563
gallonm 1:1de1ea2994d9 564 /**
gallonm 1:1de1ea2994d9 565 * @def RESULT_ALS_STATUS
gallonm 1:1de1ea2994d9 566 * @brief Result als status \n
gallonm 1:1de1ea2994d9 567 * Hold the various als interrupt flags and Specific error codes
gallonm 1:1de1ea2994d9 568 */
gallonm 4:a5abf7757947 569 #define RESULT_ALS_STATUS (uint16_t) 0x4E
gallonm 1:1de1ea2994d9 570 /** Device ready for new command bit 0*/
gallonm 1:1de1ea2994d9 571 #define ALS_DEVICE_READY_MASK 0x01
gallonm 1:1de1ea2994d9 572
gallonm 1:1de1ea2994d9 573 /**
gallonm 1:1de1ea2994d9 574 * @def RESULT_ALS_VAL
gallonm 1:1de1ea2994d9 575 * @brief 16 Bit ALS count output value.
gallonm 1:1de1ea2994d9 576 *
gallonm 1:1de1ea2994d9 577 * Lux value depends on Gain and integration settings and calibrated lux/count setting
gallonm 1:1de1ea2994d9 578 * \a VL6180x_AlsGetLux() \a VL6180x_AlsGetMeasurement()
gallonm 1:1de1ea2994d9 579 */
gallonm 4:a5abf7757947 580 #define RESULT_ALS_VAL (uint16_t) 0x50
gallonm 1:1de1ea2994d9 581
gallonm 1:1de1ea2994d9 582 /**
gallonm 1:1de1ea2994d9 583 * @def FW_ALS_RESULT_SCALER
gallonm 1:1de1ea2994d9 584 * @brief Als scaler register Bits [3:0] analogue gain 1 to 16x
gallonm 1:1de1ea2994d9 585 * these register content is cached by API in \a VL6180xDevData_t::AlsScaler
gallonm 1:1de1ea2994d9 586 * for lux computation acceleration
gallonm 1:1de1ea2994d9 587 */
gallonm 4:a5abf7757947 588 #define FW_ALS_RESULT_SCALER (uint16_t) 0x120
gallonm 1:1de1ea2994d9 589
gallonm 1:1de1ea2994d9 590
gallonm 1:1de1ea2994d9 591 /**
gallonm 1:1de1ea2994d9 592 * these union can be use as a generic bit field type for map #RESULT_INTERRUPT_STATUS_GPIO register
gallonm 1:1de1ea2994d9 593 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 594 */
gallonm 1:1de1ea2994d9 595 typedef union IntrStatus_u{
gallonm 1:1de1ea2994d9 596 uint8_t val; /*!< raw 8 bit register value*/
gallonm 1:1de1ea2994d9 597 struct {
gallonm 1:1de1ea2994d9 598 unsigned Range :3; /*!< Range status one of :\n \a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n \a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n \a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n \a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY */
gallonm 1:1de1ea2994d9 599 unsigned Als :3; /*!< Als status one of: \n \a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n \a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n \a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n \a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY */
gallonm 1:1de1ea2994d9 600 unsigned Error :2; /*!< Error status of: \n \a #RES_INT_ERROR_LASER_SAFETY \n \a #RES_INT_ERROR_PLL */
gallonm 1:1de1ea2994d9 601 } status; /*!< interrupt status as bit field */
gallonm 1:1de1ea2994d9 602 } IntrStatus_t;
gallonm 1:1de1ea2994d9 603
gallonm 1:1de1ea2994d9 604 /**
gallonm 1:1de1ea2994d9 605 * @def RESULT_INTERRUPT_STATUS_GPIO
gallonm 1:1de1ea2994d9 606 * @brief System interrupt status report selected interrupt for als and ranging
gallonm 1:1de1ea2994d9 607 *
gallonm 1:1de1ea2994d9 608 * These register can be polled even if no gpio pins is active\n
gallonm 1:1de1ea2994d9 609 * What reported is selected by \a #SYSTEM_INTERRUPT_CONFIG_GPIO \n
gallonm 1:1de1ea2994d9 610 * Range mask with \a #RES_INT_RANGE_MASK and shit by \a #RES_INT_RANGE_SHIFT
gallonm 1:1de1ea2994d9 611 * Als mask with \a #RES_INT_ALS_MASK and shit by \a #RES_INT_ALS_SHIFT
gallonm 1:1de1ea2994d9 612 * Result value express condition (or combination?)
gallonm 1:1de1ea2994d9 613 * \a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n
gallonm 1:1de1ea2994d9 614 * \a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n
gallonm 1:1de1ea2994d9 615 * \a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n
gallonm 1:1de1ea2994d9 616 * \a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY
gallonm 1:1de1ea2994d9 617 *
gallonm 1:1de1ea2994d9 618 * @ingroup device_regdef
gallonm 1:1de1ea2994d9 619 */
gallonm 4:a5abf7757947 620 #define RESULT_INTERRUPT_STATUS_GPIO (uint16_t) 0x4F
gallonm 1:1de1ea2994d9 621 /** ranging interrupt 1st bit position in #RESULT_INTERRUPT_STATUS_GPIO */
gallonm 1:1de1ea2994d9 622 #define RES_INT_RANGE_SHIFT 0
gallonm 1:1de1ea2994d9 623 /** ALS interrupt 1st bit position in #RESULT_INTERRUPT_STATUS_GPIO */
gallonm 1:1de1ea2994d9 624 #define RES_INT_ALS_SHIFT 3
gallonm 1:1de1ea2994d9 625 /** interrupt bit position in #RESULT_INTERRUPT_STATUS_GPIO */
gallonm 1:1de1ea2994d9 626 #define RES_INT_ERROR_SHIFT 6
gallonm 1:1de1ea2994d9 627 /** Ranging interrupt mask in #RESULT_INTERRUPT_STATUS_GPIO (prior to shift) \sa IntrStatus_t */
gallonm 1:1de1ea2994d9 628 #define RES_INT_RANGE_MASK (0x7<<RES_INT_RANGE_SHIFT)
gallonm 1:1de1ea2994d9 629 /** als interrupt mask in #RESULT_INTERRUPT_STATUS_GPIO (prior to shift) \sa IntrStatus_t */
gallonm 1:1de1ea2994d9 630 #define RES_INT_ALS_MASK (0x7<<RES_INT_ALS_SHIFT)
gallonm 1:1de1ea2994d9 631
gallonm 1:1de1ea2994d9 632 /** low threshold condition in #RESULT_INTERRUPT_STATUS_GPIO for */
gallonm 1:1de1ea2994d9 633 #define RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD 0x01
gallonm 1:1de1ea2994d9 634 /** high threshold condition in #RESULT_INTERRUPT_STATUS_GPIO for ALs or Rage*/
gallonm 1:1de1ea2994d9 635 #define RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD 0x02
gallonm 1:1de1ea2994d9 636 /** out of window condition in #RESULT_INTERRUPT_STATUS_GPIO */
gallonm 1:1de1ea2994d9 637 #define RES_INT_STAT_GPIO_OUT_OF_WINDOW 0x03
gallonm 1:1de1ea2994d9 638 /** new sample ready in #RESULT_INTERRUPT_STATUS_GPIO */
gallonm 1:1de1ea2994d9 639 #define RES_INT_STAT_GPIO_NEW_SAMPLE_READY 0x04
gallonm 1:1de1ea2994d9 640 /** error in #RESULT_INTERRUPT_STATUS_GPIO */
gallonm 1:1de1ea2994d9 641 #define RES_INT_ERROR_MASK (0x3<<RES_INT_ERROR_SHIFT)
gallonm 1:1de1ea2994d9 642 /** laser safety error on #RES_INT_ERROR_MASK of #RESULT_INTERRUPT_STATUS_GPIO */
gallonm 1:1de1ea2994d9 643 #define RES_INT_ERROR_LASER_SAFETY 1
gallonm 1:1de1ea2994d9 644 /** pll 1 or 2 error on #RES_INT_ERROR_MASK of #RESULT_INTERRUPT_STATUS_GPIO*/
gallonm 1:1de1ea2994d9 645 #define RES_INT_ERROR_PLL 2
gallonm 1:1de1ea2994d9 646
gallonm 1:1de1ea2994d9 647 /**
gallonm 1:1de1ea2994d9 648 * Final range result value presented to the user for use. Unit is in mm.
gallonm 1:1de1ea2994d9 649 */
gallonm 4:a5abf7757947 650 #define RESULT_RANGE_VAL (uint16_t) 0x062
gallonm 1:1de1ea2994d9 651
gallonm 1:1de1ea2994d9 652 /**
gallonm 1:1de1ea2994d9 653 * Raw Range result value with offset applied (no cross talk compensation applied). Unit is in mm.
gallonm 1:1de1ea2994d9 654 */
gallonm 4:a5abf7757947 655 #define RESULT_RANGE_RAW (uint16_t) 0x064
gallonm 1:1de1ea2994d9 656
gallonm 1:1de1ea2994d9 657 /**
gallonm 1:1de1ea2994d9 658 * @brief Sensor count rate of signal returns correlated to IR emitter.
gallonm 1:1de1ea2994d9 659 *
gallonm 1:1de1ea2994d9 660 * Computed from RETURN_SIGNAL_COUNT / RETURN_CONV_TIME. Mcps 9.7 format
gallonm 1:1de1ea2994d9 661 */
gallonm 4:a5abf7757947 662 #define RESULT_RANGE_SIGNAL_RATE (uint16_t) 0x066
gallonm 1:1de1ea2994d9 663
gallonm 1:1de1ea2994d9 664 /**
gallonm 1:1de1ea2994d9 665 * @brief Return signal count
gallonm 1:1de1ea2994d9 666 *
gallonm 1:1de1ea2994d9 667 * Sensor count output value attributed to signal correlated to IR emitter on the Return array.
gallonm 1:1de1ea2994d9 668 */
gallonm 4:a5abf7757947 669 #define RESULT_RANGE_RETURN_SIGNAL_COUNT (uint16_t) 0x06C
gallonm 1:1de1ea2994d9 670
gallonm 1:1de1ea2994d9 671 /**
gallonm 1:1de1ea2994d9 672 * @brief Reference signal count
gallonm 1:1de1ea2994d9 673 *
gallonm 1:1de1ea2994d9 674 * sensor count output value attributed to signal correlated to IR emitter on the Reference array.
gallonm 1:1de1ea2994d9 675 */
gallonm 4:a5abf7757947 676 #define RESULT_RANGE_REFERENCE_SIGNAL_COUNT (uint16_t) 0x070
gallonm 1:1de1ea2994d9 677
gallonm 1:1de1ea2994d9 678 /**
gallonm 1:1de1ea2994d9 679 * @brief Return ambient count
gallonm 1:1de1ea2994d9 680 *
gallonm 1:1de1ea2994d9 681 * sensor count output value attributed to uncorrelated ambient signal on the Return array.
gallonm 1:1de1ea2994d9 682 * Must be multiplied by 6 if used to calculate the ambient to signal threshold
gallonm 1:1de1ea2994d9 683 */
gallonm 4:a5abf7757947 684 #define RESULT_RANGE_RETURN_AMB_COUNT (uint16_t) 0x074
gallonm 1:1de1ea2994d9 685
gallonm 1:1de1ea2994d9 686 /**
gallonm 1:1de1ea2994d9 687 * @brief Reference ambient count
gallonm 1:1de1ea2994d9 688 *
gallonm 1:1de1ea2994d9 689 * Sensor count output value attributed to uncorrelated ambient signal on the Reference array.
gallonm 1:1de1ea2994d9 690 */
gallonm 4:a5abf7757947 691 #define RESULT_RANGE_REFERENCE_AMB_COUNT (uint16_t) 0x078
gallonm 1:1de1ea2994d9 692
gallonm 1:1de1ea2994d9 693 /**
gallonm 1:1de1ea2994d9 694 * sensor count output value attributed to signal on the Return array.
gallonm 1:1de1ea2994d9 695 */
gallonm 4:a5abf7757947 696 #define RESULT_RANGE_RETURN_CONV_TIME (uint16_t) 0x07C
gallonm 1:1de1ea2994d9 697
gallonm 1:1de1ea2994d9 698 /**
gallonm 1:1de1ea2994d9 699 * sensor count output value attributed to signal on the Reference array.
gallonm 1:1de1ea2994d9 700 */
gallonm 4:a5abf7757947 701 #define RESULT_RANGE_REFERENCE_CONV_TIME (uint16_t) 0x080
gallonm 1:1de1ea2994d9 702
gallonm 1:1de1ea2994d9 703
gallonm 1:1de1ea2994d9 704 /**
gallonm 1:1de1ea2994d9 705 * @def RANGE_SCALER
gallonm 1:1de1ea2994d9 706 * @brief RANGE scaling register
gallonm 1:1de1ea2994d9 707 *
gallonm 1:1de1ea2994d9 708 * Never should user write directly onto that register directly \a VL6180x_UpscaleSetScaling()
gallonm 1:1de1ea2994d9 709 */
gallonm 4:a5abf7757947 710 #define RANGE_SCALER (uint16_t) 0x096
gallonm 1:1de1ea2994d9 711
gallonm 1:1de1ea2994d9 712 /**
gallonm 1:1de1ea2994d9 713 * @def READOUT_AVERAGING_SAMPLE_PERIOD
gallonm 1:1de1ea2994d9 714 * @brief Readout averaging sample period register
gallonm 1:1de1ea2994d9 715 *
gallonm 1:1de1ea2994d9 716 *
gallonm 1:1de1ea2994d9 717 * The internal readout averaging sample period can be adjusted from 0 to 255.
gallonm 1:1de1ea2994d9 718 * Increasing the sampling period decreases noise but also reduces the effective
gallonm 1:1de1ea2994d9 719 * max convergence time and increases power consumption
gallonm 1:1de1ea2994d9 720 * Each unit sample period corresponds to around 64.5 μs additional processing time.
gallonm 1:1de1ea2994d9 721 * The recommended setting is 48 which equates to around 4.3 ms.
gallonm 1:1de1ea2994d9 722 *
gallonm 1:1de1ea2994d9 723 * see datasheet for more detail
gallonm 1:1de1ea2994d9 724 */
gallonm 4:a5abf7757947 725 #define READOUT_AVERAGING_SAMPLE_PERIOD (uint16_t) 0x10A
gallonm 1:1de1ea2994d9 726
gallonm 1:1de1ea2994d9 727 /**
gallonm 1:1de1ea2994d9 728 * @def I2C_SLAVE_DEVICE_ADDRESS
gallonm 1:1de1ea2994d9 729 * User programmable I2C address (7-bit). Device address can be re-designated after power-up.
gallonm 1:1de1ea2994d9 730 * @warning What programmed in the register 7-0 are bit 8-1 of i2c address on bus (bit 0 is rd/wr)
gallonm 1:1de1ea2994d9 731 * so what prohamd is commonly whar ergfer as adrerss /2
gallonm 1:1de1ea2994d9 732 * @sa VL6180x_SetI2CAddress()
gallonm 1:1de1ea2994d9 733 */
gallonm 4:a5abf7757947 734 #define I2C_SLAVE_DEVICE_ADDRESS (uint16_t) 0x212
gallonm 1:1de1ea2994d9 735
gallonm 1:1de1ea2994d9 736 #endif /* _VL6180x_DEF */