Kenji Arai / 6180XA1_simple

Dependents:   Check_VL6180XA1_ToF

Fork of X_NUCLEO_6180XA1 by ST

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