vl53l1_api_calibration.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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_api_core.h
  64. *
  65. * @brief EwokPlus25 low level API function definitions
  66. */
  67. #ifndef _VL53L1_API_CALIBRATION_H_
  68. #define _VL53L1_API_CALIBRATION_H_
  69. #include "vl53l1_platform.h"
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73. /**
  74. * @brief Run Reference Array SPAD Characterisation.
  75. *
  76. * This function finds the required number of reference SPAD
  77. * to meet the input required peak reference rate.
  78. *
  79. * The algorithm first tries the non apertured reference SPAD's,
  80. * if the rate is too high for the minimum allowed SPAD count (5)
  81. * then the algo switches to 5x apertured SPAD's and if the rate
  82. * is still to high then the 10x apertured SPAD are selected.
  83. *
  84. * The function reads the following results from the device and
  85. * both caches the values in the pdev->customer structure and
  86. * writes the data into the G02 customer register group.
  87. *
  88. * - num_ref_spads
  89. * - ref_location
  90. * - DCR SPAD enables for selected reference location
  91. *
  92. * Note power force is enabled as the function needs to read
  93. * data from the Patch RAM.
  94. *
  95. * Should only be called once per part with coverglass attached to
  96. * generate the required num of SPAD, Ref location and DCR SPAD enable
  97. * data
  98. *
  99. * @param[in] Dev : Device Handle
  100. * @param[out] pcal_status : Pointer to unfiltered calibration status
  101. *
  102. * @return VL53L1_ERROR_NONE Success
  103. * @return VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS
  104. * Less than 5 Good SPAD available, output not valid
  105. * @return VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH
  106. * At end of search reference rate > 40.0 Mcps
  107. * Offset stability may be degraded.
  108. * @return VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW
  109. * At end of search reference rate < 10.0 Mcps
  110. * Offset stability may be degraded.
  111. *
  112. */
  113. #ifndef VL53L1_NOCALIB
  114. VL53L1_Error VL53L1_run_ref_spad_char(VL53L1_DEV Dev, VL53L1_Error *pcal_status);
  115. #endif
  116. /**
  117. * @brief Runs the input Device Test
  118. *
  119. * Calls
  120. *
  121. * - VL53L1_enable_powerforce()
  122. * - VL53L1_start_test()
  123. * - VL53L1_poll_for_range_completion()
  124. *
  125. * @param[in] Dev : Device handle
  126. * @param[in] device_test_mode : Device test mode register value
  127. *
  128. * @return VL53L1_ERROR_NONE Success
  129. * @return "Other error code" See ::VL53L1_Error
  130. */
  131. #ifndef VL53L1_NOCALIB
  132. VL53L1_Error VL53L1_run_device_test(
  133. VL53L1_DEV Dev,
  134. VL53L1_DeviceTestMode device_test_mode);
  135. #endif
  136. /**
  137. * @brief Runs SPAD rate map
  138. *
  139. * Output structure contains SPAD rate data in SPAD number order
  140. *
  141. * @param[in] Dev : Device handle
  142. * @param[in] device_test_mode : Device test mode register value.
  143. * Valid options: \n
  144. * - VL53L1_DEVICETESTMODE_LCR_VCSEL_OFF \n
  145. * - VL53L1_DEVICETESTMODE_LCR_VCSEL_ON
  146. * @param[in] array_select : Device SPAD array select
  147. * Valid options: \n
  148. * - VL53L1_DEVICESSCARRAY_RTN \n
  149. * - VL53L1_DEVICESSCARRAY_REF
  150. * @param[in] ssc_config_timeout_us : SSC timeout in [us] e.g 36000us
  151. * @param[out] pspad_rate_data : pointer to output rates structure
  152. * 1.15 format for LCR_VCSEL_OFF
  153. * 9.7 format for LCR_VCSEL_ON
  154. *
  155. * @return VL53L1_ERROR_NONE Success
  156. * @return "Other error code" See ::VL53L1_Error
  157. */
  158. #ifndef VL53L1_NOCALIB
  159. VL53L1_Error VL53L1_run_spad_rate_map(
  160. VL53L1_DEV Dev,
  161. VL53L1_DeviceTestMode device_test_mode,
  162. VL53L1_DeviceSscArray array_select,
  163. uint32_t ssc_config_timeout_us,
  164. VL53L1_spad_rate_data_t *pspad_rate_data);
  165. #endif
  166. /**
  167. * @brief Run offset calibration
  168. *
  169. * Runs the standard ranging MM1 and MM2 calibration presets
  170. * to generate the MM1 and MM2 range offset data
  171. *
  172. * The range config timeout is used for both MM1 and MM2 so that
  173. * the sigma delta settling is the same as for the 'real' range
  174. *
  175. * Places results into VL53L1_customer_nvm_managed_t within pdev
  176. *
  177. * Use VL53L1_get_part_to_part_data() to get the offset calibration
  178. * results
  179. *
  180. * Current FMT settings:
  181. *
  182. * - offset_calibration_mode = VL53L1_OFFSETCALIBRATIONMODE__STANDARD_RANGING
  183. * - dss_config__target_total_rate_mcps = 0x0A00 (20.0Mcps) to 0x1400 (40.0Mcps)
  184. * - phasecal_config_timeout_us = 1000
  185. * - range_config_timeout_us = 13000
  186. * - pre_num_of_samples = 32
  187. * - mm1_num_of_samples = 100
  188. * - mm2_range_num_of_samples = 64
  189. * - target_distance_mm = 140 mm
  190. * - target reflectance = 5%
  191. *
  192. * Note: function parms simplified as part of Patch_CalFunctionSimplification_11791
  193. *
  194. * @param[in] Dev : Device handle
  195. * @param[in] cal_distance_mm : Distance to target in [mm] - the ground truth
  196. * @param[out] pcal_status : Pointer to unfiltered calibration status
  197. *
  198. * @return VL53L1_ERROR_NONE Success
  199. * @return VL53L1_WARNING_OFFSET_CAL_INSUFFICIENT_MM1_SPADS
  200. * Effective MM1 SPAD count too low (<5.0).
  201. * Out with recommended calibration condition.
  202. * Accuracy of offset calibration may be degraded.
  203. * @return VL53L1_WARNING_OFFSET_CAL_PRE_RANGE_RATE_TOO_HIGH
  204. * Pre range too high (>40.0) in pile up region.
  205. * Out with recommended calibration condition.
  206. * Accuracy of offset calibration may be degraded.
  207. */
  208. #ifndef VL53L1_NOCALIB
  209. VL53L1_Error VL53L1_run_offset_calibration(
  210. VL53L1_DEV Dev,
  211. int16_t cal_distance_mm,
  212. VL53L1_Error *pcal_status);
  213. #endif
  214. #ifdef __cplusplus
  215. }
  216. #endif
  217. #endif /* _VL53L1_API_CALIBRATION_H_ */