Skip to content

Commit 338a4ee

Browse files
committed
update ULD, add new API to class, add CNH example
1 parent 53c4acd commit 338a4ee

File tree

9 files changed

+724
-423
lines changed

9 files changed

+724
-423
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ There are 3 examples with the VL53L8CH library:
5151

5252
* VL53L8CH_ThresholdsDetection: This example code is to show how to configure the thresholds detection of the VL53L8CH satellite sensor.
5353

54+
* VL53L8CH_CNHData: This example code is to show how to configure, capture and decode CNH data from the VL53L8CH sensors.
5455

5556
## Documentation
5657

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/**
2+
******************************************************************************
3+
* @file VL53L8CH_CNHData.ino
4+
* @brief Example Arduino sketch using VL53L8CH class API with CNH feature.
5+
******************************************************************************
6+
*/
7+
8+
#include <vl53l8ch.h>
9+
#include <vl53lmz_plugin_cnh.h>
10+
11+
#ifdef ARDUINO_SAM_DUE
12+
#define DEV_I2C Wire1
13+
#else
14+
#define DEV_I2C Wire
15+
#endif
16+
#define SerialPort Serial
17+
18+
#define LPN_PIN A3
19+
#define PWREN_PIN 11
20+
21+
VL53L8CH sensor(&DEV_I2C, LPN_PIN);
22+
23+
VL53LMZ_Motion_Configuration cnh_config;
24+
cnh_data_buffer_t cnh_data_buffer;
25+
uint32_t cnh_data_size = 0;
26+
27+
int32_t *p_hist = NULL;
28+
int8_t *p_hist_scaler = NULL;
29+
int32_t *p_ambient = NULL;
30+
int8_t *p_ambient_scaler = NULL;
31+
32+
uint8_t status;
33+
uint8_t resolution = VL53LMZ_RESOLUTION_4X4;
34+
35+
void setup()
36+
{
37+
SerialPort.begin(460800);
38+
39+
if (PWREN_PIN >= 0) {
40+
pinMode(PWREN_PIN, OUTPUT);
41+
digitalWrite(PWREN_PIN, HIGH);
42+
delay(10);
43+
}
44+
45+
DEV_I2C.begin();
46+
47+
status = sensor.begin();
48+
if (status != VL53LMZ_STATUS_OK) {
49+
SerialPort.println("Sensor begin failed");
50+
while (1);
51+
}
52+
53+
if (status != VL53LMZ_STATUS_OK) {
54+
SerialPort.println("Sensor init failed");
55+
while (1);
56+
}
57+
58+
status = sensor.set_resolution(resolution);
59+
if (status != VL53LMZ_STATUS_OK) {
60+
SerialPort.println("Set resolution failed");
61+
while (1);
62+
}
63+
64+
status = sensor.cnh_init_config(&cnh_config, 0, 24, 4);
65+
if (status != VL53LMZ_STATUS_OK) {
66+
SerialPort.println("CNH init config failed");
67+
while (1);
68+
}
69+
70+
status = sensor.cnh_create_agg_map(&cnh_config,
71+
16, 0, 0, 1, 1, 4, 4);
72+
if (status != VL53LMZ_STATUS_OK) {
73+
SerialPort.println("CNH create agg map failed");
74+
while (1);
75+
}
76+
77+
status = sensor.cnh_calc_required_memory(&cnh_config, &cnh_data_size);
78+
if (status != VL53LMZ_STATUS_OK || cnh_data_size > VL53LMZ_CNH_MAX_DATA_BYTES) {
79+
SerialPort.println("CNH memory size error");
80+
while (1);
81+
}
82+
83+
status = sensor.cnh_send_config(&cnh_config);
84+
if (status != VL53LMZ_STATUS_OK) {
85+
SerialPort.println("CNH send config failed");
86+
while (1);
87+
}
88+
89+
status = sensor.create_output_config();
90+
if (status != VL53LMZ_STATUS_OK) {
91+
SerialPort.println("Create output config failed");
92+
while (1);
93+
}
94+
95+
union Block_header cnh_data_bh;
96+
cnh_data_bh.idx = VL53LMZ_CNH_DATA_IDX;
97+
cnh_data_bh.type = 4;
98+
cnh_data_bh.size = cnh_data_size / 4;
99+
100+
status = sensor.add_output_block(cnh_data_bh.bytes);
101+
if (status != VL53LMZ_STATUS_OK) {
102+
SerialPort.println("Add output block CNH failed");
103+
while (1);
104+
}
105+
106+
status = sensor.send_output_config_and_start();
107+
if (status != VL53LMZ_STATUS_OK) {
108+
SerialPort.println("Start ranging failed");
109+
while (1);
110+
}
111+
112+
SerialPort.println("Sensor and CNH configured, ranging started");
113+
}
114+
115+
void loop()
116+
{
117+
VL53LMZ_ResultsData results;
118+
uint8_t data_ready = 0;
119+
120+
do {
121+
status = sensor.check_data_ready(&data_ready);
122+
} while (!data_ready);
123+
124+
if (status == VL53LMZ_STATUS_OK && data_ready) {
125+
status = sensor.get_ranging_data(&results);
126+
if (status == VL53LMZ_STATUS_OK) {
127+
print_results(&results);
128+
}
129+
130+
status = sensor.results_extract_block(VL53LMZ_CNH_DATA_IDX, (uint8_t *)cnh_data_buffer, cnh_data_size);
131+
if (status == VL53LMZ_STATUS_OK) {
132+
for (int agg_id = 0; agg_id < cnh_config.nb_of_aggregates; agg_id++) {
133+
sensor.cnh_get_block_addresses(&cnh_config, agg_id, cnh_data_buffer,
134+
&p_hist, &p_hist_scaler,
135+
&p_ambient, &p_ambient_scaler);
136+
137+
float ambient = ((float) * p_ambient) / (1 << *p_ambient_scaler);
138+
SerialPort.print("Aggregate ");
139+
SerialPort.print(agg_id);
140+
SerialPort.print(", Ambient: ");
141+
SerialPort.print(ambient, 1);
142+
SerialPort.print(", Bins: ");
143+
144+
for (int bin = 0; bin < cnh_config.feature_length; bin++) {
145+
float bin_val = ((float)p_hist[bin]) / (1 << p_hist_scaler[bin]);
146+
SerialPort.print(bin_val, 1);
147+
SerialPort.print(", ");
148+
}
149+
SerialPort.println();
150+
}
151+
} else {
152+
SerialPort.println("Failed to extract CNH data block");
153+
}
154+
}
155+
delay(100);
156+
}
157+
158+
void print_results(VL53LMZ_ResultsData *res)
159+
{
160+
SerialPort.println("Ranging Results:");
161+
for (int i = 0; i < resolution; i++) {
162+
if (res->nb_target_detected[i] > 0) {
163+
SerialPort.print("Zone ");
164+
SerialPort.print(i);
165+
SerialPort.print(": Distance=");
166+
SerialPort.print(res->distance_mm[i]);
167+
SerialPort.print(" mm, Status=");
168+
SerialPort.println(res->target_status[i]);
169+
} else {
170+
SerialPort.print("Zone ");
171+
SerialPort.print(i);
172+
SerialPort.println(": No target");
173+
}
174+
}
175+
}

