Library to handle the X-NUCLEO-6180XA1 Proximity and ambient light sensor expansion board based on VL6180X.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_6180XA1 SunTracker_BLE Servo_6180XA1 BLE_HR_Light ... more

Fork of X_NUCLEO_6180XA1 by ST Expansion SW Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers vl6180x_def.h Source File

vl6180x_def.h

00001 /*******************************************************************************
00002 Copyright © 2014, STMicroelectronics International N.V.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of STMicroelectronics nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
00019 NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED. 
00020 IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
00021 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 ********************************************************************************/
00028 
00029 /*
00030  * $Date: 2015-05-13 14:12:05 +0200 (Wed, 13 May 2015) $
00031  * $Revision: 2290 $
00032  */
00033 
00034 /**
00035  * @file VL6180X_def.h
00036  *
00037  * @brief Type definitions for vl6180x api.
00038  *
00039  */
00040 
00041 
00042 #ifndef _VL6180X_DEF
00043 #define _VL6180X_DEF
00044 
00045 /** API major version */
00046 #define VL6180X_API_REV_MAJOR   3
00047 /** API minor version */
00048 #define VL6180X_API_REV_MINOR   0
00049 /** API sub version */
00050 #define VL6180X_API_REV_SUB     1
00051 
00052 #define VL6180X_STR_HELPER(x) #x
00053 #define VL6180X_STR(x) VL6180X_STR_HELPER(x)
00054 
00055 #include "vl6180x_cfg.h"
00056 #include "vl6180x_types.h"
00057 
00058 /*
00059  * check configuration macro raise error or warning and suggest a default value
00060  */
00061 
00062 #ifndef VL6180X_UPSCALE_SUPPORT
00063 #error "VL6180X_UPSCALE_SUPPORT not defined"
00064 /* TODO you must define value for  upscale support in your vl6180x_cfg.h  */
00065 #endif
00066 
00067 #ifndef VL6180X_ALS_SUPPORT
00068 #error "VL6180X_ALS_SUPPORT not defined"
00069 /* TODO you must define VL6180X_ALS_SUPPORT  with a value in your vl6180x_cfg.h  set to 0 do disable*/
00070 #endif
00071 
00072 #ifndef VL6180X_HAVE_DMAX_RANGING
00073 #error "VL6180X_HAVE_DMAX_RANGING not defined"
00074 /* TODO you may remove or comment these #error and keep the default below  or update your vl6180x_cfg.h .h file */
00075 /**
00076  * force VL6180X_HAVE_DMAX_RANGING to not supported when not part of cfg file
00077  */
00078 #define VL6180X_HAVE_DMAX_RANGING   0
00079 #endif
00080 
00081 #ifndef VL6180X_EXTENDED_RANGE
00082 #define VL6180X_EXTENDED_RANGE   0
00083 #endif
00084 
00085 #ifndef  VL6180X_WRAP_AROUND_FILTER_SUPPORT
00086 #error "VL6180X_WRAP_AROUND_FILTER_SUPPORT not defined ?"
00087 /* TODO you may remove or comment these #error and keep the default below  or update vl6180x_cfg.h file */
00088 /**
00089  * force VL6180X_WRAP_AROUND_FILTER_SUPPORT to not supported when not part of cfg file
00090  */
00091 #define VL6180X_WRAP_AROUND_FILTER_SUPPORT 0
00092 #endif
00093 
00094 
00095 
00096 
00097 /****************************************
00098  * PRIVATE define do not edit
00099  ****************************************/
00100 
00101 /** Maximal buffer size ever use in i2c */
00102 #define VL6180X_MAX_I2C_XFER_SIZE   8 /* At present time it 6 byte max but that can change */
00103 
00104 #if VL6180X_UPSCALE_SUPPORT < 0
00105 /**
00106  * @def VL6180X_HAVE_UPSCALE_DATA
00107  * @brief  is defined if device data structure has data so when user configurable up-scale is active
00108  */
00109 #define VL6180X_HAVE_UPSCALE_DATA /* have data only for user configurable up-scale config */
00110 #endif
00111 
00112 #if VL6180X_WRAP_AROUND_FILTER_SUPPORT
00113 /**
00114  * @def VL6180X_HAVE_WRAP_AROUND_DATA
00115  * @brief  is defined if device data structure has filter data so when active in cfg file
00116  */
00117 #define  VL6180X_HAVE_WRAP_AROUND_DATA
00118 #endif
00119 
00120 #if VL6180X_ALS_SUPPORT != 0
00121 /**
00122  * @def  VL6180X_HAVE_ALS_DATA
00123  * @brief is defined when als data are include in device data structure so when als suport if configured
00124  */
00125 #define VL6180X_HAVE_ALS_DATA
00126 #endif
00127 
00128 
00129 #if VL6180X_WRAP_AROUND_FILTER_SUPPORT || VL6180X_HAVE_DMAX_RANGING
00130     #define VL6180X_HAVE_RATE_DATA
00131 #endif
00132 
00133 /** Error and warning code returned by API
00134  *
00135  * negative value are true error mostly fatal\n
00136  * positive value  are warning most of time it's ok to continue\n
00137  */
00138 enum VL6180X_ErrCode_t{
00139     API_NO_ERROR        = 0,
00140     CALIBRATION_WARNING = 1,  /*!< warning invalid calibration data may be in used \a  VL6180X_InitData() \a VL6180X_GetOffsetCalibrationData \a VL6180X_SetOffsetCalibrationData*/
00141     MIN_CLIPED          = 2,  /*!< warning parameter passed was clipped to min before to be applied */
00142     NOT_GUARANTEED      = 3,  /*!< Correct operation is not guaranteed typically using extended ranging on vl6180x */
00143     NOT_READY           = 4,  /*!< the data is not ready retry */
00144 
00145     API_ERROR      = -1,    /*!< Unqualified error */
00146     INVALID_PARAMS = -2,    /*!< parameter passed is invalid or out of range */
00147     NOT_SUPPORTED  = -3,    /*!< function is not supported in current mode or configuration */
00148     RANGE_ERROR    = -4,    /*!< device report a ranging error interrupt status */
00149     TIME_OUT       = -5,    /*!< aborted due to time out */
00150 };
00151 
00152 /**
00153  * Filtered result data structure  range data is to be used
00154  */
00155 typedef struct RangeFilterResult_tag {
00156     uint16_t range_mm ;      /*!< Filtered ranging value */
00157     uint16_t rawRange_mm ;   /*!< raw range value (scaled) */
00158 } RangeFilterResult_t;
00159 
00160 /**
00161  * "small" unsigned data type used in filter
00162  *
00163  * if data space saving is not a concern it can be change to platform native unsigned int
00164  */
00165 typedef uint8_t  FilterType1_t;
00166 
00167 /**
00168  * @def FILTER_NBOF_SAMPLES
00169  * @brief sample history len used for wrap around filtering
00170  */
00171 #define FILTER_NBOF_SAMPLES             10
00172 /**
00173  * Wrap around filter internal data
00174  */
00175 struct FilterData_t {
00176     uint32_t MeasurementIndex ;                      /*!< current measurement index */
00177     uint16_t LastTrueRange [FILTER_NBOF_SAMPLES];    /*!< filtered/corrected  distance history */
00178     uint32_t LastReturnRates [FILTER_NBOF_SAMPLES];  /*!< Return rate history */
00179     uint16_t StdFilteredReads ;                      /*!< internal use */
00180     FilterType1_t Default_ZeroVal ;                  /*!< internal use */
00181     FilterType1_t Default_VAVGVal ;                  /*!< internal use */
00182     FilterType1_t NoDelay_ZeroVal ;                  /*!< internal use */
00183     FilterType1_t NoDelay_VAVGVal ;                  /*!< internal use */
00184     FilterType1_t Previous_VAVGDiff ;                /*!< internal use */
00185 };
00186 
00187 #if  VL6180X_HAVE_DMAX_RANGING
00188 typedef int32_t DMaxFix_t;
00189 struct DMaxData_t {
00190     uint32_t ambTuningWindowFactor_K; /*!<  internal algo tuning (*1000) */
00191 
00192     DMaxFix_t retSignalAt400mm;  /*!< intermediate dmax computation value caching @a #SYSRANGE_CROSSTALK_COMPENSATION_RATE and private reg 0x02A */
00193     //int32_t RegB8;              /*!< register 0xB8 cached to speed reduce i2c traffic for dmax computation */
00194     /* place all word data below to optimize struct packing */
00195     //int32_t minSignalNeeded;    /*!< optimized computation intermediate base on register cached value */
00196     int32_t snrLimit_K;         /*!< cached and optimized computation intermediate from  @a #SYSRANGE_MAX_AMBIENT_LEVEL_MULT */
00197     uint16_t ClipSnrLimit;      /*!< Max value for snr limit */
00198     /* place all byte data below to optimize packing */
00199     //uint8_t MaxConvTime;        /*!< cached max convergence time @a #SYSRANGE_MAX_CONVERGENCE_TIME*/
00200 };
00201 #endif
00202 
00203 /**
00204  * @struct VL6180XDevData_t
00205  *
00206  * @brief Per VL6180X device St private data structure \n
00207  * End user should never access any of these field directly
00208  *
00209  * These must never access directly but only via VL6180XDev/SetData(dev, field) macro
00210  */
00211 struct VL6180XDevData_t {
00212 
00213     uint32_t Part2PartAmbNVM ;  /*!< backed up NVM value */
00214     uint32_t XTalkCompRate_KCps; /*! Cached XTlak Compensation Rate */
00215 
00216     uint16_t EceFactorM ;        /*!< Ece Factor M numerator  */
00217     uint16_t EceFactorD ;        /*!< Ece Factor D denominator*/
00218 
00219 #ifdef VL6180X_HAVE_ALS_DATA
00220     uint16_t IntegrationPeriod ; /*!< cached als Integration period avoid slow read from device at each measure */
00221     uint16_t AlsGainCode ;       /*!< cached Als gain avoid slow read from device at each measure */
00222     uint16_t AlsScaler ;         /*!< cached Als scaler avoid slow read from device at each measure */
00223 #endif
00224 
00225 #ifdef VL6180X_HAVE_UPSCALE_DATA
00226     uint8_t UpscaleFactor ;      /*!<  up-scaling factor*/
00227 #endif
00228 
00229 #ifdef  VL6180X_HAVE_WRAP_AROUND_DATA
00230     uint8_t WrapAroundFilterActive ; /*!< Filter on/off */
00231     struct FilterData_t FilterData ; /*!< Filter internal data state history ... */
00232 #endif
00233 
00234 #if  VL6180X_HAVE_DMAX_RANGING
00235     struct DMaxData_t DMaxData;
00236     uint8_t DMaxEnable;
00237 #endif
00238     int8_t  Part2PartOffsetNVM ;     /*!< backed up NVM value */
00239 };
00240 
00241 #if VL6180X_SINGLE_DEVICE_DRIVER
00242 extern  struct VL6180XDevData_t SingleVL6180XDevData;
00243 #define VL6180XDevDataGet(dev, field) (SingleVL6180XDevData.field)
00244 /* is also used as direct accessor like VL6180XDevDataGet(dev, x)++*/
00245 #define VL6180XDevDataSet(dev, field, data) (SingleVL6180XDevData.field)=(data)
00246 #endif
00247 
00248 
00249 /**
00250  * @struct VL6180X_RangeData_t
00251  * @brief Range and any optional measurement data.
00252  */
00253 typedef struct {
00254     uint32_t range_mm ;          /*!< range distance in mm. */
00255     int32_t signalRate_mcps ;   /*!< signal rate (MCPS)\n these is a 9.7 fix point value, which is effectively a measure of target reflectance.*/
00256     uint32_t errorStatus;      /*!< Error status of the current measurement. \n
00257                                   see @a ::RangeError_u @a VL6180X_GetRangeStatusErrString() */
00258 
00259 
00260 #ifdef VL6180X_HAVE_RATE_DATA
00261     uint32_t rtnAmbRate ;    /*!< Return Ambient rate in KCount per sec related to \a RESULT_RANGE_RETURN_AMB_COUNT */
00262     uint32_t rtnRate ;       /*!< Return rate in KCount per sec  related to \a RESULT_RANGE_RETURN_SIGNAL_COUNT  */
00263     uint32_t rtnConvTime ;   /*!< Return Convergence time \a RESULT_RANGE_RETURN_CONV_TIME */
00264     uint32_t refConvTime ;   /*!< Reference convergence time \a RESULT_RANGE_REFERENCE_CONV_TIME */
00265 #endif
00266 
00267 
00268 #if  VL6180X_HAVE_DMAX_RANGING
00269     uint32_t DMax ;              /*!< DMax  when applicable */
00270 #endif
00271 
00272 #ifdef  VL6180X_HAVE_WRAP_AROUND_DATA
00273     RangeFilterResult_t FilteredData ; /*!< Filter result main range_mm is updated */
00274 #endif
00275 }VL6180X_RangeData_t;
00276 
00277 
00278 /** use where fix point 9.7 bit values are expected
00279  *
00280  * given a floating point value f it's .7 bit point is (int)(f*(1<<7))*/
00281 typedef uint16_t FixPoint97_t;
00282 
00283 /** lux data type */
00284 typedef uint32_t lux_t;
00285 
00286 /**
00287  * @brief This data type defines als  measurement data.
00288  */
00289 typedef struct VL6180X_AlsData_st{
00290     lux_t lux;                 /**< Light measurement (Lux) */
00291     uint32_t errorStatus;      /**< Error status of the current measurement. \n
00292      * No Error := 0. \n
00293      * Refer to product sheets for other error codes. */
00294 }VL6180X_AlsData_t;
00295 
00296 /**
00297  * @brief Range status Error code
00298  *
00299  * @a VL6180X_GetRangeStatusErrString() if configured ( @a #VL6180X_RANGE_STATUS_ERRSTRING )
00300  * related to register @a #RESULT_RANGE_STATUS and additional post processing
00301  */
00302 typedef enum {
00303     NoError_=0,                /*!< 0  0b0000 NoError  */
00304     VCSEL_Continuity_Test,     /*!< 1  0b0001 VCSEL_Continuity_Test */
00305     VCSEL_Watchdog_Test,       /*!< 2  0b0010 VCSEL_Watchdog_Test */
00306     VCSEL_Watchdog,            /*!< 3  0b0011 VCSEL_Watchdog */
00307     PLL1_Lock,                 /*!< 4  0b0100 PLL1_Lock */
00308     PLL2_Lock,                 /*!< 5  0b0101 PLL2_Lock */
00309     Early_Convergence_Estimate,/*!< 6  0b0110 Early_Convergence_Estimate */
00310     Max_Convergence,           /*!< 7  0b0111 Max_Convergence */
00311     No_Target_Ignore,          /*!< 8  0b1000 No_Target_Ignore */
00312     Not_used_9,                /*!< 9  0b1001 Not_used */
00313     Not_used_10,               /*!< 10 0b1010 Not_used_ */
00314     Max_Signal_To_Noise_Ratio, /*!< 11 0b1011 Max_Signal_To_Noise_Ratio*/
00315     Raw_Ranging_Algo_Underflow,/*!< 12 0b1100 Raw_Ranging_Algo_Underflow*/
00316     Raw_Ranging_Algo_Overflow, /*!< 13 0b1101 Raw_Ranging_Algo_Overflow */
00317     Ranging_Algo_Underflow,    /*!< 14 0b1110 Ranging_Algo_Underflow */
00318     Ranging_Algo_Overflow,     /*!< 15 0b1111 Ranging_Algo_Overflow */
00319 
00320     /* code below are addition for API/software side they are not hardware*/
00321     RangingFiltered =0x10,     /*!< 16 0b10000 filtered by post processing*/
00322 
00323 } RangeError_u;
00324 
00325 
00326 /** @defgroup device_regdef Device registers & masks definitions
00327  *  @brief    Device registers and masks definitions
00328  */
00329 
00330  
00331 /** @ingroup device_regdef
00332  * @{*/
00333 
00334 /**
00335  * The device model ID
00336  */
00337 #define IDENTIFICATION_MODEL_ID                 0x000
00338 /**
00339  * Revision identifier of the Device for major change.
00340  */
00341 #define IDENTIFICATION_MODULE_REV_MAJOR         0x003
00342 /**
00343  * Revision identifier of the Device for minor change.
00344  */
00345 #define IDENTIFICATION_MODULE_REV_MINOR         0x004
00346 
00347 
00348 /**
00349  * @def SYSTEM_MODE_GPIO0
00350  * @brief Configures polarity and select which function gpio 0 serves.
00351  *  Gpio0 is chip enable at power up ! Be aware of all h/w implication of turning it to output.
00352  *  Same definition as #SYSTEM_MODE_GPIO1
00353  * @ingroup device_regdef
00354  */
00355 #define SYSTEM_MODE_GPIO0                       0x010
00356 /**
00357  * @def SYSTEM_MODE_GPIO1
00358  * @brief Configures polarity and select what als or ranging functionality gpio pin serves.
00359  *
00360  * Function can be #GPIOx_SELECT_OFF  #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT.\n
00361  * Same definition apply to register GPIO0 that is used as chip enable at power up.
00362  * @ingroup device_regdef
00363  */
00364 #define SYSTEM_MODE_GPIO1                       0x011
00365     /** gpio pad POLARITY mask in #SYSTEM_MODE_GPIO1 (and/or 0) write  1  to set active high polarity (positive edge) */
00366     #define GPIOx_POLARITY_SELECT_MASK              0x20
00367     /** gpio pad Function select shift in #SYSTEM_MODE_GPIO1 or 0 */
00368     #define GPIOx_FUNCTIONALITY_SELECT_SHIFT          1
00369     /** gpio pad Function select mask in #SYSTEM_MODE_GPIO1 or 0 */
00370     #define GPIOx_FUNCTIONALITY_SELECT_MASK          (0xF<<GPIOx_FUNCTIONALITY_SELECT_SHIFT)
00371     /** select no interrupt in #SYSTEM_MODE_GPIO1 pad is put in  Hi-Z*/
00372     #define GPIOx_SELECT_OFF                        0x00
00373     /** select gpiox as interrupt output in  #SYSTEM_MODE_GPIO1 */
00374     #define GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT      0x08
00375     /** select range as source for interrupt on in #SYSTEM_MODE_GPIO1 */
00376     #define GPIOx_MODE_SELECT_RANGING               0x00
00377     /** select als as source for interrupt on in #SYSTEM_MODE_GPIO1 */
00378     #define GPIOx_MODE_SELECT_ALS                   0x01
00379 
00380 
00381 /**
00382  * @def SYSTEM_INTERRUPT_CONFIG_GPIO
00383  *
00384  * @brief   Configure Als and Ranging interrupt reporting
00385  *
00386  * Possible values for Range and ALS are\n
00387  *
00388  * #CONFIG_GPIO_INTERRUPT_DISABLED\n
00389  * #CONFIG_GPIO_INTERRUPT_LEVEL_LOW\n
00390  * #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH\n
00391  * #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW\n
00392  * #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY\n
00393  * Apply respective rang/als shift and mask \n
00394  *  #CONFIG_GPIO_RANGE_SHIFT and full reg mask #CONFIG_GPIO_RANGE_MASK\n
00395  *  #CONFIG_GPIO_ALS_SHIFT and full reg mask #CONFIG_GPIO_ALS_MASK\n
00396  *
00397  * \sa GPIO use for interrupt #SYSTEM_MODE_GPIO0 or #SYSTEM_MODE_GPIO1\n
00398  * @ingroup device_regdef
00399  */
00400 #define SYSTEM_INTERRUPT_CONFIG_GPIO           0x014
00401     /** RANGE bits shift in #SYSTEM_INTERRUPT_CONFIG_GPIO */
00402     #define CONFIG_GPIO_RANGE_SHIFT            0
00403     /** RANGE bits mask in #SYSTEM_INTERRUPT_CONFIG_GPIO  (unshifted)*/
00404     #define CONFIG_GPIO_RANGE_MASK             (0x7<<CONFIG_GPIO_RANGE_SHIFT)
00405     /** ALS bits shift in #SYSTEM_INTERRUPT_CONFIG_GPIO */
00406     #define CONFIG_GPIO_ALS_SHIFT              3
00407     /** ALS bits mask in #SYSTEM_INTERRUPT_CONFIG_GPIO  (unshifted)*/
00408     #define CONFIG_GPIO_ALS_MASK               (0x7<<CONFIG_GPIO_ALS_SHIFT)
00409     /** interrupt is disabled */
00410     #define CONFIG_GPIO_INTERRUPT_DISABLED         0x00
00411     /** trigger when value < low threshold */
00412     #define CONFIG_GPIO_INTERRUPT_LEVEL_LOW        0x01
00413     /** trigger when value < low threshold */
00414     #define CONFIG_GPIO_INTERRUPT_LEVEL_HIGH       0x02
00415     /** trigger when outside range defined by high low threshold */
00416     #define CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW    0x03
00417     /** trigger when new sample are ready */
00418     #define CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY 0x04
00419 
00420 /**
00421  *  @def SYSTEM_INTERRUPT_CLEAR
00422  *  @brief Writing to this register will clear interrupt source
00423  *
00424  *  Use or combination of any #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ALS , #INTERRUPT_CLEAR_ERROR
00425  *  @ingroup device_regdef
00426  */
00427 #define SYSTEM_INTERRUPT_CLEAR                0x015
00428     /** clear ranging interrupt in write to #SYSTEM_INTERRUPT_CLEAR */
00429     #define INTERRUPT_CLEAR_RANGING                0x01
00430     /** clear als interrupt  in write to #SYSTEM_INTERRUPT_CLEAR */
00431     #define INTERRUPT_CLEAR_ALS                    0x02
00432     /** clear error interrupt in write to #SYSTEM_INTERRUPT_CLEAR */
00433     #define INTERRUPT_CLEAR_ERROR                  0x04
00434 
00435 /** After power up or reset this register will start reading 1 when device is ready */
00436 #define SYSTEM_FRESH_OUT_OF_RESET             0x016
00437 
00438 /**
00439  * @def SYSTEM_GROUPED_PARAMETER_HOLD
00440  * @brief Writing 1/0 activate/deactivate safe host update of multiple register in critical group \n
00441  *        rather use \a VL6180X_SetGroupParamHold()
00442  *
00443  * The critical register group is made of: \n
00444  * #SYSTEM_INTERRUPT_CONFIG_GPIO \n
00445  * #SYSRANGE_THRESH_HIGH \n
00446  * #SYSRANGE_THRESH_LOW \n
00447  * #SYSALS_INTEGRATION_PERIOD \n
00448  * #SYSALS_ANALOGUE_GAIN \n
00449  * #SYSALS_THRESH_HIGH \n
00450  * #SYSALS_THRESH_LOW
00451  * @ingroup device_regdef
00452  */
00453 #define SYSTEM_GROUPED_PARAMETER_HOLD         0x017
00454 
00455 
00456 /**
00457  * @def SYSRANGE_START
00458  * @brief Start/stop and set operating range mode
00459  *
00460  * Write Combination of #MODE_START_STOP  and #MODE_CONTINUOUS to select and start desired operation.
00461  *
00462  * @ingroup device_regdef
00463  */
00464 #define SYSRANGE_START                        0x018
00465     /** mask existing bit in #SYSRANGE_START*/
00466     #define MODE_MASK          0x03
00467     /** bit 0 in #SYSRANGE_START write 1 toggle state in continuous mode and arm next shot in single shot mode */
00468     #define MODE_START_STOP    0x01
00469     /** bit 1 write 1 in #SYSRANGE_START set continuous operation mode */
00470     #define MODE_CONTINUOUS    0x02
00471     /** bit 1 write 0 in #SYSRANGE_START set single shot mode */
00472     #define MODE_SINGLESHOT    0x00
00473 
00474 /**
00475  * @def SYSRANGE_THRESH_HIGH
00476  * High level range  threshold (must be scaled)
00477  * @ingroup device_regdef
00478  */
00479 #define SYSRANGE_THRESH_HIGH                  0x019
00480 
00481 /**
00482  * @def SYSRANGE_THRESH_LOW
00483  * Low level range  threshold (must be scaled)
00484  * @ingroup device_regdef
00485  */
00486 #define SYSRANGE_THRESH_LOW                   0x01A
00487 
00488 /**
00489  * @def SYSRANGE_INTERMEASUREMENT_PERIOD
00490  * @brief Continuous mode intermeasurement delay \a VL6180X_RangeSetInterMeasPeriod()
00491  *
00492  * Time delay between measurements in Ranging continuous mode.\n
00493  * Range 0-254 (0 = 10ms).\n Step size = 10ms.
00494  *
00495  * @ingroup device_regdef
00496  */
00497 #define SYSRANGE_INTERMEASUREMENT_PERIOD      0x01B
00498 
00499 /**
00500  * @brief Maximum time to run measurement in Ranging modes.
00501  * Range 1 - 63 ms (1 code = 1 ms);
00502  *
00503  * Measurement aborted when limit reached to aid power  reduction.\
00504  * For example, 0x01 = 1ms, 0x0a = 10ms.\
00505  * Note: Effective max_convergence_time depends on readout_averaging_sample_period setting.
00506  *
00507  * @ingroup device_regdef
00508  */
00509 #define SYSRANGE_MAX_CONVERGENCE_TIME         0x01C
00510 /**@brief Cross talk compensation rate
00511  * @warning  never write register directly use @a VL6180X_SetXTalkCompensationRate()
00512  * refer to manual for calibration procedure and computation
00513  * @ingroup device_regdef
00514  */
00515 #define SYSRANGE_CROSSTALK_COMPENSATION_RATE  0x01E
00516 /**
00517  * @brief Minimum range value in mm to qualify for crosstalk compensation
00518  */
00519 #define SYSRANGE_CROSSTALK_VALID_HEIGHT       0x021
00520 #define SYSRANGE_EARLY_CONVERGENCE_ESTIMATE   0x022
00521 #define SYSRANGE_PART_TO_PART_RANGE_OFFSET    0x024
00522 #define SYSRANGE_RANGE_IGNORE_VALID_HEIGHT    0x025
00523 #define SYSRANGE_RANGE_IGNORE_THRESHOLD       0x026
00524 #define SYSRANGE_EMITTER_BLOCK_THRESHOLD      0x028
00525 #define SYSRANGE_MAX_AMBIENT_LEVEL_THRESH     0x02A
00526 #define SYSRANGE_MAX_AMBIENT_LEVEL_MULT       0x02C
00527 /** @brief  various Enable check enabel register
00528  *  @a VL6180X_RangeSetEceState()
00529  */
00530 #define SYSRANGE_RANGE_CHECK_ENABLES          0x02D
00531     #define RANGE_CHECK_ECE_ENABLE_MASK      0x01
00532     #define RANGE_CHECK_RANGE_ENABLE_MASK    0x02
00533     #define RANGE_CHECK_SNR_ENABLKE          0x10
00534 
00535 #define SYSRANGE_VHV_RECALIBRATE              0x02E
00536 #define SYSRANGE_VHV_REPEAT_RATE              0x031
00537 
00538 /**
00539  * @def SYSALS_START
00540  * @brief Start/stop and set operating als mode
00541  *
00542  * same bit definition as range \a #SYSRANGE_START \n
00543  */
00544 #define SYSALS_START                          0x038
00545 
00546 /** ALS low Threshold high */
00547 #define SYSALS_THRESH_HIGH                    0x03A
00548 /** ALS low Threshold low */
00549 #define SYSALS_THRESH_LOW                     0x03C
00550 /** ALS intermeasurement period */
00551 #define SYSALS_INTERMEASUREMENT_PERIOD        0x03E
00552 /** 
00553  * @warning or value with 0x40 when writing to these register*/
00554 #define SYSALS_ANALOGUE_GAIN                  0x03F
00555 /** ALS integration period */
00556 #define SYSALS_INTEGRATION_PERIOD             0x040
00557 
00558 /**
00559  * @brief Result range status
00560  *
00561  *  Hold the various range interrupt flags and error Specific error codes
00562  */
00563 #define RESULT_RANGE_STATUS                   0x04D
00564     /** Device ready for new command bit 0*/
00565     #define RANGE_DEVICE_READY_MASK       0x01
00566     /** mask for error status covers bits [7:4]  in #RESULT_RANGE_STATUS @a ::RangeError_u */
00567     #define RANGE_ERROR_CODE_MASK         0xF0 /* */
00568     /** range error bit position in #RESULT_RANGE_STATUS */
00569     #define RANGE_ERROR_CODE_SHIFT        4
00570 
00571 /**
00572  * @def RESULT_ALS_STATUS
00573  * @brief Result  als status \n
00574  *  Hold the various als interrupt flags and Specific error codes
00575  */
00576 #define RESULT_ALS_STATUS                     0x4E
00577     /** Device ready for new command bit 0*/
00578    #define ALS_DEVICE_READY_MASK       0x01
00579 
00580 /**
00581  * @def RESULT_ALS_VAL
00582  * @brief 16 Bit ALS count output value.
00583  *
00584  * Lux value depends on Gain and integration settings and calibrated lux/count setting
00585  * \a VL6180X_AlsGetLux() \a VL6180X_AlsGetMeasurement()
00586  */
00587 #define RESULT_ALS_VAL                        0x50
00588 
00589 /**
00590  * @def FW_ALS_RESULT_SCALER
00591  * @brief Als scaler register  Bits [3:0] analogue gain 1 to 16x
00592  * these register content is cached by API in \a VL6180XDevData_t::AlsScaler
00593  * for lux computation acceleration
00594  */
00595 #define FW_ALS_RESULT_SCALER                  0x120
00596 
00597 
00598 /**
00599  * these union can be use as a generic bit field type for map #RESULT_INTERRUPT_STATUS_GPIO register
00600  * @ingroup device_regdef
00601  */
00602 typedef union IntrStatus_u{
00603     uint8_t val ;           /*!< raw 8 bit register value*/
00604     struct  {
00605         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 */
00606         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  */
00607         unsigned Error      :2; /*!<  Error status of: \n \a #RES_INT_ERROR_LASER_SAFETY  \n \a #RES_INT_ERROR_PLL */
00608      } status ;                 /*!< interrupt status as bit field */
00609 } IntrStatus_t;
00610 
00611 /**
00612  * @def RESULT_INTERRUPT_STATUS_GPIO
00613  * @brief System interrupt status report selected interrupt for als and ranging
00614  *
00615  * These register can be polled even if no gpio pins is active\n
00616  * What reported is selected by \a  #SYSTEM_INTERRUPT_CONFIG_GPIO \n
00617  * Range mask with \a #RES_INT_RANGE_MASK and shit by \a #RES_INT_RANGE_SHIFT
00618  * Als   mask with \a #RES_INT_ALS_MASK and shit by \a #RES_INT_ALS_SHIFT
00619  * Result value express condition (or combination?)
00620  * \a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n
00621  * \a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n
00622  * \a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n
00623  * \a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY
00624  *
00625  * @ingroup device_regdef
00626  */
00627 #define RESULT_INTERRUPT_STATUS_GPIO          0x4F
00628     /** ranging interrupt 1st bit position in #RESULT_INTERRUPT_STATUS_GPIO */
00629     #define RES_INT_RANGE_SHIFT  0
00630     /** ALS interrupt 1st bit position in #RESULT_INTERRUPT_STATUS_GPIO */
00631     #define RES_INT_ALS_SHIFT    3
00632     /** interrupt bit position in #RESULT_INTERRUPT_STATUS_GPIO */
00633     #define RES_INT_ERROR_SHIFT  6
00634     /** Ranging interrupt mask in #RESULT_INTERRUPT_STATUS_GPIO (prior to shift)  \sa IntrStatus_t */
00635     #define RES_INT_RANGE_MASK (0x7<<RES_INT_RANGE_SHIFT)
00636     /** als interrupt mask in #RESULT_INTERRUPT_STATUS_GPIO (prior to shift)  \sa IntrStatus_t */
00637     #define RES_INT_ALS_MASK   (0x7<<RES_INT_ALS_SHIFT)
00638 
00639     /** low threshold condition in #RESULT_INTERRUPT_STATUS_GPIO for */
00640     #define RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD  0x01
00641     /** high threshold condition in #RESULT_INTERRUPT_STATUS_GPIO for ALs or Rage*/
00642     #define RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD 0x02
00643     /** out of window condition in #RESULT_INTERRUPT_STATUS_GPIO */
00644     #define RES_INT_STAT_GPIO_OUT_OF_WINDOW        0x03
00645     /** new sample ready in #RESULT_INTERRUPT_STATUS_GPIO */
00646     #define RES_INT_STAT_GPIO_NEW_SAMPLE_READY     0x04
00647     /** error  in #RESULT_INTERRUPT_STATUS_GPIO */
00648     #define RES_INT_ERROR_MASK (0x3<<RES_INT_ERROR_SHIFT)
00649         /** laser safety error on #RES_INT_ERROR_MASK of #RESULT_INTERRUPT_STATUS_GPIO */
00650         #define RES_INT_ERROR_LASER_SAFETY  1
00651         /** pll 1 or 2 error on #RES_INT_ERROR_MASK of #RESULT_INTERRUPT_STATUS_GPIO*/
00652         #define RES_INT_ERROR_PLL           2
00653 
00654 /**
00655  * Final range result value presented to the user for use. Unit is in mm.
00656  */
00657 #define RESULT_RANGE_VAL                        0x062
00658 
00659 /**
00660  * Raw Range result value with offset applied (no cross talk compensation applied). Unit is in mm.
00661  */
00662 #define RESULT_RANGE_RAW                        0x064
00663 
00664 /**
00665  * @brief Sensor count rate of signal returns correlated to IR emitter.
00666  *
00667  * Computed from RETURN_SIGNAL_COUNT / RETURN_CONV_TIME. Mcps 9.7 format
00668  */
00669 #define RESULT_RANGE_SIGNAL_RATE                0x066
00670 
00671 /**
00672  * @brief Return signal count
00673  *
00674  *  Sensor count output value attributed to signal correlated to IR emitter on the Return array.
00675  */
00676 #define RESULT_RANGE_RETURN_SIGNAL_COUNT        0x06C
00677 
00678 /**
00679  * @brief Reference signal count
00680  *
00681  * sensor count output value attributed to signal correlated to IR emitter on the Reference array.
00682  */
00683 #define RESULT_RANGE_REFERENCE_SIGNAL_COUNT     0x070
00684 
00685 /**
00686  * @brief Return ambient count
00687  *
00688  * sensor count output value attributed to uncorrelated ambient signal on the Return array.
00689  * Must be multiplied by 6 if used to calculate the ambient to signal threshold
00690  */
00691 #define RESULT_RANGE_RETURN_AMB_COUNT           0x074
00692 
00693 /**
00694  * @brief   Reference ambient count
00695  *
00696  * Sensor count output value attributed to uncorrelated ambient signal on the Reference array.
00697  */
00698 #define RESULT_RANGE_REFERENCE_AMB_COUNT        0x078
00699 
00700 /**
00701  * sensor count output value attributed to signal on the Return array.
00702  */
00703 #define RESULT_RANGE_RETURN_CONV_TIME           0x07C
00704 
00705 /**
00706  * sensor count output value attributed to signal on the Reference array.
00707  */
00708 #define RESULT_RANGE_REFERENCE_CONV_TIME        0x080
00709 
00710 
00711 /**
00712  * @def RANGE_SCALER
00713  * @brief RANGE scaling register
00714  *
00715  * Never should  user write directly onto that register directly \a VL6180X_UpscaleSetScaling()
00716  */
00717 #define RANGE_SCALER                            0x096
00718 
00719 /**
00720  * @def READOUT_AVERAGING_SAMPLE_PERIOD
00721  * @brief Readout averaging sample period register
00722  *
00723  *
00724  * The internal readout averaging sample period can be adjusted from 0 to 255.
00725  * Increasing the sampling period decreases noise but also reduces the effective
00726  * max convergence time and increases power consumption
00727  * Each unit sample period corresponds to around 64.5 μs additional processing time.
00728  * The recommended setting is 48 which equates to around 4.3 ms.
00729  *
00730  * see datasheet for more detail
00731  */
00732 #define READOUT_AVERAGING_SAMPLE_PERIOD     0x10A
00733 
00734 /**
00735  * @def I2C_SLAVE_DEVICE_ADDRESS
00736  * User programmable I2C address (7-bit). Device address can be re-designated after power-up.
00737  * @warning What programmed in the register 7-0 are bit 8-1 of i2c address on bus (bit 0 is rd/wr)
00738  * so what prohamd is commonly whar ergfer as adrerss /2
00739  * @sa VL6180X_SetI2CAddress()
00740  */
00741 #define I2C_SLAVE_DEVICE_ADDRESS               0x212
00742 
00743 #endif /* _VL6180X_DEF */