vl53l1_ll_def.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. /*
  2. * Copyright (c) 2017, STMicroelectronics - All Rights Reserved
  3. *
  4. * This file is part of VL53L1 Core and is dual licensed,
  5. * either 'STMicroelectronics
  6. * Proprietary license'
  7. * or 'BSD 3-clause "New" or "Revised" License' , at your option.
  8. *
  9. ********************************************************************************
  10. *
  11. * 'STMicroelectronics Proprietary license'
  12. *
  13. ********************************************************************************
  14. *
  15. * License terms: STMicroelectronics Proprietary in accordance with licensing
  16. * terms at www.st.com/sla0081
  17. *
  18. * STMicroelectronics confidential
  19. * Reproduction and Communication of this document is strictly prohibited unless
  20. * specifically authorized in writing by STMicroelectronics.
  21. *
  22. *
  23. ********************************************************************************
  24. *
  25. * Alternatively, VL53L1 Core may be distributed under the terms of
  26. * 'BSD 3-clause "New" or "Revised" License', in which case the following
  27. * provisions apply instead of the ones mentioned above :
  28. *
  29. ********************************************************************************
  30. *
  31. * License terms: BSD 3-clause "New" or "Revised" License.
  32. *
  33. * Redistribution and use in source and binary forms, with or without
  34. * modification, are permitted provided that the following conditions are met:
  35. *
  36. * 1. Redistributions of source code must retain the above copyright notice, this
  37. * list of conditions and the following disclaimer.
  38. *
  39. * 2. Redistributions in binary form must reproduce the above copyright notice,
  40. * this list of conditions and the following disclaimer in the documentation
  41. * and/or other materials provided with the distribution.
  42. *
  43. * 3. Neither the name of the copyright holder nor the names of its contributors
  44. * may be used to endorse or promote products derived from this software
  45. * without specific prior written permission.
  46. *
  47. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  48. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  50. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  51. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  52. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  54. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  55. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  56. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  57. *
  58. *
  59. ********************************************************************************
  60. *
  61. */
  62. /**
  63. * @file vl53l1_ll_def.h
  64. *
  65. * @brief Type definitions for VL53L1 LL Driver.
  66. *
  67. */
  68. #ifndef _VL53L1_LL_DEF_H_
  69. #define _VL53L1_LL_DEF_H_
  70. #include "vl53l1_ll_device.h"
  71. #include "vl53l1_error_codes.h"
  72. #include "vl53l1_register_structs.h"
  73. #include "vl53l1_platform_user_config.h"
  74. #include "vl53l1_platform_user_defines.h"
  75. #include "vl53l1_error_exceptions.h"
  76. #ifdef __cplusplus
  77. extern "C" {
  78. #endif
  79. /** @defgroup VL53L1_globalLLDriverDefine_group VL53L1 Defines
  80. * @brief VL53L1 LL Driver Defines
  81. * @{
  82. */
  83. /** VL53L1 Low Level Driver IMPLEMENTATION major version */
  84. #define VL53L1_LL_API_IMPLEMENTATION_VER_MAJOR 1
  85. /** VL53L1 Low Level DriverI IMPLEMENTATION minor version */
  86. #define VL53L1_LL_API_IMPLEMENTATION_VER_MINOR 2
  87. /** VL53L1 Low Level DriverI IMPLEMENTATION sub version */
  88. #define VL53L1_LL_API_IMPLEMENTATION_VER_SUB 10
  89. /** VL53L1 Low Level Driver IMPLEMENTATION sub version */
  90. #define VL53L1_LL_API_IMPLEMENTATION_VER_REVISION 1840
  91. #define VL53L1_LL_API_IMPLEMENTATION_VER_STRING "1.2.11.1840"
  92. /** VL53L1_FIRMWARE min and max compatible revisions */
  93. #define VL53L1_FIRMWARE_VER_MINIMUM 398
  94. #define VL53L1_FIRMWARE_VER_MAXIMUM 400
  95. /****************************************
  96. * PRIVATE define do not edit
  97. ****************************************/
  98. #define VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION 0xECAB0102
  99. /** VL53L1 Calibration Data struct version */
  100. /* Start Patch_ZoneCalDataStructVersion_11854 */
  101. #define VL53L1_LL_ZONE_CALIBRATION_DATA_STRUCT_VERSION 0xECAE0101
  102. /** VL53L1 Zone Calibration Data struct version */
  103. /* End Patch_ZoneCalDataStructVersion_11854 */
  104. #define VL53L1_MAX_OFFSET_RANGE_RESULTS 3
  105. /*!< Sets the maximum number of offset range results
  106. required for the offset calibration.
  107. Order is RANGE, MM1, MM2 */
  108. #define VL53L1_NVM_MAX_FMT_RANGE_DATA 4
  109. /*!< The number of FMT range data points stored in NVM */
  110. #define VL53L1_NVM_PEAK_RATE_MAP_SAMPLES 25
  111. /*!< The number of samples in the NVM peak rate signal map */
  112. #define VL53L1_NVM_PEAK_RATE_MAP_WIDTH 5
  113. /*!< Array width of NVM peak rate signal map */
  114. #define VL53L1_NVM_PEAK_RATE_MAP_HEIGHT 5
  115. /*!< Array height the NVM peak rate signal map */
  116. /** @defgroup VL53L1_defineExtraError_group Error and Warning code returned by API
  117. * The following DEFINE are used to identify the PAL ERROR
  118. * @{
  119. */
  120. #define VL53L1_ERROR_DEVICE_FIRMWARE_TOO_OLD ((VL53L1_Error) - 80)
  121. /*!< Device Firmware too old .. */
  122. #define VL53L1_ERROR_DEVICE_FIRMWARE_TOO_NEW ((VL53L1_Error) - 85)
  123. /*!< Device Firmware too new .. */
  124. #define VL53L1_ERROR_UNIT_TEST_FAIL ((VL53L1_Error) - 90)
  125. /*!< Unit Test Fail */
  126. #define VL53L1_ERROR_FILE_READ_FAIL ((VL53L1_Error) - 95)
  127. /*!< File Read Fail */
  128. #define VL53L1_ERROR_FILE_WRITE_FAIL ((VL53L1_Error) - 96)
  129. /*!< File Write Fail */
  130. /*!< Tells requested functionality has not been implemented yet or
  131. * not compatible with the device */
  132. /** @} VL53L1_defineExtraError_group */
  133. /** @brief Defines the parameters of the LL driver Get Version Functions
  134. */
  135. typedef struct {
  136. uint32_t ll_revision; /*!< revision number */
  137. uint8_t ll_major; /*!< major number */
  138. uint8_t ll_minor; /*!< minor number */
  139. uint8_t ll_build; /*!< build number */
  140. } VL53L1_ll_version_t;
  141. /** @brief Reference SPAD Characterization (RefSpadChar) Config
  142. */
  143. typedef struct {
  144. uint8_t device_test_mode; /*!< Device test mode */
  145. uint8_t vcsel_period; /*!< VCSEL period (register) value */
  146. uint32_t timeout_us; /*!< timeout in [us] */
  147. uint16_t target_count_rate_mcps;
  148. /*!< Target reference total count rate in [Mcps] - 9.7 format */
  149. uint16_t min_count_rate_limit_mcps;
  150. /*!< Min valid reference rate [Mcps] - 9.7 format */
  151. uint16_t max_count_rate_limit_mcps;
  152. /*!< Max valid reference rate [Mcps] - 9.7 format */
  153. } VL53L1_refspadchar_config_t;
  154. /** @brief SPAD Self Check (SSC) Config data structure
  155. */
  156. typedef struct {
  157. VL53L1_DeviceSscArray array_select;
  158. /*!< SPAD Array select
  159. * 0 - store RTN array count rates \n
  160. * 1 - store REF array count rates */
  161. uint8_t vcsel_period;
  162. /*!< VCSEL period (register) value */
  163. uint8_t vcsel_start;
  164. /*!< VCSEL start register value */
  165. uint8_t vcsel_width;
  166. /*!< VCSEL ssc_timeout_us width register value e.g. 2 */
  167. uint32_t timeout_us;
  168. /*!< requested Ranging Timeout in [us] e.g 100000us */
  169. uint16_t rate_limit_mcps;
  170. /*!< Rate limit for checks either 1.15 or
  171. * 9.7 dependent on test_mode
  172. */
  173. } VL53L1_ssc_config_t;
  174. /** @brief Xtalk Extraction and Paramter Config
  175. */
  176. typedef struct {
  177. uint32_t algo__crosstalk_compensation_plane_offset_kcps;
  178. /*!< Private crosstalk_compensation_plane_offset_kcps (fixed point 9.9) */
  179. int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
  180. /*!< Private crosstalk_compensation_x_plane_gradient_kcps (fixed point 5.11) */
  181. int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
  182. /*!< Private crosstalk_compensation_y_plane_gradient_kcps (fixed point 5.11) */
  183. uint32_t nvm_default__crosstalk_compensation_plane_offset_kcps;
  184. /*!< NVm stored crosstalk_compensation_plane_offset_kcps (fixed point 9.9) */
  185. int16_t nvm_default__crosstalk_compensation_x_plane_gradient_kcps;
  186. /*!< NVM stored crosstalk_compensation_x_plane_gradient_kcps (fixed point 5.11) */
  187. int16_t nvm_default__crosstalk_compensation_y_plane_gradient_kcps;
  188. /*!< NVM stored crosstalk_compensation_y_plane_gradient_kcps (fixed point 5.11) */
  189. uint8_t global_crosstalk_compensation_enable;
  190. /*!< Enable switch for crosstalk compensation in all modes */
  191. int16_t lite_mode_crosstalk_margin_kcps;
  192. /*!< Additional xtalk factor rate, added to plane_offset value in both
  193. * SD mode, applied as a seperate addition at point of
  194. * application to the device, plane_offset
  195. * value remains unaltered. (fixed point 7.9)
  196. */
  197. uint8_t crosstalk_range_ignore_threshold_mult;
  198. /*!< User set multiplier for range ignore threshold setting (fixed point 3.5) */
  199. uint16_t crosstalk_range_ignore_threshold_rate_mcps;
  200. /*!< Generated range ignore threshold rate in Mcps per spad (fixed
  201. * point 3.13)
  202. */
  203. } VL53L1_xtalk_config_t;
  204. /** @brief TuningParameter Storage
  205. *
  206. * - Storage structure for any LLD tuning parms
  207. * which are dynamically altered by low level functions
  208. * mostly when programming directly to the device
  209. *
  210. *- Added as part of Patch_AddingTuningParmStorage_11821
  211. */
  212. typedef struct {
  213. uint16_t tp_tuning_parm_version;
  214. /*!< Programmed Global tuning version num for debug
  215. */
  216. uint16_t tp_tuning_parm_key_table_version;
  217. /*!< Key Table tuning structure \
  218. * version
  219. */
  220. uint16_t tp_tuning_parm_lld_version;
  221. /*!< Programmed LLD version to ensure matching tuning structure \
  222. * key table
  223. */
  224. uint8_t tp_init_phase_rtn_lite_long;
  225. /*!< initial phase value for rtn array \
  226. * in Lite Long Ranging Mode
  227. */
  228. uint8_t tp_init_phase_rtn_lite_med;
  229. /*!< initial phase value for rtn array \
  230. * in Lite Medium Ranging Mode
  231. */
  232. uint8_t tp_init_phase_rtn_lite_short;
  233. /*!< initial phase value for rtn array \
  234. * in Lite Short Ranging Mode
  235. */
  236. uint8_t tp_init_phase_ref_lite_long;
  237. /*!< initial phase value for ref array \
  238. * in Lite Long Ranging Mode
  239. */
  240. uint8_t tp_init_phase_ref_lite_med;
  241. /*!< initial phase value for ref array \
  242. * in Lite Medium Ranging Mode
  243. */
  244. uint8_t tp_init_phase_ref_lite_short;
  245. /*!< initial phase value for ref array \
  246. * in Lite short Ranging Mode
  247. */
  248. uint8_t tp_consistency_lite_phase_tolerance;
  249. /*!< Phase tolerance consistency value to be used \
  250. * in Lite modes
  251. */
  252. uint8_t tp_phasecal_target;
  253. /*!< Phasecal target value
  254. */
  255. uint16_t tp_cal_repeat_rate;
  256. /*!< Auto VHV/Calibration repeat rate for \
  257. * use in Lite mode
  258. */
  259. uint8_t tp_lite_min_clip;
  260. /*!< Min Clip value in mm applied to device in Lite \
  261. * modes
  262. */
  263. uint16_t tp_lite_long_sigma_thresh_mm;
  264. /*!< Sigma threshold limit for Lite Long mode \
  265. * in 14.2 format mm
  266. */
  267. uint16_t tp_lite_med_sigma_thresh_mm;
  268. /*!< Sigma threshold limit for Lite Medium mode \
  269. * in 14.2 format mm
  270. */
  271. uint16_t tp_lite_short_sigma_thresh_mm;
  272. /*!< Sigma threshold limit for Lite Short mode \
  273. * in 14.2 format mm
  274. */
  275. uint16_t tp_lite_long_min_count_rate_rtn_mcps;
  276. /*!< Min count rate level used in lite long mode \
  277. * in 9.7 Mcps format
  278. */
  279. uint16_t tp_lite_med_min_count_rate_rtn_mcps;
  280. /*!< Min count rate level used in lite medium mode \
  281. * in 9.7 Mcps format
  282. */
  283. uint16_t tp_lite_short_min_count_rate_rtn_mcps;
  284. /*!< Min count rate level used in lite short mode \
  285. * in 9.7 Mcps format
  286. */
  287. uint8_t tp_lite_sigma_est_pulse_width_ns;
  288. /*!< Sigma thresholding tunign parm for Lite mode
  289. */
  290. uint8_t tp_lite_sigma_est_amb_width_ns;
  291. /*!< Sigma thresholding tunign parm for Lite mode
  292. */
  293. uint8_t tp_lite_sigma_ref_mm;
  294. /*!< Sigma thresholding tunign parm for Lite mode
  295. */
  296. uint8_t tp_lite_seed_cfg;
  297. /*!< Lite Mode Seed mode switch
  298. */
  299. uint8_t tp_timed_seed_cfg;
  300. /*!< Timed Mode Seed mode switch
  301. */
  302. uint8_t tp_lite_quantifier;
  303. /*!< Low level quantifier setting for lite modes
  304. */
  305. uint8_t tp_lite_first_order_select;
  306. /*!< Low level First order select setting for lite modes
  307. */
  308. uint16_t tp_dss_target_lite_mcps;
  309. /*!< DSS Target rate in 9.7 format Mcps for lite modes
  310. */
  311. uint16_t tp_dss_target_timed_mcps;
  312. /*!< DSS Target rate in 9.7 format Mcps for Timed modes
  313. */
  314. uint32_t tp_phasecal_timeout_lite_us;
  315. /*!< Phasecal timeout in us for lite modes
  316. */
  317. uint32_t tp_phasecal_timeout_timed_us;
  318. /*!< Phasecal timeout in us for Timed modes
  319. */
  320. uint32_t tp_mm_timeout_lite_us;
  321. /*!< MM stage timeout in us for Lite modes
  322. */
  323. uint32_t tp_mm_timeout_timed_us;
  324. /*!< MM stage timeout in us for Timed modes
  325. */
  326. uint32_t tp_mm_timeout_lpa_us;
  327. /*!< MM stage timeout in us for Low Power Auto modes
  328. */
  329. uint32_t tp_range_timeout_lite_us;
  330. /*!< Ranging stage timeout in us for Lite modes
  331. */
  332. uint32_t tp_range_timeout_timed_us;
  333. /*!< Ranging stage timeout in us for Timed modes
  334. */
  335. uint32_t tp_range_timeout_lpa_us;
  336. /*!< Ranging stage timeout in us for Low Power Auto modes
  337. */
  338. } VL53L1_tuning_parm_storage_t;
  339. /** @brief Optical Centre data
  340. *
  341. */
  342. typedef struct {
  343. uint8_t x_centre; /*!< Optical x centre : 4.4 format */
  344. uint8_t y_centre; /*!< Optical y centre : 4.4 format */
  345. } VL53L1_optical_centre_t;
  346. /** @brief Defines User Zone(ROI) parameters
  347. *
  348. */
  349. typedef struct {
  350. uint8_t x_centre; /*!< Zone x centre : 0-15 range */
  351. uint8_t y_centre; /*!< Zone y centre : 0-15 range */
  352. uint8_t width; /*!< Width of Zone 0 = 1, 7 = 8, 15 = 16 */
  353. uint8_t height; /*!< Height of Zone 0 = 1, 7 = 8, 15 = 16 */
  354. } VL53L1_user_zone_t;
  355. /**
  356. * @struct VL53L1_GPIO_interrupt_config_t
  357. *
  358. * @brief Structure to configure conditions when GPIO interrupt is trigerred
  359. *
  360. */
  361. typedef struct {
  362. /*! Distance interrupt mode */
  363. VL53L1_GPIO_Interrupt_Mode intr_mode_distance;
  364. /*! Rate interrupt mode */
  365. VL53L1_GPIO_Interrupt_Mode intr_mode_rate;
  366. /*! trigger interrupt if a new measurement is ready
  367. * __WARNING!__ will override other settings
  368. */
  369. uint8_t intr_new_measure_ready;
  370. /*! Trigger interrupt if no target found */
  371. uint8_t intr_no_target;
  372. /*! If set to 0, interrupts will only be triggered if BOTH rate AND
  373. * distance thresholds are triggered (combined mode). If set to 1,
  374. * interrupts will be triggered if EITHER rate OR distance thresholds
  375. * are triggered (independent mode). */
  376. uint8_t intr_combined_mode;
  377. /* -- thresholds -- */
  378. /* The struct holds a copy of the thresholds but they are written when
  379. * this structure is set using VL53L1_set_GPIO_interrupt_config/_struct
  380. * */
  381. /*! Distance threshold high limit (mm) */
  382. uint16_t threshold_distance_high;
  383. /*! Distance threshold low limit (mm) */
  384. uint16_t threshold_distance_low;
  385. /*! Rate threshold high limit (9.7 Mcps) */
  386. uint16_t threshold_rate_high;
  387. /*! Rate threshold low limit (9.7 Mcps) */
  388. uint16_t threshold_rate_low;
  389. } VL53L1_GPIO_interrupt_config_t;
  390. /* Start Patch_LowPowerAutoMode */
  391. /**
  392. * @struct VL53L1_low_power_auto_data_t
  393. *
  394. * @brief Structure to hold state, tuning and output variables for the low
  395. * power auto mode (Presence)
  396. *
  397. */
  398. typedef struct {
  399. /*! Tuning variable for the VHV loop bound setting in low power auto
  400. * mode. This is zero based, so the number of loops in VHV is this + 1.
  401. * Please note, the first range will run with default VHV settings.
  402. * Only lower 6 bits are allowed */
  403. uint8_t vhv_loop_bound;
  404. /*! Indicates if we are or are not in low power auto mode */
  405. uint8_t is_low_power_auto_mode;
  406. /*! Used to check if we're running the first range or not. Not to be
  407. * used as a stream count */
  408. uint8_t low_power_auto_range_count;
  409. /*! saved interrupt config byte to restore */
  410. uint8_t saved_interrupt_config;
  411. /*! saved vhv config init byte to restore */
  412. uint8_t saved_vhv_init;
  413. /*! saved vhv config timeout byte to restore */
  414. uint8_t saved_vhv_timeout;
  415. /*! phase cal resutl from the first range */
  416. uint8_t first_run_phasecal_result;
  417. /*! DSS. Total rate per spad given from the current range */
  418. uint32_t dss__total_rate_per_spad_mcps;
  419. /*! DSS. Calculated required SPADs value */
  420. uint16_t dss__required_spads;
  421. } VL53L1_low_power_auto_data_t;
  422. /* End Patch_LowPowerAutoMode */
  423. /**
  424. * @struct VL53L1_range_data_t
  425. * @brief Internal data structure for storing post processed ranges
  426. *
  427. */
  428. typedef struct {
  429. /* Info size */
  430. uint8_t range_id;
  431. /*!< Range Result id e.g 0, 1, 2 */
  432. uint32_t time_stamp;
  433. /*!< 32-bit time stamp */
  434. uint16_t width;
  435. /*!< VCSEL pulse width in [PLL clocks] 6.4 format */
  436. uint8_t woi;
  437. /*!< WOI width in [PLL clocks] */
  438. uint16_t fast_osc_frequency;
  439. /*!< Oscillator frequency in 4.12 format */
  440. uint16_t zero_distance_phase;
  441. /*!< Zero Distance phase in 5.11 format */
  442. uint16_t actual_effective_spads;
  443. /*!< effective SPAD count in 8.8 format */
  444. uint32_t total_periods_elapsed;
  445. /*!< Elapsed time in macro periods for readout channel */
  446. uint32_t peak_duration_us;
  447. /*!< Peak VCSEL width time in us */
  448. uint32_t woi_duration_us;
  449. /*!< WOI duration time in us */
  450. /* Event counts */
  451. uint32_t ambient_window_events;
  452. /*!< Return event count for the ambient window */
  453. uint32_t ranging_total_events;
  454. /*!< Return ranging event count for the ranging window.
  455. This includes both VCSEL and ambient contributions */
  456. int32_t signal_total_events;
  457. /*!< Return event count for the ranging window with ambient
  458. subtracted, Note it is 32-bit signed register */
  459. /* Rates */
  460. uint16_t peak_signal_count_rate_mcps;
  461. /*! Peak signal (VCSEL) Rate in 9.7 format */
  462. uint16_t avg_signal_count_rate_mcps;
  463. /*! Average signal (VCSEL) Rate in 9.7 format */
  464. uint16_t ambient_count_rate_mcps;
  465. /*! Ambient Rate in 9.7 format */
  466. uint16_t total_rate_per_spad_mcps;
  467. /*! Total Rate Per SPAD in 3.13 format */
  468. uint32_t peak_rate_per_spad_kcps;
  469. /*! Peak Rate Per SPAD in 13.11 format */
  470. /* Sigma */
  471. uint16_t sigma_mm;
  472. /*!< Range sigma Estimate [mm] 9.7 format */
  473. /* Phase */
  474. uint16_t median_phase;
  475. /*!< Median Phase in 5.11 format */
  476. /* Range */
  477. int16_t median_range_mm;
  478. /*!< Median Range in [mm] by default there are no fractional bits
  479. Optionally 1 or 2 fractional can be enabled via the
  480. VL53L1_SYSTEM__FRACTIONAL_ENABLE register */
  481. /* Range status */
  482. uint8_t range_status;
  483. } VL53L1_range_data_t;
  484. /**
  485. * @struct VL53L1_range_results_t
  486. * @brief Structure for storing the set of range results
  487. *
  488. */
  489. typedef struct {
  490. VL53L1_DeviceState cfg_device_state;
  491. /*!< Configuration Device State */
  492. VL53L1_DeviceState rd_device_state;
  493. /*!< Read Device State */
  494. uint8_t stream_count;
  495. /*!< 8-bit stream count */
  496. uint8_t device_status;
  497. /*!< Global device status for result set */
  498. VL53L1_range_data_t data[2];
  499. /*!< Range data each target distance */
  500. } VL53L1_range_results_t;
  501. /**
  502. * @struct VL53L1_offset_range_data_t
  503. * @brief Structure for storing the set of range results
  504. * required for the mm1 and mm2 offset calibration
  505. * functions
  506. *
  507. */
  508. typedef struct {
  509. uint8_t preset_mode;
  510. /*!< Preset Mode use for range */
  511. uint8_t dss_config__roi_mode_control;
  512. /*!< Dynamic SPAD selection mode */
  513. uint16_t dss_config__manual_effective_spads_select;
  514. /*!< Requested number of manual effective SPAD's */
  515. uint8_t no_of_samples;
  516. /*!< Number of ranges */
  517. uint32_t effective_spads;
  518. /*!< Average effective SPAD's 8.8 format */
  519. uint32_t peak_rate_mcps;
  520. /*!< Average peak rate Mcps 9.7 format */
  521. uint32_t sigma_mm;
  522. /*!< Average sigma in [mm] 14.2 format */
  523. int32_t median_range_mm;
  524. /*!< Avg of median range over all ranges \
  525. note value is signed */
  526. int32_t range_mm_offset;
  527. /*!< The calculated range offset value */
  528. } VL53L1_offset_range_data_t;
  529. /**
  530. * @struct VL53L1_offset_range_results_t
  531. * @brief Structure for storing the set of range results
  532. * required for the offset calibration functions
  533. *
  534. */
  535. typedef struct {
  536. int16_t cal_distance_mm;
  537. /*!< the calibration distance in [mm]*/
  538. VL53L1_Error cal_status;
  539. /*!< Calibration status, check for warning codes */
  540. uint8_t cal_report;
  541. /*!< Stage for above cal status - 0 Pre, 1 = MM1, 2 = MM2 */
  542. uint8_t max_results;
  543. /*!< Array size for histogram range data i.e. max number
  544. of results */
  545. uint8_t active_results;
  546. /*!< Number of active measurements */
  547. VL53L1_offset_range_data_t data[VL53L1_MAX_OFFSET_RANGE_RESULTS];
  548. /*!< Range results for each offset measurement */
  549. } VL53L1_offset_range_results_t;
  550. /**
  551. * @struct VL53L1_additional_offset_cal_data_t
  552. * @brief Additional Offset Calibration Data
  553. *
  554. * Additional offset calibration data. Contains the rate
  555. * and effective SPAD counts for the MM inner and outer
  556. * calibration steps.
  557. */
  558. typedef struct {
  559. uint16_t result__mm_inner_actual_effective_spads;
  560. /*!< MM Inner actual effective SPADs, 8.8 format */
  561. uint16_t result__mm_outer_actual_effective_spads;
  562. /*!< MM Outer actual effective SPADs, 8.8 format */
  563. uint16_t result__mm_inner_peak_signal_count_rtn_mcps;
  564. /*!< Mean value of MM Inner return peak rate in [Mcps], 9.7 format */
  565. uint16_t result__mm_outer_peak_signal_count_rtn_mcps;
  566. /*!< Mean value of MM Outer return peak rate in [Mcps], 9.7 format */
  567. } VL53L1_additional_offset_cal_data_t;
  568. /**
  569. * @struct VL53L1_cal_peak_rate_map_t
  570. * @brief Structure for storing the calibration peak rate map
  571. * Used by DMAX to understand the spatial roll off
  572. * in the signal rate map towards the corner of the
  573. * SPAD array.
  574. */
  575. typedef struct {
  576. int16_t cal_distance_mm;
  577. /*!< calibration distance in [mm], 14.2 format */
  578. uint16_t max_samples;
  579. /*!< Array size for rate map i.e. max number samples */
  580. uint16_t width;
  581. /*!< Array width */
  582. uint16_t height;
  583. /*!< Array height */
  584. uint16_t peak_rate_mcps[VL53L1_NVM_PEAK_RATE_MAP_SAMPLES];
  585. /*!< Array of rate map samples */
  586. } VL53L1_cal_peak_rate_map_t;
  587. /**
  588. * @struct VL53L1_gain_calibration_data_t
  589. *
  590. * @brief Gain calibration data
  591. *
  592. */
  593. typedef struct {
  594. uint16_t standard_ranging_gain_factor;
  595. /*!< Standard ranging gain correction factor 1.11 format */
  596. } VL53L1_gain_calibration_data_t;
  597. /**
  598. * @struct VL53L1_ll_driver_state_t
  599. *
  600. * @brief Contains the driver state information
  601. *
  602. */
  603. typedef struct {
  604. VL53L1_DeviceState cfg_device_state;
  605. /*!< Configuration Device State */
  606. uint8_t cfg_stream_count;
  607. /*!< configuration stream count, becomes expected
  608. stream count for zone */
  609. uint8_t cfg_gph_id;
  610. /*!< Config Grouped Parameter Hold ID */
  611. uint8_t cfg_timing_status;
  612. /*!< Timing A or B flag 0 = A, 1 = B */
  613. VL53L1_DeviceState rd_device_state;
  614. /*!< Read Device State */
  615. uint8_t rd_stream_count;
  616. /*!< rd stream count, used to check actual stream count */
  617. uint8_t rd_gph_id;
  618. /*!< Read Grouped Parameter Hold ID */
  619. uint8_t rd_timing_status;
  620. /*!< Timing A or B flag 0 = A, 1 = B */
  621. } VL53L1_ll_driver_state_t;
  622. /** @brief Run Offset Cal Function (offsetcal) Config
  623. */
  624. typedef struct {
  625. uint16_t dss_config__target_total_rate_mcps;
  626. /*!< DSS Target rate in MCPS (9.7 format) used \
  627. * during run_offset_calibration() */
  628. uint32_t phasecal_config_timeout_us;
  629. /*!< Phasecal timeout in us \
  630. * used during run_offset_calibration() */
  631. uint32_t range_config_timeout_us;
  632. /*!< Range timeout in us used during \
  633. * run_offset_calibration() */
  634. uint32_t mm_config_timeout_us;
  635. /*!< MM timeout in us used during \
  636. * run_offset_calibration() \
  637. * Added as part of Patch_AddedOffsetCalMMTuningParm_11791 */
  638. uint8_t pre_num_of_samples;
  639. /*!< Number of Ranging samples used during \
  640. * run_offset_calibration() */
  641. uint8_t mm1_num_of_samples;
  642. /*!< Number of MM1 samples used during \
  643. * run_offset_calibration() */
  644. uint8_t mm2_num_of_samples;
  645. /*!< Number of MM2 samples used during \
  646. * run_offset_calibration() */
  647. } VL53L1_offsetcal_config_t;
  648. /**
  649. * @struct VL53L1_LLDriverData_t
  650. *
  651. * @brief VL53L1 LL Driver ST private data structure \n
  652. *
  653. */
  654. typedef struct {
  655. uint8_t wait_method;
  656. /*!< Wait type : blocking or non blocking */
  657. VL53L1_DevicePresetModes preset_mode;
  658. /*!< Current preset mode */
  659. VL53L1_DeviceMeasurementModes measurement_mode;
  660. /*!< Current measurement mode */
  661. VL53L1_OffsetCalibrationMode offset_calibration_mode;
  662. /*!< Current offset calibration mode */
  663. VL53L1_OffsetCorrectionMode offset_correction_mode;
  664. /*!< Current offset_ correction mode */
  665. uint32_t phasecal_config_timeout_us;
  666. /*!< requested Phase Cal Timeout e.g. 1000us */
  667. uint32_t mm_config_timeout_us;
  668. /*!< requested MM Timeout e.g. 2000us */
  669. uint32_t range_config_timeout_us;
  670. /*!< requested Ranging Timeout e.g 13000us */
  671. uint32_t inter_measurement_period_ms;
  672. /*!< requested Timing mode repeat period e.g 100ms */
  673. uint16_t dss_config__target_total_rate_mcps;
  674. /*!< requested DSS Target Total Rate in 9.7 format e.g. 40.0Mcps
  675. * - Patch_ChangingPresetModeInputParms_11780 */
  676. uint32_t fw_ready_poll_duration_ms;
  677. /*!< FW ready poll duration in ms*/
  678. uint8_t fw_ready;
  679. /*!< Result of FW ready check */
  680. uint8_t debug_mode;
  681. /*!< Internal Only - read extra debug data */
  682. /*!< version info structure */
  683. VL53L1_ll_version_t version;
  684. /*!< version info structure */
  685. VL53L1_ll_driver_state_t ll_state;
  686. /*!< decoded GPIO interrupt config */
  687. VL53L1_GPIO_interrupt_config_t gpio_interrupt_config;
  688. /*!< public register data structures */
  689. VL53L1_customer_nvm_managed_t customer;
  690. VL53L1_cal_peak_rate_map_t cal_peak_rate_map;
  691. VL53L1_additional_offset_cal_data_t add_off_cal_data;
  692. VL53L1_gain_calibration_data_t gain_cal;
  693. VL53L1_user_zone_t mm_roi;
  694. VL53L1_optical_centre_t optical_centre;
  695. /*!< tuning parameter storage */
  696. VL53L1_tuning_parm_storage_t tuning_parms;
  697. /*!< private return good SPAD map */
  698. uint8_t rtn_good_spads[VL53L1_RTN_SPAD_BUFFER_SIZE];
  699. /*!< private internal configuration structures */
  700. VL53L1_refspadchar_config_t refspadchar;
  701. VL53L1_ssc_config_t ssc_cfg;
  702. VL53L1_xtalk_config_t xtalk_cfg;
  703. VL53L1_offsetcal_config_t offsetcal_cfg;
  704. /*!< private internal register data structures */
  705. VL53L1_static_nvm_managed_t stat_nvm;
  706. VL53L1_static_config_t stat_cfg;
  707. VL53L1_general_config_t gen_cfg;
  708. VL53L1_timing_config_t tim_cfg;
  709. VL53L1_dynamic_config_t dyn_cfg;
  710. VL53L1_system_control_t sys_ctrl;
  711. VL53L1_system_results_t sys_results;
  712. VL53L1_nvm_copy_data_t nvm_copy_data;
  713. /*!< Private Offset structure */
  714. VL53L1_offset_range_results_t offset_results;
  715. /*!< private debug register data structures */
  716. VL53L1_core_results_t core_results;
  717. VL53L1_debug_results_t dbg_results;
  718. /* Start Patch_LowPowerAutoMode */
  719. /*!< Low Powr Auto Mode Data */
  720. VL53L1_low_power_auto_data_t low_power_auto_data;
  721. /* End Patch_LowPowerAutoMode */
  722. #ifdef PAL_EXTENDED
  723. /* Patch Debug Data */
  724. VL53L1_patch_results_t patch_results;
  725. VL53L1_shadow_core_results_t shadow_core_results;
  726. VL53L1_shadow_system_results_t shadow_sys_results;
  727. VL53L1_prev_shadow_core_results_t prev_shadow_core_results;
  728. VL53L1_prev_shadow_system_results_t prev_shadow_sys_results;
  729. #endif
  730. } VL53L1_LLDriverData_t;
  731. /**
  732. * @struct VL53L1_LLDriverResults_t
  733. *
  734. * @brief VL53L1 LL Driver ST private results structure
  735. *
  736. */
  737. typedef struct {
  738. /* Private last range results */
  739. VL53L1_range_results_t range_results;
  740. } VL53L1_LLDriverResults_t;
  741. /**
  742. * @struct VL53L1_calibration_data_t
  743. *
  744. * @brief Per Part calibration data
  745. *
  746. */
  747. typedef struct {
  748. uint32_t struct_version;
  749. VL53L1_customer_nvm_managed_t customer;
  750. VL53L1_additional_offset_cal_data_t add_off_cal_data;
  751. VL53L1_optical_centre_t optical_centre;
  752. VL53L1_gain_calibration_data_t gain_cal;
  753. VL53L1_cal_peak_rate_map_t cal_peak_rate_map;
  754. } VL53L1_calibration_data_t;
  755. /**
  756. * @struct VL53L1_tuning_parameters_t
  757. *
  758. * @brief Tuning Parameters Debug data
  759. *
  760. */
  761. typedef struct {
  762. uint16_t vl53l1_tuningparm_version;
  763. uint16_t vl53l1_tuningparm_key_table_version;
  764. uint16_t vl53l1_tuningparm_lld_version;
  765. uint8_t vl53l1_tuningparm_consistency_lite_phase_tolerance;
  766. uint8_t vl53l1_tuningparm_phasecal_target;
  767. uint16_t vl53l1_tuningparm_lite_cal_repeat_rate;
  768. uint16_t vl53l1_tuningparm_lite_ranging_gain_factor;
  769. uint8_t vl53l1_tuningparm_lite_min_clip_mm;
  770. uint16_t vl53l1_tuningparm_lite_long_sigma_thresh_mm;
  771. uint16_t vl53l1_tuningparm_lite_med_sigma_thresh_mm;
  772. uint16_t vl53l1_tuningparm_lite_short_sigma_thresh_mm;
  773. uint16_t vl53l1_tuningparm_lite_long_min_count_rate_rtn_mcps;
  774. uint16_t vl53l1_tuningparm_lite_med_min_count_rate_rtn_mcps;
  775. uint16_t vl53l1_tuningparm_lite_short_min_count_rate_rtn_mcps;
  776. uint8_t vl53l1_tuningparm_lite_sigma_est_pulse_width;
  777. uint8_t vl53l1_tuningparm_lite_sigma_est_amb_width_ns;
  778. uint8_t vl53l1_tuningparm_lite_sigma_ref_mm;
  779. uint8_t vl53l1_tuningparm_lite_rit_mult;
  780. uint8_t vl53l1_tuningparm_lite_seed_config;
  781. uint8_t vl53l1_tuningparm_lite_quantifier;
  782. uint8_t vl53l1_tuningparm_lite_first_order_select;
  783. int16_t vl53l1_tuningparm_lite_xtalk_margin_kcps;
  784. uint8_t vl53l1_tuningparm_initial_phase_rtn_lite_long_range;
  785. uint8_t vl53l1_tuningparm_initial_phase_rtn_lite_med_range;
  786. uint8_t vl53l1_tuningparm_initial_phase_rtn_lite_short_range;
  787. uint8_t vl53l1_tuningparm_initial_phase_ref_lite_long_range;
  788. uint8_t vl53l1_tuningparm_initial_phase_ref_lite_med_range;
  789. uint8_t vl53l1_tuningparm_initial_phase_ref_lite_short_range;
  790. uint8_t vl53l1_tuningparm_timed_seed_config;
  791. uint8_t vl53l1_tuningparm_vhv_loopbound;
  792. uint8_t vl53l1_tuningparm_refspadchar_device_test_mode;
  793. uint8_t vl53l1_tuningparm_refspadchar_vcsel_period;
  794. uint32_t vl53l1_tuningparm_refspadchar_phasecal_timeout_us;
  795. uint16_t vl53l1_tuningparm_refspadchar_target_count_rate_mcps;
  796. uint16_t vl53l1_tuningparm_refspadchar_min_countrate_limit_mcps;
  797. uint16_t vl53l1_tuningparm_refspadchar_max_countrate_limit_mcps;
  798. uint16_t vl53l1_tuningparm_offset_cal_dss_rate_mcps;
  799. uint32_t vl53l1_tuningparm_offset_cal_phasecal_timeout_us;
  800. uint32_t vl53l1_tuningparm_offset_cal_mm_timeout_us;
  801. uint32_t vl53l1_tuningparm_offset_cal_range_timeout_us;
  802. uint8_t vl53l1_tuningparm_offset_cal_pre_samples;
  803. uint8_t vl53l1_tuningparm_offset_cal_mm1_samples;
  804. uint8_t vl53l1_tuningparm_offset_cal_mm2_samples;
  805. uint8_t vl53l1_tuningparm_spadmap_vcsel_period;
  806. uint8_t vl53l1_tuningparm_spadmap_vcsel_start;
  807. uint16_t vl53l1_tuningparm_spadmap_rate_limit_mcps;
  808. uint16_t vl53l1_tuningparm_lite_dss_config_target_total_rate_mcps;
  809. uint16_t vl53l1_tuningparm_timed_dss_config_target_total_rate_mcps;
  810. uint32_t vl53l1_tuningparm_lite_phasecal_config_timeout_us;
  811. uint32_t vl53l1_tuningparm_timed_phasecal_config_timeout_us;
  812. uint32_t vl53l1_tuningparm_lite_mm_config_timeout_us;
  813. uint32_t vl53l1_tuningparm_timed_mm_config_timeout_us;
  814. uint32_t vl53l1_tuningparm_lite_range_config_timeout_us;
  815. uint32_t vl53l1_tuningparm_timed_range_config_timeout_us;
  816. uint8_t vl53l1_tuningparm_lowpowerauto_vhv_loop_bound;
  817. uint32_t vl53l1_tuningparm_lowpowerauto_mm_config_timeout_us;
  818. uint32_t vl53l1_tuningparm_lowpowerauto_range_config_timeout_us;
  819. } VL53L1_tuning_parameters_t;
  820. /**
  821. * @struct VL53L1_spad_rate_data_t
  822. * @brief SPAD Rate Data output by SSC
  823. *
  824. * Container for the SPAD Rate data output by SPAD select check (SSC)
  825. * The data is stored in the buffer in SPAD number order and not
  826. * raster order
  827. *
  828. * Rate data is it either 1.15 or 9.7 fixed point format
  829. */
  830. typedef struct {
  831. uint8_t spad_type;
  832. /*!< Type of rate data stored */
  833. uint16_t buffer_size;
  834. /*!< SPAD buffer size : should be at least 256 for EwokPlus25 */
  835. uint16_t rate_data[VL53L1_NO_OF_SPAD_ENABLES];
  836. /*!< word buffer containing the SPAD rates */
  837. uint16_t no_of_values;
  838. /*!< Number of bytes used in the buffer */
  839. uint8_t fractional_bits;
  840. /*!< Number of fractional bits either 7 or 15 */
  841. uint8_t error_status;
  842. /*!< Set if supplied buffer is too small */
  843. } VL53L1_spad_rate_data_t;
  844. /* Start Patch_AdditionalDebugData_11823 */
  845. /**
  846. * @struct VL53L1_additional_data_t
  847. * @brief Additional debug data
  848. *
  849. * Contains the LL Driver configuration information
  850. */
  851. typedef struct {
  852. VL53L1_DevicePresetModes preset_mode;
  853. /*!< Current preset mode */
  854. VL53L1_DeviceMeasurementModes measurement_mode;
  855. /*!< Current measurement mode */
  856. uint32_t phasecal_config_timeout_us;
  857. /*!< requested Phase Cal Timeout e.g. 1000us */
  858. uint32_t mm_config_timeout_us;
  859. /*!< requested MM Timeout e.g. 2000us */
  860. uint32_t range_config_timeout_us;
  861. /*!< requested Ranging Timeout e.g 13000us */
  862. uint32_t inter_measurement_period_ms;
  863. /*!< requested Timing mode repeat period e.g 100ms */
  864. uint16_t dss_config__target_total_rate_mcps;
  865. /*!< requested DSS Target Total Rate in 9.7 format e.g. 40.0Mcps*/
  866. } VL53L1_additional_data_t;
  867. /* End Patch_AdditionalDebugData_11823 */
  868. /** @} VL53L1_globalLLDriverDefine_group */
  869. #define SUPPRESS_UNUSED_WARNING(x) \
  870. ((void) (x))
  871. #define IGNORE_STATUS(__FUNCTION_ID__, __ERROR_STATUS_CHECK__, __STATUS__) \
  872. do { \
  873. DISABLE_WARNINGS(); \
  874. if (__FUNCTION_ID__) { \
  875. if (__STATUS__ == __ERROR_STATUS_CHECK__) { \
  876. __STATUS__ = VL53L1_ERROR_NONE; \
  877. WARN_OVERRIDE_STATUS(__FUNCTION_ID__); \
  878. } \
  879. } \
  880. ENABLE_WARNINGS(); \
  881. } \
  882. while (0)
  883. #define VL53L1_COPYSTRING(str, ...) \
  884. (strncpy(str, ##__VA_ARGS__, VL53L1_MAX_STRING_LENGTH-1))
  885. #ifdef __cplusplus
  886. }
  887. #endif
  888. #endif /* _VL53L1_LL_DEF_H_ */