keywords.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ cnh_calc_min_max_distance KEYWORD2
7373
cnh_send_config KEYWORD2
7474
cnh_get_block_addresses KEYWORD2
7575
cnh_get_ref_residual KEYWORD2
76+
get_ranging_frequency_x256 KEYWORD2
77+
set_ranging_frequency_x256 KEYWORD2
78+
get_VHV_repeat_count KEYWORD2
79+
set_VHV_repeat_count KEYWORD2
7680

7781
#######################################
7882
# Constants (LITERAL1)
@@ -184,3 +188,5 @@ VL53LMZ_CNH_MAX_DATA_WORDS LITERAL1
184188
VL53LMZ_CNH_MAX_DATA_BYTES LITERAL1
185189
VL53LMZ_CNH_DATA_IDX LITERAL1
186190
VL53LMZ_CNH_DATA_BH LITERAL1
191+
VL53LMZ_DCI_VHV_CONFIG LITERAL1
192+
VL53LMZ_STATUS_FW_CHECKSUM_FAIL LITERAL1

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino VL53L8CH
2-
version=1.0.0
2+
version=2.0.0
33
author=STMicroelectronics
44
maintainer=stm32duino
55
sentence=Allows controlling the VL53L8CH (Time-of-Flight 8x8 multizone ranging sensor with wide field view)

