lightranger9  2.0.0.0
lightranger9.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef LIGHTRANGER9_H
29 #define LIGHTRANGER9_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
74 #define LIGHTRANGER9_REG_APPID 0x00
75 #define LIGHTRANGER9_REG_MINOR 0x01
76 #define LIGHTRANGER9_REG_ENABLE 0xE0
77 #define LIGHTRANGER9_REG_INT_STATUS 0xE1
78 #define LIGHTRANGER9_REG_INT_ENAB 0xE2
79 #define LIGHTRANGER9_REG_ID 0xE3
80 #define LIGHTRANGER9_REG_REVID 0xE4
81 
87 #define LIGHTRANGER9_REG_PATCH 0x02
88 #define LIGHTRANGER9_REG_BUILD_TYPE 0x03
89 #define LIGHTRANGER9_REG_APPLICATION_STATUS 0x04
90 #define LIGHTRANGER9_REG_MEASURE_STATUS 0x05
91 #define LIGHTRANGER9_REG_ALGORITHM_STATUS 0x06
92 #define LIGHTRANGER9_REG_CALIBRATION_STATUS 0x07
93 #define LIGHTRANGER9_REG_CMD_STAT 0x08
94 #define LIGHTRANGER9_REG_PREV_CMD 0x09
95 #define LIGHTRANGER9_REG_MODE 0x10
96 #define LIGHTRANGER9_REG_LIVE_BEAT 0x0A
97 #define LIGHTRANGER9_REG_ACTIVE_RANGE 0x19
98 #define LIGHTRANGER9_REG_SERIAL_NUMBER_0 0x1C
99 #define LIGHTRANGER9_REG_SERIAL_NUMBER_1 0x1D
100 #define LIGHTRANGER9_REG_SERIAL_NUMBER_2 0x1E
101 #define LIGHTRANGER9_REG_SERIAL_NUMBER_3 0x1F
102 #define LIGHTRANGER9_REG_CONFIG_RESULT 0x20
103 #define LIGHTRANGER9_REG_TID 0x21
104 #define LIGHTRANGER9_REG_SIZE_LSB 0x22
105 #define LIGHTRANGER9_REG_SIZE_MSB 0x23
106 
112 #define LIGHTRANGER9_REG_BLOCKREAD 0x20
113 #define LIGHTRANGER9_REG_RESULT_NUMBER 0x24
114 #define LIGHTRANGER9_REG_TEMPERATURE 0x25
115 #define LIGHTRANGER9_REG_NUMBER_VALID_RESULTS 0x26
116 #define LIGHTRANGER9_REG_AMBIENT_LIGHT_0 0x28
117 #define LIGHTRANGER9_REG_AMBIENT_LIGHT_1 0x29
118 #define LIGHTRANGER9_REG_AMBIENT_LIGHT_2 0x2A
119 #define LIGHTRANGER9_REG_AMBIENT_LIGHT_3 0x2B
120 #define LIGHTRANGER9_REG_PHOTON_COUNT_0 0x2C
121 #define LIGHTRANGER9_REG_PHOTON_COUNT_1 0x2D
122 #define LIGHTRANGER9_REG_PHOTON_COUNT_2 0x2E
123 #define LIGHTRANGER9_REG_PHOTON_COUNT_3 0x2F
124 #define LIGHTRANGER9_REG_REFERENCE_COUNT_0 0x30
125 #define LIGHTRANGER9_REG_REFERENCE_COUNT_1 0x31
126 #define LIGHTRANGER9_REG_REFERENCE_COUNT_2 0x32
127 #define LIGHTRANGER9_REG_REFERENCE_COUNT_3 0x33
128 #define LIGHTRANGER9_REG_SYS_TICK_0 0x34
129 #define LIGHTRANGER9_REG_SYS_TICK_1 0x35
130 #define LIGHTRANGER9_REG_SYS_TICK_2 0x36
131 #define LIGHTRANGER9_REG_SYS_TICK_3 0x37
132 #define LIGHTRANGER9_REG_RES_CONFIDENCE_0 0x38
133 #define LIGHTRANGER9_REG_RES_DISTANCE_0_LSB 0x39
134 #define LIGHTRANGER9_REG_RES_DISTANCE_0_MSB 0x3A
135 #define LIGHTRANGER9_REG_RES_CONFIDENCE_1 0x3B
136 #define LIGHTRANGER9_REG_RES_DISTANCE_1_LSB 0x3C
137 #define LIGHTRANGER9_REG_RES_DISTANCE_1_MSB 0x3D
138 #define LIGHTRANGER9_REG_RES_CONFIDENCE_2 0x3E
139 #define LIGHTRANGER9_REG_RES_DISTANCE_2_LSB 0x3F
140 #define LIGHTRANGER9_REG_RES_DISTANCE_2_MSB 0x40
141 #define LIGHTRANGER9_REG_RES_CONFIDENCE_3 0x41
142 #define LIGHTRANGER9_REG_RES_DISTANCE_3_LSB 0x42
143 #define LIGHTRANGER9_REG_RES_DISTANCE_3_MSB 0x43
144 #define LIGHTRANGER9_REG_RES_CONFIDENCE_4 0x44
145 #define LIGHTRANGER9_REG_RES_DISTANCE_4_LSB 0x45
146 #define LIGHTRANGER9_REG_RES_DISTANCE_4_MSB 0x46
147 #define LIGHTRANGER9_REG_RES_CONFIDENCE_5 0x47
148 #define LIGHTRANGER9_REG_RES_DISTANCE_5_LSB 0x48
149 #define LIGHTRANGER9_REG_RES_DISTANCE_5_MSB 0x49
150 #define LIGHTRANGER9_REG_RES_CONFIDENCE_6 0x4A
151 #define LIGHTRANGER9_REG_RES_DISTANCE_6_LSB 0x4B
152 #define LIGHTRANGER9_REG_RES_DISTANCE_6_MSB 0x4C
153 #define LIGHTRANGER9_REG_RES_CONFIDENCE_7 0x4D
154 #define LIGHTRANGER9_REG_RES_DISTANCE_7_LSB 0x4E
155 #define LIGHTRANGER9_REG_RES_DISTANCE_7_MSB 0x4F
156 #define LIGHTRANGER9_REG_RES_CONFIDENCE_8 0x50
157 #define LIGHTRANGER9_REG_RES_DISTANCE_8_LSB 0x51
158 #define LIGHTRANGER9_REG_RES_DISTANCE_8_MSB 0x52
159 #define LIGHTRANGER9_REG_RES_CONFIDENCE_9 0x53
160 #define LIGHTRANGER9_REG_RES_DISTANCE_9_LSB 0x54
161 #define LIGHTRANGER9_REG_RES_DISTANCE_9_MSB 0x55
162 #define LIGHTRANGER9_REG_RES_CONFIDENCE_10 0x56
163 #define LIGHTRANGER9_REG_RES_DISTANCE_10_LSB 0x57
164 #define LIGHTRANGER9_REG_RES_DISTANCE_10_MSB 0x58
165 #define LIGHTRANGER9_REG_RES_CONFIDENCE_11 0x59
166 #define LIGHTRANGER9_REG_RES_DISTANCE_11_LSB 0x5A
167 #define LIGHTRANGER9_REG_RES_DISTANCE_11_MSB 0x5B
168 #define LIGHTRANGER9_REG_RES_CONFIDENCE_12 0x5C
169 #define LIGHTRANGER9_REG_RES_DISTANCE_12_LSB 0x5D
170 #define LIGHTRANGER9_REG_RES_DISTANCE_12_MSB 0x5E
171 #define LIGHTRANGER9_REG_RES_CONFIDENCE_13 0x5F
172 #define LIGHTRANGER9_REG_RES_DISTANCE_13_LSB 0x60
173 #define LIGHTRANGER9_REG_RES_DISTANCE_13_MSB 0x61
174 #define LIGHTRANGER9_REG_RES_CONFIDENCE_14 0x62
175 #define LIGHTRANGER9_REG_RES_DISTANCE_14_LSB 0x63
176 #define LIGHTRANGER9_REG_RES_DISTANCE_14_MSB 0x64
177 #define LIGHTRANGER9_REG_RES_CONFIDENCE_15 0x65
178 #define LIGHTRANGER9_REG_RES_DISTANCE_15_LSB 0x66
179 #define LIGHTRANGER9_REG_RES_DISTANCE_15_MSB 0x67
180 #define LIGHTRANGER9_REG_RES_CONFIDENCE_16 0x68
181 #define LIGHTRANGER9_REG_RES_DISTANCE_16_LSB 0x69
182 #define LIGHTRANGER9_REG_RES_DISTANCE_16_MSB 0x6A
183 #define LIGHTRANGER9_REG_RES_CONFIDENCE_17 0x6B
184 #define LIGHTRANGER9_REG_RES_DISTANCE_17_LSB 0x6C
185 #define LIGHTRANGER9_REG_RES_DISTANCE_17_MSB 0x6D
186 #define LIGHTRANGER9_REG_RES_CONFIDENCE_18 0x6E
187 #define LIGHTRANGER9_REG_RES_DISTANCE_18_LSB 0x6F
188 #define LIGHTRANGER9_REG_RES_DISTANCE_18_MSB 0x70
189 #define LIGHTRANGER9_REG_RES_CONFIDENCE_19 0x71
190 #define LIGHTRANGER9_REG_RES_DISTANCE_19_LSB 0x72
191 #define LIGHTRANGER9_REG_RES_DISTANCE_19_MSB 0x73
192 #define LIGHTRANGER9_REG_RES_CONFIDENCE_20 0x74
193 #define LIGHTRANGER9_REG_RES_DISTANCE_20_LSB 0x75
194 #define LIGHTRANGER9_REG_RES_DISTANCE_20_MSB 0x76
195 #define LIGHTRANGER9_REG_RES_CONFIDENCE_21 0x77
196 #define LIGHTRANGER9_REG_RES_DISTANCE_21_LSB 0x78
197 #define LIGHTRANGER9_REG_RES_DISTANCE_21_MSB 0x79
198 #define LIGHTRANGER9_REG_RES_CONFIDENCE_22 0x7A
199 #define LIGHTRANGER9_REG_RES_DISTANCE_22_LSB 0x7B
200 #define LIGHTRANGER9_REG_RES_DISTANCE_22_MSB 0x7C
201 #define LIGHTRANGER9_REG_RES_CONFIDENCE_23 0x7D
202 #define LIGHTRANGER9_REG_RES_DISTANCE_23_LSB 0x7E
203 #define LIGHTRANGER9_REG_RES_DISTANCE_23_MSB 0x7F
204 #define LIGHTRANGER9_REG_RES_CONFIDENCE_24 0x80
205 #define LIGHTRANGER9_REG_RES_DISTANCE_24_LSB 0x81
206 #define LIGHTRANGER9_REG_RES_DISTANCE_24_MSB 0x82
207 #define LIGHTRANGER9_REG_RES_CONFIDENCE_25 0x83
208 #define LIGHTRANGER9_REG_RES_DISTANCE_25_LSB 0x84
209 #define LIGHTRANGER9_REG_RES_DISTANCE_25_MSB 0x85
210 #define LIGHTRANGER9_REG_RES_CONFIDENCE_26 0x86
211 #define LIGHTRANGER9_REG_RES_DISTANCE_26_LSB 0x87
212 #define LIGHTRANGER9_REG_RES_DISTANCE_26_MSB 0x88
213 #define LIGHTRANGER9_REG_RES_CONFIDENCE_27 0x89
214 #define LIGHTRANGER9_REG_RES_DISTANCE_27_LSB 0x8A
215 #define LIGHTRANGER9_REG_RES_DISTANCE_27_MSB 0x8B
216 #define LIGHTRANGER9_REG_RES_CONFIDENCE_28 0x8C
217 #define LIGHTRANGER9_REG_RES_DISTANCE_28_LSB 0x8D
218 #define LIGHTRANGER9_REG_RES_DISTANCE_28_MSB 0x8E
219 #define LIGHTRANGER9_REG_RES_CONFIDENCE_29 0x8F
220 #define LIGHTRANGER9_REG_RES_DISTANCE_29_LSB 0x90
221 #define LIGHTRANGER9_REG_RES_DISTANCE_29_MSB 0x91
222 #define LIGHTRANGER9_REG_RES_CONFIDENCE_30 0x92
223 #define LIGHTRANGER9_REG_RES_DISTANCE_30_LSB 0x93
224 #define LIGHTRANGER9_REG_RES_DISTANCE_30_MSB 0x94
225 #define LIGHTRANGER9_REG_RES_CONFIDENCE_31 0x95
226 #define LIGHTRANGER9_REG_RES_DISTANCE_31_LSB 0x96
227 #define LIGHTRANGER9_REG_RES_DISTANCE_31_MSB 0x97
228 #define LIGHTRANGER9_REG_RES_CONFIDENCE_32 0x98
229 #define LIGHTRANGER9_REG_RES_DISTANCE_32_LSB 0x99
230 #define LIGHTRANGER9_REG_RES_DISTANCE_32_MSB 0x9A
231 #define LIGHTRANGER9_REG_RES_CONFIDENCE_33 0x9B
232 #define LIGHTRANGER9_REG_RES_DISTANCE_33_LSB 0x9C
233 #define LIGHTRANGER9_REG_RES_DISTANCE_33_MSB 0x9D
234 #define LIGHTRANGER9_REG_RES_CONFIDENCE_34 0x9E
235 #define LIGHTRANGER9_REG_RES_DISTANCE_34_LSB 0x9F
236 #define LIGHTRANGER9_REG_RES_DISTANCE_34_MSB 0xA0
237 #define LIGHTRANGER9_REG_RES_CONFIDENCE_35 0xA1
238 #define LIGHTRANGER9_REG_RES_DISTANCE_35_LSB 0xA2
239 #define LIGHTRANGER9_REG_RES_DISTANCE_35_MSB 0xA3
240 
246 #define LIGHTRANGER9_REG_PERIOD_MS_LSB 0x24
247 #define LIGHTRANGER9_REG_PERIOD_MS_MSB 0x25
248 #define LIGHTRANGER9_REG_KILO_ITERATIONS_LSB 0x26
249 #define LIGHTRANGER9_REG_KILO_ITERATIONS_MSB 0x27
250 #define LIGHTRANGER9_REG_INT_THRESHOLD_LOW_LSB 0x28
251 #define LIGHTRANGER9_REG_INT_THRESHOLD_LOW_MSB 0x29
252 #define LIGHTRANGER9_REG_INT_THRESHOLD_HIGH_LSB 0x2A
253 #define LIGHTRANGER9_REG_INT_THRESHOLD_HIGH_MSB 0x2B
254 #define LIGHTRANGER9_REG_INT_ZONE_MASK_0 0x2C
255 #define LIGHTRANGER9_REG_INT_ZONE_MASK_1 0x2D
256 #define LIGHTRANGER9_REG_INT_ZONE_MASK_2 0x2E
257 #define LIGHTRANGER9_REG_INT_PERSISTANCE 0x2F
258 #define LIGHTRANGER9_REG_CONFIDENCE_THRESHOLD 0x30
259 #define LIGHTRANGER9_REG_GPIO_0 0x31
260 #define LIGHTRANGER9_REG_GPIO_1 0x32
261 #define LIGHTRANGER9_REG_POWER_CFG 0x33
262 #define LIGHTRANGER9_REG_SPAD_MAP_ID 0x34
263 #define LIGHTRANGER9_REG_ALG_SETTING_0 0x35
264 #define LIGHTRANGER9_REG_HIST_DUMP 0x39
265 #define LIGHTRANGER9_REG_SPREAD_SPECTRUM 0x3A
266 #define LIGHTRANGER9_REG_I2C_SLAVE_ADDRESS 0x3B
267 #define LIGHTRANGER9_REG_OSC_TRIM_VALUE_LSB 0x3C
268 #define LIGHTRANGER9_REG_OSC_TRIM_VALUE_MSB 0x3D
269 #define LIGHTRANGER9_REG_I2C_ADDR_CHANGE 0x3E
270 
276 #define LIGHTRANGER9_REG_SPAD_ENABLE_FIRST 0x24
277 #define LIGHTRANGER9_REG_SPAD_ENABLE_LAST 0x41
278 #define LIGHTRANGER9_REG_SPAD_TDC_FIRST 0x42
279 #define LIGHTRANGER9_REG_SPAD_TDC_LAST 0x8C
280 #define LIGHTRANGER9_REG_SPAD_X_OFFSET_2 0x8D
281 #define LIGHTRANGER9_REG_SPAD_Y_OFFSET_2 0x8E
282 #define LIGHTRANGER9_REG_SPAD_X_SIZE 0x8F
283 #define LIGHTRANGER9_REG_SPAD_Y_SIZE 0x90
284 
290 #define LIGHTRANGER9_REG_FACTORY_CALIBRATION_FIRST 0x24
291 #define LIGHTRANGER9_REG_CROSSTALK_ZONE1 0x60
292 #define LIGHTRANGER9_REG_CROSSTALK_ZONE2 0x64
293 #define LIGHTRANGER9_REG_CROSSTALK_ZONE3 0x68
294 #define LIGHTRANGER9_REG_CROSSTALK_ZONE4 0x6C
295 #define LIGHTRANGER9_REG_CROSSTALK_ZONE5 0x70
296 #define LIGHTRANGER9_REG_CROSSTALK_ZONE6 0x74
297 #define LIGHTRANGER9_REG_CROSSTALK_ZONE7 0x78
298 #define LIGHTRANGER9_REG_CROSSTALK_ZONE8 0x7C
299 #define LIGHTRANGER9_REG_CROSSTALK_ZONE9 0x80
300 #define LIGHTRANGER9_REG_CROSSTALK_ZONE1_TMUX 0xB8
301 #define LIGHTRANGER9_REG_CROSSTALK_ZONE2_TMUX 0xBC
302 #define LIGHTRANGER9_REG_CROSSTALK_ZONE3_TMUX 0xC0
303 #define LIGHTRANGER9_REG_CROSSTALK_ZONE4_TMUX 0xC4
304 #define LIGHTRANGER9_REG_CROSSTALK_ZONE5_TMUX 0xC8
305 #define LIGHTRANGER9_REG_CROSSTALK_ZONE6_TMUX 0xCC
306 #define LIGHTRANGER9_REG_CROSSTALK_ZONE7_TMUX 0xD0
307 #define LIGHTRANGER9_REG_CROSSTALK_ZONE8_TMUX 0xD4
308 #define LIGHTRANGER9_REG_CROSSTALK_ZONE9_TMUX 0xD8
309 #define LIGHTRANGER9_REG_CALIBRATION_STATUS_FC 0xDC
310 #define LIGHTRANGER9_REG_FACTORY_CALIBRATION_LAST 0xDF
311 
317 #define LIGHTRANGER9_REG_SUBPACKET_NUMBER 0x24
318 #define LIGHTRANGER9_REG_SUBPACKET_PAYLOAD 0x25
319 #define LIGHTRANGER9_REG_SUBPACKET_CONFIG 0x26
320 #define LIGHTRANGER9_REG_SUBPACKET_DATA0 0x27
321 #define LIGHTRANGER9_REG_SUBPACKET_DATA127 0xA6
322 
328 #define LIGHTRANGER9_REG_BL_CMD_STAT 0x08
329 #define LIGHTRANGER9_REG_BL_SIZE 0x09
330 #define LIGHTRANGER9_REG_BL_DATA 0x0A
331  // lightranger9_reg
333 
348 #define LIGHTRANGER9_TIMEOUT 5000
349 
354 #define LIGHTRANGER9_ENABLE_CPU_READY 0x40
355 #define LIGHTRANGER9_ENABLE_POWERUP_BL 0x00
356 #define LIGHTRANGER9_ENABLE_POWERUP_BL_NO_SLP 0x10
357 #define LIGHTRANGER9_ENABLE_POWERUP_RAM 0x20
358 #define LIGHTRANGER9_ENABLE_PON 0x01
359 
364 #define LIGHTRANGER9_INT_ENAB_REG_STATUS 0x40
365 #define LIGHTRANGER9_INT_ENAB_COMMAND 0x20
366 #define LIGHTRANGER9_INT_ENAB_HIST_READY 0x08
367 #define LIGHTRANGER9_INT_ENAB_MEAS_READY 0x02
368 
373 #define LIGHTRANGER9_INT_STATUS_REG_STATUS 0x40
374 #define LIGHTRANGER9_INT_STATUS_COMMAND 0x20
375 #define LIGHTRANGER9_INT_STATUS_HIST_READY 0x08
376 #define LIGHTRANGER9_INT_STATUS_MEAS_READY 0x02
377 
382 #define LIGHTRANGER9_CMD_STAT_MEASURE 0x10
383 #define LIGHTRANGER9_CMD_STAT_CLEAR_STATUS 0x11
384 #define LIGHTRANGER9_CMD_STAT_GPIO 0x12
385 #define LIGHTRANGER9_CMD_STAT_WRITE_CFG_PAGE 0x15
386 #define LIGHTRANGER9_CMD_STAT_LOAD_CFG_PAGE_COMMON 0x16
387 #define LIGHTRANGER9_CMD_STAT_LOAD_CFG_PAGE_SPAD_1 0x17
388 #define LIGHTRANGER9_CMD_STAT_LOAD_CFG_PAGE_SPAD_2 0x18
389 #define LIGHTRANGER9_CMD_STAT_LOAD_CFG_PAGE_F_Y_CAL 0x19
390 #define LIGHTRANGER9_CMD_STAT_FACTORY_CALIBRATION 0x20
391 #define LIGHTRANGER9_CMD_STAT_I2C_SLAVE_ADDRESS 0x21
392 #define LIGHTRANGER9_CMD_STAT_FORCE_TMF8820 0x65
393 #define LIGHTRANGER9_CMD_STAT_FORCE_TMF8828 0x6C
394 #define LIGHTRANGER9_CMD_STAT_RESET 0xFE
395 #define LIGHTRANGER9_CMD_STAT_STOP 0xFF
396 
401 #define LIGHTRANGER9_CMD_STAT_OK 0x00
402 #define LIGHTRANGER9_CMD_STAT_ACCEPTED 0x01
403 #define LIGHTRANGER9_CMD_ERR_CONFIG 0x02
404 #define LIGHTRANGER9_CMD_ERR_APPLICATION 0x03
405 #define LIGHTRANGER9_CMD_ERR_WAKEUP_TIMED 0x04
406 #define LIGHTRANGER9_CMD_ERR_RESET_UNEXPECTED 0x05
407 #define LIGHTRANGER9_CMD_ERR_UNKNOWN_CMD 0x06
408 #define LIGHTRANGER9_CMD_ERR_NO_REF_SPAD 0x07
409 #define LIGHTRANGER9_CMD_ERR_UNKNOWN_CID 0x09
410 #define LIGHTRANGER9_CMD_WARNING_CFG_SPAD_1 0x0A
411 #define LIGHTRANGER9_CMD_WARNING_CFG_SPAD_2 0x0B
412 #define LIGHTRANGER9_CMD_WARNING_OSC_TRIP 0x0C
413 #define LIGHTRANGER9_CMD_WARNING_I2C_ADDRESS 0x0D
414 #define LIGHTRANGER9_CMD_ERR_UNKNOWN_MODE 0x0E
415 
420 #define LIGHTRANGER9_CONFIG_RESULT_MEAS 0x10
421 #define LIGHTRANGER9_CONFIG_RESULT_COMMON_CID 0x16
422 #define LIGHTRANGER9_CONFIG_RESULT_SPAD_1_CID 0x17
423 #define LIGHTRANGER9_CONFIG_RESULT_SPAD_2_CID 0x18
424 #define LIGHTRANGER9_CONFIG_RESULT_FAC_CALIB_CID 0x19
425 #define LIGHTRANGER9_CONFIG_RESULT_HIST_RAW_CID 0x81
426 
431 #define LIGHTRANGER9_BL_CMD_RAMREMAP_RESET 0x11
432 #define LIGHTRANGER9_BL_CMD_DOWNLOAD_INIT 0x14
433 #define LIGHTRANGER9_BL_CMD_RAM_BIST 0x2A
434 #define LIGHTRANGER9_BL_CMD_I2C_BIST 0x2C
435 #define LIGHTRANGER9_BL_CMD_W_RAM 0x41
436 #define LIGHTRANGER9_BL_CMD_ADDR_RAM 0x43
437 
442 #define LIGHTRANGER9_BL_CMD_STAT_READY 0x00
443 #define LIGHTRANGER9_BL_CMD_STAT_ERR_SIZE 0x01
444 #define LIGHTRANGER9_BL_CMD_STAT_ERR_CSUM 0x02
445 #define LIGHTRANGER9_BL_CMD_STAT_ERR_RANGE 0x03
446 #define LIGHTRANGER9_BL_CMD_STAT_ERR_MORE 0x04
447 
452 #define LIGHTRANGER9_APP_ID_BOOTLOADER 0x80
453 #define LIGHTRANGER9_APP_ID_MEASUREMENT 0x03
454 
459 #define LIGHTRANGER9_BLOCKREAD_SIZE 132
460 #define LIGHTRANGER9_MAX_MEAS_RESULTS 36
461 #define LIGHTRANGER9_SUBCAPTURE_0 0
462 #define LIGHTRANGER9_SUBCAPTURE_1 1
463 #define LIGHTRANGER9_SUBCAPTURE_2 2
464 #define LIGHTRANGER9_SUBCAPTURE_3 3
465 #define LIGHTRANGER9_SUBCAPTURE_MASK 0x03
466 #define LIGHTRANGER9_RESULT_NUMBER_MASK 0x3F
467 #define LIGHTRANGER9_SYS_TICK_TO_SEC 0.0000002
468 #define LIGHTRANGER9_OBJECT_MAP_SIZE 64
469 
474 #define LIGHTRANGER9_DEFAULT_MEASUREMENT_PERIOD_MS 500
475 #define LIGHTRANGER9_CONFIDENCE_THRESHOLD 100
476 
481 #define LIGHTRANGER9_DEVICE_ID 0x08
482 
488 #define LIGHTRANGER9_DEVICE_ADDRESS 0x41
489  // lightranger9_set
491 
506 #define LIGHTRANGER9_MAP_MIKROBUS( cfg, mikrobus ) \
507  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
508  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
509  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
510  cfg.gpio0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
511  cfg.gpio1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
512  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
513  // lightranger9_map // lightranger9
516 
521 typedef struct
522 {
523  // Output pins
524  digital_out_t en;
525  digital_out_t gpio0;
526  digital_out_t gpio1;
528  // Input pins
529  digital_in_t int_pin;
531  // Modules
532  i2c_master_t i2c;
534  // I2C slave address
535  uint8_t slave_address;
538 
543 typedef struct
544 {
545  pin_name_t scl;
546  pin_name_t sda;
548  pin_name_t en;
549  pin_name_t gpio0;
550  pin_name_t gpio1;
551  pin_name_t int_pin;
553  uint32_t i2c_speed;
554  uint8_t i2c_address;
557 
562 typedef struct
563 {
564  uint8_t confidence;
565  uint16_t distance_mm;
566 
568 
573 typedef struct
574 {
575  uint8_t sub_capture;
576  uint8_t result_number;
577  int8_t temperature;
578  uint8_t valid_results;
579  uint32_t ambient_light;
580  uint32_t photon_count;
581  uint32_t reference_count;
584 
586 
591 typedef enum
592 {
594  LIGHTRANGER9_ERROR = -1
595 
597 
614 
629 
643 
658 err_t lightranger9_generic_write ( lightranger9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
659 
674 err_t lightranger9_generic_read ( lightranger9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
675 
688 err_t lightranger9_write_register ( lightranger9_t *ctx, uint8_t reg, uint8_t data_in );
689 
702 err_t lightranger9_read_register ( lightranger9_t *ctx, uint8_t reg, uint8_t *data_out );
703 
718 err_t lightranger9_write_bl_cmd ( lightranger9_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
719 
731 err_t lightranger9_read_bl_cmd_status ( lightranger9_t *ctx, uint8_t *status );
732 
744 
754 void lightranger9_set_gpio0_pin ( lightranger9_t *ctx, uint8_t state );
755 
765 void lightranger9_set_gpio1_pin ( lightranger9_t *ctx, uint8_t state );
766 
776 
786 
796 
809 
821 
835 
836 #ifdef __cplusplus
837 }
838 #endif
839 #endif // LIGHTRANGER9_H
840  // lightranger9
842 
843 // ------------------------------------------------------------------------ END
lightranger9_capture_t::temperature
int8_t temperature
Definition: lightranger9.h:577
lightranger9_clear_interrupts
err_t lightranger9_clear_interrupts(lightranger9_t *ctx)
LightRanger 9 clear interrupts function.
lightranger9_return_value_t
lightranger9_return_value_t
LightRanger 9 Click return value data.
Definition: lightranger9.h:592
lightranger9_cfg_t::gpio1
pin_name_t gpio1
Definition: lightranger9.h:550
lightranger9_t::en
digital_out_t en
Definition: lightranger9.h:524
lightranger9_capture_t::valid_results
uint8_t valid_results
Definition: lightranger9.h:578
lightranger9_default_cfg
err_t lightranger9_default_cfg(lightranger9_t *ctx)
LightRanger 9 default configuration function.
lightranger9_capture_t::reference_count
uint32_t reference_count
Definition: lightranger9.h:581
lightranger9_capture_t::ambient_light
uint32_t ambient_light
Definition: lightranger9.h:579
lightranger9_download_fw_bin
err_t lightranger9_download_fw_bin(lightranger9_t *ctx)
LightRanger 9 download fw bin function.
lightranger9_read_bl_cmd_status
err_t lightranger9_read_bl_cmd_status(lightranger9_t *ctx, uint8_t *status)
LightRanger 9 read bl cmd status function.
lightranger9_write_bl_cmd
err_t lightranger9_write_bl_cmd(lightranger9_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
LightRanger 9 write bl cmd function.
lightranger9_cfg_t::scl
pin_name_t scl
Definition: lightranger9.h:545
lightranger9_check_communication
err_t lightranger9_check_communication(lightranger9_t *ctx)
LightRanger 9 check communication function.
lightranger9_cfg_t
LightRanger 9 Click configuration object.
Definition: lightranger9.h:544
lightranger9_set_gpio1_pin
void lightranger9_set_gpio1_pin(lightranger9_t *ctx, uint8_t state)
LightRanger 9 set gpio1 pin function.
lightranger9_cfg_t::i2c_address
uint8_t i2c_address
Definition: lightranger9.h:554
lightranger9_generic_write
err_t lightranger9_generic_write(lightranger9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
LightRanger 9 I2C writing function.
lightranger9_enable_device
void lightranger9_enable_device(lightranger9_t *ctx)
LightRanger 9 enable device function.
lightranger9_capture_t::sys_tick_sec
float sys_tick_sec
Definition: lightranger9.h:582
lightranger9_cfg_setup
void lightranger9_cfg_setup(lightranger9_cfg_t *cfg)
LightRanger 9 configuration object setup function.
lightranger9_read_register
err_t lightranger9_read_register(lightranger9_t *ctx, uint8_t reg, uint8_t *data_out)
LightRanger 9 read register function.
lightranger9_cfg_t::en
pin_name_t en
Definition: lightranger9.h:548
lightranger9_capture_t::photon_count
uint32_t photon_count
Definition: lightranger9.h:580
lightranger9_meas_result_t::confidence
uint8_t confidence
Definition: lightranger9.h:564
lightranger9_write_register
err_t lightranger9_write_register(lightranger9_t *ctx, uint8_t reg, uint8_t data_in)
LightRanger 9 write register function.
lightranger9_init
err_t lightranger9_init(lightranger9_t *ctx, lightranger9_cfg_t *cfg)
LightRanger 9 initialization function.
lightranger9_cfg_t::gpio0
pin_name_t gpio0
Definition: lightranger9.h:549
lightranger9_disable_device
void lightranger9_disable_device(lightranger9_t *ctx)
LightRanger 9 disable device function.
lightranger9_cfg_t::sda
pin_name_t sda
Definition: lightranger9.h:546
LIGHTRANGER9_ERROR
@ LIGHTRANGER9_ERROR
Definition: lightranger9.h:594
lightranger9_meas_result_t::distance_mm
uint16_t distance_mm
Definition: lightranger9.h:565
lightranger9_t::slave_address
uint8_t slave_address
Definition: lightranger9.h:535
lightranger9_set_gpio0_pin
void lightranger9_set_gpio0_pin(lightranger9_t *ctx, uint8_t state)
LightRanger 9 set gpio0 pin function.
lightranger9_generic_read
err_t lightranger9_generic_read(lightranger9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
LightRanger 9 I2C reading function.
lightranger9_t::int_pin
digital_in_t int_pin
Definition: lightranger9.h:529
lightranger9_get_capture
err_t lightranger9_get_capture(lightranger9_t *ctx, lightranger9_capture_t *capture)
LightRanger 9 get capture function.
lightranger9_capture_t::sub_capture
uint8_t sub_capture
Definition: lightranger9.h:575
lightranger9_meas_result_t
LightRanger 9 measurement result data object.
Definition: lightranger9.h:563
lightranger9_capture_t
LightRanger 9 capture data object.
Definition: lightranger9.h:574
lightranger9_get_int_pin
uint8_t lightranger9_get_int_pin(lightranger9_t *ctx)
LightRanger 9 get int pin function.
lightranger9_capture_t::result_number
uint8_t result_number
Definition: lightranger9.h:576
lightranger9_t::i2c
i2c_master_t i2c
Definition: lightranger9.h:532
LIGHTRANGER9_OK
@ LIGHTRANGER9_OK
Definition: lightranger9.h:593
lightranger9_t
LightRanger 9 Click context object.
Definition: lightranger9.h:522
lightranger9_t::gpio0
digital_out_t gpio0
Definition: lightranger9.h:525
lightranger9_t::gpio1
digital_out_t gpio1
Definition: lightranger9.h:526
lightranger9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: lightranger9.h:553
lightranger9_cfg_t::int_pin
pin_name_t int_pin
Definition: lightranger9.h:551
LIGHTRANGER9_MAX_MEAS_RESULTS
#define LIGHTRANGER9_MAX_MEAS_RESULTS
Definition: lightranger9.h:460