1+ /**
2+ *
3+ * Copyright (c) 2021 STMicroelectronics.
4+ * All rights reserved.
5+ *
6+ *
7+ * This software component is provided to you as part of a software package and
8+ * applicable license terms are in the Package_license file. If you received this
9+ * software component outside of a package or without applicable license terms,
10+ * the terms of the BSD-3-Clause license shall apply.
11+ * You may obtain a copy of the BSD-3-Clause at:
12+ * https://opensource.org/licenses/BSD-3-Clause
13+ *
14+ ******************************************************************************
15+ */
16+
17+ #ifndef VL53_PLATFORM_H_
18+ #define VL53_PLATFORM_H_
19+ #pragma once
20+
21+ #if __has_include ("modm_config_vl53.h" )
22+ #include "modm_config_vl53.h"
23+ #endif
24+
25+ #include <stdint.h>
26+ #include <string.h>
27+
28+ /*
29+ * @brief The macro below is used to define the number of target per zone sent
30+ * through I2C. This value can be changed by user, in order to tune I2C
31+ * transaction, and also the total memory size (a lower number of target per
32+ * zone means a lower RAM). The value must be between 1 and 4.
33+ */
34+
35+ #define VL53L5CX_NB_TARGET_PER_ZONE 1U
36+
37+ /*
38+ * @brief The macro below can be used to avoid data conversion into the driver.
39+ * By default there is a conversion between firmware and user data. Using this macro
40+ * allows to use the firmware format instead of user format. The firmware format allows
41+ * an increased precision.
42+ */
43+
44+ // #define VL53L5CX_USE_RAW_FORMAT
45+
46+ /*
47+ * @brief All macro below are used to configure the sensor output. User can
48+ * define some macros if he wants to disable selected output, in order to reduce
49+ * I2C access.
50+ */
51+
52+ // #define VL53L5CX_DISABLE_AMBIENT_PER_SPAD
53+ // #define VL53L5CX_DISABLE_NB_SPADS_ENABLED
54+ // #define VL53L5CX_DISABLE_NB_TARGET_DETECTED
55+ // #define VL53L5CX_DISABLE_SIGNAL_PER_SPAD
56+ // #define VL53L5CX_DISABLE_RANGE_SIGMA_MM
57+ // #define VL53L5CX_DISABLE_DISTANCE_MM
58+ // #define VL53L5CX_DISABLE_REFLECTANCE_PERCENT
59+ // #define VL53L5CX_DISABLE_TARGET_STATUS
60+ // #define VL53L5CX_DISABLE_MOTION_INDICATOR
61+
62+ /*
63+ * @brief The macro below is used to define the number of target per zone sent
64+ * through I2C. This value can be changed by user, in order to tune I2C
65+ * transaction, and also the total memory size (a lower number of target per
66+ * zone means a lower RAM usage).
67+ */
68+
69+ #define VL53LMZ_NB_TARGET_PER_ZONE 1
70+
71+ /*
72+ * @brief All macro below are used to configure the sensor output. User can
73+ * define some macros if he wants to disable selected output, in order to reduce
74+ * I2C access.
75+ */
76+
77+ // #define VL53LMZ_DISABLE_AMBIENT_PER_SPAD
78+ // #define VL53LMZ_DISABLE_NB_SPADS_ENABLED
79+ // #define VL53LMZ_DISABLE_NB_TARGET_DETECTED
80+ // #define VL53LMZ_DISABLE_SIGNAL_PER_SPAD
81+ // #define VL53LMZ_DISABLE_RANGE_SIGMA_MM
82+ // #define VL53LMZ_DISABLE_DISTANCE_MM
83+ // #define VL53LMZ_DISABLE_REFLECTANCE_PERCENT
84+ // #define VL53LMZ_DISABLE_TARGET_STATUS
85+ // #define VL53LMZ_DISABLE_SCI
86+
87+ /**
88+ * @brief Structure VL53_Platform needs to be filled by the customer,
89+ * depending on his platform. At least, it contains the VL53 I2C address.
90+ * Some additional fields can be added, as descriptors, or platform
91+ * dependencies. Anything added into this structure is visible into the platform
92+ * layer.
93+ */
94+
95+ typedef struct
96+ {
97+ /* To be filled with customer's platform. At least an I2C address/descriptor
98+ * needs to be added */
99+ /* Example for most standard platform : I2C address of sensor */
100+ uint16_t address ;
101+
102+ void * transport ;
103+
104+ } VL53_Platform ;
105+
106+ /*
107+ * @brief The macro below is used to define the number of target per zone sent
108+ * through I2C. This value can be changed by user, in order to tune I2C
109+ * transaction, and also the total memory size (a lower number of target per
110+ * zone means a lower RAM). The value must be between 1 and 4.
111+ */
112+
113+ #define VL53_NB_TARGET_PER_ZONE 1U
114+
115+ /*
116+ * @brief The macro below can be used to avoid data conversion into the driver.
117+ * By default there is a conversion between firmware and user data. Using this macro
118+ * allows to use the firmware format instead of user format. The firmware format allows
119+ * an increased precision.
120+ */
121+
122+ // #define VL53_USE_RAW_FORMAT
123+
124+ /*
125+ * @brief All macro below are used to configure the sensor output. User can
126+ * define some macros if he wants to disable selected output, in order to reduce
127+ * I2C access.
128+ */
129+
130+ // #define VL53_DISABLE_AMBIENT_PER_SPAD
131+ // #define VL53_DISABLE_NB_SPADS_ENABLED
132+ // #define VL53_DISABLE_NB_TARGET_DETECTED
133+ // #define VL53_DISABLE_SIGNAL_PER_SPAD
134+ // #define VL53_DISABLE_RANGE_SIGMA_MM
135+ // #define VL53_DISABLE_DISTANCE_MM
136+ // #define VL53_DISABLE_REFLECTANCE_PERCENT
137+ // #define VL53_DISABLE_TARGET_STATUS
138+ // #define VL53_DISABLE_MOTION_INDICATOR
139+
140+ /**
141+ * @param (VL53_Platform*) p_platform : Pointer of VL53 platform
142+ * structure.
143+ * @param (uint16_t) Address : I2C location of value to read.
144+ * @param (uint8_t) *p_values : Pointer of value to read.
145+ * @return (uint8_t) status : 0 if OK
146+ */
147+
148+ uint8_t
149+ VL53_RdByte (VL53_Platform * p_platform , uint16_t RegisterAdress , uint8_t * p_value );
150+
151+ /**
152+ * @brief Mandatory function used to write one single byte.
153+ * @param (VL53_Platform*) p_platform : Pointer of VL53 platform
154+ * structure.
155+ * @param (uint16_t) Address : I2C location of value to read.
156+ * @param (uint8_t) value : Pointer of value to write.
157+ * @return (uint8_t) status : 0 if OK
158+ */
159+
160+ uint8_t
161+ VL53_WrByte (VL53_Platform * p_platform , uint16_t RegisterAdress , uint8_t value );
162+
163+ /**
164+ * @brief Mandatory function used to read multiples bytes.
165+ * @param (VL53_Platform*) p_platform : Pointer of VL53 platform
166+ * structure.
167+ * @param (uint16_t) Address : I2C location of values to read.
168+ * @param (uint8_t) *p_values : Buffer of bytes to read.
169+ * @param (uint32_t) size : Size of *p_values buffer.
170+ * @return (uint8_t) status : 0 if OK
171+ */
172+
173+ uint8_t
174+ VL53_RdMulti (VL53_Platform * p_platform , uint16_t RegisterAdress , uint8_t * p_values , uint32_t size );
175+
176+ /**
177+ * @brief Mandatory function used to write multiples bytes.
178+ * @param (VL53_Platform*) p_platform : Pointer of VL53 platform
179+ * structure.
180+ * @param (uint16_t) Address : I2C location of values to write.
181+ * @param (uint8_t) *p_values : Buffer of bytes to write.
182+ * @param (uint32_t) size : Size of *p_values buffer.
183+ * @return (uint8_t) status : 0 if OK
184+ */
185+
186+ uint8_t
187+ VL53_WrMulti (VL53_Platform * p_platform , uint16_t RegisterAdress , uint8_t * p_values , uint32_t size );
188+
189+ /**
190+ * @brief Optional function, only used to perform an hardware reset of the
191+ * sensor. This function is not used in the API, but it can be used by the host.
192+ * This function is not mandatory to fill if user don't want to reset the
193+ * sensor.
194+ * @param (VL53_Platform*) p_platform : Pointer of VL53 platform
195+ * structure.
196+ * @return (uint8_t) status : 0 if OK
197+ */
198+
199+ uint8_t
200+ VL53_Reset_Sensor (VL53_Platform * p_platform );
201+
202+ /**
203+ * @brief Mandatory function, used to swap a buffer. The buffer size is always a
204+ * multiple of 4 (4, 8, 12, 16, ...).
205+ * @param (uint8_t*) buffer : Buffer to swap, generally uint32_t
206+ * @param (uint16_t) size : Buffer size to swap
207+ */
208+
209+ void
210+ VL53_SwapBuffer (uint8_t * buffer , uint16_t size );
211+ /**
212+ * @brief Mandatory function, used to wait during an amount of time. It must be
213+ * filled as it's used into the API.
214+ * @param (VL53_Platform*) p_platform : Pointer of VL53 platform
215+ * structure.
216+ * @param (uint32_t) TimeMs : Time to wait in ms.
217+ * @return (uint8_t) status : 0 if wait is finished.
218+ */
219+
220+ uint8_t
221+ VL53_WaitMs (VL53_Platform * p_platform , uint32_t TimeMs );
222+
223+ #endif // _PLATFORM_H_
0 commit comments