src/vl53l8ch.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,63 @@ uint32_t VL53L8CH::cnh_get_ref_residual(cnh_data_buffer_t mi_persistent_array)
770770
return vl53lmz_cnh_get_ref_residual(mi_persistent_array);
771771
}
772772

773+
/**
774+
* @brief This function gets the current ranging frequency in Hz scaled up by
775+
* a factor of 256 to enable non-integer values to be returned.
776+
* Ranging frequency corresponds to the time between each measurement.
777+
* @param (VL53LMZ_Configuration) *p_dev : VL53LMZ configuration structure.
778+
* @param (uint8_t) *p_frequency_x256: Contains the ranging frequency scaled
779+
* to 256 x Hz.
780+
* @return (uint8_t) status : 0 if ranging frequency is OK.
781+
*/
782+
uint8_t VL53L8CH::get_ranging_frequency_x256(VL53LMZ_Configuration *p_dev, uint16_t *p_frequency_x256)
783+
{
784+
return vl53lmz_get_ranging_frequency_x256(p_dev, p_frequency_x256);
785+
}
786+
787+
/**
788+
* @brief This function sets a new ranging frequency in Hz scaled up by 256
789+
* to enable non-integer values to be set.
790+
* Ranging frequencycorresponds to the measurements frequency. This setting
791+
* depends on the resolution, so please select your resolution before using
792+
* this function.
793+
* @param (VL53LMZ_Configuration) *p_dev : VL53LMZ configuration structure.
794+
* @param (uint8_t) frequency_x256 : Contains the ranging frequency in Hz.
795+
* - For 4x4, min and max allowed values are : [1*256;60*256]
796+
* - For 8x8, min and max allowed values are : [1*256;15*256]
797+
* @return (uint8_t) status : 0 if ranging frequency is OK, or 127 if the value
798+
* is not correct.
799+
*/
800+
uint8_t VL53L8CH::set_ranging_frequency_x256(VL53LMZ_Configuration *p_dev, uint16_t frequency_x256)
801+
{
802+
return vl53lmz_set_ranging_frequency_x256(p_dev, frequency_x256);
803+
}
804+
805+
/**
806+
* @brief This function is used to get the number of frames between 2 temperature
807+
* compensation.
808+
* @param (VL53LMZ_Configuration) *p_dev : VL53LMZ configuration structure.
809+
* @param (uint32_t) *p_repeat_count : Number of frames before next temperature
810+
* compensation. Set to 0 to disable the feature (default configuration).
811+
*/
812+
uint8_t VL53L8CH::get_VHV_repeat_count(VL53LMZ_Configuration *p_dev, uint32_t *p_repeat_count)
813+
{
814+
return vl53lmz_get_VHV_repeat_count(p_dev, p_repeat_count);
815+
}
816+
817+
/**
818+
* @brief This function is used to set a periodic temperature compensation. By
819+
* setting a repeat count different to 0 the firmware automatically runs a
820+
* temperature calibration every N frames.
821+
* default the repeat count is set to 0
822+
* @param (VL53LMZ_Configuration) *p_dev : VL53LMZ configuration structure.
823+
* @param (uint32_t) repeat_count : Number of frames between temperature
824+
* compensation. Set to 0 to disable the feature (default configuration).
825+
*/
826+
uint8_t VL53L8CH::set_VHV_repeat_count(VL53LMZ_Configuration *p_dev, uint32_t repeat_count)
827+
{
828+
return vl53lmz_set_VHV_repeat_count(p_dev, repeat_count);
829+
}
773830

