Fork from ST-Expansion-Sw-Team Repo.
Dependencies: VL53L1X_mbed
Revision 14:8320b5ff96fa, committed 2017-08-07
- Comitter:
- johnAlexander
- Date:
- Mon Aug 07 14:30:21 2017 +0000
- Parent:
- 13:615f7e38568c
- Child:
- 15:44e6c9013bff
- Child:
- 16:27d3d95c8593
- Commit message:
- Aligned to ARM mbed coding style.
Changed in this revision
--- a/Components/Display/Display_class.h Thu Jun 15 13:33:35 2017 +0000
+++ b/Components/Display/Display_class.h Mon Aug 07 14:30:21 2017 +0000
@@ -72,12 +72,12 @@
uint32_t u32; /*!< single dword i/o view */
}
/** cache the extended IO values */
-CurIOVal;
+cur_io_val;
/**
* lookup table for digit to bit position
*/
-static int DisplayBitPos[4]={0, 7, 16, 16+7};
+static int display_bit_posn[4] = {0, 7, 16, 16 + 7};
/**
* @defgroup XNUCLEO53L0A1_7Segment 7 segment display
@@ -96,22 +96,22 @@
* @{
*/
/** decimal point bit mapping* */
-#define DP (1<<7)
+#define DP (1 << 7)
/** sgement s0 bit mapping*/
-#define S0 (1<<3)
+#define S0 (1 << 3)
/** sgement s1 bit mapping*/
-#define S1 (1<<5)
+#define S1 (1 << 5)
/** sgement s2 bit mapping*/
-#define S2 (1<<6)
+#define S2 (1 << 6)
/** sgement s3 bit mapping*/
-#define S3 (1<<4)
+#define S3 (1 << 4)
/** sgement s4 bit mapping*/
-#define S4 (1<<0)
+#define S4 (1 << 0)
/** sgement s5 bit mapping*/
-#define S5 (1<<1)
+#define S5 (1 << 1)
/** sgement s6 bit mapping*/
-#define S6 (1<<2)
+#define S6 (1 << 2)
/**
* build a character by defining the non lighted segment (not one and no DP)
@@ -133,173 +133,173 @@
*/
#ifndef __cpluplus
/* refer to http://www.twyman.org.uk/Fonts/ */
-static const uint8_t ascii_to_display_lut[256]={
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- [32]= 0,
- 0,0,0,0,0,0,0,0,
- 0,
- [42]= NOT_7_NO_DP(),
- 0,0,
- [45]= S6,
- 0,0,
- [48]= NOT_7_NO_DP(S6),
- [49]= S1+S2,
- [50]= S0+S1+S6+S4+S3,
- [51]= NOT_7_NO_DP(S4+S5),
- [52]= S5+S1+S6+S2,
- [53]= NOT_7_NO_DP(S1+S4),
- [54]= NOT_7_NO_DP(S1),
- [55]= S0+S1+S2,
- [56]= NOT_7_NO_DP(0),
- [57]= NOT_7_NO_DP(S4),
- 0,0,0,
- [61]= S3+S6,
- 0,
- [63]= NOT_7_NO_DP(S5+S3+S2),
- [64]= S0+S3,
- [65]= NOT_7_NO_DP(S3),
- [66]= NOT_7_NO_DP(S0+S1), /* as b */
- [67]= S0+S3+S4+S5, // same as [
- [68]= S0+S3+S4+S5, // same as [ DUMMY
- [69]= NOT_7_NO_DP(S1+S2),
- [70]= S6+S5+S4+S0,
- [71]= NOT_7_NO_DP(S4), /* same as 9 */
- [72]= NOT_7_NO_DP(S0+S3),
- [73]= S1+S2,
- [74]= S1+S2+S3+S4,
- [75]= NOT_7_NO_DP(S0+S3), /* same as H */
- [76]= S3+S4+S5,
- [77]= S0+S4+S2, /* same as m*/
- [78]= S2+S4+S6, /* same as n*/
- [79]= NOT_7_NO_DP(S6),
- [80]= S0+S1+S2+S5+S6, // sames as 'q'
- [81]= NOT_7_NO_DP(S3+S2),
- [82]= S4+S6,
- [83]= NOT_7_NO_DP(S1+S4), /* sasme as 5 */
- [84]= NOT_7_NO_DP(S0+S1+S2), /* sasme as t */
- [85]= NOT_7_NO_DP(S6+S0),
- [86]= S4+S3+S2, // is u but u use U
- [87]= S1+S3+S5,
- [88]= NOT_7_NO_DP(S0+S3), // similar to H
- [89]= NOT_7_NO_DP(S0+S4),
- [90]= S0+S1+S6+S4+S3, // same as 2
- [91]= S0+S3+S4+S5,
- 0,
- [93]= S0+S3+S2+S1,
- [94]= S0, /* use as top bar */
- [95]= S3,
- 0,
- [97]= S2+ S3+ S4+ S6 ,
- [98]= NOT_7_NO_DP(S0+S1),
- [99]= S6+S4+S3,
- [100]= NOT_7_NO_DP(S0+S5),
- [101]= NOT_7_NO_DP(S2),
- [102]= S6+S5+S4+S0, /* same as F */
- [103]= NOT_7_NO_DP(S4), /* same as 9 */
- [104]= S6+S5+S4+S2,
- [105]= S4,
- [106]= S1+S2+S3+S4,
- [107]= S6+S5+S4+S2, /* a h */
- [108]= S3+S4,
- [109]= S0+S4+S2, /* same as */
- [110]= S2+S4+S6,
- [111]= S6+S4+S3+S2,
- [112]= NOT_7_NO_DP(S3+S2), // same as P
- [113]= S0+S1+S2+S5+S6,
- [114]= S4+S6,
- [115]= NOT_7_NO_DP(S1+S4),
- [116]= NOT_7_NO_DP(S0+S1+S2),
- [117]= S4+S3+S2+S5+S1, // U
- [118]= S4+S3+S2, // is u but u use U
- [119]= S1+S3+S5,
- [120]= NOT_7_NO_DP(S0+S3), // similar to H
- [121]= NOT_7_NO_DP(S0+S4),
- [122]= S0+S1+S6+S4+S3, // same as 2
- 0,0,0,
- [126]= S0+S3+S6 /* 3 h bar */
+static const uint8_t ascii_to_display_lut[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ [32] = 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0,
+ [42] = NOT_7_NO_DP(),
+ 0, 0,
+ [45] = S6,
+ 0, 0,
+ [48] = NOT_7_NO_DP(S6),
+ [49] = S1 + S2,
+ [50] = S0 + S1 + S6 + S4 + S3,
+ [51] = NOT_7_NO_DP(S4 + S5),
+ [52] = S5 + S1 + S6 + S2,
+ [53] = NOT_7_NO_DP(S1 + S4),
+ [54] = NOT_7_NO_DP(S1),
+ [55] = S0 + S1 + S2,
+ [56] = NOT_7_NO_DP(0),
+ [57] = NOT_7_NO_DP(S4),
+ 0, 0, 0,
+ [61] = S3 + S6,
+ 0,
+ [63] = NOT_7_NO_DP(S5 + S3 + S2),
+ [64] = S0 + S3,
+ [65] = NOT_7_NO_DP(S3),
+ [66] = NOT_7_NO_DP(S0 + S1), /* as b */
+ [67] = S0 + S3 + S4 + S5, // same as [
+ [68] = S0 + S3 + S4 + S5, // same as [ DUMMY
+ [69] = NOT_7_NO_DP(S1 + S2),
+ [70] = S6 + S5 + S4 + S0,
+ [71] = NOT_7_NO_DP(S4), /* same as 9 */
+ [72] = NOT_7_NO_DP(S0 + S3),
+ [73] = S1 + S2,
+ [74] = S1 + S2 + S3 + S4,
+ [75] = NOT_7_NO_DP(S0 + S3), /* same as H */
+ [76] = S3 + S4 + S5,
+ [77] = S0 + S4 + S2, /* same as m*/
+ [78] = S2 + S4 + S6, /* same as n*/
+ [79] = NOT_7_NO_DP(S6),
+ [80] = S0 + S1 + S2 + S5 + S6, // sames as 'q'
+ [81] = NOT_7_NO_DP(S3 + S2),
+ [82] = S4 + S6,
+ [83] = NOT_7_NO_DP(S1 + S4), /* sasme as 5 */
+ [84] = NOT_7_NO_DP(S0 + S1 + S2), /* sasme as t */
+ [85] = NOT_7_NO_DP(S6 + S0),
+ [86] = S4 + S3 + S2, // is u but u use U
+ [87] = S1 + S3 + S5,
+ [88] = NOT_7_NO_DP(S0 + S3), // similar to H
+ [89] = NOT_7_NO_DP(S0 + S4),
+ [90] = S0 + S1 + S6 + S4 + S3, // same as 2
+ [91] = S0 + S3 + S4 + S5,
+ 0,
+ [93] = S0 + S3 + S2 + S1,
+ [94] = S0, /* use as top bar */
+ [95] = S3,
+ 0,
+ [97] = S2 + S3 + S4 + S6,
+ [98] = NOT_7_NO_DP(S0 + S1),
+ [99] = S6 + S4 + S3,
+ [100] = NOT_7_NO_DP(S0 + S5),
+ [101] = NOT_7_NO_DP(S2),
+ [102] = S6 + S5 + S4 + S0, /* same as F */
+ [103] = NOT_7_NO_DP(S4), /* same as 9 */
+ [104] = S6 + S5 + S4 + S2,
+ [105] = S4,
+ [106] = S1 + S2 + S3 + S4,
+ [107] = S6 + S5 + S4 + S2, /* a h */
+ [108] = S3 + S4,
+ [109] = S0 + S4 + S2, /* same as */
+ [110] = S2 + S4 + S6,
+ [111] = S6 + S4 + S3 + S2,
+ [112] = NOT_7_NO_DP(S3 + S2), // same as P
+ [113] = S0 + S1 + S2 + S5 + S6,
+ [114] = S4 + S6,
+ [115] = NOT_7_NO_DP(S1 + S4),
+ [116] = NOT_7_NO_DP(S0 + S1 + S2),
+ [117] = S4 + S3 + S2 + S5 + S1, // U
+ [118] = S4 + S3 + S2, // is u but u use U
+ [119] = S1 + S3 + S5,
+ [120] = NOT_7_NO_DP(S0 + S3), // similar to H
+ [121] = NOT_7_NO_DP(S0 + S4),
+ [122] = S0 + S1 + S6 + S4 + S3, // same as 2
+ 0, 0, 0,
+ [126] = S0 + S3 + S6 /* 3 h bar */
};
#else
/* refer to http://www.twyman.org.uk/Fonts/ */
-static const uint8_t ascii_to_display_lut[256]={
- [' ']= 0,
- ['-']= S6,
- ['_']= S3,
- ['=']= S3+S6,
- ['~']= S0+S3+S6, /* 3 h bar */
- ['^']= S0, /* use as top bar */
+static const uint8_t ascii_to_display_lut[256] = {
+ [' '] = 0,
+ ['-'] = S6,
+ ['_'] = S3,
+ ['='] = S3 + S6,
+ ['~'] = S0 + S3 + S6, /* 3 h bar */
+ ['^'] = S0, /* use as top bar */
- ['?']= NOT_7_NO_DP(S5+S3+S2),
- ['*']= NOT_7_NO_DP(),
- ['[']= S0+S3+S4+S5,
- [']']= S0+S3+S2+S1,
- ['@']= S0+S3,
+ ['?'] = NOT_7_NO_DP(S5 + S3 + S2),
+ ['*'] = NOT_7_NO_DP(),
+ ['['] = S0 + S3 + S4 + S5,
+ [']'] = S0 + S3 + S2 + S1,
+ ['@'] = S0 + S3,
- ['0']= NOT_7_NO_DP(S6),
- ['1']= S1+S2,
- ['2']= S0+S1+S6+S4+S3,
- ['3']= NOT_7_NO_DP(S4+S5),
- ['4']= S5+S1+S6+S2,
- ['5']= NOT_7_NO_DP(S1+S4),
- ['6']= NOT_7_NO_DP(S1),
- ['7']= S0+S1+S2,
- ['8']= NOT_7_NO_DP(0),
- ['9']= NOT_7_NO_DP(S4),
+ ['0'] = NOT_7_NO_DP(S6),
+ ['1'] = S1 + S2,
+ ['2'] = S0 + S1 + S6 + S4 + S3,
+ ['3'] = NOT_7_NO_DP(S4 + S5),
+ ['4'] = S5 + S1 + S6 + S2,
+ ['5'] = NOT_7_NO_DP(S1 + S4),
+ ['6'] = NOT_7_NO_DP(S1),
+ ['7'] = S0 + S1 + S2,
+ ['8'] = NOT_7_NO_DP(0),
+ ['9'] = NOT_7_NO_DP(S4),
- ['a']= S2+ S3+ S4+ S6 ,
- ['b']= NOT_7_NO_DP(S0+S1),
- ['c']= S6+S4+S3,
- ['d']= NOT_7_NO_DP(S0+S5),
- ['e']= NOT_7_NO_DP(S2),
- ['f']= S6+S5+S4+S0, /* same as F */
- ['g']= NOT_7_NO_DP(S4), /* same as 9 */
- ['h']= S6+S5+S4+S2,
- ['i']= S4,
- ['j']= S1+S2+S3+S4,
- ['k']= S6+S5+S4+S2, /* a h */
- ['l']= S3+S4,
- ['m']= S0+S4+S2, /* same as */
- ['n']= S2+S4+S6,
- ['o']= S6+S4+S3+S2,
- ['p']= NOT_7_NO_DP(S3+S2), // same as P
- ['q']= S0+S1+S2+S5+S6,
- ['r']= S4+S6,
- ['s']= NOT_7_NO_DP(S1+S4),
- ['t']= NOT_7_NO_DP(S0+S1+S2),
- ['u']= S4+S3+S2+S5+S1, // U
- ['v']= S4+S3+S2, // is u but u use U
- ['w']= S1+S3+S5,
- ['x']= NOT_7_NO_DP(S0+S3), // similar to H
- ['y']= NOT_7_NO_DP(S0+S4),
- ['z']= S0+S1+S6+S4+S3, // same as 2
+ ['a'] = S2 + S3 + S4 + S6,
+ ['b'] = NOT_7_NO_DP(S0 + S1),
+ ['c'] = S6 + S4 + S3,
+ ['d'] = NOT_7_NO_DP(S0 + S5),
+ ['e'] = NOT_7_NO_DP(S2),
+ ['f'] = S6 + S5 + S4 + S0, /* same as F */
+ ['g'] = NOT_7_NO_DP(S4), /* same as 9 */
+ ['h'] = S6 + S5 + S4 + S2,
+ ['i'] = S4,
+ ['j'] = S1 + S2 + S3 + S4,
+ ['k'] = S6 + S5 + S4 + S2, /* a h */
+ ['l'] = S3 + S4,
+ ['m'] = S0 + S4 + S2, /* same as */
+ ['n'] = S2 + S4 + S6,
+ ['o'] = S6 + S4 + S3 + S2,
+ ['p'] = NOT_7_NO_DP(S3 + S2), // same as P
+ ['q'] = S0 + S1 + S2 + S5 + S6,
+ ['r'] = S4 + S6,
+ ['s'] = NOT_7_NO_DP(S1 + S4),
+ ['t'] = NOT_7_NO_DP(S0 + S1 + S2),
+ ['u'] = S4 + S3 + S2 + S5 + S1, // U
+ ['v'] = S4 + S3 + S2, // is u but u use U
+ ['w'] = S1 + S3 + S5,
+ ['x'] = NOT_7_NO_DP(S0 + S3), // similar to H
+ ['y'] = NOT_7_NO_DP(S0 + S4),
+ ['z'] = S0 + S1 + S6 + S4 + S3, // same as 2
- ['A']= NOT_7_NO_DP(S3),
- ['B']= NOT_7_NO_DP(S0+S1), /* as b */
- ['C']= S0+S3+S4+S5, // same as [
- ['E']= NOT_7_NO_DP(S1+S2),
- ['F']= S6+S5+S4+S0,
- ['G']= NOT_7_NO_DP(S4), /* same as 9 */
- ['H']= NOT_7_NO_DP(S0+S3),
- ['I']= S1+S2,
- ['J']= S1+S2+S3+S4,
- ['K']= NOT_7_NO_DP(S0+S3), /* same as H */
- ['L']= S3+S4+S5,
- ['M']= S0+S4+S2, /* same as m*/
- ['N']= S2+S4+S6, /* same as n*/
- ['O']= NOT_7_NO_DP(S6),
- ['P']= S0+S1+S2+S5+S6, // sames as 'q'
- ['Q']= NOT_7_NO_DP(S3+S2),
- ['R']= S4+S6,
- ['S']= NOT_7_NO_DP(S1+S4), /* sasme as 5 */
- ['T']= NOT_7_NO_DP(S0+S1+S2), /* sasme as t */
- ['U']= NOT_7_NO_DP(S6+S0),
- ['V']= S4+S3+S2, // is u but u use U
- ['W']= S1+S3+S5,
- ['X']= NOT_7_NO_DP(S0+S3), // similar to H
- ['Y']= NOT_7_NO_DP(S0+S4),
- ['Z']= S0+S1+S6+S4+S3 // same as 2
+ ['A'] = NOT_7_NO_DP(S3),
+ ['B'] = NOT_7_NO_DP(S0 + S1), /* as b */
+ ['C'] = S0 + S3 + S4 + S5, // same as [
+ ['E'] = NOT_7_NO_DP(S1 + S2),
+ ['F'] = S6 + S5 + S4 + S0,
+ ['G'] = NOT_7_NO_DP(S4), /* same as 9 */
+ ['H'] = NOT_7_NO_DP(S0 + S3),
+ ['I'] = S1 + S2,
+ ['J'] = S1 + S2 + S3 + S4,
+ ['K'] = NOT_7_NO_DP(S0 + S3), /* same as H */
+ ['L'] = S3 + S4 + S5,
+ ['M'] = S0 + S4 + S2, /* same as m*/
+ ['N'] = S2 + S4 + S6, /* same as n*/
+ ['O'] = NOT_7_NO_DP(S6),
+ ['P'] = S0 + S1 + S2 + S5 + S6, // sames as 'q'
+ ['Q'] = NOT_7_NO_DP(S3 + S2),
+ ['R'] = S4 + S6,
+ ['S'] = NOT_7_NO_DP(S1 + S4), /* sasme as 5 */
+ ['T'] = NOT_7_NO_DP(S0 + S1 + S2), /* sasme as t */
+ ['U'] = NOT_7_NO_DP(S6 + S0),
+ ['V'] = S4 + S3 + S2, // is u but u use U
+ ['W'] = S1 + S3 + S5,
+ ['X'] = NOT_7_NO_DP(S0 + S3), // similar to H
+ ['Y'] = NOT_7_NO_DP(S0 + S4),
+ ['Z'] = S0 + S1 + S6 + S4 + S3 // same as 2
};
#endif
@@ -315,89 +315,91 @@
/** @} */
-//#define DISPLAY_DELAY 1 // in mSec
+//#define DISPLAY_DELAY 1 // in mSec
/* Classes -------------------------------------------------------------------*/
/** Class representing Display
- */
+ */
class Display
{
private:
- STMPE1600 &stmpe1600_exp0;
- STMPE1600 &stmpe1600_exp1;
+ Stmpe1600 &stmpe1600_exp0;
+ Stmpe1600 &stmpe1600_exp1;
public:
- /** Constructor
- * @param[in] &stmpe_1600 device handler to be used for display control
- */
- Display (STMPE1600 &stmpe_1600_exp0, STMPE1600 &stmpe_1600_exp1) : stmpe1600_exp0(stmpe_1600_exp0), stmpe1600_exp1(stmpe_1600_exp1) {
- uint16_t ExpanderData;
+ /** Constructor
+ * @param[in] &stmpe_1600 device handler to be used for display control
+ */
+ Display(Stmpe1600 &stmpe_1600_exp0, Stmpe1600 &stmpe_1600_exp1) : stmpe1600_exp0(stmpe_1600_exp0),
+ stmpe1600_exp1(stmpe_1600_exp1)
+ {
+ uint16_t expander_data;
// detect the extenders
- stmpe1600_exp0.read16bitReg(0x00, &ExpanderData);
+ stmpe1600_exp0.read_16bit_reg(0x00, &expander_data);
// if (ExpanderData != 0x1600) {/* log - failed to find expander exp0 */ }
- stmpe1600_exp1.read16bitReg(0x00, &ExpanderData);
+ stmpe1600_exp1.read_16bit_reg(0x00, &expander_data);
// if (ExpanderData != 0x1600) {/* log - failed to find expander exp1 */ }
// configure all necessary GPIO pins as outputs
- ExpanderData = 0xFFFF;
- stmpe1600_exp0.write16bitReg(GPDR, &ExpanderData);
- ExpanderData = 0xBFFF; // leave bit 14 as an input, for the pushbutton, PB1.
- stmpe1600_exp1.write16bitReg(GPDR, &ExpanderData);
+ expander_data = 0xFFFF;
+ stmpe1600_exp0.write_16bit_reg(GPDR, &expander_data);
+ expander_data = 0xBFFF; // leave bit 14 as an input, for the pushbutton, PB1.
+ stmpe1600_exp1.write_16bit_reg(GPDR, &expander_data);
// shut down all segment and all device
- ExpanderData = 0x7F + (0x7F << 7);
- stmpe1600_exp0.write16bitReg(GPSR, &ExpanderData);
- stmpe1600_exp1.write16bitReg(GPSR, &ExpanderData);
+ expander_data = 0x7F + (0x7F << 7);
+ stmpe1600_exp0.write_16bit_reg(GPSR, &expander_data);
+ stmpe1600_exp1.write_16bit_reg(GPSR, &expander_data);
}
-
- /*** Interface Methods ***/
- /**
- * @brief Print the string on display
- * @param[in] String to be printed
- * @param[in] String lenght [min 1, max 4]
- * @return void
- */
- void DisplayString (const char *str)
+
+ /*** Interface Methods ***/
+ /**
+ * @brief Print the string on display
+ * @param[in] String to be printed
+ * @param[in] String lenght [min 1, max 4]
+ * @return void
+ */
+ void display_string(const char *str)
{
- uint16_t ExpanderData;
- uint32_t Segments;
- int BitPos;
+ uint16_t expander_data;
+ uint32_t segments;
+ int bit_posn;
int i;
- for( i=0; i<4 && str[i]!=0; i++){
- Segments = (uint32_t)ascii_to_display_lut[(uint8_t)str[i]];
- Segments =(~Segments)&0x7F;
- BitPos=DisplayBitPos[i];
- CurIOVal.u32 &=~(0x7F<<BitPos);
- CurIOVal.u32 |= Segments<<BitPos;
+ for (i = 0; (i < 4 && str[i] != 0); i++) {
+ segments = (uint32_t) ascii_to_display_lut[(uint8_t) str[i]];
+ segments = (~segments) & 0x7F;
+ bit_posn = display_bit_posn[i];
+ cur_io_val.u32 &= ~(0x7F << bit_posn);
+ cur_io_val.u32 |= segments << bit_posn;
}
/* clear unused digit */
- for( ; i<4;i++){
- BitPos=DisplayBitPos[i];
- CurIOVal.u32 |=0x7F<<BitPos;
+ for (; i < 4; i++) {
+ bit_posn = display_bit_posn[i];
+ cur_io_val.u32 |= 0x7F << bit_posn;
}
// stmpe1600_exp0.write16bitReg(GPSR, (uint16_t *)&CurIOVal.bytes[0]);
// stmpe1600_exp1.write16bitReg(GPSR, (uint16_t *)&CurIOVal.bytes[2]);
// ordered low-byte/high-byte!
- CurIOVal.bytes[1] |= 0xC0; // ensure highest bits are high, as these are xshutdown pins for left & right sensors!
- ExpanderData = (CurIOVal.bytes[1] << 8) + CurIOVal.bytes[0];
- stmpe1600_exp0.write16bitReg(GPSR, &ExpanderData);
- CurIOVal.bytes[3] |= 0x80; // ensure highest bit is high, as this is xshutdown pin on central sensor!
- ExpanderData = (CurIOVal.bytes[3] << 8) + CurIOVal.bytes[2];
- stmpe1600_exp1.write16bitReg(GPSR, &ExpanderData);
+ cur_io_val.bytes[1] |= 0xC0; // ensure highest bits are high, as these are xshutdown pins for left & right sensors!
+ expander_data = (cur_io_val.bytes[1] << 8) + cur_io_val.bytes[0];
+ stmpe1600_exp0.write_16bit_reg(GPSR, &expander_data);
+ cur_io_val.bytes[3] |= 0x80; // ensure highest bit is high, as this is xshutdown pin on central sensor!
+ expander_data = (cur_io_val.bytes[3] << 8) + cur_io_val.bytes[2];
+ stmpe1600_exp1.write_16bit_reg(GPSR, &expander_data);
}
- void ClearDisplay(void)
+ void clear_display(void)
{
- uint16_t ExpanderData;
+ uint16_t expander_data;
- ExpanderData = 0x7F + (0x7F << 7);
- stmpe1600_exp0.write16bitReg(GPSR, &ExpanderData);
- stmpe1600_exp1.write16bitReg(GPSR, &ExpanderData);
+ expander_data = 0x7F + (0x7F << 7);
+ stmpe1600_exp0.write_16bit_reg(GPSR, &expander_data);
+ stmpe1600_exp1.write_16bit_reg(GPSR, &expander_data);
}
};
--- a/Components/STMPE1600/stmpe1600_class.h Thu Jun 15 13:33:35 2017 +0000
+++ b/Components/STMPE1600/stmpe1600_class.h Mon Aug 07 14:30:21 2017 +0000
@@ -39,17 +39,17 @@
/* Includes ------------------------------------------------------------------*/
#include "DevI2C.h"
-#define STMPE1600_DEF_DEVICE_ADDRESS (uint8_t)0x42*2
+#define STMPE1600_DEF_DEVICE_ADDRESS (uint8_t)0x42*2
#define STMPE1600_DEF_DIGIOUT_LVL 1
/** STMPE1600 registr map **/
-#define ChipID_0_7 (uint8_t)0x00
-#define ChipID_8_15 (uint8_t)0x01
-#define VersionId (uint8_t)0x02
-#define SYS_CTRL (uint8_t)0x03
-#define IEGPIOR_0_7 (uint8_t)0x08
+#define CHIP_ID_0_7 (uint8_t)0x00
+#define CHIP_ID_8_15 (uint8_t)0x01
+#define VERSION_ID (uint8_t)0x02
+#define SYS_CTRL (uint8_t)0x03
+#define IEGPIOR_0_7 (uint8_t)0x08
#define IEGPIOR_8_15 (uint8_t)0x09
-#define ISGPIOR_0_7 (uint8_t)0x0A
+#define ISGPIOR_0_7 (uint8_t)0x0A
#define ISGPIOR_8_15 (uint8_t)0x0B
#define GPMR_0_7 (uint8_t)0x10
#define GPMR_8_15 (uint8_t)0x11
@@ -60,250 +60,270 @@
#define GPIR_0_7 (uint8_t)0x16
#define GPIR_8_15 (uint8_t)0x17
-#define SOFT_RESET (uint8_t)0x80
+#define SOFT_RESET (uint8_t)0x80
- typedef enum {
+typedef enum {
// GPIO Expander pin names
- GPIO_0=0,
+ GPIO_0 = 0,
GPIO_1,
GPIO_2,
- GPIO_3,
+ GPIO_3,
GPIO_4,
GPIO_5,
GPIO_6,
- GPIO_7,
+ GPIO_7,
GPIO_8,
GPIO_9,
GPIO_10,
- GPIO_11,
+ GPIO_11,
GPIO_12,
GPIO_13,
GPIO_14,
GPIO_15,
- NOT_CON
-} ExpGpioPinName;
+ NOT_CON
+} ExpGpioPinName;
typedef enum {
INPUT = 0,
OUTPUT,
NOT_CONNECTED
-}ExpGpioPinDirection;
+} ExpGpioPinDirection;
/* Classes -------------------------------------------------------------------*/
/** Class representing a single stmpe1600 GPIO expander output pin
*/
-class STMPE1600DigiOut {
-
- public:
+class Stmpe1600DigiOut
+{
+
+public:
/** Constructor
* @param[in] &i2c device I2C to be used for communication
* @param[in] outpinname the desired out pin name to be created
- * @param[in] DevAddr the stmpe1600 I2C device addres (deft STMPE1600_DEF_DEVICE_ADDRESS)
- * @param[in] lvl the default ot pin level
- */
- STMPE1600DigiOut (DevI2C &i2c, ExpGpioPinName outpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS, bool lvl=STMPE1600_DEF_DIGIOUT_LVL): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(outpinname)
+ * @param[in] DevAddr the stmpe1600 I2C device address (deft STMPE1600_DEF_DEVICE_ADDRESS)
+ * @param[in] lvl the default ot pin level
+ */
+ Stmpe1600DigiOut(DevI2C &i2c, ExpGpioPinName out_pin_name, uint8_t dev_addr = STMPE1600_DEF_DEVICE_ADDRESS,
+ bool lvl = STMPE1600_DEF_DIGIOUT_LVL) : dev_i2c(i2c), exp_dev_addr(dev_addr), exp_pin_name(out_pin_name)
{
- uint8_t data[2];
- if (exppinname == NOT_CON) return;
- /* set the exppinname as output */
- dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 1);
- dev_i2c.i2c_read(&data[1], expdevaddr, GPDR_8_15, 1);
- *(uint16_t*)data = *(uint16_t*)data | (1<<(uint16_t)exppinname); // set gpio as out
- dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 1);
- dev_i2c.i2c_write(&data[1], expdevaddr, GPDR_8_15, 1);
- write(lvl);
- }
+ uint8_t data[2];
- /**
- * @brief Write on the out pin
- * @param[in] lvl level to write
- * @return 0 on Success
- */
- void write (int lvl)
- {
- uint8_t data[2];
- if (exppinname == NOT_CON) return;
- /* set the exppinname state to lvl */
- dev_i2c.i2c_read(data, expdevaddr, GPSR_0_7, 2);
- *(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname)); // set pin mask
- if (lvl) *(uint16_t*)data = *(uint16_t*)data | (uint16_t)(1<<(uint16_t)exppinname);
- dev_i2c.i2c_write(data, expdevaddr, GPSR_0_7, 2);
+ if (exp_pin_name == NOT_CON)
+ return;
+ /* set the exp_pin_name as output */
+ dev_i2c.i2c_read(data, exp_dev_addr, GPDR_0_7, 1);
+ dev_i2c.i2c_read(&data[1], exp_dev_addr, GPDR_8_15, 1);
+ * (uint16_t *) data = * (uint16_t *) data | (1 << (uint16_t) exp_pin_name); // set gpio as out
+ dev_i2c.i2c_write(data, exp_dev_addr, GPDR_0_7, 1);
+ dev_i2c.i2c_write(&data[1], exp_dev_addr, GPDR_8_15, 1);
+ write(lvl);
}
- /**
- * @brief Overload assignement operator
- */
- STMPE1600DigiOut& operator=(int lvl)
+ /**
+ * @brief Write on the out pin
+ * @param[in] lvl level to write
+ * @return 0 on Success
+ */
+ void write(int lvl)
{
- write (lvl);
- return *this;
- }
-
- private:
- DevI2C &dev_i2c;
- uint8_t expdevaddr;
- ExpGpioPinName exppinname;
+ uint8_t data[2];
+
+ if (exp_pin_name == NOT_CON)
+ return;
+ /* set the exp_pin_name state to lvl */
+ dev_i2c.i2c_read(data, exp_dev_addr, GPSR_0_7, 2);
+ * (uint16_t *) data = * (uint16_t *) data & (uint16_t)(~(1 << (uint16_t) exp_pin_name)); // set pin mask
+ if (lvl)
+ * (uint16_t *) data = * (uint16_t *) data | (uint16_t)(1 << (uint16_t) exp_pin_name);
+ dev_i2c.i2c_write(data, exp_dev_addr, GPSR_0_7, 2);
+ }
+
+ /**
+ * @brief Overload assignement operator
+ */
+ Stmpe1600DigiOut &operator= (int lvl)
+ {
+ write(lvl);
+ return *this;
+ }
+
+private:
+ DevI2C &dev_i2c;
+ uint8_t exp_dev_addr;
+ ExpGpioPinName exp_pin_name;
};
/* Classes -------------------------------------------------------------------*/
/** Class representing a single stmpe1600 GPIO expander input pin
*/
-class STMPE1600DigiIn
-{
- public:
- /** Constructor
- * @param[in] &i2c device I2C to be used for communication
- * @param[in] inpinname the desired input pin name to be created
- * @param[in] DevAddr the stmpe1600 I2C device addres (deft STMPE1600_DEF_DEVICE_ADDRESS)
- */
- STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(inpinname)
+class Stmpe1600DigiIn
+{
+public:
+ /** Constructor
+ * @param[in] &i2c device I2C to be used for communication
+ * @param[in] inpinname the desired input pin name to be created
+ * @param[in] DevAddr the stmpe1600 I2C device addres (deft STMPE1600_DEF_DEVICE_ADDRESS)
+ */
+ Stmpe1600DigiIn(DevI2C &i2c, ExpGpioPinName in_pin_name,
+ uint8_t dev_addr = STMPE1600_DEF_DEVICE_ADDRESS) : dev_i2c(i2c), exp_dev_addr(dev_addr),
+ exp_pin_name(in_pin_name)
{
- uint8_t data[2];
- if (exppinname == NOT_CON) return;
- /* set the exppinname as input pin direction */
- dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 2);
- *(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname)); // set gpio as in
- dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 2);
- }
+ uint8_t data[2];
+
+ if (exp_pin_name == NOT_CON)
+ return;
+ /* set the exp_pin_name as input pin direction */
+ dev_i2c.i2c_read(data, exp_dev_addr, GPDR_0_7, 2);
+ * (uint16_t *) data = * (uint16_t *) data & (uint16_t)(~(1 << (uint16_t) exp_pin_name)); // set gpio as in
+ dev_i2c.i2c_write(data, exp_dev_addr, GPDR_0_7, 2);
+ }
- /**
- * @brief Read the input pin
- * @return The pin logical state 0 or 1
- */
- bool read ()
+ /**
+ * @brief Read the input pin
+ * @return The pin logical state 0 or 1
+ */
+ bool read()
{
- uint8_t data[2];
- if (exppinname == NOT_CON) return 0;
- /* read the exppinname */
- dev_i2c.i2c_read(data, expdevaddr, GPMR_0_7, 2);
- *(uint16_t*)data = *(uint16_t*)data & (uint16_t)(1<<(uint16_t)exppinname); // mask the in gpio
- if (data[0] || data[1]) return 1;
- return 0;
+ uint8_t data[2];
+
+ if (exp_pin_name == NOT_CON)
+ return false;
+ /* read the exp_pin_name */
+ dev_i2c.i2c_read(data, exp_dev_addr, GPMR_0_7, 2);
+ * (uint16_t *) data = * (uint16_t *) data & (uint16_t)(1 << (uint16_t) exp_pin_name); // mask the in gpio
+ if (data[0] || data[1])
+ return true;
+ return false;
}
-
- operator int()
- {
- return read();
- }
-
- private:
- DevI2C &dev_i2c;
- uint8_t expdevaddr;
- ExpGpioPinName exppinname;
+
+ operator int()
+ {
+ return read();
+ }
+
+private:
+ DevI2C &dev_i2c;
+ uint8_t exp_dev_addr;
+ ExpGpioPinName exp_pin_name;
};
/* Classes -------------------------------------------------------------------*/
/** Class representing a whole stmpe1600 component (16 gpio)
*/
-class STMPE1600 {
-
- public:
+class Stmpe1600
+{
+
+public:
/** Constructor
* @param[in] &i2c device I2C to be used for communication
* @param[in] DevAddr the stmpe1600 I2C device addres (deft STMPE1600_DEF_DEVICE_ADDRESS)
- */
- STMPE1600 (DevI2C &i2c, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS ) : dev_i2c(i2c)
- {
- dev_i2c = i2c;
- expdevaddr = DevAddr;
- writeSYS_CTRL (SOFT_RESET);
-
- GPDR0_15 = (uint16_t)0; // gpio dir all IN
- write16bitReg (GPDR_0_7, &GPDR0_15);
- GPSR0_15 = (uint16_t)0x0ffff; // gpio status all 1
- write16bitReg (GPSR_0_7, &GPSR0_15);
+ */
+ Stmpe1600(DevI2C &i2c, uint8_t dev_addr = STMPE1600_DEF_DEVICE_ADDRESS) : dev_i2c(i2c)
+ {
+ dev_i2c = i2c;
+ exp_dev_addr = dev_addr;
+ write_sys_ctrl(SOFT_RESET);
+
+ gpdr0_15 = (uint16_t) 0; // gpio dir all IN
+ write_16bit_reg(GPDR_0_7, &gpdr0_15);
+ gpsr0_15 = (uint16_t) 0x0ffff; // gpio status all 1
+ write_16bit_reg(GPSR_0_7, &gpsr0_15);
+ }
+
+ /**
+ * @brief Write the SYS_CTRL register
+ * @param[in] Data to be written (bit fields)
+ */
+ void write_sys_ctrl(uint8_t data) // data = SOFT_RESET reset the device
+ {
+ dev_i2c.i2c_write(&data, exp_dev_addr, SYS_CTRL, 1);
+ }
+
+ /**
+ * @brief Set the out pin
+ * @param[in] The pin name
+ * @return 0 on Success
+ */
+ bool set_gpio(ExpGpioPinName pin_name)
+ {
+ if (pin_name == NOT_CON)
+ return true;
+ gpsr0_15 = gpsr0_15 | ((uint16_t) 0x0001 << pin_name);
+ write_16bit_reg(GPSR_0_7, &gpsr0_15);
+ return false;
+ }
+
+ /**
+ * @brief Clear the out pin
+ * @param[in] The pin name
+ * @return 0 on Success
+ */
+ bool clear_gpio(ExpGpioPinName pin_name)
+ {
+ if (pin_name == NOT_CON)
+ return true;
+ gpsr0_15 = gpsr0_15 & (~((uint16_t) 0x0001 << pin_name));
+ write_16bit_reg(GPSR_0_7, &gpsr0_15);
+ return false;
}
- /**
- * @brief Write the SYS_CTRL register
- * @param[in] Data to be written (bit fields)
- */
- void writeSYS_CTRL (uint8_t data) // data = SOFT_RESET reset the device
+ /**
+ * @brief Read the input pin
+ * @param[in] The pin name
+ * @return The logical pin level
+ */
+ bool read_gpio(ExpGpioPinName pin_name)
{
- dev_i2c.i2c_write(&data, expdevaddr, SYS_CTRL, 1);
+ uint16_t gpmr0_15;
+ if (pin_name == NOT_CON)
+ return true;
+ read_16bit_reg(GPMR_0_7, &gpmr0_15);
+ gpmr0_15 = gpmr0_15 & ((uint16_t) 0x0001 << pin_name);
+ if (gpmr0_15)
+ return true;
+ return false;
}
-
- /**
- * @brief Set the out pin
- * @param[in] The pin name
- * @return 0 on Success
- */
- bool setGPIO (ExpGpioPinName PinName)
- {
- if (PinName == NOT_CON) return true;
- GPSR0_15 = GPSR0_15 | ((uint16_t)0x0001<<PinName);
- write16bitReg (GPSR_0_7 , &GPSR0_15);
- return false;
- }
-
- /**
- * @brief Clear the out pin
- * @param[in] The pin name
- * @return 0 on Success
- */
- bool clrGPIO (ExpGpioPinName PinName)
- {
- if (PinName == NOT_CON) return true;
- GPSR0_15 = GPSR0_15 & (~((uint16_t)0x0001<<PinName));
- write16bitReg (GPSR_0_7 , &GPSR0_15);
- return false;
- }
-
- /**
- * @brief Read the input pin
- * @param[in] The pin name
- * @return The logical pin level
- */
- bool rdGPIO (ExpGpioPinName PinName)
- {
- uint16_t gpmr0_15;
- if (PinName == NOT_CON) return true;
- read16bitReg (GPMR_0_7, &gpmr0_15);
- gpmr0_15 = gpmr0_15 & ((uint16_t)0x0001<<PinName);
- if (gpmr0_15) return true;
- return false;
- }
-
- /**
- * @brief Set the pin direction
- * @param[in] The pin name
- * @param[in] The pin direction
- * @return 0 on success
- */
- bool setGPIOdir (ExpGpioPinName PinName, ExpGpioPinDirection PinDir)
- {
- if (PinName == NOT_CON || PinDir == NOT_CONNECTED) return true;
- GPDR0_15 = GPDR0_15 & (~((uint16_t)0x0001<<PinName)); // clear the Pin
- GPDR0_15 = GPDR0_15 | ((uint16_t)PinDir<<PinName);
- write16bitReg (GPDR_0_7 , &GPDR0_15);
- return false;
- }
+
+ /**
+ * @brief Set the pin direction
+ * @param[in] The pin name
+ * @param[in] The pin direction
+ * @return 0 on success
+ */
+ bool set_gpio_dir(ExpGpioPinName pin_name, ExpGpioPinDirection pin_dir)
+ {
+ if (pin_name == NOT_CON || pin_dir == NOT_CONNECTED)
+ return true;
+ gpdr0_15 = gpdr0_15 & (~((uint16_t) 0x0001 << pin_name)); // clear the Pin
+ gpdr0_15 = gpdr0_15 | ((uint16_t) pin_dir << pin_name);
+ write_16bit_reg(GPDR_0_7, &gpdr0_15);
+ return false;
+ }
- /**
- * @brief Read a 16 bits register
- * @param[in] The register address
- * @param[in] The pointer to the read data
- */
- void read16bitReg (uint8_t Reg16Addr, uint16_t *Reg16Data)
+ /**
+ * @brief Read a 16 bits register
+ * @param[in] The register address
+ * @param[in] The pointer to the read data
+ */
+ void read_16bit_reg(uint8_t reg16_addr, uint16_t *reg16_data)
{
- dev_i2c.i2c_read((uint8_t*)Reg16Data, expdevaddr, Reg16Addr, 2);
- }
+ dev_i2c.i2c_read((uint8_t *) reg16_data, exp_dev_addr, reg16_addr, 2);
+ }
- /**
- * @brief Write a 16 bits register
- * @param[in] The register address
- * @param[in] The pointer to the data to be written
- */
- void write16bitReg (uint8_t Reg16Addr, uint16_t *Reg16Data)
+ /**
+ * @brief Write a 16 bits register
+ * @param[in] The register address
+ * @param[in] The pointer to the data to be written
+ */
+ void write_16bit_reg(uint8_t reg16_addr, uint16_t *reg16_data)
{
- dev_i2c.i2c_write((uint8_t*)Reg16Data, expdevaddr, Reg16Addr, 2);
- }
+ dev_i2c.i2c_write((uint8_t *) reg16_data, exp_dev_addr, reg16_addr, 2);
+ }
- private:
- DevI2C &dev_i2c;
- uint16_t GPDR0_15; // local copy of bit direction reg
- uint16_t GPSR0_15; // local copy of bit status reg
- uint8_t expdevaddr; // expander device i2c addr
+private:
+ DevI2C &dev_i2c;
+ uint16_t gpdr0_15; // local copy of bit direction reg
+ uint16_t gpsr0_15; // local copy of bit status reg
+ uint8_t exp_dev_addr; // expander device i2c addr
};
#endif // __STMPE1600_CLASS
--- a/Components/VL53L0X/vl53l0x_class.cpp Thu Jun 15 13:33:35 2017 +0000
+++ b/Components/VL53L0X/vl53l0x_class.cpp Mon Aug 07 14:30:21 2017 +0000
@@ -34,7 +34,7 @@
*
******************************************************************************
*/
-
+
/* Includes */
#include <stdlib.h>
@@ -49,13 +49,13 @@
/****************** define for i2c configuration *******************************/
-
+
#define TEMP_BUF_SIZE 64
/** Maximum buffer size to be used in i2c */
#define VL53L0X_MAX_I2C_XFER_SIZE 64 /* Maximum buffer size to be used in i2c */
#define VL53L0X_I2C_USER_VAR /* none but could be for a flag var to get/pass to mutex interruptible return flags and try again */
-
+
#define LOG_FUNCTION_START(fmt, ...) \
_LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__)
@@ -74,1748 +74,1750 @@
#define REF_ARRAY_SPAD_10 10
uint32_t refArrayQuadrants[4] = {REF_ARRAY_SPAD_10, REF_ARRAY_SPAD_5,
- REF_ARRAY_SPAD_0, REF_ARRAY_SPAD_5 };
-
-
-
-
-VL53L0X_Error VL53L0X::VL53L0X_device_read_strobe(VL53L0X_DEV Dev)
+ REF_ARRAY_SPAD_0, REF_ARRAY_SPAD_5
+ };
+
+
+
+
+VL53L0X_Error VL53L0X::vl53l0x_device_read_strobe(VL53L0X_DEV dev)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t strobe;
- uint32_t LoopNb;
- LOG_FUNCTION_START("");
-
- Status |= VL53L0X_WrByte(Dev, 0x83, 0x00);
-
- /* polling
- * use timeout to avoid deadlock*/
- if (Status == VL53L0X_ERROR_NONE) {
- LoopNb = 0;
- do {
- Status = VL53L0X_RdByte(Dev, 0x83, &strobe);
- if ((strobe != 0x00) || Status != VL53L0X_ERROR_NONE)
- break;
-
- LoopNb = LoopNb + 1;
- } while (LoopNb < VL53L0X_DEFAULT_MAX_LOOP);
-
- if (LoopNb >= VL53L0X_DEFAULT_MAX_LOOP)
- Status = VL53L0X_ERROR_TIME_OUT;
-
- }
-
- Status |= VL53L0X_WrByte(Dev, 0x83, 0x01);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t strobe;
+ uint32_t loop_nb;
+ LOG_FUNCTION_START("");
+
+ status |= vl53l0x_write_byte(dev, 0x83, 0x00);
+
+ /* polling
+ * use timeout to avoid deadlock*/
+ if (status == VL53L0X_ERROR_NONE) {
+ loop_nb = 0;
+ do {
+ status = vl53l0x_read_byte(dev, 0x83, &strobe);
+ if ((strobe != 0x00) || status != VL53L0X_ERROR_NONE)
+ break;
+
+ loop_nb = loop_nb + 1;
+ } while (loop_nb < VL53L0X_DEFAULT_MAX_LOOP);
+
+ if (loop_nb >= VL53L0X_DEFAULT_MAX_LOOP)
+ status = VL53L0X_ERROR_TIME_OUT;
+
+ }
+
+ status |= vl53l0x_write_byte(dev, 0x83, 0x01);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_get_info_from_device(VL53L0X_DEV Dev, uint8_t option)
+VL53L0X_Error VL53L0X::vl53l0x_get_info_from_device(VL53L0X_DEV dev, uint8_t option)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t byte;
- uint32_t TmpDWord;
- uint8_t ModuleId;
- uint8_t Revision;
- uint8_t ReferenceSpadCount = 0;
- uint8_t ReferenceSpadType = 0;
- uint32_t PartUIDUpper = 0;
- uint32_t PartUIDLower = 0;
- uint32_t OffsetFixed1104_mm = 0;
- int16_t OffsetMicroMeters = 0;
- uint32_t DistMeasTgtFixed1104_mm = 400 << 4;
- uint32_t DistMeasFixed1104_400_mm = 0;
- uint32_t SignalRateMeasFixed1104_400_mm = 0;
- char ProductId[19];
- char *ProductId_tmp;
- uint8_t ReadDataFromDeviceDone;
- FixPoint1616_t SignalRateMeasFixed400mmFix = 0;
- uint8_t NvmRefGoodSpadMap[VL53L0X_REF_SPAD_BUFFER_SIZE];
- int i;
-
-
- LOG_FUNCTION_START("");
-
- ReadDataFromDeviceDone = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
- ReadDataFromDeviceDone);
-
- /* This access is done only once after that a GetDeviceInfo or
- * datainit is done*/
- if (ReadDataFromDeviceDone != 7) {
-
- Status |= VL53L0X_WrByte(Dev, 0x80, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0x00, 0x00);
-
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x06);
- Status |= VL53L0X_RdByte(Dev, 0x83, &byte);
- Status |= VL53L0X_WrByte(Dev, 0x83, byte|4);
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x07);
- Status |= VL53L0X_WrByte(Dev, 0x81, 0x01);
-
- Status |= VL53L0X_PollingDelay(Dev);
-
- Status |= VL53L0X_WrByte(Dev, 0x80, 0x01);
-
- if (((option & 1) == 1) &&
- ((ReadDataFromDeviceDone & 1) == 0)) {
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x6b);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdDWord(Dev, 0x90, &TmpDWord);
-
- ReferenceSpadCount = (uint8_t)((TmpDWord >> 8) & 0x07f);
- ReferenceSpadType = (uint8_t)((TmpDWord >> 15) & 0x01);
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x24);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdDWord(Dev, 0x90, &TmpDWord);
-
-
- NvmRefGoodSpadMap[0] = (uint8_t)((TmpDWord >> 24)
- & 0xff);
- NvmRefGoodSpadMap[1] = (uint8_t)((TmpDWord >> 16)
- & 0xff);
- NvmRefGoodSpadMap[2] = (uint8_t)((TmpDWord >> 8)
- & 0xff);
- NvmRefGoodSpadMap[3] = (uint8_t)(TmpDWord & 0xff);
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x25);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdDWord(Dev, 0x90, &TmpDWord);
-
- NvmRefGoodSpadMap[4] = (uint8_t)((TmpDWord >> 24)
- & 0xff);
- NvmRefGoodSpadMap[5] = (uint8_t)((TmpDWord >> 16)
- & 0xff);
- }
-
- if (((option & 2) == 2) &&
- ((ReadDataFromDeviceDone & 2) == 0)) {
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x02);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdByte(Dev, 0x90, &ModuleId);
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x7B);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdByte(Dev, 0x90, &Revision);
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x77);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdDWord(Dev, 0x90, &TmpDWord);
-
- ProductId[0] = (char)((TmpDWord >> 25) & 0x07f);
- ProductId[1] = (char)((TmpDWord >> 18) & 0x07f);
- ProductId[2] = (char)((TmpDWord >> 11) & 0x07f);
- ProductId[3] = (char)((TmpDWord >> 4) & 0x07f);
-
- byte = (uint8_t)((TmpDWord & 0x00f) << 3);
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x78);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdDWord(Dev, 0x90, &TmpDWord);
-
- ProductId[4] = (char)(byte +
- ((TmpDWord >> 29) & 0x07f));
- ProductId[5] = (char)((TmpDWord >> 22) & 0x07f);
- ProductId[6] = (char)((TmpDWord >> 15) & 0x07f);
- ProductId[7] = (char)((TmpDWord >> 8) & 0x07f);
- ProductId[8] = (char)((TmpDWord >> 1) & 0x07f);
-
- byte = (uint8_t)((TmpDWord & 0x001) << 6);
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x79);
-
- Status |= VL53L0X_device_read_strobe(Dev);
-
- Status |= VL53L0X_RdDWord(Dev, 0x90, &TmpDWord);
-
- ProductId[9] = (char)(byte +
- ((TmpDWord >> 26) & 0x07f));
- ProductId[10] = (char)((TmpDWord >> 19) & 0x07f);
- ProductId[11] = (char)((TmpDWord >> 12) & 0x07f);
- ProductId[12] = (char)((TmpDWord >> 5) & 0x07f);
-
- byte = (uint8_t)((TmpDWord & 0x01f) << 2);
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x7A);
-
- Status |= VL53L0X_device_read_strobe(Dev);
-
- Status |= VL53L0X_RdDWord(Dev, 0x90, &TmpDWord);
-
- ProductId[13] = (char)(byte +
- ((TmpDWord >> 30) & 0x07f));
- ProductId[14] = (char)((TmpDWord >> 23) & 0x07f);
- ProductId[15] = (char)((TmpDWord >> 16) & 0x07f);
- ProductId[16] = (char)((TmpDWord >> 9) & 0x07f);
- ProductId[17] = (char)((TmpDWord >> 2) & 0x07f);
- ProductId[18] = '\0';
-
- }
-
- if (((option & 4) == 4) &&
- ((ReadDataFromDeviceDone & 4) == 0)) {
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x7B);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdDWord(Dev, 0x90, &PartUIDUpper);
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x7C);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdDWord(Dev, 0x90, &PartUIDLower);
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x73);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdDWord(Dev, 0x90, &TmpDWord);
-
- SignalRateMeasFixed1104_400_mm = (TmpDWord &
- 0x0000000ff) << 8;
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x74);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdDWord(Dev, 0x90, &TmpDWord);
-
- SignalRateMeasFixed1104_400_mm |= ((TmpDWord &
- 0xff000000) >> 24);
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x75);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdDWord(Dev, 0x90, &TmpDWord);
-
- DistMeasFixed1104_400_mm = (TmpDWord & 0x0000000ff)
- << 8;
-
- Status |= VL53L0X_WrByte(Dev, 0x94, 0x76);
- Status |= VL53L0X_device_read_strobe(Dev);
- Status |= VL53L0X_RdDWord(Dev, 0x90, &TmpDWord);
-
- DistMeasFixed1104_400_mm |= ((TmpDWord & 0xff000000)
- >> 24);
- }
-
- Status |= VL53L0X_WrByte(Dev, 0x81, 0x00);
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x06);
- Status |= VL53L0X_RdByte(Dev, 0x83, &byte);
- Status |= VL53L0X_WrByte(Dev, 0x83, byte&0xfb);
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0x00, 0x01);
-
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
- Status |= VL53L0X_WrByte(Dev, 0x80, 0x00);
- }
-
- if ((Status == VL53L0X_ERROR_NONE) &&
- (ReadDataFromDeviceDone != 7)) {
- /* Assign to variable if status is ok */
- if (((option & 1) == 1) &&
- ((ReadDataFromDeviceDone & 1) == 0)) {
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- ReferenceSpadCount, ReferenceSpadCount);
-
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- ReferenceSpadType, ReferenceSpadType);
-
- for (i = 0; i < VL53L0X_REF_SPAD_BUFFER_SIZE; i++) {
- Dev->Data.SpadData.RefGoodSpadMap[i] =
- NvmRefGoodSpadMap[i];
- }
- }
-
- if (((option & 2) == 2) &&
- ((ReadDataFromDeviceDone & 2) == 0)) {
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- ModuleId, ModuleId);
-
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- Revision, Revision);
-
- ProductId_tmp = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
- ProductId);
- VL53L0X_COPYSTRING(ProductId_tmp, ProductId);
-
- }
-
- if (((option & 4) == 4) &&
- ((ReadDataFromDeviceDone & 4) == 0)) {
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- PartUIDUpper, PartUIDUpper);
-
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- PartUIDLower, PartUIDLower);
-
- SignalRateMeasFixed400mmFix =
- VL53L0X_FIXPOINT97TOFIXPOINT1616(
- SignalRateMeasFixed1104_400_mm);
-
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- SignalRateMeasFixed400mm,
- SignalRateMeasFixed400mmFix);
-
- OffsetMicroMeters = 0;
- if (DistMeasFixed1104_400_mm != 0) {
- OffsetFixed1104_mm =
- DistMeasFixed1104_400_mm -
- DistMeasTgtFixed1104_mm;
- OffsetMicroMeters = (OffsetFixed1104_mm
- * 1000) >> 4;
- OffsetMicroMeters *= -1;
- }
-
- PALDevDataSet(Dev,
- Part2PartOffsetAdjustmentNVMMicroMeter,
- OffsetMicroMeters);
- }
- byte = (uint8_t)(ReadDataFromDeviceDone|option);
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, ReadDataFromDeviceDone,
- byte);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t byte;
+ uint32_t tmp_dword;
+ uint8_t module_id;
+ uint8_t revision;
+ uint8_t reference_spad_count = 0;
+ uint8_t reference_spad_type = 0;
+ uint32_t part_uid_upper = 0;
+ uint32_t part_uid_lower = 0;
+ uint32_t offset_fixed1104_mm = 0;
+ int16_t offset_micro_meters = 0;
+ uint32_t dist_meas_tgt_fixed1104_mm = 400 << 4;
+ uint32_t dist_meas_fixed1104_400_mm = 0;
+ uint32_t signal_rate_meas_fixed1104_400_mm = 0;
+ char product_id[19];
+ char *product_id_tmp;
+ uint8_t read_data_from_device_done;
+ FixPoint1616_t signal_rate_meas_fixed400_mm_fix = 0;
+ uint8_t nvm_ref_good_spad_map[VL53L0X_REF_SPAD_BUFFER_SIZE];
+ int i;
+
+
+ LOG_FUNCTION_START("");
+
+ read_data_from_device_done = VL53L0X_GETDEVICESPECIFICPARAMETER(dev,
+ ReadDataFromDeviceDone);
+
+ /* This access is done only once after that a GetDeviceInfo or
+ * datainit is done*/
+ if (read_data_from_device_done != 7) {
+
+ status |= vl53l0x_write_byte(dev, 0x80, 0x01);
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x01);
+ status |= vl53l0x_write_byte(dev, 0x00, 0x00);
+
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x06);
+ status |= vl53l0x_read_byte(dev, 0x83, &byte);
+ status |= vl53l0x_write_byte(dev, 0x83, byte | 4);
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x07);
+ status |= vl53l0x_write_byte(dev, 0x81, 0x01);
+
+ status |= vl53l0x_polling_delay(dev);
+
+ status |= vl53l0x_write_byte(dev, 0x80, 0x01);
+
+ if (((option & 1) == 1) &&
+ ((read_data_from_device_done & 1) == 0)) {
+ status |= vl53l0x_write_byte(dev, 0x94, 0x6b);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_dword(dev, 0x90, &tmp_dword);
+
+ reference_spad_count = (uint8_t)((tmp_dword >> 8) & 0x07f);
+ reference_spad_type = (uint8_t)((tmp_dword >> 15) & 0x01);
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x24);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_dword(dev, 0x90, &tmp_dword);
+
+
+ nvm_ref_good_spad_map[0] = (uint8_t)((tmp_dword >> 24)
+ & 0xff);
+ nvm_ref_good_spad_map[1] = (uint8_t)((tmp_dword >> 16)
+ & 0xff);
+ nvm_ref_good_spad_map[2] = (uint8_t)((tmp_dword >> 8)
+ & 0xff);
+ nvm_ref_good_spad_map[3] = (uint8_t)(tmp_dword & 0xff);
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x25);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_dword(dev, 0x90, &tmp_dword);
+
+ nvm_ref_good_spad_map[4] = (uint8_t)((tmp_dword >> 24)
+ & 0xff);
+ nvm_ref_good_spad_map[5] = (uint8_t)((tmp_dword >> 16)
+ & 0xff);
+ }
+
+ if (((option & 2) == 2) &&
+ ((read_data_from_device_done & 2) == 0)) {
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x02);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_byte(dev, 0x90, &module_id);
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x7B);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_byte(dev, 0x90, &revision);
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x77);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_dword(dev, 0x90, &tmp_dword);
+
+ product_id[0] = (char)((tmp_dword >> 25) & 0x07f);
+ product_id[1] = (char)((tmp_dword >> 18) & 0x07f);
+ product_id[2] = (char)((tmp_dword >> 11) & 0x07f);
+ product_id[3] = (char)((tmp_dword >> 4) & 0x07f);
+
+ byte = (uint8_t)((tmp_dword & 0x00f) << 3);
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x78);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_dword(dev, 0x90, &tmp_dword);
+
+ product_id[4] = (char)(byte +
+ ((tmp_dword >> 29) & 0x07f));
+ product_id[5] = (char)((tmp_dword >> 22) & 0x07f);
+ product_id[6] = (char)((tmp_dword >> 15) & 0x07f);
+ product_id[7] = (char)((tmp_dword >> 8) & 0x07f);
+ product_id[8] = (char)((tmp_dword >> 1) & 0x07f);
+
+ byte = (uint8_t)((tmp_dword & 0x001) << 6);
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x79);
+
+ status |= vl53l0x_device_read_strobe(dev);
+
+ status |= vl53l0x_read_dword(dev, 0x90, &tmp_dword);
+
+ product_id[9] = (char)(byte +
+ ((tmp_dword >> 26) & 0x07f));
+ product_id[10] = (char)((tmp_dword >> 19) & 0x07f);
+ product_id[11] = (char)((tmp_dword >> 12) & 0x07f);
+ product_id[12] = (char)((tmp_dword >> 5) & 0x07f);
+
+ byte = (uint8_t)((tmp_dword & 0x01f) << 2);
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x7A);
+
+ status |= vl53l0x_device_read_strobe(dev);
+
+ status |= vl53l0x_read_dword(dev, 0x90, &tmp_dword);
+
+ product_id[13] = (char)(byte +
+ ((tmp_dword >> 30) & 0x07f));
+ product_id[14] = (char)((tmp_dword >> 23) & 0x07f);
+ product_id[15] = (char)((tmp_dword >> 16) & 0x07f);
+ product_id[16] = (char)((tmp_dword >> 9) & 0x07f);
+ product_id[17] = (char)((tmp_dword >> 2) & 0x07f);
+ product_id[18] = '\0';
+
+ }
+
+ if (((option & 4) == 4) &&
+ ((read_data_from_device_done & 4) == 0)) {
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x7B);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_dword(dev, 0x90, &part_uid_upper);
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x7C);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_dword(dev, 0x90, &part_uid_lower);
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x73);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_dword(dev, 0x90, &tmp_dword);
+
+ signal_rate_meas_fixed1104_400_mm = (tmp_dword &
+ 0x0000000ff) << 8;
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x74);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_dword(dev, 0x90, &tmp_dword);
+
+ signal_rate_meas_fixed1104_400_mm |= ((tmp_dword &
+ 0xff000000) >> 24);
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x75);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_dword(dev, 0x90, &tmp_dword);
+
+ dist_meas_fixed1104_400_mm = (tmp_dword & 0x0000000ff)
+ << 8;
+
+ status |= vl53l0x_write_byte(dev, 0x94, 0x76);
+ status |= vl53l0x_device_read_strobe(dev);
+ status |= vl53l0x_read_dword(dev, 0x90, &tmp_dword);
+
+ dist_meas_fixed1104_400_mm |= ((tmp_dword & 0xff000000)
+ >> 24);
+ }
+
+ status |= vl53l0x_write_byte(dev, 0x81, 0x00);
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x06);
+ status |= vl53l0x_read_byte(dev, 0x83, &byte);
+ status |= vl53l0x_write_byte(dev, 0x83, byte & 0xfb);
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x01);
+ status |= vl53l0x_write_byte(dev, 0x00, 0x01);
+
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x00);
+ status |= vl53l0x_write_byte(dev, 0x80, 0x00);
+ }
+
+ if ((status == VL53L0X_ERROR_NONE) &&
+ (read_data_from_device_done != 7)) {
+ /* Assign to variable if status is ok */
+ if (((option & 1) == 1) &&
+ ((read_data_from_device_done & 1) == 0)) {
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ ReferenceSpadCount, reference_spad_count);
+
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ ReferenceSpadType, reference_spad_type);
+
+ for (i = 0; i < VL53L0X_REF_SPAD_BUFFER_SIZE; i++) {
+ dev->Data.SpadData.RefGoodSpadMap[i] =
+ nvm_ref_good_spad_map[i];
+ }
+ }
+
+ if (((option & 2) == 2) &&
+ ((read_data_from_device_done & 2) == 0)) {
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ ModuleId, module_id);
+
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ Revision, revision);
+
+ product_id_tmp = VL53L0X_GETDEVICESPECIFICPARAMETER(dev,
+ ProductId);
+ VL53L0X_COPYSTRING(product_id_tmp, product_id);
+
+ }
+
+ if (((option & 4) == 4) &&
+ ((read_data_from_device_done & 4) == 0)) {
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ PartUIDUpper, part_uid_upper);
+
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ PartUIDLower, part_uid_lower);
+
+ signal_rate_meas_fixed400_mm_fix =
+ VL53L0X_FIXPOINT97TOFIXPOINT1616(
+ signal_rate_meas_fixed1104_400_mm);
+
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ SignalRateMeasFixed400mm,
+ signal_rate_meas_fixed400_mm_fix);
+
+ offset_micro_meters = 0;
+ if (dist_meas_fixed1104_400_mm != 0) {
+ offset_fixed1104_mm =
+ dist_meas_fixed1104_400_mm -
+ dist_meas_tgt_fixed1104_mm;
+ offset_micro_meters = (offset_fixed1104_mm
+ * 1000) >> 4;
+ offset_micro_meters *= -1;
+ }
+
+ PALDevDataSet(dev,
+ Part2PartOffsetAdjustmentNVMMicroMeter,
+ offset_micro_meters);
+ }
+ byte = (uint8_t)(read_data_from_device_done | option);
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev, ReadDataFromDeviceDone,
+ byte);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_get_offset_calibration_data_micro_meter(VL53L0X_DEV Dev,
- int32_t *pOffsetCalibrationDataMicroMeter)
+VL53L0X_Error VL53L0X::wrapped_vl53l0x_get_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
+ int32_t *p_offset_calibration_data_micro_meter)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint16_t RangeOffsetRegister;
- int16_t cMaxOffset = 2047;
- int16_t cOffsetRange = 4096;
-
- /* Note that offset has 10.2 format */
-
- Status = VL53L0X_RdWord(Dev,
- VL53L0X_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM,
- &RangeOffsetRegister);
-
- if (Status == VL53L0X_ERROR_NONE) {
- RangeOffsetRegister = (RangeOffsetRegister & 0x0fff);
-
- /* Apply 12 bit 2's compliment conversion */
- if (RangeOffsetRegister > cMaxOffset)
- *pOffsetCalibrationDataMicroMeter =
- (int16_t)(RangeOffsetRegister - cOffsetRange)
- * 250;
- else
- *pOffsetCalibrationDataMicroMeter =
- (int16_t)RangeOffsetRegister * 250;
-
- }
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint16_t range_offset_register;
+ int16_t c_max_offset = 2047;
+ int16_t c_offset_range = 4096;
+
+ /* Note that offset has 10.2 format */
+
+ status = vl53l0x_read_word(dev,
+ VL53L0X_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM,
+ &range_offset_register);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ range_offset_register = (range_offset_register & 0x0fff);
+
+ /* Apply 12 bit 2's compliment conversion */
+ if (range_offset_register > c_max_offset)
+ *p_offset_calibration_data_micro_meter =
+ (int16_t)(range_offset_register - c_offset_range)
+ * 250;
+ else
+ *p_offset_calibration_data_micro_meter =
+ (int16_t)range_offset_register * 250;
+
+ }
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetOffsetCalibrationDataMicroMeter(VL53L0X_DEV Dev,
- int32_t *pOffsetCalibrationDataMicroMeter)
+VL53L0X_Error VL53L0X::vl53l0x_get_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
+ int32_t *p_offset_calibration_data_micro_meter)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_get_offset_calibration_data_micro_meter(Dev,
- pOffsetCalibrationDataMicroMeter);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = wrapped_vl53l0x_get_offset_calibration_data_micro_meter(dev,
+ p_offset_calibration_data_micro_meter);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_set_offset_calibration_data_micro_meter(VL53L0X_DEV Dev,
- int32_t OffsetCalibrationDataMicroMeter)
+VL53L0X_Error VL53L0X::wrapped_vl53l0x_set_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
+ int32_t offset_calibration_data_micro_meter)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- int32_t cMaxOffsetMicroMeter = 511000;
- int32_t cMinOffsetMicroMeter = -512000;
- int16_t cOffsetRange = 4096;
- uint32_t encodedOffsetVal;
-
- LOG_FUNCTION_START("");
-
- if (OffsetCalibrationDataMicroMeter > cMaxOffsetMicroMeter)
- OffsetCalibrationDataMicroMeter = cMaxOffsetMicroMeter;
- else if (OffsetCalibrationDataMicroMeter < cMinOffsetMicroMeter)
- OffsetCalibrationDataMicroMeter = cMinOffsetMicroMeter;
-
- /* The offset register is 10.2 format and units are mm
- * therefore conversion is applied by a division of
- * 250.
- */
- if (OffsetCalibrationDataMicroMeter >= 0) {
- encodedOffsetVal =
- OffsetCalibrationDataMicroMeter/250;
- } else {
- encodedOffsetVal =
- cOffsetRange +
- OffsetCalibrationDataMicroMeter/250;
- }
-
- Status = VL53L0X_WrWord(Dev,
- VL53L0X_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM,
- encodedOffsetVal);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ int32_t c_max_offset_micro_meter = 511000;
+ int32_t c_min_offset_micro_meter = -512000;
+ int16_t c_offset_range = 4096;
+ uint32_t encoded_offset_val;
+
+ LOG_FUNCTION_START("");
+
+ if (offset_calibration_data_micro_meter > c_max_offset_micro_meter)
+ offset_calibration_data_micro_meter = c_max_offset_micro_meter;
+ else if (offset_calibration_data_micro_meter < c_min_offset_micro_meter)
+ offset_calibration_data_micro_meter = c_min_offset_micro_meter;
+
+ /* The offset register is 10.2 format and units are mm
+ * therefore conversion is applied by a division of
+ * 250.
+ */
+ if (offset_calibration_data_micro_meter >= 0) {
+ encoded_offset_val =
+ offset_calibration_data_micro_meter / 250;
+ } else {
+ encoded_offset_val =
+ c_offset_range +
+ offset_calibration_data_micro_meter / 250;
+ }
+
+ status = vl53l0x_write_word(dev,
+ VL53L0X_REG_ALGO_PART_TO_PART_RANGE_OFFSET_MM,
+ encoded_offset_val);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_SetOffsetCalibrationDataMicroMeter(VL53L0X_DEV Dev,
- int32_t OffsetCalibrationDataMicroMeter)
+VL53L0X_Error VL53L0X::vl53l0x_set_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
+ int32_t offset_calibration_data_micro_meter)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_set_offset_calibration_data_micro_meter(Dev,
- OffsetCalibrationDataMicroMeter);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = wrapped_vl53l0x_set_offset_calibration_data_micro_meter(dev,
+ offset_calibration_data_micro_meter);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_apply_offset_adjustment(VL53L0X_DEV Dev)
+VL53L0X_Error VL53L0X::vl53l0x_apply_offset_adjustment(VL53L0X_DEV dev)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- int32_t CorrectedOffsetMicroMeters;
- int32_t CurrentOffsetMicroMeters;
-
- /* if we run on this function we can read all the NVM info
- * used by the API */
- Status = VL53L0X_get_info_from_device(Dev, 7);
-
- /* Read back current device offset */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_GetOffsetCalibrationDataMicroMeter(Dev,
- &CurrentOffsetMicroMeters);
- }
-
- /* Apply Offset Adjustment derived from 400mm measurements */
- if (Status == VL53L0X_ERROR_NONE) {
-
- /* Store initial device offset */
- PALDevDataSet(Dev, Part2PartOffsetNVMMicroMeter,
- CurrentOffsetMicroMeters);
-
- CorrectedOffsetMicroMeters = CurrentOffsetMicroMeters +
- (int32_t)PALDevDataGet(Dev,
- Part2PartOffsetAdjustmentNVMMicroMeter);
-
- Status = VL53L0X_SetOffsetCalibrationDataMicroMeter(Dev,
- CorrectedOffsetMicroMeters);
-
- /* store current, adjusted offset */
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETPARAMETERFIELD(Dev, RangeOffsetMicroMeters,
- CorrectedOffsetMicroMeters);
- }
- }
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ int32_t corrected_offset_micro_meters;
+ int32_t current_offset_micro_meters;
+
+ /* if we run on this function we can read all the NVM info
+ * used by the API */
+ status = vl53l0x_get_info_from_device(dev, 7);
+
+ /* Read back current device offset */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_get_offset_calibration_data_micro_meter(dev,
+ ¤t_offset_micro_meters);
+ }
+
+ /* Apply Offset Adjustment derived from 400mm measurements */
+ if (status == VL53L0X_ERROR_NONE) {
+
+ /* Store initial device offset */
+ PALDevDataSet(dev, Part2PartOffsetNVMMicroMeter,
+ current_offset_micro_meters);
+
+ corrected_offset_micro_meters = current_offset_micro_meters +
+ (int32_t)PALDevDataGet(dev,
+ Part2PartOffsetAdjustmentNVMMicroMeter);
+
+ status = vl53l0x_set_offset_calibration_data_micro_meter(dev,
+ corrected_offset_micro_meters);
+
+ /* store current, adjusted offset */
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETPARAMETERFIELD(dev, RangeOffsetMicroMeters,
+ corrected_offset_micro_meters);
+ }
+ }
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetDeviceMode(VL53L0X_DEV Dev,
- VL53L0X_DeviceModes *pDeviceMode)
+VL53L0X_Error VL53L0X::vl53l0x_get_device_mode(VL53L0X_DEV dev,
+ VL53L0X_DeviceModes *p_device_mode)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- VL53L0X_GETPARAMETERFIELD(Dev, DeviceMode, *pDeviceMode);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ VL53L0X_GETPARAMETERFIELD(dev, DeviceMode, *p_device_mode);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetInterMeasurementPeriodMilliSeconds(VL53L0X_DEV Dev,
- uint32_t *pInterMeasurementPeriodMilliSeconds)
+VL53L0X_Error VL53L0X::vl53l0x_get_inter_measurement_period_milli_seconds(VL53L0X_DEV dev,
+ uint32_t *p_inter_measurement_period_milli_seconds)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint16_t osc_calibrate_val;
- uint32_t IMPeriodMilliSeconds;
-
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_RdWord(Dev, VL53L0X_REG_OSC_CALIBRATE_VAL,
- &osc_calibrate_val);
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_RdDWord(Dev,
- VL53L0X_REG_SYSTEM_INTERMEASUREMENT_PERIOD,
- &IMPeriodMilliSeconds);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- if (osc_calibrate_val != 0) {
- *pInterMeasurementPeriodMilliSeconds =
- IMPeriodMilliSeconds / osc_calibrate_val;
- }
- VL53L0X_SETPARAMETERFIELD(Dev,
- InterMeasurementPeriodMilliSeconds,
- *pInterMeasurementPeriodMilliSeconds);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint16_t osc_calibrate_val;
+ uint32_t im_period_milli_seconds;
+
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_read_word(dev, VL53L0X_REG_OSC_CALIBRATE_VAL,
+ &osc_calibrate_val);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_read_dword(dev,
+ VL53L0X_REG_SYSTEM_INTERMEASUREMENT_PERIOD,
+ &im_period_milli_seconds);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ if (osc_calibrate_val != 0) {
+ *p_inter_measurement_period_milli_seconds =
+ im_period_milli_seconds / osc_calibrate_val;
+ }
+ VL53L0X_SETPARAMETERFIELD(dev,
+ InterMeasurementPeriodMilliSeconds,
+ *p_inter_measurement_period_milli_seconds);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetXTalkCompensationRateMegaCps(VL53L0X_DEV Dev,
- FixPoint1616_t *pXTalkCompensationRateMegaCps)
+VL53L0X_Error VL53L0X::vl53l0x_get_x_talk_compensation_rate_mega_cps(VL53L0X_DEV dev,
+ FixPoint1616_t *p_xtalk_compensation_rate_mega_cps)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint16_t Value;
- FixPoint1616_t TempFix1616;
-
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_RdWord(Dev,
- VL53L0X_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS, (uint16_t *)&Value);
- if (Status == VL53L0X_ERROR_NONE) {
- if (Value == 0) {
- /* the Xtalk is disabled return value from memory */
- VL53L0X_GETPARAMETERFIELD(Dev,
- XTalkCompensationRateMegaCps, TempFix1616);
- *pXTalkCompensationRateMegaCps = TempFix1616;
- VL53L0X_SETPARAMETERFIELD(Dev, XTalkCompensationEnable,
- 0);
- } else {
- TempFix1616 = VL53L0X_FIXPOINT313TOFIXPOINT1616(Value);
- *pXTalkCompensationRateMegaCps = TempFix1616;
- VL53L0X_SETPARAMETERFIELD(Dev,
- XTalkCompensationRateMegaCps, TempFix1616);
- VL53L0X_SETPARAMETERFIELD(Dev, XTalkCompensationEnable,
- 1);
- }
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint16_t value;
+ FixPoint1616_t temp_fix1616;
+
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_read_word(dev,
+ VL53L0X_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS, (uint16_t *)&value);
+ if (status == VL53L0X_ERROR_NONE) {
+ if (value == 0) {
+ /* the Xtalk is disabled return value from memory */
+ VL53L0X_GETPARAMETERFIELD(dev,
+ XTalkCompensationRateMegaCps, temp_fix1616);
+ *p_xtalk_compensation_rate_mega_cps = temp_fix1616;
+ VL53L0X_SETPARAMETERFIELD(dev, XTalkCompensationEnable,
+ 0);
+ } else {
+ temp_fix1616 = VL53L0X_FIXPOINT313TOFIXPOINT1616(value);
+ *p_xtalk_compensation_rate_mega_cps = temp_fix1616;
+ VL53L0X_SETPARAMETERFIELD(dev,
+ XTalkCompensationRateMegaCps, temp_fix1616);
+ VL53L0X_SETPARAMETERFIELD(dev, XTalkCompensationEnable,
+ 1);
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetLimitCheckValue(VL53L0X_DEV Dev, uint16_t LimitCheckId,
- FixPoint1616_t *pLimitCheckValue)
+VL53L0X_Error VL53L0X::vl53l0x_get_limit_check_value(VL53L0X_DEV dev, uint16_t limit_check_id,
+ FixPoint1616_t *p_limit_check_value)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t EnableZeroValue = 0;
- uint16_t Temp16;
- FixPoint1616_t TempFix1616;
-
- LOG_FUNCTION_START("");
-
- switch (LimitCheckId) {
-
- case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:
- /* internal computation: */
- VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
- VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, TempFix1616);
- EnableZeroValue = 0;
- break;
-
- case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
- Status = VL53L0X_RdWord(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
- &Temp16);
- if (Status == VL53L0X_ERROR_NONE)
- TempFix1616 = VL53L0X_FIXPOINT97TOFIXPOINT1616(Temp16);
-
-
- EnableZeroValue = 1;
- break;
-
- case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:
- /* internal computation: */
- VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
- VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP, TempFix1616);
- EnableZeroValue = 0;
- break;
-
- case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
- /* internal computation: */
- VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
- VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, TempFix1616);
- EnableZeroValue = 0;
- break;
-
- case VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC:
- case VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE:
- Status = VL53L0X_RdWord(Dev,
- VL53L0X_REG_PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT,
- &Temp16);
- if (Status == VL53L0X_ERROR_NONE)
- TempFix1616 = VL53L0X_FIXPOINT97TOFIXPOINT1616(Temp16);
-
-
- EnableZeroValue = 0;
- break;
-
- default:
- Status = VL53L0X_ERROR_INVALID_PARAMS;
-
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
-
- if (EnableZeroValue == 1) {
-
- if (TempFix1616 == 0) {
- /* disabled: return value from memory */
- VL53L0X_GETARRAYPARAMETERFIELD(Dev,
- LimitChecksValue, LimitCheckId,
- TempFix1616);
- *pLimitCheckValue = TempFix1616;
- VL53L0X_SETARRAYPARAMETERFIELD(Dev,
- LimitChecksEnable, LimitCheckId, 0);
- } else {
- *pLimitCheckValue = TempFix1616;
- VL53L0X_SETARRAYPARAMETERFIELD(Dev,
- LimitChecksValue, LimitCheckId,
- TempFix1616);
- VL53L0X_SETARRAYPARAMETERFIELD(Dev,
- LimitChecksEnable, LimitCheckId, 1);
- }
- } else {
- *pLimitCheckValue = TempFix1616;
- }
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t enable_zero_value = 0;
+ uint16_t temp16;
+ FixPoint1616_t temp_fix1616;
+
+ LOG_FUNCTION_START("");
+
+ switch (limit_check_id) {
+
+ case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:
+ /* internal computation: */
+ VL53L0X_GETARRAYPARAMETERFIELD(dev, LimitChecksValue,
+ VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, temp_fix1616);
+ enable_zero_value = 0;
+ break;
+
+ case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+ status = vl53l0x_read_word(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
+ &temp16);
+ if (status == VL53L0X_ERROR_NONE)
+ temp_fix1616 = VL53L0X_FIXPOINT97TOFIXPOINT1616(temp16);
+
+
+ enable_zero_value = 1;
+ break;
+
+ case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:
+ /* internal computation: */
+ VL53L0X_GETARRAYPARAMETERFIELD(dev, LimitChecksValue,
+ VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP, temp_fix1616);
+ enable_zero_value = 0;
+ break;
+
+ case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
+ /* internal computation: */
+ VL53L0X_GETARRAYPARAMETERFIELD(dev, LimitChecksValue,
+ VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, temp_fix1616);
+ enable_zero_value = 0;
+ break;
+
+ case VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC:
+ case VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE:
+ status = vl53l0x_read_word(dev,
+ VL53L0X_REG_PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT,
+ &temp16);
+ if (status == VL53L0X_ERROR_NONE)
+ temp_fix1616 = VL53L0X_FIXPOINT97TOFIXPOINT1616(temp16);
+
+
+ enable_zero_value = 0;
+ break;
+
+ default:
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+
+ if (enable_zero_value == 1) {
+
+ if (temp_fix1616 == 0) {
+ /* disabled: return value from memory */
+ VL53L0X_GETARRAYPARAMETERFIELD(dev,
+ LimitChecksValue, limit_check_id,
+ temp_fix1616);
+ *p_limit_check_value = temp_fix1616;
+ VL53L0X_SETARRAYPARAMETERFIELD(dev,
+ LimitChecksEnable, limit_check_id, 0);
+ } else {
+ *p_limit_check_value = temp_fix1616;
+ VL53L0X_SETARRAYPARAMETERFIELD(dev,
+ LimitChecksValue, limit_check_id,
+ temp_fix1616);
+ VL53L0X_SETARRAYPARAMETERFIELD(dev,
+ LimitChecksEnable, limit_check_id, 1);
+ }
+ } else {
+ *p_limit_check_value = temp_fix1616;
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetLimitCheckEnable(VL53L0X_DEV Dev, uint16_t LimitCheckId,
- uint8_t *pLimitCheckEnable)
+VL53L0X_Error VL53L0X::vl53l0x_get_limit_check_enable(VL53L0X_DEV dev, uint16_t limit_check_id,
+ uint8_t *p_limit_check_enable)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t Temp8;
-
- LOG_FUNCTION_START("");
-
- if (LimitCheckId >= VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS) {
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- *pLimitCheckEnable = 0;
- } else {
- VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
- LimitCheckId, Temp8);
- *pLimitCheckEnable = Temp8;
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t temp8;
+
+ LOG_FUNCTION_START("");
+
+ if (limit_check_id >= VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS) {
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ *p_limit_check_enable = 0;
+ } else {
+ VL53L0X_GETARRAYPARAMETERFIELD(dev, LimitChecksEnable,
+ limit_check_id, temp8);
+ *p_limit_check_enable = temp8;
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetWrapAroundCheckEnable(VL53L0X_DEV Dev,
- uint8_t *pWrapAroundCheckEnable)
+VL53L0X_Error VL53L0X::vl53l0x_get_wrap_around_check_enable(VL53L0X_DEV dev,
+ uint8_t *p_wrap_around_check_enable)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t data;
-
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_RdByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &data);
- if (Status == VL53L0X_ERROR_NONE) {
- PALDevDataSet(Dev, SequenceConfig, data);
- if (data & (0x01 << 7))
- *pWrapAroundCheckEnable = 0x01;
- else
- *pWrapAroundCheckEnable = 0x00;
- }
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETPARAMETERFIELD(Dev, WrapAroundCheckEnable,
- *pWrapAroundCheckEnable);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t data;
+
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_read_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &data);
+ if (status == VL53L0X_ERROR_NONE) {
+ PALDevDataSet(dev, SequenceConfig, data);
+ if (data & (0x01 << 7))
+ *p_wrap_around_check_enable = 0x01;
+ else
+ *p_wrap_around_check_enable = 0x00;
+ }
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETPARAMETERFIELD(dev, WrapAroundCheckEnable,
+ *p_wrap_around_check_enable);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::sequence_step_enabled(VL53L0X_DEV Dev,
- VL53L0X_SequenceStepId SequenceStepId, uint8_t SequenceConfig,
- uint8_t *pSequenceStepEnabled)
+VL53L0X_Error VL53L0X::sequence_step_enabled(VL53L0X_DEV dev,
+ VL53L0X_SequenceStepId sequence_step_id, uint8_t sequence_config,
+ uint8_t *p_sequence_step_enabled)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- *pSequenceStepEnabled = 0;
- LOG_FUNCTION_START("");
-
- switch (SequenceStepId) {
- case VL53L0X_SEQUENCESTEP_TCC:
- *pSequenceStepEnabled = (SequenceConfig & 0x10) >> 4;
- break;
- case VL53L0X_SEQUENCESTEP_DSS:
- *pSequenceStepEnabled = (SequenceConfig & 0x08) >> 3;
- break;
- case VL53L0X_SEQUENCESTEP_MSRC:
- *pSequenceStepEnabled = (SequenceConfig & 0x04) >> 2;
- break;
- case VL53L0X_SEQUENCESTEP_PRE_RANGE:
- *pSequenceStepEnabled = (SequenceConfig & 0x40) >> 6;
- break;
- case VL53L0X_SEQUENCESTEP_FINAL_RANGE:
- *pSequenceStepEnabled = (SequenceConfig & 0x80) >> 7;
- break;
- default:
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error Status = VL53L0X_ERROR_NONE;
+ *p_sequence_step_enabled = 0;
+ LOG_FUNCTION_START("");
+
+ switch (sequence_step_id) {
+ case VL53L0X_SEQUENCESTEP_TCC:
+ *p_sequence_step_enabled = (sequence_config & 0x10) >> 4;
+ break;
+ case VL53L0X_SEQUENCESTEP_DSS:
+ *p_sequence_step_enabled = (sequence_config & 0x08) >> 3;
+ break;
+ case VL53L0X_SEQUENCESTEP_MSRC:
+ *p_sequence_step_enabled = (sequence_config & 0x04) >> 2;
+ break;
+ case VL53L0X_SEQUENCESTEP_PRE_RANGE:
+ *p_sequence_step_enabled = (sequence_config & 0x40) >> 6;
+ break;
+ case VL53L0X_SEQUENCESTEP_FINAL_RANGE:
+ *p_sequence_step_enabled = (sequence_config & 0x80) >> 7;
+ break;
+ default:
+ Status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+
+ LOG_FUNCTION_END(status);
+ return Status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetSequenceStepEnables(VL53L0X_DEV Dev,
- VL53L0X_SchedulerSequenceSteps_t *pSchedulerSequenceSteps)
+VL53L0X_Error VL53L0X::vl53l0x_get_sequence_step_enables(VL53L0X_DEV dev,
+ VL53L0X_SchedulerSequenceSteps_t *p_scheduler_sequence_steps)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t SequenceConfig = 0;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_RdByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
- &SequenceConfig);
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = sequence_step_enabled(Dev,
- VL53L0X_SEQUENCESTEP_TCC, SequenceConfig,
- &pSchedulerSequenceSteps->TccOn);
- }
- if (Status == VL53L0X_ERROR_NONE) {
- Status = sequence_step_enabled(Dev,
- VL53L0X_SEQUENCESTEP_DSS, SequenceConfig,
- &pSchedulerSequenceSteps->DssOn);
- }
- if (Status == VL53L0X_ERROR_NONE) {
- Status = sequence_step_enabled(Dev,
- VL53L0X_SEQUENCESTEP_MSRC, SequenceConfig,
- &pSchedulerSequenceSteps->MsrcOn);
- }
- if (Status == VL53L0X_ERROR_NONE) {
- Status = sequence_step_enabled(Dev,
- VL53L0X_SEQUENCESTEP_PRE_RANGE, SequenceConfig,
- &pSchedulerSequenceSteps->PreRangeOn);
- }
- if (Status == VL53L0X_ERROR_NONE) {
- Status = sequence_step_enabled(Dev,
- VL53L0X_SEQUENCESTEP_FINAL_RANGE, SequenceConfig,
- &pSchedulerSequenceSteps->FinalRangeOn);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t sequence_config = 0;
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_read_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
+ &sequence_config);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = sequence_step_enabled(dev,
+ VL53L0X_SEQUENCESTEP_TCC, sequence_config,
+ &p_scheduler_sequence_steps->TccOn);
+ }
+ if (status == VL53L0X_ERROR_NONE) {
+ status = sequence_step_enabled(dev,
+ VL53L0X_SEQUENCESTEP_DSS, sequence_config,
+ &p_scheduler_sequence_steps->DssOn);
+ }
+ if (status == VL53L0X_ERROR_NONE) {
+ status = sequence_step_enabled(dev,
+ VL53L0X_SEQUENCESTEP_MSRC, sequence_config,
+ &p_scheduler_sequence_steps->MsrcOn);
+ }
+ if (status == VL53L0X_ERROR_NONE) {
+ status = sequence_step_enabled(dev,
+ VL53L0X_SEQUENCESTEP_PRE_RANGE, sequence_config,
+ &p_scheduler_sequence_steps->PreRangeOn);
+ }
+ if (status == VL53L0X_ERROR_NONE) {
+ status = sequence_step_enabled(dev,
+ VL53L0X_SEQUENCESTEP_FINAL_RANGE, sequence_config,
+ &p_scheduler_sequence_steps->FinalRangeOn);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-uint8_t VL53L0X::VL53L0X_decode_vcsel_period(uint8_t vcsel_period_reg)
+uint8_t VL53L0X::vl53l0x_decode_vcsel_period(uint8_t vcsel_period_reg)
{
- /*!
- * Converts the encoded VCSEL period register value into the real
- * period in PLL clocks
- */
-
- uint8_t vcsel_period_pclks = 0;
-
- vcsel_period_pclks = (vcsel_period_reg + 1) << 1;
-
- return vcsel_period_pclks;
+ /*!
+ * Converts the encoded VCSEL period register value into the real
+ * period in PLL clocks
+ */
+
+ uint8_t vcsel_period_pclks = 0;
+
+ vcsel_period_pclks = (vcsel_period_reg + 1) << 1;
+
+ return vcsel_period_pclks;
}
-uint8_t VL53L0X::VL53L0X_encode_vcsel_period(uint8_t vcsel_period_pclks)
+uint8_t VL53L0X::lv53l0x_encode_vcsel_period(uint8_t vcsel_period_pclks)
{
- /*!
- * Converts the encoded VCSEL period register value into the real period
- * in PLL clocks
- */
-
- uint8_t vcsel_period_reg = 0;
-
- vcsel_period_reg = (vcsel_period_pclks >> 1) - 1;
-
- return vcsel_period_reg;
+ /*!
+ * Converts the encoded VCSEL period register value into the real period
+ * in PLL clocks
+ */
+
+ uint8_t vcsel_period_reg = 0;
+
+ vcsel_period_reg = (vcsel_period_pclks >> 1) - 1;
+
+ return vcsel_period_reg;
}
-VL53L0X_Error VL53L0X::VL53L0X_set_vcsel_pulse_period(VL53L0X_DEV Dev,
- VL53L0X_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriodPCLK)
+VL53L0X_Error VL53L0X::wrapped_vl53l0x_set_vcsel_pulse_period(VL53L0X_DEV dev,
+ VL53L0X_VcselPeriod vcsel_period_type, uint8_t vcsel_pulse_period_pclk)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t vcsel_period_reg;
- uint8_t MinPreVcselPeriodPCLK = 12;
- uint8_t MaxPreVcselPeriodPCLK = 18;
- uint8_t MinFinalVcselPeriodPCLK = 8;
- uint8_t MaxFinalVcselPeriodPCLK = 14;
- uint32_t MeasurementTimingBudgetMicroSeconds;
- uint32_t FinalRangeTimeoutMicroSeconds;
- uint32_t PreRangeTimeoutMicroSeconds;
- uint32_t MsrcTimeoutMicroSeconds;
- uint8_t PhaseCalInt = 0;
-
- /* Check if valid clock period requested */
-
- if ((VCSELPulsePeriodPCLK % 2) != 0) {
- /* Value must be an even number */
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- } else if (VcselPeriodType == VL53L0X_VCSEL_PERIOD_PRE_RANGE &&
- (VCSELPulsePeriodPCLK < MinPreVcselPeriodPCLK ||
- VCSELPulsePeriodPCLK > MaxPreVcselPeriodPCLK)) {
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- } else if (VcselPeriodType == VL53L0X_VCSEL_PERIOD_FINAL_RANGE &&
- (VCSELPulsePeriodPCLK < MinFinalVcselPeriodPCLK ||
- VCSELPulsePeriodPCLK > MaxFinalVcselPeriodPCLK)) {
-
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
-
- /* Apply specific settings for the requested clock period */
-
- if (Status != VL53L0X_ERROR_NONE)
- return Status;
-
-
- if (VcselPeriodType == VL53L0X_VCSEL_PERIOD_PRE_RANGE) {
-
- /* Set phase check limits */
- if (VCSELPulsePeriodPCLK == 12) {
-
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
- 0x18);
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
- 0x08);
- } else if (VCSELPulsePeriodPCLK == 14) {
-
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
- 0x30);
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
- 0x08);
- } else if (VCSELPulsePeriodPCLK == 16) {
-
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
- 0x40);
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
- 0x08);
- } else if (VCSELPulsePeriodPCLK == 18) {
-
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
- 0x50);
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
- 0x08);
- }
- } else if (VcselPeriodType == VL53L0X_VCSEL_PERIOD_FINAL_RANGE) {
-
- if (VCSELPulsePeriodPCLK == 8) {
-
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
- 0x10);
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
- 0x08);
-
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x02);
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x0C);
-
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x01);
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_ALGO_PHASECAL_LIM,
- 0x30);
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x00);
- } else if (VCSELPulsePeriodPCLK == 10) {
-
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
- 0x28);
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
- 0x08);
-
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x09);
-
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x01);
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_ALGO_PHASECAL_LIM,
- 0x20);
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x00);
- } else if (VCSELPulsePeriodPCLK == 12) {
-
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
- 0x38);
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
- 0x08);
-
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x08);
-
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x01);
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_ALGO_PHASECAL_LIM,
- 0x20);
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x00);
- } else if (VCSELPulsePeriodPCLK == 14) {
-
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
- 0x048);
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
- 0x08);
-
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x07);
-
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x01);
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_ALGO_PHASECAL_LIM,
- 0x20);
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x00);
- }
- }
-
-
- /* Re-calculate and apply timeouts, in macro periods */
-
- if (Status == VL53L0X_ERROR_NONE) {
- vcsel_period_reg = VL53L0X_encode_vcsel_period((uint8_t)
- VCSELPulsePeriodPCLK);
-
- /* When the VCSEL period for the pre or final range is changed,
- * the corresponding timeout must be read from the device using
- * the current VCSEL period, then the new VCSEL period can be
- * applied. The timeout then must be written back to the device
- * using the new VCSEL period.
- *
- * For the MSRC timeout, the same applies - this timeout being
- * dependant on the pre-range vcsel period.
- */
- switch (VcselPeriodType) {
- case VL53L0X_VCSEL_PERIOD_PRE_RANGE:
- Status = get_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_PRE_RANGE,
- &PreRangeTimeoutMicroSeconds);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = get_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_MSRC,
- &MsrcTimeoutMicroSeconds);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD,
- vcsel_period_reg);
-
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = set_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_PRE_RANGE,
- PreRangeTimeoutMicroSeconds);
-
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = set_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_MSRC,
- MsrcTimeoutMicroSeconds);
-
- VL53L0X_SETDEVICESPECIFICPARAMETER(
- Dev,
- PreRangeVcselPulsePeriod,
- VCSELPulsePeriodPCLK);
- break;
- case VL53L0X_VCSEL_PERIOD_FINAL_RANGE:
- Status = get_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_FINAL_RANGE,
- &FinalRangeTimeoutMicroSeconds);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD,
- vcsel_period_reg);
-
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = set_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_FINAL_RANGE,
- FinalRangeTimeoutMicroSeconds);
-
- VL53L0X_SETDEVICESPECIFICPARAMETER(
- Dev,
- FinalRangeVcselPulsePeriod,
- VCSELPulsePeriodPCLK);
- break;
- default:
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
- }
-
- /* Finally, the timing budget must be re-applied */
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_GETPARAMETERFIELD(Dev,
- MeasurementTimingBudgetMicroSeconds,
- MeasurementTimingBudgetMicroSeconds);
-
- Status = VL53L0X_SetMeasurementTimingBudgetMicroSeconds(Dev,
- MeasurementTimingBudgetMicroSeconds);
- }
-
- /* Perform the phase calibration. This is needed after changing on
- * vcsel period.
- * get_data_enable = 0, restore_config = 1 */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_perform_phase_calibration(
- Dev, &PhaseCalInt, 0, 1);
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t vcsel_period_reg;
+ uint8_t min_pre_vcsel_period_pclk = 12;
+ uint8_t max_pre_vcsel_period_pclk = 18;
+ uint8_t min_final_vcsel_period_pclk = 8;
+ uint8_t max_final_vcsel_period_pclk = 14;
+ uint32_t measurement_timing_budget_micro_seconds;
+ uint32_t final_range_timeout_micro_seconds;
+ uint32_t pre_range_timeout_micro_seconds;
+ uint32_t msrc_timeout_micro_seconds;
+ uint8_t phase_cal_int = 0;
+
+ /* Check if valid clock period requested */
+
+ if ((vcsel_pulse_period_pclk % 2) != 0) {
+ /* Value must be an even number */
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ } else if (vcsel_period_type == VL53L0X_VCSEL_PERIOD_PRE_RANGE &&
+ (vcsel_pulse_period_pclk < min_pre_vcsel_period_pclk ||
+ vcsel_pulse_period_pclk > max_pre_vcsel_period_pclk)) {
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ } else if (vcsel_period_type == VL53L0X_VCSEL_PERIOD_FINAL_RANGE &&
+ (vcsel_pulse_period_pclk < min_final_vcsel_period_pclk ||
+ vcsel_pulse_period_pclk > max_final_vcsel_period_pclk)) {
+
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+
+ /* Apply specific settings for the requested clock period */
+
+ if (status != VL53L0X_ERROR_NONE)
+ return status;
+
+
+ if (vcsel_period_type == VL53L0X_VCSEL_PERIOD_PRE_RANGE) {
+
+ /* Set phase check limits */
+ if (vcsel_pulse_period_pclk == 12) {
+
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x18);
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+ } else if (vcsel_pulse_period_pclk == 14) {
+
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x30);
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+ } else if (vcsel_pulse_period_pclk == 16) {
+
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x40);
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+ } else if (vcsel_pulse_period_pclk == 18) {
+
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x50);
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+ }
+ } else if (vcsel_period_type == VL53L0X_VCSEL_PERIOD_FINAL_RANGE) {
+
+ if (vcsel_pulse_period_pclk == 8) {
+
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x10);
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x02);
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x0C);
+
+ status |= vl53l0x_write_byte(dev, 0xff, 0x01);
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_ALGO_PHASECAL_LIM,
+ 0x30);
+ status |= vl53l0x_write_byte(dev, 0xff, 0x00);
+ } else if (vcsel_pulse_period_pclk == 10) {
+
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x28);
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x09);
+
+ status |= vl53l0x_write_byte(dev, 0xff, 0x01);
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_ALGO_PHASECAL_LIM,
+ 0x20);
+ status |= vl53l0x_write_byte(dev, 0xff, 0x00);
+ } else if (vcsel_pulse_period_pclk == 12) {
+
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x38);
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x08);
+
+ status |= vl53l0x_write_byte(dev, 0xff, 0x01);
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_ALGO_PHASECAL_LIM,
+ 0x20);
+ status |= vl53l0x_write_byte(dev, 0xff, 0x00);
+ } else if (vcsel_pulse_period_pclk == 14) {
+
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
+ 0x048);
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
+ 0x08);
+
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_GLOBAL_CONFIG_VCSEL_WIDTH, 0x03);
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_ALGO_PHASECAL_CONFIG_TIMEOUT, 0x07);
+
+ status |= vl53l0x_write_byte(dev, 0xff, 0x01);
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_ALGO_PHASECAL_LIM,
+ 0x20);
+ status |= vl53l0x_write_byte(dev, 0xff, 0x00);
+ }
+ }
+
+
+ /* Re-calculate and apply timeouts, in macro periods */
+
+ if (status == VL53L0X_ERROR_NONE) {
+ vcsel_period_reg = lv53l0x_encode_vcsel_period((uint8_t)
+ vcsel_pulse_period_pclk);
+
+ /* When the VCSEL period for the pre or final range is changed,
+ * the corresponding timeout must be read from the device using
+ * the current VCSEL period, then the new VCSEL period can be
+ * applied. The timeout then must be written back to the device
+ * using the new VCSEL period.
+ *
+ * For the MSRC timeout, the same applies - this timeout being
+ * dependant on the pre-range vcsel period.
+ */
+ switch (vcsel_period_type) {
+ case VL53L0X_VCSEL_PERIOD_PRE_RANGE:
+ status = get_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_PRE_RANGE,
+ &pre_range_timeout_micro_seconds);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = get_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_MSRC,
+ &msrc_timeout_micro_seconds);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD,
+ vcsel_period_reg);
+
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = set_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_PRE_RANGE,
+ pre_range_timeout_micro_seconds);
+
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = set_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_MSRC,
+ msrc_timeout_micro_seconds);
+
+ VL53L0X_SETDEVICESPECIFICPARAMETER(
+ dev,
+ PreRangeVcselPulsePeriod,
+ vcsel_pulse_period_pclk);
+ break;
+ case VL53L0X_VCSEL_PERIOD_FINAL_RANGE:
+ status = get_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_FINAL_RANGE,
+ &final_range_timeout_micro_seconds);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD,
+ vcsel_period_reg);
+
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = set_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_FINAL_RANGE,
+ final_range_timeout_micro_seconds);
+
+ VL53L0X_SETDEVICESPECIFICPARAMETER(
+ dev,
+ FinalRangeVcselPulsePeriod,
+ vcsel_pulse_period_pclk);
+ break;
+ default:
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ /* Finally, the timing budget must be re-applied */
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_GETPARAMETERFIELD(dev,
+ MeasurementTimingBudgetMicroSeconds,
+ measurement_timing_budget_micro_seconds);
+
+ status = vl53l0x_set_measurement_timing_budget_micro_seconds(dev,
+ measurement_timing_budget_micro_seconds);
+ }
+
+ /* Perform the phase calibration. This is needed after changing on
+ * vcsel period.
+ * get_data_enable = 0, restore_config = 1 */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_perform_phase_calibration(
+ dev, &phase_cal_int, 0, 1);
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_SetVcselPulsePeriod(VL53L0X_DEV Dev,
- VL53L0X_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriodPCLK)
+VL53L0X_Error VL53L0X::vl53l0x_set_vcsel_pulse_period(VL53L0X_DEV dev,
+ VL53L0X_VcselPeriod vcsel_period_type, uint8_t vcsel_pulse_period)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_set_vcsel_pulse_period(Dev, VcselPeriodType,
- VCSELPulsePeriodPCLK);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = wrapped_vl53l0x_set_vcsel_pulse_period(dev, vcsel_period_type,
+ vcsel_pulse_period);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_get_vcsel_pulse_period(VL53L0X_DEV Dev,
- VL53L0X_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriodPCLK)
+VL53L0X_Error VL53L0X::wrapped_vl53l0x_get_vcsel_pulse_period(VL53L0X_DEV dev,
+ VL53L0X_VcselPeriod vcsel_period_type, uint8_t *p_vcsel_pulse_period_pclk)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t vcsel_period_reg;
-
- switch (VcselPeriodType) {
- case VL53L0X_VCSEL_PERIOD_PRE_RANGE:
- Status = VL53L0X_RdByte(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD,
- &vcsel_period_reg);
- break;
- case VL53L0X_VCSEL_PERIOD_FINAL_RANGE:
- Status = VL53L0X_RdByte(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD,
- &vcsel_period_reg);
- break;
- default:
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
-
- if (Status == VL53L0X_ERROR_NONE)
- *pVCSELPulsePeriodPCLK =
- VL53L0X_decode_vcsel_period(vcsel_period_reg);
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t vcsel_period_reg;
+
+ switch (vcsel_period_type) {
+ case VL53L0X_VCSEL_PERIOD_PRE_RANGE:
+ status = vl53l0x_read_byte(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD,
+ &vcsel_period_reg);
+ break;
+ case VL53L0X_VCSEL_PERIOD_FINAL_RANGE:
+ status = vl53l0x_read_byte(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD,
+ &vcsel_period_reg);
+ break;
+ default:
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+
+ if (status == VL53L0X_ERROR_NONE)
+ *p_vcsel_pulse_period_pclk =
+ vl53l0x_decode_vcsel_period(vcsel_period_reg);
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetVcselPulsePeriod(VL53L0X_DEV Dev,
- VL53L0X_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriodPCLK)
+VL53L0X_Error VL53L0X::vl53l0x_get_vcsel_pulse_period(VL53L0X_DEV dev,
+ VL53L0X_VcselPeriod vcsel_period_type, uint8_t *p_vcsel_pulse_period_pclk)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_get_vcsel_pulse_period(Dev, VcselPeriodType,
- pVCSELPulsePeriodPCLK);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = wrapped_vl53l0x_get_vcsel_pulse_period(dev, vcsel_period_type,
+ p_vcsel_pulse_period_pclk);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-uint32_t VL53L0X::VL53L0X_decode_timeout(uint16_t encoded_timeout)
+uint32_t VL53L0X::vl53l0x_decode_timeout(uint16_t encoded_timeout)
{
- /*!
- * Decode 16-bit timeout register value - format (LSByte * 2^MSByte) + 1
- */
-
- uint32_t timeout_macro_clks = 0;
-
- timeout_macro_clks = ((uint32_t) (encoded_timeout & 0x00FF)
- << (uint32_t) ((encoded_timeout & 0xFF00) >> 8)) + 1;
-
- return timeout_macro_clks;
+ /*!
+ * Decode 16-bit timeout register value - format (LSByte * 2^MSByte) + 1
+ */
+
+ uint32_t timeout_macro_clks = 0;
+
+ timeout_macro_clks = ((uint32_t)(encoded_timeout & 0x00FF)
+ << (uint32_t)((encoded_timeout & 0xFF00) >> 8)) + 1;
+
+ return timeout_macro_clks;
}
-uint32_t VL53L0X::VL53L0X_calc_macro_period_ps(VL53L0X_DEV Dev, uint8_t vcsel_period_pclks)
+uint32_t VL53L0X::vl53l0x_calc_macro_period_ps(VL53L0X_DEV dev, uint8_t vcsel_period_pclks)
{
- uint64_t PLL_period_ps;
- uint32_t macro_period_vclks;
- uint32_t macro_period_ps;
-
- LOG_FUNCTION_START("");
-
- /* The above calculation will produce rounding errors,
- therefore set fixed value
- */
- PLL_period_ps = 1655;
-
- macro_period_vclks = 2304;
- macro_period_ps = (uint32_t)(macro_period_vclks
- * vcsel_period_pclks * PLL_period_ps);
-
- LOG_FUNCTION_END("");
- return macro_period_ps;
+ uint64_t pll_period_ps;
+ uint32_t macro_period_vclks;
+ uint32_t macro_period_ps;
+
+ LOG_FUNCTION_START("");
+
+ /* The above calculation will produce rounding errors,
+ therefore set fixed value
+ */
+ pll_period_ps = 1655;
+
+ macro_period_vclks = 2304;
+ macro_period_ps = (uint32_t)(macro_period_vclks
+ * vcsel_period_pclks * pll_period_ps);
+
+ LOG_FUNCTION_END("");
+ return macro_period_ps;
}
/* To convert register value into us */
-uint32_t VL53L0X::VL53L0X_calc_timeout_us(VL53L0X_DEV Dev,
- uint16_t timeout_period_mclks,
- uint8_t vcsel_period_pclks)
+uint32_t VL53L0X::vl53l0x_calc_timeout_us(VL53L0X_DEV dev,
+ uint16_t timeout_period_mclks,
+ uint8_t vcsel_period_pclks)
{
- uint32_t macro_period_ps;
- uint32_t macro_period_ns;
- uint32_t actual_timeout_period_us = 0;
-
- macro_period_ps = VL53L0X_calc_macro_period_ps(Dev, vcsel_period_pclks);
- macro_period_ns = (macro_period_ps + 500) / 1000;
-
- actual_timeout_period_us =
- ((timeout_period_mclks * macro_period_ns) + 500) / 1000;
-
- return actual_timeout_period_us;
+ uint32_t macro_period_ps;
+ uint32_t macro_period_ns;
+ uint32_t actual_timeout_period_us = 0;
+
+ macro_period_ps = vl53l0x_calc_macro_period_ps(dev, vcsel_period_pclks);
+ macro_period_ns = (macro_period_ps + 500) / 1000;
+
+ actual_timeout_period_us =
+ ((timeout_period_mclks * macro_period_ns) + 500) / 1000;
+
+ return actual_timeout_period_us;
}
-VL53L0X_Error VL53L0X::get_sequence_step_timeout(VL53L0X_DEV Dev,
- VL53L0X_SequenceStepId SequenceStepId,
- uint32_t *pTimeOutMicroSecs)
+VL53L0X_Error VL53L0X::get_sequence_step_timeout(VL53L0X_DEV dev,
+ VL53L0X_SequenceStepId sequence_step_id,
+ uint32_t *p_time_out_micro_secs)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t CurrentVCSELPulsePeriodPClk;
- uint8_t EncodedTimeOutByte = 0;
- uint32_t TimeoutMicroSeconds = 0;
- uint16_t PreRangeEncodedTimeOut = 0;
- uint16_t MsrcTimeOutMClks;
- uint16_t PreRangeTimeOutMClks;
- uint16_t FinalRangeTimeOutMClks = 0;
- uint16_t FinalRangeEncodedTimeOut;
- VL53L0X_SchedulerSequenceSteps_t SchedulerSequenceSteps;
-
- if ((SequenceStepId == VL53L0X_SEQUENCESTEP_TCC) ||
- (SequenceStepId == VL53L0X_SEQUENCESTEP_DSS) ||
- (SequenceStepId == VL53L0X_SEQUENCESTEP_MSRC)) {
-
- Status = VL53L0X_GetVcselPulsePeriod(Dev,
- VL53L0X_VCSEL_PERIOD_PRE_RANGE,
- &CurrentVCSELPulsePeriodPClk);
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_RdByte(Dev,
- VL53L0X_REG_MSRC_CONFIG_TIMEOUT_MACROP,
- &EncodedTimeOutByte);
- }
- MsrcTimeOutMClks = VL53L0X_decode_timeout(EncodedTimeOutByte);
-
- TimeoutMicroSeconds = VL53L0X_calc_timeout_us(Dev,
- MsrcTimeOutMClks,
- CurrentVCSELPulsePeriodPClk);
- } else if (SequenceStepId == VL53L0X_SEQUENCESTEP_PRE_RANGE) {
- /* Retrieve PRE-RANGE VCSEL Period */
- Status = VL53L0X_GetVcselPulsePeriod(Dev,
- VL53L0X_VCSEL_PERIOD_PRE_RANGE,
- &CurrentVCSELPulsePeriodPClk);
-
- /* Retrieve PRE-RANGE Timeout in Macro periods (MCLKS) */
- if (Status == VL53L0X_ERROR_NONE) {
-
- /* Retrieve PRE-RANGE VCSEL Period */
- Status = VL53L0X_GetVcselPulsePeriod(Dev,
- VL53L0X_VCSEL_PERIOD_PRE_RANGE,
- &CurrentVCSELPulsePeriodPClk);
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_RdWord(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
- &PreRangeEncodedTimeOut);
- }
-
- PreRangeTimeOutMClks = VL53L0X_decode_timeout(
- PreRangeEncodedTimeOut);
-
- TimeoutMicroSeconds = VL53L0X_calc_timeout_us(Dev,
- PreRangeTimeOutMClks,
- CurrentVCSELPulsePeriodPClk);
- }
- } else if (SequenceStepId == VL53L0X_SEQUENCESTEP_FINAL_RANGE) {
-
- VL53L0X_GetSequenceStepEnables(Dev, &SchedulerSequenceSteps);
- PreRangeTimeOutMClks = 0;
-
- if (SchedulerSequenceSteps.PreRangeOn) {
- /* Retrieve PRE-RANGE VCSEL Period */
- Status = VL53L0X_GetVcselPulsePeriod(Dev,
- VL53L0X_VCSEL_PERIOD_PRE_RANGE,
- &CurrentVCSELPulsePeriodPClk);
-
- /* Retrieve PRE-RANGE Timeout in Macro periods
- * (MCLKS) */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_RdWord(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
- &PreRangeEncodedTimeOut);
- PreRangeTimeOutMClks = VL53L0X_decode_timeout(
- PreRangeEncodedTimeOut);
- }
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- /* Retrieve FINAL-RANGE VCSEL Period */
- Status = VL53L0X_GetVcselPulsePeriod(Dev,
- VL53L0X_VCSEL_PERIOD_FINAL_RANGE,
- &CurrentVCSELPulsePeriodPClk);
- }
-
- /* Retrieve FINAL-RANGE Timeout in Macro periods (MCLKS) */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_RdWord(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,
- &FinalRangeEncodedTimeOut);
- FinalRangeTimeOutMClks = VL53L0X_decode_timeout(
- FinalRangeEncodedTimeOut);
- }
-
- FinalRangeTimeOutMClks -= PreRangeTimeOutMClks;
- TimeoutMicroSeconds = VL53L0X_calc_timeout_us(Dev,
- FinalRangeTimeOutMClks,
- CurrentVCSELPulsePeriodPClk);
- }
-
- *pTimeOutMicroSecs = TimeoutMicroSeconds;
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t current_vcsel_pulse_period_p_clk;
+ uint8_t encoded_time_out_byte = 0;
+ uint32_t timeout_micro_seconds = 0;
+ uint16_t pre_range_encoded_time_out = 0;
+ uint16_t msrc_time_out_m_clks;
+ uint16_t pre_range_time_out_m_clks;
+ uint16_t final_range_time_out_m_clks = 0;
+ uint16_t final_range_encoded_time_out;
+ VL53L0X_SchedulerSequenceSteps_t scheduler_sequence_steps;
+
+ if ((sequence_step_id == VL53L0X_SEQUENCESTEP_TCC) ||
+ (sequence_step_id == VL53L0X_SEQUENCESTEP_DSS) ||
+ (sequence_step_id == VL53L0X_SEQUENCESTEP_MSRC)) {
+
+ status = vl53l0x_get_vcsel_pulse_period(dev,
+ VL53L0X_VCSEL_PERIOD_PRE_RANGE,
+ ¤t_vcsel_pulse_period_p_clk);
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_read_byte(dev,
+ VL53L0X_REG_MSRC_CONFIG_TIMEOUT_MACROP,
+ &encoded_time_out_byte);
+ }
+ msrc_time_out_m_clks = vl53l0x_decode_timeout(encoded_time_out_byte);
+
+ timeout_micro_seconds = vl53l0x_calc_timeout_us(dev,
+ msrc_time_out_m_clks,
+ current_vcsel_pulse_period_p_clk);
+ } else if (sequence_step_id == VL53L0X_SEQUENCESTEP_PRE_RANGE) {
+ /* Retrieve PRE-RANGE VCSEL Period */
+ status = vl53l0x_get_vcsel_pulse_period(dev,
+ VL53L0X_VCSEL_PERIOD_PRE_RANGE,
+ ¤t_vcsel_pulse_period_p_clk);
+
+ /* Retrieve PRE-RANGE Timeout in Macro periods (MCLKS) */
+ if (status == VL53L0X_ERROR_NONE) {
+
+ /* Retrieve PRE-RANGE VCSEL Period */
+ status = vl53l0x_get_vcsel_pulse_period(dev,
+ VL53L0X_VCSEL_PERIOD_PRE_RANGE,
+ ¤t_vcsel_pulse_period_p_clk);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_read_word(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
+ &pre_range_encoded_time_out);
+ }
+
+ pre_range_time_out_m_clks = vl53l0x_decode_timeout(
+ pre_range_encoded_time_out);
+
+ timeout_micro_seconds = vl53l0x_calc_timeout_us(dev,
+ pre_range_time_out_m_clks,
+ current_vcsel_pulse_period_p_clk);
+ }
+ } else if (sequence_step_id == VL53L0X_SEQUENCESTEP_FINAL_RANGE) {
+
+ vl53l0x_get_sequence_step_enables(dev, &scheduler_sequence_steps);
+ pre_range_time_out_m_clks = 0;
+
+ if (scheduler_sequence_steps.PreRangeOn) {
+ /* Retrieve PRE-RANGE VCSEL Period */
+ status = vl53l0x_get_vcsel_pulse_period(dev,
+ VL53L0X_VCSEL_PERIOD_PRE_RANGE,
+ ¤t_vcsel_pulse_period_p_clk);
+
+ /* Retrieve PRE-RANGE Timeout in Macro periods
+ * (MCLKS) */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_read_word(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
+ &pre_range_encoded_time_out);
+ pre_range_time_out_m_clks = vl53l0x_decode_timeout(
+ pre_range_encoded_time_out);
+ }
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ /* Retrieve FINAL-RANGE VCSEL Period */
+ status = vl53l0x_get_vcsel_pulse_period(dev,
+ VL53L0X_VCSEL_PERIOD_FINAL_RANGE,
+ ¤t_vcsel_pulse_period_p_clk);
+ }
+
+ /* Retrieve FINAL-RANGE Timeout in Macro periods (MCLKS) */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_read_word(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,
+ &final_range_encoded_time_out);
+ final_range_time_out_m_clks = vl53l0x_decode_timeout(
+ final_range_encoded_time_out);
+ }
+
+ final_range_time_out_m_clks -= pre_range_time_out_m_clks;
+ timeout_micro_seconds = vl53l0x_calc_timeout_us(dev,
+ final_range_time_out_m_clks,
+ current_vcsel_pulse_period_p_clk);
+ }
+
+ *p_time_out_micro_secs = timeout_micro_seconds;
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_get_measurement_timing_budget_micro_seconds(VL53L0X_DEV Dev,
- uint32_t *pMeasurementTimingBudgetMicroSeconds)
+VL53L0X_Error VL53L0X::wrapped_vl53l0x_get_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
+ uint32_t *p_measurement_timing_budget_micro_seconds)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- VL53L0X_SchedulerSequenceSteps_t SchedulerSequenceSteps;
- uint32_t FinalRangeTimeoutMicroSeconds;
- uint32_t MsrcDccTccTimeoutMicroSeconds = 2000;
- uint32_t StartOverheadMicroSeconds = 1910;
- uint32_t EndOverheadMicroSeconds = 960;
- uint32_t MsrcOverheadMicroSeconds = 660;
- uint32_t TccOverheadMicroSeconds = 590;
- uint32_t DssOverheadMicroSeconds = 690;
- uint32_t PreRangeOverheadMicroSeconds = 660;
- uint32_t FinalRangeOverheadMicroSeconds = 550;
- uint32_t PreRangeTimeoutMicroSeconds = 0;
-
- LOG_FUNCTION_START("");
-
- /* Start and end overhead times always present */
- *pMeasurementTimingBudgetMicroSeconds
- = StartOverheadMicroSeconds + EndOverheadMicroSeconds;
-
- Status = VL53L0X_GetSequenceStepEnables(Dev, &SchedulerSequenceSteps);
-
- if (Status != VL53L0X_ERROR_NONE) {
- LOG_FUNCTION_END(Status);
- return Status;
- }
-
-
- if (SchedulerSequenceSteps.TccOn ||
- SchedulerSequenceSteps.MsrcOn ||
- SchedulerSequenceSteps.DssOn) {
-
- Status = get_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_MSRC,
- &MsrcDccTccTimeoutMicroSeconds);
-
- if (Status == VL53L0X_ERROR_NONE) {
- if (SchedulerSequenceSteps.TccOn) {
- *pMeasurementTimingBudgetMicroSeconds +=
- MsrcDccTccTimeoutMicroSeconds +
- TccOverheadMicroSeconds;
- }
-
- if (SchedulerSequenceSteps.DssOn) {
- *pMeasurementTimingBudgetMicroSeconds +=
- 2 * (MsrcDccTccTimeoutMicroSeconds +
- DssOverheadMicroSeconds);
- } else if (SchedulerSequenceSteps.MsrcOn) {
- *pMeasurementTimingBudgetMicroSeconds +=
- MsrcDccTccTimeoutMicroSeconds +
- MsrcOverheadMicroSeconds;
- }
- }
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- if (SchedulerSequenceSteps.PreRangeOn) {
- Status = get_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_PRE_RANGE,
- &PreRangeTimeoutMicroSeconds);
- *pMeasurementTimingBudgetMicroSeconds +=
- PreRangeTimeoutMicroSeconds +
- PreRangeOverheadMicroSeconds;
- }
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- if (SchedulerSequenceSteps.FinalRangeOn) {
- Status = get_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_FINAL_RANGE,
- &FinalRangeTimeoutMicroSeconds);
- *pMeasurementTimingBudgetMicroSeconds +=
- (FinalRangeTimeoutMicroSeconds +
- FinalRangeOverheadMicroSeconds);
- }
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETPARAMETERFIELD(Dev,
- MeasurementTimingBudgetMicroSeconds,
- *pMeasurementTimingBudgetMicroSeconds);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ VL53L0X_SchedulerSequenceSteps_t scheduler_sequence_steps;
+ uint32_t final_range_timeout_micro_seconds;
+ uint32_t msrc_dcc_tcc_timeout_micro_seconds = 2000;
+ uint32_t start_overhead_micro_seconds = 1910;
+ uint32_t end_overhead_micro_seconds = 960;
+ uint32_t msrc_overhead_micro_seconds = 660;
+ uint32_t tcc_overhead_micro_seconds = 590;
+ uint32_t dss_overhead_micro_seconds = 690;
+ uint32_t pre_range_overhead_micro_seconds = 660;
+ uint32_t final_range_overhead_micro_seconds = 550;
+ uint32_t pre_range_timeout_micro_seconds = 0;
+
+ LOG_FUNCTION_START("");
+
+ /* Start and end overhead times always present */
+ *p_measurement_timing_budget_micro_seconds
+ = start_overhead_micro_seconds + end_overhead_micro_seconds;
+
+ status = vl53l0x_get_sequence_step_enables(dev, &scheduler_sequence_steps);
+
+ if (status != VL53L0X_ERROR_NONE) {
+ LOG_FUNCTION_END(status);
+ return status;
+ }
+
+
+ if (scheduler_sequence_steps.TccOn ||
+ scheduler_sequence_steps.MsrcOn ||
+ scheduler_sequence_steps.DssOn) {
+
+ status = get_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_MSRC,
+ &msrc_dcc_tcc_timeout_micro_seconds);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ if (scheduler_sequence_steps.TccOn) {
+ *p_measurement_timing_budget_micro_seconds +=
+ msrc_dcc_tcc_timeout_micro_seconds +
+ tcc_overhead_micro_seconds;
+ }
+
+ if (scheduler_sequence_steps.DssOn) {
+ *p_measurement_timing_budget_micro_seconds +=
+ 2 * (msrc_dcc_tcc_timeout_micro_seconds +
+ dss_overhead_micro_seconds);
+ } else if (scheduler_sequence_steps.MsrcOn) {
+ *p_measurement_timing_budget_micro_seconds +=
+ msrc_dcc_tcc_timeout_micro_seconds +
+ msrc_overhead_micro_seconds;
+ }
+ }
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ if (scheduler_sequence_steps.PreRangeOn) {
+ status = get_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_PRE_RANGE,
+ &pre_range_timeout_micro_seconds);
+ *p_measurement_timing_budget_micro_seconds +=
+ pre_range_timeout_micro_seconds +
+ pre_range_overhead_micro_seconds;
+ }
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ if (scheduler_sequence_steps.FinalRangeOn) {
+ status = get_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_FINAL_RANGE,
+ &final_range_timeout_micro_seconds);
+ *p_measurement_timing_budget_micro_seconds +=
+ (final_range_timeout_micro_seconds +
+ final_range_overhead_micro_seconds);
+ }
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETPARAMETERFIELD(dev,
+ MeasurementTimingBudgetMicroSeconds,
+ *p_measurement_timing_budget_micro_seconds);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetMeasurementTimingBudgetMicroSeconds(VL53L0X_DEV Dev,
- uint32_t *pMeasurementTimingBudgetMicroSeconds)
+VL53L0X_Error VL53L0X::vl53l0x_get_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
+ uint32_t *p_measurement_timing_budget_micro_seconds)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_get_measurement_timing_budget_micro_seconds(Dev,
- pMeasurementTimingBudgetMicroSeconds);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = wrapped_vl53l0x_get_measurement_timing_budget_micro_seconds(dev,
+ p_measurement_timing_budget_micro_seconds);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetDeviceParameters(VL53L0X_DEV Dev,
- VL53L0X_DeviceParameters_t *pDeviceParameters)
+VL53L0X_Error VL53L0X::vl53l0x_get_device_parameters(VL53L0X_DEV dev,
+ VL53L0X_DeviceParameters_t *p_device_parameters)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- int i;
-
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_GetDeviceMode(Dev, &(pDeviceParameters->DeviceMode));
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_GetInterMeasurementPeriodMilliSeconds(Dev,
- &(pDeviceParameters->InterMeasurementPeriodMilliSeconds));
-
-
- if (Status == VL53L0X_ERROR_NONE)
- pDeviceParameters->XTalkCompensationEnable = 0;
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_GetXTalkCompensationRateMegaCps(Dev,
- &(pDeviceParameters->XTalkCompensationRateMegaCps));
-
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_GetOffsetCalibrationDataMicroMeter(Dev,
- &(pDeviceParameters->RangeOffsetMicroMeters));
-
-
- if (Status == VL53L0X_ERROR_NONE) {
- for (i = 0; i < VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
- /* get first the values, then the enables.
- * VL53L0X_GetLimitCheckValue will modify the enable
- * flags
- */
- if (Status == VL53L0X_ERROR_NONE) {
- Status |= VL53L0X_GetLimitCheckValue(Dev, i,
- &(pDeviceParameters->LimitChecksValue[i]));
- } else {
- break;
- }
- if (Status == VL53L0X_ERROR_NONE) {
- Status |= VL53L0X_GetLimitCheckEnable(Dev, i,
- &(pDeviceParameters->LimitChecksEnable[i]));
- } else {
- break;
- }
- }
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_GetWrapAroundCheckEnable(Dev,
- &(pDeviceParameters->WrapAroundCheckEnable));
- }
-
- /* Need to be done at the end as it uses VCSELPulsePeriod */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_GetMeasurementTimingBudgetMicroSeconds(Dev,
- &(pDeviceParameters->MeasurementTimingBudgetMicroSeconds));
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ int i;
+
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_get_device_mode(dev, &(p_device_parameters->DeviceMode));
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_get_inter_measurement_period_milli_seconds(dev,
+ &(p_device_parameters->InterMeasurementPeriodMilliSeconds));
+
+
+ if (status == VL53L0X_ERROR_NONE)
+ p_device_parameters->XTalkCompensationEnable = 0;
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_get_x_talk_compensation_rate_mega_cps(dev,
+ &(p_device_parameters->XTalkCompensationRateMegaCps));
+
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_get_offset_calibration_data_micro_meter(dev,
+ &(p_device_parameters->RangeOffsetMicroMeters));
+
+
+ if (status == VL53L0X_ERROR_NONE) {
+ for (i = 0; i < VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
+ /* get first the values, then the enables.
+ * VL53L0X_GetLimitCheckValue will modify the enable
+ * flags
+ */
+ if (status == VL53L0X_ERROR_NONE) {
+ status |= vl53l0x_get_limit_check_value(dev, i,
+ &(p_device_parameters->LimitChecksValue[i]));
+ } else {
+ break;
+ }
+ if (status == VL53L0X_ERROR_NONE) {
+ status |= vl53l0x_get_limit_check_enable(dev, i,
+ &(p_device_parameters->LimitChecksEnable[i]));
+ } else {
+ break;
+ }
+ }
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_get_wrap_around_check_enable(dev,
+ &(p_device_parameters->WrapAroundCheckEnable));
+ }
+
+ /* Need to be done at the end as it uses VCSELPulsePeriod */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_get_measurement_timing_budget_micro_seconds(dev,
+ &(p_device_parameters->MeasurementTimingBudgetMicroSeconds));
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_SetLimitCheckValue(VL53L0X_DEV Dev, uint16_t LimitCheckId,
- FixPoint1616_t LimitCheckValue)
+VL53L0X_Error VL53L0X::vl53l0x_set_limit_check_value(VL53L0X_DEV dev, uint16_t limit_check_id,
+ FixPoint1616_t limit_check_value)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t Temp8;
-
- LOG_FUNCTION_START("");
-
- VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable, LimitCheckId,
- Temp8);
-
- if (Temp8 == 0) { /* disabled write only internal value */
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
- LimitCheckId, LimitCheckValue);
- } else {
-
- switch (LimitCheckId) {
-
- case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:
- /* internal computation: */
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
- VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
- LimitCheckValue);
- break;
-
- case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
-
- Status = VL53L0X_WrWord(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
- VL53L0X_FIXPOINT1616TOFIXPOINT97(
- LimitCheckValue));
-
- break;
-
- case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:
-
- /* internal computation: */
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
- VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
- LimitCheckValue);
-
- break;
-
- case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
-
- /* internal computation: */
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
- VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
- LimitCheckValue);
-
- break;
-
- case VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC:
- case VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE:
-
- Status = VL53L0X_WrWord(Dev,
- VL53L0X_REG_PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT,
- VL53L0X_FIXPOINT1616TOFIXPOINT97(
- LimitCheckValue));
-
- break;
-
- default:
- Status = VL53L0X_ERROR_INVALID_PARAMS;
-
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
- LimitCheckId, LimitCheckValue);
- }
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t temp8;
+
+ LOG_FUNCTION_START("");
+
+ VL53L0X_GETARRAYPARAMETERFIELD(dev, LimitChecksEnable, limit_check_id,
+ temp8);
+
+ if (temp8 == 0) { /* disabled write only internal value */
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksValue,
+ limit_check_id, limit_check_value);
+ } else {
+
+ switch (limit_check_id) {
+
+ case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:
+ /* internal computation: */
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksValue,
+ VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
+ limit_check_value);
+ break;
+
+ case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+
+ status = vl53l0x_write_word(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
+ VL53L0X_FIXPOINT1616TOFIXPOINT97(
+ limit_check_value));
+
+ break;
+
+ case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:
+
+ /* internal computation: */
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksValue,
+ VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
+ limit_check_value);
+
+ break;
+
+ case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
+
+ /* internal computation: */
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksValue,
+ VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ limit_check_value);
+
+ break;
+
+ case VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC:
+ case VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE:
+
+ status = vl53l0x_write_word(dev,
+ VL53L0X_REG_PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT,
+ VL53L0X_FIXPOINT1616TOFIXPOINT97(
+ limit_check_value));
+
+ break;
+
+ default:
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksValue,
+ limit_check_id, limit_check_value);
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_DataInit(VL53L0X_DEV Dev)
+VL53L0X_Error VL53L0X::vl53l0x_data_init(VL53L0X_DEV dev)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- VL53L0X_DeviceParameters_t CurrentParameters;
- int i;
- uint8_t StopVariable;
-
- LOG_FUNCTION_START("");
-
- /* by default the I2C is running at 1V8 if you want to change it you
- * need to include this define at compilation level. */
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ VL53L0X_DeviceParameters_t CurrentParameters;
+ int i;
+ uint8_t StopVariable;
+
+ LOG_FUNCTION_START("");
+
+ /* by default the I2C is running at 1V8 if you want to change it you
+ * need to include this define at compilation level. */
#ifdef USE_I2C_2V8
- Status = VL53L0X_UpdateByte(Dev,
- VL53L0X_REG_VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV,
- 0xFE,
- 0x01);
+ Status = VL53L0X_UpdateByte(Dev,
+ VL53L0X_REG_VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV,
+ 0xFE,
+ 0x01);
#endif
- /* Set I2C standard mode */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev, 0x88, 0x00);
-
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, ReadDataFromDeviceDone, 0);
+ /* Set I2C standard mode */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev, 0x88, 0x00);
+
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev, ReadDataFromDeviceDone, 0);
#ifdef USE_IQC_STATION
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_apply_offset_adjustment(Dev);
+ if (Status == VL53L0X_ERROR_NONE)
+ Status = VL53L0X_apply_offset_adjustment(Dev);
#endif
- /* Default value is 1000 for Linearity Corrective Gain */
- PALDevDataSet(Dev, LinearityCorrectiveGain, 1000);
-
- /* Dmax default Parameter */
- PALDevDataSet(Dev, DmaxCalRangeMilliMeter, 400);
- PALDevDataSet(Dev, DmaxCalSignalRateRtnMegaCps,
- (FixPoint1616_t)((0x00016B85))); /* 1.42 No Cover Glass*/
-
- /* Set Default static parameters
- *set first temporary values 9.44MHz * 65536 = 618660 */
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, OscFrequencyMHz, 618660);
-
- /* Set Default XTalkCompensationRateMegaCps to 0 */
- VL53L0X_SETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps, 0);
-
- /* Get default parameters */
- Status = VL53L0X_GetDeviceParameters(Dev, &CurrentParameters);
- if (Status == VL53L0X_ERROR_NONE) {
- /* initialize PAL values */
- CurrentParameters.DeviceMode = VL53L0X_DEVICEMODE_SINGLE_RANGING;
- CurrentParameters.HistogramMode = VL53L0X_HISTOGRAMMODE_DISABLED;
- PALDevDataSet(Dev, CurrentParameters, CurrentParameters);
- }
-
- /* Sigma estimator variable */
- PALDevDataSet(Dev, SigmaEstRefArray, 100);
- PALDevDataSet(Dev, SigmaEstEffPulseWidth, 900);
- PALDevDataSet(Dev, SigmaEstEffAmbWidth, 500);
- PALDevDataSet(Dev, targetRefRate, 0x0A00); /* 20 MCPS in 9:7 format */
-
- /* Use internal default settings */
- PALDevDataSet(Dev, UseInternalTuningSettings, 1);
-
- Status |= VL53L0X_WrByte(Dev, 0x80, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0x00, 0x00);
- Status |= VL53L0X_RdByte(Dev, 0x91, &StopVariable);
- PALDevDataSet(Dev, StopVariable, StopVariable);
- Status |= VL53L0X_WrByte(Dev, 0x00, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
- Status |= VL53L0X_WrByte(Dev, 0x80, 0x00);
-
- /* Enable all check */
- for (i = 0; i < VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
- if (Status == VL53L0X_ERROR_NONE)
- Status |= VL53L0X_SetLimitCheckEnable(Dev, i, 1);
- else
- break;
-
- }
-
- /* Disable the following checks */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_SetLimitCheckEnable(Dev,
- VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP, 0);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_SetLimitCheckEnable(Dev,
- VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 0);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_SetLimitCheckEnable(Dev,
- VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC, 0);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_SetLimitCheckEnable(Dev,
- VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE, 0);
-
- /* Limit default values */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetLimitCheckValue(Dev,
- VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
- (FixPoint1616_t)(18 * 65536));
- }
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetLimitCheckValue(Dev,
- VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
- (FixPoint1616_t)(25 * 65536 / 100));
- /* 0.25 * 65536 */
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetLimitCheckValue(Dev,
- VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
- (FixPoint1616_t)(35 * 65536));
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetLimitCheckValue(Dev,
- VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
- (FixPoint1616_t)(0 * 65536));
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
-
- PALDevDataSet(Dev, SequenceConfig, 0xFF);
- Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
- 0xFF);
-
- /* Set PAL state to tell that we are waiting for call to
- * VL53L0X_StaticInit */
- PALDevDataSet(Dev, PalState, VL53L0X_STATE_WAIT_STATICINIT);
- }
-
- if (Status == VL53L0X_ERROR_NONE)
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, RefSpadsInitialised, 0);
-
-
- LOG_FUNCTION_END(Status);
- return Status;
+ /* Default value is 1000 for Linearity Corrective Gain */
+ PALDevDataSet(dev, LinearityCorrectiveGain, 1000);
+
+ /* Dmax default Parameter */
+ PALDevDataSet(dev, DmaxCalRangeMilliMeter, 400);
+ PALDevDataSet(dev, DmaxCalSignalRateRtnMegaCps,
+ (FixPoint1616_t)((0x00016B85))); /* 1.42 No Cover Glass*/
+
+ /* Set Default static parameters
+ *set first temporary values 9.44MHz * 65536 = 618660 */
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev, OscFrequencyMHz, 618660);
+
+ /* Set Default XTalkCompensationRateMegaCps to 0 */
+ VL53L0X_SETPARAMETERFIELD(dev, XTalkCompensationRateMegaCps, 0);
+
+ /* Get default parameters */
+ status = vl53l0x_get_device_parameters(dev, &CurrentParameters);
+ if (status == VL53L0X_ERROR_NONE) {
+ /* initialize PAL values */
+ CurrentParameters.DeviceMode = VL53L0X_DEVICEMODE_SINGLE_RANGING;
+ CurrentParameters.HistogramMode = VL53L0X_HISTOGRAMMODE_DISABLED;
+ PALDevDataSet(dev, CurrentParameters, CurrentParameters);
+ }
+
+ /* Sigma estimator variable */
+ PALDevDataSet(dev, SigmaEstRefArray, 100);
+ PALDevDataSet(dev, SigmaEstEffPulseWidth, 900);
+ PALDevDataSet(dev, SigmaEstEffAmbWidth, 500);
+ PALDevDataSet(dev, targetRefRate, 0x0A00); /* 20 MCPS in 9:7 format */
+
+ /* Use internal default settings */
+ PALDevDataSet(dev, UseInternalTuningSettings, 1);
+
+ status |= vl53l0x_write_byte(dev, 0x80, 0x01);
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x01);
+ status |= vl53l0x_write_byte(dev, 0x00, 0x00);
+ status |= vl53l0x_read_byte(dev, 0x91, &StopVariable);
+ PALDevDataSet(dev, StopVariable, StopVariable);
+ status |= vl53l0x_write_byte(dev, 0x00, 0x01);
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x00);
+ status |= vl53l0x_write_byte(dev, 0x80, 0x00);
+
+ /* Enable all check */
+ for (i = 0; i < VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
+ if (status == VL53L0X_ERROR_NONE)
+ status |= vl53l0x_set_limit_check_enable(dev, i, 1);
+ else
+ break;
+
+ }
+
+ /* Disable the following checks */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_set_limit_check_enable(dev,
+ VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP, 0);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_set_limit_check_enable(dev,
+ VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 0);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_set_limit_check_enable(dev,
+ VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC, 0);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_set_limit_check_enable(dev,
+ VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE, 0);
+
+ /* Limit default values */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_set_limit_check_value(dev,
+ VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
+ (FixPoint1616_t)(18 * 65536));
+ }
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_set_limit_check_value(dev,
+ VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ (FixPoint1616_t)(25 * 65536 / 100));
+ /* 0.25 * 65536 */
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_set_limit_check_value(dev,
+ VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
+ (FixPoint1616_t)(35 * 65536));
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_set_limit_check_value(dev,
+ VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ (FixPoint1616_t)(0 * 65536));
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+
+ PALDevDataSet(dev, SequenceConfig, 0xFF);
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
+ 0xFF);
+
+ /* Set PAL state to tell that we are waiting for call to
+ * VL53L0X_StaticInit */
+ PALDevDataSet(dev, PalState, VL53L0X_STATE_WAIT_STATICINIT);
+ }
+
+ if (status == VL53L0X_ERROR_NONE)
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev, RefSpadsInitialised, 0);
+
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_check_part_used(VL53L0X_DEV Dev,
- uint8_t *Revision,
- VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo)
+VL53L0X_Error VL53L0X::vl53l0x_check_part_used(VL53L0X_DEV dev,
+ uint8_t *revision,
+ VL53L0X_DeviceInfo_t *p_vl53l0x_device_info)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t ModuleIdInt;
- char *ProductId_tmp;
-
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_get_info_from_device(Dev, 2);
-
- if (Status == VL53L0X_ERROR_NONE) {
- ModuleIdInt = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev, ModuleId);
-
- if (ModuleIdInt == 0) {
- *Revision = 0;
- VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->ProductId, "");
- } else {
- *Revision = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev, Revision);
- ProductId_tmp = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
- ProductId);
- VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->ProductId, ProductId_tmp);
- }
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t module_id_int;
+ char *product_id_tmp;
+
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_get_info_from_device(dev, 2);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ module_id_int = VL53L0X_GETDEVICESPECIFICPARAMETER(dev, ModuleId);
+
+ if (module_id_int == 0) {
+ *revision = 0;
+ VL53L0X_COPYSTRING(p_vl53l0x_device_info->ProductId, "");
+ } else {
+ *revision = VL53L0X_GETDEVICESPECIFICPARAMETER(dev, Revision);
+ product_id_tmp = VL53L0X_GETDEVICESPECIFICPARAMETER(dev,
+ ProductId);
+ VL53L0X_COPYSTRING(p_vl53l0x_device_info->ProductId, product_id_tmp);
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_get_device_info(VL53L0X_DEV Dev,
- VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo)
+VL53L0X_Error VL53L0X::wrapped_vl53l0x_get_device_info(VL53L0X_DEV dev,
+ VL53L0X_DeviceInfo_t *p_vl53l0x_device_info)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t revision_id;
- uint8_t Revision;
-
- Status = VL53L0X_check_part_used(Dev, &Revision, pVL53L0X_DeviceInfo);
-
- if (Status == VL53L0X_ERROR_NONE) {
- if (Revision == 0) {
- VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->Name,
- VL53L0X_STRING_DEVICE_INFO_NAME_TS0);
- } else if ((Revision <= 34) && (Revision != 32)) {
- VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->Name,
- VL53L0X_STRING_DEVICE_INFO_NAME_TS1);
- } else if (Revision < 39) {
- VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->Name,
- VL53L0X_STRING_DEVICE_INFO_NAME_TS2);
- } else {
- VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->Name,
- VL53L0X_STRING_DEVICE_INFO_NAME_ES1);
- }
-
- VL53L0X_COPYSTRING(pVL53L0X_DeviceInfo->Type,
- VL53L0X_STRING_DEVICE_INFO_TYPE);
-
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_RdByte(Dev, VL53L0X_REG_IDENTIFICATION_MODEL_ID,
- &pVL53L0X_DeviceInfo->ProductType);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_RdByte(Dev,
- VL53L0X_REG_IDENTIFICATION_REVISION_ID,
- &revision_id);
- pVL53L0X_DeviceInfo->ProductRevisionMajor = 1;
- pVL53L0X_DeviceInfo->ProductRevisionMinor =
- (revision_id & 0xF0) >> 4;
- }
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t revision_id;
+ uint8_t revision;
+
+ status = vl53l0x_check_part_used(dev, &revision, p_vl53l0x_device_info);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ if (revision == 0) {
+ VL53L0X_COPYSTRING(p_vl53l0x_device_info->Name,
+ VL53L0X_STRING_DEVICE_INFO_NAME_TS0);
+ } else if ((revision <= 34) && (revision != 32)) {
+ VL53L0X_COPYSTRING(p_vl53l0x_device_info->Name,
+ VL53L0X_STRING_DEVICE_INFO_NAME_TS1);
+ } else if (revision < 39) {
+ VL53L0X_COPYSTRING(p_vl53l0x_device_info->Name,
+ VL53L0X_STRING_DEVICE_INFO_NAME_TS2);
+ } else {
+ VL53L0X_COPYSTRING(p_vl53l0x_device_info->Name,
+ VL53L0X_STRING_DEVICE_INFO_NAME_ES1);
+ }
+
+ VL53L0X_COPYSTRING(p_vl53l0x_device_info->Type,
+ VL53L0X_STRING_DEVICE_INFO_TYPE);
+
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_read_byte(dev, VL53L0X_REG_IDENTIFICATION_MODEL_ID,
+ &p_vl53l0x_device_info->ProductType);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_read_byte(dev,
+ VL53L0X_REG_IDENTIFICATION_REVISION_ID,
+ &revision_id);
+ p_vl53l0x_device_info->ProductRevisionMajor = 1;
+ p_vl53l0x_device_info->ProductRevisionMinor =
+ (revision_id & 0xF0) >> 4;
+ }
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetDeviceInfo(VL53L0X_DEV Dev,
- VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo)
+VL53L0X_Error VL53L0X::vl53l0x_get_device_info(VL53L0X_DEV dev,
+ VL53L0X_DeviceInfo_t *p_vl53l0x_device_info)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_get_device_info(Dev, pVL53L0X_DeviceInfo);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = wrapped_vl53l0x_get_device_info(dev, p_vl53l0x_device_info);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetInterruptMaskStatus(VL53L0X_DEV Dev,
- uint32_t *pInterruptMaskStatus)
+VL53L0X_Error VL53L0X::vl53l0x_get_interrupt_mask_status(VL53L0X_DEV dev,
+ uint32_t *p_interrupt_mask_status)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t Byte;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_RdByte(Dev, VL53L0X_REG_RESULT_INTERRUPT_STATUS, &Byte);
- *pInterruptMaskStatus = Byte & 0x07;
-
- if (Byte & 0x18)
- Status = VL53L0X_ERROR_RANGE_ERROR;
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t byte;
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_read_byte(dev, VL53L0X_REG_RESULT_INTERRUPT_STATUS, &byte);
+ *p_interrupt_mask_status = byte & 0x07;
+
+ if (byte & 0x18)
+ status = VL53L0X_ERROR_RANGE_ERROR;
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetMeasurementDataReady(VL53L0X_DEV Dev,
- uint8_t *pMeasurementDataReady)
+VL53L0X_Error VL53L0X::vl53l0x_get_measurement_data_ready(VL53L0X_DEV dev,
+ uint8_t *p_measurement_data_ready)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t SysRangeStatusRegister;
- uint8_t InterruptConfig;
- uint32_t InterruptMask;
- LOG_FUNCTION_START("");
-
- InterruptConfig = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
- Pin0GpioFunctionality);
-
- if (InterruptConfig ==
- VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY) {
- Status = VL53L0X_GetInterruptMaskStatus(Dev, &InterruptMask);
- if (InterruptMask ==
- VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY)
- *pMeasurementDataReady = 1;
- else
- *pMeasurementDataReady = 0;
- } else {
- Status = VL53L0X_RdByte(Dev, VL53L0X_REG_RESULT_RANGE_STATUS,
- &SysRangeStatusRegister);
- if (Status == VL53L0X_ERROR_NONE) {
- if (SysRangeStatusRegister & 0x01)
- *pMeasurementDataReady = 1;
- else
- *pMeasurementDataReady = 0;
- }
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t sys_range_status_register;
+ uint8_t interrupt_config;
+ uint32_t interrupt_mask;
+ LOG_FUNCTION_START("");
+
+ interrupt_config = VL53L0X_GETDEVICESPECIFICPARAMETER(dev,
+ Pin0GpioFunctionality);
+
+ if (interrupt_config ==
+ VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY) {
+ status = vl53l0x_get_interrupt_mask_status(dev, &interrupt_mask);
+ if (interrupt_mask ==
+ VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY)
+ *p_measurement_data_ready = 1;
+ else
+ *p_measurement_data_ready = 0;
+ } else {
+ status = vl53l0x_read_byte(dev, VL53L0X_REG_RESULT_RANGE_STATUS,
+ &sys_range_status_register);
+ if (status == VL53L0X_ERROR_NONE) {
+ if (sys_range_status_register & 0x01)
+ *p_measurement_data_ready = 1;
+ else
+ *p_measurement_data_ready = 0;
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_PollingDelay(VL53L0X_DEV Dev) {
+VL53L0X_Error VL53L0X::vl53l0x_polling_delay(VL53L0X_DEV dev)
+{
VL53L0X_Error status = VL53L0X_ERROR_NONE;
// do nothing
@@ -1823,3390 +1825,3375 @@
return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_measurement_poll_for_completion(VL53L0X_DEV Dev)
+VL53L0X_Error VL53L0X::vl53l0x_measurement_poll_for_completion(VL53L0X_DEV dev)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t NewDataReady = 0;
- uint32_t LoopNb;
-
- LOG_FUNCTION_START("");
-
- LoopNb = 0;
-
- do {
- Status = VL53L0X_GetMeasurementDataReady(Dev, &NewDataReady);
- if (Status != 0)
- break; /* the error is set */
-
- if (NewDataReady == 1)
- break; /* done note that status == 0 */
-
- LoopNb++;
- if (LoopNb >= VL53L0X_DEFAULT_MAX_LOOP) {
- Status = VL53L0X_ERROR_TIME_OUT;
- break;
- }
-
- VL53L0X_PollingDelay(Dev);
- } while (1);
-
- LOG_FUNCTION_END(Status);
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t new_data_ready = 0;
+ uint32_t loop_nb;
+
+ LOG_FUNCTION_START("");
+
+ loop_nb = 0;
+
+ do {
+ status = vl53l0x_get_measurement_data_ready(dev, &new_data_ready);
+ if (status != 0)
+ break; /* the error is set */
+
+ if (new_data_ready == 1)
+ break; /* done note that status == 0 */
+
+ loop_nb++;
+ if (loop_nb >= VL53L0X_DEFAULT_MAX_LOOP) {
+ status = VL53L0X_ERROR_TIME_OUT;
+ break;
+ }
+
+ vl53l0x_polling_delay(dev);
+ } while (1);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
}
/* Group PAL Interrupt Functions */
-VL53L0X_Error VL53L0X::VL53L0X_ClearInterruptMask(VL53L0X_DEV Dev, uint32_t InterruptMask)
+VL53L0X_Error VL53L0X::vl53l0x_clear_interrupt_mask(VL53L0X_DEV dev, uint32_t interrupt_mask)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t LoopCount;
- uint8_t Byte;
- LOG_FUNCTION_START("");
-
- /* clear bit 0 range interrupt, bit 1 error interrupt */
- LoopCount = 0;
- do {
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR, 0x01);
- Status |= VL53L0X_WrByte(Dev,
- VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR, 0x00);
- Status |= VL53L0X_RdByte(Dev,
- VL53L0X_REG_RESULT_INTERRUPT_STATUS, &Byte);
- LoopCount++;
- } while (((Byte & 0x07) != 0x00)
- && (LoopCount < 3)
- && (Status == VL53L0X_ERROR_NONE));
-
-
- if (LoopCount >= 3)
- Status = VL53L0X_ERROR_INTERRUPT_NOT_CLEARED;
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t loop_count;
+ uint8_t byte;
+ LOG_FUNCTION_START("");
+
+ /* clear bit 0 range interrupt, bit 1 error interrupt */
+ loop_count = 0;
+ do {
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR, 0x01);
+ status |= vl53l0x_write_byte(dev,
+ VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR, 0x00);
+ status |= vl53l0x_read_byte(dev,
+ VL53L0X_REG_RESULT_INTERRUPT_STATUS, &byte);
+ loop_count++;
+ } while (((byte & 0x07) != 0x00)
+ && (loop_count < 3)
+ && (status == VL53L0X_ERROR_NONE));
+
+
+ if (loop_count >= 3)
+ status = VL53L0X_ERROR_INTERRUPT_NOT_CLEARED;
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_perform_single_ref_calibration(VL53L0X_DEV Dev,
- uint8_t vhv_init_byte)
+VL53L0X_Error VL53L0X::vl53l0x_perform_single_ref_calibration(VL53L0X_DEV dev,
+ uint8_t vhv_init_byte)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSRANGE_START,
- VL53L0X_REG_SYSRANGE_MODE_START_STOP |
- vhv_init_byte);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_measurement_poll_for_completion(Dev);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_ClearInterruptMask(Dev, 0);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSRANGE_START, 0x00);
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_SYSRANGE_START,
+ VL53L0X_REG_SYSRANGE_MODE_START_STOP |
+ vhv_init_byte);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_measurement_poll_for_completion(dev);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_clear_interrupt_mask(dev, 0);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_SYSRANGE_START, 0x00);
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_ref_calibration_io(VL53L0X_DEV Dev, uint8_t read_not_write,
- uint8_t VhvSettings, uint8_t PhaseCal,
- uint8_t *pVhvSettings, uint8_t *pPhaseCal,
- const uint8_t vhv_enable, const uint8_t phase_enable)
+VL53L0X_Error VL53L0X::vl53l0x_ref_calibration_io(VL53L0X_DEV dev, uint8_t read_not_write,
+ uint8_t vhv_settings, uint8_t phase_cal,
+ uint8_t *p_vhv_settings, uint8_t *p_phase_cal,
+ const uint8_t vhv_enable, const uint8_t phase_enable)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t PhaseCalint = 0;
-
- /* Read VHV from device */
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0x00, 0x00);
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
-
- if (read_not_write) {
- if (vhv_enable)
- Status |= VL53L0X_RdByte(Dev, 0xCB, pVhvSettings);
- if (phase_enable)
- Status |= VL53L0X_RdByte(Dev, 0xEE, &PhaseCalint);
- } else {
- if (vhv_enable)
- Status |= VL53L0X_WrByte(Dev, 0xCB, VhvSettings);
- if (phase_enable)
- Status |= VL53L0X_UpdateByte(Dev, 0xEE, 0x80, PhaseCal);
- }
-
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0x00, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
-
- *pPhaseCal = (uint8_t)(PhaseCalint&0xEF);
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t phase_calint = 0;
+
+ /* Read VHV from device */
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x01);
+ status |= vl53l0x_write_byte(dev, 0x00, 0x00);
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x00);
+
+ if (read_not_write) {
+ if (vhv_enable)
+ status |= vl53l0x_read_byte(dev, 0xCB, p_vhv_settings);
+ if (phase_enable)
+ status |= vl53l0x_read_byte(dev, 0xEE, &phase_calint);
+ } else {
+ if (vhv_enable)
+ status |= vl53l0x_write_byte(dev, 0xCB, vhv_settings);
+ if (phase_enable)
+ status |= vl53l0x_update_byte(dev, 0xEE, 0x80, phase_cal);
+ }
+
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x01);
+ status |= vl53l0x_write_byte(dev, 0x00, 0x01);
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x00);
+
+ *p_phase_cal = (uint8_t)(phase_calint & 0xEF);
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_perform_vhv_calibration(VL53L0X_DEV Dev,
- uint8_t *pVhvSettings, const uint8_t get_data_enable,
- const uint8_t restore_config)
+VL53L0X_Error VL53L0X::vl53l0x_perform_vhv_calibration(VL53L0X_DEV dev,
+ uint8_t *p_vhv_settings, const uint8_t get_data_enable,
+ const uint8_t restore_config)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t SequenceConfig = 0;
- uint8_t VhvSettings = 0;
- uint8_t PhaseCal = 0;
- uint8_t PhaseCalInt = 0;
-
- /* store the value of the sequence config,
- * this will be reset before the end of the function
- */
-
- if (restore_config)
- SequenceConfig = PALDevDataGet(Dev, SequenceConfig);
-
- /* Run VHV */
- Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, 0x01);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_perform_single_ref_calibration(Dev, 0x40);
-
- /* Read VHV from device */
- if ((Status == VL53L0X_ERROR_NONE) && (get_data_enable == 1)) {
- Status = VL53L0X_ref_calibration_io(Dev, 1,
- VhvSettings, PhaseCal, /* Not used here */
- pVhvSettings, &PhaseCalInt,
- 1, 0);
- } else
- *pVhvSettings = 0;
-
-
- if ((Status == VL53L0X_ERROR_NONE) && restore_config) {
- /* restore the previous Sequence Config */
- Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
- SequenceConfig);
- if (Status == VL53L0X_ERROR_NONE)
- PALDevDataSet(Dev, SequenceConfig, SequenceConfig);
-
- }
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t sequence_config = 0;
+ uint8_t vhv_settings = 0;
+ uint8_t phase_cal = 0;
+ uint8_t phase_cal_int = 0;
+
+ /* store the value of the sequence config,
+ * this will be reset before the end of the function
+ */
+
+ if (restore_config)
+ sequence_config = PALDevDataGet(dev, SequenceConfig);
+
+ /* Run VHV */
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, 0x01);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_perform_single_ref_calibration(dev, 0x40);
+
+ /* Read VHV from device */
+ if ((status == VL53L0X_ERROR_NONE) && (get_data_enable == 1)) {
+ status = vl53l0x_ref_calibration_io(dev, 1,
+ vhv_settings, phase_cal, /* Not used here */
+ p_vhv_settings, &phase_cal_int,
+ 1, 0);
+ } else
+ *p_vhv_settings = 0;
+
+
+ if ((status == VL53L0X_ERROR_NONE) && restore_config) {
+ /* restore the previous Sequence Config */
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
+ sequence_config);
+ if (status == VL53L0X_ERROR_NONE)
+ PALDevDataSet(dev, SequenceConfig, sequence_config);
+
+ }
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_perform_phase_calibration(VL53L0X_DEV Dev,
- uint8_t *pPhaseCal, const uint8_t get_data_enable,
- const uint8_t restore_config)
+VL53L0X_Error VL53L0X::vl53l0x_perform_phase_calibration(VL53L0X_DEV dev,
+ uint8_t *p_phase_cal, const uint8_t get_data_enable,
+ const uint8_t restore_config)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t SequenceConfig = 0;
- uint8_t VhvSettings = 0;
- uint8_t PhaseCal = 0;
- uint8_t VhvSettingsint;
-
- /* store the value of the sequence config,
- * this will be reset before the end of the function
- */
-
- if (restore_config)
- SequenceConfig = PALDevDataGet(Dev, SequenceConfig);
-
- /* Run PhaseCal */
- Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, 0x02);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_perform_single_ref_calibration(Dev, 0x0);
-
- /* Read PhaseCal from device */
- if ((Status == VL53L0X_ERROR_NONE) && (get_data_enable == 1)) {
- Status = VL53L0X_ref_calibration_io(Dev, 1,
- VhvSettings, PhaseCal, /* Not used here */
- &VhvSettingsint, pPhaseCal,
- 0, 1);
- } else
- *pPhaseCal = 0;
-
-
- if ((Status == VL53L0X_ERROR_NONE) && restore_config) {
- /* restore the previous Sequence Config */
- Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
- SequenceConfig);
- if (Status == VL53L0X_ERROR_NONE)
- PALDevDataSet(Dev, SequenceConfig, SequenceConfig);
-
- }
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t sequence_config = 0;
+ uint8_t vhv_settings = 0;
+ uint8_t phase_cal = 0;
+ uint8_t vhv_settingsint;
+
+ /* store the value of the sequence config,
+ * this will be reset before the end of the function
+ */
+
+ if (restore_config)
+ sequence_config = PALDevDataGet(dev, SequenceConfig);
+
+ /* Run PhaseCal */
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, 0x02);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_perform_single_ref_calibration(dev, 0x0);
+
+ /* Read PhaseCal from device */
+ if ((status == VL53L0X_ERROR_NONE) && (get_data_enable == 1)) {
+ status = vl53l0x_ref_calibration_io(dev, 1,
+ vhv_settings, phase_cal, /* Not used here */
+ &vhv_settingsint, p_phase_cal,
+ 0, 1);
+ } else
+ *p_phase_cal = 0;
+
+
+ if ((status == VL53L0X_ERROR_NONE) && restore_config) {
+ /* restore the previous Sequence Config */
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
+ sequence_config);
+ if (status == VL53L0X_ERROR_NONE)
+ PALDevDataSet(dev, SequenceConfig, sequence_config);
+
+ }
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_perform_ref_calibration(VL53L0X_DEV Dev,
- uint8_t *pVhvSettings, uint8_t *pPhaseCal, uint8_t get_data_enable)
+VL53L0X_Error VL53L0X::vl53l0x_perform_ref_calibration(VL53L0X_DEV dev,
+ uint8_t *p_vhv_settings, uint8_t *p_phase_cal, uint8_t get_data_enable)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t SequenceConfig = 0;
-
- /* store the value of the sequence config,
- * this will be reset before the end of the function
- */
-
- SequenceConfig = PALDevDataGet(Dev, SequenceConfig);
-
- /* In the following function we don't save the config to optimize
- * writes on device. Config is saved and restored only once. */
- Status = VL53L0X_perform_vhv_calibration(
- Dev, pVhvSettings, get_data_enable, 0);
-
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_perform_phase_calibration(
- Dev, pPhaseCal, get_data_enable, 0);
-
-
- if (Status == VL53L0X_ERROR_NONE) {
- /* restore the previous Sequence Config */
- Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
- SequenceConfig);
- if (Status == VL53L0X_ERROR_NONE)
- PALDevDataSet(Dev, SequenceConfig, SequenceConfig);
-
- }
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t sequence_config = 0;
+
+ /* store the value of the sequence config,
+ * this will be reset before the end of the function
+ */
+
+ sequence_config = PALDevDataGet(dev, SequenceConfig);
+
+ /* In the following function we don't save the config to optimize
+ * writes on device. Config is saved and restored only once. */
+ status = vl53l0x_perform_vhv_calibration(
+ dev, p_vhv_settings, get_data_enable, 0);
+
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_perform_phase_calibration(
+ dev, p_phase_cal, get_data_enable, 0);
+
+
+ if (status == VL53L0X_ERROR_NONE) {
+ /* restore the previous Sequence Config */
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
+ sequence_config);
+ if (status == VL53L0X_ERROR_NONE)
+ PALDevDataSet(dev, SequenceConfig, sequence_config);
+
+ }
+
+ return status;
}
-void VL53L0X::get_next_good_spad(uint8_t goodSpadArray[], uint32_t size,
- uint32_t curr, int32_t *next)
+void VL53L0X::get_next_good_spad(uint8_t good_spad_array[], uint32_t size,
+ uint32_t curr, int32_t *p_next)
{
- uint32_t startIndex;
- uint32_t fineOffset;
- uint32_t cSpadsPerByte = 8;
- uint32_t coarseIndex;
- uint32_t fineIndex;
- uint8_t dataByte;
- uint8_t success = 0;
-
- /*
- * Starting with the current good spad, loop through the array to find
- * the next. i.e. the next bit set in the sequence.
- *
- * The coarse index is the byte index of the array and the fine index is
- * the index of the bit within each byte.
- */
-
- *next = -1;
-
- startIndex = curr / cSpadsPerByte;
- fineOffset = curr % cSpadsPerByte;
-
- for (coarseIndex = startIndex; ((coarseIndex < size) && !success);
- coarseIndex++) {
- fineIndex = 0;
- dataByte = goodSpadArray[coarseIndex];
-
- if (coarseIndex == startIndex) {
- /* locate the bit position of the provided current
- * spad bit before iterating */
- dataByte >>= fineOffset;
- fineIndex = fineOffset;
- }
-
- while (fineIndex < cSpadsPerByte) {
- if ((dataByte & 0x1) == 1) {
- success = 1;
- *next = coarseIndex * cSpadsPerByte + fineIndex;
- break;
- }
- dataByte >>= 1;
- fineIndex++;
- }
- }
+ uint32_t start_index;
+ uint32_t fine_offset;
+ uint32_t c_spads_per_byte = 8;
+ uint32_t coarse_index;
+ uint32_t fine_index;
+ uint8_t data_byte;
+ uint8_t success = 0;
+
+ /*
+ * Starting with the current good spad, loop through the array to find
+ * the next. i.e. the next bit set in the sequence.
+ *
+ * The coarse index is the byte index of the array and the fine index is
+ * the index of the bit within each byte.
+ */
+
+ *p_next = -1;
+
+ start_index = curr / c_spads_per_byte;
+ fine_offset = curr % c_spads_per_byte;
+
+ for (coarse_index = start_index; ((coarse_index < size) && !success);
+ coarse_index++) {
+ fine_index = 0;
+ data_byte = good_spad_array[coarse_index];
+
+ if (coarse_index == start_index) {
+ /* locate the bit position of the provided current
+ * spad bit before iterating */
+ data_byte >>= fine_offset;
+ fine_index = fine_offset;
+ }
+
+ while (fine_index < c_spads_per_byte) {
+ if ((data_byte & 0x1) == 1) {
+ success = 1;
+ *p_next = coarse_index * c_spads_per_byte + fine_index;
+ break;
+ }
+ data_byte >>= 1;
+ fine_index++;
+ }
+ }
}
-uint8_t VL53L0X::is_aperture(uint32_t spadIndex)
+uint8_t VL53L0X::is_aperture(uint32_t spad_index)
{
- /*
- * This function reports if a given spad index is an aperture SPAD by
- * deriving the quadrant.
- */
- uint32_t quadrant;
- uint8_t isAperture = 1;
- quadrant = spadIndex >> 6;
- if (refArrayQuadrants[quadrant] == REF_ARRAY_SPAD_0)
- isAperture = 0;
-
- return isAperture;
+ /*
+ * This function reports if a given spad index is an aperture SPAD by
+ * deriving the quadrant.
+ */
+ uint32_t quadrant;
+ uint8_t is_aperture = 1;
+ quadrant = spad_index >> 6;
+ if (refArrayQuadrants[quadrant] == REF_ARRAY_SPAD_0)
+ is_aperture = 0;
+
+ return is_aperture;
}
-VL53L0X_Error VL53L0X::enable_spad_bit(uint8_t spadArray[], uint32_t size,
- uint32_t spadIndex)
+VL53L0X_Error VL53L0X::enable_spad_bit(uint8_t spad_array[], uint32_t size,
+ uint32_t spad_index)
{
- VL53L0X_Error status = VL53L0X_ERROR_NONE;
- uint32_t cSpadsPerByte = 8;
- uint32_t coarseIndex;
- uint32_t fineIndex;
-
- coarseIndex = spadIndex / cSpadsPerByte;
- fineIndex = spadIndex % cSpadsPerByte;
- if (coarseIndex >= size)
- status = VL53L0X_ERROR_REF_SPAD_INIT;
- else
- spadArray[coarseIndex] |= (1 << fineIndex);
-
- return status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint32_t c_spads_per_byte = 8;
+ uint32_t coarse_index;
+ uint32_t fine_index;
+
+ coarse_index = spad_index / c_spads_per_byte;
+ fine_index = spad_index % c_spads_per_byte;
+ if (coarse_index >= size)
+ status = VL53L0X_ERROR_REF_SPAD_INIT;
+ else
+ spad_array[coarse_index] |= (1 << fine_index);
+
+ return status;
}
-VL53L0X_Error VL53L0X::set_ref_spad_map(VL53L0X_DEV Dev, uint8_t *refSpadArray)
+VL53L0X_Error VL53L0X::set_ref_spad_map(VL53L0X_DEV dev, uint8_t *p_ref_spad_array)
{
- VL53L0X_Error status = VL53L0X_WriteMulti(Dev,
- VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,
- refSpadArray, 6);
-
- return status;
+ VL53L0X_Error status = vl53l0x_write_multi(dev,
+ VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,
+ p_ref_spad_array, 6);
+
+ return status;
}
-VL53L0X_Error VL53L0X::get_ref_spad_map(VL53L0X_DEV Dev, uint8_t *refSpadArray)
+VL53L0X_Error VL53L0X::get_ref_spad_map(VL53L0X_DEV dev, uint8_t *p_ref_spad_array)
{
- VL53L0X_Error status = VL53L0X_ReadMulti(Dev,
- VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,
- refSpadArray,
- 6);
+ VL53L0X_Error status = vl53l0x_read_multi(dev,
+ VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,
+ p_ref_spad_array,
+ 6);
// VL53L0X_Error status = VL53L0X_ERROR_NONE;
// uint8_t count=0;
// for (count = 0; count < 6; count++)
// status = VL53L0X_RdByte(Dev, (VL53L0X_REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0 + count), &refSpadArray[count]);
- return status;
+ return status;
}
-VL53L0X_Error VL53L0X::enable_ref_spads(VL53L0X_DEV Dev,
- uint8_t apertureSpads,
- uint8_t goodSpadArray[],
- uint8_t spadArray[],
- uint32_t size,
- uint32_t start,
- uint32_t offset,
- uint32_t spadCount,
- uint32_t *lastSpad)
+VL53L0X_Error VL53L0X::enable_ref_spads(VL53L0X_DEV dev,
+ uint8_t aperture_spads,
+ uint8_t good_spad_array[],
+ uint8_t spad_array[],
+ uint32_t size,
+ uint32_t start,
+ uint32_t offset,
+ uint32_t spad_count,
+ uint32_t *p_last_spad)
{
- VL53L0X_Error status = VL53L0X_ERROR_NONE;
- uint32_t index;
- uint32_t i;
- int32_t nextGoodSpad = offset;
- uint32_t currentSpad;
- uint8_t checkSpadArray[6];
-
- /*
- * This function takes in a spad array which may or may not have SPADS
- * already enabled and appends from a given offset a requested number
- * of new SPAD enables. The 'good spad map' is applied to
- * determine the next SPADs to enable.
- *
- * This function applies to only aperture or only non-aperture spads.
- * Checks are performed to ensure this.
- */
-
- currentSpad = offset;
- for (index = 0; index < spadCount; index++) {
- get_next_good_spad(goodSpadArray, size, currentSpad,
- &nextGoodSpad);
-
- if (nextGoodSpad == -1) {
- status = VL53L0X_ERROR_REF_SPAD_INIT;
- break;
- }
-
- /* Confirm that the next good SPAD is non-aperture */
- if (is_aperture(start + nextGoodSpad) != apertureSpads) {
- /* if we can't get the required number of good aperture
- * spads from the current quadrant then this is an error
- */
- status = VL53L0X_ERROR_REF_SPAD_INIT;
- break;
- }
- currentSpad = (uint32_t)nextGoodSpad;
- enable_spad_bit(spadArray, size, currentSpad);
- currentSpad++;
- }
- *lastSpad = currentSpad;
-
- if (status == VL53L0X_ERROR_NONE)
- status = set_ref_spad_map(Dev, spadArray);
-
-
- if (status == VL53L0X_ERROR_NONE) {
- status = get_ref_spad_map(Dev, checkSpadArray);
-
- i = 0;
-
- /* Compare spad maps. If not equal report error. */
- while (i < size) {
- if (spadArray[i] != checkSpadArray[i]) {
- status = VL53L0X_ERROR_REF_SPAD_INIT;
- break;
- }
- i++;
- }
- }
- return status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint32_t index;
+ uint32_t i;
+ int32_t next_good_spad = offset;
+ uint32_t current_spad;
+ uint8_t check_spad_array[6];
+
+ /*
+ * This function takes in a spad array which may or may not have SPADS
+ * already enabled and appends from a given offset a requested number
+ * of new SPAD enables. The 'good spad map' is applied to
+ * determine the next SPADs to enable.
+ *
+ * This function applies to only aperture or only non-aperture spads.
+ * Checks are performed to ensure this.
+ */
+
+ current_spad = offset;
+ for (index = 0; index < spad_count; index++) {
+ get_next_good_spad(good_spad_array, size, current_spad,
+ &next_good_spad);
+
+ if (next_good_spad == -1) {
+ status = VL53L0X_ERROR_REF_SPAD_INIT;
+ break;
+ }
+
+ /* Confirm that the next good SPAD is non-aperture */
+ if (is_aperture(start + next_good_spad) != aperture_spads) {
+ /* if we can't get the required number of good aperture
+ * spads from the current quadrant then this is an error
+ */
+ status = VL53L0X_ERROR_REF_SPAD_INIT;
+ break;
+ }
+ current_spad = (uint32_t)next_good_spad;
+ enable_spad_bit(spad_array, size, current_spad);
+ current_spad++;
+ }
+ *p_last_spad = current_spad;
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = set_ref_spad_map(dev, spad_array);
+
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = get_ref_spad_map(dev, check_spad_array);
+
+ i = 0;
+
+ /* Compare spad maps. If not equal report error. */
+ while (i < size) {
+ if (spad_array[i] != check_spad_array[i]) {
+ status = VL53L0X_ERROR_REF_SPAD_INIT;
+ break;
+ }
+ i++;
+ }
+ }
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_SetDeviceMode(VL53L0X_DEV Dev, VL53L0X_DeviceModes DeviceMode)
+VL53L0X_Error VL53L0X::vl53l0x_set_device_mode(VL53L0X_DEV dev, VL53L0X_DeviceModes device_mode)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
-
- LOG_FUNCTION_START("%d", (int)DeviceMode);
-
- switch (DeviceMode) {
- case VL53L0X_DEVICEMODE_SINGLE_RANGING:
- case VL53L0X_DEVICEMODE_CONTINUOUS_RANGING:
- case VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING:
- case VL53L0X_DEVICEMODE_GPIO_DRIVE:
- case VL53L0X_DEVICEMODE_GPIO_OSC:
- /* Supported modes */
- VL53L0X_SETPARAMETERFIELD(Dev, DeviceMode, DeviceMode);
- break;
- default:
- /* Unsupported mode */
- Status = VL53L0X_ERROR_MODE_NOT_SUPPORTED;
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+
+ LOG_FUNCTION_START("%d", (int)DeviceMode);
+
+ switch (device_mode) {
+ case VL53L0X_DEVICEMODE_SINGLE_RANGING:
+ case VL53L0X_DEVICEMODE_CONTINUOUS_RANGING:
+ case VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING:
+ case VL53L0X_DEVICEMODE_GPIO_DRIVE:
+ case VL53L0X_DEVICEMODE_GPIO_OSC:
+ /* Supported modes */
+ VL53L0X_SETPARAMETERFIELD(dev, DeviceMode, device_mode);
+ break;
+ default:
+ /* Unsupported mode */
+ status = VL53L0X_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_SetInterruptThresholds(VL53L0X_DEV Dev,
- VL53L0X_DeviceModes DeviceMode, FixPoint1616_t ThresholdLow,
- FixPoint1616_t ThresholdHigh)
+VL53L0X_Error VL53L0X::vl53l0x_set_interrupt_thresholds(VL53L0X_DEV dev,
+ VL53L0X_DeviceModes device_mode, FixPoint1616_t threshold_low,
+ FixPoint1616_t threshold_high)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint16_t Threshold16;
- LOG_FUNCTION_START("");
-
- /* no dependency on DeviceMode for Ewok */
- /* Need to divide by 2 because the FW will apply a x2 */
- Threshold16 = (uint16_t)((ThresholdLow >> 17) & 0x00fff);
- Status = VL53L0X_WrWord(Dev, VL53L0X_REG_SYSTEM_THRESH_LOW, Threshold16);
-
- if (Status == VL53L0X_ERROR_NONE) {
- /* Need to divide by 2 because the FW will apply a x2 */
- Threshold16 = (uint16_t)((ThresholdHigh >> 17) & 0x00fff);
- Status = VL53L0X_WrWord(Dev, VL53L0X_REG_SYSTEM_THRESH_HIGH,
- Threshold16);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint16_t threshold16;
+ LOG_FUNCTION_START("");
+
+ /* no dependency on DeviceMode for Ewok */
+ /* Need to divide by 2 because the FW will apply a x2 */
+ threshold16 = (uint16_t)((threshold_low >> 17) & 0x00fff);
+ status = vl53l0x_write_word(dev, VL53L0X_REG_SYSTEM_THRESH_LOW, threshold16);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ /* Need to divide by 2 because the FW will apply a x2 */
+ threshold16 = (uint16_t)((threshold_high >> 17) & 0x00fff);
+ status = vl53l0x_write_word(dev, VL53L0X_REG_SYSTEM_THRESH_HIGH,
+ threshold16);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetInterruptThresholds(VL53L0X_DEV Dev,
- VL53L0X_DeviceModes DeviceMode, FixPoint1616_t *pThresholdLow,
- FixPoint1616_t *pThresholdHigh)
+VL53L0X_Error VL53L0X::vl53l0x_get_interrupt_thresholds(VL53L0X_DEV dev,
+ VL53L0X_DeviceModes device_mode, FixPoint1616_t *p_threshold_low,
+ FixPoint1616_t *p_threshold_high)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint16_t Threshold16;
- LOG_FUNCTION_START("");
-
- /* no dependency on DeviceMode for Ewok */
-
- Status = VL53L0X_RdWord(Dev, VL53L0X_REG_SYSTEM_THRESH_LOW, &Threshold16);
- /* Need to multiply by 2 because the FW will apply a x2 */
- *pThresholdLow = (FixPoint1616_t)((0x00fff & Threshold16) << 17);
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_RdWord(Dev, VL53L0X_REG_SYSTEM_THRESH_HIGH,
- &Threshold16);
- /* Need to multiply by 2 because the FW will apply a x2 */
- *pThresholdHigh =
- (FixPoint1616_t)((0x00fff & Threshold16) << 17);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint16_t threshold16;
+ LOG_FUNCTION_START("");
+
+ /* no dependency on DeviceMode for Ewok */
+
+ status = vl53l0x_read_word(dev, VL53L0X_REG_SYSTEM_THRESH_LOW, &threshold16);
+ /* Need to multiply by 2 because the FW will apply a x2 */
+ *p_threshold_low = (FixPoint1616_t)((0x00fff & threshold16) << 17);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_read_word(dev, VL53L0X_REG_SYSTEM_THRESH_HIGH,
+ &threshold16);
+ /* Need to multiply by 2 because the FW will apply a x2 */
+ *p_threshold_high =
+ (FixPoint1616_t)((0x00fff & threshold16) << 17);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_load_tuning_settings(VL53L0X_DEV Dev,
- uint8_t *pTuningSettingBuffer)
+VL53L0X_Error VL53L0X::vl53l0x_load_tuning_settings(VL53L0X_DEV dev,
+ uint8_t *p_tuning_setting_buffer)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- int i;
- int Index;
- uint8_t msb;
- uint8_t lsb;
- uint8_t SelectParam;
- uint8_t NumberOfWrites;
- uint8_t Address;
- uint8_t localBuffer[4]; /* max */
- uint16_t Temp16;
-
- LOG_FUNCTION_START("");
-
- Index = 0;
-
- while ((*(pTuningSettingBuffer + Index) != 0) &&
- (Status == VL53L0X_ERROR_NONE)) {
- NumberOfWrites = *(pTuningSettingBuffer + Index);
- Index++;
- if (NumberOfWrites == 0xFF) {
- /* internal parameters */
- SelectParam = *(pTuningSettingBuffer + Index);
- Index++;
- switch (SelectParam) {
- case 0: /* uint16_t SigmaEstRefArray -> 2 bytes */
- msb = *(pTuningSettingBuffer + Index);
- Index++;
- lsb = *(pTuningSettingBuffer + Index);
- Index++;
- Temp16 = VL53L0X_MAKEUINT16(lsb, msb);
- PALDevDataSet(Dev, SigmaEstRefArray, Temp16);
- break;
- case 1: /* uint16_t SigmaEstEffPulseWidth -> 2 bytes */
- msb = *(pTuningSettingBuffer + Index);
- Index++;
- lsb = *(pTuningSettingBuffer + Index);
- Index++;
- Temp16 = VL53L0X_MAKEUINT16(lsb, msb);
- PALDevDataSet(Dev, SigmaEstEffPulseWidth,
- Temp16);
- break;
- case 2: /* uint16_t SigmaEstEffAmbWidth -> 2 bytes */
- msb = *(pTuningSettingBuffer + Index);
- Index++;
- lsb = *(pTuningSettingBuffer + Index);
- Index++;
- Temp16 = VL53L0X_MAKEUINT16(lsb, msb);
- PALDevDataSet(Dev, SigmaEstEffAmbWidth, Temp16);
- break;
- case 3: /* uint16_t targetRefRate -> 2 bytes */
- msb = *(pTuningSettingBuffer + Index);
- Index++;
- lsb = *(pTuningSettingBuffer + Index);
- Index++;
- Temp16 = VL53L0X_MAKEUINT16(lsb, msb);
- PALDevDataSet(Dev, targetRefRate, Temp16);
- break;
- default: /* invalid parameter */
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
-
- } else if (NumberOfWrites <= 4) {
- Address = *(pTuningSettingBuffer + Index);
- Index++;
-
- for (i = 0; i < NumberOfWrites; i++) {
- localBuffer[i] = *(pTuningSettingBuffer +
- Index);
- Index++;
- }
-
- Status = VL53L0X_WriteMulti(Dev, Address, localBuffer,
- NumberOfWrites);
-
- } else {
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ int i;
+ int index;
+ uint8_t msb;
+ uint8_t lsb;
+ uint8_t select_param;
+ uint8_t number_of_writes;
+ uint8_t address;
+ uint8_t local_buffer[4]; /* max */
+ uint16_t temp16;
+
+ LOG_FUNCTION_START("");
+
+ index = 0;
+
+ while ((*(p_tuning_setting_buffer + index) != 0) &&
+ (status == VL53L0X_ERROR_NONE)) {
+ number_of_writes = *(p_tuning_setting_buffer + index);
+ index++;
+ if (number_of_writes == 0xFF) {
+ /* internal parameters */
+ select_param = *(p_tuning_setting_buffer + index);
+ index++;
+ switch (select_param) {
+ case 0: /* uint16_t SigmaEstRefArray -> 2 bytes */
+ msb = *(p_tuning_setting_buffer + index);
+ index++;
+ lsb = *(p_tuning_setting_buffer + index);
+ index++;
+ temp16 = VL53L0X_MAKEUINT16(lsb, msb);
+ PALDevDataSet(dev, SigmaEstRefArray, temp16);
+ break;
+ case 1: /* uint16_t SigmaEstEffPulseWidth -> 2 bytes */
+ msb = *(p_tuning_setting_buffer + index);
+ index++;
+ lsb = *(p_tuning_setting_buffer + index);
+ index++;
+ temp16 = VL53L0X_MAKEUINT16(lsb, msb);
+ PALDevDataSet(dev, SigmaEstEffPulseWidth,
+ temp16);
+ break;
+ case 2: /* uint16_t SigmaEstEffAmbWidth -> 2 bytes */
+ msb = *(p_tuning_setting_buffer + index);
+ index++;
+ lsb = *(p_tuning_setting_buffer + index);
+ index++;
+ temp16 = VL53L0X_MAKEUINT16(lsb, msb);
+ PALDevDataSet(dev, SigmaEstEffAmbWidth, temp16);
+ break;
+ case 3: /* uint16_t targetRefRate -> 2 bytes */
+ msb = *(p_tuning_setting_buffer + index);
+ index++;
+ lsb = *(p_tuning_setting_buffer + index);
+ index++;
+ temp16 = VL53L0X_MAKEUINT16(lsb, msb);
+ PALDevDataSet(dev, targetRefRate, temp16);
+ break;
+ default: /* invalid parameter */
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+
+ } else if (number_of_writes <= 4) {
+ address = *(p_tuning_setting_buffer + index);
+ index++;
+
+ for (i = 0; i < number_of_writes; i++) {
+ local_buffer[i] = *(p_tuning_setting_buffer +
+ index);
+ index++;
+ }
+
+ status = vl53l0x_write_multi(dev, address, local_buffer,
+ number_of_writes);
+
+ } else {
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_CheckAndLoadInterruptSettings(VL53L0X_DEV Dev,
- uint8_t StartNotStopFlag)
+VL53L0X_Error VL53L0X::vl53l0x_check_and_load_interrupt_settings(VL53L0X_DEV dev,
+ uint8_t start_not_stopflag)
{
- uint8_t InterruptConfig;
- FixPoint1616_t ThresholdLow;
- FixPoint1616_t ThresholdHigh;
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
-
- InterruptConfig = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
- Pin0GpioFunctionality);
-
- if ((InterruptConfig ==
- VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW) ||
- (InterruptConfig ==
- VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH) ||
- (InterruptConfig ==
- VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT)) {
-
- Status = VL53L0X_GetInterruptThresholds(Dev,
- VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
- &ThresholdLow, &ThresholdHigh);
-
- if (((ThresholdLow > 255*65536) ||
- (ThresholdHigh > 255*65536)) &&
- (Status == VL53L0X_ERROR_NONE)) {
-
- if (StartNotStopFlag != 0) {
- Status = VL53L0X_load_tuning_settings(Dev,
- InterruptThresholdSettings);
- } else {
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x04);
- Status |= VL53L0X_WrByte(Dev, 0x70, 0x00);
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
- Status |= VL53L0X_WrByte(Dev, 0x80, 0x00);
- }
-
- }
-
-
- }
-
- return Status;
+ uint8_t interrupt_config;
+ FixPoint1616_t threshold_low;
+ FixPoint1616_t threshold_high;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+
+ interrupt_config = VL53L0X_GETDEVICESPECIFICPARAMETER(dev,
+ Pin0GpioFunctionality);
+
+ if ((interrupt_config ==
+ VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW) ||
+ (interrupt_config ==
+ VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH) ||
+ (interrupt_config ==
+ VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT)) {
+
+ status = vl53l0x_get_interrupt_thresholds(dev,
+ VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
+ &threshold_low, &threshold_high);
+
+ if (((threshold_low > 255 * 65536) ||
+ (threshold_high > 255 * 65536)) &&
+ (status == VL53L0X_ERROR_NONE)) {
+
+ if (start_not_stopflag != 0) {
+ status = vl53l0x_load_tuning_settings(dev,
+ InterruptThresholdSettings);
+ } else {
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x04);
+ status |= vl53l0x_write_byte(dev, 0x70, 0x00);
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x00);
+ status |= vl53l0x_write_byte(dev, 0x80, 0x00);
+ }
+
+ }
+
+
+ }
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_StartMeasurement(VL53L0X_DEV Dev)
+VL53L0X_Error VL53L0X::vl53l0x_start_measurement(VL53L0X_DEV dev)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- VL53L0X_DeviceModes DeviceMode;
- uint8_t Byte;
- uint8_t StartStopByte = VL53L0X_REG_SYSRANGE_MODE_START_STOP;
- uint32_t LoopNb;
- LOG_FUNCTION_START("");
-
- /* Get Current DeviceMode */
- VL53L0X_GetDeviceMode(Dev, &DeviceMode);
-
- Status = VL53L0X_WrByte(Dev, 0x80, 0x01);
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
- Status = VL53L0X_WrByte(Dev, 0x00, 0x00);
- Status = VL53L0X_WrByte(Dev, 0x91, PALDevDataGet(Dev, StopVariable));
- Status = VL53L0X_WrByte(Dev, 0x00, 0x01);
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x00);
- Status = VL53L0X_WrByte(Dev, 0x80, 0x00);
-
- switch (DeviceMode) {
- case VL53L0X_DEVICEMODE_SINGLE_RANGING:
- Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSRANGE_START, 0x01);
-
- Byte = StartStopByte;
- if (Status == VL53L0X_ERROR_NONE) {
- /* Wait until start bit has been cleared */
- LoopNb = 0;
- do {
- if (LoopNb > 0)
- Status = VL53L0X_RdByte(Dev,
- VL53L0X_REG_SYSRANGE_START, &Byte);
- LoopNb = LoopNb + 1;
- } while (((Byte & StartStopByte) == StartStopByte)
- && (Status == VL53L0X_ERROR_NONE)
- && (LoopNb < VL53L0X_DEFAULT_MAX_LOOP));
-
- if (LoopNb >= VL53L0X_DEFAULT_MAX_LOOP)
- Status = VL53L0X_ERROR_TIME_OUT;
-
- }
-
- break;
- case VL53L0X_DEVICEMODE_CONTINUOUS_RANGING:
- /* Back-to-back mode */
-
- /* Check if need to apply interrupt settings */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_CheckAndLoadInterruptSettings(Dev, 1);
-
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_SYSRANGE_START,
- VL53L0X_REG_SYSRANGE_MODE_BACKTOBACK);
- if (Status == VL53L0X_ERROR_NONE) {
- /* Set PAL State to Running */
- PALDevDataSet(Dev, PalState, VL53L0X_STATE_RUNNING);
- }
- break;
- case VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING:
- /* Continuous mode */
- /* Check if need to apply interrupt settings */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_CheckAndLoadInterruptSettings(Dev, 1);
-
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_SYSRANGE_START,
- VL53L0X_REG_SYSRANGE_MODE_TIMED);
-
- if (Status == VL53L0X_ERROR_NONE) {
- /* Set PAL State to Running */
- PALDevDataSet(Dev, PalState, VL53L0X_STATE_RUNNING);
- }
- break;
- default:
- /* Selected mode not supported */
- Status = VL53L0X_ERROR_MODE_NOT_SUPPORTED;
- }
-
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ VL53L0X_DeviceModes device_mode;
+ uint8_t byte;
+ uint8_t start_stop_byte = VL53L0X_REG_SYSRANGE_MODE_START_STOP;
+ uint32_t loop_nb;
+ LOG_FUNCTION_START("");
+
+ /* Get Current DeviceMode */
+ vl53l0x_get_device_mode(dev, &device_mode);
+
+ status = vl53l0x_write_byte(dev, 0x80, 0x01);
+ status = vl53l0x_write_byte(dev, 0xFF, 0x01);
+ status = vl53l0x_write_byte(dev, 0x00, 0x00);
+ status = vl53l0x_write_byte(dev, 0x91, PALDevDataGet(dev, StopVariable));
+ status = vl53l0x_write_byte(dev, 0x00, 0x01);
+ status = vl53l0x_write_byte(dev, 0xFF, 0x00);
+ status = vl53l0x_write_byte(dev, 0x80, 0x00);
+
+ switch (device_mode) {
+ case VL53L0X_DEVICEMODE_SINGLE_RANGING:
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_SYSRANGE_START, 0x01);
+
+ byte = start_stop_byte;
+ if (status == VL53L0X_ERROR_NONE) {
+ /* Wait until start bit has been cleared */
+ loop_nb = 0;
+ do {
+ if (loop_nb > 0)
+ status = vl53l0x_read_byte(dev,
+ VL53L0X_REG_SYSRANGE_START, &byte);
+ loop_nb = loop_nb + 1;
+ } while (((byte & start_stop_byte) == start_stop_byte)
+ && (status == VL53L0X_ERROR_NONE)
+ && (loop_nb < VL53L0X_DEFAULT_MAX_LOOP));
+
+ if (loop_nb >= VL53L0X_DEFAULT_MAX_LOOP)
+ status = VL53L0X_ERROR_TIME_OUT;
+
+ }
+
+ break;
+ case VL53L0X_DEVICEMODE_CONTINUOUS_RANGING:
+ /* Back-to-back mode */
+
+ /* Check if need to apply interrupt settings */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_check_and_load_interrupt_settings(dev, 1);
+
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_SYSRANGE_START,
+ VL53L0X_REG_SYSRANGE_MODE_BACKTOBACK);
+ if (status == VL53L0X_ERROR_NONE) {
+ /* Set PAL State to Running */
+ PALDevDataSet(dev, PalState, VL53L0X_STATE_RUNNING);
+ }
+ break;
+ case VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING:
+ /* Continuous mode */
+ /* Check if need to apply interrupt settings */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_check_and_load_interrupt_settings(dev, 1);
+
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_SYSRANGE_START,
+ VL53L0X_REG_SYSRANGE_MODE_TIMED);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ /* Set PAL State to Running */
+ PALDevDataSet(dev, PalState, VL53L0X_STATE_RUNNING);
+ }
+ break;
+ default:
+ /* Selected mode not supported */
+ status = VL53L0X_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+
+ LOG_FUNCTION_END(status);
+ return status;
}
/* Group PAL Measurement Functions */
-VL53L0X_Error VL53L0X::VL53L0X_PerformSingleMeasurement(VL53L0X_DEV Dev)
+VL53L0X_Error VL53L0X::vl53l0x_perform_single_measurement(VL53L0X_DEV dev)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- VL53L0X_DeviceModes DeviceMode;
-
- LOG_FUNCTION_START("");
-
- /* Get Current DeviceMode */
- Status = VL53L0X_GetDeviceMode(Dev, &DeviceMode);
-
- /* Start immediately to run a single ranging measurement in case of
- * single ranging or single histogram */
- if (Status == VL53L0X_ERROR_NONE
- && DeviceMode == VL53L0X_DEVICEMODE_SINGLE_RANGING)
- Status = VL53L0X_StartMeasurement(Dev);
-
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_measurement_poll_for_completion(Dev);
-
-
- /* Change PAL State in case of single ranging or single histogram */
- if (Status == VL53L0X_ERROR_NONE
- && DeviceMode == VL53L0X_DEVICEMODE_SINGLE_RANGING)
- PALDevDataSet(Dev, PalState, VL53L0X_STATE_IDLE);
-
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ VL53L0X_DeviceModes device_mode;
+
+ LOG_FUNCTION_START("");
+
+ /* Get Current DeviceMode */
+ status = vl53l0x_get_device_mode(dev, &device_mode);
+
+ /* Start immediately to run a single ranging measurement in case of
+ * single ranging or single histogram */
+ if (status == VL53L0X_ERROR_NONE
+ && device_mode == VL53L0X_DEVICEMODE_SINGLE_RANGING)
+ status = vl53l0x_start_measurement(dev);
+
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_measurement_poll_for_completion(dev);
+
+
+ /* Change PAL State in case of single ranging or single histogram */
+ if (status == VL53L0X_ERROR_NONE
+ && device_mode == VL53L0X_DEVICEMODE_SINGLE_RANGING)
+ PALDevDataSet(dev, PalState, VL53L0X_STATE_IDLE);
+
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetXTalkCompensationEnable(VL53L0X_DEV Dev,
- uint8_t *pXTalkCompensationEnable)
+VL53L0X_Error VL53L0X::vl53l0x_get_x_talk_compensation_enable(VL53L0X_DEV dev,
+ uint8_t *p_x_talk_compensation_enable)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t Temp8;
- LOG_FUNCTION_START("");
-
- VL53L0X_GETPARAMETERFIELD(Dev, XTalkCompensationEnable, Temp8);
- *pXTalkCompensationEnable = Temp8;
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t temp8;
+ LOG_FUNCTION_START("");
+
+ VL53L0X_GETPARAMETERFIELD(dev, XTalkCompensationEnable, temp8);
+ *p_x_talk_compensation_enable = temp8;
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_get_total_xtalk_rate(VL53L0X_DEV Dev,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
- FixPoint1616_t *ptotal_xtalk_rate_mcps)
+VL53L0X_Error VL53L0X::vl53l0x_get_total_xtalk_rate(VL53L0X_DEV dev,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
+ FixPoint1616_t *p_total_xtalk_rate_mcps)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
-
- uint8_t xtalkCompEnable;
- FixPoint1616_t totalXtalkMegaCps;
- FixPoint1616_t xtalkPerSpadMegaCps;
-
- *ptotal_xtalk_rate_mcps = 0;
-
- Status = VL53L0X_GetXTalkCompensationEnable(Dev, &xtalkCompEnable);
- if (Status == VL53L0X_ERROR_NONE) {
-
- if (xtalkCompEnable) {
-
- VL53L0X_GETPARAMETERFIELD(
- Dev,
- XTalkCompensationRateMegaCps,
- xtalkPerSpadMegaCps);
-
- /* FixPoint1616 * FixPoint 8:8 = FixPoint0824 */
- totalXtalkMegaCps =
- pRangingMeasurementData->EffectiveSpadRtnCount *
- xtalkPerSpadMegaCps;
-
- /* FixPoint0824 >> 8 = FixPoint1616 */
- *ptotal_xtalk_rate_mcps =
- (totalXtalkMegaCps + 0x80) >> 8;
- }
- }
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+
+ uint8_t xtalk_comp_enable;
+ FixPoint1616_t total_xtalk_mega_cps;
+ FixPoint1616_t xtalk_per_spad_mega_cps;
+
+ *p_total_xtalk_rate_mcps = 0;
+
+ status = vl53l0x_get_x_talk_compensation_enable(dev, &xtalk_comp_enable);
+ if (status == VL53L0X_ERROR_NONE) {
+
+ if (xtalk_comp_enable) {
+
+ VL53L0X_GETPARAMETERFIELD(
+ dev,
+ XTalkCompensationRateMegaCps,
+ xtalk_per_spad_mega_cps);
+
+ /* FixPoint1616 * FixPoint 8:8 = FixPoint0824 */
+ total_xtalk_mega_cps =
+ p_ranging_measurement_data->EffectiveSpadRtnCount *
+ xtalk_per_spad_mega_cps;
+
+ /* FixPoint0824 >> 8 = FixPoint1616 */
+ *p_total_xtalk_rate_mcps =
+ (total_xtalk_mega_cps + 0x80) >> 8;
+ }
+ }
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_get_total_signal_rate(VL53L0X_DEV Dev,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
- FixPoint1616_t *ptotal_signal_rate_mcps)
+VL53L0X_Error VL53L0X::vl53l0x_get_total_signal_rate(VL53L0X_DEV dev,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
+ FixPoint1616_t *p_total_signal_rate_mcps)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- FixPoint1616_t totalXtalkMegaCps;
-
- LOG_FUNCTION_START("");
-
- *ptotal_signal_rate_mcps =
- pRangingMeasurementData->SignalRateRtnMegaCps;
-
- Status = VL53L0X_get_total_xtalk_rate(
- Dev, pRangingMeasurementData, &totalXtalkMegaCps);
-
- if (Status == VL53L0X_ERROR_NONE)
- *ptotal_signal_rate_mcps += totalXtalkMegaCps;
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ FixPoint1616_t total_xtalk_mega_cps;
+
+ LOG_FUNCTION_START("");
+
+ *p_total_signal_rate_mcps =
+ p_ranging_measurement_data->SignalRateRtnMegaCps;
+
+ status = vl53l0x_get_total_xtalk_rate(
+ dev, p_ranging_measurement_data, &total_xtalk_mega_cps);
+
+ if (status == VL53L0X_ERROR_NONE)
+ *p_total_signal_rate_mcps += total_xtalk_mega_cps;
+
+ return status;
}
/* To convert ms into register value */
-uint32_t VL53L0X::VL53L0X_calc_timeout_mclks(VL53L0X_DEV Dev,
- uint32_t timeout_period_us,
- uint8_t vcsel_period_pclks)
+uint32_t VL53L0X::vl53l0x_calc_timeout_mclks(VL53L0X_DEV dev,
+ uint32_t timeout_period_us,
+ uint8_t vcsel_period_pclks)
{
- uint32_t macro_period_ps;
- uint32_t macro_period_ns;
- uint32_t timeout_period_mclks = 0;
-
- macro_period_ps = VL53L0X_calc_macro_period_ps(Dev, vcsel_period_pclks);
- macro_period_ns = (macro_period_ps + 500) / 1000;
-
- timeout_period_mclks =
- (uint32_t) (((timeout_period_us * 1000)
- + (macro_period_ns / 2)) / macro_period_ns);
+ uint32_t macro_period_ps;
+ uint32_t macro_period_ns;
+ uint32_t timeout_period_mclks = 0;
+
+ macro_period_ps = vl53l0x_calc_macro_period_ps(dev, vcsel_period_pclks);
+ macro_period_ns = (macro_period_ps + 500) / 1000;
+
+ timeout_period_mclks =
+ (uint32_t)(((timeout_period_us * 1000)
+ + (macro_period_ns / 2)) / macro_period_ns);
return timeout_period_mclks;
}
-uint32_t VL53L0X::VL53L0X_isqrt(uint32_t num)
+uint32_t VL53L0X::vl53l0x_isqrt(uint32_t num)
{
- /*
- * Implements an integer square root
- *
- * From: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
- */
-
- uint32_t res = 0;
- uint32_t bit = 1 << 30;
- /* The second-to-top bit is set:
- * 1 << 14 for 16-bits, 1 << 30 for 32 bits */
-
- /* "bit" starts at the highest power of four <= the argument. */
- while (bit > num)
- bit >>= 2;
-
-
- while (bit != 0) {
- if (num >= res + bit) {
- num -= res + bit;
- res = (res >> 1) + bit;
- } else
- res >>= 1;
-
- bit >>= 2;
- }
-
- return res;
+ /*
+ * Implements an integer square root
+ *
+ * From: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
+ */
+
+ uint32_t res = 0;
+ uint32_t bit = 1 << 30;
+ /* The second-to-top bit is set:
+ * 1 << 14 for 16-bits, 1 << 30 for 32 bits */
+
+ /* "bit" starts at the highest power of four <= the argument. */
+ while (bit > num)
+ bit >>= 2;
+
+
+ while (bit != 0) {
+ if (num >= res + bit) {
+ num -= res + bit;
+ res = (res >> 1) + bit;
+ } else
+ res >>= 1;
+
+ bit >>= 2;
+ }
+
+ return res;
}
-VL53L0X_Error VL53L0X::VL53L0X_calc_dmax(
- VL53L0X_DEV Dev,
- FixPoint1616_t totalSignalRate_mcps,
- FixPoint1616_t totalCorrSignalRate_mcps,
- FixPoint1616_t pwMult,
- uint32_t sigmaEstimateP1,
- FixPoint1616_t sigmaEstimateP2,
- uint32_t peakVcselDuration_us,
- uint32_t *pdmax_mm)
+VL53L0X_Error VL53L0X::vl53l0x_calc_dmax(
+ VL53L0X_DEV dev,
+ FixPoint1616_t total_signal_rate_mcps,
+ FixPoint1616_t total_corr_signal_rate_mcps,
+ FixPoint1616_t pw_mult,
+ uint32_t sigma_estimate_p1,
+ FixPoint1616_t sigma_estimate_p2,
+ uint32_t peak_vcsel_duration_us,
+ uint32_t *pd_max_mm)
{
- const uint32_t cSigmaLimit = 18;
- const FixPoint1616_t cSignalLimit = 0x4000; /* 0.25 */
- const FixPoint1616_t cSigmaEstRef = 0x00000042; /* 0.001 */
- const uint32_t cAmbEffWidthSigmaEst_ns = 6;
- const uint32_t cAmbEffWidthDMax_ns = 7;
- uint32_t dmaxCalRange_mm;
- FixPoint1616_t dmaxCalSignalRateRtn_mcps;
- FixPoint1616_t minSignalNeeded;
- FixPoint1616_t minSignalNeeded_p1;
- FixPoint1616_t minSignalNeeded_p2;
- FixPoint1616_t minSignalNeeded_p3;
- FixPoint1616_t minSignalNeeded_p4;
- FixPoint1616_t sigmaLimitTmp;
- FixPoint1616_t sigmaEstSqTmp;
- FixPoint1616_t signalLimitTmp;
- FixPoint1616_t SignalAt0mm;
- FixPoint1616_t dmaxDark;
- FixPoint1616_t dmaxAmbient;
- FixPoint1616_t dmaxDarkTmp;
- FixPoint1616_t sigmaEstP2Tmp;
- uint32_t signalRateTemp_mcps;
-
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
-
- LOG_FUNCTION_START("");
-
- dmaxCalRange_mm =
- PALDevDataGet(Dev, DmaxCalRangeMilliMeter);
-
- dmaxCalSignalRateRtn_mcps =
- PALDevDataGet(Dev, DmaxCalSignalRateRtnMegaCps);
-
- /* uint32 * FixPoint1616 = FixPoint1616 */
- SignalAt0mm = dmaxCalRange_mm * dmaxCalSignalRateRtn_mcps;
-
- /* FixPoint1616 >> 8 = FixPoint2408 */
- SignalAt0mm = (SignalAt0mm + 0x80) >> 8;
- SignalAt0mm *= dmaxCalRange_mm;
-
- minSignalNeeded_p1 = 0;
- if (totalCorrSignalRate_mcps > 0) {
-
- /* Shift by 10 bits to increase resolution prior to the
- * division */
- signalRateTemp_mcps = totalSignalRate_mcps << 10;
-
- /* Add rounding value prior to division */
- minSignalNeeded_p1 = signalRateTemp_mcps +
- (totalCorrSignalRate_mcps/2);
-
- /* FixPoint0626/FixPoint1616 = FixPoint2210 */
- minSignalNeeded_p1 /= totalCorrSignalRate_mcps;
-
- /* Apply a factored version of the speed of light.
- Correction to be applied at the end */
- minSignalNeeded_p1 *= 3;
-
- /* FixPoint2210 * FixPoint2210 = FixPoint1220 */
- minSignalNeeded_p1 *= minSignalNeeded_p1;
-
- /* FixPoint1220 >> 16 = FixPoint2804 */
- minSignalNeeded_p1 = (minSignalNeeded_p1 + 0x8000) >> 16;
- }
-
- minSignalNeeded_p2 = pwMult * sigmaEstimateP1;
-
- /* FixPoint1616 >> 16 = uint32 */
- minSignalNeeded_p2 = (minSignalNeeded_p2 + 0x8000) >> 16;
-
- /* uint32 * uint32 = uint32 */
- minSignalNeeded_p2 *= minSignalNeeded_p2;
-
- /* Check sigmaEstimateP2
- * If this value is too high there is not enough signal rate
- * to calculate dmax value so set a suitable value to ensure
- * a very small dmax.
- */
- sigmaEstP2Tmp = (sigmaEstimateP2 + 0x8000) >> 16;
- sigmaEstP2Tmp = (sigmaEstP2Tmp + cAmbEffWidthSigmaEst_ns/2)/
- cAmbEffWidthSigmaEst_ns;
- sigmaEstP2Tmp *= cAmbEffWidthDMax_ns;
-
- if (sigmaEstP2Tmp > 0xffff) {
- minSignalNeeded_p3 = 0xfff00000;
- } else {
-
- /* DMAX uses a different ambient width from sigma, so apply
- * correction.
- * Perform division before multiplication to prevent overflow.
- */
- sigmaEstimateP2 = (sigmaEstimateP2 + cAmbEffWidthSigmaEst_ns/2)/
- cAmbEffWidthSigmaEst_ns;
- sigmaEstimateP2 *= cAmbEffWidthDMax_ns;
-
- /* FixPoint1616 >> 16 = uint32 */
- minSignalNeeded_p3 = (sigmaEstimateP2 + 0x8000) >> 16;
-
- minSignalNeeded_p3 *= minSignalNeeded_p3;
-
- }
-
- /* FixPoint1814 / uint32 = FixPoint1814 */
- sigmaLimitTmp = ((cSigmaLimit << 14) + 500) / 1000;
-
- /* FixPoint1814 * FixPoint1814 = FixPoint3628 := FixPoint0428 */
- sigmaLimitTmp *= sigmaLimitTmp;
-
- /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
- sigmaEstSqTmp = cSigmaEstRef * cSigmaEstRef;
-
- /* FixPoint3232 >> 4 = FixPoint0428 */
- sigmaEstSqTmp = (sigmaEstSqTmp + 0x08) >> 4;
-
- /* FixPoint0428 - FixPoint0428 = FixPoint0428 */
- sigmaLimitTmp -= sigmaEstSqTmp;
-
- /* uint32_t * FixPoint0428 = FixPoint0428 */
- minSignalNeeded_p4 = 4 * 12 * sigmaLimitTmp;
-
- /* FixPoint0428 >> 14 = FixPoint1814 */
- minSignalNeeded_p4 = (minSignalNeeded_p4 + 0x2000) >> 14;
-
- /* uint32 + uint32 = uint32 */
- minSignalNeeded = (minSignalNeeded_p2 + minSignalNeeded_p3);
-
- /* uint32 / uint32 = uint32 */
- minSignalNeeded += (peakVcselDuration_us/2);
- minSignalNeeded /= peakVcselDuration_us;
-
- /* uint32 << 14 = FixPoint1814 */
- minSignalNeeded <<= 14;
-
- /* FixPoint1814 / FixPoint1814 = uint32 */
- minSignalNeeded += (minSignalNeeded_p4/2);
- minSignalNeeded /= minSignalNeeded_p4;
-
- /* FixPoint3200 * FixPoint2804 := FixPoint2804*/
- minSignalNeeded *= minSignalNeeded_p1;
-
- /* Apply correction by dividing by 1000000.
- * This assumes 10E16 on the numerator of the equation
- * and 10E-22 on the denominator.
- * We do this because 32bit fix point calculation can't
- * handle the larger and smaller elements of this equation,
- * i.e. speed of light and pulse widths.
- */
- minSignalNeeded = (minSignalNeeded + 500) / 1000;
- minSignalNeeded <<= 4;
-
- minSignalNeeded = (minSignalNeeded + 500) / 1000;
-
- /* FixPoint1616 >> 8 = FixPoint2408 */
- signalLimitTmp = (cSignalLimit + 0x80) >> 8;
-
- /* FixPoint2408/FixPoint2408 = uint32 */
- if (signalLimitTmp != 0)
- dmaxDarkTmp = (SignalAt0mm + (signalLimitTmp / 2))
- / signalLimitTmp;
- else
- dmaxDarkTmp = 0;
-
- dmaxDark = VL53L0X_isqrt(dmaxDarkTmp);
-
- /* FixPoint2408/FixPoint2408 = uint32 */
- if (minSignalNeeded != 0)
- dmaxAmbient = (SignalAt0mm + minSignalNeeded/2)
- / minSignalNeeded;
- else
- dmaxAmbient = 0;
-
- dmaxAmbient = VL53L0X_isqrt(dmaxAmbient);
-
- *pdmax_mm = dmaxDark;
- if (dmaxDark > dmaxAmbient)
- *pdmax_mm = dmaxAmbient;
-
- LOG_FUNCTION_END(Status);
-
- return Status;
+ const uint32_t c_sigma_limit = 18;
+ const FixPoint1616_t c_signal_limit = 0x4000; /* 0.25 */
+ const FixPoint1616_t c_sigma_est_ref = 0x00000042; /* 0.001 */
+ const uint32_t c_amb_eff_width_sigma_est_ns = 6;
+ const uint32_t c_amb_eff_width_d_max_ns = 7;
+ uint32_t dmax_cal_range_mm;
+ FixPoint1616_t dmax_cal_signal_rate_rtn_mcps;
+ FixPoint1616_t min_signal_needed;
+ FixPoint1616_t min_signal_needed_p1;
+ FixPoint1616_t min_signal_needed_p2;
+ FixPoint1616_t min_signal_needed_p3;
+ FixPoint1616_t min_signal_needed_p4;
+ FixPoint1616_t sigma_limit_tmp;
+ FixPoint1616_t sigma_est_sq_tmp;
+ FixPoint1616_t signal_limit_tmp;
+ FixPoint1616_t signal_at0_mm;
+ FixPoint1616_t dmax_dark;
+ FixPoint1616_t dmax_ambient;
+ FixPoint1616_t dmax_dark_tmp;
+ FixPoint1616_t sigma_est_p2_tmp;
+ uint32_t signal_rate_temp_mcps;
+
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ dmax_cal_range_mm =
+ PALDevDataGet(dev, DmaxCalRangeMilliMeter);
+
+ dmax_cal_signal_rate_rtn_mcps =
+ PALDevDataGet(dev, DmaxCalSignalRateRtnMegaCps);
+
+ /* uint32 * FixPoint1616 = FixPoint1616 */
+ signal_at0_mm = dmax_cal_range_mm * dmax_cal_signal_rate_rtn_mcps;
+
+ /* FixPoint1616 >> 8 = FixPoint2408 */
+ signal_at0_mm = (signal_at0_mm + 0x80) >> 8;
+ signal_at0_mm *= dmax_cal_range_mm;
+
+ min_signal_needed_p1 = 0;
+ if (total_corr_signal_rate_mcps > 0) {
+
+ /* Shift by 10 bits to increase resolution prior to the
+ * division */
+ signal_rate_temp_mcps = total_signal_rate_mcps << 10;
+
+ /* Add rounding value prior to division */
+ min_signal_needed_p1 = signal_rate_temp_mcps +
+ (total_corr_signal_rate_mcps / 2);
+
+ /* FixPoint0626/FixPoint1616 = FixPoint2210 */
+ min_signal_needed_p1 /= total_corr_signal_rate_mcps;
+
+ /* Apply a factored version of the speed of light.
+ Correction to be applied at the end */
+ min_signal_needed_p1 *= 3;
+
+ /* FixPoint2210 * FixPoint2210 = FixPoint1220 */
+ min_signal_needed_p1 *= min_signal_needed_p1;
+
+ /* FixPoint1220 >> 16 = FixPoint2804 */
+ min_signal_needed_p1 = (min_signal_needed_p1 + 0x8000) >> 16;
+ }
+
+ min_signal_needed_p2 = pw_mult * sigma_estimate_p1;
+
+ /* FixPoint1616 >> 16 = uint32 */
+ min_signal_needed_p2 = (min_signal_needed_p2 + 0x8000) >> 16;
+
+ /* uint32 * uint32 = uint32 */
+ min_signal_needed_p2 *= min_signal_needed_p2;
+
+ /* Check sigmaEstimateP2
+ * If this value is too high there is not enough signal rate
+ * to calculate dmax value so set a suitable value to ensure
+ * a very small dmax.
+ */
+ sigma_est_p2_tmp = (sigma_estimate_p2 + 0x8000) >> 16;
+ sigma_est_p2_tmp = (sigma_est_p2_tmp + c_amb_eff_width_sigma_est_ns / 2) /
+ c_amb_eff_width_sigma_est_ns;
+ sigma_est_p2_tmp *= c_amb_eff_width_d_max_ns;
+
+ if (sigma_est_p2_tmp > 0xffff) {
+ min_signal_needed_p3 = 0xfff00000;
+ } else {
+
+ /* DMAX uses a different ambient width from sigma, so apply
+ * correction.
+ * Perform division before multiplication to prevent overflow.
+ */
+ sigma_estimate_p2 = (sigma_estimate_p2 + c_amb_eff_width_sigma_est_ns / 2) /
+ c_amb_eff_width_sigma_est_ns;
+ sigma_estimate_p2 *= c_amb_eff_width_d_max_ns;
+
+ /* FixPoint1616 >> 16 = uint32 */
+ min_signal_needed_p3 = (sigma_estimate_p2 + 0x8000) >> 16;
+
+ min_signal_needed_p3 *= min_signal_needed_p3;
+
+ }
+
+ /* FixPoint1814 / uint32 = FixPoint1814 */
+ sigma_limit_tmp = ((c_sigma_limit << 14) + 500) / 1000;
+
+ /* FixPoint1814 * FixPoint1814 = FixPoint3628 := FixPoint0428 */
+ sigma_limit_tmp *= sigma_limit_tmp;
+
+ /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
+ sigma_est_sq_tmp = c_sigma_est_ref * c_sigma_est_ref;
+
+ /* FixPoint3232 >> 4 = FixPoint0428 */
+ sigma_est_sq_tmp = (sigma_est_sq_tmp + 0x08) >> 4;
+
+ /* FixPoint0428 - FixPoint0428 = FixPoint0428 */
+ sigma_limit_tmp -= sigma_est_sq_tmp;
+
+ /* uint32_t * FixPoint0428 = FixPoint0428 */
+ min_signal_needed_p4 = 4 * 12 * sigma_limit_tmp;
+
+ /* FixPoint0428 >> 14 = FixPoint1814 */
+ min_signal_needed_p4 = (min_signal_needed_p4 + 0x2000) >> 14;
+
+ /* uint32 + uint32 = uint32 */
+ min_signal_needed = (min_signal_needed_p2 + min_signal_needed_p3);
+
+ /* uint32 / uint32 = uint32 */
+ min_signal_needed += (peak_vcsel_duration_us / 2);
+ min_signal_needed /= peak_vcsel_duration_us;
+
+ /* uint32 << 14 = FixPoint1814 */
+ min_signal_needed <<= 14;
+
+ /* FixPoint1814 / FixPoint1814 = uint32 */
+ min_signal_needed += (min_signal_needed_p4 / 2);
+ min_signal_needed /= min_signal_needed_p4;
+
+ /* FixPoint3200 * FixPoint2804 := FixPoint2804*/
+ min_signal_needed *= min_signal_needed_p1;
+
+ /* Apply correction by dividing by 1000000.
+ * This assumes 10E16 on the numerator of the equation
+ * and 10E-22 on the denominator.
+ * We do this because 32bit fix point calculation can't
+ * handle the larger and smaller elements of this equation,
+ * i.e. speed of light and pulse widths.
+ */
+ min_signal_needed = (min_signal_needed + 500) / 1000;
+ min_signal_needed <<= 4;
+
+ min_signal_needed = (min_signal_needed + 500) / 1000;
+
+ /* FixPoint1616 >> 8 = FixPoint2408 */
+ signal_limit_tmp = (c_signal_limit + 0x80) >> 8;
+
+ /* FixPoint2408/FixPoint2408 = uint32 */
+ if (signal_limit_tmp != 0)
+ dmax_dark_tmp = (signal_at0_mm + (signal_limit_tmp / 2))
+ / signal_limit_tmp;
+ else
+ dmax_dark_tmp = 0;
+
+ dmax_dark = vl53l0x_isqrt(dmax_dark_tmp);
+
+ /* FixPoint2408/FixPoint2408 = uint32 */
+ if (min_signal_needed != 0)
+ dmax_ambient = (signal_at0_mm + min_signal_needed / 2)
+ / min_signal_needed;
+ else
+ dmax_ambient = 0;
+
+ dmax_ambient = vl53l0x_isqrt(dmax_ambient);
+
+ *pd_max_mm = dmax_dark;
+ if (dmax_dark > dmax_ambient)
+ *pd_max_mm = dmax_ambient;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_calc_sigma_estimate(VL53L0X_DEV Dev,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
- FixPoint1616_t *pSigmaEstimate,
- uint32_t *pDmax_mm)
+VL53L0X_Error VL53L0X::vl53l0x_calc_sigma_estimate(VL53L0X_DEV dev,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
+ FixPoint1616_t *p_sigma_estimate,
+ uint32_t *p_dmax_mm)
{
- /* Expressed in 100ths of a ns, i.e. centi-ns */
- const uint32_t cPulseEffectiveWidth_centi_ns = 800;
- /* Expressed in 100ths of a ns, i.e. centi-ns */
- const uint32_t cAmbientEffectiveWidth_centi_ns = 600;
- const FixPoint1616_t cDfltFinalRangeIntegrationTimeMilliSecs = 0x00190000; /* 25ms */
- const uint32_t cVcselPulseWidth_ps = 4700; /* pico secs */
- const FixPoint1616_t cSigmaEstMax = 0x028F87AE;
- const FixPoint1616_t cSigmaEstRtnMax = 0xF000;
- const FixPoint1616_t cAmbToSignalRatioMax = 0xF0000000/
- cAmbientEffectiveWidth_centi_ns;
- /* Time Of Flight per mm (6.6 pico secs) */
- const FixPoint1616_t cTOF_per_mm_ps = 0x0006999A;
- const uint32_t c16BitRoundingParam = 0x00008000;
- const FixPoint1616_t cMaxXTalk_kcps = 0x00320000;
- const uint32_t cPllPeriod_ps = 1655;
-
- uint32_t vcselTotalEventsRtn;
- uint32_t finalRangeTimeoutMicroSecs;
- uint32_t preRangeTimeoutMicroSecs;
- uint32_t finalRangeIntegrationTimeMilliSecs;
- FixPoint1616_t sigmaEstimateP1;
- FixPoint1616_t sigmaEstimateP2;
- FixPoint1616_t sigmaEstimateP3;
- FixPoint1616_t deltaT_ps;
- FixPoint1616_t pwMult;
- FixPoint1616_t sigmaEstRtn;
- FixPoint1616_t sigmaEstimate;
- FixPoint1616_t xTalkCorrection;
- FixPoint1616_t ambientRate_kcps;
- FixPoint1616_t peakSignalRate_kcps;
- FixPoint1616_t xTalkCompRate_mcps;
- uint32_t xTalkCompRate_kcps;
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- FixPoint1616_t diff1_mcps;
- FixPoint1616_t diff2_mcps;
- FixPoint1616_t sqr1;
- FixPoint1616_t sqr2;
- FixPoint1616_t sqrSum;
- FixPoint1616_t sqrtResult_centi_ns;
- FixPoint1616_t sqrtResult;
- FixPoint1616_t totalSignalRate_mcps;
- FixPoint1616_t correctedSignalRate_mcps;
- FixPoint1616_t sigmaEstRef;
- uint32_t vcselWidth;
- uint32_t finalRangeMacroPCLKS;
- uint32_t preRangeMacroPCLKS;
- uint32_t peakVcselDuration_us;
- uint8_t finalRangeVcselPCLKS;
- uint8_t preRangeVcselPCLKS;
- /*! \addtogroup calc_sigma_estimate
- * @{
- *
- * Estimates the range sigma
- */
-
- LOG_FUNCTION_START("");
-
- VL53L0X_GETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps,
- xTalkCompRate_mcps);
-
- /*
- * We work in kcps rather than mcps as this helps keep within the
- * confines of the 32 Fix1616 type.
- */
-
- ambientRate_kcps =
- (pRangingMeasurementData->AmbientRateRtnMegaCps * 1000) >> 16;
-
- correctedSignalRate_mcps =
- pRangingMeasurementData->SignalRateRtnMegaCps;
-
-
- Status = VL53L0X_get_total_signal_rate(
- Dev, pRangingMeasurementData, &totalSignalRate_mcps);
- Status = VL53L0X_get_total_xtalk_rate(
- Dev, pRangingMeasurementData, &xTalkCompRate_mcps);
-
-
- /* Signal rate measurement provided by device is the
- * peak signal rate, not average.
- */
- peakSignalRate_kcps = (totalSignalRate_mcps * 1000);
- peakSignalRate_kcps = (peakSignalRate_kcps + 0x8000) >> 16;
-
- xTalkCompRate_kcps = xTalkCompRate_mcps * 1000;
-
- if (xTalkCompRate_kcps > cMaxXTalk_kcps)
- xTalkCompRate_kcps = cMaxXTalk_kcps;
-
- if (Status == VL53L0X_ERROR_NONE) {
-
- /* Calculate final range macro periods */
- finalRangeTimeoutMicroSecs = VL53L0X_GETDEVICESPECIFICPARAMETER(
- Dev, FinalRangeTimeoutMicroSecs);
-
- finalRangeVcselPCLKS = VL53L0X_GETDEVICESPECIFICPARAMETER(
- Dev, FinalRangeVcselPulsePeriod);
-
- finalRangeMacroPCLKS = VL53L0X_calc_timeout_mclks(
- Dev, finalRangeTimeoutMicroSecs, finalRangeVcselPCLKS);
-
- /* Calculate pre-range macro periods */
- preRangeTimeoutMicroSecs = VL53L0X_GETDEVICESPECIFICPARAMETER(
- Dev, PreRangeTimeoutMicroSecs);
-
- preRangeVcselPCLKS = VL53L0X_GETDEVICESPECIFICPARAMETER(
- Dev, PreRangeVcselPulsePeriod);
-
- preRangeMacroPCLKS = VL53L0X_calc_timeout_mclks(
- Dev, preRangeTimeoutMicroSecs, preRangeVcselPCLKS);
-
- vcselWidth = 3;
- if (finalRangeVcselPCLKS == 8)
- vcselWidth = 2;
-
-
- peakVcselDuration_us = vcselWidth * 2048 *
- (preRangeMacroPCLKS + finalRangeMacroPCLKS);
- peakVcselDuration_us = (peakVcselDuration_us + 500)/1000;
- peakVcselDuration_us *= cPllPeriod_ps;
- peakVcselDuration_us = (peakVcselDuration_us + 500)/1000;
-
- /* Fix1616 >> 8 = Fix2408 */
- totalSignalRate_mcps = (totalSignalRate_mcps + 0x80) >> 8;
-
- /* Fix2408 * uint32 = Fix2408 */
- vcselTotalEventsRtn = totalSignalRate_mcps *
- peakVcselDuration_us;
-
- /* Fix2408 >> 8 = uint32 */
- vcselTotalEventsRtn = (vcselTotalEventsRtn + 0x80) >> 8;
-
- /* Fix2408 << 8 = Fix1616 = */
- totalSignalRate_mcps <<= 8;
- }
-
- if (Status != VL53L0X_ERROR_NONE) {
- LOG_FUNCTION_END(Status);
- return Status;
- }
-
- if (peakSignalRate_kcps == 0) {
- *pSigmaEstimate = cSigmaEstMax;
- PALDevDataSet(Dev, SigmaEstimate, cSigmaEstMax);
- *pDmax_mm = 0;
- } else {
- if (vcselTotalEventsRtn < 1)
- vcselTotalEventsRtn = 1;
-
- sigmaEstimateP1 = cPulseEffectiveWidth_centi_ns;
-
- /* ((FixPoint1616 << 16)* uint32)/uint32 = FixPoint1616 */
- sigmaEstimateP2 = (ambientRate_kcps << 16)/peakSignalRate_kcps;
- if (sigmaEstimateP2 > cAmbToSignalRatioMax) {
- /* Clip to prevent overflow. Will ensure safe
- * max result. */
- sigmaEstimateP2 = cAmbToSignalRatioMax;
- }
- sigmaEstimateP2 *= cAmbientEffectiveWidth_centi_ns;
-
- sigmaEstimateP3 = 2 * VL53L0X_isqrt(vcselTotalEventsRtn * 12);
-
- /* uint32 * FixPoint1616 = FixPoint1616 */
- deltaT_ps = pRangingMeasurementData->RangeMilliMeter *
- cTOF_per_mm_ps;
-
- /*
- * vcselRate - xtalkCompRate
- * (uint32 << 16) - FixPoint1616 = FixPoint1616.
- * Divide result by 1000 to convert to mcps.
- * 500 is added to ensure rounding when integer division
- * truncates.
- */
- diff1_mcps = (((peakSignalRate_kcps << 16) -
- 2 * xTalkCompRate_kcps) + 500)/1000;
-
- /* vcselRate + xtalkCompRate */
- diff2_mcps = ((peakSignalRate_kcps << 16) + 500)/1000;
-
- /* Shift by 8 bits to increase resolution prior to the
- * division */
- diff1_mcps <<= 8;
-
- /* FixPoint0824/FixPoint1616 = FixPoint2408 */
+ /* Expressed in 100ths of a ns, i.e. centi-ns */
+ const uint32_t c_pulse_effective_width_centi_ns = 800;
+ /* Expressed in 100ths of a ns, i.e. centi-ns */
+ const uint32_t c_ambient_effective_width_centi_ns = 600;
+ const FixPoint1616_t c_dflt_final_range_integration_time_milli_secs = 0x00190000; /* 25ms */
+ const uint32_t c_vcsel_pulse_width_ps = 4700; /* pico secs */
+ const FixPoint1616_t c_sigma_est_max = 0x028F87AE;
+ const FixPoint1616_t c_sigma_est_rtn_max = 0xF000;
+ const FixPoint1616_t c_amb_to_signal_ratio_max = 0xF0000000 /
+ c_ambient_effective_width_centi_ns;
+ /* Time Of Flight per mm (6.6 pico secs) */
+ const FixPoint1616_t c_tof_per_mm_ps = 0x0006999A;
+ const uint32_t c_16bit_rounding_param = 0x00008000;
+ const FixPoint1616_t c_max_x_talk_kcps = 0x00320000;
+ const uint32_t c_pll_period_ps = 1655;
+
+ uint32_t vcsel_total_events_rtn;
+ uint32_t final_range_timeout_micro_secs;
+ uint32_t pre_range_timeout_micro_secs;
+ uint32_t final_range_integration_time_milli_secs;
+ FixPoint1616_t sigma_estimate_p1;
+ FixPoint1616_t sigma_estimate_p2;
+ FixPoint1616_t sigma_estimate_p3;
+ FixPoint1616_t delta_t_ps;
+ FixPoint1616_t pw_mult;
+ FixPoint1616_t sigma_est_rtn;
+ FixPoint1616_t sigma_estimate;
+ FixPoint1616_t x_talk_correction;
+ FixPoint1616_t ambient_rate_kcps;
+ FixPoint1616_t peak_signal_rate_kcps;
+ FixPoint1616_t x_talk_comp_rate_mcps;
+ uint32_t x_talk_comp_rate_kcps;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ FixPoint1616_t diff1_mcps;
+ FixPoint1616_t diff2_mcps;
+ FixPoint1616_t sqr1;
+ FixPoint1616_t sqr2;
+ FixPoint1616_t sqr_sum;
+ FixPoint1616_t sqrt_result_centi_ns;
+ FixPoint1616_t sqrt_result;
+ FixPoint1616_t total_signal_rate_mcps;
+ FixPoint1616_t corrected_signal_rate_mcps;
+ FixPoint1616_t sigma_est_ref;
+ uint32_t vcsel_width;
+ uint32_t final_range_macro_pclks;
+ uint32_t pre_range_macro_pclks;
+ uint32_t peak_vcsel_duration_us;
+ uint8_t final_range_vcsel_pclks;
+ uint8_t pre_range_vcsel_pclks;
+ /*! \addtogroup calc_sigma_estimate
+ * @{
+ *
+ * Estimates the range sigma
+ */
+
+ LOG_FUNCTION_START("");
+
+ VL53L0X_GETPARAMETERFIELD(dev, XTalkCompensationRateMegaCps,
+ x_talk_comp_rate_mcps);
+
+ /*
+ * We work in kcps rather than mcps as this helps keep within the
+ * confines of the 32 Fix1616 type.
+ */
+
+ ambient_rate_kcps =
+ (p_ranging_measurement_data->AmbientRateRtnMegaCps * 1000) >> 16;
+
+ corrected_signal_rate_mcps =
+ p_ranging_measurement_data->SignalRateRtnMegaCps;
+
+
+ status = vl53l0x_get_total_signal_rate(
+ dev, p_ranging_measurement_data, &total_signal_rate_mcps);
+ status = vl53l0x_get_total_xtalk_rate(
+ dev, p_ranging_measurement_data, &x_talk_comp_rate_mcps);
+
+
+ /* Signal rate measurement provided by device is the
+ * peak signal rate, not average.
+ */
+ peak_signal_rate_kcps = (total_signal_rate_mcps * 1000);
+ peak_signal_rate_kcps = (peak_signal_rate_kcps + 0x8000) >> 16;
+
+ x_talk_comp_rate_kcps = x_talk_comp_rate_mcps * 1000;
+
+ if (x_talk_comp_rate_kcps > c_max_x_talk_kcps)
+ x_talk_comp_rate_kcps = c_max_x_talk_kcps;
+
+ if (status == VL53L0X_ERROR_NONE) {
+
+ /* Calculate final range macro periods */
+ final_range_timeout_micro_secs = VL53L0X_GETDEVICESPECIFICPARAMETER(
+ dev, FinalRangeTimeoutMicroSecs);
+
+ final_range_vcsel_pclks = VL53L0X_GETDEVICESPECIFICPARAMETER(
+ dev, FinalRangeVcselPulsePeriod);
+
+ final_range_macro_pclks = vl53l0x_calc_timeout_mclks(
+ dev, final_range_timeout_micro_secs, final_range_vcsel_pclks);
+
+ /* Calculate pre-range macro periods */
+ pre_range_timeout_micro_secs = VL53L0X_GETDEVICESPECIFICPARAMETER(
+ dev, PreRangeTimeoutMicroSecs);
+
+ pre_range_vcsel_pclks = VL53L0X_GETDEVICESPECIFICPARAMETER(
+ dev, PreRangeVcselPulsePeriod);
+
+ pre_range_macro_pclks = vl53l0x_calc_timeout_mclks(
+ dev, pre_range_timeout_micro_secs, pre_range_vcsel_pclks);
+
+ vcsel_width = 3;
+ if (final_range_vcsel_pclks == 8)
+ vcsel_width = 2;
+
+
+ peak_vcsel_duration_us = vcsel_width * 2048 *
+ (pre_range_macro_pclks + final_range_macro_pclks);
+ peak_vcsel_duration_us = (peak_vcsel_duration_us + 500) / 1000;
+ peak_vcsel_duration_us *= c_pll_period_ps;
+ peak_vcsel_duration_us = (peak_vcsel_duration_us + 500) / 1000;
+
+ /* Fix1616 >> 8 = Fix2408 */
+ total_signal_rate_mcps = (total_signal_rate_mcps + 0x80) >> 8;
+
+ /* Fix2408 * uint32 = Fix2408 */
+ vcsel_total_events_rtn = total_signal_rate_mcps *
+ peak_vcsel_duration_us;
+
+ /* Fix2408 >> 8 = uint32 */
+ vcsel_total_events_rtn = (vcsel_total_events_rtn + 0x80) >> 8;
+
+ /* Fix2408 << 8 = Fix1616 = */
+ total_signal_rate_mcps <<= 8;
+ }
+
+ if (status != VL53L0X_ERROR_NONE) {
+ LOG_FUNCTION_END(status);
+ return status;
+ }
+
+ if (peak_signal_rate_kcps == 0) {
+ *p_sigma_estimate = c_sigma_est_max;
+ PALDevDataSet(dev, SigmaEstimate, c_sigma_est_max);
+ *p_dmax_mm = 0;
+ } else {
+ if (vcsel_total_events_rtn < 1)
+ vcsel_total_events_rtn = 1;
+
+ sigma_estimate_p1 = c_pulse_effective_width_centi_ns;
+
+ /* ((FixPoint1616 << 16)* uint32)/uint32 = FixPoint1616 */
+ sigma_estimate_p2 = (ambient_rate_kcps << 16) / peak_signal_rate_kcps;
+ if (sigma_estimate_p2 > c_amb_to_signal_ratio_max) {
+ /* Clip to prevent overflow. Will ensure safe
+ * max result. */
+ sigma_estimate_p2 = c_amb_to_signal_ratio_max;
+ }
+ sigma_estimate_p2 *= c_ambient_effective_width_centi_ns;
+
+ sigma_estimate_p3 = 2 * vl53l0x_isqrt(vcsel_total_events_rtn * 12);
+
+ /* uint32 * FixPoint1616 = FixPoint1616 */
+ delta_t_ps = p_ranging_measurement_data->RangeMilliMeter *
+ c_tof_per_mm_ps;
+
+ /*
+ * vcselRate - xtalkCompRate
+ * (uint32 << 16) - FixPoint1616 = FixPoint1616.
+ * Divide result by 1000 to convert to mcps.
+ * 500 is added to ensure rounding when integer division
+ * truncates.
+ */
+ diff1_mcps = (((peak_signal_rate_kcps << 16) -
+ 2 * x_talk_comp_rate_kcps) + 500) / 1000;
+
+ /* vcselRate + xtalkCompRate */
+ diff2_mcps = ((peak_signal_rate_kcps << 16) + 500) / 1000;
+
+ /* Shift by 8 bits to increase resolution prior to the
+ * division */
+ diff1_mcps <<= 8;
+
+ /* FixPoint0824/FixPoint1616 = FixPoint2408 */
// xTalkCorrection = abs(diff1_mcps/diff2_mcps);
// abs is causing compiler overloading isue in C++, but unsigned types. So, redundant call anyway!
- xTalkCorrection = diff1_mcps/diff2_mcps;
-
- /* FixPoint2408 << 8 = FixPoint1616 */
- xTalkCorrection <<= 8;
-
- if(pRangingMeasurementData->RangeStatus != 0){
- pwMult = 1 << 16;
- } else {
- /* FixPoint1616/uint32 = FixPoint1616 */
- pwMult = deltaT_ps/cVcselPulseWidth_ps; /* smaller than 1.0f */
-
- /*
- * FixPoint1616 * FixPoint1616 = FixPoint3232, however both
- * values are small enough such that32 bits will not be
- * exceeded.
- */
- pwMult *= ((1 << 16) - xTalkCorrection);
-
- /* (FixPoint3232 >> 16) = FixPoint1616 */
- pwMult = (pwMult + c16BitRoundingParam) >> 16;
-
- /* FixPoint1616 + FixPoint1616 = FixPoint1616 */
- pwMult += (1 << 16);
-
- /*
- * At this point the value will be 1.xx, therefore if we square
- * the value this will exceed 32 bits. To address this perform
- * a single shift to the right before the multiplication.
- */
- pwMult >>= 1;
- /* FixPoint1715 * FixPoint1715 = FixPoint3430 */
- pwMult = pwMult * pwMult;
-
- /* (FixPoint3430 >> 14) = Fix1616 */
- pwMult >>= 14;
- }
-
- /* FixPoint1616 * uint32 = FixPoint1616 */
- sqr1 = pwMult * sigmaEstimateP1;
-
- /* (FixPoint1616 >> 16) = FixPoint3200 */
- sqr1 = (sqr1 + 0x8000) >> 16;
-
- /* FixPoint3200 * FixPoint3200 = FixPoint6400 */
- sqr1 *= sqr1;
-
- sqr2 = sigmaEstimateP2;
-
- /* (FixPoint1616 >> 16) = FixPoint3200 */
- sqr2 = (sqr2 + 0x8000) >> 16;
-
- /* FixPoint3200 * FixPoint3200 = FixPoint6400 */
- sqr2 *= sqr2;
-
- /* FixPoint64000 + FixPoint6400 = FixPoint6400 */
- sqrSum = sqr1 + sqr2;
-
- /* SQRT(FixPoin6400) = FixPoint3200 */
- sqrtResult_centi_ns = VL53L0X_isqrt(sqrSum);
-
- /* (FixPoint3200 << 16) = FixPoint1616 */
- sqrtResult_centi_ns <<= 16;
-
- /*
- * Note that the Speed Of Light is expressed in um per 1E-10
- * seconds (2997) Therefore to get mm/ns we have to divide by
- * 10000
- */
- sigmaEstRtn = (((sqrtResult_centi_ns+50)/100) /
- sigmaEstimateP3);
- sigmaEstRtn *= VL53L0X_SPEED_OF_LIGHT_IN_AIR;
-
- /* Add 5000 before dividing by 10000 to ensure rounding. */
- sigmaEstRtn += 5000;
- sigmaEstRtn /= 10000;
-
- if (sigmaEstRtn > cSigmaEstRtnMax) {
- /* Clip to prevent overflow. Will ensure safe
- * max result. */
- sigmaEstRtn = cSigmaEstRtnMax;
- }
- finalRangeIntegrationTimeMilliSecs =
- (finalRangeTimeoutMicroSecs + preRangeTimeoutMicroSecs + 500)/1000;
-
- /* sigmaEstRef = 1mm * 25ms/final range integration time (inc pre-range)
- * sqrt(FixPoint1616/int) = FixPoint2408)
- */
- sigmaEstRef =
- VL53L0X_isqrt((cDfltFinalRangeIntegrationTimeMilliSecs +
- finalRangeIntegrationTimeMilliSecs/2)/
- finalRangeIntegrationTimeMilliSecs);
-
- /* FixPoint2408 << 8 = FixPoint1616 */
- sigmaEstRef <<= 8;
- sigmaEstRef = (sigmaEstRef + 500)/1000;
-
- /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
- sqr1 = sigmaEstRtn * sigmaEstRtn;
- /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
- sqr2 = sigmaEstRef * sigmaEstRef;
-
- /* sqrt(FixPoint3232) = FixPoint1616 */
- sqrtResult = VL53L0X_isqrt((sqr1 + sqr2));
- /*
- * Note that the Shift by 4 bits increases resolution prior to
- * the sqrt, therefore the result must be shifted by 2 bits to
- * the right to revert back to the FixPoint1616 format.
- */
-
- sigmaEstimate = 1000 * sqrtResult;
-
- if ((peakSignalRate_kcps < 1) || (vcselTotalEventsRtn < 1) ||
- (sigmaEstimate > cSigmaEstMax)) {
- sigmaEstimate = cSigmaEstMax;
- }
-
- *pSigmaEstimate = (uint32_t)(sigmaEstimate);
- PALDevDataSet(Dev, SigmaEstimate, *pSigmaEstimate);
- Status = VL53L0X_calc_dmax(
- Dev,
- totalSignalRate_mcps,
- correctedSignalRate_mcps,
- pwMult,
- sigmaEstimateP1,
- sigmaEstimateP2,
- peakVcselDuration_us,
- pDmax_mm);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ x_talk_correction = diff1_mcps / diff2_mcps;
+
+ /* FixPoint2408 << 8 = FixPoint1616 */
+ x_talk_correction <<= 8;
+
+ if (p_ranging_measurement_data->RangeStatus != 0) {
+ pw_mult = 1 << 16;
+ } else {
+ /* FixPoint1616/uint32 = FixPoint1616 */
+ pw_mult = delta_t_ps / c_vcsel_pulse_width_ps; /* smaller than 1.0f */
+
+ /*
+ * FixPoint1616 * FixPoint1616 = FixPoint3232, however both
+ * values are small enough such that32 bits will not be
+ * exceeded.
+ */
+ pw_mult *= ((1 << 16) - x_talk_correction);
+
+ /* (FixPoint3232 >> 16) = FixPoint1616 */
+ pw_mult = (pw_mult + c_16bit_rounding_param) >> 16;
+
+ /* FixPoint1616 + FixPoint1616 = FixPoint1616 */
+ pw_mult += (1 << 16);
+
+ /*
+ * At this point the value will be 1.xx, therefore if we square
+ * the value this will exceed 32 bits. To address this perform
+ * a single shift to the right before the multiplication.
+ */
+ pw_mult >>= 1;
+ /* FixPoint1715 * FixPoint1715 = FixPoint3430 */
+ pw_mult = pw_mult * pw_mult;
+
+ /* (FixPoint3430 >> 14) = Fix1616 */
+ pw_mult >>= 14;
+ }
+
+ /* FixPoint1616 * uint32 = FixPoint1616 */
+ sqr1 = pw_mult * sigma_estimate_p1;
+
+ /* (FixPoint1616 >> 16) = FixPoint3200 */
+ sqr1 = (sqr1 + 0x8000) >> 16;
+
+ /* FixPoint3200 * FixPoint3200 = FixPoint6400 */
+ sqr1 *= sqr1;
+
+ sqr2 = sigma_estimate_p2;
+
+ /* (FixPoint1616 >> 16) = FixPoint3200 */
+ sqr2 = (sqr2 + 0x8000) >> 16;
+
+ /* FixPoint3200 * FixPoint3200 = FixPoint6400 */
+ sqr2 *= sqr2;
+
+ /* FixPoint64000 + FixPoint6400 = FixPoint6400 */
+ sqr_sum = sqr1 + sqr2;
+
+ /* SQRT(FixPoin6400) = FixPoint3200 */
+ sqrt_result_centi_ns = vl53l0x_isqrt(sqr_sum);
+
+ /* (FixPoint3200 << 16) = FixPoint1616 */
+ sqrt_result_centi_ns <<= 16;
+
+ /*
+ * Note that the Speed Of Light is expressed in um per 1E-10
+ * seconds (2997) Therefore to get mm/ns we have to divide by
+ * 10000
+ */
+ sigma_est_rtn = (((sqrt_result_centi_ns + 50) / 100) /
+ sigma_estimate_p3);
+ sigma_est_rtn *= VL53L0X_SPEED_OF_LIGHT_IN_AIR;
+
+ /* Add 5000 before dividing by 10000 to ensure rounding. */
+ sigma_est_rtn += 5000;
+ sigma_est_rtn /= 10000;
+
+ if (sigma_est_rtn > c_sigma_est_rtn_max) {
+ /* Clip to prevent overflow. Will ensure safe
+ * max result. */
+ sigma_est_rtn = c_sigma_est_rtn_max;
+ }
+ final_range_integration_time_milli_secs =
+ (final_range_timeout_micro_secs + pre_range_timeout_micro_secs + 500) / 1000;
+
+ /* sigmaEstRef = 1mm * 25ms/final range integration time (inc pre-range)
+ * sqrt(FixPoint1616/int) = FixPoint2408)
+ */
+ sigma_est_ref =
+ vl53l0x_isqrt((c_dflt_final_range_integration_time_milli_secs +
+ final_range_integration_time_milli_secs / 2) /
+ final_range_integration_time_milli_secs);
+
+ /* FixPoint2408 << 8 = FixPoint1616 */
+ sigma_est_ref <<= 8;
+ sigma_est_ref = (sigma_est_ref + 500) / 1000;
+
+ /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
+ sqr1 = sigma_est_rtn * sigma_est_rtn;
+ /* FixPoint1616 * FixPoint1616 = FixPoint3232 */
+ sqr2 = sigma_est_ref * sigma_est_ref;
+
+ /* sqrt(FixPoint3232) = FixPoint1616 */
+ sqrt_result = vl53l0x_isqrt((sqr1 + sqr2));
+ /*
+ * Note that the Shift by 4 bits increases resolution prior to
+ * the sqrt, therefore the result must be shifted by 2 bits to
+ * the right to revert back to the FixPoint1616 format.
+ */
+
+ sigma_estimate = 1000 * sqrt_result;
+
+ if ((peak_signal_rate_kcps < 1) || (vcsel_total_events_rtn < 1) ||
+ (sigma_estimate > c_sigma_est_max)) {
+ sigma_estimate = c_sigma_est_max;
+ }
+
+ *p_sigma_estimate = (uint32_t)(sigma_estimate);
+ PALDevDataSet(dev, SigmaEstimate, *p_sigma_estimate);
+ status = vl53l0x_calc_dmax(
+ dev,
+ total_signal_rate_mcps,
+ corrected_signal_rate_mcps,
+ pw_mult,
+ sigma_estimate_p1,
+ sigma_estimate_p2,
+ peak_vcsel_duration_us,
+ p_dmax_mm);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_get_pal_range_status(VL53L0X_DEV Dev,
- uint8_t DeviceRangeStatus,
- FixPoint1616_t SignalRate,
- uint16_t EffectiveSpadRtnCount,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
- uint8_t *pPalRangeStatus)
+VL53L0X_Error VL53L0X::vl53l0x_get_pal_range_status(VL53L0X_DEV dev,
+ uint8_t device_range_status,
+ FixPoint1616_t signal_rate,
+ uint16_t effective_spad_rtn_count,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
+ uint8_t *p_pal_range_status)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t NoneFlag;
- uint8_t SigmaLimitflag = 0;
- uint8_t SignalRefClipflag = 0;
- uint8_t RangeIgnoreThresholdflag = 0;
- uint8_t SigmaLimitCheckEnable = 0;
- uint8_t SignalRateFinalRangeLimitCheckEnable = 0;
- uint8_t SignalRefClipLimitCheckEnable = 0;
- uint8_t RangeIgnoreThresholdLimitCheckEnable = 0;
- FixPoint1616_t SigmaEstimate;
- FixPoint1616_t SigmaLimitValue;
- FixPoint1616_t SignalRefClipValue;
- FixPoint1616_t RangeIgnoreThresholdValue;
- FixPoint1616_t SignalRatePerSpad;
- uint8_t DeviceRangeStatusInternal = 0;
- uint16_t tmpWord = 0;
- uint8_t Temp8;
- uint32_t Dmax_mm = 0;
- FixPoint1616_t LastSignalRefMcps;
-
- LOG_FUNCTION_START("");
-
-
- /*
- * VL53L0X has a good ranging when the value of the
- * DeviceRangeStatus = 11. This function will replace the value 0 with
- * the value 11 in the DeviceRangeStatus.
- * In addition, the SigmaEstimator is not included in the VL53L0X
- * DeviceRangeStatus, this will be added in the PalRangeStatus.
- */
-
- DeviceRangeStatusInternal = ((DeviceRangeStatus & 0x78) >> 3);
-
- if (DeviceRangeStatusInternal == 0 ||
- DeviceRangeStatusInternal == 5 ||
- DeviceRangeStatusInternal == 7 ||
- DeviceRangeStatusInternal == 12 ||
- DeviceRangeStatusInternal == 13 ||
- DeviceRangeStatusInternal == 14 ||
- DeviceRangeStatusInternal == 15
- ) {
- NoneFlag = 1;
- } else {
- NoneFlag = 0;
- }
-
- /*
- * Check if Sigma limit is enabled, if yes then do comparison with limit
- * value and put the result back into pPalRangeStatus.
- */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_GetLimitCheckEnable(Dev,
- VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
- &SigmaLimitCheckEnable);
-
- if ((SigmaLimitCheckEnable != 0) && (Status == VL53L0X_ERROR_NONE)) {
- /*
- * compute the Sigma and check with limit
- */
- Status = VL53L0X_calc_sigma_estimate(
- Dev,
- pRangingMeasurementData,
- &SigmaEstimate,
- &Dmax_mm);
- if (Status == VL53L0X_ERROR_NONE)
- pRangingMeasurementData->RangeDMaxMilliMeter = Dmax_mm;
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_GetLimitCheckValue(Dev,
- VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
- &SigmaLimitValue);
-
- if ((SigmaLimitValue > 0) &&
- (SigmaEstimate > SigmaLimitValue))
- /* Limit Fail */
- SigmaLimitflag = 1;
- }
- }
-
- /*
- * Check if Signal ref clip limit is enabled, if yes then do comparison
- * with limit value and put the result back into pPalRangeStatus.
- */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_GetLimitCheckEnable(Dev,
- VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
- &SignalRefClipLimitCheckEnable);
-
- if ((SignalRefClipLimitCheckEnable != 0) &&
- (Status == VL53L0X_ERROR_NONE)) {
-
- Status = VL53L0X_GetLimitCheckValue(Dev,
- VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
- &SignalRefClipValue);
-
- /* Read LastSignalRefMcps from device */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_RdWord(Dev,
- VL53L0X_REG_RESULT_PEAK_SIGNAL_RATE_REF,
- &tmpWord);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x00);
-
- LastSignalRefMcps = VL53L0X_FIXPOINT97TOFIXPOINT1616(tmpWord);
- PALDevDataSet(Dev, LastSignalRefMcps, LastSignalRefMcps);
-
- if ((SignalRefClipValue > 0) &&
- (LastSignalRefMcps > SignalRefClipValue)) {
- /* Limit Fail */
- SignalRefClipflag = 1;
- }
- }
-
- /*
- * Check if Signal ref clip limit is enabled, if yes then do comparison
- * with limit value and put the result back into pPalRangeStatus.
- * EffectiveSpadRtnCount has a format 8.8
- * If (Return signal rate < (1.5 x Xtalk x number of Spads)) : FAIL
- */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_GetLimitCheckEnable(Dev,
- VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
- &RangeIgnoreThresholdLimitCheckEnable);
-
- if ((RangeIgnoreThresholdLimitCheckEnable != 0) &&
- (Status == VL53L0X_ERROR_NONE)) {
-
- /* Compute the signal rate per spad */
- if (EffectiveSpadRtnCount == 0) {
- SignalRatePerSpad = 0;
- } else {
- SignalRatePerSpad = (FixPoint1616_t)((256 * SignalRate)
- / EffectiveSpadRtnCount);
- }
-
- Status = VL53L0X_GetLimitCheckValue(Dev,
- VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
- &RangeIgnoreThresholdValue);
-
- if ((RangeIgnoreThresholdValue > 0) &&
- (SignalRatePerSpad < RangeIgnoreThresholdValue)) {
- /* Limit Fail add 2^6 to range status */
- RangeIgnoreThresholdflag = 1;
- }
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- if (NoneFlag == 1) {
- *pPalRangeStatus = 255; /* NONE */
- } else if (DeviceRangeStatusInternal == 1 ||
- DeviceRangeStatusInternal == 2 ||
- DeviceRangeStatusInternal == 3) {
- *pPalRangeStatus = 5; /* HW fail */
- } else if (DeviceRangeStatusInternal == 6 ||
- DeviceRangeStatusInternal == 9) {
- *pPalRangeStatus = 4; /* Phase fail */
- } else if (DeviceRangeStatusInternal == 8 ||
- DeviceRangeStatusInternal == 10 ||
- SignalRefClipflag == 1) {
- *pPalRangeStatus = 3; /* Min range */
- } else if (DeviceRangeStatusInternal == 4 ||
- RangeIgnoreThresholdflag == 1) {
- *pPalRangeStatus = 2; /* Signal Fail */
- } else if (SigmaLimitflag == 1) {
- *pPalRangeStatus = 1; /* Sigma Fail */
- } else {
- *pPalRangeStatus = 0; /* Range Valid */
- }
- }
-
- /* DMAX only relevant during range error */
- if (*pPalRangeStatus == 0)
- pRangingMeasurementData->RangeDMaxMilliMeter = 0;
-
- /* fill the Limit Check Status */
-
- Status = VL53L0X_GetLimitCheckEnable(Dev,
- VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
- &SignalRateFinalRangeLimitCheckEnable);
-
- if (Status == VL53L0X_ERROR_NONE) {
- if ((SigmaLimitCheckEnable == 0) || (SigmaLimitflag == 1))
- Temp8 = 1;
- else
- Temp8 = 0;
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
- VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, Temp8);
-
- if ((DeviceRangeStatusInternal == 4) ||
- (SignalRateFinalRangeLimitCheckEnable == 0))
- Temp8 = 1;
- else
- Temp8 = 0;
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
- VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
- Temp8);
-
- if ((SignalRefClipLimitCheckEnable == 0) ||
- (SignalRefClipflag == 1))
- Temp8 = 1;
- else
- Temp8 = 0;
-
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
- VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP, Temp8);
-
- if ((RangeIgnoreThresholdLimitCheckEnable == 0) ||
- (RangeIgnoreThresholdflag == 1))
- Temp8 = 1;
- else
- Temp8 = 0;
-
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
- VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
- Temp8);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t none_flag;
+ uint8_t sigma_limitflag = 0;
+ uint8_t signal_ref_clipflag = 0;
+ uint8_t range_ignore_thresholdflag = 0;
+ uint8_t sigma_limit_check_enable = 0;
+ uint8_t signal_rate_final_range_limit_check_enable = 0;
+ uint8_t signal_ref_clip_limit_check_enable = 0;
+ uint8_t range_ignore_threshold_limit_check_enable = 0;
+ FixPoint1616_t sigma_estimate;
+ FixPoint1616_t sigma_limit_value;
+ FixPoint1616_t signal_ref_clip_value;
+ FixPoint1616_t range_ignore_threshold_value;
+ FixPoint1616_t signal_rate_per_spad;
+ uint8_t device_range_status_internal = 0;
+ uint16_t tmp_word = 0;
+ uint8_t temp8;
+ uint32_t dmax_mm = 0;
+ FixPoint1616_t last_signal_ref_mcps;
+
+ LOG_FUNCTION_START("");
+
+
+ /*
+ * VL53L0X has a good ranging when the value of the
+ * DeviceRangeStatus = 11. This function will replace the value 0 with
+ * the value 11 in the DeviceRangeStatus.
+ * In addition, the SigmaEstimator is not included in the VL53L0X
+ * DeviceRangeStatus, this will be added in the PalRangeStatus.
+ */
+
+ device_range_status_internal = ((device_range_status & 0x78) >> 3);
+
+ if (device_range_status_internal == 0 ||
+ device_range_status_internal == 5 ||
+ device_range_status_internal == 7 ||
+ device_range_status_internal == 12 ||
+ device_range_status_internal == 13 ||
+ device_range_status_internal == 14 ||
+ device_range_status_internal == 15
+ ) {
+ none_flag = 1;
+ } else {
+ none_flag = 0;
+ }
+
+ /*
+ * Check if Sigma limit is enabled, if yes then do comparison with limit
+ * value and put the result back into pPalRangeStatus.
+ */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_get_limit_check_enable(dev,
+ VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &sigma_limit_check_enable);
+
+ if ((sigma_limit_check_enable != 0) && (status == VL53L0X_ERROR_NONE)) {
+ /*
+ * compute the Sigma and check with limit
+ */
+ status = vl53l0x_calc_sigma_estimate(
+ dev,
+ p_ranging_measurement_data,
+ &sigma_estimate,
+ &dmax_mm);
+ if (status == VL53L0X_ERROR_NONE)
+ p_ranging_measurement_data->RangeDMaxMilliMeter = dmax_mm;
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_get_limit_check_value(dev,
+ VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &sigma_limit_value);
+
+ if ((sigma_limit_value > 0) &&
+ (sigma_estimate > sigma_limit_value))
+ /* Limit Fail */
+ sigma_limitflag = 1;
+ }
+ }
+
+ /*
+ * Check if Signal ref clip limit is enabled, if yes then do comparison
+ * with limit value and put the result back into pPalRangeStatus.
+ */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_get_limit_check_enable(dev,
+ VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
+ &signal_ref_clip_limit_check_enable);
+
+ if ((signal_ref_clip_limit_check_enable != 0) &&
+ (status == VL53L0X_ERROR_NONE)) {
+
+ status = vl53l0x_get_limit_check_value(dev,
+ VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
+ &signal_ref_clip_value);
+
+ /* Read LastSignalRefMcps from device */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev, 0xFF, 0x01);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_read_word(dev,
+ VL53L0X_REG_RESULT_PEAK_SIGNAL_RATE_REF,
+ &tmp_word);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev, 0xFF, 0x00);
+
+ last_signal_ref_mcps = VL53L0X_FIXPOINT97TOFIXPOINT1616(tmp_word);
+ PALDevDataSet(dev, LastSignalRefMcps, last_signal_ref_mcps);
+
+ if ((signal_ref_clip_value > 0) &&
+ (last_signal_ref_mcps > signal_ref_clip_value)) {
+ /* Limit Fail */
+ signal_ref_clipflag = 1;
+ }
+ }
+
+ /*
+ * Check if Signal ref clip limit is enabled, if yes then do comparison
+ * with limit value and put the result back into pPalRangeStatus.
+ * EffectiveSpadRtnCount has a format 8.8
+ * If (Return signal rate < (1.5 x Xtalk x number of Spads)) : FAIL
+ */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_get_limit_check_enable(dev,
+ VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ &range_ignore_threshold_limit_check_enable);
+
+ if ((range_ignore_threshold_limit_check_enable != 0) &&
+ (status == VL53L0X_ERROR_NONE)) {
+
+ /* Compute the signal rate per spad */
+ if (effective_spad_rtn_count == 0) {
+ signal_rate_per_spad = 0;
+ } else {
+ signal_rate_per_spad = (FixPoint1616_t)((256 * signal_rate)
+ / effective_spad_rtn_count);
+ }
+
+ status = vl53l0x_get_limit_check_value(dev,
+ VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ &range_ignore_threshold_value);
+
+ if ((range_ignore_threshold_value > 0) &&
+ (signal_rate_per_spad < range_ignore_threshold_value)) {
+ /* Limit Fail add 2^6 to range status */
+ range_ignore_thresholdflag = 1;
+ }
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ if (none_flag == 1) {
+ *p_pal_range_status = 255; /* NONE */
+ } else if (device_range_status_internal == 1 ||
+ device_range_status_internal == 2 ||
+ device_range_status_internal == 3) {
+ *p_pal_range_status = 5; /* HW fail */
+ } else if (device_range_status_internal == 6 ||
+ device_range_status_internal == 9) {
+ *p_pal_range_status = 4; /* Phase fail */
+ } else if (device_range_status_internal == 8 ||
+ device_range_status_internal == 10 ||
+ signal_ref_clipflag == 1) {
+ *p_pal_range_status = 3; /* Min range */
+ } else if (device_range_status_internal == 4 ||
+ range_ignore_thresholdflag == 1) {
+ *p_pal_range_status = 2; /* Signal Fail */
+ } else if (sigma_limitflag == 1) {
+ *p_pal_range_status = 1; /* Sigma Fail */
+ } else {
+ *p_pal_range_status = 0; /* Range Valid */
+ }
+ }
+
+ /* DMAX only relevant during range error */
+ if (*p_pal_range_status == 0)
+ p_ranging_measurement_data->RangeDMaxMilliMeter = 0;
+
+ /* fill the Limit Check Status */
+
+ status = vl53l0x_get_limit_check_enable(dev,
+ VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &signal_rate_final_range_limit_check_enable);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ if ((sigma_limit_check_enable == 0) || (sigma_limitflag == 1))
+ temp8 = 1;
+ else
+ temp8 = 0;
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksStatus,
+ VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, temp8);
+
+ if ((device_range_status_internal == 4) ||
+ (signal_rate_final_range_limit_check_enable == 0))
+ temp8 = 1;
+ else
+ temp8 = 0;
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksStatus,
+ VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ temp8);
+
+ if ((signal_ref_clip_limit_check_enable == 0) ||
+ (signal_ref_clipflag == 1))
+ temp8 = 1;
+ else
+ temp8 = 0;
+
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksStatus,
+ VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP, temp8);
+
+ if ((range_ignore_threshold_limit_check_enable == 0) ||
+ (range_ignore_thresholdflag == 1))
+ temp8 = 1;
+ else
+ temp8 = 0;
+
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksStatus,
+ VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ temp8);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetRangingMeasurementData(VL53L0X_DEV Dev,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData)
+VL53L0X_Error VL53L0X::vl53l0x_get_ranging_measurement_data(VL53L0X_DEV dev,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t DeviceRangeStatus;
- uint8_t RangeFractionalEnable;
- uint8_t PalRangeStatus;
- uint8_t XTalkCompensationEnable;
- uint16_t AmbientRate;
- FixPoint1616_t SignalRate;
- uint16_t XTalkCompensationRateMegaCps;
- uint16_t EffectiveSpadRtnCount;
- uint16_t tmpuint16;
- uint16_t XtalkRangeMilliMeter;
- uint16_t LinearityCorrectiveGain;
- uint8_t localBuffer[12];
- VL53L0X_RangingMeasurementData_t LastRangeDataBuffer;
-
- LOG_FUNCTION_START("");
-
- /*
- * use multi read even if some registers are not useful, result will
- * be more efficient
- * start reading at 0x14 dec20
- * end reading at 0x21 dec33 total 14 bytes to read
- */
- Status = VL53L0X_ReadMulti(Dev, 0x14, localBuffer, 12);
-
- if (Status == VL53L0X_ERROR_NONE) {
-
- pRangingMeasurementData->ZoneId = 0; /* Only one zone */
- pRangingMeasurementData->TimeStamp = 0; /* Not Implemented */
-
- tmpuint16 = VL53L0X_MAKEUINT16(localBuffer[11], localBuffer[10]);
- /* cut1.1 if SYSTEM__RANGE_CONFIG if 1 range is 2bits fractional
- *(format 11.2) else no fractional
- */
-
- pRangingMeasurementData->MeasurementTimeUsec = 0;
-
- SignalRate = VL53L0X_FIXPOINT97TOFIXPOINT1616(
- VL53L0X_MAKEUINT16(localBuffer[7], localBuffer[6]));
- /* peak_signal_count_rate_rtn_mcps */
- pRangingMeasurementData->SignalRateRtnMegaCps = SignalRate;
-
- AmbientRate = VL53L0X_MAKEUINT16(localBuffer[9], localBuffer[8]);
- pRangingMeasurementData->AmbientRateRtnMegaCps =
- VL53L0X_FIXPOINT97TOFIXPOINT1616(AmbientRate);
-
- EffectiveSpadRtnCount = VL53L0X_MAKEUINT16(localBuffer[3],
- localBuffer[2]);
- /* EffectiveSpadRtnCount is 8.8 format */
- pRangingMeasurementData->EffectiveSpadRtnCount =
- EffectiveSpadRtnCount;
-
- DeviceRangeStatus = localBuffer[0];
-
- /* Get Linearity Corrective Gain */
- LinearityCorrectiveGain = PALDevDataGet(Dev,
- LinearityCorrectiveGain);
-
- /* Get ranging configuration */
- RangeFractionalEnable = PALDevDataGet(Dev,
- RangeFractionalEnable);
-
- if (LinearityCorrectiveGain != 1000) {
-
- tmpuint16 = (uint16_t)((LinearityCorrectiveGain
- * tmpuint16 + 500) / 1000);
-
- /* Implement Xtalk */
- VL53L0X_GETPARAMETERFIELD(Dev,
- XTalkCompensationRateMegaCps,
- XTalkCompensationRateMegaCps);
- VL53L0X_GETPARAMETERFIELD(Dev, XTalkCompensationEnable,
- XTalkCompensationEnable);
-
- if (XTalkCompensationEnable) {
-
- if ((SignalRate
- - ((XTalkCompensationRateMegaCps
- * EffectiveSpadRtnCount) >> 8))
- <= 0) {
- if (RangeFractionalEnable)
- XtalkRangeMilliMeter = 8888;
- else
- XtalkRangeMilliMeter = 8888
- << 2;
- } else {
- XtalkRangeMilliMeter =
- (tmpuint16 * SignalRate)
- / (SignalRate
- - ((XTalkCompensationRateMegaCps
- * EffectiveSpadRtnCount)
- >> 8));
- }
-
- tmpuint16 = XtalkRangeMilliMeter;
- }
-
- }
-
- if (RangeFractionalEnable) {
- pRangingMeasurementData->RangeMilliMeter =
- (uint16_t)((tmpuint16) >> 2);
- pRangingMeasurementData->RangeFractionalPart =
- (uint8_t)((tmpuint16 & 0x03) << 6);
- } else {
- pRangingMeasurementData->RangeMilliMeter = tmpuint16;
- pRangingMeasurementData->RangeFractionalPart = 0;
- }
-
- /*
- * For a standard definition of RangeStatus, this should
- * return 0 in case of good result after a ranging
- * The range status depends on the device so call a device
- * specific function to obtain the right Status.
- */
- Status |= VL53L0X_get_pal_range_status(Dev, DeviceRangeStatus,
- SignalRate, EffectiveSpadRtnCount,
- pRangingMeasurementData, &PalRangeStatus);
-
- if (Status == VL53L0X_ERROR_NONE)
- pRangingMeasurementData->RangeStatus = PalRangeStatus;
-
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- /* Copy last read data into Dev buffer */
- LastRangeDataBuffer = PALDevDataGet(Dev, LastRangeMeasure);
-
- LastRangeDataBuffer.RangeMilliMeter =
- pRangingMeasurementData->RangeMilliMeter;
- LastRangeDataBuffer.RangeFractionalPart =
- pRangingMeasurementData->RangeFractionalPart;
- LastRangeDataBuffer.RangeDMaxMilliMeter =
- pRangingMeasurementData->RangeDMaxMilliMeter;
- LastRangeDataBuffer.MeasurementTimeUsec =
- pRangingMeasurementData->MeasurementTimeUsec;
- LastRangeDataBuffer.SignalRateRtnMegaCps =
- pRangingMeasurementData->SignalRateRtnMegaCps;
- LastRangeDataBuffer.AmbientRateRtnMegaCps =
- pRangingMeasurementData->AmbientRateRtnMegaCps;
- LastRangeDataBuffer.EffectiveSpadRtnCount =
- pRangingMeasurementData->EffectiveSpadRtnCount;
- LastRangeDataBuffer.RangeStatus =
- pRangingMeasurementData->RangeStatus;
-
- PALDevDataSet(Dev, LastRangeMeasure, LastRangeDataBuffer);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t device_range_status;
+ uint8_t range_fractional_enable;
+ uint8_t pal_range_status;
+ uint8_t x_talk_compensation_enable;
+ uint16_t ambient_rate;
+ FixPoint1616_t signal_rate;
+ uint16_t x_talk_compensation_rate_mega_cps;
+ uint16_t effective_spad_rtn_count;
+ uint16_t tmpuint16;
+ uint16_t xtalk_range_milli_meter;
+ uint16_t linearity_corrective_gain;
+ uint8_t localBuffer[12];
+ VL53L0X_RangingMeasurementData_t last_range_data_buffer;
+
+ LOG_FUNCTION_START("");
+
+ /*
+ * use multi read even if some registers are not useful, result will
+ * be more efficient
+ * start reading at 0x14 dec20
+ * end reading at 0x21 dec33 total 14 bytes to read
+ */
+ status = vl53l0x_read_multi(dev, 0x14, localBuffer, 12);
+
+ if (status == VL53L0X_ERROR_NONE) {
+
+ p_ranging_measurement_data->ZoneId = 0; /* Only one zone */
+ p_ranging_measurement_data->TimeStamp = 0; /* Not Implemented */
+
+ tmpuint16 = VL53L0X_MAKEUINT16(localBuffer[11], localBuffer[10]);
+ /* cut1.1 if SYSTEM__RANGE_CONFIG if 1 range is 2bits fractional
+ *(format 11.2) else no fractional
+ */
+
+ p_ranging_measurement_data->MeasurementTimeUsec = 0;
+
+ signal_rate = VL53L0X_FIXPOINT97TOFIXPOINT1616(
+ VL53L0X_MAKEUINT16(localBuffer[7], localBuffer[6]));
+ /* peak_signal_count_rate_rtn_mcps */
+ p_ranging_measurement_data->SignalRateRtnMegaCps = signal_rate;
+
+ ambient_rate = VL53L0X_MAKEUINT16(localBuffer[9], localBuffer[8]);
+ p_ranging_measurement_data->AmbientRateRtnMegaCps =
+ VL53L0X_FIXPOINT97TOFIXPOINT1616(ambient_rate);
+
+ effective_spad_rtn_count = VL53L0X_MAKEUINT16(localBuffer[3],
+ localBuffer[2]);
+ /* EffectiveSpadRtnCount is 8.8 format */
+ p_ranging_measurement_data->EffectiveSpadRtnCount =
+ effective_spad_rtn_count;
+
+ device_range_status = localBuffer[0];
+
+ /* Get Linearity Corrective Gain */
+ linearity_corrective_gain = PALDevDataGet(dev,
+ LinearityCorrectiveGain);
+
+ /* Get ranging configuration */
+ range_fractional_enable = PALDevDataGet(dev,
+ RangeFractionalEnable);
+
+ if (linearity_corrective_gain != 1000) {
+
+ tmpuint16 = (uint16_t)((linearity_corrective_gain
+ * tmpuint16 + 500) / 1000);
+
+ /* Implement Xtalk */
+ VL53L0X_GETPARAMETERFIELD(dev,
+ XTalkCompensationRateMegaCps,
+ x_talk_compensation_rate_mega_cps);
+ VL53L0X_GETPARAMETERFIELD(dev, XTalkCompensationEnable,
+ x_talk_compensation_enable);
+
+ if (x_talk_compensation_enable) {
+
+ if ((signal_rate
+ - ((x_talk_compensation_rate_mega_cps
+ * effective_spad_rtn_count) >> 8))
+ <= 0) {
+ if (range_fractional_enable)
+ xtalk_range_milli_meter = 8888;
+ else
+ xtalk_range_milli_meter = 8888
+ << 2;
+ } else {
+ xtalk_range_milli_meter =
+ (tmpuint16 * signal_rate)
+ / (signal_rate
+ - ((x_talk_compensation_rate_mega_cps
+ * effective_spad_rtn_count)
+ >> 8));
+ }
+
+ tmpuint16 = xtalk_range_milli_meter;
+ }
+
+ }
+
+ if (range_fractional_enable) {
+ p_ranging_measurement_data->RangeMilliMeter =
+ (uint16_t)((tmpuint16) >> 2);
+ p_ranging_measurement_data->RangeFractionalPart =
+ (uint8_t)((tmpuint16 & 0x03) << 6);
+ } else {
+ p_ranging_measurement_data->RangeMilliMeter = tmpuint16;
+ p_ranging_measurement_data->RangeFractionalPart = 0;
+ }
+
+ /*
+ * For a standard definition of RangeStatus, this should
+ * return 0 in case of good result after a ranging
+ * The range status depends on the device so call a device
+ * specific function to obtain the right Status.
+ */
+ status |= vl53l0x_get_pal_range_status(dev, device_range_status,
+ signal_rate, effective_spad_rtn_count,
+ p_ranging_measurement_data, &pal_range_status);
+
+ if (status == VL53L0X_ERROR_NONE)
+ p_ranging_measurement_data->RangeStatus = pal_range_status;
+
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ /* Copy last read data into Dev buffer */
+ last_range_data_buffer = PALDevDataGet(dev, LastRangeMeasure);
+
+ last_range_data_buffer.RangeMilliMeter =
+ p_ranging_measurement_data->RangeMilliMeter;
+ last_range_data_buffer.RangeFractionalPart =
+ p_ranging_measurement_data->RangeFractionalPart;
+ last_range_data_buffer.RangeDMaxMilliMeter =
+ p_ranging_measurement_data->RangeDMaxMilliMeter;
+ last_range_data_buffer.MeasurementTimeUsec =
+ p_ranging_measurement_data->MeasurementTimeUsec;
+ last_range_data_buffer.SignalRateRtnMegaCps =
+ p_ranging_measurement_data->SignalRateRtnMegaCps;
+ last_range_data_buffer.AmbientRateRtnMegaCps =
+ p_ranging_measurement_data->AmbientRateRtnMegaCps;
+ last_range_data_buffer.EffectiveSpadRtnCount =
+ p_ranging_measurement_data->EffectiveSpadRtnCount;
+ last_range_data_buffer.RangeStatus =
+ p_ranging_measurement_data->RangeStatus;
+
+ PALDevDataSet(dev, LastRangeMeasure, last_range_data_buffer);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_PerformSingleRangingMeasurement(VL53L0X_DEV Dev,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData)
+VL53L0X_Error VL53L0X::vl53l0x_perform_single_ranging_measurement(VL53L0X_DEV dev,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
-
- LOG_FUNCTION_START("");
-
- /* This function will do a complete single ranging
- * Here we fix the mode! */
- Status = VL53L0X_SetDeviceMode(Dev, VL53L0X_DEVICEMODE_SINGLE_RANGING);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_PerformSingleMeasurement(Dev);
-
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_GetRangingMeasurementData(Dev,
- pRangingMeasurementData);
-
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_ClearInterruptMask(Dev, 0);
-
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ /* This function will do a complete single ranging
+ * Here we fix the mode! */
+ status = vl53l0x_set_device_mode(dev, VL53L0X_DEVICEMODE_SINGLE_RANGING);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_perform_single_measurement(dev);
+
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_get_ranging_measurement_data(dev,
+ p_ranging_measurement_data);
+
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_clear_interrupt_mask(dev, 0);
+
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::perform_ref_signal_measurement(VL53L0X_DEV Dev,
- uint16_t *refSignalRate)
+VL53L0X_Error VL53L0X::perform_ref_signal_measurement(VL53L0X_DEV dev,
+ uint16_t *p_ref_signal_rate)
{
- VL53L0X_Error status = VL53L0X_ERROR_NONE;
- VL53L0X_RangingMeasurementData_t rangingMeasurementData;
-
- uint8_t SequenceConfig = 0;
-
- /* store the value of the sequence config,
- * this will be reset before the end of the function
- */
-
- SequenceConfig = PALDevDataGet(Dev, SequenceConfig);
-
- /*
- * This function performs a reference signal rate measurement.
- */
- if (status == VL53L0X_ERROR_NONE)
- status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, 0xC0);
-
- if (status == VL53L0X_ERROR_NONE)
- status = VL53L0X_PerformSingleRangingMeasurement(Dev,
- &rangingMeasurementData);
-
- if (status == VL53L0X_ERROR_NONE)
- status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
-
- if (status == VL53L0X_ERROR_NONE)
- status = VL53L0X_RdWord(Dev,
- VL53L0X_REG_RESULT_PEAK_SIGNAL_RATE_REF,
- refSignalRate);
-
- if (status == VL53L0X_ERROR_NONE)
- status = VL53L0X_WrByte(Dev, 0xFF, 0x00);
-
- if (status == VL53L0X_ERROR_NONE) {
- /* restore the previous Sequence Config */
- status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
- SequenceConfig);
- if (status == VL53L0X_ERROR_NONE)
- PALDevDataSet(Dev, SequenceConfig, SequenceConfig);
- }
-
- return status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ VL53L0X_RangingMeasurementData_t ranging_measurement_data;
+
+ uint8_t sequence_config = 0;
+
+ /* store the value of the sequence config,
+ * this will be reset before the end of the function
+ */
+
+ sequence_config = PALDevDataGet(dev, SequenceConfig);
+
+ /*
+ * This function performs a reference signal rate measurement.
+ */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, 0xC0);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_perform_single_ranging_measurement(dev,
+ &ranging_measurement_data);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev, 0xFF, 0x01);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_read_word(dev,
+ VL53L0X_REG_RESULT_PEAK_SIGNAL_RATE_REF,
+ p_ref_signal_rate);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev, 0xFF, 0x00);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ /* restore the previous Sequence Config */
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
+ sequence_config);
+ if (status == VL53L0X_ERROR_NONE)
+ PALDevDataSet(dev, SequenceConfig, sequence_config);
+ }
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_perform_ref_spad_management(VL53L0X_DEV Dev,
- uint32_t *refSpadCount,
- uint8_t *isApertureSpads)
+VL53L0X_Error VL53L0X::wrapped_vl53l0x_perform_ref_spad_management(VL53L0X_DEV dev,
+ uint32_t *ref_spad_count,
+ uint8_t *is_aperture_spads)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t lastSpadArray[6];
- uint8_t startSelect = 0xB4;
- uint32_t minimumSpadCount = 3;
- uint32_t maxSpadCount = 44;
- uint32_t currentSpadIndex = 0;
- uint32_t lastSpadIndex = 0;
- int32_t nextGoodSpad = 0;
- uint16_t targetRefRate = 0x0A00; /* 20 MCPS in 9:7 format */
- uint16_t peakSignalRateRef;
- uint32_t needAptSpads = 0;
- uint32_t index = 0;
- uint32_t spadArraySize = 6;
- uint32_t signalRateDiff = 0;
- uint32_t lastSignalRateDiff = 0;
- uint8_t complete = 0;
- uint8_t VhvSettings = 0;
- uint8_t PhaseCal = 0;
- uint32_t refSpadCount_int = 0;
- uint8_t isApertureSpads_int = 0;
-
- /*
- * The reference SPAD initialization procedure determines the minimum
- * amount of reference spads to be enables to achieve a target reference
- * signal rate and should be performed once during initialization.
- *
- * Either aperture or non-aperture spads are applied but never both.
- * Firstly non-aperture spads are set, begining with 5 spads, and
- * increased one spad at a time until the closest measurement to the
- * target rate is achieved.
- *
- * If the target rate is exceeded when 5 non-aperture spads are enabled,
- * initialization is performed instead with aperture spads.
- *
- * When setting spads, a 'Good Spad Map' is applied.
- *
- * This procedure operates within a SPAD window of interest of a maximum
- * 44 spads.
- * The start point is currently fixed to 180, which lies towards the end
- * of the non-aperture quadrant and runs in to the adjacent aperture
- * quadrant.
- */
-
-
- targetRefRate = PALDevDataGet(Dev, targetRefRate);
-
- /*
- * Initialize Spad arrays.
- * Currently the good spad map is initialised to 'All good'.
- * This is a short term implementation. The good spad map will be
- * provided as an input.
- * Note that there are 6 bytes. Only the first 44 bits will be used to
- * represent spads.
- */
- for (index = 0; index < spadArraySize; index++)
- Dev->Data.SpadData.RefSpadEnables[index] = 0;
-
-
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_DYNAMIC_SPAD_REF_EN_START_OFFSET, 0x00);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD, 0x2C);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x00);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_GLOBAL_CONFIG_REF_EN_START_SELECT,
- startSelect);
-
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_POWER_MANAGEMENT_GO1_POWER_FORCE, 0);
-
- /* Perform ref calibration */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_perform_ref_calibration(Dev, &VhvSettings,
- &PhaseCal, 0);
-
- if (Status == VL53L0X_ERROR_NONE) {
- /* Enable Minimum NON-APERTURE Spads */
- currentSpadIndex = 0;
- lastSpadIndex = currentSpadIndex;
- needAptSpads = 0;
- Status = enable_ref_spads(Dev,
- needAptSpads,
- Dev->Data.SpadData.RefGoodSpadMap,
- Dev->Data.SpadData.RefSpadEnables,
- spadArraySize,
- startSelect,
- currentSpadIndex,
- minimumSpadCount,
- &lastSpadIndex);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- currentSpadIndex = lastSpadIndex;
-
- Status = perform_ref_signal_measurement(Dev,
- &peakSignalRateRef);
- if ((Status == VL53L0X_ERROR_NONE) &&
- (peakSignalRateRef > targetRefRate)) {
- /* Signal rate measurement too high,
- * switch to APERTURE SPADs */
-
- for (index = 0; index < spadArraySize; index++)
- Dev->Data.SpadData.RefSpadEnables[index] = 0;
-
-
- /* Increment to the first APERTURE spad */
- while ((is_aperture(startSelect + currentSpadIndex)
- == 0) && (currentSpadIndex < maxSpadCount)) {
- currentSpadIndex++;
- }
-
- needAptSpads = 1;
-
- Status = enable_ref_spads(Dev,
- needAptSpads,
- Dev->Data.SpadData.RefGoodSpadMap,
- Dev->Data.SpadData.RefSpadEnables,
- spadArraySize,
- startSelect,
- currentSpadIndex,
- minimumSpadCount,
- &lastSpadIndex);
-
- if (Status == VL53L0X_ERROR_NONE) {
- currentSpadIndex = lastSpadIndex;
- Status = perform_ref_signal_measurement(Dev,
- &peakSignalRateRef);
-
- if ((Status == VL53L0X_ERROR_NONE) &&
- (peakSignalRateRef > targetRefRate)) {
- /* Signal rate still too high after
- * setting the minimum number of
- * APERTURE spads. Can do no more
- * therefore set the min number of
- * aperture spads as the result.
- */
- isApertureSpads_int = 1;
- refSpadCount_int = minimumSpadCount;
- }
- }
- } else {
- needAptSpads = 0;
- }
- }
-
- if ((Status == VL53L0X_ERROR_NONE) &&
- (peakSignalRateRef < targetRefRate)) {
- /* At this point, the minimum number of either aperture
- * or non-aperture spads have been set. Proceed to add
- * spads and perform measurements until the target
- * reference is reached.
- */
- isApertureSpads_int = needAptSpads;
- refSpadCount_int = minimumSpadCount;
-
- memcpy(lastSpadArray, Dev->Data.SpadData.RefSpadEnables,
- spadArraySize);
- lastSignalRateDiff = abs(peakSignalRateRef -
- targetRefRate);
- complete = 0;
-
- while (!complete) {
- get_next_good_spad(
- Dev->Data.SpadData.RefGoodSpadMap,
- spadArraySize, currentSpadIndex,
- &nextGoodSpad);
-
- if (nextGoodSpad == -1) {
- Status = VL53L0X_ERROR_REF_SPAD_INIT;
- break;
- }
-
- /* Cannot combine Aperture and Non-Aperture spads, so
- * ensure the current spad is of the correct type.
- */
- if (is_aperture((uint32_t)startSelect + nextGoodSpad) !=
- needAptSpads) {
- /* At this point we have enabled the maximum
- * number of Aperture spads.
- */
- complete = 1;
- break;
- }
-
- (refSpadCount_int)++;
-
- currentSpadIndex = nextGoodSpad;
- Status = enable_spad_bit(
- Dev->Data.SpadData.RefSpadEnables,
- spadArraySize, currentSpadIndex);
-
- if (Status == VL53L0X_ERROR_NONE) {
- currentSpadIndex++;
- /* Proceed to apply the additional spad and
- * perform measurement. */
- Status = set_ref_spad_map(Dev,
- Dev->Data.SpadData.RefSpadEnables);
- }
-
- if (Status != VL53L0X_ERROR_NONE)
- break;
-
- Status = perform_ref_signal_measurement(Dev,
- &peakSignalRateRef);
-
- if (Status != VL53L0X_ERROR_NONE)
- break;
-
- signalRateDiff = abs(peakSignalRateRef - targetRefRate);
-
- if (peakSignalRateRef > targetRefRate) {
- /* Select the spad map that provides the
- * measurement closest to the target rate,
- * either above or below it.
- */
- if (signalRateDiff > lastSignalRateDiff) {
- /* Previous spad map produced a closer
- * measurement, so choose this. */
- Status = set_ref_spad_map(Dev,
- lastSpadArray);
- memcpy(
- Dev->Data.SpadData.RefSpadEnables,
- lastSpadArray, spadArraySize);
-
- (refSpadCount_int)--;
- }
- complete = 1;
- } else {
- /* Continue to add spads */
- lastSignalRateDiff = signalRateDiff;
- memcpy(lastSpadArray,
- Dev->Data.SpadData.RefSpadEnables,
- spadArraySize);
- }
-
- } /* while */
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- *refSpadCount = refSpadCount_int;
- *isApertureSpads = isApertureSpads_int;
-
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, RefSpadsInitialised, 1);
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- ReferenceSpadCount, (uint8_t)(*refSpadCount));
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- ReferenceSpadType, *isApertureSpads);
- }
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t last_spad_array[6];
+ uint8_t start_select = 0xB4;
+ uint32_t minimum_spad_count = 3;
+ uint32_t max_spad_count = 44;
+ uint32_t current_spad_index = 0;
+ uint32_t last_spad_index = 0;
+ int32_t next_good_spad = 0;
+ uint16_t target_ref_rate = 0x0A00; /* 20 MCPS in 9:7 format */
+ uint16_t peak_signal_rate_ref;
+ uint32_t need_apt_spads = 0;
+ uint32_t index = 0;
+ uint32_t spad_array_size = 6;
+ uint32_t signal_rate_diff = 0;
+ uint32_t last_signal_rate_diff = 0;
+ uint8_t complete = 0;
+ uint8_t vhv_settings = 0;
+ uint8_t phase_cal = 0;
+ uint32_t ref_spad_count_int = 0;
+ uint8_t is_aperture_spads_int = 0;
+
+ /*
+ * The reference SPAD initialization procedure determines the minimum
+ * amount of reference spads to be enables to achieve a target reference
+ * signal rate and should be performed once during initialization.
+ *
+ * Either aperture or non-aperture spads are applied but never both.
+ * Firstly non-aperture spads are set, begining with 5 spads, and
+ * increased one spad at a time until the closest measurement to the
+ * target rate is achieved.
+ *
+ * If the target rate is exceeded when 5 non-aperture spads are enabled,
+ * initialization is performed instead with aperture spads.
+ *
+ * When setting spads, a 'Good Spad Map' is applied.
+ *
+ * This procedure operates within a SPAD window of interest of a maximum
+ * 44 spads.
+ * The start point is currently fixed to 180, which lies towards the end
+ * of the non-aperture quadrant and runs in to the adjacent aperture
+ * quadrant.
+ */
+
+
+ target_ref_rate = PALDevDataGet(dev, targetRefRate);
+
+ /*
+ * Initialize Spad arrays.
+ * Currently the good spad map is initialised to 'All good'.
+ * This is a short term implementation. The good spad map will be
+ * provided as an input.
+ * Note that there are 6 bytes. Only the first 44 bits will be used to
+ * represent spads.
+ */
+ for (index = 0; index < spad_array_size; index++)
+ dev->Data.SpadData.RefSpadEnables[index] = 0;
+
+
+ status = vl53l0x_write_byte(dev, 0xFF, 0x01);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_DYNAMIC_SPAD_REF_EN_START_OFFSET, 0x00);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD, 0x2C);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev, 0xFF, 0x00);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_GLOBAL_CONFIG_REF_EN_START_SELECT,
+ start_select);
+
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_POWER_MANAGEMENT_GO1_POWER_FORCE, 0);
+
+ /* Perform ref calibration */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_perform_ref_calibration(dev, &vhv_settings,
+ &phase_cal, 0);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ /* Enable Minimum NON-APERTURE Spads */
+ current_spad_index = 0;
+ last_spad_index = current_spad_index;
+ need_apt_spads = 0;
+ status = enable_ref_spads(dev,
+ need_apt_spads,
+ dev->Data.SpadData.RefGoodSpadMap,
+ dev->Data.SpadData.RefSpadEnables,
+ spad_array_size,
+ start_select,
+ current_spad_index,
+ minimum_spad_count,
+ &last_spad_index);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ current_spad_index = last_spad_index;
+
+ status = perform_ref_signal_measurement(dev,
+ &peak_signal_rate_ref);
+ if ((status == VL53L0X_ERROR_NONE) &&
+ (peak_signal_rate_ref > target_ref_rate)) {
+ /* Signal rate measurement too high,
+ * switch to APERTURE SPADs */
+
+ for (index = 0; index < spad_array_size; index++)
+ dev->Data.SpadData.RefSpadEnables[index] = 0;
+
+
+ /* Increment to the first APERTURE spad */
+ while ((is_aperture(start_select + current_spad_index)
+ == 0) && (current_spad_index < max_spad_count)) {
+ current_spad_index++;
+ }
+
+ need_apt_spads = 1;
+
+ status = enable_ref_spads(dev,
+ need_apt_spads,
+ dev->Data.SpadData.RefGoodSpadMap,
+ dev->Data.SpadData.RefSpadEnables,
+ spad_array_size,
+ start_select,
+ current_spad_index,
+ minimum_spad_count,
+ &last_spad_index);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ current_spad_index = last_spad_index;
+ status = perform_ref_signal_measurement(dev,
+ &peak_signal_rate_ref);
+
+ if ((status == VL53L0X_ERROR_NONE) &&
+ (peak_signal_rate_ref > target_ref_rate)) {
+ /* Signal rate still too high after
+ * setting the minimum number of
+ * APERTURE spads. Can do no more
+ * therefore set the min number of
+ * aperture spads as the result.
+ */
+ is_aperture_spads_int = 1;
+ ref_spad_count_int = minimum_spad_count;
+ }
+ }
+ } else {
+ need_apt_spads = 0;
+ }
+ }
+
+ if ((status == VL53L0X_ERROR_NONE) &&
+ (peak_signal_rate_ref < target_ref_rate)) {
+ /* At this point, the minimum number of either aperture
+ * or non-aperture spads have been set. Proceed to add
+ * spads and perform measurements until the target
+ * reference is reached.
+ */
+ is_aperture_spads_int = need_apt_spads;
+ ref_spad_count_int = minimum_spad_count;
+
+ memcpy(last_spad_array, dev->Data.SpadData.RefSpadEnables,
+ spad_array_size);
+ last_signal_rate_diff = abs(peak_signal_rate_ref -
+ target_ref_rate);
+ complete = 0;
+
+ while (!complete) {
+ get_next_good_spad(
+ dev->Data.SpadData.RefGoodSpadMap,
+ spad_array_size, current_spad_index,
+ &next_good_spad);
+
+ if (next_good_spad == -1) {
+ status = VL53L0X_ERROR_REF_SPAD_INIT;
+ break;
+ }
+
+ /* Cannot combine Aperture and Non-Aperture spads, so
+ * ensure the current spad is of the correct type.
+ */
+ if (is_aperture((uint32_t)start_select + next_good_spad) !=
+ need_apt_spads) {
+ /* At this point we have enabled the maximum
+ * number of Aperture spads.
+ */
+ complete = 1;
+ break;
+ }
+
+ (ref_spad_count_int)++;
+
+ current_spad_index = next_good_spad;
+ status = enable_spad_bit(
+ dev->Data.SpadData.RefSpadEnables,
+ spad_array_size, current_spad_index);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ current_spad_index++;
+ /* Proceed to apply the additional spad and
+ * perform measurement. */
+ status = set_ref_spad_map(dev,
+ dev->Data.SpadData.RefSpadEnables);
+ }
+
+ if (status != VL53L0X_ERROR_NONE)
+ break;
+
+ status = perform_ref_signal_measurement(dev,
+ &peak_signal_rate_ref);
+
+ if (status != VL53L0X_ERROR_NONE)
+ break;
+
+ signal_rate_diff = abs(peak_signal_rate_ref - target_ref_rate);
+
+ if (peak_signal_rate_ref > target_ref_rate) {
+ /* Select the spad map that provides the
+ * measurement closest to the target rate,
+ * either above or below it.
+ */
+ if (signal_rate_diff > last_signal_rate_diff) {
+ /* Previous spad map produced a closer
+ * measurement, so choose this. */
+ status = set_ref_spad_map(dev,
+ last_spad_array);
+ memcpy(
+ dev->Data.SpadData.RefSpadEnables,
+ last_spad_array, spad_array_size);
+
+ (ref_spad_count_int)--;
+ }
+ complete = 1;
+ } else {
+ /* Continue to add spads */
+ last_signal_rate_diff = signal_rate_diff;
+ memcpy(last_spad_array,
+ dev->Data.SpadData.RefSpadEnables,
+ spad_array_size);
+ }
+
+ } /* while */
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ *ref_spad_count = ref_spad_count_int;
+ *is_aperture_spads = is_aperture_spads_int;
+
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev, RefSpadsInitialised, 1);
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ ReferenceSpadCount, (uint8_t)(*ref_spad_count));
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ ReferenceSpadType, *is_aperture_spads);
+ }
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_set_reference_spads(VL53L0X_DEV Dev,
- uint32_t count, uint8_t isApertureSpads)
+VL53L0X_Error VL53L0X::vl53l0x_set_reference_spads(VL53L0X_DEV dev,
+ uint32_t count, uint8_t is_aperture_spads)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint32_t currentSpadIndex = 0;
- uint8_t startSelect = 0xB4;
- uint32_t spadArraySize = 6;
- uint32_t maxSpadCount = 44;
- uint32_t lastSpadIndex;
- uint32_t index;
-
- /*
- * This function applies a requested number of reference spads, either
- * aperture or
- * non-aperture, as requested.
- * The good spad map will be applied.
- */
-
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_DYNAMIC_SPAD_REF_EN_START_OFFSET, 0x00);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD, 0x2C);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x00);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_GLOBAL_CONFIG_REF_EN_START_SELECT,
- startSelect);
-
- for (index = 0; index < spadArraySize; index++)
- Dev->Data.SpadData.RefSpadEnables[index] = 0;
-
- if (isApertureSpads) {
- /* Increment to the first APERTURE spad */
- while ((is_aperture(startSelect + currentSpadIndex) == 0) &&
- (currentSpadIndex < maxSpadCount)) {
- currentSpadIndex++;
- }
- }
- Status = enable_ref_spads(Dev,
- isApertureSpads,
- Dev->Data.SpadData.RefGoodSpadMap,
- Dev->Data.SpadData.RefSpadEnables,
- spadArraySize,
- startSelect,
- currentSpadIndex,
- count,
- &lastSpadIndex);
-
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, RefSpadsInitialised, 1);
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- ReferenceSpadCount, (uint8_t)(count));
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- ReferenceSpadType, isApertureSpads);
- }
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint32_t current_spad_index = 0;
+ uint8_t start_select = 0xB4;
+ uint32_t spad_array_size = 6;
+ uint32_t max_spad_count = 44;
+ uint32_t last_spad_index;
+ uint32_t index;
+
+ /*
+ * This function applies a requested number of reference spads, either
+ * aperture or
+ * non-aperture, as requested.
+ * The good spad map will be applied.
+ */
+
+ status = vl53l0x_write_byte(dev, 0xFF, 0x01);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_DYNAMIC_SPAD_REF_EN_START_OFFSET, 0x00);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD, 0x2C);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev, 0xFF, 0x00);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_GLOBAL_CONFIG_REF_EN_START_SELECT,
+ start_select);
+
+ for (index = 0; index < spad_array_size; index++)
+ dev->Data.SpadData.RefSpadEnables[index] = 0;
+
+ if (is_aperture_spads) {
+ /* Increment to the first APERTURE spad */
+ while ((is_aperture(start_select + current_spad_index) == 0) &&
+ (current_spad_index < max_spad_count)) {
+ current_spad_index++;
+ }
+ }
+ status = enable_ref_spads(dev,
+ is_aperture_spads,
+ dev->Data.SpadData.RefGoodSpadMap,
+ dev->Data.SpadData.RefSpadEnables,
+ spad_array_size,
+ start_select,
+ current_spad_index,
+ count,
+ &last_spad_index);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev, RefSpadsInitialised, 1);
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ ReferenceSpadCount, (uint8_t)(count));
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ ReferenceSpadType, is_aperture_spads);
+ }
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_WaitDeviceBooted(VL53L0X_DEV Dev)
+VL53L0X_Error VL53L0X::vl53l0x_wait_device_booted(VL53L0X_DEV dev)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NOT_IMPLEMENTED;
- LOG_FUNCTION_START("");
-
- /* not implemented on VL53L0X */
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NOT_IMPLEMENTED;
+ LOG_FUNCTION_START("");
+
+ /* not implemented on VL53L0X */
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_PerformRefCalibration(VL53L0X_DEV Dev, uint8_t *pVhvSettings,
- uint8_t *pPhaseCal)
+VL53L0X_Error VL53L0X::vl53l0x_perform_ref_calibration(VL53L0X_DEV dev, uint8_t *p_vhv_settings,
+ uint8_t *p_phase_cal)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_perform_ref_calibration(Dev, pVhvSettings,
- pPhaseCal, 1);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_perform_ref_calibration(dev, p_vhv_settings,
+ p_phase_cal, 1);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_PerformRefSpadManagement(VL53L0X_DEV Dev,
- uint32_t *refSpadCount, uint8_t *isApertureSpads)
+VL53L0X_Error VL53L0X::vl53l0x_perform_ref_spad_management(VL53L0X_DEV dev,
+ uint32_t *ref_spad_count, uint8_t *is_aperture_spads)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_perform_ref_spad_management(Dev, refSpadCount,
- isApertureSpads);
-
- LOG_FUNCTION_END(Status);
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = wrapped_vl53l0x_perform_ref_spad_management(dev, ref_spad_count,
+ is_aperture_spads);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
}
/* Group PAL Init Functions */
-VL53L0X_Error VL53L0X::VL53L0X_SetDeviceAddress(VL53L0X_DEV Dev, uint8_t DeviceAddress)
+VL53L0X_Error VL53L0X::vl53l0x_set_device_address(VL53L0X_DEV dev, uint8_t device_address)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_WrByte(Dev, VL53L0X_REG_I2C_SLAVE_DEVICE_ADDRESS,
- DeviceAddress / 2);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_I2C_SLAVE_DEVICE_ADDRESS,
+ device_address / 2);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_SetGpioConfig(VL53L0X_DEV Dev, uint8_t Pin,
- VL53L0X_DeviceModes DeviceMode, VL53L0X_GpioFunctionality Functionality,
- VL53L0X_InterruptPolarity Polarity)
+VL53L0X_Error VL53L0X::vl53l0x_set_gpio_config(VL53L0X_DEV dev, uint8_t pin,
+ VL53L0X_DeviceModes device_mode, VL53L0X_GpioFunctionality functionality,
+ VL53L0X_InterruptPolarity polarity)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t data;
-
- LOG_FUNCTION_START("");
-
- if (Pin != 0) {
- Status = VL53L0X_ERROR_GPIO_NOT_EXISTING;
- } else if (DeviceMode == VL53L0X_DEVICEMODE_GPIO_DRIVE) {
- if (Polarity == VL53L0X_INTERRUPTPOLARITY_LOW)
- data = 0x10;
- else
- data = 1;
-
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_GPIO_HV_MUX_ACTIVE_HIGH, data);
-
- } else if (DeviceMode == VL53L0X_DEVICEMODE_GPIO_OSC) {
-
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0x00, 0x00);
-
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x00);
- Status |= VL53L0X_WrByte(Dev, 0x80, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0x85, 0x02);
-
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x04);
- Status |= VL53L0X_WrByte(Dev, 0xcd, 0x00);
- Status |= VL53L0X_WrByte(Dev, 0xcc, 0x11);
-
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x07);
- Status |= VL53L0X_WrByte(Dev, 0xbe, 0x00);
-
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x06);
- Status |= VL53L0X_WrByte(Dev, 0xcc, 0x09);
-
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x00);
- Status |= VL53L0X_WrByte(Dev, 0xff, 0x01);
- Status |= VL53L0X_WrByte(Dev, 0x00, 0x00);
-
- } else {
-
- if (Status == VL53L0X_ERROR_NONE) {
- switch (Functionality) {
- case VL53L0X_GPIOFUNCTIONALITY_OFF:
- data = 0x00;
- break;
- case VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW:
- data = 0x01;
- break;
- case VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH:
- data = 0x02;
- break;
- case VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT:
- data = 0x03;
- break;
- case VL53L0X_GPIOFUNCTIONALITY_NEW_MEASURE_READY:
- data = 0x04;
- break;
- default:
- Status =
- VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED;
- }
- }
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_SYSTEM_INTERRUPT_CONFIG_GPIO, data);
-
- if (Status == VL53L0X_ERROR_NONE) {
- if (Polarity == VL53L0X_INTERRUPTPOLARITY_LOW)
- data = 0;
- else
- data = (uint8_t)(1 << 4);
-
- Status = VL53L0X_UpdateByte(Dev,
- VL53L0X_REG_GPIO_HV_MUX_ACTIVE_HIGH, 0xEF, data);
- }
-
- if (Status == VL53L0X_ERROR_NONE)
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- Pin0GpioFunctionality, Functionality);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_ClearInterruptMask(Dev, 0);
-
- }
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t data;
+
+ LOG_FUNCTION_START("");
+
+ if (pin != 0) {
+ status = VL53L0X_ERROR_GPIO_NOT_EXISTING;
+ } else if (device_mode == VL53L0X_DEVICEMODE_GPIO_DRIVE) {
+ if (polarity == VL53L0X_INTERRUPTPOLARITY_LOW)
+ data = 0x10;
+ else
+ data = 1;
+
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_GPIO_HV_MUX_ACTIVE_HIGH, data);
+
+ } else if (device_mode == VL53L0X_DEVICEMODE_GPIO_OSC) {
+
+ status |= vl53l0x_write_byte(dev, 0xff, 0x01);
+ status |= vl53l0x_write_byte(dev, 0x00, 0x00);
+
+ status |= vl53l0x_write_byte(dev, 0xff, 0x00);
+ status |= vl53l0x_write_byte(dev, 0x80, 0x01);
+ status |= vl53l0x_write_byte(dev, 0x85, 0x02);
+
+ status |= vl53l0x_write_byte(dev, 0xff, 0x04);
+ status |= vl53l0x_write_byte(dev, 0xcd, 0x00);
+ status |= vl53l0x_write_byte(dev, 0xcc, 0x11);
+
+ status |= vl53l0x_write_byte(dev, 0xff, 0x07);
+ status |= vl53l0x_write_byte(dev, 0xbe, 0x00);
+
+ status |= vl53l0x_write_byte(dev, 0xff, 0x06);
+ status |= vl53l0x_write_byte(dev, 0xcc, 0x09);
+
+ status |= vl53l0x_write_byte(dev, 0xff, 0x00);
+ status |= vl53l0x_write_byte(dev, 0xff, 0x01);
+ status |= vl53l0x_write_byte(dev, 0x00, 0x00);
+
+ } else {
+
+ if (status == VL53L0X_ERROR_NONE) {
+ switch (functionality) {
+ case VL53L0X_GPIOFUNCTIONALITY_OFF:
+ data = 0x00;
+ break;
+ case VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW:
+ data = 0x01;
+ break;
+ case VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH:
+ data = 0x02;
+ break;
+ case VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT:
+ data = 0x03;
+ break;
+ case VL53L0X_GPIOFUNCTIONALITY_NEW_MEASURE_READY:
+ data = 0x04;
+ break;
+ default:
+ status =
+ VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED;
+ }
+ }
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_SYSTEM_INTERRUPT_CONFIG_GPIO, data);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ if (polarity == VL53L0X_INTERRUPTPOLARITY_LOW)
+ data = 0;
+ else
+ data = (uint8_t)(1 << 4);
+
+ status = vl53l0x_update_byte(dev,
+ VL53L0X_REG_GPIO_HV_MUX_ACTIVE_HIGH, 0xEF, data);
+ }
+
+ if (status == VL53L0X_ERROR_NONE)
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ Pin0GpioFunctionality, functionality);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_clear_interrupt_mask(dev, 0);
+
+ }
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetFractionEnable(VL53L0X_DEV Dev, uint8_t *pEnabled)
+VL53L0X_Error VL53L0X::vl53l0x_get_fraction_enable(VL53L0X_DEV dev, uint8_t *p_enabled)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_RdByte(Dev, VL53L0X_REG_SYSTEM_RANGE_CONFIG, pEnabled);
-
- if (Status == VL53L0X_ERROR_NONE)
- *pEnabled = (*pEnabled & 1);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_read_byte(dev, VL53L0X_REG_SYSTEM_RANGE_CONFIG, p_enabled);
+
+ if (status == VL53L0X_ERROR_NONE)
+ *p_enabled = (*p_enabled & 1);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-uint16_t VL53L0X::VL53L0X_encode_timeout(uint32_t timeout_macro_clks)
+uint16_t VL53L0X::vl53l0x_encode_timeout(uint32_t timeout_macro_clks)
{
- /*!
- * Encode timeout in macro periods in (LSByte * 2^MSByte) + 1 format
- */
-
- uint16_t encoded_timeout = 0;
- uint32_t ls_byte = 0;
- uint16_t ms_byte = 0;
-
- if (timeout_macro_clks > 0) {
- ls_byte = timeout_macro_clks - 1;
-
- while ((ls_byte & 0xFFFFFF00) > 0) {
- ls_byte = ls_byte >> 1;
- ms_byte++;
- }
-
- encoded_timeout = (ms_byte << 8)
- + (uint16_t) (ls_byte & 0x000000FF);
- }
-
- return encoded_timeout;
+ /*!
+ * Encode timeout in macro periods in (LSByte * 2^MSByte) + 1 format
+ */
+
+ uint16_t encoded_timeout = 0;
+ uint32_t ls_byte = 0;
+ uint16_t ms_byte = 0;
+
+ if (timeout_macro_clks > 0) {
+ ls_byte = timeout_macro_clks - 1;
+
+ while ((ls_byte & 0xFFFFFF00) > 0) {
+ ls_byte = ls_byte >> 1;
+ ms_byte++;
+ }
+
+ encoded_timeout = (ms_byte << 8)
+ + (uint16_t)(ls_byte & 0x000000FF);
+ }
+
+ return encoded_timeout;
}
-VL53L0X_Error VL53L0X::set_sequence_step_timeout(VL53L0X_DEV Dev,
- VL53L0X_SequenceStepId SequenceStepId,
- uint32_t TimeOutMicroSecs)
+VL53L0X_Error VL53L0X::set_sequence_step_timeout(VL53L0X_DEV dev,
+ VL53L0X_SequenceStepId sequence_step_id,
+ uint32_t timeout_micro_secs)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t CurrentVCSELPulsePeriodPClk;
- uint8_t MsrcEncodedTimeOut;
- uint16_t PreRangeEncodedTimeOut;
- uint16_t PreRangeTimeOutMClks;
- uint16_t MsrcRangeTimeOutMClks;
- uint32_t FinalRangeTimeOutMClks;
- uint16_t FinalRangeEncodedTimeOut;
- VL53L0X_SchedulerSequenceSteps_t SchedulerSequenceSteps;
-
- if ((SequenceStepId == VL53L0X_SEQUENCESTEP_TCC) ||
- (SequenceStepId == VL53L0X_SEQUENCESTEP_DSS) ||
- (SequenceStepId == VL53L0X_SEQUENCESTEP_MSRC)) {
-
- Status = VL53L0X_GetVcselPulsePeriod(Dev,
- VL53L0X_VCSEL_PERIOD_PRE_RANGE,
- &CurrentVCSELPulsePeriodPClk);
-
- if (Status == VL53L0X_ERROR_NONE) {
- MsrcRangeTimeOutMClks = VL53L0X_calc_timeout_mclks(Dev,
- TimeOutMicroSecs,
- (uint8_t)CurrentVCSELPulsePeriodPClk);
-
- if (MsrcRangeTimeOutMClks > 256)
- MsrcEncodedTimeOut = 255;
- else
- MsrcEncodedTimeOut =
- (uint8_t)MsrcRangeTimeOutMClks - 1;
-
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- LastEncodedTimeout,
- MsrcEncodedTimeOut);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_MSRC_CONFIG_TIMEOUT_MACROP,
- MsrcEncodedTimeOut);
- }
- } else {
-
- if (SequenceStepId == VL53L0X_SEQUENCESTEP_PRE_RANGE) {
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_GetVcselPulsePeriod(Dev,
- VL53L0X_VCSEL_PERIOD_PRE_RANGE,
- &CurrentVCSELPulsePeriodPClk);
- PreRangeTimeOutMClks =
- VL53L0X_calc_timeout_mclks(Dev,
- TimeOutMicroSecs,
- (uint8_t)CurrentVCSELPulsePeriodPClk);
- PreRangeEncodedTimeOut = VL53L0X_encode_timeout(
- PreRangeTimeOutMClks);
-
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
- LastEncodedTimeout,
- PreRangeEncodedTimeOut);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_WrWord(Dev,
- VL53L0X_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
- PreRangeEncodedTimeOut);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETDEVICESPECIFICPARAMETER(
- Dev,
- PreRangeTimeoutMicroSecs,
- TimeOutMicroSecs);
- }
- } else if (SequenceStepId == VL53L0X_SEQUENCESTEP_FINAL_RANGE) {
-
- /* For the final range timeout, the pre-range timeout
- * must be added. To do this both final and pre-range
- * timeouts must be expressed in macro periods MClks
- * because they have different vcsel periods.
- */
-
- VL53L0X_GetSequenceStepEnables(Dev,
- &SchedulerSequenceSteps);
- PreRangeTimeOutMClks = 0;
- if (SchedulerSequenceSteps.PreRangeOn) {
-
- /* Retrieve PRE-RANGE VCSEL Period */
- Status = VL53L0X_GetVcselPulsePeriod(Dev,
- VL53L0X_VCSEL_PERIOD_PRE_RANGE,
- &CurrentVCSELPulsePeriodPClk);
-
- /* Retrieve PRE-RANGE Timeout in Macro periods
- * (MCLKS) */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_RdWord(Dev, 0x51,
- &PreRangeEncodedTimeOut);
- PreRangeTimeOutMClks =
- VL53L0X_decode_timeout(
- PreRangeEncodedTimeOut);
- }
- }
-
- /* Calculate FINAL RANGE Timeout in Macro Periods
- * (MCLKS) and add PRE-RANGE value
- */
- if (Status == VL53L0X_ERROR_NONE) {
-
- Status = VL53L0X_GetVcselPulsePeriod(Dev,
- VL53L0X_VCSEL_PERIOD_FINAL_RANGE,
- &CurrentVCSELPulsePeriodPClk);
- }
- if (Status == VL53L0X_ERROR_NONE) {
-
- FinalRangeTimeOutMClks =
- VL53L0X_calc_timeout_mclks(Dev,
- TimeOutMicroSecs,
- (uint8_t) CurrentVCSELPulsePeriodPClk);
-
- FinalRangeTimeOutMClks += PreRangeTimeOutMClks;
-
- FinalRangeEncodedTimeOut =
- VL53L0X_encode_timeout(FinalRangeTimeOutMClks);
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_WrWord(Dev, 0x71,
- FinalRangeEncodedTimeOut);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETDEVICESPECIFICPARAMETER(
- Dev,
- FinalRangeTimeoutMicroSecs,
- TimeOutMicroSecs);
- }
- }
- } else
- Status = VL53L0X_ERROR_INVALID_PARAMS;
-
- }
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t current_vcsel_pulse_period_p_clk;
+ uint8_t msrc_encoded_time_out;
+ uint16_t pre_range_encoded_time_out;
+ uint16_t pre_range_time_out_m_clks;
+ uint16_t msrc_range_time_out_m_clks;
+ uint32_t final_range_time_out_m_clks;
+ uint16_t final_range_encoded_time_out;
+ VL53L0X_SchedulerSequenceSteps_t scheduler_sequence_steps;
+
+ if ((sequence_step_id == VL53L0X_SEQUENCESTEP_TCC) ||
+ (sequence_step_id == VL53L0X_SEQUENCESTEP_DSS) ||
+ (sequence_step_id == VL53L0X_SEQUENCESTEP_MSRC)) {
+
+ status = vl53l0x_get_vcsel_pulse_period(dev,
+ VL53L0X_VCSEL_PERIOD_PRE_RANGE,
+ ¤t_vcsel_pulse_period_p_clk);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ msrc_range_time_out_m_clks = vl53l0x_calc_timeout_mclks(dev,
+ timeout_micro_secs,
+ (uint8_t)current_vcsel_pulse_period_p_clk);
+
+ if (msrc_range_time_out_m_clks > 256)
+ msrc_encoded_time_out = 255;
+ else
+ msrc_encoded_time_out =
+ (uint8_t)msrc_range_time_out_m_clks - 1;
+
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ LastEncodedTimeout,
+ msrc_encoded_time_out);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_MSRC_CONFIG_TIMEOUT_MACROP,
+ msrc_encoded_time_out);
+ }
+ } else {
+
+ if (sequence_step_id == VL53L0X_SEQUENCESTEP_PRE_RANGE) {
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_get_vcsel_pulse_period(dev,
+ VL53L0X_VCSEL_PERIOD_PRE_RANGE,
+ ¤t_vcsel_pulse_period_p_clk);
+ pre_range_time_out_m_clks =
+ vl53l0x_calc_timeout_mclks(dev,
+ timeout_micro_secs,
+ (uint8_t)current_vcsel_pulse_period_p_clk);
+ pre_range_encoded_time_out = vl53l0x_encode_timeout(
+ pre_range_time_out_m_clks);
+
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev,
+ LastEncodedTimeout,
+ pre_range_encoded_time_out);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_write_word(dev,
+ VL53L0X_REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
+ pre_range_encoded_time_out);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETDEVICESPECIFICPARAMETER(
+ dev,
+ PreRangeTimeoutMicroSecs,
+ timeout_micro_secs);
+ }
+ } else if (sequence_step_id == VL53L0X_SEQUENCESTEP_FINAL_RANGE) {
+
+ /* For the final range timeout, the pre-range timeout
+ * must be added. To do this both final and pre-range
+ * timeouts must be expressed in macro periods MClks
+ * because they have different vcsel periods.
+ */
+
+ vl53l0x_get_sequence_step_enables(dev,
+ &scheduler_sequence_steps);
+ pre_range_time_out_m_clks = 0;
+ if (scheduler_sequence_steps.PreRangeOn) {
+
+ /* Retrieve PRE-RANGE VCSEL Period */
+ status = vl53l0x_get_vcsel_pulse_period(dev,
+ VL53L0X_VCSEL_PERIOD_PRE_RANGE,
+ ¤t_vcsel_pulse_period_p_clk);
+
+ /* Retrieve PRE-RANGE Timeout in Macro periods
+ * (MCLKS) */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_read_word(dev, 0x51,
+ &pre_range_encoded_time_out);
+ pre_range_time_out_m_clks =
+ vl53l0x_decode_timeout(
+ pre_range_encoded_time_out);
+ }
+ }
+
+ /* Calculate FINAL RANGE Timeout in Macro Periods
+ * (MCLKS) and add PRE-RANGE value
+ */
+ if (status == VL53L0X_ERROR_NONE) {
+
+ status = vl53l0x_get_vcsel_pulse_period(dev,
+ VL53L0X_VCSEL_PERIOD_FINAL_RANGE,
+ ¤t_vcsel_pulse_period_p_clk);
+ }
+ if (status == VL53L0X_ERROR_NONE) {
+
+ final_range_time_out_m_clks =
+ vl53l0x_calc_timeout_mclks(dev,
+ timeout_micro_secs,
+ (uint8_t) current_vcsel_pulse_period_p_clk);
+
+ final_range_time_out_m_clks += pre_range_time_out_m_clks;
+
+ final_range_encoded_time_out =
+ vl53l0x_encode_timeout(final_range_time_out_m_clks);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_write_word(dev, 0x71,
+ final_range_encoded_time_out);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETDEVICESPECIFICPARAMETER(
+ dev,
+ FinalRangeTimeoutMicroSecs,
+ timeout_micro_secs);
+ }
+ }
+ } else
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+
+ }
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_set_measurement_timing_budget_micro_seconds(VL53L0X_DEV Dev,
- uint32_t MeasurementTimingBudgetMicroSeconds)
+VL53L0X_Error VL53L0X::wrapped_vl53l0x_set_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
+ uint32_t measurement_timing_budget_micro_seconds)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint32_t FinalRangeTimingBudgetMicroSeconds;
- VL53L0X_SchedulerSequenceSteps_t SchedulerSequenceSteps;
- uint32_t MsrcDccTccTimeoutMicroSeconds = 2000;
- uint32_t StartOverheadMicroSeconds = 1910;
- uint32_t EndOverheadMicroSeconds = 960;
- uint32_t MsrcOverheadMicroSeconds = 660;
- uint32_t TccOverheadMicroSeconds = 590;
- uint32_t DssOverheadMicroSeconds = 690;
- uint32_t PreRangeOverheadMicroSeconds = 660;
- uint32_t FinalRangeOverheadMicroSeconds = 550;
- uint32_t PreRangeTimeoutMicroSeconds = 0;
- uint32_t cMinTimingBudgetMicroSeconds = 20000;
- uint32_t SubTimeout = 0;
-
- LOG_FUNCTION_START("");
-
- if (MeasurementTimingBudgetMicroSeconds
- < cMinTimingBudgetMicroSeconds) {
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- return Status;
- }
-
- FinalRangeTimingBudgetMicroSeconds =
- MeasurementTimingBudgetMicroSeconds -
- (StartOverheadMicroSeconds + EndOverheadMicroSeconds);
-
- Status = VL53L0X_GetSequenceStepEnables(Dev, &SchedulerSequenceSteps);
-
- if (Status == VL53L0X_ERROR_NONE &&
- (SchedulerSequenceSteps.TccOn ||
- SchedulerSequenceSteps.MsrcOn ||
- SchedulerSequenceSteps.DssOn)) {
-
- /* TCC, MSRC and DSS all share the same timeout */
- Status = get_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_MSRC,
- &MsrcDccTccTimeoutMicroSeconds);
-
- /* Subtract the TCC, MSRC and DSS timeouts if they are
- * enabled. */
-
- if (Status != VL53L0X_ERROR_NONE)
- return Status;
-
- /* TCC */
- if (SchedulerSequenceSteps.TccOn) {
-
- SubTimeout = MsrcDccTccTimeoutMicroSeconds
- + TccOverheadMicroSeconds;
-
- if (SubTimeout <
- FinalRangeTimingBudgetMicroSeconds) {
- FinalRangeTimingBudgetMicroSeconds -=
- SubTimeout;
- } else {
- /* Requested timeout too big. */
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
- }
-
- if (Status != VL53L0X_ERROR_NONE) {
- LOG_FUNCTION_END(Status);
- return Status;
- }
-
- /* DSS */
- if (SchedulerSequenceSteps.DssOn) {
-
- SubTimeout = 2 * (MsrcDccTccTimeoutMicroSeconds +
- DssOverheadMicroSeconds);
-
- if (SubTimeout < FinalRangeTimingBudgetMicroSeconds) {
- FinalRangeTimingBudgetMicroSeconds
- -= SubTimeout;
- } else {
- /* Requested timeout too big. */
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
- } else if (SchedulerSequenceSteps.MsrcOn) {
- /* MSRC */
- SubTimeout = MsrcDccTccTimeoutMicroSeconds +
- MsrcOverheadMicroSeconds;
-
- if (SubTimeout < FinalRangeTimingBudgetMicroSeconds) {
- FinalRangeTimingBudgetMicroSeconds
- -= SubTimeout;
- } else {
- /* Requested timeout too big. */
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
- }
-
- }
-
- if (Status != VL53L0X_ERROR_NONE) {
- LOG_FUNCTION_END(Status);
- return Status;
- }
-
- if (SchedulerSequenceSteps.PreRangeOn) {
-
- /* Subtract the Pre-range timeout if enabled. */
-
- Status = get_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_PRE_RANGE,
- &PreRangeTimeoutMicroSeconds);
-
- SubTimeout = PreRangeTimeoutMicroSeconds +
- PreRangeOverheadMicroSeconds;
-
- if (SubTimeout < FinalRangeTimingBudgetMicroSeconds) {
- FinalRangeTimingBudgetMicroSeconds -= SubTimeout;
- } else {
- /* Requested timeout too big. */
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
- }
-
-
- if (Status == VL53L0X_ERROR_NONE &&
- SchedulerSequenceSteps.FinalRangeOn) {
-
- FinalRangeTimingBudgetMicroSeconds -=
- FinalRangeOverheadMicroSeconds;
-
- /* Final Range Timeout
- * Note that the final range timeout is determined by the timing
- * budget and the sum of all other timeouts within the sequence.
- * If there is no room for the final range timeout, then an error
- * will be set. Otherwise the remaining time will be applied to
- * the final range.
- */
- Status = set_sequence_step_timeout(Dev,
- VL53L0X_SEQUENCESTEP_FINAL_RANGE,
- FinalRangeTimingBudgetMicroSeconds);
-
- VL53L0X_SETPARAMETERFIELD(Dev,
- MeasurementTimingBudgetMicroSeconds,
- MeasurementTimingBudgetMicroSeconds);
- }
-
- LOG_FUNCTION_END(Status);
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint32_t final_range_timing_budget_micro_seconds;
+ VL53L0X_SchedulerSequenceSteps_t scheduler_sequence_steps;
+ uint32_t msrc_dcc_tcc_timeout_micro_seconds = 2000;
+ uint32_t start_overhead_micro_seconds = 1910;
+ uint32_t end_overhead_micro_seconds = 960;
+ uint32_t msrc_overhead_micro_seconds = 660;
+ uint32_t tcc_overhead_micro_seconds = 590;
+ uint32_t dss_overhead_micro_seconds = 690;
+ uint32_t pre_range_overhead_micro_seconds = 660;
+ uint32_t final_range_overhead_micro_seconds = 550;
+ uint32_t pre_range_timeout_micro_seconds = 0;
+ uint32_t c_min_timing_budget_micro_seconds = 20000;
+ uint32_t sub_timeout = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (measurement_timing_budget_micro_seconds
+ < c_min_timing_budget_micro_seconds) {
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ return status;
+ }
+
+ final_range_timing_budget_micro_seconds =
+ measurement_timing_budget_micro_seconds -
+ (start_overhead_micro_seconds + end_overhead_micro_seconds);
+
+ status = vl53l0x_get_sequence_step_enables(dev, &scheduler_sequence_steps);
+
+ if (status == VL53L0X_ERROR_NONE &&
+ (scheduler_sequence_steps.TccOn ||
+ scheduler_sequence_steps.MsrcOn ||
+ scheduler_sequence_steps.DssOn)) {
+
+ /* TCC, MSRC and DSS all share the same timeout */
+ status = get_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_MSRC,
+ &msrc_dcc_tcc_timeout_micro_seconds);
+
+ /* Subtract the TCC, MSRC and DSS timeouts if they are
+ * enabled. */
+
+ if (status != VL53L0X_ERROR_NONE)
+ return status;
+
+ /* TCC */
+ if (scheduler_sequence_steps.TccOn) {
+
+ sub_timeout = msrc_dcc_tcc_timeout_micro_seconds
+ + tcc_overhead_micro_seconds;
+
+ if (sub_timeout <
+ final_range_timing_budget_micro_seconds) {
+ final_range_timing_budget_micro_seconds -=
+ sub_timeout;
+ } else {
+ /* Requested timeout too big. */
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ if (status != VL53L0X_ERROR_NONE) {
+ LOG_FUNCTION_END(status);
+ return status;
+ }
+
+ /* DSS */
+ if (scheduler_sequence_steps.DssOn) {
+
+ sub_timeout = 2 * (msrc_dcc_tcc_timeout_micro_seconds +
+ dss_overhead_micro_seconds);
+
+ if (sub_timeout < final_range_timing_budget_micro_seconds) {
+ final_range_timing_budget_micro_seconds
+ -= sub_timeout;
+ } else {
+ /* Requested timeout too big. */
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+ } else if (scheduler_sequence_steps.MsrcOn) {
+ /* MSRC */
+ sub_timeout = msrc_dcc_tcc_timeout_micro_seconds +
+ msrc_overhead_micro_seconds;
+
+ if (sub_timeout < final_range_timing_budget_micro_seconds) {
+ final_range_timing_budget_micro_seconds
+ -= sub_timeout;
+ } else {
+ /* Requested timeout too big. */
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ }
+
+ if (status != VL53L0X_ERROR_NONE) {
+ LOG_FUNCTION_END(status);
+ return status;
+ }
+
+ if (scheduler_sequence_steps.PreRangeOn) {
+
+ /* Subtract the Pre-range timeout if enabled. */
+
+ status = get_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_PRE_RANGE,
+ &pre_range_timeout_micro_seconds);
+
+ sub_timeout = pre_range_timeout_micro_seconds +
+ pre_range_overhead_micro_seconds;
+
+ if (sub_timeout < final_range_timing_budget_micro_seconds) {
+ final_range_timing_budget_micro_seconds -= sub_timeout;
+ } else {
+ /* Requested timeout too big. */
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+ }
+
+
+ if (status == VL53L0X_ERROR_NONE &&
+ scheduler_sequence_steps.FinalRangeOn) {
+
+ final_range_timing_budget_micro_seconds -=
+ final_range_overhead_micro_seconds;
+
+ /* Final Range Timeout
+ * Note that the final range timeout is determined by the timing
+ * budget and the sum of all other timeouts within the sequence.
+ * If there is no room for the final range timeout, then an error
+ * will be set. Otherwise the remaining time will be applied to
+ * the final range.
+ */
+ status = set_sequence_step_timeout(dev,
+ VL53L0X_SEQUENCESTEP_FINAL_RANGE,
+ final_range_timing_budget_micro_seconds);
+
+ VL53L0X_SETPARAMETERFIELD(dev,
+ MeasurementTimingBudgetMicroSeconds,
+ measurement_timing_budget_micro_seconds);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_SetMeasurementTimingBudgetMicroSeconds(VL53L0X_DEV Dev,
- uint32_t MeasurementTimingBudgetMicroSeconds)
+VL53L0X_Error VL53L0X::vl53l0x_set_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
+ uint32_t measurement_timing_budget_micro_seconds)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_set_measurement_timing_budget_micro_seconds(Dev,
- MeasurementTimingBudgetMicroSeconds);
-
- LOG_FUNCTION_END(Status);
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = wrapped_vl53l0x_set_measurement_timing_budget_micro_seconds(dev,
+ measurement_timing_budget_micro_seconds);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_SetSequenceStepEnable(VL53L0X_DEV Dev,
- VL53L0X_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled)
+VL53L0X_Error VL53L0X::vl53l0x_set_sequence_step_enable(VL53L0X_DEV dev,
+ VL53L0X_SequenceStepId sequence_step_id, uint8_t sequence_step_enabled)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t SequenceConfig = 0;
- uint8_t SequenceConfigNew = 0;
- uint32_t MeasurementTimingBudgetMicroSeconds;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_RdByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
- &SequenceConfig);
-
- SequenceConfigNew = SequenceConfig;
-
- if (Status == VL53L0X_ERROR_NONE) {
- if (SequenceStepEnabled == 1) {
-
- /* Enable requested sequence step
- */
- switch (SequenceStepId) {
- case VL53L0X_SEQUENCESTEP_TCC:
- SequenceConfigNew |= 0x10;
- break;
- case VL53L0X_SEQUENCESTEP_DSS:
- SequenceConfigNew |= 0x28;
- break;
- case VL53L0X_SEQUENCESTEP_MSRC:
- SequenceConfigNew |= 0x04;
- break;
- case VL53L0X_SEQUENCESTEP_PRE_RANGE:
- SequenceConfigNew |= 0x40;
- break;
- case VL53L0X_SEQUENCESTEP_FINAL_RANGE:
- SequenceConfigNew |= 0x80;
- break;
- default:
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
- } else {
- /* Disable requested sequence step
- */
- switch (SequenceStepId) {
- case VL53L0X_SEQUENCESTEP_TCC:
- SequenceConfigNew &= 0xef;
- break;
- case VL53L0X_SEQUENCESTEP_DSS:
- SequenceConfigNew &= 0xd7;
- break;
- case VL53L0X_SEQUENCESTEP_MSRC:
- SequenceConfigNew &= 0xfb;
- break;
- case VL53L0X_SEQUENCESTEP_PRE_RANGE:
- SequenceConfigNew &= 0xbf;
- break;
- case VL53L0X_SEQUENCESTEP_FINAL_RANGE:
- SequenceConfigNew &= 0x7f;
- break;
- default:
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- }
- }
- }
-
- if (SequenceConfigNew != SequenceConfig) {
- /* Apply New Setting */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_WrByte(Dev,
- VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, SequenceConfigNew);
- }
- if (Status == VL53L0X_ERROR_NONE)
- PALDevDataSet(Dev, SequenceConfig, SequenceConfigNew);
-
-
- /* Recalculate timing budget */
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_GETPARAMETERFIELD(Dev,
- MeasurementTimingBudgetMicroSeconds,
- MeasurementTimingBudgetMicroSeconds);
-
- VL53L0X_SetMeasurementTimingBudgetMicroSeconds(Dev,
- MeasurementTimingBudgetMicroSeconds);
- }
- }
-
- LOG_FUNCTION_END(Status);
-
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t sequence_config = 0;
+ uint8_t sequence_config_new = 0;
+ uint32_t measurement_timing_budget_micro_seconds;
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_read_byte(dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
+ &sequence_config);
+
+ sequence_config_new = sequence_config;
+
+ if (status == VL53L0X_ERROR_NONE) {
+ if (sequence_step_enabled == 1) {
+
+ /* Enable requested sequence step
+ */
+ switch (sequence_step_id) {
+ case VL53L0X_SEQUENCESTEP_TCC:
+ sequence_config_new |= 0x10;
+ break;
+ case VL53L0X_SEQUENCESTEP_DSS:
+ sequence_config_new |= 0x28;
+ break;
+ case VL53L0X_SEQUENCESTEP_MSRC:
+ sequence_config_new |= 0x04;
+ break;
+ case VL53L0X_SEQUENCESTEP_PRE_RANGE:
+ sequence_config_new |= 0x40;
+ break;
+ case VL53L0X_SEQUENCESTEP_FINAL_RANGE:
+ sequence_config_new |= 0x80;
+ break;
+ default:
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+ } else {
+ /* Disable requested sequence step
+ */
+ switch (sequence_step_id) {
+ case VL53L0X_SEQUENCESTEP_TCC:
+ sequence_config_new &= 0xef;
+ break;
+ case VL53L0X_SEQUENCESTEP_DSS:
+ sequence_config_new &= 0xd7;
+ break;
+ case VL53L0X_SEQUENCESTEP_MSRC:
+ sequence_config_new &= 0xfb;
+ break;
+ case VL53L0X_SEQUENCESTEP_PRE_RANGE:
+ sequence_config_new &= 0xbf;
+ break;
+ case VL53L0X_SEQUENCESTEP_FINAL_RANGE:
+ sequence_config_new &= 0x7f;
+ break;
+ default:
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ }
+ }
+ }
+
+ if (sequence_config_new != sequence_config) {
+ /* Apply New Setting */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_write_byte(dev,
+ VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, sequence_config_new);
+ }
+ if (status == VL53L0X_ERROR_NONE)
+ PALDevDataSet(dev, SequenceConfig, sequence_config_new);
+
+
+ /* Recalculate timing budget */
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_GETPARAMETERFIELD(dev,
+ MeasurementTimingBudgetMicroSeconds,
+ measurement_timing_budget_micro_seconds);
+
+ vl53l0x_set_measurement_timing_budget_micro_seconds(dev,
+ measurement_timing_budget_micro_seconds);
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_SetLimitCheckEnable(VL53L0X_DEV Dev, uint16_t LimitCheckId,
- uint8_t LimitCheckEnable)
+VL53L0X_Error VL53L0X::vl53l0x_set_limit_check_enable(VL53L0X_DEV dev, uint16_t limit_check_id,
+ uint8_t limit_check_enable)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- FixPoint1616_t TempFix1616 = 0;
- uint8_t LimitCheckEnableInt = 0;
- uint8_t LimitCheckDisable = 0;
- uint8_t Temp8;
-
- LOG_FUNCTION_START("");
-
- if (LimitCheckId >= VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS) {
- Status = VL53L0X_ERROR_INVALID_PARAMS;
- } else {
- if (LimitCheckEnable == 0) {
- TempFix1616 = 0;
- LimitCheckEnableInt = 0;
- LimitCheckDisable = 1;
-
- } else {
- VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
- LimitCheckId, TempFix1616);
- LimitCheckDisable = 0;
- /* this to be sure to have either 0 or 1 */
- LimitCheckEnableInt = 1;
- }
-
- switch (LimitCheckId) {
-
- case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:
- /* internal computation: */
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
- VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
- LimitCheckEnableInt);
-
- break;
-
- case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
-
- Status = VL53L0X_WrWord(Dev,
- VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
- VL53L0X_FIXPOINT1616TOFIXPOINT97(TempFix1616));
-
- break;
-
- case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:
-
- /* internal computation: */
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
- VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
- LimitCheckEnableInt);
-
- break;
-
- case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
-
- /* internal computation: */
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
- VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
- LimitCheckEnableInt);
-
- break;
-
- case VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC:
-
- Temp8 = (uint8_t)(LimitCheckDisable << 1);
- Status = VL53L0X_UpdateByte(Dev,
- VL53L0X_REG_MSRC_CONFIG_CONTROL,
- 0xFE, Temp8);
-
- break;
-
- case VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE:
-
- Temp8 = (uint8_t)(LimitCheckDisable << 4);
- Status = VL53L0X_UpdateByte(Dev,
- VL53L0X_REG_MSRC_CONFIG_CONTROL,
- 0xEF, Temp8);
-
- break;
-
-
- default:
- Status = VL53L0X_ERROR_INVALID_PARAMS;
-
- }
-
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- if (LimitCheckEnable == 0) {
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
- LimitCheckId, 0);
- } else {
- VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
- LimitCheckId, 1);
- }
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ FixPoint1616_t temp_fix1616 = 0;
+ uint8_t limit_check_enable_int = 0;
+ uint8_t limit_check_disable = 0;
+ uint8_t temp8;
+
+ LOG_FUNCTION_START("");
+
+ if (limit_check_id >= VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS) {
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+ } else {
+ if (limit_check_enable == 0) {
+ temp_fix1616 = 0;
+ limit_check_enable_int = 0;
+ limit_check_disable = 1;
+
+ } else {
+ VL53L0X_GETARRAYPARAMETERFIELD(dev, LimitChecksValue,
+ limit_check_id, temp_fix1616);
+ limit_check_disable = 0;
+ /* this to be sure to have either 0 or 1 */
+ limit_check_enable_int = 1;
+ }
+
+ switch (limit_check_id) {
+
+ case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:
+ /* internal computation: */
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksEnable,
+ VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
+ limit_check_enable_int);
+
+ break;
+
+ case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+
+ status = vl53l0x_write_word(dev,
+ VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
+ VL53L0X_FIXPOINT1616TOFIXPOINT97(temp_fix1616));
+
+ break;
+
+ case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:
+
+ /* internal computation: */
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksEnable,
+ VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
+ limit_check_enable_int);
+
+ break;
+
+ case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
+
+ /* internal computation: */
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksEnable,
+ VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
+ limit_check_enable_int);
+
+ break;
+
+ case VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC:
+
+ temp8 = (uint8_t)(limit_check_disable << 1);
+ status = vl53l0x_update_byte(dev,
+ VL53L0X_REG_MSRC_CONFIG_CONTROL,
+ 0xFE, temp8);
+
+ break;
+
+ case VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE:
+
+ temp8 = (uint8_t)(limit_check_disable << 4);
+ status = vl53l0x_update_byte(dev,
+ VL53L0X_REG_MSRC_CONFIG_CONTROL,
+ 0xEF, temp8);
+
+ break;
+
+
+ default:
+ status = VL53L0X_ERROR_INVALID_PARAMS;
+
+ }
+
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ if (limit_check_enable == 0) {
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksEnable,
+ limit_check_id, 0);
+ } else {
+ VL53L0X_SETARRAYPARAMETERFIELD(dev, LimitChecksEnable,
+ limit_check_id, 1);
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_StaticInit(VL53L0X_DEV Dev)
+VL53L0X_Error VL53L0X::vl53l0x_static_init(VL53L0X_DEV dev)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- VL53L0X_DeviceParameters_t CurrentParameters = {0};
- uint8_t *pTuningSettingBuffer;
- uint16_t tempword = 0;
- uint8_t tempbyte = 0;
- uint8_t UseInternalTuningSettings = 0;
- uint32_t count = 0;
- uint8_t isApertureSpads = 0;
- uint32_t refSpadCount = 0;
- uint8_t ApertureSpads = 0;
- uint8_t vcselPulsePeriodPCLK;
- uint32_t seqTimeoutMicroSecs;
-
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_get_info_from_device(Dev, 1);
-
- /* set the ref spad from NVM */
- count = (uint32_t)VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
- ReferenceSpadCount);
- ApertureSpads = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
- ReferenceSpadType);
-
- /* NVM value invalid */
- if ((ApertureSpads > 1) ||
- ((ApertureSpads == 1) && (count > 32)) ||
- ((ApertureSpads == 0) && (count > 12)))
- Status = VL53L0X_perform_ref_spad_management(Dev, &refSpadCount,
- &isApertureSpads);
- else
- Status = VL53L0X_set_reference_spads(Dev, count, ApertureSpads);
-
-
- /* Initialize tuning settings buffer to prevent compiler warning. */
- pTuningSettingBuffer = DefaultTuningSettings;
-
- if (Status == VL53L0X_ERROR_NONE) {
- UseInternalTuningSettings = PALDevDataGet(Dev,
- UseInternalTuningSettings);
-
- if (UseInternalTuningSettings == 0)
- pTuningSettingBuffer = PALDevDataGet(Dev,
- pTuningSettingsPointer);
- else
- pTuningSettingBuffer = DefaultTuningSettings;
-
- }
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_load_tuning_settings(Dev, pTuningSettingBuffer);
-
-
- /* Set interrupt config to new sample ready */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetGpioConfig(Dev, 0, 0,
- VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,
- VL53L0X_INTERRUPTPOLARITY_LOW);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
- Status |= VL53L0X_RdWord(Dev, 0x84, &tempword);
- Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, OscFrequencyMHz,
- VL53L0X_FIXPOINT412TOFIXPOINT1616(tempword));
- }
-
- /* After static init, some device parameters may be changed,
- * so update them */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_GetDeviceParameters(Dev, &CurrentParameters);
-
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_GetFractionEnable(Dev, &tempbyte);
- if (Status == VL53L0X_ERROR_NONE)
- PALDevDataSet(Dev, RangeFractionalEnable, tempbyte);
-
- }
-
- if (Status == VL53L0X_ERROR_NONE)
- PALDevDataSet(Dev, CurrentParameters, CurrentParameters);
-
-
- /* read the sequence config and save it */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_RdByte(Dev,
- VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &tempbyte);
- if (Status == VL53L0X_ERROR_NONE)
- PALDevDataSet(Dev, SequenceConfig, tempbyte);
-
- }
-
- /* Disable MSRC and TCC by default */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_SetSequenceStepEnable(Dev,
- VL53L0X_SEQUENCESTEP_TCC, 0);
-
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_SetSequenceStepEnable(Dev,
- VL53L0X_SEQUENCESTEP_MSRC, 0);
-
-
- /* Set PAL State to standby */
- if (Status == VL53L0X_ERROR_NONE)
- PALDevDataSet(Dev, PalState, VL53L0X_STATE_IDLE);
-
-
-
- /* Store pre-range vcsel period */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_GetVcselPulsePeriod(
- Dev,
- VL53L0X_VCSEL_PERIOD_PRE_RANGE,
- &vcselPulsePeriodPCLK);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETDEVICESPECIFICPARAMETER(
- Dev,
- PreRangeVcselPulsePeriod,
- vcselPulsePeriodPCLK);
- }
-
- /* Store final-range vcsel period */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_GetVcselPulsePeriod(
- Dev,
- VL53L0X_VCSEL_PERIOD_FINAL_RANGE,
- &vcselPulsePeriodPCLK);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETDEVICESPECIFICPARAMETER(
- Dev,
- FinalRangeVcselPulsePeriod,
- vcselPulsePeriodPCLK);
- }
-
- /* Store pre-range timeout */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = get_sequence_step_timeout(
- Dev,
- VL53L0X_SEQUENCESTEP_PRE_RANGE,
- &seqTimeoutMicroSecs);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETDEVICESPECIFICPARAMETER(
- Dev,
- PreRangeTimeoutMicroSecs,
- seqTimeoutMicroSecs);
- }
-
- /* Store final-range timeout */
- if (Status == VL53L0X_ERROR_NONE) {
- Status = get_sequence_step_timeout(
- Dev,
- VL53L0X_SEQUENCESTEP_FINAL_RANGE,
- &seqTimeoutMicroSecs);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- VL53L0X_SETDEVICESPECIFICPARAMETER(
- Dev,
- FinalRangeTimeoutMicroSecs,
- seqTimeoutMicroSecs);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ VL53L0X_DeviceParameters_t current_parameters = {0};
+ uint8_t *p_tuning_setting_buffer;
+ uint16_t tempword = 0;
+ uint8_t tempbyte = 0;
+ uint8_t use_internal_tuning_settings = 0;
+ uint32_t count = 0;
+ uint8_t is_aperture_spads = 0;
+ uint32_t ref_spad_count = 0;
+ uint8_t aperture_spads = 0;
+ uint8_t vcsel_pulse_period_pclk;
+ uint32_t seq_timeout_micro_secs;
+
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_get_info_from_device(dev, 1);
+
+ /* set the ref spad from NVM */
+ count = (uint32_t)VL53L0X_GETDEVICESPECIFICPARAMETER(dev,
+ ReferenceSpadCount);
+ aperture_spads = VL53L0X_GETDEVICESPECIFICPARAMETER(dev,
+ ReferenceSpadType);
+
+ /* NVM value invalid */
+ if ((aperture_spads > 1) ||
+ ((aperture_spads == 1) && (count > 32)) ||
+ ((aperture_spads == 0) && (count > 12)))
+ status = wrapped_vl53l0x_perform_ref_spad_management(dev, &ref_spad_count,
+ &is_aperture_spads);
+ else
+ status = vl53l0x_set_reference_spads(dev, count, aperture_spads);
+
+
+ /* Initialize tuning settings buffer to prevent compiler warning. */
+ p_tuning_setting_buffer = DefaultTuningSettings;
+
+ if (status == VL53L0X_ERROR_NONE) {
+ use_internal_tuning_settings = PALDevDataGet(dev,
+ UseInternalTuningSettings);
+
+ if (use_internal_tuning_settings == 0)
+ p_tuning_setting_buffer = PALDevDataGet(dev,
+ pTuningSettingsPointer);
+ else
+ p_tuning_setting_buffer = DefaultTuningSettings;
+
+ }
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_load_tuning_settings(dev, p_tuning_setting_buffer);
+
+
+ /* Set interrupt config to new sample ready */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_set_gpio_config(dev, 0, 0,
+ VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,
+ VL53L0X_INTERRUPTPOLARITY_LOW);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_write_byte(dev, 0xFF, 0x01);
+ status |= vl53l0x_read_word(dev, 0x84, &tempword);
+ status |= vl53l0x_write_byte(dev, 0xFF, 0x00);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETDEVICESPECIFICPARAMETER(dev, OscFrequencyMHz,
+ VL53L0X_FIXPOINT412TOFIXPOINT1616(tempword));
+ }
+
+ /* After static init, some device parameters may be changed,
+ * so update them */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_get_device_parameters(dev, ¤t_parameters);
+
+
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_get_fraction_enable(dev, &tempbyte);
+ if (status == VL53L0X_ERROR_NONE)
+ PALDevDataSet(dev, RangeFractionalEnable, tempbyte);
+
+ }
+
+ if (status == VL53L0X_ERROR_NONE)
+ PALDevDataSet(dev, CurrentParameters, current_parameters);
+
+
+ /* read the sequence config and save it */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_read_byte(dev,
+ VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &tempbyte);
+ if (status == VL53L0X_ERROR_NONE)
+ PALDevDataSet(dev, SequenceConfig, tempbyte);
+
+ }
+
+ /* Disable MSRC and TCC by default */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_set_sequence_step_enable(dev,
+ VL53L0X_SEQUENCESTEP_TCC, 0);
+
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_set_sequence_step_enable(dev,
+ VL53L0X_SEQUENCESTEP_MSRC, 0);
+
+
+ /* Set PAL State to standby */
+ if (status == VL53L0X_ERROR_NONE)
+ PALDevDataSet(dev, PalState, VL53L0X_STATE_IDLE);
+
+
+
+ /* Store pre-range vcsel period */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_get_vcsel_pulse_period(
+ dev,
+ VL53L0X_VCSEL_PERIOD_PRE_RANGE,
+ &vcsel_pulse_period_pclk);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETDEVICESPECIFICPARAMETER(
+ dev,
+ PreRangeVcselPulsePeriod,
+ vcsel_pulse_period_pclk);
+ }
+
+ /* Store final-range vcsel period */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = vl53l0x_get_vcsel_pulse_period(
+ dev,
+ VL53L0X_VCSEL_PERIOD_FINAL_RANGE,
+ &vcsel_pulse_period_pclk);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETDEVICESPECIFICPARAMETER(
+ dev,
+ FinalRangeVcselPulsePeriod,
+ vcsel_pulse_period_pclk);
+ }
+
+ /* Store pre-range timeout */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = get_sequence_step_timeout(
+ dev,
+ VL53L0X_SEQUENCESTEP_PRE_RANGE,
+ &seq_timeout_micro_secs);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETDEVICESPECIFICPARAMETER(
+ dev,
+ PreRangeTimeoutMicroSecs,
+ seq_timeout_micro_secs);
+ }
+
+ /* Store final-range timeout */
+ if (status == VL53L0X_ERROR_NONE) {
+ status = get_sequence_step_timeout(
+ dev,
+ VL53L0X_SEQUENCESTEP_FINAL_RANGE,
+ &seq_timeout_micro_secs);
+ }
+
+ if (status == VL53L0X_ERROR_NONE) {
+ VL53L0X_SETDEVICESPECIFICPARAMETER(
+ dev,
+ FinalRangeTimeoutMicroSecs,
+ seq_timeout_micro_secs);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_StopMeasurement(VL53L0X_DEV Dev)
+VL53L0X_Error VL53L0X::vl53l0x_stop_measurement(VL53L0X_DEV dev)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSRANGE_START,
- VL53L0X_REG_SYSRANGE_MODE_SINGLESHOT);
-
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
- Status = VL53L0X_WrByte(Dev, 0x00, 0x00);
- Status = VL53L0X_WrByte(Dev, 0x91, 0x00);
- Status = VL53L0X_WrByte(Dev, 0x00, 0x01);
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x00);
-
- if (Status == VL53L0X_ERROR_NONE) {
- /* Set PAL State to Idle */
- PALDevDataSet(Dev, PalState, VL53L0X_STATE_IDLE);
- }
-
- /* Check if need to apply interrupt settings */
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_CheckAndLoadInterruptSettings(Dev, 0);
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_write_byte(dev, VL53L0X_REG_SYSRANGE_START,
+ VL53L0X_REG_SYSRANGE_MODE_SINGLESHOT);
+
+ status = vl53l0x_write_byte(dev, 0xFF, 0x01);
+ status = vl53l0x_write_byte(dev, 0x00, 0x00);
+ status = vl53l0x_write_byte(dev, 0x91, 0x00);
+ status = vl53l0x_write_byte(dev, 0x00, 0x01);
+ status = vl53l0x_write_byte(dev, 0xFF, 0x00);
+
+ if (status == VL53L0X_ERROR_NONE) {
+ /* Set PAL State to Idle */
+ PALDevDataSet(dev, PalState, VL53L0X_STATE_IDLE);
+ }
+
+ /* Check if need to apply interrupt settings */
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_check_and_load_interrupt_settings(dev, 0);
+
+ LOG_FUNCTION_END(status);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_GetStopCompletedStatus(VL53L0X_DEV Dev,
- uint32_t *pStopStatus)
+VL53L0X_Error VL53L0X::vl53l0x_get_stop_completed_status(VL53L0X_DEV dev,
+ uint32_t *p_stop_status)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t Byte = 0;
- LOG_FUNCTION_START("");
-
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_RdByte(Dev, 0x04, &Byte);
-
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x0);
-
- *pStopStatus = Byte;
-
- if (Byte == 0) {
- Status = VL53L0X_WrByte(Dev, 0x80, 0x01);
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
- Status = VL53L0X_WrByte(Dev, 0x00, 0x00);
- Status = VL53L0X_WrByte(Dev, 0x91,
- PALDevDataGet(Dev, StopVariable));
- Status = VL53L0X_WrByte(Dev, 0x00, 0x01);
- Status = VL53L0X_WrByte(Dev, 0xFF, 0x00);
- Status = VL53L0X_WrByte(Dev, 0x80, 0x00);
- }
-
- LOG_FUNCTION_END(Status);
- return Status;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t byte = 0;
+ LOG_FUNCTION_START("");
+
+ status = vl53l0x_write_byte(dev, 0xFF, 0x01);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_read_byte(dev, 0x04, &byte);
+
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_write_byte(dev, 0xFF, 0x0);
+
+ *p_stop_status = byte;
+
+ if (byte == 0) {
+ status = vl53l0x_write_byte(dev, 0x80, 0x01);
+ status = vl53l0x_write_byte(dev, 0xFF, 0x01);
+ status = vl53l0x_write_byte(dev, 0x00, 0x00);
+ status = vl53l0x_write_byte(dev, 0x91,
+ PALDevDataGet(dev, StopVariable));
+ status = vl53l0x_write_byte(dev, 0x00, 0x01);
+ status = vl53l0x_write_byte(dev, 0xFF, 0x00);
+ status = vl53l0x_write_byte(dev, 0x80, 0x00);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
}
/****************** Write and read functions from I2C *************************/
-VL53L0X_Error VL53L0X::VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count)
+VL53L0X_Error VL53L0X::vl53l0x_write_multi(VL53L0X_DEV dev, uint8_t index, uint8_t *p_data, uint32_t count)
{
- int status;
-
- status = VL53L0X_I2CWrite(Dev->I2cDevAddr, index, pdata, (uint16_t)count);
- return status;
+ int status;
+
+ status = vl53l0x_i2c_write(dev->I2cDevAddr, index, p_data, (uint16_t)count);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count)
+VL53L0X_Error VL53L0X::vl53l0x_read_multi(VL53L0X_DEV dev, uint8_t index, uint8_t *p_data, uint32_t count)
{
int status;
- if (count>=VL53L0X_MAX_I2C_XFER_SIZE){
+ if (count >= VL53L0X_MAX_I2C_XFER_SIZE) {
status = VL53L0X_ERROR_INVALID_PARAMS;
}
- status = VL53L0X_I2CRead(Dev->I2cDevAddr, index, pdata, (uint16_t)count);
+ status = vl53l0x_i2c_read(dev->I2cDevAddr, index, p_data, (uint16_t)count);
return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data)
+VL53L0X_Error VL53L0X::vl53l0x_write_byte(VL53L0X_DEV Dev, uint8_t index, uint8_t data)
{
- int status;
-
- status=VL53L0X_I2CWrite(Dev->I2cDevAddr, index, &data, 1);
- return status;
+ int status;
+
+ status = vl53l0x_i2c_write(Dev->I2cDevAddr, index, &data, 1);
+ return status;
}
-
-VL53L0X_Error VL53L0X::VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data)
+
+VL53L0X_Error VL53L0X::vl53l0x_write_word(VL53L0X_DEV dev, uint8_t index, uint16_t data)
{
- int status;
- uint8_t buffer[2];
-
- buffer[0] = data >> 8;
- buffer[1] = data & 0x00FF;
- status=VL53L0X_I2CWrite(Dev->I2cDevAddr, index, (uint8_t *)buffer, 2);
- return status;
+ int status;
+ uint8_t buffer[2];
+
+ buffer[0] = data >> 8;
+ buffer[1] = data & 0x00FF;
+ status = vl53l0x_i2c_write(dev->I2cDevAddr, index, (uint8_t *)buffer, 2);
+ return status;
}
-
-VL53L0X_Error VL53L0X::VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t data)
+
+VL53L0X_Error VL53L0X::vl53l0x_write_dword(VL53L0X_DEV Dev, uint8_t index, uint32_t data)
{
- int status;
- uint8_t buffer[4];
-
- buffer[0] = (data >> 24) & 0xFF;
- buffer[1] = (data >> 16) & 0xFF;
- buffer[2] = (data >> 8) & 0xFF;
- buffer[3] = (data >> 0) & 0xFF;
- status=VL53L0X_I2CWrite(Dev->I2cDevAddr, index, (uint8_t *)buffer, 4);
- return status;
+ int status;
+ uint8_t buffer[4];
+
+ buffer[0] = (data >> 24) & 0xFF;
+ buffer[1] = (data >> 16) & 0xFF;
+ buffer[2] = (data >> 8) & 0xFF;
+ buffer[3] = (data >> 0) & 0xFF;
+ status = vl53l0x_i2c_write(Dev->I2cDevAddr, index, (uint8_t *)buffer, 4);
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data)
+VL53L0X_Error VL53L0X::vl53l0x_read_byte(VL53L0X_DEV Dev, uint8_t index, uint8_t *p_data)
{
- int status;
-
- status = VL53L0X_I2CRead(Dev->I2cDevAddr, index, data, 1);
-
- if(status)
- return -1;
-
- return 0;
+ int status;
+
+ status = vl53l0x_i2c_read(Dev->I2cDevAddr, index, p_data, 1);
+
+ if (status)
+ return -1;
+
+ return 0;
}
-
-VL53L0X_Error VL53L0X::VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, uint16_t *data)
+
+VL53L0X_Error VL53L0X::vl53l0x_read_word(VL53L0X_DEV Dev, uint8_t index, uint16_t *p_data)
{
- int status;
- uint8_t buffer[2] = {0,0};
-
- status = VL53L0X_I2CRead(Dev->I2cDevAddr, index, buffer, 2);
- if (!status)
- {
- *data = (buffer[0] << 8) + buffer[1];
- }
- return status;
+ int status;
+ uint8_t buffer[2] = {0, 0};
+
+ status = vl53l0x_i2c_read(Dev->I2cDevAddr, index, buffer, 2);
+ if (!status) {
+ *p_data = (buffer[0] << 8) + buffer[1];
+ }
+ return status;
}
-
-VL53L0X_Error VL53L0X::VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t *data)
+
+VL53L0X_Error VL53L0X::vl53l0x_read_dword(VL53L0X_DEV Dev, uint8_t index, uint32_t *p_data)
{
- int status;
- uint8_t buffer[4] = {0,0,0,0};
-
- status = VL53L0X_I2CRead(Dev->I2cDevAddr, index, buffer, 4);
- if(!status)
- {
- *data = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3];
- }
- return status;
+ int status;
+ uint8_t buffer[4] = {0, 0, 0, 0};
+
+ status = vl53l0x_i2c_read(Dev->I2cDevAddr, index, buffer, 4);
+ if (!status) {
+ *p_data = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3];
+ }
+ return status;
}
-VL53L0X_Error VL53L0X::VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index, uint8_t AndData, uint8_t OrData)
+VL53L0X_Error VL53L0X::vl53l0x_update_byte(VL53L0X_DEV Dev, uint8_t index, uint8_t and_data, uint8_t or_data)
{
- int status;
- uint8_t buffer = 0;
-
- /* read data direct onto buffer */
- status = VL53L0X_I2CRead(Dev->I2cDevAddr, index, &buffer,1);
- if (!status)
- {
- buffer = (buffer & AndData) | OrData;
- status = VL53L0X_I2CWrite(Dev->I2cDevAddr, index, &buffer, (uint8_t)1);
- }
- return status;
+ int status;
+ uint8_t buffer = 0;
+
+ /* read data direct onto buffer */
+ status = vl53l0x_i2c_read(Dev->I2cDevAddr, index, &buffer, 1);
+ if (!status) {
+ buffer = (buffer & and_data) | or_data;
+ status = vl53l0x_i2c_write(Dev->I2cDevAddr, index, &buffer, (uint8_t)1);
+ }
+ return status;
}
-
-VL53L0X_Error VL53L0X::VL53L0X_I2CWrite(uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t* pBuffer, uint16_t NumByteToWrite)
+
+VL53L0X_Error VL53L0X::vl53l0x_i2c_write(uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t *p_data,
+ uint16_t NumByteToWrite)
{
- int ret;
-
- ret = dev_i2c.i2c_write(pBuffer, DeviceAddr, RegisterAddr, NumByteToWrite);
-
- if(ret)
- return -1;
- return 0;
+ int ret;
+
+ ret = dev_i2c.i2c_write(p_data, DeviceAddr, RegisterAddr, NumByteToWrite);
+
+ if (ret)
+ return -1;
+ return 0;
}
-
-VL53L0X_Error VL53L0X::VL53L0X_I2CRead(uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t* pBuffer, uint16_t NumByteToRead)
+
+VL53L0X_Error VL53L0X::vl53l0x_i2c_read(uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t *p_data,
+ uint16_t NumByteToRead)
{
- int ret;
-
- ret = dev_i2c.i2c_read(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead);
-
- if(ret)
- return -1;
- return 0;
-}
+ int ret;
+
+ ret = dev_i2c.i2c_read(p_data, DeviceAddr, RegisterAddr, NumByteToRead);
+
+ if (ret)
+ return -1;
+ return 0;
+}
int VL53L0X::read_id(uint8_t *id)
{
int status = 0;
- uint16_t rl_id=0;
-
- status = VL53L0X_RdWord(Device, VL53L0X_REG_IDENTIFICATION_MODEL_ID, &rl_id);
+ uint16_t rl_id = 0;
+
+ status = vl53l0x_read_word(_device, VL53L0X_REG_IDENTIFICATION_MODEL_ID, &rl_id);
if (rl_id == 0xEEAA)
return status;
-
+
return -1;
}
-int VL53L0X::ReadID(uint8_t *id)
+
+VL53L0X_Error VL53L0X::wait_measurement_data_ready(VL53L0X_DEV dev)
{
- return read_id(id);
-}
-
-
-VL53L0X_Error VL53L0X::WaitMeasurementDataReady(VL53L0X_DEV Dev)
-{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint8_t NewDatReady=0;
- uint32_t LoopNb;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint8_t new_dat_ready = 0;
+ uint32_t loop_nb;
// Wait until it finished
// use timeout to avoid deadlock
- if (Status == VL53L0X_ERROR_NONE) {
- LoopNb = 0;
+ if (status == VL53L0X_ERROR_NONE) {
+ loop_nb = 0;
do {
- Status = VL53L0X_GetMeasurementDataReady(Dev, &NewDatReady);
- if ((NewDatReady == 0x01) || Status != VL53L0X_ERROR_NONE) {
+ status = vl53l0x_get_measurement_data_ready(dev, &new_dat_ready);
+ if ((new_dat_ready == 0x01) || status != VL53L0X_ERROR_NONE) {
break;
}
- LoopNb = LoopNb + 1;
- VL53L0X_PollingDelay(Dev);
- } while (LoopNb < VL53L0X_DEFAULT_MAX_LOOP);
-
- if (LoopNb >= VL53L0X_DEFAULT_MAX_LOOP) {
- Status = VL53L0X_ERROR_TIME_OUT;
+ loop_nb = loop_nb + 1;
+ vl53l0x_polling_delay(dev);
+ } while (loop_nb < VL53L0X_DEFAULT_MAX_LOOP);
+
+ if (loop_nb >= VL53L0X_DEFAULT_MAX_LOOP) {
+ status = VL53L0X_ERROR_TIME_OUT;
}
}
- return Status;
+ return status;
}
-VL53L0X_Error VL53L0X::WaitStopCompleted(VL53L0X_DEV Dev)
+VL53L0X_Error VL53L0X::wait_stop_completed(VL53L0X_DEV dev)
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint32_t StopCompleted=0;
- uint32_t LoopNb;
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint32_t stop_completed = 0;
+ uint32_t loop_nb;
// Wait until it finished
// use timeout to avoid deadlock
- if (Status == VL53L0X_ERROR_NONE) {
- LoopNb = 0;
+ if (status == VL53L0X_ERROR_NONE) {
+ loop_nb = 0;
do {
- Status = VL53L0X_GetStopCompletedStatus(Dev, &StopCompleted);
- if ((StopCompleted == 0x00) || Status != VL53L0X_ERROR_NONE) {
+ status = vl53l0x_get_stop_completed_status(dev, &stop_completed);
+ if ((stop_completed == 0x00) || status != VL53L0X_ERROR_NONE) {
break;
}
- LoopNb = LoopNb + 1;
- VL53L0X_PollingDelay(Dev);
- } while (LoopNb < VL53L0X_DEFAULT_MAX_LOOP);
-
- if (LoopNb >= VL53L0X_DEFAULT_MAX_LOOP) {
- Status = VL53L0X_ERROR_TIME_OUT;
+ loop_nb = loop_nb + 1;
+ vl53l0x_polling_delay(dev);
+ } while (loop_nb < VL53L0X_DEFAULT_MAX_LOOP);
+
+ if (loop_nb >= VL53L0X_DEFAULT_MAX_LOOP) {
+ status = VL53L0X_ERROR_TIME_OUT;
}
}
- return Status;
+ return status;
}
-int VL53L0X::InitSensor(uint8_t NewAddr)
+int VL53L0X::init_sensor(uint8_t new_addr)
{
- int status;
-
- VL53L0X_Off();
- VL53L0X_On();
+ int status;
+
+ vl53l0x_off();
+ vl53l0x_on();
// status=VL53L0X_WaitDeviceBooted(Device);
// if(status)
// printf("WaitDeviceBooted fail\n\r");
- status=IsPresent();
- if(!status)
- {
- status=Init(&MyDevice);
- if(status != VL53L0X_ERROR_NONE)
- {
- printf("Failed to init VL53L0X sensor!\n\r");
- return status;
- }
-
- // deduce silicon version
- status = VL53L0X_GetDeviceInfo(&MyDevice, &DeviceInfo);
-
-
- status=Prepare();
- if(status != VL53L0X_ERROR_NONE)
- {
- printf("Failed to prepare VL53L0X!\n\r");
- return status;
- }
-
- if(NewAddr!=DEFAULT_DEVICE_ADDRESS)
- {
- status=SetDeviceAddress(NewAddr);
- if(status)
- {
- printf("Failed to change I2C address!\n\r");
+ status = is_present();
+ if (!status) {
+ status = init(&_my_device);
+ if (status != VL53L0X_ERROR_NONE) {
+ printf("Failed to init VL53L0X sensor!\n\r");
+ return status;
+ }
+
+ // deduce silicon version
+ status = vl53l0x_get_device_info(&_my_device, &_device_info);
+
+
+ status = prepare();
+ if (status != VL53L0X_ERROR_NONE) {
+ printf("Failed to prepare VL53L0X!\n\r");
return status;
- }
- }
- else
- {
- printf("Invalid new address!\n\r");
- return VL53L0X_ERROR_INVALID_PARAMS;
- }
- }
- return status;
+ }
+
+ if (new_addr != DEFAULT_DEVICE_ADDRESS) {
+ status = set_device_address(new_addr);
+ if (status) {
+ printf("Failed to change I2C address!\n\r");
+ return status;
+ }
+ } else {
+ printf("Invalid new address!\n\r");
+ return VL53L0X_ERROR_INVALID_PARAMS;
+ }
+ }
+ return status;
}
-int VL53L0X::RangeMeasIntContinuousMode(void (*fptr)(void))
+int VL53L0X::range_meas_int_continuous_mode(void (*fptr)(void))
{
- int status, ClrStatus;
-
- status = VL53L0X_StopMeasurement(Device); // it is safer to do this while sensor is stopped
+ int status, clr_status;
+
+ status = vl53l0x_stop_measurement(_device); // it is safer to do this while sensor is stopped
// status = VL53L0X_SetInterruptThresholds(Device, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING, 0, 300);
- status = VL53L0X_SetGpioConfig(Device, 0, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
- VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,
- VL53L0X_INTERRUPTPOLARITY_HIGH);
-
- if (!status)
- {
- AttachInterruptMeasureDetectionIRQ(fptr);
- EnableInterruptMeasureDetectionIRQ();
- }
-
- ClrStatus=ClearInterrupt(VL53L0X_REG_RESULT_INTERRUPT_STATUS|VL53L0X_REG_RESULT_RANGE_STATUS);
- if(ClrStatus)
- VL53L0X_ErrLog("VL53L0X_ClearErrorInterrupt fail\r\n");
-
- if(!status)
- {
- status=RangeStartContinuousMode();
- }
- return status;
+ status = vl53l0x_set_gpio_config(_device, 0, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
+ VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,
+ VL53L0X_INTERRUPTPOLARITY_HIGH);
+
+ if (!status) {
+ attach_interrupt_measure_detection_irq(fptr);
+ enable_interrupt_measure_detection_irq();
+ }
+
+ clr_status = clear_interrupt(VL53L0X_REG_RESULT_INTERRUPT_STATUS | VL53L0X_REG_RESULT_RANGE_STATUS);
+ if (clr_status)
+ VL53L0X_ErrLog("VL53L0X_ClearErrorInterrupt fail\r\n");
+
+ if (!status) {
+ status = range_start_continuous_mode();
+ }
+ return status;
}
-int VL53L0X::StartMeasurement(OperatingMode operating_mode, void (*fptr)(void))
+int VL53L0X::start_measurement(OperatingMode operating_mode, void (*fptr)(void))
{
int Status = VL53L0X_ERROR_NONE;
int ClrStatus;
@@ -5215,225 +5202,207 @@
uint8_t PhaseCal;
// *** from mass market cube expansion v1.1, ranging with satellites.
// default settings, for normal range.
- FixPoint1616_t signalLimit = (FixPoint1616_t)(0.25*65536);
- FixPoint1616_t sigmaLimit = (FixPoint1616_t)(18*65536);
- uint32_t timingBudget = 33000;
- uint8_t preRangeVcselPeriod = 14;
- uint8_t finalRangeVcselPeriod = 10;
-
- if (operating_mode == range_continuous_interrupt)
- {
- if (gpio1Int==NULL)
- {
- printf ("GPIO1 Error\r\n");
+ FixPoint1616_t signalLimit = (FixPoint1616_t)(0.25 * 65536);
+ FixPoint1616_t sigmaLimit = (FixPoint1616_t)(18 * 65536);
+ uint32_t timingBudget = 33000;
+ uint8_t preRangeVcselPeriod = 14;
+ uint8_t finalRangeVcselPeriod = 10;
+
+ if (operating_mode == range_continuous_interrupt) {
+ if (gpio1Int == NULL) {
+ printf("GPIO1 Error\r\n");
return 1;
}
- Status = VL53L0X_StopMeasurement(Device); // it is safer to do this while sensor is stopped
+ Status = vl53l0x_stop_measurement(_device); // it is safer to do this while sensor is stopped
// Status = VL53L0X_SetInterruptThresholds(Device, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING, 0, 300);
- Status = VL53L0X_SetGpioConfig(Device, 0, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
- VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,
- VL53L0X_INTERRUPTPOLARITY_HIGH);
-
- if (Status == VL53L0X_ERROR_NONE)
- {
- AttachInterruptMeasureDetectionIRQ(fptr);
- EnableInterruptMeasureDetectionIRQ();
+ Status = vl53l0x_set_gpio_config(_device, 0, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
+ VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,
+ VL53L0X_INTERRUPTPOLARITY_HIGH);
+
+ if (Status == VL53L0X_ERROR_NONE) {
+ attach_interrupt_measure_detection_irq(fptr);
+ enable_interrupt_measure_detection_irq();
}
- ClrStatus=ClearInterrupt(VL53L0X_REG_RESULT_INTERRUPT_STATUS|VL53L0X_REG_RESULT_RANGE_STATUS);
- if(ClrStatus)
- VL53L0X_ErrLog("VL53L0X_ClearErrorInterrupt fail\r\n");
-
- if(Status == VL53L0X_ERROR_NONE)
- {
- Status = VL53L0X_SetDeviceMode(Device, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in continuous ranging mode
+ ClrStatus = clear_interrupt(VL53L0X_REG_RESULT_INTERRUPT_STATUS | VL53L0X_REG_RESULT_RANGE_STATUS);
+ if (ClrStatus)
+ VL53L0X_ErrLog("VL53L0X_ClearErrorInterrupt fail\r\n");
+
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = vl53l0x_set_device_mode(_device, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in continuous ranging mode
}
- if(Status == VL53L0X_ERROR_NONE)
- {
- Status = VL53L0X_StartMeasurement(Device);
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = vl53l0x_start_measurement(_device);
}
}
- if (operating_mode == range_single_shot_polling)
- {
+ if (operating_mode == range_single_shot_polling) {
// singelshot, polled ranging
- if(Status == VL53L0X_ERROR_NONE)
- {
+ if (Status == VL53L0X_ERROR_NONE) {
// no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
- Status = VL53L0X_SetDeviceMode(Device, VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode
+ Status = vl53l0x_set_device_mode(_device, VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode
}
// Enable/Disable Sigma and Signal check
if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetLimitCheckEnable(Device,
- VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1);
+ Status = vl53l0x_set_limit_check_enable(_device,
+ VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1);
}
if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetLimitCheckEnable(Device,
- VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
+ Status = vl53l0x_set_limit_check_enable(_device,
+ VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
}
// *** from mass market cube expansion v1.1, ranging with satellites.
- /* Ranging configuration */
+ /* Ranging configuration */
//*
// switch(rangingConfig) {
// case LONG_RANGE:
- signalLimit = (FixPoint1616_t)(0.1*65536);
- sigmaLimit = (FixPoint1616_t)(60*65536);
- timingBudget = 33000;
- preRangeVcselPeriod = 18;
- finalRangeVcselPeriod = 14;
-/* break;
- case HIGH_ACCURACY:
- signalLimit = (FixPoint1616_t)(0.25*65536);
- sigmaLimit = (FixPoint1616_t)(18*65536);
- timingBudget = 200000;
- preRangeVcselPeriod = 14;
- finalRangeVcselPeriod = 10;
- break;
- case HIGH_SPEED:
- signalLimit = (FixPoint1616_t)(0.25*65536);
- sigmaLimit = (FixPoint1616_t)(32*65536);
- timingBudget = 20000;
- preRangeVcselPeriod = 14;
- finalRangeVcselPeriod = 10;
- break;
- default:
- debug_printf("Not Supported");
- }
-*/
+ signalLimit = (FixPoint1616_t)(0.1 * 65536);
+ sigmaLimit = (FixPoint1616_t)(60 * 65536);
+ timingBudget = 33000;
+ preRangeVcselPeriod = 18;
+ finalRangeVcselPeriod = 14;
+ /* break;
+ case HIGH_ACCURACY:
+ signalLimit = (FixPoint1616_t)(0.25*65536);
+ sigmaLimit = (FixPoint1616_t)(18*65536);
+ timingBudget = 200000;
+ preRangeVcselPeriod = 14;
+ finalRangeVcselPeriod = 10;
+ break;
+ case HIGH_SPEED:
+ signalLimit = (FixPoint1616_t)(0.25*65536);
+ sigmaLimit = (FixPoint1616_t)(32*65536);
+ timingBudget = 20000;
+ preRangeVcselPeriod = 14;
+ finalRangeVcselPeriod = 10;
+ break;
+ default:
+ debug_printf("Not Supported");
+ }
+ */
if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetLimitCheckValue(Device,
- VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, signalLimit);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetLimitCheckValue(Device,
- VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, sigmaLimit);
- }
-
- if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetMeasurementTimingBudgetMicroSeconds(Device, timingBudget);
+ Status = vl53l0x_set_limit_check_value(_device,
+ VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, signalLimit);
}
if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetVcselPulsePeriod(Device,
- VL53L0X_VCSEL_PERIOD_PRE_RANGE, preRangeVcselPeriod);
- }
+ Status = vl53l0x_set_limit_check_value(_device,
+ VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, sigmaLimit);
+ }
+
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = vl53l0x_set_measurement_timing_budget_micro_seconds(_device, timingBudget);
+ }
if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_SetVcselPulsePeriod(Device,
- VL53L0X_VCSEL_PERIOD_FINAL_RANGE, finalRangeVcselPeriod);
- }
+ Status = vl53l0x_set_vcsel_pulse_period(_device,
+ VL53L0X_VCSEL_PERIOD_PRE_RANGE, preRangeVcselPeriod);
+ }
if (Status == VL53L0X_ERROR_NONE) {
- Status = VL53L0X_PerformRefCalibration(Device, &VhvSettings, &PhaseCal);
- }
+ Status = vl53l0x_set_vcsel_pulse_period(_device,
+ VL53L0X_VCSEL_PERIOD_FINAL_RANGE, finalRangeVcselPeriod);
+ }
+
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = vl53l0x_perform_ref_calibration(_device, &VhvSettings, &PhaseCal);
+ }
}
- if (operating_mode == range_continuous_polling)
- {
- if(Status == VL53L0X_ERROR_NONE)
- {
- printf ("Call of VL53L0X_SetDeviceMode\n");
- Status = VL53L0X_SetDeviceMode(Device, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in continuous ranging mode
+ if (operating_mode == range_continuous_polling) {
+ if (Status == VL53L0X_ERROR_NONE) {
+ printf("Call of VL53L0X_SetDeviceMode\n");
+ Status = vl53l0x_set_device_mode(_device, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in continuous ranging mode
}
- if(Status == VL53L0X_ERROR_NONE)
- {
- printf ("Call of VL53L0X_StartMeasurement\n");
- Status = VL53L0X_StartMeasurement(Device);
+ if (Status == VL53L0X_ERROR_NONE) {
+ printf("Call of VL53L0X_StartMeasurement\n");
+ Status = vl53l0x_start_measurement(_device);
}
}
return Status;
}
-
-
-int VL53L0X::GetMeasurement(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *Data)
+
+
+int VL53L0X::get_measurement(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *p_data)
{
int Status = VL53L0X_ERROR_NONE;
- if (operating_mode == range_single_shot_polling)
- {
- Status = VL53L0X_PerformSingleRangingMeasurement(Device, Data);
+ if (operating_mode == range_single_shot_polling) {
+ Status = vl53l0x_perform_single_ranging_measurement(_device, p_data);
}
- if (operating_mode == range_continuous_polling)
- {
- if (Status == VL53L0X_ERROR_NONE)
- Status = VL53L0X_measurement_poll_for_completion(Device);
-
- if(Status == VL53L0X_ERROR_NONE)
- {
- Status = VL53L0X_GetRangingMeasurementData(Device, Data);
-
- // Clear the interrupt
- VL53L0X_ClearInterruptMask(Device, VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
- VL53L0X_PollingDelay(Device);
+ if (operating_mode == range_continuous_polling) {
+ if (Status == VL53L0X_ERROR_NONE)
+ Status = vl53l0x_measurement_poll_for_completion(_device);
+
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = vl53l0x_get_ranging_measurement_data(_device, p_data);
+
+ // Clear the interrupt
+ vl53l0x_clear_interrupt_mask(_device, VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
+ vl53l0x_polling_delay(_device);
}
}
- if (operating_mode == range_continuous_interrupt)
- {
- Status = VL53L0X_GetRangingMeasurementData(Device, Data);
- VL53L0X_ClearInterruptMask(Device, VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR | VL53L0X_REG_RESULT_INTERRUPT_STATUS);
- }
+ if (operating_mode == range_continuous_interrupt) {
+ Status = vl53l0x_get_ranging_measurement_data(_device, p_data);
+ vl53l0x_clear_interrupt_mask(_device, VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR | VL53L0X_REG_RESULT_INTERRUPT_STATUS);
+ }
return Status;
}
-
-
-int VL53L0X::StopMeasurement(OperatingMode operating_mode)
+
+
+int VL53L0X::stop_measurement(OperatingMode operating_mode)
{
int status = VL53L0X_ERROR_NONE;
- // don't need to stop for a singleshot range!
- if (operating_mode==range_single_shot_polling)
- {
+ // don't need to stop for a singleshot range!
+ if (operating_mode == range_single_shot_polling) {
}
- if (operating_mode==range_continuous_interrupt || operating_mode==range_continuous_polling)
- {
- // continuous mode
- if(status == VL53L0X_ERROR_NONE)
- {
- printf ("Call of VL53L0X_StopMeasurement\n");
- status = VL53L0X_StopMeasurement(Device);
+ if (operating_mode == range_continuous_interrupt || operating_mode == range_continuous_polling) {
+ // continuous mode
+ if (status == VL53L0X_ERROR_NONE) {
+ printf("Call of VL53L0X_StopMeasurement\n");
+ status = vl53l0x_stop_measurement(_device);
}
- if(status == VL53L0X_ERROR_NONE)
- {
- printf ("Wait Stop to be competed\n");
- status = WaitStopCompleted(Device);
+ if (status == VL53L0X_ERROR_NONE) {
+ printf("Wait Stop to be competed\n");
+ status = wait_stop_completed(_device);
}
- if(status == VL53L0X_ERROR_NONE)
- status = VL53L0X_ClearInterruptMask(Device,
- VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
+ if (status == VL53L0X_ERROR_NONE)
+ status = vl53l0x_clear_interrupt_mask(_device,
+ VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
}
return status;
}
-int VL53L0X::HandleIRQ(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *Data)
+int VL53L0X::handle_irq(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *data)
{
- int status;
- status=GetMeasurement(operating_mode, Data);
- EnableInterruptMeasureDetectionIRQ();
- return status;
+ int status;
+ status = get_measurement(operating_mode, data);
+ enable_interrupt_measure_detection_irq();
+ return status;
}
-
-
-
+
+
+
/******************************************************************************/
--- a/Components/VL53L0X/vl53l0x_class.h Thu Jun 15 13:33:35 2017 +0000
+++ b/Components/VL53L0X/vl53l0x_class.h Mon Aug 07 14:30:21 2017 +0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- Copyright © 2016, STMicroelectronics International N.V.
+ Copyright © 2016, STMicroelectronics International N.V.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -44,8 +44,8 @@
/* Includes ------------------------------------------------------------------*/
#include "mbed.h"
#include "RangeSensor.h"
-#include "DevI2C.h"
-
+#include "DevI2C.h"
+#include "PinNames.h"
#include "vl53l0x_def.h"
#include "vl53l0x_platform.h"
#include "stmpe1600_class.h"
@@ -55,239 +55,237 @@
* The device model ID
*/
#define IDENTIFICATION_MODEL_ID 0x000
-
+
#define STATUS_OK 0x00
#define STATUS_FAIL 0x01
-
-#define VL53L0X_OsDelay(...) HAL_Delay(2)
+#define VL53L0X_OsDelay(...) wait_ms(2) // 2 msec delay. can also use wait(float secs)/wait_us(int)
#ifdef USE_EMPTY_STRING
- #define VL53L0X_STRING_DEVICE_INFO_NAME ""
- #define VL53L0X_STRING_DEVICE_INFO_NAME_TS0 ""
- #define VL53L0X_STRING_DEVICE_INFO_NAME_TS1 ""
- #define VL53L0X_STRING_DEVICE_INFO_NAME_TS2 ""
- #define VL53L0X_STRING_DEVICE_INFO_NAME_ES1 ""
- #define VL53L0X_STRING_DEVICE_INFO_TYPE ""
+#define VL53L0X_STRING_DEVICE_INFO_NAME ""
+#define VL53L0X_STRING_DEVICE_INFO_NAME_TS0 ""
+#define VL53L0X_STRING_DEVICE_INFO_NAME_TS1 ""
+#define VL53L0X_STRING_DEVICE_INFO_NAME_TS2 ""
+#define VL53L0X_STRING_DEVICE_INFO_NAME_ES1 ""
+#define VL53L0X_STRING_DEVICE_INFO_TYPE ""
- /* PAL ERROR strings */
- #define VL53L0X_STRING_ERROR_NONE ""
- #define VL53L0X_STRING_ERROR_CALIBRATION_WARNING ""
- #define VL53L0X_STRING_ERROR_MIN_CLIPPED ""
- #define VL53L0X_STRING_ERROR_UNDEFINED ""
- #define VL53L0X_STRING_ERROR_INVALID_PARAMS ""
- #define VL53L0X_STRING_ERROR_NOT_SUPPORTED ""
- #define VL53L0X_STRING_ERROR_RANGE_ERROR ""
- #define VL53L0X_STRING_ERROR_TIME_OUT ""
- #define VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED ""
- #define VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL ""
- #define VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING ""
- #define VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ""
- #define VL53L0X_STRING_ERROR_CONTROL_INTERFACE ""
- #define VL53L0X_STRING_ERROR_INVALID_COMMAND ""
- #define VL53L0X_STRING_ERROR_DIVISION_BY_ZERO ""
- #define VL53L0X_STRING_ERROR_REF_SPAD_INIT ""
- #define VL53L0X_STRING_ERROR_NOT_IMPLEMENTED ""
+/* PAL ERROR strings */
+#define VL53L0X_STRING_ERROR_NONE ""
+#define VL53L0X_STRING_ERROR_CALIBRATION_WARNING ""
+#define VL53L0X_STRING_ERROR_MIN_CLIPPED ""
+#define VL53L0X_STRING_ERROR_UNDEFINED ""
+#define VL53L0X_STRING_ERROR_INVALID_PARAMS ""
+#define VL53L0X_STRING_ERROR_NOT_SUPPORTED ""
+#define VL53L0X_STRING_ERROR_RANGE_ERROR ""
+#define VL53L0X_STRING_ERROR_TIME_OUT ""
+#define VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED ""
+#define VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL ""
+#define VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING ""
+#define VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ""
+#define VL53L0X_STRING_ERROR_CONTROL_INTERFACE ""
+#define VL53L0X_STRING_ERROR_INVALID_COMMAND ""
+#define VL53L0X_STRING_ERROR_DIVISION_BY_ZERO ""
+#define VL53L0X_STRING_ERROR_REF_SPAD_INIT ""
+#define VL53L0X_STRING_ERROR_NOT_IMPLEMENTED ""
- #define VL53L0X_STRING_UNKNOW_ERROR_CODE ""
+#define VL53L0X_STRING_UNKNOW_ERROR_CODE ""
- /* Range Status */
- #define VL53L0X_STRING_RANGESTATUS_NONE ""
- #define VL53L0X_STRING_RANGESTATUS_RANGEVALID ""
- #define VL53L0X_STRING_RANGESTATUS_SIGMA ""
- #define VL53L0X_STRING_RANGESTATUS_SIGNAL ""
- #define VL53L0X_STRING_RANGESTATUS_MINRANGE ""
- #define VL53L0X_STRING_RANGESTATUS_PHASE ""
- #define VL53L0X_STRING_RANGESTATUS_HW ""
+/* Range Status */
+#define VL53L0X_STRING_RANGESTATUS_NONE ""
+#define VL53L0X_STRING_RANGESTATUS_RANGEVALID ""
+#define VL53L0X_STRING_RANGESTATUS_SIGMA ""
+#define VL53L0X_STRING_RANGESTATUS_SIGNAL ""
+#define VL53L0X_STRING_RANGESTATUS_MINRANGE ""
+#define VL53L0X_STRING_RANGESTATUS_PHASE ""
+#define VL53L0X_STRING_RANGESTATUS_HW ""
- /* Range Status */
- #define VL53L0X_STRING_STATE_POWERDOWN ""
- #define VL53L0X_STRING_STATE_WAIT_STATICINIT ""
- #define VL53L0X_STRING_STATE_STANDBY ""
- #define VL53L0X_STRING_STATE_IDLE ""
- #define VL53L0X_STRING_STATE_RUNNING ""
- #define VL53L0X_STRING_STATE_UNKNOWN ""
- #define VL53L0X_STRING_STATE_ERROR ""
+/* Range Status */
+#define VL53L0X_STRING_STATE_POWERDOWN ""
+#define VL53L0X_STRING_STATE_WAIT_STATICINIT ""
+#define VL53L0X_STRING_STATE_STANDBY ""
+#define VL53L0X_STRING_STATE_IDLE ""
+#define VL53L0X_STRING_STATE_RUNNING ""
+#define VL53L0X_STRING_STATE_UNKNOWN ""
+#define VL53L0X_STRING_STATE_ERROR ""
- /* Device Specific */
- #define VL53L0X_STRING_DEVICEERROR_NONE ""
- #define VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE ""
- #define VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE ""
- #define VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND ""
- #define VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET ""
- #define VL53L0X_STRING_DEVICEERROR_SNRCHECK ""
- #define VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK ""
- #define VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK ""
- #define VL53L0X_STRING_DEVICEERROR_TCC ""
- #define VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY ""
- #define VL53L0X_STRING_DEVICEERROR_MINCLIP ""
- #define VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE ""
- #define VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW ""
- #define VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW ""
- #define VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD ""
- #define VL53L0X_STRING_DEVICEERROR_UNKNOWN ""
+/* Device Specific */
+#define VL53L0X_STRING_DEVICEERROR_NONE ""
+#define VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE ""
+#define VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE ""
+#define VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND ""
+#define VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET ""
+#define VL53L0X_STRING_DEVICEERROR_SNRCHECK ""
+#define VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK ""
+#define VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK ""
+#define VL53L0X_STRING_DEVICEERROR_TCC ""
+#define VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY ""
+#define VL53L0X_STRING_DEVICEERROR_MINCLIP ""
+#define VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE ""
+#define VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW ""
+#define VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW ""
+#define VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD ""
+#define VL53L0X_STRING_DEVICEERROR_UNKNOWN ""
- /* Check Enable */
- #define VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE ""
- #define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE ""
- #define VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP ""
- #define VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD ""
+/* Check Enable */
+#define VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE ""
+#define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE ""
+#define VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP ""
+#define VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD ""
- /* Sequence Step */
- #define VL53L0X_STRING_SEQUENCESTEP_TCC ""
- #define VL53L0X_STRING_SEQUENCESTEP_DSS ""
- #define VL53L0X_STRING_SEQUENCESTEP_MSRC ""
- #define VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE ""
- #define VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE ""
+/* Sequence Step */
+#define VL53L0X_STRING_SEQUENCESTEP_TCC ""
+#define VL53L0X_STRING_SEQUENCESTEP_DSS ""
+#define VL53L0X_STRING_SEQUENCESTEP_MSRC ""
+#define VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE ""
+#define VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE ""
#else
- #define VL53L0X_STRING_DEVICE_INFO_NAME "VL53L0X cut1.0"
- #define VL53L0X_STRING_DEVICE_INFO_NAME_TS0 "VL53L0X TS0"
- #define VL53L0X_STRING_DEVICE_INFO_NAME_TS1 "VL53L0X TS1"
- #define VL53L0X_STRING_DEVICE_INFO_NAME_TS2 "VL53L0X TS2"
- #define VL53L0X_STRING_DEVICE_INFO_NAME_ES1 "VL53L0X ES1 or later"
- #define VL53L0X_STRING_DEVICE_INFO_TYPE "VL53L0X"
+#define VL53L0X_STRING_DEVICE_INFO_NAME "VL53L0X cut1.0"
+#define VL53L0X_STRING_DEVICE_INFO_NAME_TS0 "VL53L0X TS0"
+#define VL53L0X_STRING_DEVICE_INFO_NAME_TS1 "VL53L0X TS1"
+#define VL53L0X_STRING_DEVICE_INFO_NAME_TS2 "VL53L0X TS2"
+#define VL53L0X_STRING_DEVICE_INFO_NAME_ES1 "VL53L0X ES1 or later"
+#define VL53L0X_STRING_DEVICE_INFO_TYPE "VL53L0X"
- /* PAL ERROR strings */
- #define VL53L0X_STRING_ERROR_NONE \
+/* PAL ERROR strings */
+#define VL53L0X_STRING_ERROR_NONE \
"No Error"
- #define VL53L0X_STRING_ERROR_CALIBRATION_WARNING \
+#define VL53L0X_STRING_ERROR_CALIBRATION_WARNING \
"Calibration Warning Error"
- #define VL53L0X_STRING_ERROR_MIN_CLIPPED \
+#define VL53L0X_STRING_ERROR_MIN_CLIPPED \
"Min clipped error"
- #define VL53L0X_STRING_ERROR_UNDEFINED \
+#define VL53L0X_STRING_ERROR_UNDEFINED \
"Undefined error"
- #define VL53L0X_STRING_ERROR_INVALID_PARAMS \
+#define VL53L0X_STRING_ERROR_INVALID_PARAMS \
"Invalid parameters error"
- #define VL53L0X_STRING_ERROR_NOT_SUPPORTED \
+#define VL53L0X_STRING_ERROR_NOT_SUPPORTED \
"Not supported error"
- #define VL53L0X_STRING_ERROR_RANGE_ERROR \
+#define VL53L0X_STRING_ERROR_RANGE_ERROR \
"Range error"
- #define VL53L0X_STRING_ERROR_TIME_OUT \
+#define VL53L0X_STRING_ERROR_TIME_OUT \
"Time out error"
- #define VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED \
+#define VL53L0X_STRING_ERROR_MODE_NOT_SUPPORTED \
"Mode not supported error"
- #define VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL \
+#define VL53L0X_STRING_ERROR_BUFFER_TOO_SMALL \
"Buffer too small"
- #define VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING \
+#define VL53L0X_STRING_ERROR_GPIO_NOT_EXISTING \
"GPIO not existing"
- #define VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED \
+#define VL53L0X_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED \
"GPIO funct not supported"
- #define VL53L0X_STRING_ERROR_INTERRUPT_NOT_CLEARED \
+#define VL53L0X_STRING_ERROR_INTERRUPT_NOT_CLEARED \
"Interrupt not Cleared"
- #define VL53L0X_STRING_ERROR_CONTROL_INTERFACE \
+#define VL53L0X_STRING_ERROR_CONTROL_INTERFACE \
"Control Interface Error"
- #define VL53L0X_STRING_ERROR_INVALID_COMMAND \
+#define VL53L0X_STRING_ERROR_INVALID_COMMAND \
"Invalid Command Error"
- #define VL53L0X_STRING_ERROR_DIVISION_BY_ZERO \
+#define VL53L0X_STRING_ERROR_DIVISION_BY_ZERO \
"Division by zero Error"
- #define VL53L0X_STRING_ERROR_REF_SPAD_INIT \
+#define VL53L0X_STRING_ERROR_REF_SPAD_INIT \
"Reference Spad Init Error"
- #define VL53L0X_STRING_ERROR_NOT_IMPLEMENTED \
+#define VL53L0X_STRING_ERROR_NOT_IMPLEMENTED \
"Not implemented error"
- #define VL53L0X_STRING_UNKNOW_ERROR_CODE \
+#define VL53L0X_STRING_UNKNOW_ERROR_CODE \
"Unknown Error Code"
- /* Range Status */
- #define VL53L0X_STRING_RANGESTATUS_NONE "No Update"
- #define VL53L0X_STRING_RANGESTATUS_RANGEVALID "Range Valid"
- #define VL53L0X_STRING_RANGESTATUS_SIGMA "Sigma Fail"
- #define VL53L0X_STRING_RANGESTATUS_SIGNAL "Signal Fail"
- #define VL53L0X_STRING_RANGESTATUS_MINRANGE "Min Range Fail"
- #define VL53L0X_STRING_RANGESTATUS_PHASE "Phase Fail"
- #define VL53L0X_STRING_RANGESTATUS_HW "Hardware Fail"
+/* Range Status */
+#define VL53L0X_STRING_RANGESTATUS_NONE "No Update"
+#define VL53L0X_STRING_RANGESTATUS_RANGEVALID "Range Valid"
+#define VL53L0X_STRING_RANGESTATUS_SIGMA "Sigma Fail"
+#define VL53L0X_STRING_RANGESTATUS_SIGNAL "Signal Fail"
+#define VL53L0X_STRING_RANGESTATUS_MINRANGE "Min Range Fail"
+#define VL53L0X_STRING_RANGESTATUS_PHASE "Phase Fail"
+#define VL53L0X_STRING_RANGESTATUS_HW "Hardware Fail"
- /* Range Status */
- #define VL53L0X_STRING_STATE_POWERDOWN "POWERDOWN State"
- #define VL53L0X_STRING_STATE_WAIT_STATICINIT \
+/* Range Status */
+#define VL53L0X_STRING_STATE_POWERDOWN "POWERDOWN State"
+#define VL53L0X_STRING_STATE_WAIT_STATICINIT \
"Wait for staticinit State"
- #define VL53L0X_STRING_STATE_STANDBY "STANDBY State"
- #define VL53L0X_STRING_STATE_IDLE "IDLE State"
- #define VL53L0X_STRING_STATE_RUNNING "RUNNING State"
- #define VL53L0X_STRING_STATE_UNKNOWN "UNKNOWN State"
- #define VL53L0X_STRING_STATE_ERROR "ERROR State"
+#define VL53L0X_STRING_STATE_STANDBY "STANDBY State"
+#define VL53L0X_STRING_STATE_IDLE "IDLE State"
+#define VL53L0X_STRING_STATE_RUNNING "RUNNING State"
+#define VL53L0X_STRING_STATE_UNKNOWN "UNKNOWN State"
+#define VL53L0X_STRING_STATE_ERROR "ERROR State"
- /* Device Specific */
- #define VL53L0X_STRING_DEVICEERROR_NONE "No Update"
- #define VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE \
+/* Device Specific */
+#define VL53L0X_STRING_DEVICEERROR_NONE "No Update"
+#define VL53L0X_STRING_DEVICEERROR_VCSELCONTINUITYTESTFAILURE \
"VCSEL Continuity Test Failure"
- #define VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE \
+#define VL53L0X_STRING_DEVICEERROR_VCSELWATCHDOGTESTFAILURE \
"VCSEL Watchdog Test Failure"
- #define VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND \
+#define VL53L0X_STRING_DEVICEERROR_NOVHVVALUEFOUND \
"No VHV Value found"
- #define VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET \
+#define VL53L0X_STRING_DEVICEERROR_MSRCNOTARGET \
"MSRC No Target Error"
- #define VL53L0X_STRING_DEVICEERROR_SNRCHECK \
+#define VL53L0X_STRING_DEVICEERROR_SNRCHECK \
"SNR Check Exit"
- #define VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK \
+#define VL53L0X_STRING_DEVICEERROR_RANGEPHASECHECK \
"Range Phase Check Error"
- #define VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK \
+#define VL53L0X_STRING_DEVICEERROR_SIGMATHRESHOLDCHECK \
"Sigma Threshold Check Error"
- #define VL53L0X_STRING_DEVICEERROR_TCC \
+#define VL53L0X_STRING_DEVICEERROR_TCC \
"TCC Error"
- #define VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY \
+#define VL53L0X_STRING_DEVICEERROR_PHASECONSISTENCY \
"Phase Consistency Error"
- #define VL53L0X_STRING_DEVICEERROR_MINCLIP \
+#define VL53L0X_STRING_DEVICEERROR_MINCLIP \
"Min Clip Error"
- #define VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE \
+#define VL53L0X_STRING_DEVICEERROR_RANGECOMPLETE \
"Range Complete"
- #define VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW \
+#define VL53L0X_STRING_DEVICEERROR_ALGOUNDERFLOW \
"Range Algo Underflow Error"
- #define VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW \
+#define VL53L0X_STRING_DEVICEERROR_ALGOOVERFLOW \
"Range Algo Overlow Error"
- #define VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD \
+#define VL53L0X_STRING_DEVICEERROR_RANGEIGNORETHRESHOLD \
"Range Ignore Threshold Error"
- #define VL53L0X_STRING_DEVICEERROR_UNKNOWN \
+#define VL53L0X_STRING_DEVICEERROR_UNKNOWN \
"Unknown error code"
- /* Check Enable */
- #define VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE \
+/* Check Enable */
+#define VL53L0X_STRING_CHECKENABLE_SIGMA_FINAL_RANGE \
"SIGMA FINAL RANGE"
- #define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE \
+#define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE \
"SIGNAL RATE FINAL RANGE"
- #define VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP \
+#define VL53L0X_STRING_CHECKENABLE_SIGNAL_REF_CLIP \
"SIGNAL REF CLIP"
- #define VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD \
+#define VL53L0X_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD \
"RANGE IGNORE THRESHOLD"
- #define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_MSRC \
+#define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_MSRC \
"SIGNAL RATE MSRC"
- #define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_PRE_RANGE \
+#define VL53L0X_STRING_CHECKENABLE_SIGNAL_RATE_PRE_RANGE \
"SIGNAL RATE PRE RANGE"
- /* Sequence Step */
- #define VL53L0X_STRING_SEQUENCESTEP_TCC "TCC"
- #define VL53L0X_STRING_SEQUENCESTEP_DSS "DSS"
- #define VL53L0X_STRING_SEQUENCESTEP_MSRC "MSRC"
- #define VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE "PRE RANGE"
- #define VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE "FINAL RANGE"
+/* Sequence Step */
+#define VL53L0X_STRING_SEQUENCESTEP_TCC "TCC"
+#define VL53L0X_STRING_SEQUENCESTEP_DSS "DSS"
+#define VL53L0X_STRING_SEQUENCESTEP_MSRC "MSRC"
+#define VL53L0X_STRING_SEQUENCESTEP_PRE_RANGE "PRE RANGE"
+#define VL53L0X_STRING_SEQUENCESTEP_FINAL_RANGE "FINAL RANGE"
#endif /* USE_EMPTY_STRING */
-/* sensor operating modes */
-typedef enum
-{
- range_single_shot_polling=1,
- range_continuous_polling,
- range_continuous_interrupt,
- range_continuous_polling_low_threshold,
- range_continuous_polling_high_threshold,
- range_continuous_polling_out_of_window,
- range_continuous_interrupt_low_threshold,
- range_continuous_interrupt_high_threshold,
- range_continuous_interrupt_out_of_window,
-}OperatingMode;
+/* sensor operating modes */
+typedef enum {
+ range_single_shot_polling = 1,
+ range_continuous_polling,
+ range_continuous_interrupt,
+ range_continuous_polling_low_threshold,
+ range_continuous_polling_high_threshold,
+ range_continuous_polling_out_of_window,
+ range_continuous_interrupt_low_threshold,
+ range_continuous_interrupt_high_threshold,
+ range_continuous_interrupt_out_of_window,
+} OperatingMode;
/** default device address */
#define DEFAULT_DEVICE_ADDRESS 0x52 /* (8-bit) */
@@ -297,1163 +295,2459 @@
*/
class VL53L0X : public RangeSensor
{
- public:
+public:
/** Constructor
* @param[in] &i2c device I2C to be used for communication
* @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
- * @param[in] DevAddr device address, 0x29 by default
+ * @param[in] dev_addr device address, 0x29 by default
*/
- VL53L0X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : dev_i2c(i2c), gpio0(&pin)
+ VL53L0X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t dev_addr = DEFAULT_DEVICE_ADDRESS) : dev_i2c(i2c),
+ gpio0(&pin)
{
- MyDevice.I2cDevAddr=DevAddr;
- MyDevice.comms_type=1; // VL53L0X_COMMS_I2C
- MyDevice.comms_speed_khz=400;
- Device=&MyDevice;
- expgpio0=NULL;
- if (pin_gpio1 != NC) { gpio1Int = new InterruptIn(pin_gpio1); }
- else { gpio1Int = NULL; }
- }
-
+ _my_device.I2cDevAddr = dev_addr;
+ _my_device.comms_type = 1; // VL53L0X_COMMS_I2C
+ _my_device.comms_speed_khz = 400;
+ _device = &_my_device;
+ expgpio0 = NULL;
+ if (pin_gpio1 != NC) {
+ gpio1Int = new InterruptIn(pin_gpio1);
+ } else {
+ gpio1Int = NULL;
+ }
+ }
+
/** Constructor 2 (STMPE1600DigiOut)
* @param[in] i2c device I2C to be used for communication
* @param[in] &pin Gpio Expander STMPE1600DigiOut pin to be used as component GPIO_0 CE
* @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
- * @param[in] device address, 0x29 by default
- */
- VL53L0X(DevI2C &i2c, STMPE1600DigiOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : dev_i2c(i2c), expgpio0(&pin)
+ * @param[in] device address, 0x29 by default
+ */
+ VL53L0X(DevI2C &i2c, Stmpe1600DigiOut &pin, PinName pin_gpio1,
+ uint8_t dev_addr = DEFAULT_DEVICE_ADDRESS) : dev_i2c(i2c), expgpio0(&pin)
{
- MyDevice.I2cDevAddr=DevAddr;
- MyDevice.comms_type=1; // VL53L0X_COMMS_I2C
- MyDevice.comms_speed_khz=400;
- Device=&MyDevice;
- gpio0=NULL;
- if (pin_gpio1 != NC) { gpio1Int = new InterruptIn(pin_gpio1); }
- else { gpio1Int = NULL; }
- }
-
- /** Destructor
- */
- virtual ~VL53L0X(){
- if (gpio1Int != NULL) delete gpio1Int;
- }
- /* warning: VL53L0X class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
- The warning should request to introduce a virtual destructor to make sure to delete the object */
+ _my_device.I2cDevAddr = dev_addr;
+ _my_device.comms_type = 1; // VL53L0X_COMMS_I2C
+ _my_device.comms_speed_khz = 400;
+ _device = &_my_device;
+ gpio0 = NULL;
+ if (pin_gpio1 != NC) {
+ gpio1Int = new InterruptIn(pin_gpio1);
+ } else {
+ gpio1Int = NULL;
+ }
+ }
- /*** Interface Methods ***/
- /*** High level API ***/
- /**
- * @brief PowerOn the sensor
- * @return void
- */
- /* turns on the sensor */
- void VL53L0X_On(void)
+ /** Destructor
+ */
+ virtual ~VL53L0X()
{
- if (gpio0)
- *gpio0 = 1;
- else if (expgpio0)
+ if (gpio1Int != NULL)
+ delete gpio1Int;
+ }
+
+ /*** Interface Methods ***/
+ /*** High level API ***/
+ /**
+ * @brief PowerOn the sensor
+ * @return void
+ */
+ /* turns on the sensor */
+ void vl53l0x_on(void)
+ {
+ if (gpio0)
+ *gpio0 = 1;
+ else if (expgpio0)
*expgpio0 = 1;
wait_ms(10);
- }
+ }
- /**
- * @brief PowerOff the sensor
- * @return void
- */
+ /**
+ * @brief PowerOff the sensor
+ * @return void
+ */
/* turns off the sensor */
- void VL53L0X_Off(void)
+ void vl53l0x_off(void)
{
- if (gpio0)
- *gpio0 = 0;
- else if (expgpio0)
+ if (gpio0)
+ *gpio0 = 0;
+ else if (expgpio0)
*expgpio0 = 0;
wait_ms(10);
}
-
- /**
- * @brief Initialize the sensor with default values
- * @return 0 on Success
- */
- int InitSensor(uint8_t NewAddr);
+ /**
+ * @brief Initialize the sensor with default values
+ * @return 0 on Success
+ */
+ int init_sensor(uint8_t new_addr);
- int RawInitSensor(void);
- int initDevice(VL53L0X_DEV Dev);
- int setLongRangePresets(VL53L0X_DEV Dev);
- int DoRanging(VL53L0X_Dev_t *pMyDevice);
-
-
-
+ /**
+ * @brief Start the measure indicated by operating mode
+ * @param[in] operating_mode specifies requested measure
+ * @param[in] fptr specifies call back function must be !NULL in case of interrupt measure
+ * @return 0 on Success
+ */
+ int start_measurement(OperatingMode operating_mode, void (*fptr)(void));
- /**
- * @brief Start the measure indicated by operating mode
- * @param[in] operating_mode specifies requested measure
- * @param[in] fptr specifies call back function must be !NULL in case of interrupt measure
- * @return 0 on Success
- */
- int StartMeasurement(OperatingMode operating_mode, void (*fptr)(void));
+ /**
+ * @brief Get results for the measure indicated by operating mode
+ * @param[in] operating_mode specifies requested measure results
+ * @param[out] p_data pointer to the MeasureData_t structure to read data in to
+ * @return 0 on Success
+ */
+ int get_measurement(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *p_data);
- /**
- * @brief Get results for the measure indicated by operating mode
- * @param[in] operating_mode specifies requested measure results
- * @param[out] Data pointer to the MeasureData_t structure to read data in to
- * @return 0 on Success
- */
- int GetMeasurement(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *Data);
+ /**
+ * @brief Stop the currently running measure indicate by operating_mode
+ * @param[in] operating_mode specifies requested measure to stop
+ * @return 0 on Success
+ */
+ int stop_measurement(OperatingMode operating_mode);
- /**
- * @brief Stop the currently running measure indicate by operating_mode
- * @param[in] operating_mode specifies requested measure to stop
- * @return 0 on Success
- */
- int StopMeasurement(OperatingMode operating_mode);
-
- /**
- * @brief Interrupt handling func to be called by user after an INT is occourred
- * @param[in] opeating_mode indicating the in progress measure
- * @param[out] Data pointer to the MeasureData_t structure to read data in to
- * @return 0 on Success
- */
- int HandleIRQ(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *Data);
+ /**
+ * @brief Interrupt handling func to be called by user after an INT is occourred
+ * @param[in] opeating_mode indicating the in progress measure
+ * @param[out] Data pointer to the MeasureData_t structure to read data in to
+ * @return 0 on Success
+ */
+ int handle_irq(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *data);
- /**
- * @brief Enable interrupt measure IRQ
- * @return 0 on Success
- */
- void EnableInterruptMeasureDetectionIRQ(void)
+ /**
+ * @brief Enable interrupt measure IRQ
+ * @return 0 on Success
+ */
+ void enable_interrupt_measure_detection_irq(void)
{
- if (gpio1Int != NULL) gpio1Int->enable_irq();
+ if (gpio1Int != NULL)
+ gpio1Int->enable_irq();
}
- /**
- * @brief Disable interrupt measure IRQ
- * @return 0 on Success
- */
- void DisableInterruptMeasureDetectionIRQ(void)
- {
- if (gpio1Int != NULL) gpio1Int->disable_irq();
- }
- /*** End High level API ***/
-
- /**
- * @brief Attach a function to call when an interrupt is detected, i.e. measurement is ready
- * @param[in] fptr pointer to call back function to be called whenever an interrupt occours
- * @return 0 on Success
- */
- void AttachInterruptMeasureDetectionIRQ(void (*fptr)(void))
- {
- if (gpio1Int != NULL) gpio1Int->rise(fptr);
- }
-
- /**
- * @brief Check the sensor presence
- * @return 1 when device is present
- */
- unsigned Present()
- {
-// return Device->Present;
- return 1;
- }
-
- /** Wrapper functions */
-/** @defgroup api_init Init functions
- * @brief API init functions
- * @ingroup api_hl
- * @{
- */
-/**
- * @brief Wait for device booted after chip enable (hardware standby)
- * @par Function Description
- * After Chip enable Application you can also simply wait at least 1ms to ensure device is ready
- * @warning After device chip enable (gpio0) de-asserted user must wait gpio1 to get asserted (hardware standby).
- * or wait at least 400usec prior to do any low level access or api call .
- *
- * This function implements polling for standby but you must ensure 400usec from chip enable passed\n
- * @warning if device get prepared @a VL53L0X_Prepare() re-using these function can hold indefinitely\n
- *
- * @param void
- * @return 0 on success
- */
- int WaitDeviceBooted()
+ /**
+ * @brief Disable interrupt measure IRQ
+ * @return 0 on Success
+ */
+ void disable_interrupt_measure_detection_irq(void)
{
-// return VL53L0X_WaitDeviceBooted(Device);
- return 1;
- }
-
-
-/**
- *
- * @brief One time device initialization
- *
- * To be called once and only once after device is brought out of reset (Chip enable) and booted see @a VL6180x_WaitDeviceBooted()
- *
- * @par Function Description
- * When not used after a fresh device "power up" or reset, it may return @a #CALIBRATION_WARNING
- * meaning wrong calibration data may have been fetched from device that can result in ranging offset error\n
- * If application cannot execute device reset or need to run VL6180x_InitData multiple time
- * then it must ensure proper offset calibration saving and restore on its own
- * by using @a VL6180x_GetOffsetCalibrationData() on first power up and then @a VL6180x_SetOffsetCalibrationData() all all subsequent init
- *
- * @param void
- * @return 0 on success, @a #CALIBRATION_WARNING if failed
- */
- virtual int init(void *init)
- {
- return VL53L0X_DataInit(Device);
- }
-
-/** deprecated Init function from ComponentObject. for backward compatibility
-*/
- virtual int Init(void * NewAddr)
- {
- return init(NewAddr);
- }
-
-/**
- * @brief Configure GPIO1 function and set polarity.
- * @par Function Description
- * To be used prior to arm single shot measure or start continuous mode.
- *
- * The function uses @a VL6180x_SetupGPIOx() for setting gpio 1.
- * @warning changing polarity can generate a spurious interrupt on pins.
- * It sets an interrupt flags condition that must be cleared to avoid polling hangs. \n
- * It is safe to run VL6180x_ClearAllInterrupt() just after.
- *
- * @param IntFunction The interrupt functionality to use one of :\n
- * @a #GPIOx_SELECT_OFF \n
- * @a #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT
- * @param ActiveHigh The interrupt line polarity see ::IntrPol_e
- * use @a #INTR_POL_LOW (falling edge) or @a #INTR_POL_HIGH (rising edge)
- * @return 0 on success
- */
- int SetupGPIO1(uint8_t InitFunction, int ActiveHigh)
- {
-// return VL6180x_SetupGPIO1(Device, InitFunction, ActiveHigh);
- return 1;
+ if (gpio1Int != NULL)
+ gpio1Int->disable_irq();
}
-/**
- * @brief Prepare device for operation
- * @par Function Description
- * Does static initialization and reprogram common default settings \n
- * Device is prepared for new measure, ready single shot ranging or ALS typical polling operation\n
- * After prepare user can : \n
- * @li Call other API function to set other settings\n
- * @li Configure the interrupt pins, etc... \n
- * @li Then start ranging or ALS operations in single shot or continuous mode
- *
- * @param void
- * @return 0 on success
- */
- int Prepare()
+ /**
+ * @brief Attach a function to call when an interrupt is detected, i.e. measurement is ready
+ * @param[in] fptr pointer to call back function to be called whenever an interrupt occours
+ * @return 0 on Success
+ */
+ void attach_interrupt_measure_detection_irq(void (*fptr)(void))
{
- VL53L0X_Error Status = VL53L0X_ERROR_NONE;
- uint32_t refSpadCount;
- uint8_t isApertureSpads;
- uint8_t VhvSettings;
- uint8_t PhaseCal;
-
- if(Status == VL53L0X_ERROR_NONE)
- {
- printf ("Call of VL53L0X_StaticInit\n");
- Status = VL53L0X_StaticInit(Device); // Device Initialization
- }
-
- if(Status == VL53L0X_ERROR_NONE)
- {
- printf ("Call of VL53L0X_PerformRefCalibration\n");
- Status = VL53L0X_PerformRefCalibration(Device,
- &VhvSettings, &PhaseCal); // Device Initialization
- }
-
- if(Status == VL53L0X_ERROR_NONE)
- {
- printf ("Call of VL53L0X_PerformRefSpadManagement\n");
- Status = VL53L0X_PerformRefSpadManagement(Device,
- &refSpadCount, &isApertureSpads); // Device Initialization
-// printf ("refSpadCount = %d, isApertureSpads = %d\n", refSpadCount, isApertureSpads);
- }
-
- return Status;
+ if (gpio1Int != NULL)
+ gpio1Int->rise(fptr);
}
- /**
- * @brief Start continuous ranging mode
- *
- * @details End user should ensure device is in idle state and not already running
- * @return 0 on success
- */
- int RangeStartContinuousMode()
- {
- int status;
- status = VL53L0X_SetDeviceMode(Device, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING);
-
- if(status == VL53L0X_ERROR_NONE)
- {
- printf ("Call of VL53L0X_StartMeasurement\n");
- status = VL53L0X_StartMeasurement(Device);
- }
-
- return status;
- }
+ /** Wrapper functions */
+ /** @defgroup api_init Init functions
+ * @brief API init functions
+ * @ingroup api_hl
+ * @{
+ */
-/**
- * @brief Start single shot ranging measure
- *
- * @details End user should ensure device is in idle state and not already running
- * @return 0 on success
- */
- int RangeStartSingleShot()
+ /**
+ *
+ * @brief One time device initialization
+ *
+ * To be called once and only once after device is brought out of reset (Chip enable) and booted.
+ *
+ * @par Function Description
+ * When not used after a fresh device "power up" or reset, it may return @a #CALIBRATION_WARNING
+ * meaning wrong calibration data may have been fetched from device that can result in ranging offset error\n
+ * If application cannot execute device reset or need to run vl53l0x_data_init multiple time
+ * then it must ensure proper offset calibration saving and restore on its own
+ * by using @a vl53l0x_get_offset_calibration_data_micro_meter() on first power up and then @a vl53l0x_set_offset_calibration_data_micro_meter() all all subsequent init
+ *
+ * @param void
+ * @return 0 on success, @a #CALIBRATION_WARNING if failed
+ */
+ virtual int init(void *init)
{
-// return VL6180x_RangeStartSingleShot(Device);
- return 1;
- }
-
-/**
- * @brief Set maximum convergence time
- *
- * @par Function Description
- * Setting a low convergence time can impact maximal detectable distance.
- * Refer to VL6180x Datasheet Table 7 : Typical range convergence time.
- * A typical value for up to x3 scaling is 50 ms
- *
- * @param MaxConTime_msec
- * @return 0 on success. <0 on error. >0 for calibration warning status
- */
- int RangeSetMaxConvergenceTime(uint8_t MaxConTime_msec)
- {
-// return VL6180x_RangeSetMaxConvergenceTime(Device, MaxConTime_msec);
- return 1;
+ return vl53l0x_data_init(_device);
}
-/**
- * @brief Single shot Range measurement in polling mode.
- *
- * @par Function Description
- * Kick off a new single shot range then wait for ready to retrieve it by polling interrupt status \n
- * Ranging must be prepared by a first call to @a VL6180x_Prepare() and it is safer to clear very first poll call \n
- * This function reference VL6180x_PollDelay(dev) porting macro/call on each polling loop,
- * but PollDelay(dev) may never be called if measure in ready on first poll loop \n
- * Should not be use in continuous mode operation as it will stop it and cause stop/start misbehaviour \n
- * \n This function clears Range Interrupt status , but not error one. For that uses @a VL6180x_ClearErrorInterrupt() \n
- * This range error is not related VL6180x_RangeData_t::errorStatus that refer measure status \n
- *
- * @param pRangeData Will be populated with the result ranging data @a VL6180x_RangeData_t
- * @return 0 on success , @a #RANGE_ERROR if device reports an error case in it status (not cleared) use
- *
- * \sa ::VL6180x_RangeData_t
- */
- int RangePollMeasurement(VL53L0X_RangingMeasurementData_t *pRangeData)
+ /**
+ * @brief Prepare device for operation
+ * @par Function Description
+ * Does static initialization and reprogram common default settings \n
+ * Device is prepared for new measure, ready single shot ranging or ALS typical polling operation\n
+ * After prepare user can : \n
+ * @li Call other API function to set other settings\n
+ * @li Configure the interrupt pins, etc... \n
+ * @li Then start ranging or ALS operations in single shot or continuous mode
+ *
+ * @param void
+ * @return 0 on success
+ */
+ int prepare()
{
-// return VL6180x_RangePollMeasurement(Device, pRangeData);
- return 1;
- }
-
-/**
- * @brief Check for measure readiness and get it if ready
- *
- * @par Function Description
- * Using this function is an alternative to @a VL6180x_RangePollMeasurement() to avoid polling operation. This is suitable for applications
- * where host CPU is triggered on a interrupt (not from VL6180X) to perform ranging operation. In this scenario, we assume that the very first ranging
- * operation is triggered by a call to @a VL6180x_RangeStartSingleShot(). Then, host CPU regularly calls @a VL6180x_RangeGetMeasurementIfReady() to
- * get a distance measure if ready. In case the distance is not ready, host may get it at the next call.\n
- *
- * @warning
- * This function does not re-start a new measurement : this is up to the host CPU to do it.\n
- * This function clears Range Interrupt for measure ready , but not error interrupts. For that, uses @a VL6180x_ClearErrorInterrupt() \n
- *
- * @param pRangeData Will be populated with the result ranging data if available
- * @return 0 when measure is ready pRange data is updated (untouched when not ready), >0 for warning and @a #NOT_READY if measurement not yet ready, <0 for error @a #RANGE_ERROR if device report an error,
- */
- int RangeGetMeasurementIfReady(VL53L0X_RangingMeasurementData_t *pRangeData)
- {
-// return VL6180x_RangeGetMeasurementIfReady(Device, pRangeData);
- return 1;
- }
+ VL53L0X_Error status = VL53L0X_ERROR_NONE;
+ uint32_t ref_spad_count;
+ uint8_t is_aperture_spads;
+ uint8_t vhv_settings;
+ uint8_t phase_cal;
-/**
- * @brief Retrieve range measurements set from device
- *
- * @par Function Description
- * The measurement is made of range_mm status and error code @a VL6180x_RangeData_t \n
- * Based on configuration selected extra measures are included.
- *
- * @warning should not be used in continuous if wrap around filter is active \n
- * Does not perform any wait nor check for result availability or validity.
- *\sa VL6180x_RangeGetResult for "range only" measurement
- *
- * @param pRangeData Pointer to the data structure to fill up
- * @return 0 on success
- */
- int RangeGetMeasurement(VL53L0X_RangingMeasurementData_t *pRangeData)
- {
-// return VL6180x_RangeGetMeasurement(Device, pRangeData);
- return 1;
- }
+ if (status == VL53L0X_ERROR_NONE) {
+ printf("Call of VL53L0X_StaticInit\n");
+ status = vl53l0x_static_init(_device); // Device Initialization
+ }
-/**
- * @brief Get ranging result and only that
- *
- * @par Function Description
- * Unlike @a VL6180x_RangeGetMeasurement() this function only retrieves the range in millimeter \n
- * It does any required up-scale translation\n
- * It can be called after success status polling or in interrupt mode \n
- * @warning these function is not doing wrap around filtering \n
- * This function doesn't perform any data ready check!
- *
- * @param pRange_mm Pointer to range distance
- * @return 0 on success
- */
- virtual int get_distance(uint32_t *piData)
- {
- int status=0;
- VL53L0X_RangingMeasurementData_t pRangingMeasurementData;
+ if (status == VL53L0X_ERROR_NONE) {
+ printf("Call of VL53L0X_PerformRefCalibration\n");
+ status = vl53l0x_perform_ref_calibration(_device,
+ &vhv_settings, &phase_cal); // Device Initialization
+ }
- status=StartMeasurement(range_single_shot_polling, NULL);
- if (!status) {
- status=GetMeasurement(range_single_shot_polling, &pRangingMeasurementData);
+ if (status == VL53L0X_ERROR_NONE) {
+ printf("Call of VL53L0X_PerformRefSpadManagement\n");
+ status = vl53l0x_perform_ref_spad_management(_device,
+ &ref_spad_count, &is_aperture_spads); // Device Initialization
+// printf ("refSpadCount = %d, isApertureSpads = %d\n", refSpadCount, isApertureSpads);
}
- if (pRangingMeasurementData.RangeStatus == 0) {
- // we have a valid range.
- *piData = pRangingMeasurementData.RangeMilliMeter;
- }
- else {
- *piData = 0;
- status = VL53L0X_ERROR_RANGE_ERROR;
- }
- StopMeasurement(range_single_shot_polling);
+
return status;
}
-/* Deprecated function from RangeSensor class. For backward compatibility*/
- virtual int GetDistance(uint32_t *piData)
- {
- return get_distance(piData);
- }
-/**
- * @brief Configure ranging interrupt reported to application
- *
- * @param ConfigGpioInt Select ranging report\n select one (and only one) of:\n
- * @a #CONFIG_GPIO_INTERRUPT_DISABLED \n
- * @a #CONFIG_GPIO_INTERRUPT_LEVEL_LOW \n
- * @a #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH \n
- * @a #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW \n
- * @a #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY
- * @return 0 on success
- */
- int RangeConfigInterrupt(uint8_t ConfigGpioInt)
- {
- int status = VL53L0X_ERROR_NONE;
-/* if( ConfigGpioInt<= VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY)
- {
- status = VL53L0X_UpdateByte(Device, VL53L0X_REG_SYSTEM_INTERRUPT_CONFIG_GPIO, (uint8_t)(~(0x7<<0)), ConfigGpioInt);
- }
- else
- {
- status = 1;
- }
-*/
-// return VL6180x_RangeConfigInterrupt(Device, ConfigGpioInt);
- return status;
- }
-
-/**
- * @brief Return ranging error interrupt status
- *
- * @par Function Description
- * Appropriate Interrupt report must have been selected first by @a VL6180x_RangeConfigInterrupt() or @a VL6180x_Prepare() \n
- *
- * Can be used in polling loop to wait for a given ranging event or in interrupt to read the trigger \n
- * Events triggers are : \n
- * @a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n
- * @a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n
- * @a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n (RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD|RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD)
- * @a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY \n
- *
- * @sa IntrStatus_t
- * @param pIntStatus Pointer to status variable to update
- * @return 0 on success
- */
- int RangeGetInterruptStatus(uint8_t *pIntStatus)
- {
-// return VL6180x_RangeGetInterruptStatus(Device, pIntStatus);
- return 1;
- }
-
-/**
- * @brief Low level ranging and ALS register static settings (you should call @a VL6180x_Prepare() function instead)
- *
- * @return 0 on success
- */
- int StaticInit()
- {
-// return VL6180x_StaticInit(Device);
- return 1;
- }
-
-/**
- * @brief Wait for device to be ready (before a new ranging command can be issued by application)
- * @param MaxLoop Max Number of i2c polling loop see @a #msec_2_i2cloop
- * @return 0 on success. <0 when fail \n
- * @ref VL6180x_ErrCode_t::TIME_OUT for time out \n
- * @ref VL6180x_ErrCode_t::INVALID_PARAMS if MaxLop<1
- */
- int RangeWaitDeviceReady(int MaxLoop )
- {
-// return VL6180x_RangeWaitDeviceReady(Device, MaxLoop);
- return 1;
- }
-/**
- * @brief Program Inter measurement period (used only in continuous mode)
- *
- * @par Function Description
- * When trying to set too long time, it returns #INVALID_PARAMS
- *
- * @param InterMeasTime_msec Requires inter-measurement time in msec
- * @return 0 on success
- */
- int RangeSetInterMeasPeriod(uint32_t InterMeasTime_msec)
+ /**
+ * @brief Start continuous ranging mode
+ *
+ * @details End user should ensure device is in idle state and not already running
+ * @return 0 on success
+ */
+ int range_start_continuous_mode()
{
-// return VL6180x_RangeSetInterMeasPeriod(Device, InterMeasTime_msec);
- return 1;
- }
-
-/**
- * @brief Set device ranging scaling factor
- *
- * @par Function Description
- * The ranging scaling factor is applied on the raw distance measured by the device to increase operating ranging at the price of the precision.
- * Changing the scaling factor when device is not in f/w standby state (free running) is not safe.
- * It can be source of spurious interrupt, wrongly scaled range etc ...
- * @warning __This function doesns't update high/low threshold and other programmed settings linked to scaling factor__.
- * To ensure proper operation, threshold and scaling changes should be done following this procedure: \n
- * @li Set Group hold : @a VL6180x_SetGroupParamHold() \n
- * @li Get Threshold @a VL6180x_RangeGetThresholds() \n
- * @li Change scaling : @a VL6180x_UpscaleSetScaling() \n
- * @li Set Threshold : @a VL6180x_RangeSetThresholds() \n
- * @li Unset Group Hold : @a VL6180x_SetGroupParamHold()
- *
- * @param scaling Scaling factor to apply (1,2 or 3)
- * @return 0 on success when up-scale support is not configured it fail for any
- * scaling than the one statically configured.
- */
- int UpscaleSetScaling(uint8_t scaling)
- {
-// return VL6180x_UpscaleSetScaling(Device, scaling);
- return 1;
- }
+ int status;
+ status = vl53l0x_set_device_mode(_device, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING);
-/**
- * @brief Get current ranging scaling factor
- *
- * @return The current scaling factor
- */
- int UpscaleGetScaling()
- {
-// return VL6180x_UpscaleGetScaling(Device);
- return 1;
- }
+ if(status == VL53L0X_ERROR_NONE) {
+ printf ("Call of VL53L0X_StartMeasurement\n");
+ status = vl53l0x_start_measurement(_device);
+ }
-/**
- * @brief Get the maximal distance for actual scaling
- * @par Function Description
- * Do not use prior to @a VL6180x_Prepare() or at least @a VL6180x_InitData()
- *
- * Any range value more than the value returned by this function is to be considered as "no target detected"
- * or "no target in detectable range" \n
- * @warning The maximal distance depends on the scaling
- *
- * @return The maximal range limit for actual mode and scaling
- */
- uint16_t GetUpperLimit()
- {
-// return VL6180x_GetUpperLimit(Device);
- return 1;
- }
-
-/**
- * @brief Apply low and high ranging thresholds that are considered only in continuous mode
- *
- * @par Function Description
- * This function programs low and high ranging thresholds that are considered in continuous mode :
- * interrupt will be raised only when an object is detected at a distance inside this [low:high] range.
- * The function takes care of applying current scaling factor if any.\n
- * To be safe, in continuous operation, thresholds must be changed under "group parameter hold" cover.
- * Group hold can be activated/deactivated directly in the function or externally (then set 0)
- * using /a VL6180x_SetGroupParamHold() function.
- *
- * @param low Low threshold in mm
- * @param high High threshold in mm
- * @param SafeHold Use of group parameters hold to surround threshold programming.
- * @return 0 On success
- */
- int RangeSetThresholds(uint16_t low, uint16_t high, int SafeHold)
- {
-// return VL6180x_RangeSetThresholds(Device, low, high, SafeHold);
- return 1;
+ return status;
}
-/**
- * @brief Get scaled high and low threshold from device
- *
- * @par Function Description
- * Due to scaling factor, the returned value may be different from what has been programmed first (precision lost).
- * For instance VL6180x_RangeSetThresholds(dev,11,22) with scale 3
- * will read back 9 ((11/3)x3) and 21 ((22/3)x3).
- *
- * @param low scaled low Threshold ptr can be NULL if not needed
- * @param high scaled High Threshold ptr can be NULL if not needed
- * @return 0 on success, return value is undefined if both low and high are NULL
- * @warning return value is undefined if both low and high are NULL
- */
- int RangeGetThresholds(uint16_t *low, uint16_t *high)
- {
-// return VL6180x_RangeGetThresholds(Device, low, high);
- return 1;
- }
-
-/**
- * @brief Set ranging raw thresholds (scaling not considered so not recommended to use it)
- *
- * @param low raw low threshold set to raw register
- * @param high raw high threshold set to raw register
- * @return 0 on success
- */
- int RangeSetRawThresholds(uint8_t low, uint8_t high)
- {
-// return VL6180x_RangeSetRawThresholds(Device, low, high);
- return 1;
- }
-
-/**
- * @brief Set Early Convergence Estimate ratio
- * @par Function Description
- * For more information on ECE check datasheet
- * @warning May return a calibration warning in some use cases
- *
- * @param FactorM ECE factor M in M/D
- * @param FactorD ECE factor D in M/D
- * @return 0 on success. <0 on error. >0 on warning
- */
- int RangeSetEceFactor(uint16_t FactorM, uint16_t FactorD)
+ /**
+ * @brief Get ranging result and only that
+ *
+ * @par Function Description
+ * Unlike @a vl53l0x_get_ranging_measurement_data() this function only retrieves the range in millimeter \n
+ * It does any required up-scale translation\n
+ * It can be called after success status polling or in interrupt mode \n
+ * @warning these function is not doing wrap around filtering \n
+ * This function doesn't perform any data ready check!
+ *
+ * @param p_data Pointer to range distance
+ * @return 0 on success
+ */
+ virtual int get_distance(uint32_t *p_data)
{
-// return VL6180x_RangeSetEceFactor(Device, FactorM, FactorD);
- return 1;
- }
-
-/**
- * @brief Set Early Convergence Estimate state (See #SYSRANGE_RANGE_CHECK_ENABLES register)
- * @param enable State to be set 0=disabled, otherwise enabled
- * @return 0 on success
- */
- int RangeSetEceState(int enable)
- {
-// return VL6180x_RangeSetEceState(Device, enable);
- return 1;
- }
+ int status = 0;
+ VL53L0X_RangingMeasurementData_t p_ranging_measurement_data;
-/**
- * @brief Set activation state of the wrap around filter
- * @param state New activation state (0=off, otherwise on)
- * @return 0 on success
- */
- int FilterSetState(int state)
- {
-// return VL6180x_FilterSetState(Device, state);
- return 1;
- }
-
-/**
- * Get activation state of the wrap around filter
- * @return Filter enabled or not, when filter is not supported it always returns 0S
- */
- int FilterGetState()
- {
-// return VL6180x_FilterGetState(Device);
- return 1;
- }
-
-/**
- * @brief Set activation state of DMax computation
- * @param state New activation state (0=off, otherwise on)
- * @return 0 on success
- */
- int DMaxSetState(int state)
- {
-// return VL6180x_DMaxSetState(Device, state);
- return 1;
+ status = start_measurement(range_single_shot_polling, NULL);
+ if (!status) {
+ status = get_measurement(range_single_shot_polling, &p_ranging_measurement_data);
+ }
+ if (p_ranging_measurement_data.RangeStatus == 0) {
+ // we have a valid range.
+ *p_data = p_ranging_measurement_data.RangeMilliMeter;
+ } else {
+ *p_data = 0;
+ status = VL53L0X_ERROR_RANGE_ERROR;
+ }
+ stop_measurement(range_single_shot_polling);
+ return status;
}
-/**
- * Get activation state of DMax computation
- * @return Filter enabled or not, when filter is not supported it always returns 0S
- */
- int DMaxGetState()
- {
-// return VL6180x_DMaxGetState(Device);
- return 1;
- }
-
-/**
- * @brief Set ranging mode and start/stop measure (use high level functions instead : @a VL6180x_RangeStartSingleShot() or @a VL6180x_RangeStartContinuousMode())
- *
- * @par Function Description
- * When used outside scope of known polling single shot stopped state, \n
- * user must ensure the device state is "idle" before to issue a new command.
- *
- * @param mode A combination of working mode (#MODE_SINGLESHOT or #MODE_CONTINUOUS) and start/stop condition (#MODE_START_STOP) \n
- * @return 0 on success
- */
- int RangeSetSystemMode(uint8_t mode)
- {
- int status;
- /* FIXME we are not checking device is ready via @a VL6180X_RangeWaitDeviceReady
- * so if called back to back real fast we are not checking
- * if previous mode "set" got absorbed => bit 0 must be 0 so that it work
- */
- if( mode <= 3){
- status=VL53L0X_WrByte(Device, VL53L0X_REG_SYSRANGE_START, mode);
- if( status ){
- VL53L0X_ErrLog("SYSRANGE_START wr fail");
- }
- }
- else{
- status = 1;
- }
- return status;
-// return VL6180x_RangeSetSystemMode(Device, mode);
-// return 1;
- }
-
-/** @} */
+ /** @} */
-/** @defgroup api_ll_range_calibration Ranging calibration functions
- * @brief Ranging calibration functions
- * @ingroup api_ll
- * @{
- */
-/**
- * @brief Get part to part calibration offset
- *
- * @par Function Description
- * Should only be used after a successful call to @a VL6180x_InitData to backup device nvm value
- *
- * @return part to part calibration offset from device
- */
- int8_t GetOffsetCalibrationData()
+ /**
+ * @brief Set new device i2c address
+ *
+ * After completion the device will answer to the new address programmed.
+ *
+ * @param new_addr The new i2c address (7bit)
+ * @return 0 on success
+ */
+ int set_device_address(int new_addr)
{
-// return VL6180x_GetOffsetCalibrationData(Device);
- return 1;
- }
-
-/**
- * Set or over-write part to part calibration offset
- * \sa VL6180x_InitData(), VL6180x_GetOffsetCalibrationData()
- * @param offset Offset
- */
- void SetOffsetCalibrationData(int8_t offset)
- {
-// return VL6180x_SetOffsetCalibrationData(Device, offset);
- return;
- }
+ int status;
-/**
- * @brief Set Cross talk compensation rate
- *
- * @par Function Description
- * It programs register @a #SYSRANGE_CROSSTALK_COMPENSATION_RATE
- *
- * @param Rate Compensation rate (9.7 fix point) see datasheet for details
- * @return 0 on success
- */
- int SetXTalkCompensationRate(uint16_t Rate)
- {
-// return VL6180x_SetXTalkCompensationRate(Device, Rate);
- return 1;
- }
-/** @} */
-
-/**
- * @brief Set new device i2c address
- *
- * After completion the device will answer to the new address programmed.
- *
- * @sa AN4478: Using multiple VL6180X's in a single design
- * @param NewAddr The new i2c address (7bit)
- * @return 0 on success
- */
- int SetDeviceAddress(int NewAddr)
- {
- int status;
-
- status=VL53L0X_SetDeviceAddress(Device, NewAddr);
- if(!status)
- Device->I2cDevAddr=NewAddr;
- return status;
+ status = vl53l0x_set_device_address(_device, new_addr);
+ if (!status)
+ _device->I2cDevAddr = new_addr;
+ return status;
}
-/**
- * @brief Fully configure gpio 0/1 pin : polarity and functionality
- *
- * @param pin gpio pin 0 or 1
- * @param IntFunction Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
- * @param ActiveHigh Set active high polarity, or active low see @a ::IntrPol_e
- * @return 0 on success
- */
- int SetupGPIOx(int pin, uint8_t IntFunction, int ActiveHigh)
- {
-// return VL6180x_SetupGPIOx(Device, pin, IntFunction, ActiveHigh);
- return 1;
- }
-
-/**
- * @brief Set interrupt pin polarity for the given GPIO
- *
- * @param pin Pin 0 or 1
- * @param active_high select active high or low polarity using @ref IntrPol_e
- * @return 0 on success
- */
- int SetGPIOxPolarity(int pin, int active_high)
- {
-// return VL6180x_SetGPIOxPolarity(Device, pin, active_high);
- return 1;
- }
-
-/**
- * Select interrupt functionality for the given GPIO
- *
- * @par Function Description
- * Functionality refer to @a SYSTEM_MODE_GPIO0
- *
- * @param pin Pin to configure 0 or 1 (gpio0 or gpio1)\nNote that gpio0 is chip enable at power up !
- * @param functionality Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
- * @return 0 on success
- */
- int SetGPIOxFunctionality(int pin, uint8_t functionality)
+ /**
+ * @brief Clear given system interrupt condition
+ *
+ * @par Function Description
+ * Clear given interrupt cause by writing into register #SYSTEM_INTERRUPT_CLEAR register.
+ * @param dev The device
+ * @param int_clear Which interrupt source to clear. Use any combinations of #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ALS , #INTERRUPT_CLEAR_ERROR.
+ * @return 0 On success
+ */
+ int clear_interrupt(uint8_t int_clear)
{
-// return VL6180x_SetGPIOxFunctionality(Device, pin, functionality);
- return 1;
- }
-
-/**
- * #brief Disable and turn to Hi-Z gpio output pin
- *
- * @param pin The pin number to disable 0 or 1
- * @return 0 on success
- */
- int DisableGPIOxOut(int pin)
- {
-// return VL6180x_DisableGPIOxOut(Device, pin);
- return 1;
- }
-
-/** @} */
-
-/** @defgroup api_ll_intr Interrupts management functions
- * @brief Interrupts management functions
- * @ingroup api_ll
- * @{
- */
-
-/**
- * @brief Get all interrupts cause
- *
- * @param status Ptr to interrupt status. You can use @a IntrStatus_t::val
- * @return 0 on success
- */
- int GetInterruptStatus(uint8_t *status)
- {
-// return VL6180x_GetInterruptStatus(Device, status);
- return 1;
- }
-
-/**
- * @brief Clear given system interrupt condition
- *
- * @par Function Description
- * Clear given interrupt cause by writing into register #SYSTEM_INTERRUPT_CLEAR register.
- * @param dev The device
- * @param IntClear Which interrupt source to clear. Use any combinations of #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ALS , #INTERRUPT_CLEAR_ERROR.
- * @return 0 On success
- */
- int ClearInterrupt(uint8_t IntClear)
- {
- int status = VL53L0X_WrByte(Device, VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR, IntClear);
-// return VL6180x_ClearInterrupt(Device, IntClear );
- return status;
+ return vl53l0x_clear_interrupt_mask(_device, int_clear);
}
-/**
- * @brief Clear error interrupt
- *
- * @param dev The device
- * @return 0 On success
- */
- #define VL6180x_ClearErrorInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR)
+ /**
+ *
+ * @brief One time device initialization
+ *
+ * To be called once and only once after device is brought out of reset
+ * (Chip enable) and booted see @a VL53L0X_WaitDeviceBooted()
+ *
+ * @par Function Description
+ * When not used after a fresh device "power up" or reset, it may return
+ * @a #VL53L0X_ERROR_CALIBRATION_WARNING meaning wrong calibration data
+ * may have been fetched from device that can result in ranging offset error\n
+ * If application cannot execute device reset or need to run VL53L0X_DataInit
+ * multiple time then it must ensure proper offset calibration saving and
+ * restore on its own by using @a VL53L0X_GetOffsetCalibrationData() on first
+ * power up and then @a VL53L0X_SetOffsetCalibrationData() in all subsequent init
+ * This function will change the VL53L0X_State from VL53L0X_STATE_POWERDOWN to
+ * VL53L0X_STATE_WAIT_STATICINIT.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_data_init(VL53L0X_DEV dev);
+
+ /**
+ * @brief Do basic device init (and eventually patch loading)
+ * This function will change the VL53L0X_State from
+ * VL53L0X_STATE_WAIT_STATICINIT to VL53L0X_STATE_IDLE.
+ * In this stage all default setting will be applied.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_static_init(VL53L0X_DEV dev);
+
+ /**
+ * @brief Perform Reference Calibration
+ *
+ * @details Perform a reference calibration of the Device.
+ * This function should be run from time to time before doing
+ * a ranging measurement.
+ * This function will launch a special ranging measurement, so
+ * if interrupt are enable an interrupt will be done.
+ * This function will clear the interrupt generated automatically.
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_vhv_settings Pointer to vhv settings parameter.
+ * @param p_phase_cal Pointer to PhaseCal parameter.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_perform_ref_calibration(VL53L0X_DEV dev, uint8_t *p_vhv_settings,
+ uint8_t *p_phase_cal);
+
+ /**
+ * @brief Get Reference Calibration Parameters
+ *
+ * @par Function Description
+ * Get Reference Calibration Parameters.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_vhv_settings Pointer to VHV parameter
+ * @param p_phase_cal Pointer to PhaseCal Parameter
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_ref_calibration(VL53L0X_DEV dev,
+ uint8_t *p_vhv_settings, uint8_t *p_phase_cal);
+
+ VL53L0X_Error vl53l0x_set_ref_calibration(VL53L0X_DEV dev,
+ uint8_t vhv_settings, uint8_t phase_cal);
+
+ /**
+ * @brief Performs Reference Spad Management
+ *
+ * @par Function Description
+ * The reference SPAD initialization procedure determines the minimum amount
+ * of reference spads to be enables to achieve a target reference signal rate
+ * and should be performed once during initialization.
+ *
+ * @note This function Access to the device
+ *
+ * @note This function change the device mode to
+ * VL53L0X_DEVICEMODE_SINGLE_RANGING
+ *
+ * @param dev Device Handle
+ * @param ref_spad_count Reports ref Spad Count
+ * @param is_aperture_spads Reports if spads are of type
+ * aperture or non-aperture.
+ * 1:=aperture, 0:=Non-Aperture
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_REF_SPAD_INIT Error in the Ref Spad procedure.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_perform_ref_spad_management(VL53L0X_DEV dev,
+ uint32_t *ref_spad_count, uint8_t *is_aperture_spads);
+
+ /**
+ * @brief Applies Reference SPAD configuration
+ *
+ * @par Function Description
+ * This function applies a given number of reference spads, identified as
+ * either Aperture or Non-Aperture.
+ * The requested spad count and type are stored within the device specific
+ * parameters data for access by the host.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param refSpadCount Number of ref spads.
+ * @param is_aperture_spads Defines if spads are of type
+ * aperture or non-aperture.
+ * 1:=aperture, 0:=Non-Aperture
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_REF_SPAD_INIT Error in the in the reference
+ * spad configuration.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_reference_spads(VL53L0X_DEV dev,
+ uint32_t refSpadCount, uint8_t is_aperture_spads);
+
+ /**
+ * @brief Retrieves SPAD configuration
+ *
+ * @par Function Description
+ * This function retrieves the current number of applied reference spads
+ * and also their type : Aperture or Non-Aperture.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_spad_count Number ref Spad Count
+ * @param p_is_aperture_spads Reports if spads are of type
+ * aperture or non-aperture.
+ * 1:=aperture, 0:=Non-Aperture
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_REF_SPAD_INIT Error in the in the reference
+ * spad configuration.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_reference_spads(VL53L0X_DEV dev,
+ uint32_t *p_spad_count, uint8_t *p_is_aperture_spads);
+
+ /**
+ * @brief Get part to part calibration offset
+ *
+ * @par Function Description
+ * Should only be used after a successful call to @a VL53L0X_DataInit to backup
+ * device NVM value
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_offset_calibration_data_micro_meter Return part to part
+ * calibration offset from device (microns)
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
+ int32_t *p_offset_calibration_data_micro_meter);
+ /**
+ * Set or over-hide part to part calibration offset
+ * \sa VL53L0X_DataInit() VL53L0X_GetOffsetCalibrationDataMicroMeter()
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_offset_calibration_data_micro_meter Offset (microns)
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
+ int32_t offset_calibration_data_micro_meter);
+
+ VL53L0X_Error vl53l0x_perform_offset_calibration(VL53L0X_DEV dev,
+ FixPoint1616_t cal_distance_milli_meter,
+ int32_t *p_offset_micro_meter);
+
+ VL53L0X_Error vl53l0x_perform_xtalk_calibration(VL53L0X_DEV dev,
+ FixPoint1616_t xtalk_cal_distance,
+ FixPoint1616_t *p_xtalk_compensation_rate_mega_cps);
+
+ /**
+ * @brief Perform XTalk Measurement
+ *
+ * @details Measures the current cross talk from glass in front
+ * of the sensor.
+ * This functions performs a histogram measurement and uses the results
+ * to measure the crosstalk. For the function to be successful, there
+ * must be no target in front of the sensor.
+ *
+ * @warning This function is a blocking function
+ *
+ * @warning This function is not supported when the final range
+ * vcsel clock period is set below 10 PCLKS.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param timeout_ms Histogram measurement duration.
+ * @param p_xtalk_per_spad Output parameter containing the crosstalk
+ * measurement result, in MCPS/Spad. Format fixpoint 16:16.
+ * @param p_ambient_too_high Output parameter which indicate that
+ * pXtalkPerSpad is not good if the Ambient is too high.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS vcsel clock period not supported
+ * for this operation. Must not be less than 10PCLKS.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_perform_xtalk_measurement(VL53L0X_DEV dev,
+ uint32_t timeout_ms, FixPoint1616_t *p_xtalk_per_spad,
+ uint8_t *p_ambient_too_high);
+
+ /**
+ * @brief Enable/Disable Cross talk compensation feature
+ *
+ * @note This function is not Implemented.
+ * Enable/Disable Cross Talk by set to zero the Cross Talk value
+ * by using @a VL53L0X_SetXTalkCompensationRateMegaCps().
+ *
+ * @param dev Device Handle
+ * @param x_talk_compensation_enable Cross talk compensation
+ * to be set 0=disabled else = enabled
+ * @return VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+ VL53L0X_Error vl53l0x_set_x_talk_compensation_enable(VL53L0X_DEV dev,
+ uint8_t x_talk_compensation_enable);
+
+ /**
+ * @brief Get Cross talk compensation rate
+ *
+ * @note This function is not Implemented.
+ * Enable/Disable Cross Talk by set to zero the Cross Talk value by
+ * using @a VL53L0X_SetXTalkCompensationRateMegaCps().
+ *
+ * @param dev Device Handle
+ * @param p_x_talk_compensation_enable Pointer to the Cross talk compensation
+ * state 0=disabled or 1 = enabled
+ * @return VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+ VL53L0X_Error vl53l0x_get_x_talk_compensation_enable(VL53L0X_DEV dev,
+ uint8_t *p_x_talk_compensation_enable);
+ /**
+ * @brief Set Cross talk compensation rate
+ *
+ * @par Function Description
+ * Set Cross talk compensation rate.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param x_talk_compensation_rate_mega_cps Compensation rate in
+ * Mega counts per second (16.16 fix point) see datasheet for details
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_x_talk_compensation_rate_mega_cps(VL53L0X_DEV dev,
+ FixPoint1616_t x_talk_compensation_rate_mega_cps);
+
+ /**
+ * @brief Get Cross talk compensation rate
+ *
+ * @par Function Description
+ * Get Cross talk compensation rate.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_xtalk_compensation_rate_mega_cps Pointer to Compensation rate
+ in Mega counts per second (16.16 fix point) see datasheet for details
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_x_talk_compensation_rate_mega_cps(VL53L0X_DEV dev,
+ FixPoint1616_t *p_xtalk_compensation_rate_mega_cps);
+
+ /**
+ * @brief Set a new device mode
+ * @par Function Description
+ * Set device to a new mode (ranging, histogram ...)
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param dev Device Handle
+ * @param device_mode New device mode to apply
+ * Valid values are:
+ * VL53L0X_DEVICEMODE_SINGLE_RANGING
+ * VL53L0X_DEVICEMODE_CONTINUOUS_RANGING
+ * VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING
+ * VL53L0X_DEVICEMODE_SINGLE_HISTOGRAM
+ * VL53L0X_HISTOGRAMMODE_REFERENCE_ONLY
+ * VL53L0X_HISTOGRAMMODE_RETURN_ONLY
+ * VL53L0X_HISTOGRAMMODE_BOTH
+ *
+ *
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_MODE_NOT_SUPPORTED This error occurs when DeviceMode is
+ * not in the supported list
+ */
+ VL53L0X_Error vl53l0x_set_device_mode(VL53L0X_DEV dev, VL53L0X_DeviceModes device_mode);
+
+ /**
+ * @brief Get current new device mode
+ * @par Function Description
+ * Get actual mode of the device(ranging, histogram ...)
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_device_mode Pointer to current apply mode value
+ * Valid values are:
+ * VL53L0X_DEVICEMODE_SINGLE_RANGING
+ * VL53L0X_DEVICEMODE_CONTINUOUS_RANGING
+ * VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING
+ * VL53L0X_DEVICEMODE_SINGLE_HISTOGRAM
+ * VL53L0X_HISTOGRAMMODE_REFERENCE_ONLY
+ * VL53L0X_HISTOGRAMMODE_RETURN_ONLY
+ * VL53L0X_HISTOGRAMMODE_BOTH
+ *
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * DeviceMode is not in the supported list
+ */
+ VL53L0X_Error vl53l0x_get_device_mode(VL53L0X_DEV dev,
+ VL53L0X_DeviceModes *p_device_mode);
+
+ /**
+ * @brief Get current configuration for GPIO pin for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param pin ID of the GPIO Pin
+ * @param p_device_mode Pointer to Device Mode associated to the Gpio.
+ * @param p_functionality Pointer to Pin functionality.
+ * Refer to ::VL53L0X_GpioFunctionality
+ * @param p_polarity Pointer to interrupt polarity.
+ * Active high or active low see ::VL53L0X_InterruptPolarity
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_GPIO_NOT_EXISTING Only Pin=0 is accepted.
+ * @return VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED This error occurs
+ * when Functionality programmed is not in the supported list:
+ * Supported value are:
+ * VL53L0X_GPIOFUNCTIONALITY_OFF,
+ * VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
+ * VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH,
+ * VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT,
+ * VL53L0X_GPIOFUNCTIONALITY_NEW_MEASURE_READY
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_gpio_config(VL53L0X_DEV dev, uint8_t pin,
+ VL53L0X_DeviceModes *p_device_mode,
+ VL53L0X_GpioFunctionality *p_functionality,
+ VL53L0X_InterruptPolarity *p_polarity);
+
+ /**
+ * @brief Set the configuration of GPIO pin for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param pin ID of the GPIO Pin
+ * @param functionality Select Pin functionality.
+ * Refer to ::VL53L0X_GpioFunctionality
+ * @param device_mode Device Mode associated to the Gpio.
+ * @param polarity Set interrupt polarity. Active high
+ * or active low see ::VL53L0X_InterruptPolarity
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_GPIO_NOT_EXISTING Only Pin=0 is accepted.
+ * @return VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED This error occurs
+ * when Functionality programmed is not in the supported list:
+ * Supported value are:
+ * VL53L0X_GPIOFUNCTIONALITY_OFF,
+ * VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW,
+ * VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH,
+ VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT,
+ * VL53L0X_GPIOFUNCTIONALITY_NEW_MEASURE_READY
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_gpio_config(VL53L0X_DEV dev, uint8_t pin,
+ VL53L0X_DeviceModes device_mode, VL53L0X_GpioFunctionality functionality,
+ VL53L0X_InterruptPolarity polarity);
+
+ /**
+ * @brief Start device measurement
+ *
+ * @details Started measurement will depend on device parameters set through
+ * @a VL53L0X_SetParameters()
+ * This is a non-blocking function.
+ * This function will change the VL53L0X_State from VL53L0X_STATE_IDLE to
+ * VL53L0X_STATE_RUNNING.
+ *
+ * @note This function Access to the device
+ *
+
+ * @param dev Device Handle
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * DeviceMode programmed with @a VL53L0X_SetDeviceMode is not in the supported
+ * list:
+ * Supported mode are:
+ * VL53L0X_DEVICEMODE_SINGLE_RANGING,
+ * VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
+ * VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING
+ * @return VL53L0X_ERROR_TIME_OUT Time out on start measurement
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_start_measurement(VL53L0X_DEV dev);
+
+ /**
+ * @brief Stop device measurement
+ *
+ * @details Will set the device in standby mode at end of current measurement\n
+ * Not necessary in single mode as device shall return automatically
+ * in standby mode at end of measurement.
+ * This function will change the VL53L0X_State from VL53L0X_STATE_RUNNING
+ * to VL53L0X_STATE_IDLE.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_stop_measurement(VL53L0X_DEV dev);
+
+ /**
+ * @brief Return device stop completion status
+ *
+ * @par Function Description
+ * Returns stop completiob status.
+ * User shall call this function after a stop command
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_stop_status Pointer to status variable to update
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_stop_completed_status(VL53L0X_DEV dev,
+ uint32_t *p_stop_status);
+
+ /**
+ * @brief Return Measurement Data Ready
+ *
+ * @par Function Description
+ * This function indicate that a measurement data is ready.
+ * This function check if interrupt mode is used then check is done accordingly.
+ * If perform function clear the interrupt, this function will not work,
+ * like in case of @a VL53L0X_PerformSingleRangingMeasurement().
+ * The previous function is blocking function, VL53L0X_GetMeasurementDataReady
+ * is used for non-blocking capture.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_measurement_data_ready Pointer to Measurement Data Ready.
+ * 0=data not ready, 1 = data ready
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_measurement_data_ready(VL53L0X_DEV dev,
+ uint8_t *p_measurement_data_ready);
+
+ /**
+ * @brief Retrieve the measurements from device for a given setup
+ *
+ * @par Function Description
+ * Get data from last successful Ranging measurement
+ * @warning USER should take care about @a VL53L0X_GetNumberOfROIZones()
+ * before get data.
+ * PAL will fill a NumberOfROIZones times the corresponding data
+ * structure used in the measurement function.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_ranging_measurement_data Pointer to the data structure to fill up.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_ranging_measurement_data(VL53L0X_DEV dev,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data);
+
+ /**
+ * @brief Clear given system interrupt condition
+ *
+ * @par Function Description
+ * Clear given interrupt(s).
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param interrupt_mask Mask of interrupts to clear
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INTERRUPT_NOT_CLEARED Cannot clear interrupts
+ *
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_clear_interrupt_mask(VL53L0X_DEV dev, uint32_t interrupt_mask);
+
+ /**
+ * @brief Return device interrupt status
+ *
+ * @par Function Description
+ * Returns currently raised interrupts by the device.
+ * User shall be able to activate/deactivate interrupts through
+ * @a VL53L0X_SetGpioConfig()
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_interrupt_mask_status Pointer to status variable to update
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_interrupt_mask_status(VL53L0X_DEV dev,
+ uint32_t *p_interrupt_mask_status);
+
+ /**
+ * @brief Performs a single ranging measurement and retrieve the ranging
+ * measurement data
+ *
+ * @par Function Description
+ * This function will change the device mode to VL53L0X_DEVICEMODE_SINGLE_RANGING
+ * with @a VL53L0X_SetDeviceMode(),
+ * It performs measurement with @a VL53L0X_PerformSingleMeasurement()
+ * It get data from last successful Ranging measurement with
+ * @a VL53L0X_GetRangingMeasurementData.
+ * Finally it clear the interrupt with @a VL53L0X_ClearInterruptMask().
+ *
+ * @note This function Access to the device
+ *
+ * @note This function change the device mode to
+ * VL53L0X_DEVICEMODE_SINGLE_RANGING
+ *
+ * @param dev Device Handle
+ * @param p_ranging_measurement_data Pointer to the data structure to fill up.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_perform_single_ranging_measurement(VL53L0X_DEV dev,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data);
+
+ /**
+ * @brief Single shot measurement.
+ *
+ * @par Function Description
+ * Perform simple measurement sequence (Start measure, Wait measure to end,
+ * and returns when measurement is done).
+ * Once function returns, user can get valid data by calling
+ * VL53L0X_GetRangingMeasurement or VL53L0X_GetHistogramMeasurement
+ * depending on defined measurement mode
+ * User should Clear the interrupt in case this are enabled by using the
+ * function VL53L0X_ClearInterruptMask().
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_perform_single_measurement(VL53L0X_DEV dev);
+
+ /**
+ * @brief Read current status of the error register for the selected device
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_device_error_status Pointer to current error code of the device
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_device_error_status(VL53L0X_DEV dev,
+ VL53L0X_DeviceError *p_device_error_status);
-/**
- * @brief Clear All interrupt causes (als+range+error)
- *
- * @param dev The device
- * @return 0 On success
- */
-#define VL6180x_ClearAllInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR|INTERRUPT_CLEAR_RANGING|INTERRUPT_CLEAR_ALS)
-
+ /**
+ * @brief Human readable error string for a given Error Code
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param error_code The error code as stored on ::VL53L0X_DeviceError
+ * @param p_device_error_string The error string corresponding to the ErrorCode
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_device_error_string(
+ VL53L0X_DeviceError error_code, char *p_device_error_string);
+
+ /**
+ * @brief Human readable Range Status string for a given RangeStatus
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param range_status The RangeStatus code as stored on
+ * @a VL53L0X_RangingMeasurementData_t
+ * @param p_range_status_string The returned RangeStatus string.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_range_status_string(uint8_t range_status,
+ char *p_range_status_string);
+
+ VL53L0X_Error vl53l0x_get_total_signal_rate(VL53L0X_DEV dev,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
+ FixPoint1616_t *p_total_signal_rate_mcps);
+
+ VL53L0X_Error vl53l0x_get_total_xtalk_rate(VL53L0X_DEV dev,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
+ FixPoint1616_t *p_total_xtalk_rate_mcps);
+
+ /**
+ * @brief Get Ranging Timing Budget in microseconds
+ *
+ * @par Function Description
+ * Returns the programmed the maximum time allowed by the user to the
+ * device to run a full ranging sequence for the current mode
+ * (ranging, histogram, ASL ...)
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_measurement_timing_budget_micro_seconds Max measurement time in
+ * microseconds.
+ * Valid values are:
+ * >= 17000 microsecs when wraparound enabled
+ * >= 12000 microsecs when wraparound disabled
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
+ uint32_t *p_measurement_timing_budget_micro_seconds);
+
+ /**
+ * @brief Set Ranging Timing Budget in microseconds
+ *
+ * @par Function Description
+ * Defines the maximum time allowed by the user to the device to run a
+ * full ranging sequence for the current mode (ranging, histogram, ASL ...)
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param measurement_timing_budget_micro_seconds Max measurement time in
+ * microseconds.
+ * Valid values are:
+ * >= 17000 microsecs when wraparound enabled
+ * >= 12000 microsecs when wraparound disabled
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS This error is returned if
+ MeasurementTimingBudgetMicroSeconds out of range
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
+ uint32_t measurement_timing_budget_micro_seconds);
+
+ /**
+ * @brief Get specific limit check enable state
+ *
+ * @par Function Description
+ * This function get the enable state of a specific limit check.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param limit_check_id Limit Check ID
+ * (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
+ * @param p_limit_check_enable Pointer to the check limit enable
+ * value.
+ * if 1 the check limit
+ * corresponding to LimitCheckId is Enabled
+ * if 0 the check limit
+ * corresponding to LimitCheckId is disabled
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS This error is returned
+ * when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_limit_check_enable(VL53L0X_DEV dev, uint16_t limit_check_id,
+ uint8_t *p_limit_check_enable);
+
+ /**
+ * @brief Enable/Disable a specific limit check
+ *
+ * @par Function Description
+ * This function Enable/Disable a specific limit check.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param dev Device Handle
+ * @param limit_check_id Limit Check ID
+ * (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
+ * @param limit_check_enable if 1 the check limit
+ * corresponding to LimitCheckId is Enabled
+ * if 0 the check limit
+ * corresponding to LimitCheckId is disabled
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS This error is returned
+ * when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_limit_check_enable(VL53L0X_DEV dev, uint16_t limit_check_id,
+ uint8_t limit_check_enable);
+
+ /**
+ * @brief Get a specific limit check value
+ *
+ * @par Function Description
+ * This function get a specific limit check value from device then it updates
+ * internal values and check enables.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param limit_check_id Limit Check ID
+ * (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
+ * @param p_limit_check_value Pointer to Limit
+ * check Value for a given LimitCheckId.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS This error is returned
+ * when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_limit_check_value(VL53L0X_DEV dev, uint16_t limit_check_id,
+ FixPoint1616_t *p_limit_check_value);
+
+ /**
+ * @brief Set a specific limit check value
+ *
+ * @par Function Description
+ * This function set a specific limit check value.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param limit_check_id Limit Check ID
+ * (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
+ * @param limit_check_value Limit check Value for a given
+ * LimitCheckId
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS This error is returned when either
+ * LimitCheckId or LimitCheckValue value is out of range.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_limit_check_value(VL53L0X_DEV dev, uint16_t limit_check_id,
+ FixPoint1616_t limit_check_value);
+
+ /**
+ * @brief Get the current value of the signal used for the limit check
+ *
+ * @par Function Description
+ * This function get a the current value of the signal used for the limit check.
+ * To obtain the latest value you should run a ranging before.
+ * The value reported is linked to the limit check identified with the
+ * LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param limit_check_id Limit Check ID
+ * (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
+ * @param p_limit_check_current Pointer to current Value for a
+ * given LimitCheckId.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS This error is returned when
+ * LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_limit_check_current(VL53L0X_DEV dev, uint16_t limit_check_id,
+ FixPoint1616_t *p_limit_check_current);
+
+ /**
+ * @brief Return a the Status of the specified check limit
+ *
+ * @par Function Description
+ * This function returns the Status of the specified check limit.
+ * The value indicate if the check is fail or not.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param dev Device Handle
+ * @param limit_check_id Limit Check ID
+ (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
+ * @param p_limit_check_status Pointer to the
+ Limit Check Status of the given check limit.
+ * LimitCheckStatus :
+ * 0 the check is not fail
+ * 1 the check if fail or not enabled
+ *
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS This error is
+ returned when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_limit_check_status(VL53L0X_DEV dev,
+ uint16_t limit_check_id, uint8_t *p_limit_check_status);
+
+ /**
+ * Get continuous mode Inter-Measurement period in milliseconds
+ *
+ * @par Function Description
+ * When trying to set too short time return INVALID_PARAMS minimal value
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_inter_measurement_period_milli_seconds Pointer to programmed
+ * Inter-Measurement Period in milliseconds.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_inter_measurement_period_milli_seconds(VL53L0X_DEV dev,
+ uint32_t *p_inter_measurement_period_milli_seconds);
+
+ /**
+ * Program continuous mode Inter-Measurement period in milliseconds
+ *
+ * @par Function Description
+ * When trying to set too short time return INVALID_PARAMS minimal value
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param inter_measurement_period_milli_seconds Inter-Measurement Period in ms.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_inter_measurement_period_milli_seconds(
+ VL53L0X_DEV dev, uint32_t inter_measurement_period_milli_seconds);
+
+ /**
+ * @brief Set new device address
+ *
+ * After completion the device will answer to the new address programmed.
+ * This function should be called when several devices are used in parallel
+ * before start programming the sensor.
+ * When a single device us used, there is no need to call this function.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param device_address The new Device address
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_device_address(VL53L0X_DEV dev, uint8_t device_address);
+
+ /**
+ * @brief Do an hard reset or soft reset (depending on implementation) of the
+ * device \nAfter call of this function, device must be in same state as right
+ * after a power-up sequence.This function will change the VL53L0X_State to
+ * VL53L0X_STATE_POWERDOWN.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_reset_device(VL53L0X_DEV dev);
- private:
+ /**
+ * @brief Get setup of Wrap around Check
+ *
+ * @par Function Description
+ * This function get the wrapAround check enable parameters
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_wrap_around_check_enable Pointer to the Wrap around Check state
+ * 0=disabled or 1 = enabled
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_wrap_around_check_enable(VL53L0X_DEV dev,
+ uint8_t *p_wrap_around_check_enable);
+
+ /**
+ * @brief Enable (or disable) Wrap around Check
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param wrap_around_check_enable Wrap around Check to be set
+ * 0=disabled, other = enabled
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_wrap_around_check_enable(VL53L0X_DEV dev,
+ uint8_t wrap_around_check_enable);
+
+ /**
+ * @brief Gets the VCSEL pulse period.
+ *
+ * @par Function Description
+ * This function retrieves the VCSEL pulse period for the given period type.
+ *
+ * @note This function Accesses the device
+ *
+ * @param dev Device Handle
+ * @param vcsel_period_type VCSEL period identifier (pre-range|final).
+ * @param p_vcsel_pulse_period_pclk Pointer to VCSEL period value.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS Error VcselPeriodType parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_vcsel_pulse_period(VL53L0X_DEV dev,
+ VL53L0X_VcselPeriod vcsel_period_type, uint8_t *p_vcsel_pulse_period_pclk);
+
+ /**
+ * @brief Sets the VCSEL pulse period.
+ *
+ * @par Function Description
+ * This function retrieves the VCSEL pulse period for the given period type.
+ *
+ * @note This function Accesses the device
+ *
+ * @param dev Device Handle
+ * @param vcsel_period_type VCSEL period identifier (pre-range|final).
+ * @param vcsel_pulse_period VCSEL period value
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS Error VcselPeriodType parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_vcsel_pulse_period(VL53L0X_DEV dev,
+ VL53L0X_VcselPeriod vcsel_period_type, uint8_t vcsel_pulse_period);
+
+ /**
+ * @brief Set low and high Interrupt thresholds for a given mode
+ * (ranging, ALS, ...) for a given device
+ *
+ * @par Function Description
+ * Set low and high Interrupt thresholds for a given mode (ranging, ALS, ...)
+ * for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @note DeviceMode is ignored for the current device
+ *
+ * @param dev Device Handle
+ * @param device_mode Device Mode for which change thresholds
+ * @param threshold_low Low threshold (mm, lux ..., depending on the mode)
+ * @param threshold_high High threshold (mm, lux ..., depending on the mode)
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_interrupt_thresholds(VL53L0X_DEV dev,
+ VL53L0X_DeviceModes device_mode, FixPoint1616_t threshold_low,
+ FixPoint1616_t threshold_high);
+
+ /**
+ * @brief Get high and low Interrupt thresholds for a given mode
+ * (ranging, ALS, ...) for a given device
+ *
+ * @par Function Description
+ * Get high and low Interrupt thresholds for a given mode (ranging, ALS, ...)
+ * for a given device
+ *
+ * @note This function Access to the device
+ *
+ * @note DeviceMode is ignored for the current device
+ *
+ * @param dev Device Handle
+ * @param device_mode Device Mode from which read thresholds
+ * @param p_threshold_low Low threshold (mm, lux ..., depending on the mode)
+ * @param p_threshold_high High threshold (mm, lux ..., depending on the mode)
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_interrupt_thresholds(VL53L0X_DEV dev,
+ VL53L0X_DeviceModes device_mode, FixPoint1616_t *p_threshold_low,
+ FixPoint1616_t *p_threshold_high);
+
+ /**
+ * @brief Reads the Device information for given Device
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_vl53l0x_device_info Pointer to current device info for a given
+ * Device
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_device_info(VL53L0X_DEV dev,
+ VL53L0X_DeviceInfo_t *p_vl53l0x_device_info);
+
+ /**
+ * @brief Gets the (on/off) state of all sequence steps.
+ *
+ * @par Function Description
+ * This function retrieves the state of all sequence step in the scheduler.
+ *
+ * @note This function Accesses the device
+ *
+ * @param dev Device Handle
+ * @param p_scheduler_sequence_steps Pointer to struct containing result.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_sequence_step_enables(VL53L0X_DEV dev,
+ VL53L0X_SchedulerSequenceSteps_t *p_scheduler_sequence_steps);
+
+ /**
+ * @brief Sets the (on/off) state of a requested sequence step.
+ *
+ * @par Function Description
+ * This function enables/disables a requested sequence step.
+ *
+ * @note This function Accesses the device
+ *
+ * @param dev Device Handle
+ * @param sequence_step_id Sequence step identifier.
+ * @param sequence_step_enabled Demanded state {0=Off,1=On}
+ * is enabled.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_sequence_step_enable(VL53L0X_DEV dev,
+ VL53L0X_SequenceStepId sequence_step_id, uint8_t sequence_step_enabled);
+
+ /**
+ * @brief Gets the fraction enable parameter indicating the resolution of
+ * range measurements.
+ *
+ * @par Function Description
+ * Gets the fraction enable state, which translates to the resolution of
+ * range measurements as follows :Enabled:=0.25mm resolution,
+ * Not Enabled:=1mm resolution.
+ *
+ * @note This function Accesses the device
+ *
+ * @param dev Device Handle
+ * @param p_enabled Output Parameter reporting the fraction enable state.
+ *
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_fraction_enable(VL53L0X_DEV dev, uint8_t *p_enabled);
+
+ /**
+ * @brief Sets the resolution of range measurements.
+ * @par Function Description
+ * Set resolution of range measurements to either 0.25mm if
+ * fraction enabled or 1mm if not enabled.
+ *
+ * @note This function Accesses the device
+ *
+ * @param dev Device Handle
+ * @param enable Enable high resolution
+ *
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_range_fraction_enable(VL53L0X_DEV dev,
+ uint8_t enable);
+
+ /**
+ * @brief Return the VL53L0X PAL Implementation Version
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param p_version Pointer to current PAL Implementation Version
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_version(VL53L0X_Version_t *p_version);
+
+ /**
+ * @brief Reads the Product Revision for a for given Device
+ * This function can be used to distinguish cut1.0 from cut1.1.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_product_revision_major Pointer to Product Revision Major
+ * for a given Device
+ * @param p_product_revision_minor Pointer to Product Revision Minor
+ * for a given Device
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_product_revision(VL53L0X_DEV dev,
+ uint8_t *p_product_revision_major, uint8_t *p_product_revision_minor);
+
+ /**
+ * @brief Retrieve current device parameters
+ * @par Function Description
+ * Get actual parameters of the device
+ * @li Then start ranging operation.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_device_parameters Pointer to store current device parameters.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_device_parameters(VL53L0X_DEV dev,
+ VL53L0X_DeviceParameters_t *p_device_parameters);
+
+ /**
+ * @brief Human readable error string for current PAL error status
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param pal_error_code The error code as stored on @a VL53L0X_Error
+ * @param p_pal_error_string The error string corresponding to the
+ * PalErrorCode
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_pal_error_string(VL53L0X_Error pal_error_code,
+ char *p_pal_error_string);
+
+ /**
+ * @brief Return the PAL Specification Version used for the current
+ * implementation.
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param p_pal_spec_version Pointer to current PAL Specification Version
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_pal_spec_version(
+ VL53L0X_Version_t *p_pal_spec_version);
+
+ /**
+ * @brief Reads the internal state of the PAL for a given Device
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param dev Device Handle
+ * @param p_pal_state Pointer to current state of the PAL for a
+ * given Device
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_pal_state(VL53L0X_DEV dev,
+ VL53L0X_State *p_pal_state);
+
+ /**
+ * @brief Human readable PAL State string
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param pal_state_code The State code as stored on @a VL53L0X_State
+ * @param p_pal_state_string The State string corresponding to the
+ * PalStateCode
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_pal_state_string(VL53L0X_State pal_state_code,
+ char *p_pal_state_string);
+
+ /*** End High level API ***/
+private:
/* api.h functions */
- VL53L0X_Error VL53L0X_DataInit(VL53L0X_DEV Dev);
- VL53L0X_Error VL53L0X_GetOffsetCalibrationDataMicroMeter(VL53L0X_DEV Dev, int32_t *pOffsetCalibrationDataMicroMeter);
- VL53L0X_Error VL53L0X_SetOffsetCalibrationDataMicroMeter(VL53L0X_DEV Dev,
- int32_t OffsetCalibrationDataMicroMeter);
- VL53L0X_Error VL53L0X_GetDeviceParameters(VL53L0X_DEV Dev,
- VL53L0X_DeviceParameters_t *pDeviceParameters);
- VL53L0X_Error VL53L0X_GetDeviceMode(VL53L0X_DEV Dev,
- VL53L0X_DeviceModes *pDeviceMode);
- VL53L0X_Error VL53L0X_GetInterMeasurementPeriodMilliSeconds(VL53L0X_DEV Dev,
- uint32_t *pInterMeasurementPeriodMilliSeconds);
- VL53L0X_Error VL53L0X_GetXTalkCompensationRateMegaCps(VL53L0X_DEV Dev,
- FixPoint1616_t *pXTalkCompensationRateMegaCps);
- VL53L0X_Error VL53L0X_GetLimitCheckValue(VL53L0X_DEV Dev, uint16_t LimitCheckId,
- FixPoint1616_t *pLimitCheckValue);
- VL53L0X_Error VL53L0X_GetLimitCheckEnable(VL53L0X_DEV Dev, uint16_t LimitCheckId,
- uint8_t *pLimitCheckEnable);
- VL53L0X_Error VL53L0X_GetWrapAroundCheckEnable(VL53L0X_DEV Dev,
- uint8_t *pWrapAroundCheckEnable);
- VL53L0X_Error VL53L0X_GetMeasurementTimingBudgetMicroSeconds(VL53L0X_DEV Dev,
- uint32_t *pMeasurementTimingBudgetMicroSeconds);
- VL53L0X_Error VL53L0X_GetSequenceStepEnables(VL53L0X_DEV Dev,
- VL53L0X_SchedulerSequenceSteps_t *pSchedulerSequenceSteps);
- VL53L0X_Error sequence_step_enabled(VL53L0X_DEV Dev,
- VL53L0X_SequenceStepId SequenceStepId, uint8_t SequenceConfig,
- uint8_t *pSequenceStepEnabled);
- VL53L0X_Error VL53L0X_GetVcselPulsePeriod(VL53L0X_DEV Dev,
- VL53L0X_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriodPCLK);
- VL53L0X_Error VL53L0X_GetDeviceInfo(VL53L0X_DEV Dev,
- VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo);
- VL53L0X_Error VL53L0X_StaticInit(VL53L0X_DEV Dev);
- VL53L0X_Error VL53L0X_GetMeasurementDataReady(VL53L0X_DEV Dev,
- uint8_t *pMeasurementDataReady);
- VL53L0X_Error VL53L0X_GetInterruptMaskStatus(VL53L0X_DEV Dev,
- uint32_t *pInterruptMaskStatus);
- VL53L0X_Error VL53L0X_ClearInterruptMask(VL53L0X_DEV Dev, uint32_t InterruptMask);
- VL53L0X_Error VL53L0X_PerformSingleRangingMeasurement(VL53L0X_DEV Dev,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData);
- VL53L0X_Error VL53L0X_SetDeviceMode(VL53L0X_DEV Dev, VL53L0X_DeviceModes DeviceMode);
- VL53L0X_Error VL53L0X_PerformSingleMeasurement(VL53L0X_DEV Dev);
- VL53L0X_Error VL53L0X_StartMeasurement(VL53L0X_DEV Dev);
- VL53L0X_Error VL53L0X_CheckAndLoadInterruptSettings(VL53L0X_DEV Dev,
- uint8_t StartNotStopFlag);
- VL53L0X_Error VL53L0X_SetInterruptThresholds(VL53L0X_DEV Dev,
- VL53L0X_DeviceModes DeviceMode, FixPoint1616_t ThresholdLow,
- FixPoint1616_t ThresholdHigh);
- VL53L0X_Error VL53L0X_GetInterruptThresholds(VL53L0X_DEV Dev,
- VL53L0X_DeviceModes DeviceMode, FixPoint1616_t *pThresholdLow,
- FixPoint1616_t *pThresholdHigh);
- VL53L0X_Error VL53L0X_GetRangingMeasurementData(VL53L0X_DEV Dev,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData);
- VL53L0X_Error VL53L0X_GetXTalkCompensationEnable(VL53L0X_DEV Dev,
- uint8_t *pXTalkCompensationEnable);
- VL53L0X_Error VL53L0X_WaitDeviceBooted(VL53L0X_DEV Dev);
- VL53L0X_Error VL53L0X_PerformRefCalibration(VL53L0X_DEV Dev, uint8_t *pVhvSettings,
- uint8_t *pPhaseCal);
- VL53L0X_Error VL53L0X_PerformRefSpadManagement(VL53L0X_DEV Dev,
- uint32_t *refSpadCount, uint8_t *isApertureSpads);
- VL53L0X_Error VL53L0X_SetDeviceAddress(VL53L0X_DEV Dev, uint8_t DeviceAddress);
- VL53L0X_Error VL53L0X_SetGpioConfig(VL53L0X_DEV Dev, uint8_t Pin,
- VL53L0X_DeviceModes DeviceMode, VL53L0X_GpioFunctionality Functionality,
- VL53L0X_InterruptPolarity Polarity);
- VL53L0X_Error VL53L0X_GetFractionEnable(VL53L0X_DEV Dev, uint8_t *pEnabled);
- VL53L0X_Error VL53L0X_SetSequenceStepEnable(VL53L0X_DEV Dev,
- VL53L0X_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled);
- VL53L0X_Error VL53L0X_SetMeasurementTimingBudgetMicroSeconds(VL53L0X_DEV Dev,
- uint32_t MeasurementTimingBudgetMicroSeconds);
- VL53L0X_Error VL53L0X_SetLimitCheckEnable(VL53L0X_DEV Dev, uint16_t LimitCheckId,
- uint8_t LimitCheckEnable);
- VL53L0X_Error VL53L0X_SetLimitCheckValue(VL53L0X_DEV Dev, uint16_t LimitCheckId,
- FixPoint1616_t LimitCheckValue);
- VL53L0X_Error VL53L0X_StopMeasurement(VL53L0X_DEV Dev);
- VL53L0X_Error VL53L0X_GetStopCompletedStatus(VL53L0X_DEV Dev,
- uint32_t *pStopStatus);
- VL53L0X_Error VL53L0X_SetVcselPulsePeriod(VL53L0X_DEV Dev,
- VL53L0X_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriod);
+
+ /**
+ * @brief Wait for device booted after chip enable (hardware standby)
+ * This function can be run only when VL53L0X_State is VL53L0X_STATE_POWERDOWN.
+ *
+ * @note This function is not Implemented
+ *
+ * @param dev Device Handle
+ * @return VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented
+ *
+ */
+ VL53L0X_Error vl53l0x_wait_device_booted(VL53L0X_DEV dev);
+
+
+ VL53L0X_Error sequence_step_enabled(VL53L0X_DEV dev,
+ VL53L0X_SequenceStepId sequence_step_id, uint8_t sequence_config,
+ uint8_t *p_sequence_step_enabled);
+
+ VL53L0X_Error vl53l0x_check_and_load_interrupt_settings(VL53L0X_DEV dev,
+ uint8_t start_not_stopflag);
+
/* api_core.h functions */
- VL53L0X_Error VL53L0X_get_info_from_device(VL53L0X_DEV Dev, uint8_t option);
- VL53L0X_Error VL53L0X_device_read_strobe(VL53L0X_DEV Dev);
- VL53L0X_Error VL53L0X_get_measurement_timing_budget_micro_seconds(VL53L0X_DEV Dev,
- uint32_t *pMeasurementTimingBudgetMicroSeconds);
- VL53L0X_Error VL53L0X_get_vcsel_pulse_period(VL53L0X_DEV Dev,
- VL53L0X_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriodPCLK);
- uint8_t VL53L0X_decode_vcsel_period(uint8_t vcsel_period_reg);
- uint32_t VL53L0X_decode_timeout(uint16_t encoded_timeout);
- uint32_t VL53L0X_calc_timeout_us(VL53L0X_DEV Dev,
- uint16_t timeout_period_mclks,
- uint8_t vcsel_period_pclks);
- uint32_t VL53L0X_calc_macro_period_ps(VL53L0X_DEV Dev, uint8_t vcsel_period_pclks);
- VL53L0X_Error VL53L0X_measurement_poll_for_completion(VL53L0X_DEV Dev);
- VL53L0X_Error VL53L0X_load_tuning_settings(VL53L0X_DEV Dev,
- uint8_t *pTuningSettingBuffer);
- VL53L0X_Error VL53L0X_get_pal_range_status(VL53L0X_DEV Dev,
- uint8_t DeviceRangeStatus,
- FixPoint1616_t SignalRate,
- uint16_t EffectiveSpadRtnCount,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
- uint8_t *pPalRangeStatus);
- VL53L0X_Error VL53L0X_calc_sigma_estimate(VL53L0X_DEV Dev,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
- FixPoint1616_t *pSigmaEstimate,
- uint32_t *pDmax_mm);
- VL53L0X_Error VL53L0X_get_total_signal_rate(VL53L0X_DEV Dev,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
- FixPoint1616_t *ptotal_signal_rate_mcps);
- VL53L0X_Error VL53L0X_get_total_xtalk_rate(VL53L0X_DEV Dev,
- VL53L0X_RangingMeasurementData_t *pRangingMeasurementData,
- FixPoint1616_t *ptotal_xtalk_rate_mcps);
- uint32_t VL53L0X_calc_timeout_mclks(VL53L0X_DEV Dev,
- uint32_t timeout_period_us,
- uint8_t vcsel_period_pclks);
- uint32_t VL53L0X_isqrt(uint32_t num);
- VL53L0X_Error VL53L0X_calc_dmax(
- VL53L0X_DEV Dev,
- FixPoint1616_t totalSignalRate_mcps,
- FixPoint1616_t totalCorrSignalRate_mcps,
- FixPoint1616_t pwMult,
- uint32_t sigmaEstimateP1,
- FixPoint1616_t sigmaEstimateP2,
- uint32_t peakVcselDuration_us,
- uint32_t *pdmax_mm);
- VL53L0X_Error VL53L0X_set_measurement_timing_budget_micro_seconds(VL53L0X_DEV Dev,
- uint32_t MeasurementTimingBudgetMicroSeconds);
- VL53L0X_Error get_sequence_step_timeout(VL53L0X_DEV Dev,
- VL53L0X_SequenceStepId SequenceStepId,
- uint32_t *pTimeOutMicroSecs);
- VL53L0X_Error set_sequence_step_timeout(VL53L0X_DEV Dev,
- VL53L0X_SequenceStepId SequenceStepId,
- uint32_t TimeOutMicroSecs);
- uint16_t VL53L0X_encode_timeout(uint32_t timeout_macro_clks);
- VL53L0X_Error VL53L0X_set_vcsel_pulse_period(VL53L0X_DEV Dev,
- VL53L0X_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriodPCLK);
- uint8_t VL53L0X_encode_vcsel_period(uint8_t vcsel_period_pclks);
+
+ VL53L0X_Error vl53l0x_get_info_from_device(VL53L0X_DEV dev, uint8_t option);
+
+ VL53L0X_Error vl53l0x_device_read_strobe(VL53L0X_DEV dev);
+
+ VL53L0X_Error wrapped_vl53l0x_get_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
+ uint32_t *p_measurement_timing_budget_micro_seconds);
+
+ VL53L0X_Error wrapped_vl53l0x_get_vcsel_pulse_period(VL53L0X_DEV dev,
+ VL53L0X_VcselPeriod vcsel_period_type, uint8_t *p_vcsel_pulse_period_pclk);
+
+ uint8_t vl53l0x_decode_vcsel_period(uint8_t vcsel_period_reg);
+
+ uint32_t vl53l0x_decode_timeout(uint16_t encoded_timeout);
+
+ uint32_t vl53l0x_calc_timeout_us(VL53L0X_DEV dev,
+ uint16_t timeout_period_mclks,
+ uint8_t vcsel_period_pclks);
+
+ uint32_t vl53l0x_calc_macro_period_ps(VL53L0X_DEV dev, uint8_t vcsel_period_pclks);
+
+ VL53L0X_Error vl53l0x_measurement_poll_for_completion(VL53L0X_DEV dev);
+
+ VL53L0X_Error vl53l0x_load_tuning_settings(VL53L0X_DEV dev,
+ uint8_t *p_tuning_setting_buffer);
+
+ VL53L0X_Error vl53l0x_get_pal_range_status(VL53L0X_DEV dev,
+ uint8_t device_range_status,
+ FixPoint1616_t signal_rate,
+ uint16_t effective_spad_rtn_count,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
+ uint8_t *p_pal_range_status);
+ VL53L0X_Error vl53l0x_calc_sigma_estimate(VL53L0X_DEV dev,
+ VL53L0X_RangingMeasurementData_t *p_ranging_measurement_data,
+ FixPoint1616_t *p_sigma_estimate,
+ uint32_t *p_dmax_mm);
+ uint32_t vl53l0x_calc_timeout_mclks(VL53L0X_DEV dev,
+ uint32_t timeout_period_us,
+ uint8_t vcsel_period_pclks);
+ uint32_t vl53l0x_isqrt(uint32_t num);
+
+ uint32_t vl53l0x_quadrature_sum(uint32_t a, uint32_t b);
+
+ VL53L0X_Error vl53l0x_calc_dmax(
+ VL53L0X_DEV dev,
+ FixPoint1616_t total_signal_rate_mcps,
+ FixPoint1616_t total_corr_signal_rate_mcps,
+ FixPoint1616_t pw_mult,
+ uint32_t sigma_estimate_p1,
+ FixPoint1616_t sigma_estimate_p2,
+ uint32_t peak_vcsel_duration_us,
+ uint32_t *pd_max_mm);
+ VL53L0X_Error wrapped_vl53l0x_set_measurement_timing_budget_micro_seconds(VL53L0X_DEV dev,
+ uint32_t measurement_timing_budget_micro_seconds);
+ VL53L0X_Error get_sequence_step_timeout(VL53L0X_DEV dev,
+ VL53L0X_SequenceStepId sequence_step_id,
+ uint32_t *p_time_out_micro_secs);
+ VL53L0X_Error set_sequence_step_timeout(VL53L0X_DEV dev,
+ VL53L0X_SequenceStepId sequence_step_id,
+ uint32_t timeout_micro_secs);
+ uint16_t vl53l0x_encode_timeout(uint32_t timeout_macro_clks);
+ VL53L0X_Error wrapped_vl53l0x_set_vcsel_pulse_period(VL53L0X_DEV dev,
+ VL53L0X_VcselPeriod vcsel_period_type, uint8_t vcsel_pulse_period_pclk);
+ uint8_t lv53l0x_encode_vcsel_period(uint8_t vcsel_period_pclks);
/* api_calibration.h functions */
- VL53L0X_Error VL53L0X_apply_offset_adjustment(VL53L0X_DEV Dev);
- VL53L0X_Error VL53L0X_get_offset_calibration_data_micro_meter(VL53L0X_DEV Dev,
- int32_t *pOffsetCalibrationDataMicroMeter);
- VL53L0X_Error VL53L0X_set_offset_calibration_data_micro_meter(VL53L0X_DEV Dev,
- int32_t OffsetCalibrationDataMicroMeter);
- VL53L0X_Error VL53L0X_perform_ref_spad_management(VL53L0X_DEV Dev,
- uint32_t *refSpadCount,
- uint8_t *isApertureSpads);
- VL53L0X_Error VL53L0X_perform_ref_calibration(VL53L0X_DEV Dev,
- uint8_t *pVhvSettings, uint8_t *pPhaseCal, uint8_t get_data_enable);
- VL53L0X_Error VL53L0X_perform_vhv_calibration(VL53L0X_DEV Dev,
- uint8_t *pVhvSettings, const uint8_t get_data_enable,
- const uint8_t restore_config);
- VL53L0X_Error VL53L0X_perform_single_ref_calibration(VL53L0X_DEV Dev,
- uint8_t vhv_init_byte);
- VL53L0X_Error VL53L0X_ref_calibration_io(VL53L0X_DEV Dev, uint8_t read_not_write,
- uint8_t VhvSettings, uint8_t PhaseCal,
- uint8_t *pVhvSettings, uint8_t *pPhaseCal,
- const uint8_t vhv_enable, const uint8_t phase_enable);
- VL53L0X_Error VL53L0X_perform_phase_calibration(VL53L0X_DEV Dev,
- uint8_t *pPhaseCal, const uint8_t get_data_enable,
- const uint8_t restore_config);
- VL53L0X_Error enable_ref_spads(VL53L0X_DEV Dev,
- uint8_t apertureSpads,
- uint8_t goodSpadArray[],
- uint8_t spadArray[],
- uint32_t size,
- uint32_t start,
- uint32_t offset,
- uint32_t spadCount,
- uint32_t *lastSpad);
- void get_next_good_spad(uint8_t goodSpadArray[], uint32_t size,
- uint32_t curr, int32_t *next);
- uint8_t is_aperture(uint32_t spadIndex);
- VL53L0X_Error enable_spad_bit(uint8_t spadArray[], uint32_t size,
- uint32_t spadIndex);
- VL53L0X_Error set_ref_spad_map(VL53L0X_DEV Dev, uint8_t *refSpadArray);
- VL53L0X_Error get_ref_spad_map(VL53L0X_DEV Dev, uint8_t *refSpadArray);
- VL53L0X_Error perform_ref_signal_measurement(VL53L0X_DEV Dev,
- uint16_t *refSignalRate);
- VL53L0X_Error VL53L0X_set_reference_spads(VL53L0X_DEV Dev,
- uint32_t count, uint8_t isApertureSpads);
+ VL53L0X_Error vl53l0x_apply_offset_adjustment(VL53L0X_DEV dev);
+ VL53L0X_Error wrapped_vl53l0x_get_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
+ int32_t *p_offset_calibration_data_micro_meter);
+ VL53L0X_Error wrapped_vl53l0x_set_offset_calibration_data_micro_meter(VL53L0X_DEV dev,
+ int32_t offset_calibration_data_micro_meter);
+ VL53L0X_Error wrapped_vl53l0x_perform_ref_spad_management(VL53L0X_DEV dev,
+ uint32_t *ref_spad_count,
+ uint8_t *is_aperture_spads);
+ VL53L0X_Error vl53l0x_perform_ref_calibration(VL53L0X_DEV dev,
+ uint8_t *p_vhv_settings, uint8_t *p_phase_cal, uint8_t get_data_enable);
+ VL53L0X_Error vl53l0x_perform_vhv_calibration(VL53L0X_DEV dev,
+ uint8_t *p_vhv_settings, const uint8_t get_data_enable,
+ const uint8_t restore_config);
+ VL53L0X_Error vl53l0x_perform_single_ref_calibration(VL53L0X_DEV dev,
+ uint8_t vhv_init_byte);
+ VL53L0X_Error vl53l0x_ref_calibration_io(VL53L0X_DEV dev, uint8_t read_not_write,
+ uint8_t vhv_settings, uint8_t phase_cal,
+ uint8_t *p_vhv_settings, uint8_t *p_phase_cal,
+ const uint8_t vhv_enable, const uint8_t phase_enable);
+ VL53L0X_Error vl53l0x_perform_phase_calibration(VL53L0X_DEV dev,
+ uint8_t *p_phase_cal, const uint8_t get_data_enable,
+ const uint8_t restore_config);
+ VL53L0X_Error enable_ref_spads(VL53L0X_DEV dev,
+ uint8_t aperture_spads,
+ uint8_t good_spad_array[],
+ uint8_t spad_array[],
+ uint32_t size,
+ uint32_t start,
+ uint32_t offset,
+ uint32_t spad_count,
+ uint32_t *p_last_spad);
+ void get_next_good_spad(uint8_t good_spad_array[], uint32_t size,
+ uint32_t curr, int32_t *p_next);
+ uint8_t is_aperture(uint32_t spad_index);
+ VL53L0X_Error enable_spad_bit(uint8_t spad_array[], uint32_t size,
+ uint32_t spad_index);
+ VL53L0X_Error set_ref_spad_map(VL53L0X_DEV dev, uint8_t *p_ref_spad_array);
+ VL53L0X_Error get_ref_spad_map(VL53L0X_DEV dev, uint8_t *p_ref_spad_array);
+ VL53L0X_Error perform_ref_signal_measurement(VL53L0X_DEV dev,
+ uint16_t *p_ref_signal_rate);
+ VL53L0X_Error wrapped_vl53l0x_set_reference_spads(VL53L0X_DEV dev,
+ uint32_t count, uint8_t is_aperture_spads);
/* api_strings.h functions */
- VL53L0X_Error VL53L0X_get_device_info(VL53L0X_DEV Dev,
- VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo);
- VL53L0X_Error VL53L0X_check_part_used(VL53L0X_DEV Dev,
- uint8_t *Revision,
- VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo);
+ VL53L0X_Error wrapped_vl53l0x_get_device_info(VL53L0X_DEV dev,
+ VL53L0X_DeviceInfo_t *p_vl53l0x_device_info);
+ VL53L0X_Error vl53l0x_check_part_used(VL53L0X_DEV dev,
+ uint8_t *revision,
+ VL53L0X_DeviceInfo_t *p_vl53l0x_device_info);
- /* deprecated Read function from Component class for backward compatibility*/
- // virtual int ReadID();
- virtual int ReadID(uint8_t *id);
+ /* Read function of the ID device */
+ // virtual int read_id();
+ virtual int read_id(uint8_t *id);
- /* Read function of the ID device */
- // virtual int read_id();
- virtual int read_id(uint8_t *id);
-
- VL53L0X_Error WaitMeasurementDataReady(VL53L0X_DEV Dev);
- VL53L0X_Error WaitStopCompleted(VL53L0X_DEV Dev);
+ VL53L0X_Error wait_measurement_data_ready(VL53L0X_DEV dev);
+
+ VL53L0X_Error wait_stop_completed(VL53L0X_DEV dev);
/* Write and read functions from I2C */
-
- VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV dev, uint8_t index, uint8_t data);
- VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV dev, uint8_t index, uint16_t data);
- VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV dev, uint8_t index, uint32_t data);
- VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV dev, uint8_t index, uint8_t *data);
- VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV dev, uint8_t index, uint16_t *data);
- VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV dev, uint8_t index, uint32_t *data);
- VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV dev, uint8_t index, uint8_t AndData, uint8_t OrData);
-
- VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
- VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
-
- VL53L0X_Error VL53L0X_I2CWrite(uint8_t dev, uint8_t index, uint8_t *data, uint16_t number_of_bytes);
- VL53L0X_Error VL53L0X_I2CRead(uint8_t dev, uint8_t index, uint8_t *data, uint16_t number_of_bytes);
-
- VL53L0X_Error VL53L0X_PollingDelay(VL53L0X_DEV Dev); /* usually best implemented as a real function */
-
- int IsPresent()
+ /**
+ * Write single byte register
+ * @param dev Device Handle
+ * @param index The register index
+ * @param data 8 bit register data
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_write_byte(VL53L0X_DEV dev, uint8_t index, uint8_t data);
+ /**
+ * Write word register
+ * @param dev Device Handle
+ * @param index The register index
+ * @param data 16 bit register data
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_write_word(VL53L0X_DEV dev, uint8_t index, uint16_t data);
+ /**
+ * Write double word (4 byte) register
+ * @param dev Device Handle
+ * @param index The register index
+ * @param data 32 bit register data
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_write_dword(VL53L0X_DEV dev, uint8_t index, uint32_t data);
+ /**
+ * Read single byte register
+ * @param dev Device Handle
+ * @param index The register index
+ * @param data pointer to 8 bit data
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_read_byte(VL53L0X_DEV dev, uint8_t index, uint8_t *p_data);
+ /**
+ * Read word (2byte) register
+ * @param dev Device Handle
+ * @param index The register index
+ * @param data pointer to 16 bit data
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_read_word(VL53L0X_DEV dev, uint8_t index, uint16_t *p_data);
+ /**
+ * Read dword (4byte) register
+ * @param dev Device Handle
+ * @param index The register index
+ * @param data pointer to 32 bit data
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_read_dword(VL53L0X_DEV dev, uint8_t index, uint32_t *p_data);
+ /**
+ * Threat safe Update (read/modify/write) single byte register
+ *
+ * Final_reg = (Initial_reg & and_data) |or_data
+ *
+ * @param dev Device Handle
+ * @param index The register index
+ * @param and_data 8 bit and data
+ * @param or_data 8 bit or data
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_update_byte(VL53L0X_DEV dev, uint8_t index, uint8_t and_data, uint8_t or_data);
+ /**
+ * Writes the supplied byte buffer to the device
+ * @param dev Device Handle
+ * @param index The register index
+ * @param p_data Pointer to uint8_t buffer containing the data to be written
+ * @param count Number of bytes in the supplied byte buffer
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_write_multi(VL53L0X_DEV dev, uint8_t index, uint8_t *p_data, uint32_t count);
+ /**
+ * Reads the requested number of bytes from the device
+ * @param dev Device Handle
+ * @param index The register index
+ * @param p_data Pointer to the uint8_t buffer to store read data
+ * @param count Number of uint8_t's to read
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_read_multi(VL53L0X_DEV dev, uint8_t index, uint8_t *p_data, uint32_t count);
+
+ /**
+ * @brief Writes a buffer towards the I2C peripheral device.
+ * @param dev Device Handle
+ * @param p_data pointer to the byte-array data to send
+ * @param number_of_bytes number of bytes to be written.
+ * @retval 0 if ok,
+ * @retval -1 if an I2C error has occured
+ * @note On some devices if NumByteToWrite is greater
+ * than one, the RegisterAddr must be masked correctly!
+ */
+ VL53L0X_Error vl53l0x_i2c_write(uint8_t dev, uint8_t index, uint8_t *p_data, uint16_t number_of_bytes);
+
+ /**
+ * @brief Reads a buffer from the I2C peripheral device.
+ * @param dev Device Handle
+ * @param p_data pointer to the byte-array to read data in to
+ * @param number_of_bytes number of bytes to be read.
+ * @retval 0 if ok,
+ * @retval -1 if an I2C error has occured
+ * @note On some devices if NumByteToWrite is greater
+ * than one, the RegisterAddr must be masked correctly!
+ */
+ VL53L0X_Error vl53l0x_i2c_read(uint8_t dev, uint8_t index, uint8_t *p_data, uint16_t number_of_bytes);
+
+ /**
+ * @brief execute delay in all polling API call
+ *
+ * A typical multi-thread or RTOs implementation is to sleep the task for some 5ms (with 100Hz max rate faster polling is not needed)
+ * if nothing specific is need you can define it as an empty/void macro
+ * @code
+ * #define VL53L0X_PollingDelay(...) (void)0
+ * @endcode
+ * @param dev Device Handle
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_polling_delay(VL53L0X_DEV dev); /* usually best implemented as a real function */
+
+ int is_present()
{
- int status;
- uint8_t id=0;
-
- status=ReadID(&id);
- if(status)
- VL53L0X_ErrLog("Failed to read ID device. Device not present!\n\r");
- return status;
- }
- int StopRangeMeasurement(OperatingMode operating_mode);
- int GetRangeMeas(OperatingMode operating_mode, VL53L0X_RangingMeasurementData_t *Data);
- int RangeSetLowThreshold(uint16_t threshold);
- int RangeSetHighThreshold(uint16_t threshold);
- int GetRangeError(VL53L0X_RangingMeasurementData_t *Data, VL53L0X_RangingMeasurementData_t RangeData);
- int RangeMeasPollSingleShot();
- int RangeMeasPollContinuousMode();
- int RangeMeasIntContinuousMode(void (*fptr)(void));
+ int status;
+ uint8_t id = 0;
+
+ status = read_id(&id);
+ if (status)
+ VL53L0X_ErrLog("Failed to read ID device. Device not present!\n\r");
+ return status;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////
+ //Added functions //
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @brief Cycle Power to Device
+ *
+ * @return status - status 0 = ok, 1 = error
+ *
+ */
+ int32_t vl53l0x_cycle_power(void);
+
+ uint8_t vl53l0x_encode_vcsel_period(uint8_t vcsel_period_pclks);
+
+ VL53L0X_Error wrapped_vl53l0x_get_device_error_string(VL53L0X_DeviceError error_code,
+ char *p_device_error_string);
+
+ VL53L0X_Error wrapped_vl53l0x_get_limit_check_info(VL53L0X_DEV dev, uint16_t limit_check_id,
+ char *p_limit_check_string);
+
+ VL53L0X_Error wrapped_vl53l0x_get_pal_error_string(VL53L0X_Error pal_error_code,
+ char *p_pal_error_string);
+
+ VL53L0X_Error wrapped_vl53l0x_get_pal_state_string(VL53L0X_State pal_state_code,
+ char *p_pal_state_string);
+
+ VL53L0X_Error wrapped_vl53l0x_get_range_status_string(uint8_t range_status,
+ char *p_range_status_string);
+
+ VL53L0X_Error wrapped_vl53l0x_get_ref_calibration(VL53L0X_DEV dev,
+ uint8_t *p_vhv_settings, uint8_t *p_phase_cal);
+
+
+ VL53L0X_Error count_enabled_spads(uint8_t spad_array[],
+ uint32_t byte_count, uint32_t max_spads,
+ uint32_t *p_total_spads_enabled, uint8_t *p_is_aperture);
+
+ VL53L0X_Error wrapped_vl53l0x_get_sequence_steps_info(VL53L0X_SequenceStepId sequence_step_id,
+ char *p_sequence_steps_string);
- VL53L0X_DeviceInfo_t DeviceInfo;
-
+ /**
+ * @brief Gets the name of a given sequence step.
+ *
+ * @par Function Description
+ * This function retrieves the name of sequence steps corresponding to
+ * SequenceStepId.
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param sequence_step_id Sequence step identifier.
+ * @param p_sequence_steps_string Pointer to Info string
+ *
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_sequence_steps_info(VL53L0X_SequenceStepId sequence_step_id,
+ char *p_sequence_steps_string);
+
+ /**
+ * @brief Get the frequency of the timer used for ranging results time stamps
+ *
+ * @param[out] p_timer_freq_hz : pointer for timer frequency
+ *
+ * @return status : 0 = ok, 1 = error
+ *
+ */
+ int32_t vl53l0x_get_timer_frequency(int32_t *p_timer_freq_hz);
+
+ /**
+ * @brief Get the timer value in units of timer_freq_hz (see VL53L0X_get_timestamp_frequency())
+ *
+ * @param[out] p_timer_count : pointer for timer count value
+ *
+ * @return status : 0 = ok, 1 = error
+ *
+ */
+ int32_t vl53l0x_get_timer_value(int32_t *p_timer_count);
+
+ /**
+ * @brief Configure ranging interrupt reported to system
+ *
+ * @note This function is not Implemented
+ *
+ * @param dev Device Handle
+ * @param interrupt_mask Mask of interrupt to Enable/disable
+ * (0:interrupt disabled or 1: interrupt enabled)
+ * @return VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+ VL53L0X_Error vl53l0x_enable_interrupt_mask(VL53L0X_DEV dev,
+ uint32_t interrupt_mask);
+
+ /**
+ * @brief Get Dmax Calibration Parameters for a given device
+ *
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_range_milli_meter Pointer to Calibration Distance
+ * @param p_signal_rate_rtn_mega_cps Pointer to Signal rate return
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_dmax_cal_parameters(VL53L0X_DEV dev,
+ uint16_t *p_range_milli_meter, FixPoint1616_t *p_signal_rate_rtn_mega_cps);
+
+ /**
+ * @brief Set Dmax Calibration Parameters for a given device
+ * When one of the parameter is zero, this function will get parameter
+ * from NVM.
+ * @note This function doesn't Access to the device
+ *
+ * @param dev Device Handle
+ * @param range_milli_meter Calibration Distance
+ * @param signal_rate_rtn_mega_cps Signal rate return read at CalDistance
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_dmax_cal_parameters(VL53L0X_DEV dev,
+ uint16_t range_milli_meter, FixPoint1616_t signal_rate_rtn_mega_cps);
+
+ /**
+ * @brief Retrieve the measurements from device for a given setup
+ *
+ * @par Function Description
+ * Get data from last successful Histogram measurement
+ * @warning USER should take care about @a VL53L0X_GetNumberOfROIZones()
+ * before get data.
+ * PAL will fill a NumberOfROIZones times the corresponding data structure
+ * used in the measurement function.
+ *
+ * @note This function is not Implemented
+ *
+ * @param dev Device Handle
+ * @param p_histogram_measurement_data Pointer to the histogram data structure.
+ * @return VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+ VL53L0X_Error vl53l0x_get_histogram_measurement_data(VL53L0X_DEV dev,
+ VL53L0X_HistogramMeasurementData_t *p_histogram_measurement_data);
+
+ /**
+ * @brief Get current new device mode
+ * @par Function Description
+ * Get current Histogram mode of a Device
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_histogram_mode Pointer to current Histogram Mode value
+ * Valid values are:
+ * VL53L0X_HISTOGRAMMODE_DISABLED
+ * VL53L0X_DEVICEMODE_SINGLE_HISTOGRAM
+ * VL53L0X_HISTOGRAMMODE_REFERENCE_ONLY
+ * VL53L0X_HISTOGRAMMODE_RETURN_ONLY
+ * VL53L0X_HISTOGRAMMODE_BOTH
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_histogram_mode(VL53L0X_DEV dev,
+ VL53L0X_HistogramModes *p_histogram_mode);
+
+ /**
+ * @brief Set a new Histogram mode
+ * @par Function Description
+ * Set device to a new Histogram mode
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param dev Device Handle
+ * @param histogram_mode New device mode to apply
+ * Valid values are:
+ * VL53L0X_HISTOGRAMMODE_DISABLED
+ * VL53L0X_DEVICEMODE_SINGLE_HISTOGRAM
+ * VL53L0X_HISTOGRAMMODE_REFERENCE_ONLY
+ * VL53L0X_HISTOGRAMMODE_RETURN_ONLY
+ * VL53L0X_HISTOGRAMMODE_BOTH
+ *
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * HistogramMode is not in the supported list
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_histogram_mode(VL53L0X_DEV dev,
+ VL53L0X_HistogramModes histogram_mode);
+
+ /**
+ * @brief Return a description string for a given limit check number
+ *
+ * @par Function Description
+ * This function returns a description string for a given limit check number.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param dev Device Handle
+ * @param limit_check_id Limit Check ID
+ (0<= LimitCheckId < VL53L0X_GetNumberOfLimitCheck() ).
+ * @param p_limit_check_string Pointer to the
+ description string of the given check limit.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS This error is
+ returned when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_limit_check_info(VL53L0X_DEV dev,
+ uint16_t limit_check_id, char *p_limit_check_string);
+
+ /**
+ * @brief Get the linearity corrective gain
+ *
+ * @par Function Description
+ * Should only be used after a successful call to @a VL53L0X_DataInit to backup
+ * device NVM value
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_linearity_corrective_gain Pointer to the linearity
+ * corrective gain in x1000
+ * if value is 1000 then no modification is applied.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_linearity_corrective_gain(VL53L0X_DEV dev,
+ uint16_t *p_linearity_corrective_gain);
+
+ /**
+ * Set the linearity corrective gain
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param linearity_corrective_gain Linearity corrective
+ * gain in x1000
+ * if value is 1000 then no modification is applied.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_linearity_corrective_gain(VL53L0X_DEV dev,
+ int16_t linearity_corrective_gain);
+
+ /**
+ * @brief Get the Maximum number of ROI Zones managed by the Device
+ *
+ * @par Function Description
+ * Get Maximum number of ROI Zones managed by the Device.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_max_number_of_roi_zones Pointer to the Maximum Number
+ * of ROI Zones value.
+ * @return VL53L0X_ERROR_NONE Success
+ */
+ VL53L0X_Error vl53l0x_get_max_number_of_roi_zones(VL53L0X_DEV dev,
+ uint8_t *p_max_number_of_roi_zones);
+
+ /**
+ * @brief Retrieve the Reference Signal after a measurements
+ *
+ * @par Function Description
+ * Get Reference Signal from last successful Ranging measurement
+ * This function return a valid value after that you call the
+ * @a VL53L0X_GetRangingMeasurementData().
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_measurement_ref_signal Pointer to the Ref Signal to fill up.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_measurement_ref_signal(VL53L0X_DEV dev,
+ FixPoint1616_t *p_measurement_ref_signal);
+
+ /**
+ * @brief Get the number of the check limit managed by a given Device
+ *
+ * @par Function Description
+ * This function give the number of the check limit managed by the Device
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param p_number_of_limit_check Pointer to the number of check limit.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_number_of_limit_check(
+ uint16_t *p_number_of_limit_check);
+
+ /**
+ * @brief Get the number of ROI Zones managed by the Device
+ *
+ * @par Function Description
+ * Get number of ROI Zones managed by the Device
+ * USER should take care about @a VL53L0X_GetNumberOfROIZones()
+ * before get data after a perform measurement.
+ * PAL will fill a NumberOfROIZones times the corresponding data
+ * structure used in the measurement function.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_number_of_roi_zones Pointer to the Number of ROI Zones value.
+ * @return VL53L0X_ERROR_NONE Success
+ */
+ VL53L0X_Error vl53l0x_get_number_of_roi_zones(VL53L0X_DEV dev,
+ uint8_t *p_number_of_roi_zones);
+
+ /**
+ * @brief Set the number of ROI Zones to be used for a specific Device
+ *
+ * @par Function Description
+ * Set the number of ROI Zones to be used for a specific Device.
+ * The programmed value should be less than the max number of ROI Zones given
+ * with @a VL53L0X_GetMaxNumberOfROIZones().
+ * This version of API manage only one zone.
+ *
+ * @param dev Device Handle
+ * @param number_of_roi_zones Number of ROI Zones to be used for a
+ * specific Device.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS This error is returned if
+ * NumberOfROIZones != 1
+ */
+ VL53L0X_Error vl53l0x_set_number_of_roi_zones(VL53L0X_DEV dev,
+ uint8_t number_of_roi_zones);
+
+ /**
+ * @brief Gets number of sequence steps managed by the API.
+ *
+ * @par Function Description
+ * This function retrieves the number of sequence steps currently managed
+ * by the API
+ *
+ * @note This function Accesses the device
+ *
+ * @param dev Device Handle
+ * @param p_number_of_sequence_steps Out parameter reporting the number of
+ * sequence steps.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_number_of_sequence_steps(VL53L0X_DEV dev,
+ uint8_t *p_number_of_sequence_steps);
+ /**
+ * @brief Get the power mode for a given Device
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_power_mode Pointer to the current value of the power
+ * mode. see ::VL53L0X_PowerModes
+ * Valid values are:
+ * VL53L0X_POWERMODE_STANDBY_LEVEL1,
+ * VL53L0X_POWERMODE_IDLE_LEVEL1
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_power_mode(VL53L0X_DEV dev,
+ VL53L0X_PowerModes *p_power_mode);
+
+ /**
+ * @brief Set the power mode for a given Device
+ * The power mode can be Standby or Idle. Different level of both Standby and
+ * Idle can exists.
+ * This function should not be used when device is in Ranging state.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param power_mode The value of the power mode to set.
+ * see ::VL53L0X_PowerModes
+ * Valid values are:
+ * VL53L0X_POWERMODE_STANDBY_LEVEL1,
+ * VL53L0X_POWERMODE_IDLE_LEVEL1
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_MODE_NOT_SUPPORTED This error occurs when PowerMode
+ * is not in the supported list
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_power_mode(VL53L0X_DEV dev,
+ VL53L0X_PowerModes power_mode);
+
+ /**
+ * @brief Retrieves SPAD configuration
+ *
+ * @par Function Description
+ * This function retrieves the current number of applied reference spads
+ * and also their type : Aperture or Non-Aperture.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_spad_count Number ref Spad Count
+ * @param p_is_aperture_spads Reports if spads are of type
+ * aperture or non-aperture.
+ * 1:=aperture, 0:=Non-Aperture
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_REF_SPAD_INIT Error in the in the reference
+ * spad configuration.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error wrapped_vl53l0x_get_reference_spads(VL53L0X_DEV dev,
+ uint32_t *p_spad_count, uint8_t *p_is_aperture_spads);
+
+ /**
+ * @brief Gets the (on/off) state of a requested sequence step.
+ *
+ * @par Function Description
+ * This function retrieves the state of a requested sequence step, i.e. on/off.
+ *
+ * @note This function Accesses the device
+ *
+ * @param dev Device Handle
+ * @param sequence_step_id Sequence step identifier.
+ * @param p_sequence_step_enabled Out parameter reporting if the sequence step
+ * is enabled {0=Off,1=On}.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_sequence_step_enable(VL53L0X_DEV dev,
+ VL53L0X_SequenceStepId sequence_step_id, uint8_t *p_sequence_step_enabled);
+
+
+ /**
+ * @brief Gets the timeout of a requested sequence step.
+ *
+ * @par Function Description
+ * This function retrieves the timeout of a requested sequence step.
+ *
+ * @note This function Accesses the device
+ *
+ * @param dev Device Handle
+ * @param sequence_step_id Sequence step identifier.
+ * @param p_time_out_milli_secs Timeout value.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_sequence_step_timeout(VL53L0X_DEV dev,
+ VL53L0X_SequenceStepId sequence_step_id,
+ FixPoint1616_t *p_time_out_milli_secs);
+
+ /**
+ * @brief Sets the timeout of a requested sequence step.
+ *
+ * @par Function Description
+ * This function sets the timeout of a requested sequence step.
+ *
+ * @note This function Accesses the device
+ *
+ * @param dev Device Handle
+ * @param sequence_step_id Sequence step identifier.
+ * @param time_out_milli_secs Demanded timeout
+ * @return VL53L0X_ERROR_NONE Success
+ * @return VL53L0X_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_sequence_step_timeout(VL53L0X_DEV dev,
+ VL53L0X_SequenceStepId sequence_step_id, FixPoint1616_t time_out_milli_secs);
+
+ /**
+ * @brief Get the current SPAD Ambient Damper Factor value
+ *
+ * @par Function Description
+ * This function get the SPAD Ambient Damper Factor value
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_spad_ambient_damper_factor Pointer to programmed SPAD Ambient
+ * Damper Factor value
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_spad_ambient_damper_factor(VL53L0X_DEV dev,
+ uint16_t *p_spad_ambient_damper_factor);
+ /**
+ * @brief Set the SPAD Ambient Damper Factor value
+ *
+ * @par Function Description
+ * This function set the SPAD Ambient Damper Factor value
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param spad_ambient_damper_factor SPAD Ambient Damper Factor value
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_spad_ambient_damper_factor(VL53L0X_DEV dev,
+ uint16_t spad_ambient_damper_factor);
+
+ /**
+ * @brief Get the current SPAD Ambient Damper Threshold value
+ *
+ * @par Function Description
+ * This function get the SPAD Ambient Damper Threshold value
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_spad_ambient_damper_threshold Pointer to programmed
+ * SPAD Ambient Damper Threshold value
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_spad_ambient_damper_threshold(VL53L0X_DEV dev,
+ uint16_t *p_spad_ambient_damper_threshold);
+
+ /**
+ * @brief Set the SPAD Ambient Damper Threshold value
+ *
+ * @par Function Description
+ * This function set the SPAD Ambient Damper Threshold value
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param spad_ambient_damper_threshold SPAD Ambient Damper Threshold value
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_spad_ambient_damper_threshold(VL53L0X_DEV dev,
+ uint16_t spad_ambient_damper_threshold);
+
+ /**
+ * @brief Get the maximal distance for actual setup
+ * @par Function Description
+ * Device must be initialized through @a VL53L0X_SetParameters() prior calling
+ * this function.
+ *
+ * Any range value more than the value returned is to be considered as
+ * "no target detected" or
+ * "no target in detectable range"\n
+ * @warning The maximal distance depends on the setup
+ *
+ * @note This function is not Implemented
+ *
+ * @param dev Device Handle
+ * @param p_upper_limit_milli_meter The maximal range limit for actual setup
+ * (in millimeter)
+ * @return VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+ VL53L0X_Error vl53l0x_get_upper_limit_milli_meter(VL53L0X_DEV dev,
+ uint16_t *p_upper_limit_milli_meter);
+
+ /**
+ * @brief Get the tuning settings pointer and the internal external switch
+ * value.
+ *
+ * This function is used to get the Tuning settings buffer pointer and the
+ * value.
+ * of the switch to select either external or internal tuning settings.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param pp_tuning_setting_buffer Pointer to tuning settings buffer.
+ * @param p_use_internal_tuning_settings Pointer to store Use internal tuning
+ * settings value.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_get_tuning_setting_buffer(VL53L0X_DEV dev,
+ uint8_t **pp_tuning_setting_buffer, uint8_t *p_use_internal_tuning_settings);
+
+ /**
+ * @brief Set the tuning settings pointer
+ *
+ * This function is used to specify the Tuning settings buffer to be used
+ * for a given device. The buffer contains all the necessary data to permit
+ * the API to write tuning settings.
+ * This function permit to force the usage of either external or internal
+ * tuning settings.
+ *
+ * @note This function Access to the device
+ *
+ * @param dev Device Handle
+ * @param p_tuning_setting_buffer Pointer to tuning settings buffer.
+ * @param use_internal_tuning_settings Use internal tuning settings value.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_set_tuning_setting_buffer(VL53L0X_DEV dev,
+ uint8_t *p_tuning_setting_buffer, uint8_t use_internal_tuning_settings);
+
+ /**
+ * @defgroup VL53L0X_registerAccess_group PAL Register Access Functions
+ * @brief PAL Register Access Functions
+ * @{
+ */
+
+ /**
+ * Lock comms interface to serialize all commands to a shared I2C interface for a specific device
+ * @param dev Device Handle
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_lock_sequence_access(VL53L0X_DEV dev);
+
+ /**
+ * Unlock comms interface to serialize all commands to a shared I2C interface for a specific device
+ * @param dev Device Handle
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53l0x_unlock_sequence_access(VL53L0X_DEV dev);
+
+ /**
+ * @brief Prepare device for operation
+ * @par Function Description
+ * Update device with provided parameters
+ * @li Then start ranging operation.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pDeviceParameters Pointer to store current device parameters.
+ * @return VL53L0X_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L0X_Error
+ */
+ VL53L0X_Error vl53L0x_set_device_parameters(VL53L0X_DEV Dev,
+ const VL53L0X_DeviceParameters_t *pDeviceParameters);
+
+ /**
+ * Set Group parameter Hold state
+ *
+ * @par Function Description
+ * Set or remove device internal group parameter hold
+ *
+ * @note This function is not Implemented
+ *
+ * @param dev Device Handle
+ * @param group_param_hold Group parameter Hold state to be set (on/off)
+ * @return VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+ VL53L0X_Error vl53l0x_set_group_param_hold(VL53L0X_DEV dev,
+ uint8_t group_param_hold);
+
+
+ /**
+ * @brief Wait for device ready for a new measurement command.
+ * Blocking function.
+ *
+ * @note This function is not Implemented
+ *
+ * @param dev Device Handle
+ * @param max_loop Max Number of polling loop (timeout).
+ * @return VL53L0X_ERROR_NOT_IMPLEMENTED Not implemented
+ */
+ VL53L0X_Error vl53l0x_wait_device_ready_for_new_measurement(VL53L0X_DEV dev,
+ uint32_t max_loop);
+
+ VL53L0X_Error VL53L0X_reverse_bytes(uint8_t *data, uint32_t size);
+
+ int range_meas_int_continuous_mode(void (*fptr)(void));
+
+
+ VL53L0X_DeviceInfo_t _device_info;
+
/* IO Device */
DevI2C &dev_i2c;
/* Digital out pin */
DigitalOut *gpio0;
/* GPIO expander */
- STMPE1600DigiOut *expgpio0;
+ Stmpe1600DigiOut *expgpio0;
/* Measure detection IRQ */
InterruptIn *gpio1Int;
/* Device data */
- VL53L0X_Dev_t MyDevice;
- VL53L0X_DEV Device;
+ VL53L0X_Dev_t _my_device;
+ VL53L0X_DEV _device;
};
#endif /* _VL53L0X_CLASS_H_ */
-
-
-
-
--- a/x_nucleo_53l0a1.cpp Thu Jun 15 13:33:35 2017 +0000
+++ b/x_nucleo_53l0a1.cpp Mon Aug 07 14:30:21 2017 +0000
@@ -38,84 +38,89 @@
/* Includes ------------------------------------------------------------------*/
#include "x_nucleo_53l0a1.h"
+#include "vl53l0x_platform_log.h"
/* Static variables ----------------------------------------------------------*/
-X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::_instance = NULL;
+X_NUCLEO_53L0A1 *X_NUCLEO_53L0A1::_instance = NULL;
-X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::Instance(DevI2C *ext_i2c)
+X_NUCLEO_53L0A1 *X_NUCLEO_53L0A1::instance(DevI2C *ext_i2c)
{
- if(_instance==NULL)
- _instance=new X_NUCLEO_53L0A1(ext_i2c);
- else
- VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r");
- return _instance;
+ if (_instance == NULL)
+ _instance = new X_NUCLEO_53L0A1(ext_i2c);
+ else
+ VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r");
+ return _instance;
}
-X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::Instance(DevI2C *ext_i2c,
- PinName gpio1_centre,
- PinName gpio1_left, PinName gpio1_right)
+X_NUCLEO_53L0A1 *X_NUCLEO_53L0A1::instance(DevI2C *ext_i2c,
+ PinName gpio1_centre,
+ PinName gpio1_left, PinName gpio1_right)
{
- if(_instance==NULL)
- _instance=new X_NUCLEO_53L0A1(ext_i2c, gpio1_centre, gpio1_left, gpio1_right);
- else
- VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r");
- return _instance;
+ if (_instance == NULL)
+ _instance = new X_NUCLEO_53L0A1(ext_i2c, gpio1_centre, gpio1_left, gpio1_right);
+ else
+ VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r");
+ return _instance;
}
-int X_NUCLEO_53L0A1::InitBoard()
-{
- int status, n_dev=0;
+int X_NUCLEO_53L0A1::init_board()
+{
+ int status, n_dev = 0;
+
+
+
+
+
+ sensor_centre->vl53l0x_off();
+ sensor_left->vl53l0x_off();
+ sensor_right->vl53l0x_off();
+ status = sensor_centre->init_sensor(NEW_SENSOR_CENTRE_ADDRESS);
+ if (status) {
+
+ delete sensor_centre;
+ delete xshutdown_centre;
+ sensor_centre = NULL;
+ xshutdown_centre = NULL;
+ printf("Sensor centre not present\n\r");
+
+ } else {
+
+ printf("Sensor centre present\n\r");
+ n_dev++;
+ }
+ status = sensor_left->init_sensor(NEW_SENSOR_LEFT_ADDRESS);
+ if (status) {
- sensor_centre->VL53L0X_Off();
- sensor_left->VL53L0X_Off();
- sensor_right->VL53L0X_Off();
- status=sensor_centre->InitSensor(NEW_SENSOR_CENTRE_ADDRESS);
- if(status)
- {
- delete sensor_centre;
- delete xshutdown_centre;
- sensor_centre=NULL;
- xshutdown_centre=NULL;
- printf("Sensor centre not present\n\r");
- }
- else
- {
- printf("Sensor centre present\n\r");
- n_dev++;
- }
- status=sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS);
- if(status)
- {
- delete sensor_left;
- delete xshutdown_left;
- sensor_left=NULL;
- xshutdown_left=NULL;
- printf("Sensor left not present\n\r");
- }
- else
- {
- printf("Sensor left present\n\r");
- n_dev++;
- }
+ delete sensor_left;
+ delete xshutdown_left;
+ sensor_left = NULL;
+ xshutdown_left = NULL;
+ printf("Sensor left not present\n\r");
+
+ } else {
+
+ printf("Sensor left present\n\r");
+ n_dev++;
+ }
- status=sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS);
- if(status)
- {
- delete sensor_right;
- delete xshutdown_right;
- sensor_right=NULL;
- xshutdown_right=NULL;
- printf("Sensor right not present\n\r");
- }
- else
- {
- printf("Sensor right present\n\r");
- n_dev++;
- }
+ status = sensor_right->init_sensor(NEW_SENSOR_RIGHT_ADDRESS);
+ if (status) {
+
+ delete sensor_right;
+ delete xshutdown_right;
+ sensor_right = NULL;
+ xshutdown_right = NULL;
+ printf("Sensor right not present\n\r");
+
+ } else {
+
+ printf("Sensor right present\n\r");
+ n_dev++;
+ }
- if(n_dev==0)
- return 1;
- else
- return 0;
+ if (n_dev == 0)
+ return 1;
+ else
+ return 0;
}
--- a/x_nucleo_53l0a1.h Thu Jun 15 13:33:35 2017 +0000
+++ b/x_nucleo_53l0a1.h Mon Aug 07 14:30:21 2017 +0000
@@ -1,7 +1,7 @@
/**
******************************************************************************
* @file x_nucleo_53L0A1.h
- * @author IMG
+ * @author IMG
* @version V1.0.0
* @date 28-November-2016
* @brief Header file for class X_NUCLEO_53L0A1 representing a X-NUCLEO-53L0A1
@@ -59,132 +59,127 @@
class X_NUCLEO_53L0A1
{
public:
- /** Constructor 1
- * @param[in] &i2c device I2C to be used for communication
- */
+ /** Constructor 1
+ * @param[in] &i2c device I2C to be used for communication
+ */
X_NUCLEO_53L0A1(DevI2C *ext_i2c) : dev_i2c(ext_i2c)
{
- stmpe1600_exp0 = new STMPE1600(*ext_i2c, (0x43 * 2)); // U21
+ stmpe1600_exp0 = new Stmpe1600(*ext_i2c, (0x43 * 2)); // U21
- stmpe1600_exp1 = new STMPE1600(*ext_i2c, (0x42 * 2)); // U19
+ stmpe1600_exp1 = new Stmpe1600(*ext_i2c, (0x42 * 2)); // U19
display = new Display(*stmpe1600_exp0, *stmpe1600_exp1);
-
- xshutdown_centre=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic
- sensor_centre=new VL53L0X(*dev_i2c, *xshutdown_centre, A2);
-
- xshutdown_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic
- sensor_left=new VL53L0X(*dev_i2c, *xshutdown_left, D8);
-
- xshutdown_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic
- sensor_right=new VL53L0X(*dev_i2c, *xshutdown_right, D2);
+
+ xshutdown_centre = new Stmpe1600DigiOut(*dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic
+ sensor_centre = new VL53L0X(*dev_i2c, *xshutdown_centre, A2);
+
+ xshutdown_left = new Stmpe1600DigiOut(*dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic
+ sensor_left = new VL53L0X(*dev_i2c, *xshutdown_left, D8);
+
+ xshutdown_right = new Stmpe1600DigiOut(*dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic
+ sensor_right = new VL53L0X(*dev_i2c, *xshutdown_right, D2);
}
-
+
/** Constructor 2
* @param[in] &i2c device I2C to be used for communication
* @param[in] PinName gpio1_top Mbed DigitalOut pin name to be used as a top sensor GPIO_1 INT
* @param[in] PinName gpio1_bottom Mbed DigitalOut pin name to be used as a bottom sensor GPIO_1 INT
* @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT
- * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT
- */
+ * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT
+ */
X_NUCLEO_53L0A1(DevI2C *ext_i2c, PinName gpio1_centre,
- PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) {
- stmpe1600_exp0 = new STMPE1600(*ext_i2c, (0x43 * 2)); // U21
+ PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c)
+ {
+ stmpe1600_exp0 = new Stmpe1600(*ext_i2c, (0x43 * 2)); // U21
- stmpe1600_exp1 = new STMPE1600(*ext_i2c, (0x42 * 2)); // U19
+ stmpe1600_exp1 = new Stmpe1600(*ext_i2c, (0x42 * 2)); // U19
display = new Display(*stmpe1600_exp0, *stmpe1600_exp1);
- xshutdown_centre=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic
- sensor_centre=new VL53L0X(*dev_i2c, *xshutdown_centre, gpio1_centre);
-
- xshutdown_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic
- sensor_left=new VL53L0X(*dev_i2c, *xshutdown_left, gpio1_left);
-
- xshutdown_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic
- sensor_right=new VL53L0X(*dev_i2c, *xshutdown_right, gpio1_right);
- }
+ xshutdown_centre = new Stmpe1600DigiOut(*dev_i2c, GPIO_15, (0x42 * 2)); // U19 on schematic
+ sensor_centre = new VL53L0X(*dev_i2c, *xshutdown_centre, gpio1_centre);
+
+ xshutdown_left = new Stmpe1600DigiOut(*dev_i2c, GPIO_14, (0x43 * 2)); // U21 on schematic
+ sensor_left = new VL53L0X(*dev_i2c, *xshutdown_left, gpio1_left);
- /** Destructor
- */
+ xshutdown_right = new Stmpe1600DigiOut(*dev_i2c, GPIO_15, (0x43 * 2)); // U21 on schematic
+ sensor_right = new VL53L0X(*dev_i2c, *xshutdown_right, gpio1_right);
+ }
+
+ /** Destructor
+ */
~X_NUCLEO_53L0A1()
{
- if(xshutdown_centre!=NULL)
- {
- delete xshutdown_centre;
- xshutdown_centre=NULL;
+ if (xshutdown_centre != NULL) {
+ delete xshutdown_centre;
+ xshutdown_centre = NULL;
+ }
+ if (sensor_centre != NULL) {
+ delete sensor_centre;
+ sensor_centre = NULL;
+ }
+ if (xshutdown_left != NULL) {
+ delete xshutdown_left;
+ xshutdown_left = NULL;
+ }
+ if (sensor_left != NULL) {
+ delete sensor_left;
+ sensor_left = NULL;
}
- if(sensor_centre!=NULL)
- {
- delete sensor_centre;
- sensor_centre=NULL;
- }
- if(xshutdown_left!=NULL)
- {
- delete xshutdown_left;
- xshutdown_left=NULL;
- }
- if(sensor_left!=NULL)
- {
- delete sensor_left;
- sensor_left=NULL;
- }
- if(xshutdown_right!=NULL)
- {
- delete xshutdown_right;
- xshutdown_right=NULL;
- }
- if(sensor_right!=NULL)
- {
- delete sensor_right;
- sensor_right=NULL;
- }
+ if (xshutdown_right != NULL) {
+ delete xshutdown_right;
+ xshutdown_right = NULL;
+ }
+ if (sensor_right != NULL) {
+ delete sensor_right;
+ sensor_right = NULL;
+ }
- delete stmpe1600_exp0;
- stmpe1600_exp0 = NULL;
- delete stmpe1600_exp1;
- stmpe1600_exp1 = NULL;
- delete display;
- display = NULL;
- _instance=NULL;
+ delete stmpe1600_exp0;
+ stmpe1600_exp0 = NULL;
+ delete stmpe1600_exp1;
+ stmpe1600_exp1 = NULL;
+ delete display;
+ display = NULL;
+ _instance = NULL;
}
- /**
- * @brief Creates a singleton object instance
+ /**
+ * @brief Creates a singleton object instance
* @param[in] &i2c device I2C to be used for communication
- * @return Pointer to the object instance
- */
- static X_NUCLEO_53L0A1 *Instance(DevI2C *ext_i2c);
-
- /**
- * @brief Creates a singleton object instance
+ * @return Pointer to the object instance
+ */
+ static X_NUCLEO_53L0A1 *instance(DevI2C *ext_i2c);
+
+ /**
+ * @brief Creates a singleton object instance
* @param[in] &i2c device I2C to be used for communication
- * @param[in] PinName gpio1_centre the pin connected to top sensor INT
- * @param[in] PinName gpio1_left the pin connected to left sensor INT
- * @param[in] PinName gpio1_right the pin connected to right sensor INT
- * @return Pointer to the object instance
- */
- static X_NUCLEO_53L0A1 *Instance(DevI2C *ext_i2c, PinName gpio1_centre,
- PinName gpio1_left, PinName gpio1_right);
+ * @param[in] PinName gpio1_centre the pin connected to top sensor INT
+ * @param[in] PinName gpio1_left the pin connected to left sensor INT
+ * @param[in] PinName gpio1_right the pin connected to right sensor INT
+ * @return Pointer to the object instance
+ */
+ static X_NUCLEO_53L0A1 *instance(DevI2C *ext_i2c, PinName gpio1_centre,
+ PinName gpio1_left, PinName gpio1_right);
- /**
- * @brief Initialize the board and sensors with deft values
- * @return 0 on success
- */
- int InitBoard();
+ /**
+ * @brief Initialize the board and sensors with deft values
+ * @return 0 on success
+ */
+ int init_board();
DevI2C *dev_i2c;
VL53L0X *sensor_centre;
VL53L0X *sensor_left;
VL53L0X *sensor_right;
- STMPE1600 *stmpe1600_exp0;
- STMPE1600 *stmpe1600_exp1;
- STMPE1600DigiOut *xshutdown_centre;
- STMPE1600DigiOut *xshutdown_left;
- STMPE1600DigiOut *xshutdown_right;
+ Stmpe1600 *stmpe1600_exp0;
+ Stmpe1600 *stmpe1600_exp1;
+ Stmpe1600DigiOut *xshutdown_centre;
+ Stmpe1600DigiOut *xshutdown_left;
+ Stmpe1600DigiOut *xshutdown_right;
Display *display;
-
- private:
+
+private:
static X_NUCLEO_53L0A1 *_instance;
};