vl6180x_def.h 30 KB

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