774831
uint8_t VL53L8CH_io_write(void *handle, uint16_t RegisterAddress, uint8_t *p_values, uint32_t size)
775832
{

src/vl53l8ch.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ class VL53L8CH {
117117
uint8_t cnh_send_config(VL53LMZ_Motion_Configuration *p_mi_config);
118118
uint8_t cnh_get_block_addresses(VL53LMZ_Motion_Configuration *p_mi_config, int32_t agg_id, cnh_data_buffer_t mi_persistent_array, int32_t **p_hist, int8_t **p_hist_scaler, int32_t **p_ambient, int8_t **p_ambient_scaler);
119119
uint32_t cnh_get_ref_residual(cnh_data_buffer_t mi_persistent_array);
120+
uint8_t get_ranging_frequency_x256(VL53LMZ_Configuration *p_dev, uint16_t *p_frequency_x256);
121+
uint8_t set_ranging_frequency_x256(VL53LMZ_Configuration *p_dev, uint16_t p_frequency_x256);
122+
uint8_t get_VHV_repeat_count(VL53LMZ_Configuration *p_dev, uint32_t *p_repeat_count);
123+
uint8_t set_VHV_repeat_count(VL53LMZ_Configuration *p_dev, uint32_t p_repeat_count);
120124

121125
/**
122126
* @brief Utility function to read data.

src/vl53lmz_api.h

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma anon_unions
1818
#endif
1919

20+
2021
#ifdef __cplusplus
2122
extern "C" {
2223
#endif
@@ -27,7 +28,7 @@ extern "C" {
2728
* @brief Current driver version.
2829
*/
2930

30-
#define VL53LMZ_API_REVISION "VL53LMZ_2.0.10"
31+
#define VL53LMZ_API_REVISION "VL53LMZ_2.0.16"
3132

3233

3334
/**
@@ -86,7 +87,7 @@ extern "C" {
8687
* - VL53LMZ_POWER_MODE_DEEP_SLEEP: This mode clears all memory, by consequence the firmware,
8788
* the configuration and the calibration are lost. It is recommended when the device sleeps during
8889
* a long time as it consumes a very low current consumption.
89-
* Both modes can be changed using function vl53l8ch_set_power_mode().
90+
* Both modes can be changed using function vl53l8cx_set_power_mode().
9091
*/
9192

9293
#define VL53LMZ_POWER_MODE_SLEEP ((uint8_t) 0U)
@@ -104,6 +105,7 @@ extern "C" {
104105
#define VL53LMZ_STATUS_CORRUPTED_FRAME ((uint8_t) 2U)
105106
#define VL53LMZ_STATUS_LASER_SAFETY ((uint8_t) 3U)
106107
#define VL53LMZ_STATUS_UNKNOWN_DEVICE ((uint8_t) 4U)
108+
#define VL53LMZ_STATUS_FW_CHECKSUM_FAIL ((uint8_t) 5U)
107109
#define VL53LMZ_MCU_ERROR ((uint8_t) 66U)
108110
#define VL53LMZ_STATUS_INVALID_PARAM ((uint8_t) 127U)
109111
#define VL53LMZ_STATUS_FUNC_NOT_AVAILABLE ((uint8_t) 254U)
@@ -181,6 +183,7 @@ extern "C" {
181183
#define VL53LMZ_DCI_FW_NB_TARGET ((uint16_t)0x5478U)
182184
#define VL53LMZ_DCI_RANGING_MODE ((uint16_t)0xAD30U)
183185
#define VL53LMZ_DCI_DSS_CONFIG ((uint16_t)0xAD38U)
186+
#define VL53LMZ_DCI_VHV_CONFIG ((uint16_t)0xAD60U)
184187
#define VL53LMZ_DCI_TARGET_ORDER ((uint16_t)0xAE64U)
185188
#define VL53LMZ_DCI_SHARPENER ((uint16_t)0xAED8U)
186189
#define VL53LMZ_DCI_INTERNAL_CP ((uint16_t)0xB39CU)
@@ -557,6 +560,36 @@ uint8_t vl53lmz_set_ranging_frequency_hz(
557560
VL53LMZ_Configuration *p_dev,
558561
uint8_t frequency_hz);
559562

563+
/**
564+
* @brief This function gets the current ranging frequency in Hz scaled up by
565+
* a factor of 256 to enable non-integer values to be returned.
566+
* Ranging frequency corresponds to the time between each measurement.
567+
* @param (VL53LMZ_Configuration) *p_dev : VL53LMZ configuration structure.
568+
* @param (uint8_t) *p_frequency_x256: Contains the ranging frequency scaled
569+
* to 256 x Hz.
570+
* @return (uint8_t) status : 0 if ranging frequency is OK.
571+
*/
572+
uint8_t vl53lmz_get_ranging_frequency_x256(
573+
VL53LMZ_Configuration *p_dev,
574+
uint16_t *p_frequency_x256);
575+
576+
/**
577+
* @brief This function sets a new ranging frequency in Hz scaled up by 256
578+
* to enable non-integer values to be set.
579+
* Ranging frequencycorresponds to the measurements frequency. This setting
580+
* depends on the resolution, so please select your resolution before using
581+
* this function.
582+
* @param (VL53LMZ_Configuration) *p_dev : VL53LMZ configuration structure.
583+
* @param (uint8_t) frequency_x256 : Contains the ranging frequency in Hz.
584+
* - For 4x4, min and max allowed values are : [1*256;60*256]
585+
* - For 8x8, min and max allowed values are : [1*256;15*256]
586+
* @return (uint8_t) status : 0 if ranging frequency is OK, or 127 if the value
587+
* is not correct.
588+
*/
589+
uint8_t vl53lmz_set_ranging_frequency_x256(
590+
VL53LMZ_Configuration *p_dev,
591+
uint16_t frequency_x256);
592+
560593
/**
561594
* @brief This function gets the current integration time in ms.
562595
* @param (VL53LMZ_Configuration) *p_dev : VL53LMZ configuration structure.
@@ -724,6 +757,29 @@ uint8_t vl53lmz_set_glare_filter_cfg(
724757
uint8_t threshold_pc_x10,
725758
int16_t max_range);
726759

760+
/**
761+
* @brief This function is used to get the number of frames between 2 temperature
762+
* compensation.
763+
* @param (VL53LMZ_Configuration) *p_dev : VL53LMZ configuration structure.
764+
* @param (uint32_t) *p_repeat_count : Number of frames before next temperature
765+
* compensation. Set to 0 to disable the feature (default configuration).
766+
*/
767+
uint8_t vl53lmz_get_VHV_repeat_count(
768+
VL53LMZ_Configuration *p_dev,
769+
uint32_t *p_repeat_count);
770+
771+
/**
772+
* @brief This function is used to set a periodic temperature compensation. By
773+
* setting a repeat count different to 0 the firmware automatically runs a
774+
* temperature calibration every N frames.
775+
* default the repeat count is set to 0
776+
* @param (VL53LMZ_Configuration) *p_dev : VL53LMZ configuration structure.
777+
* @param (uint32_t) repeat_count : Number of frames between temperature
778+
* compensation. Set to 0 to disable the feature (default configuration).
779+
*/
780+
uint8_t vl53lmz_set_VHV_repeat_count(
781+
VL53LMZ_Configuration *p_dev,
782+
uint32_t repeat_count);
727783

728784
/**
729785
* @brief This function can be used to read 'extra data' from DCI. Using a known

0 commit comments

Comments
 (0)