CRINSA-team2025 V1
Documentation du Club Robot INSA Rennes 2025
Chargement...
Recherche...
Aucune correspondance
VL53L5CX.h
1//
2// Created by romain on 5/18/25.
3//
4
5#ifndef VL53L5CX_H
6#define VL53L5CX_H
7
8#include <Wire.h>
9
10#include "Arduino.h"
11#include "platform.h"
12#include "vl53l5cx_api.h"
13
14#define VL53L5CX_SENSOR_FOV 45.0F
15
16class VL53L5CX {
17 public:
23 VL53L5CX(i2c_t *i2c)
24 {
25 memset((void *)&_dev, 0x0, sizeof(VL53L5CX_Configuration));
26 _dev.platform.address = VL53L5CX_DEFAULT_I2C_ADDRESS;
27 _dev.platform.dev_i2c = i2c;
28 p_dev = &_dev;
29 }
30
31
34 virtual ~VL53L5CX() {}
35 /* warning: VL53LX class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
36 The warning should request to introduce a virtual destructor to make sure to delete the object */
37
43 int init_sensor(uint8_t addr = VL53L5CX_DEFAULT_I2C_ADDRESS)
44 {
45 uint8_t status = VL53L5CX_STATUS_OK;
46 uint8_t isAlive = 0;
47
48 if (addr != _dev.platform.address) {
49 status = vl53l5cx_set_i2c_address(addr);
50 if (status != VL53L5CX_STATUS_OK) {
51 return VL53L5CX_STATUS_ERROR;
52 }
53 }
54
55 status = vl53l5cx_is_alive(&isAlive);
56 if (!isAlive || status != VL53L5CX_STATUS_OK) {
57 return VL53L5CX_STATUS_ERROR;
58 }
59
60 // Init VL53L5CX sensor
61 status = vl53l5cx_init();
62 if (status != VL53L5CX_STATUS_OK) {
63 return VL53L5CX_STATUS_ERROR;
64 }
65
66 return (int)status;
67 }
68
69
70 /* vl53l5cx_api.h */
76 uint8_t vl53l5cx_is_alive(
77 uint8_t *p_is_alive);
78
85
86 uint8_t vl53l5cx_init();
87
95
97 uint16_t i2c_address);
98
107
109 uint8_t *p_power_mode);
110
122
124 uint8_t power_mode);
125
131
132 uint8_t vl53l5cx_start_ranging();
133
139
140 uint8_t vl53l5cx_stop_ranging();
141
149
151 uint8_t *p_isReady);
152
159
161 VL53L5CX_ResultsData *p_results);
162
169
171 uint8_t *p_resolution);
172
179
181 uint8_t resolution);
182
189
191 uint8_t *p_frequency_hz);
192
203
205 uint8_t frequency_hz);
206
212
214 uint32_t *p_time_ms);
215
225
227 uint32_t integration_time_ms);
228
235
237 uint8_t *p_sharpener_percent);
238
246
248 uint8_t sharpener_percent);
249
255
257 uint8_t *p_target_order);
258
268
270 uint8_t target_order);
271
279
281 uint8_t *p_ranging_mode);
282
291
293 uint8_t ranging_mode);
294
306
308 uint8_t *data,
309 uint32_t index,
310 uint16_t data_size);
311
323
325 uint8_t *data,
326 uint32_t index,
327 uint16_t data_size);
328
349
351 uint8_t *data,
352 uint32_t index,
353 uint16_t data_size,
354 uint8_t *new_data,
355 uint16_t new_data_size,
356 uint16_t new_data_pos);
357
358 void SwapBuffer(
359 uint8_t *buffer,
360 uint16_t size);
361
362 /* Helpful APIs */
363 uint8_t get_stream_count(void)
364 {
365 return _dev.streamcount;
366 };
367
368 /* VL53L5CX Device */
369 VL53L5CX_Configuration _dev;
370 VL53L5CX_Configuration *p_dev;
371
372
373 protected:
374
380 uint8_t size,
381 uint8_t pos,
382 uint16_t address,
383 uint8_t mask,
384 uint8_t expected_value);
385
386 uint8_t _vl53l5cx_poll_for_mcu_boot();
387
393 uint8_t resolution);
394
395
401 uint8_t resolution);
402
408 uint16_t address,
409 uint8_t expected_value);
410
416
417 /* Platform APIs */
418
426
427 uint8_t RdByte(
428 VL53L5CX_Platform *p_platform,
429 uint16_t RegisterAddress,
430 uint8_t *p_value);
431
440
441 uint8_t WrByte(
442 VL53L5CX_Platform *p_platform,
443 uint16_t RegisterAddress,
444 uint8_t value);
445
455
456 uint8_t RdMulti(
457 VL53L5CX_Platform *p_platform,
458 uint16_t RegisterAddress,
459 uint8_t *p_values,
460 uint32_t size);
461
471
472 uint8_t WrMulti(
473 VL53L5CX_Platform *p_platform,
474 uint16_t RegisterAddress,
475 uint8_t *p_values,
476 uint32_t size);
477
486
487 uint8_t WaitMs(
488 VL53L5CX_Platform *p_platform,
489 uint32_t TimeMs);
490
491 uint8_t vl53l5cx_set_VHV_repeat_count(
492 uint32_t repeat_count);
493
494 uint8_t vl53l5cx_get_VHV_repeat_count(
495 uint32_t *p_repeat_count);
496
497 uint8_t vl53l5cx_disable_internal_cp();
498
499 uint8_t vl53l5cx_enable_internal_cp();
500};
501
502
503
504#endif //VL53L5CX_H
uint8_t _vl53l5cx_send_offset_data(uint8_t resolution)
Inner function, not available outside this file. This function is used to set the offset data gathere...
Definition vl53l5cx_api.cpp:92
uint8_t vl53l5cx_get_ranging_frequency_hz(uint8_t *p_frequency_hz)
This function gets the current ranging frequency in Hz. Ranging frequency corresponds to the time bet...
Definition vl53l5cx_api.cpp:946
uint8_t _vl53l5cx_poll_for_answer(uint8_t size, uint8_t pos, uint16_t address, uint8_t mask, uint8_t expected_value)
Inner function, not available outside this file. This function is used to wait for an answer from VL5...
Definition vl53l5cx_api.cpp:25
uint8_t _vl53l5cx_program_output_config()
Inner function, not available outside this file. This function is used to program the output using th...
uint8_t RdMulti(VL53L5CX_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_values, uint32_t size)
Mandatory function used to read multiples bytes.
Definition platform.cpp:83
uint8_t vl53l5cx_get_power_mode(uint8_t *p_power_mode)
This function is used to get the current sensor power mode.
Definition vl53l5cx_api.cpp:417
uint8_t vl53l5cx_get_ranging_data(VL53L5CX_ResultsData *p_results)
This function gets the ranging data, using the selected output and the resolution.
Definition vl53l5cx_api.cpp:698
uint8_t vl53l5cx_set_integration_time_ms(uint32_t integration_time_ms)
This function sets a new integration time in ms. Integration time must be computed to be lower than t...
Definition vl53l5cx_api.cpp:984
uint8_t vl53l5cx_get_target_order(uint8_t *p_target_order)
This function gets the current target order (closest or strongest).
Definition vl53l5cx_api.cpp:1042
uint8_t vl53l5cx_check_data_ready(uint8_t *p_isReady)
This function checks if a new data is ready by polling I2C. If a new data is ready,...
Definition vl53l5cx_api.cpp:668
uint8_t vl53l5cx_set_sharpener_percent(uint8_t sharpener_percent)
This function sets a new sharpener value in percent. Sharpener can be changed to blur more or less zo...
Definition vl53l5cx_api.cpp:1021
uint8_t _vl53l5cx_poll_for_answer_xtalk(uint16_t address, uint8_t expected_value)
Inner function, not available outside this file. This function is used to wait for an answer from VL5...
uint8_t vl53l5cx_init()
Mandatory function used to initialize the sensor. This function must be called after a power on,...
Definition vl53l5cx_api.cpp:238
uint8_t vl53l5cx_dci_write_data(uint8_t *data, uint32_t index, uint16_t data_size)
This function can be used to write 'extra data' to DCI. The data can be simple data,...
Definition vl53l5cx_api.cpp:1233
uint8_t vl53l5cx_dci_replace_data(uint8_t *data, uint32_t index, uint16_t data_size, uint8_t *new_data, uint16_t new_data_size, uint16_t new_data_pos)
Definition vl53l5cx_api.cpp:1287
uint8_t vl53l5cx_get_resolution(uint8_t *p_resolution)
This function gets the current resolution (4x4 or 8x8).
Definition vl53l5cx_api.cpp:868
int init_sensor(uint8_t addr=VL53L5CX_DEFAULT_I2C_ADDRESS)
Initialize the sensor.
Definition VL53L5CX.h:43
uint8_t WrMulti(VL53L5CX_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_values, uint32_t size)
Mandatory function used to write multiples bytes.
Definition platform.cpp:45
uint8_t vl53l5cx_stop_ranging()
This function stops the ranging session. It must be used when the sensor streams, after calling vl53l...
Definition vl53l5cx_api.cpp:615
uint8_t vl53l5cx_get_ranging_mode(uint8_t *p_ranging_mode)
This function is used to get the ranging mode. Two modes are available using ULD : Continuous and aut...
Definition vl53l5cx_api.cpp:1072
virtual ~VL53L5CX()
Definition VL53L5CX.h:34
uint8_t vl53l5cx_set_ranging_mode(uint8_t ranging_mode)
This function is used to set the ranging mode. Two modes are available using ULD : Continuous and aut...
Definition vl53l5cx_api.cpp:1092
uint8_t vl53l5cx_set_i2c_address(uint16_t i2c_address)
This function is used to change the I2C address of the sensor. If multiple VL53L5 sensors are connect...
Definition vl53l5cx_api.cpp:404
uint8_t vl53l5cx_set_target_order(uint8_t target_order)
This function sets a new target order. Please use macros VL53L5CX_TARGET_ORDER_STRONGEST and VL53L5CX...
Definition vl53l5cx_api.cpp:1053
uint8_t WaitMs(VL53L5CX_Platform *p_platform, uint32_t TimeMs)
Mandatory function, used to wait during an amount of time. It must be filled as it's used into the AP...
Definition platform.cpp:122
uint8_t vl53l5cx_dci_read_data(uint8_t *data, uint32_t index, uint16_t data_size)
This function can be used to read 'extra data' from DCI. Using a known index, the function fills the ...
Definition vl53l5cx_api.cpp:1188
VL53L5CX(i2c_t *i2c)
Definition VL53L5CX.h:23
uint8_t vl53l5cx_set_resolution(uint8_t resolution)
This function sets a new resolution (4x4 or 8x8).
Definition vl53l5cx_api.cpp:882
uint8_t vl53l5cx_get_sharpener_percent(uint8_t *p_sharpener_percent)
This function gets the current sharpener in percent. Sharpener can be changed to blur more or less zo...
Definition vl53l5cx_api.cpp:1007
uint8_t _vl53l5cx_send_xtalk_data(uint8_t resolution)
Inner function, not available outside this file. This function is used to set the Xtalk data from gen...
Definition vl53l5cx_api.cpp:161
uint8_t vl53l5cx_set_power_mode(uint8_t power_mode)
This function is used to set the sensor in Low Power mode, for example if the sensor is not used duri...
Definition vl53l5cx_api.cpp:445
uint8_t vl53l5cx_is_alive(uint8_t *p_is_alive)
This function is used to check if the sensor is alive.
Definition vl53l5cx_api.cpp:215
uint8_t vl53l5cx_get_integration_time_ms(uint32_t *p_time_ms)
This function gets the current integration time in ms.
Definition vl53l5cx_api.cpp:970
uint8_t WrByte(VL53L5CX_Platform *p_platform, uint16_t RegisterAddress, uint8_t value)
Mandatory function used to write one single byte.
Definition platform.cpp:36
uint8_t vl53l5cx_set_ranging_frequency_hz(uint8_t frequency_hz)
This function sets a new ranging frequency in Hz. Ranging frequency corresponds to the measurements f...
Definition vl53l5cx_api.cpp:958
uint8_t vl53l5cx_start_ranging()
This function starts a ranging session. When the sensor streams, host cannot change settings 'on-the-...
Definition vl53l5cx_api.cpp:479
uint8_t RdByte(VL53L5CX_Platform *p_platform, uint16_t RegisterAddress, uint8_t *p_value)
Definition platform.cpp:27
Structure VL53L5CX_Configuration contains the sensor configuration. User MUST not manually change the...
Definition vl53l5cx_api.h:268
Structure VL53L5CX_Platform needs to be filled by the customer, depending on his platform....
Definition platform.h:28
Structure VL53L5CX_ResultsData contains the ranging results of VL53L5CX. If user wants more than 1 ta...
Definition vl53l5cx_api.h:302