Librairie adaptée au laboratoire 2
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_6180XA1 by
Revision 16:0d4776564733, committed 2015-10-27
- Comitter:
- gallonm
- Date:
- Tue Oct 27 15:25:11 2015 +0100
- Parent:
- 15:454710d17358
- Child:
- 17:922c88827e4d
- Commit message:
- Added display class.
Updated STMPE1600 class.
Updated cfg.h with the modify of the range scaling.
Updated platform.h with the addition of printf.
Updated x_nucleo_6180xa1.h and x_nucleo_6180xa1.cpp
Changed in this revision
--- a/Components/Display/Display_class.h Tue Oct 20 16:44:28 2015 +0200 +++ b/Components/Display/Display_class.h Tue Oct 27 15:25:11 2015 +0100 @@ -40,30 +40,322 @@ /* Includes ------------------------------------------------------------------*/ #include "mbed.h" +#include "stmpe1600_class.h" +#include "DevI2C.h" +#ifdef __cplusplus +extern "C" { +#endif + +#define FAST_DISPLAY + +#define DP (1<<7) +#define NOT_7_NO_DP( ... ) (uint8_t) ~( __VA_ARGS__ + DP ) +#define S0 (1<<0) +#define S1 (1<<1) +#define S2 (1<<2) +#define S3 (1<<3) +#define S4 (1<<4) +#define S5 (1<<5) +#define S6 (1<<6) + +/* 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 */ + + ['?']= 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), + + ['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 + + +}; + +#undef S0 +#undef S1 +#undef S2 +#undef S3 +#undef S4 +#undef S5 +#undef S6 +#undef DP + +#define DISPLAY_DELAY 1 // in mSec /* Classes -------------------------------------------------------------------*/ -/** Class representing GPIO expander - */ +/** Class representing Display + */ -/* -class Display : +class Display { public: - Display(DevI2C &i2c) : device_i2c(i2c); - +#ifndef FAST_DISPLAY + + Display(DevI2C &i2c, STMPE1600DigiOut &D1, STMPE1600DigiOut &D2, STMPE1600DigiOut &D3, STMPE1600DigiOut &D4, + STMPE1600DigiOut &D_A, STMPE1600DigiOut &D_B, STMPE1600DigiOut &D_C, STMPE1600DigiOut &D_D, + STMPE1600DigiOut &D_E, STMPE1600DigiOut &D_F, STMPE1600DigiOut &D_G) + : Display_D1(D1), Display_D2(D2), Display_D3(D3), Display_D4(D4), + Display_A(D_A), Display_B(D_B), Display_C(D_C), Display_D(D_D), + Display_E(D_E), Display_F(D_F), Display_G(D_G), dev_i2c(i2c) + { + pDisplay_DGT[0] = &Display_D1; + pDisplay_DGT[1] = &Display_D2; + pDisplay_DGT[2] = &Display_D3; + pDisplay_DGT[3] = &Display_D4; + pDisplay_SEG[0] = &Display_A; + pDisplay_SEG[1] = &Display_B; + pDisplay_SEG[2] = &Display_C; + pDisplay_SEG[3] = &Display_D; + pDisplay_SEG[4] = &Display_E; + pDisplay_SEG[5] = &Display_F; + pDisplay_SEG[6] = &Display_G; + + for (int i=0; i<4; i++) { *pDisplay_DGT[i]=1; } + for (int i=0; i<7; i++) { *pDisplay_SEG[i]=1; } + } +#else + Display(DevI2C &i2c) : dev_i2c(i2c) {} +#endif virtual ~Display() { //nella classe board ci sara' un puntatore ad un oggetto di tipo Display che verra' creato con una new - //qui devo fare il delete[] del new + //qui devo fare il delete[] del new } - - - private: - DevI2C &device_i2c; - + +#ifndef FAST_DISPLAY + void Digits_off (void) // all 4 digits off + { + Display_D1=1; + Display_D2=1; + Display_D3=1; + Display_D4=1; + } + + void Digits_on (void) // all 4 digits on + { + Display_D1=0; + Display_D2=0; + Display_D3=0; + Display_D4=0; + } + + void Digit_on (int digit) // digits on + { + *pDisplay_DGT[digit] = 0; + } + + void Digit_off (int digit) // digits on + { + *pDisplay_DGT[digit] = 1; + } + + void Segments_off () // all 7 segments off + { + Display_A=1; + Display_B=1; + Display_C=1; + Display_D=1; + Display_E=1; + Display_F=1; + Display_G=1; + } + + void Segment_off (int seg) // segment off + { + *pDisplay_SEG[seg] = 1; + } + + void Segment_on (int seg) // segment on + { + *pDisplay_SEG[seg] = 0; + } + + + void DisplayString (char str[4]) + { + int i; + const char *pc; + + for( i=0, pc=str; i<4 && *pc!=0 ; i++, pc++){ + _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], i); + if( *(pc+1)== '.'){ + pc++; + } + wait_ms(DISPLAY_DELAY); + Digits_off(); + } + } + + + void _V2_Set7Segment( int Leds, int digit ){ + //Digits_off(); + Segments_off(); // 7 seg off */ + int mask=1; + for (int i=0; i<7; i++) { + if (Leds & mask) Segment_on(i); + mask = mask<<1; + } + Digit_on(digit); + } + + +#else + + void DisplayDigit (char *val, char dgt) + { + uint8_t data[2]; + uint16_t *pdata = (uint16_t*)data; + dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7 + *pdata = *pdata | (uint16_t)0x0780; // all digits off + dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7 + + _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*val], dgt); + } + + void DisplayString (char str[4], char strlen) + { + int i, dgt; + const char *pc; + uint8_t data[2]; + uint16_t *pdata = (uint16_t*)data; + + // dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7 +// *pdata = *pdata | (uint16_t)0x0780; // all digits off +// dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7 + + for(i=0, dgt=4-strlen, pc=str; i<strlen && *pc!=0; i++, pc++, dgt++){ + _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], dgt); + if( *(pc+1)== '.'){ + pc++; + } + wait_ms(DISPLAY_DELAY); + dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7 + *pdata = *pdata | (uint16_t)0x0780; // all digits off + dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7 + } + } + + + void _V2_Set7Segment( int Leds, int digit ){ + //Digits_off(); + + uint16_t dgt; + dgt = 1<<digit; + dgt = ((uint16_t)dgt)<<7; + dgt = ~dgt; + uint8_t data[2]; + uint16_t *pdata = (uint16_t*)data; + + + /* set the exppinname state to lvl */ + dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7 + *pdata = *pdata | (uint16_t)0x007F; // 7 segments off + dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7 + + int mask=1; + for (int i=0; i<7; i++) { + if (Leds & mask) *pdata = *pdata & ~(uint16_t)mask; + mask = mask<<1; + } + *pdata = *pdata & dgt; + dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); // GPSR_0_7 + } +#endif + + + private: + +#ifndef FAST_DISPLAY + STMPE1600DigiOut &Display_D1; + STMPE1600DigiOut &Display_D2; + STMPE1600DigiOut &Display_D3; + STMPE1600DigiOut &Display_D4; + STMPE1600DigiOut *pDisplay_DGT[4]; // the 4 display digits + + STMPE1600DigiOut &Display_A; + STMPE1600DigiOut &Display_B; + STMPE1600DigiOut &Display_C; + STMPE1600DigiOut &Display_D; + STMPE1600DigiOut &Display_E; + STMPE1600DigiOut &Display_F; + STMPE1600DigiOut &Display_G; + STMPE1600DigiOut *pDisplay_SEG[7]; // the 7 digit segmments +#endif + DevI2C &dev_i2c; }; -*/ +#ifdef __cplusplus +} +#endif #endif // __GPIO_EXPANDER_CLASS_H \ No newline at end of file
--- a/Components/STMPE1600/stmpe1600_class.h Tue Oct 20 16:44:28 2015 +0200 +++ b/Components/STMPE1600/stmpe1600_class.h Tue Oct 27 15:25:11 2015 +0100 @@ -43,20 +43,20 @@ #define STMPE1600_DEF_DIGIOUT_LVL 1 /** STMPE1600 registr map **/ -#define VersionId (uint8_t)0x02 -#define SystemControl (uint8_t)0x03 -#define IEGPIOR_0_7 (uint8_t)0x08 +#define VersionId (uint8_t)0x02 +#define SystemControl (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 -#define GPSR_0_7 (uint8_t)0x12 -#define GPSR_8_15 (uint8_t)0x13 -#define GPDR_0_7 (uint8_t)0x14 -#define GPDR_8_15 (uint8_t)0x15 -#define GPIR_0_7 (uint8_t)0x16 -#define GPIR_8_15 (uint8_t)0x17 +#define GPMR_0_7 (uint8_t)0x10 +#define GPMR_8_15 (uint8_t)0x11 +#define GPSR_0_7 (uint8_t)0x12 +#define GPSR_8_15 (uint8_t)0x13 +#define GPDR_0_7 (uint8_t)0x14 +#define GPDR_8_15 (uint8_t)0x15 +#define GPIR_0_7 (uint8_t)0x16 +#define GPIR_8_15 (uint8_t)0x17 typedef enum { // GPIO Expander pin names @@ -79,9 +79,9 @@ } ExpGpioPinName; typedef enum { - INPUT, + INPUT = 0, OUTPUT, - NOT_CONNECTED + NOT_CONNECTED }ExpGpioPinDirection; @@ -89,74 +89,122 @@ public: 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) - { - uint8_t data[2]; - /* 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]; + /* 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); + } void write (int lvl) { uint8_t data[2]; /* set the exppinname state to lvl */ - dev_i2c.i2c_read(data, expdevaddr, GPSR_0_7, 1); - dev_i2c.i2c_read(&data[1], expdevaddr, GPSR_8_15, 1); + 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, 1); - dev_i2c.i2c_write(&data[1], expdevaddr, GPSR_8_15, 1); + if (lvl) *(uint16_t*)data = *(uint16_t*)data | (uint16_t)(1<<(uint16_t)exppinname); + dev_i2c.i2c_write(data, expdevaddr, GPSR_0_7, 2); } - STMPE1600DigiOut& operator=(int lvl) { - write (lvl); - return *this; - } + STMPE1600DigiOut& operator=(int lvl) + { + write (lvl); + return *this; + } private: - DevI2C &dev_i2c; - uint8_t expdevaddr; - ExpGpioPinName exppinname; + DevI2C &dev_i2c; + uint8_t expdevaddr; + ExpGpioPinName exppinname; }; -class STMPE1600DigiIn { - +class STMPE1600DigiIn +{ public: - STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS*2): dev_i2c(i2c), expdevaddr(DevAddr*2), exppinname(inpinname) + STMPE1600DigiIn (DevI2C &i2c, ExpGpioPinName inpinname, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS*2): dev_i2c(i2c), expdevaddr(DevAddr), exppinname(inpinname) { uint8_t data[2]; /* set the exppinname as input pin direction */ - dev_i2c.i2c_read(data, expdevaddr, GPDR_0_7, 1); - dev_i2c.i2c_read(&data[1], expdevaddr, GPDR_8_15, 1); + 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, 1); - dev_i2c.i2c_write(&data[1], expdevaddr, GPDR_8_15, 1); + dev_i2c.i2c_write(data, expdevaddr, GPDR_0_7, 2); } bool read () { uint8_t data[2]; /* read the exppinname */ - dev_i2c.i2c_read(data, expdevaddr, GPMR_0_7, 1); - dev_i2c.i2c_read(&data[1], expdevaddr, GPMR_8_15, 1); + 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; } - operator int() { - return read(); - } + operator int() + { + return read(); + } private: - DevI2C &dev_i2c; - uint8_t expdevaddr; - ExpGpioPinName exppinname; + DevI2C &dev_i2c; + uint8_t expdevaddr; + ExpGpioPinName exppinname; }; +/* +class STMPE1600 { + + public: + STMPE1600 (DevI2C &i2c, + ExpGpioPinDirection GPDR0, ExpGpioPinDirection GPDR1, ExpGpioPinDirection GPDR2, + ExpGpioPinDirection GPDR3, ExpGpioPinDirection GPDR4, ExpGpioPinDirection GPDR5, + ExpGpioPinDirection GPDR6, ExpGpioPinDirection GPDR7, ExpGpioPinDirection GPDR8, + ExpGpioPinDirection GPDR9, ExpGpioPinDirection GPDR10, ExpGpioPinDirection GPDR11, + ExpGpioPinDirection GPDR12, ExpGpioPinDirection GPDR13, ExpGpioPinDirection GPDR14, ExpGpioPinDirection GPDR15, uint8_t DevAddr=STMPE1600_DEF_DEVICE_ADDRESS ) :dev_i2c(i2c) + + { + dev_i2c = i2c; + expdevaddr = DevAddr; + GPDR0_15 = (uint16_t)0; // gpio dir all IN + GPSR0_15 = (uint16_t)0x0ffff; // gpio status all 1 + if (GPDR0 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0001; + if (GPDR1 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0002; + if (GPDR2 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0004; + if (GPDR3 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0008; + if (GPDR4 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0010; + if (GPDR5 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0020; + if (GPDR6 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0040; + if (GPDR7 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0080; + if (GPDR8 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0100; + if (GPDR9 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0200; + if (GPDR10 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0400; + if (GPDR11 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x0800; + if (GPDR12 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x1000; + if (GPDR13 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x2000; + if (GPDR14 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x4000; + if (GPDR15 == OUTPUT) GPDR0_15 = GPDR0_15 | (uint16_t)0x8000; + dev_i2c.i2c_write((uint8_t*)&GPDR0_15, expdevaddr, GPDR_0_7, 2); + dev_i2c.i2c_write((uint8_t*)&GPSR0_15, expdevaddr, GPSR_0_7, 2); + } + + void readGPSR0_15 (uint16_t * gpsr0_15){ + dev_i2c.i2c_read((uint8_t*)gpsr0_15, expdevaddr, GPSR_0_7, 2); + GPSR0_15 = gpsr0_15; + } + + void writeGPSR0_15 (uint16_t *gpsr0_15){ + dev_i2c.i2c_write((uint8_t*)*gpsr0_15, expdevaddr, GPSR_0_7, 2); + GPSR0_15 = *gpsr0_15; + } + + private: + DevI2C &dev_i2c; + uint16_t GPDR0_15; + uint16_t GPSR0_15; + uint8_t expdevaddr; + }; +*/ #endif // __STMPE1600_CLASS
--- a/Components/VL6180X/vl6180x_cfg.h Tue Oct 20 16:44:28 2015 +0200 +++ b/Components/VL6180X/vl6180x_cfg.h Tue Oct 27 15:25:11 2015 +0100 @@ -58,7 +58,7 @@ * @li 3 : Fixed scaling by 3 * @li -1 -2 -3 : Run time programmable through @a VL6180x_UpscaleSetScaling(). Default scaling factore is -VL6180x_UPSCALE_SUPPORT \n */ -#define VL6180x_UPSCALE_SUPPORT -1 +#define VL6180x_UPSCALE_SUPPORT -3 // -1 to -3 /** * @def VL6180x_ALS_SUPPORT @@ -106,7 +106,7 @@ * Device that do not formally support extended ranging should only be used with a scaling factor of 1. * Correct operation with scaling factor other than 1 (>200mm ) is not granted by ST. */ -#define VL6180x_EXTENDED_RANGE 0 +#define VL6180x_EXTENDED_RANGE 1 // 0 to 1 #if (VL6180x_EXTENDED_RANGE) && (VL6180x_ALS_SUPPORT)
--- a/Components/VL6180X/vl6180x_class.cpp Tue Oct 20 16:44:28 2015 +0200 +++ b/Components/VL6180X/vl6180x_class.cpp Tue Oct 27 15:25:11 2015 +0100 @@ -34,11 +34,11 @@ * ****************************************************************************** */ - + /* Includes */ #include "vl6180x_class.h" - + #ifndef VL6180x_RANGE_STATUS_ERRSTRING #warning "VL6180x_RANGE_STATUS_ERRSTRING not defined ?" /* TODO you may remove or comment these #warning and keep the default below to keep compatibility @@ -48,7 +48,7 @@ */ #define VL6180x_RANGE_STATUS_ERRSTRING 0 #endif - + #ifndef VL6180X_SAFE_POLLING_ENTER #warning "VL6180X_SAFE_POLLING_ENTER not defined, likely old vl6180x_cfg.h file ?" /* TODO you may remove or comment these #warning and keep the default below to keep compatibility @@ -58,41 +58,41 @@ */ #define VL6180X_SAFE_POLLING_ENTER 0 /* off by default as in api 2.0 */ #endif - + #ifndef VL6180X_LOG_ENABLE /** * Force VL6180X_LOG_ENABLE to none as default */ #define VL6180X_LOG_ENABLE 0 #endif - + #if VL6180x_RANGE_STATUS_ERRSTRING /**@def VL6180x_HAVE_RANGE_STATUS_ERRSTRING * @brief is defined when @a #VL6180x_RANGE_STATUS_ERRSTRING is enable */ #define VL6180x_HAVE_RANGE_STATUS_ERRSTRING #endif - - + + /** @brief Get API version as "hex integer" 0xMMnnss */ #define VL6180x_ApiRevInt ((VL6180x_API_REV_MAJOR<<24)+(VL6180x_API_REV_MINOR<<16)+VL6180x_API_REV_SUB) - + /** Get API version as string for exe "2.1.12" " */ #define VL6180x_ApiRevStr VL6180X_STR(VL6180x_API_REV_MAJOR) "." VL6180X_STR(VL6180x_API_REV_MINOR) "." VL6180X_STR(VL6180x_API_REV_SUB) - + /** @defgroup api_init Init functions * @brief API init functions * @ingroup api_hl * @{ */ - - + + /****************** define for i2c configuration *******************************/ - -#define TEMP_BUF_SIZE 32 - + +#define TEMP_BUF_SIZE 32 + #define IsValidGPIOFunction(x) ((x)==GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT || (x)==GPIOx_SELECT_OFF) /** * @brief Clear All interrupt causes (als+range+error) @@ -115,19 +115,19 @@ * @return 0 On success */ #define VL6180x_RangeClearInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_RANGING) - + /******************************************************************************/ /******************************* file api.c ***********************************/ - + #define VL6180x_9to7Conv(x) (x) - + /* TODO when set all "cached" value with "default init" are updated after init from register read back */ #define REFRESH_CACHED_DATA_AFTER_INIT 1 - - + + #define IsValidGPIOFunction(x) ((x)==GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT || (x)==GPIOx_SELECT_OFF) - - + + /** default value ECE factor Molecular */ #define DEF_ECE_FACTOR_M 85 /** default value ECE factor Denominator */ @@ -142,21 +142,21 @@ #define DEF_DMAX_ENABLE 1 /** default ambient tuning factor %x1000 */ #define DEF_AMBIENT_TUNING 80 - + #if VL6180x_SINGLE_DEVICE_DRIVER extern struct VL6180xDevData_t SingleVL6180xDevData; #define VL6180xDevDataGet(dev, field) (SingleVL6180xDevData.field) #define VL6180xDevDataSet(dev, field, data) SingleVL6180xDevData.field=(data) #endif - + #define LUXRES_FIX_PREC 8 #define GAIN_FIX_PREC 8 /* ! if not sme as LUX_PREC then :( adjust GetLux */ #define AN_GAIN_MULT (1<<GAIN_FIX_PREC) - - + + static int32_t _GetAveTotalTime(VL6180xDev_t dev); static int VL6180x_RangeSetEarlyConvergenceEestimateThreshold(VL6180xDev_t dev); - + /** * ScalerLookUP scaling factor-1 to register #RANGE_SCALER lookup */ @@ -178,8 +178,8 @@ (uint16_t)(1.0f * AN_GAIN_MULT), (uint16_t)(40.0f * AN_GAIN_MULT), }; - - + + #if VL6180x_RANGE_STATUS_ERRSTRING const char * ROMABLE_DATA VL6180x_RangeStatusErrString[]={ "No Error", @@ -198,17 +198,17 @@ "Raw Ranging Algo Overflow", "Ranging Algo Underflow", "Ranging Algo Overflow", - + "Filtered by post processing" }; - + const char * VL6180x_RangeGetStatusErrString(uint8_t RangeErrCode){ if( RangeErrCode > sizeof(VL6180x_RangeStatusErrString)/sizeof(VL6180x_RangeStatusErrString[0]) ) return NULL; return VL6180x_RangeStatusErrString[RangeErrCode]; } #endif - + #if VL6180x_UPSCALE_SUPPORT == 1 #define _GetUpscale(dev, ... ) 1 #define _SetUpscale(...) -1 @@ -226,8 +226,8 @@ #define _GetUpscale(dev, ... ) VL6180xDevDataGet(dev, UpscaleFactor) #define _SetUpscale(dev, Scaling ) VL6180xDevDataSet(dev, UpscaleFactor, Scaling) #endif - - + + #if VL6180x_SINGLE_DEVICE_DRIVER /** * the unique driver data When single device driver is active @@ -248,16 +248,16 @@ #endif }; #endif /* VL6180x_SINGLE_DEVICE_DRIVER */ - - - + + + #define Fix7_2_KCPs(x) ((((uint32_t)(x))*1000)>>7) - - + + #if VL6180x_WRAP_AROUND_FILTER_SUPPORT || VL6180x_HAVE_DMAX_RANGING static int _GetRateResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); #endif - + #if VL6180x_WRAP_AROUND_FILTER_SUPPORT static int _filter_Init(VL6180xDev_t dev); static int _filter_GetResult(VL6180xDev_t dev, VL6180x_RangeData_t *pData); @@ -265,8 +265,8 @@ #else #define _IsWrapArroundActive(dev) 0 #endif - - + + #if VL6180x_HAVE_DMAX_RANGING void _DMax_OneTimeInit(VL6180xDev_t dev); static int _DMax_InitData(VL6180xDev_t dev); @@ -277,22 +277,22 @@ #define _DMax_OneTimeInit(...) (void)0 #define _IsDMaxActive(...) 0 #endif - + static int VL6180x_RangeStaticInit(VL6180xDev_t dev); static int VL6180x_UpscaleStaticInit(VL6180xDev_t dev); - + int VL6180X::VL6180x_WaitDeviceBooted(VL6180xDev_t dev){ - uint8_t FreshOutReset; - int status; - LOG_FUNCTION_START(""); - do{ - status = VL6180x_RdByte(dev,SYSTEM_FRESH_OUT_OF_RESET, &FreshOutReset); - } - while( FreshOutReset!=1 && status==0); - LOG_FUNCTION_END(status); - return status; + uint8_t FreshOutReset; + int status; + LOG_FUNCTION_START(""); + do{ + status = VL6180x_RdByte(dev,SYSTEM_FRESH_OUT_OF_RESET, &FreshOutReset); + } + while( FreshOutReset!=1 && status==0); + LOG_FUNCTION_END(status); + return status; } - + int VL6180X::VL6180x_InitData(VL6180xDev_t dev){ int status, dmax_status ; int8_t offset; @@ -300,30 +300,30 @@ uint32_t CalValue; uint16_t u16; uint32_t XTalkCompRate_KCps; - + LOG_FUNCTION_START(""); - + VL6180xDevDataSet(dev, EceFactorM , DEF_ECE_FACTOR_M); VL6180xDevDataSet(dev, EceFactorD , DEF_ECE_FACTOR_D); - + #ifdef VL6180x_HAVE_UPSCALE_DATA VL6180xDevDataSet(dev, UpscaleFactor , DEF_UPSCALE); #endif - + #ifdef VL6180x_HAVE_ALS_DATA VL6180xDevDataSet(dev, IntegrationPeriod, DEF_INT_PEFRIOD); VL6180xDevDataSet(dev, AlsGainCode, DEF_ALS_GAIN); VL6180xDevDataSet(dev, AlsScaler, DEF_ALS_SCALER); #endif - + #ifdef VL6180x_HAVE_WRAP_AROUND_DATA VL6180xDevDataSet(dev, WrapAroundFilterActive, (VL6180x_WRAP_AROUND_FILTER_SUPPORT >0)); VL6180xDevDataSet(dev, DMaxEnable, DEF_DMAX_ENABLE); #endif - + _DMax_OneTimeInit(dev); do{ - + /* backup offset initial value from nvm these must be done prior any over call that use offset */ status = VL6180X::VL6180x_RdByte(dev,SYSRANGE_PART_TO_PART_RANGE_OFFSET, (uint8_t*)&offset); if( status ){ @@ -331,7 +331,7 @@ break; } VL6180xDevDataSet(dev, Part2PartOffsetNVM, offset); - + status=VL6180x_RdDWord( dev, SYSRANGE_RANGE_IGNORE_THRESHOLD, &CalValue); if( status ){ VL6180x_ErrLog("Part2PartAmbNVM rd fail"); @@ -341,7 +341,7 @@ CalValue=0x00CE03F8; } VL6180xDevDataSet(dev, Part2PartAmbNVM, CalValue); - + status = VL6180x_RdWord(dev, SYSRANGE_CROSSTALK_COMPENSATION_RATE ,&u16); if( status){ VL6180x_ErrLog("SYSRANGE_CROSSTALK_COMPENSATION_RATE rd fail "); @@ -349,13 +349,13 @@ } XTalkCompRate_KCps = Fix7_2_KCPs(u16); VL6180xDevDataSet(dev, XTalkCompRate_KCps , XTalkCompRate_KCps ); - + dmax_status = _DMax_InitData(dev); if( dmax_status < 0 ){ VL6180x_ErrLog("DMax init failure"); break; } - + /* Read or wait for fresh out of reset */ status = VL6180x_RdByte(dev,SYSTEM_FRESH_OUT_OF_RESET, &FreshOutReset); if( status ) { @@ -364,14 +364,14 @@ } if( FreshOutReset!= 1 || dmax_status ) status = CALIBRATION_WARNING; - + } while(0); - + LOG_FUNCTION_END(status); return status; } - + int8_t VL6180X::VL6180x_GetOffsetCalibrationData(VL6180xDev_t dev) { int8_t offset; @@ -380,14 +380,14 @@ LOG_FUNCTION_END( offset ); return offset; } - + void VL6180X::VL6180x_SetOffsetCalibrationData(VL6180xDev_t dev, int8_t offset) { LOG_FUNCTION_START("%d", offset); VL6180xDevDataSet(dev, Part2PartOffsetNVM, offset); LOG_FUNCTION_END(0); } - + int VL6180X::VL6180x_SetXTalkCompensationRate(VL6180xDev_t dev, FixPoint97_t Rate) { int status; @@ -403,11 +403,11 @@ LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_SetI2CAddress(VL6180xDev_t dev, uint8_t NewAddress){ int status; LOG_FUNCTION_START(""); - + status = VL6180x_WrByte(dev, I2C_SLAVE_DEVICE_ADDRESS, NewAddress); if( status ){ VL6180x_ErrLog("new i2c addr Wr fail"); @@ -415,43 +415,43 @@ LOG_FUNCTION_END(status); return status; } - - + + uint16_t VL6180X::VL6180x_GetUpperLimit(VL6180xDev_t dev) { uint16_t limit; int scaling; - + LOG_FUNCTION_START(""); - + scaling = _GetUpscale(dev); /* FIXME we do assume here _GetUpscale is valid if user call us prior to init we may overflow the LUT mem area */ limit = UpperLimitLookUP[scaling - 1]; - + LOG_FUNCTION_END((int )limit); return limit; } - - - + + + int VL6180X::VL6180x_StaticInit(VL6180xDev_t dev){ int status=0, init_status; LOG_FUNCTION_START(""); - + /* TODO doc When using configurable scaling but using 1x as start condition * load tunning upscale or not ??? */ if( _GetUpscale(dev) == 1 && !(VL6180x_UPSCALE_SUPPORT<0)) - init_status=VL6180x_RangeStaticInit(dev); + init_status=VL6180x_RangeStaticInit(dev); else - init_status=VL6180x_UpscaleStaticInit(dev); - + init_status=VL6180x_UpscaleStaticInit(dev); + if( init_status <0 ){ - VL6180x_ErrLog("StaticInit fail"); - goto error; + VL6180x_ErrLog("StaticInit fail"); + goto error; } else if(init_status > 0){ - VL6180x_ErrLog("StaticInit warning"); + VL6180x_ErrLog("StaticInit warning"); } - + #if REFRESH_CACHED_DATA_AFTER_INIT /* update cached value after tuning applied */ do{ @@ -460,7 +460,7 @@ status= VL6180x_RdByte(dev, FW_ALS_RESULT_SCALER, &data); if( status ) break; VL6180xDevDataSet(dev, AlsScaler, data); - + status= VL6180x_RdByte(dev, SYSALS_ANALOGUE_GAIN, &data); if( status ) break; VL6180x_AlsSetAnalogueGain(dev, data); @@ -472,45 +472,45 @@ VL6180x_ErrLog("StaticInit fail"); } if( !status && init_status){ - status = init_status; + status = init_status; } error: LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_SetGroupParamHold(VL6180xDev_t dev, int Hold) { int status; uint8_t value; - + LOG_FUNCTION_START("%d", Hold); if( Hold ) value = 1; else value = 0; status = VL6180x_WrByte(dev, SYSTEM_GROUPED_PARAMETER_HOLD, value); - + LOG_FUNCTION_END(status); return status; - + } - + int VL6180X::VL6180x_Prepare(VL6180xDev_t dev) { int status; LOG_FUNCTION_START(""); - + do{ status=VL6180x_StaticInit(dev); if( status<0) break; - + /* set range InterruptMode to new sample */ status=VL6180x_RangeConfigInterrupt(dev, CONFIG_GPIO_INTERRUPT_DISABLED ); if( status) break; - + /* set default threshold */ status=VL6180x_RangeSetRawThresholds(dev, 10, 200); if( status ){ @@ -541,10 +541,10 @@ } while(0); LOG_FUNCTION_END(status); - + return status; } - + #if VL6180x_ALS_SUPPORT int VL6180X::VL6180x_AlsGetLux(VL6180xDev_t dev, lux_t *pLux) { @@ -555,14 +555,14 @@ uint32_t AlsAnGain; uint32_t GainFix; uint32_t AlsScaler; - + #if LUXRES_FIX_PREC != GAIN_FIX_PREC #error "LUXRES_FIX_PREC != GAIN_FIX_PREC review these code to be correct" #endif const uint32_t LuxResxIntIme =(uint32_t)(0.56f* DEF_INT_PEFRIOD *(1<<LUXRES_FIX_PREC)); - + LOG_FUNCTION_START("%p", pLux); - + status = VL6180x_RdWord( dev, RESULT_ALS_VAL, &RawAls); if( !status){ /* wer are yet here at no fix point */ @@ -577,34 +577,34 @@ luxValue = luxValue / (AlsScaler * GainFix); *pLux=luxValue; } - + LOG_FUNCTION_END_FMT(status, "%x",(int)*pLux); return status; } - + int VL6180X::VL6180x_AlsGetMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData) { int status; uint8_t ErrStatus; - + LOG_FUNCTION_START("%p", pAlsData); - + status = VL6180x_AlsGetLux(dev, &pAlsData->lux); if( !status ){ status = VL6180x_RdByte(dev, RESULT_ALS_STATUS, & ErrStatus); pAlsData->errorStatus = ErrStatus>>4; } LOG_FUNCTION_END_FMT(status,"%d %d", (int)pAlsData->lux, (int)pAlsData->errorStatus); - + return status; } - - + + int VL6180X::VL6180x_AlsPollMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData) { int status; int ClrStatus; uint8_t IntStatus; - + LOG_FUNCTION_START("%p", pAlsData); #if VL6180X_SAFE_POLLING_ENTER /* if device get stopped with left interrupt uncleared , it is required to clear them now or poll for new condition will never occur*/ @@ -614,13 +614,13 @@ goto over; } #endif - + status=VL6180x_AlsSetSystemMode(dev, MODE_START_STOP|MODE_SINGLESHOT); if( status){ VL6180x_ErrLog("VL6180x_AlsSetSystemMode fail"); goto over; } - + /* poll for new sample ready */ while (1 ) { status = VL6180x_AlsGetInterruptStatus(dev, &IntStatus); @@ -630,14 +630,14 @@ if (IntStatus == RES_INT_STAT_GPIO_NEW_SAMPLE_READY) { break; /* break on new data (status is 0) */ } - + VL6180x_PollDelay(dev); }; - + if (!status) { status = VL6180x_AlsGetMeasurement(dev, pAlsData); } - + ClrStatus = VL6180x_AlsClearInterrupt(dev); if (ClrStatus) { VL6180x_ErrLog("VL6180x_AlsClearInterrupt fail"); @@ -647,22 +647,22 @@ } over: LOG_FUNCTION_END(status); - + return status; } - + int VL6180X::VL6180x_AlsGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus) { int status; uint8_t IntStatus; LOG_FUNCTION_START("%p", pIntStatus); - + status = VL6180x_RdByte(dev, RESULT_INTERRUPT_STATUS_GPIO, &IntStatus); *pIntStatus= (IntStatus>>3)&0x07; - + LOG_FUNCTION_END_FMT(status, "%d", (int)*pIntStatus); return status; } - + int VL6180X::VL6180x_AlsWaitDeviceReady(VL6180xDev_t dev, int MaxLoop ){ int status; int n; @@ -679,7 +679,7 @@ u8 = u8 & ALS_DEVICE_READY_MASK; if( u8 ) break; - + } if( !status && !u8 ){ status = TIME_OUT; @@ -688,7 +688,7 @@ LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_AlsSetSystemMode(VL6180xDev_t dev, uint8_t mode) { int status; @@ -704,11 +704,11 @@ LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_AlsConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt) { int status; - + if( ConfigGpioInt<= CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY){ status = VL6180x_UpdateByte(dev, SYSTEM_INTERRUPT_CONFIG_GPIO, (uint8_t)(~CONFIG_GPIO_ALS_MASK), (ConfigGpioInt<<3)); } @@ -719,78 +719,78 @@ LOG_FUNCTION_END(status); return status; } - - - + + + int VL6180X::VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high) { int status; - + LOG_FUNCTION_START("%d %d", (int )low, (int)high); - + status = VL6180x_WrByte(dev, SYSALS_THRESH_LOW, low); //FIXME i valori passati devono essere uint16_t (vedi registri), inoltre i valori delle soglie NON sono in lux! bisogna invertire il calcolo fatto nella VL6180x_AlsGetLux() if(!status ){ status = VL6180x_WrByte(dev, SYSALS_THRESH_HIGH, high); } - + LOG_FUNCTION_END(status) ; return status; } - - + + int VL6180X::VL6180x_AlsSetAnalogueGain(VL6180xDev_t dev, uint8_t gain) { int status; uint8_t GainTotal; - + LOG_FUNCTION_START("%d", (int )gain); gain&=~0x40; if (gain > 7) { gain = 7; } GainTotal = gain|0x40; - + status = VL6180x_WrByte(dev, SYSALS_ANALOGUE_GAIN, GainTotal); if( !status){ VL6180xDevDataSet(dev, AlsGainCode, gain); } - + LOG_FUNCTION_END_FMT(status, "%d %d", (int ) gain, (int )GainTotal); return status; } - + int VL6180X::VL6180x_AlsSetInterMeasurementPeriod(VL6180xDev_t dev, uint16_t intermeasurement_period_ms) { int status; - + LOG_FUNCTION_START("%d",(int)intermeasurement_period_ms); /* clipping: range is 0-2550ms */ if (intermeasurement_period_ms >= 255 *10) intermeasurement_period_ms = 255 *10; status=VL6180x_WrByte(dev, SYSALS_INTERMEASUREMENT_PERIOD, (uint8_t)(intermeasurement_period_ms/10)); - + LOG_FUNCTION_END_FMT(status, "%d", (int) intermeasurement_period_ms); return status; } - - + + int VL6180X::VL6180x_AlsSetIntegrationPeriod(VL6180xDev_t dev, uint16_t period_ms) { int status; uint16_t SetIntegrationPeriod; - + LOG_FUNCTION_START("%d", (int)period_ms); - + if( period_ms>=1 ) SetIntegrationPeriod = period_ms - 1; else SetIntegrationPeriod = period_ms; - + if (SetIntegrationPeriod > 464) { SetIntegrationPeriod = 464; } else if (SetIntegrationPeriod == 255) { SetIntegrationPeriod++; /* can't write 255 since this causes the device to lock out.*/ } - + status =VL6180x_WrWord(dev, SYSALS_INTEGRATION_PERIOD, SetIntegrationPeriod); if( !status ){ VL6180xDevDataSet(dev, IntegrationPeriod, SetIntegrationPeriod) ; @@ -798,20 +798,20 @@ LOG_FUNCTION_END_FMT(status, "%d", (int)SetIntegrationPeriod); return status; } - + #endif /* HAVE_ALS_SUPPORT */ - - + + int VL6180X::VL6180x_RangePollMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData) { int status; int ClrStatus; IntrStatus_t IntStatus; - + LOG_FUNCTION_START(""); /* start single range measurement */ - - + + #if VL6180X_SAFE_POLLING_ENTER /* if device get stopped with left interrupt uncleared , it is required to clear them now or poll for new condition will never occur*/ status=VL6180x_RangeClearInterrupt(dev); @@ -826,7 +826,7 @@ VL6180x_ErrLog("VL6180x_RangeSetSystemMode fail"); goto done; } - + /* poll for new sample ready */ while(1 ){ status=VL6180x_RangeGetInterruptStatus(dev, &IntStatus.val); @@ -846,11 +846,11 @@ VL6180x_PollDelay(dev); } /* //![single_shot_snipet] */ - + if ( !status ){ status = VL6180x_RangeGetMeasurement(dev, pRangeData); } - + /* clear range interrupt source */ ClrStatus = VL6180x_RangeClearInterrupt(dev); if( ClrStatus ){ @@ -864,17 +864,17 @@ LOG_FUNCTION_END(status); return status; } - - - + + + int VL6180X::VL6180x_RangeGetMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData) { int status; uint16_t RawRate; uint8_t RawStatus; - + LOG_FUNCTION_START(""); - + status = VL6180x_RangeGetResult(dev, &pRangeData->range_mm); if( !status ){ status = VL6180x_RdWord(dev,RESULT_RANGE_SIGNAL_RATE, &RawRate ); @@ -887,11 +887,11 @@ else{ VL6180x_ErrLog("Rd RESULT_RANGE_STATUS fail"); } - #if VL6180x_WRAP_AROUND_FILTER_SUPPORT || VL6180x_HAVE_DMAX_RANGING + #if VL6180x_WRAP_AROUND_FILTER_SUPPORT || VL6180x_HAVE_DMAX_RANGING status = _GetRateResult(dev, pRangeData); if( status ) - goto error; - #endif + goto error; + #endif #if VL6180x_WRAP_AROUND_FILTER_SUPPORT /* if enabled run filter */ if( _IsWrapArroundActive(dev) ){ @@ -905,7 +905,7 @@ } } #endif - + #if VL6180x_HAVE_DMAX_RANGING if(_IsDMaxActive(dev) ){ _DMax_Compute(dev, pRangeData); @@ -923,15 +923,15 @@ LOG_FUNCTION_END_FMT(status, "%d %d %d", (int)pRangeData->range_mm, (int)pRangeData->signalRate_mcps, (int)pRangeData->errorStatus) ; return status; } - - + + int VL6180X::VL6180x_RangeGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData) { int status; IntrStatus_t IntStatus; - + LOG_FUNCTION_START(); - + status = VL6180x_RangeGetInterruptStatus(dev, &IntStatus.val); if( status ==0 ){ if( IntStatus.status.Error !=0 ){ @@ -959,7 +959,7 @@ LOG_FUNCTION_END(status) ; return status; } - + int VL6180X::VL6180x_FilterSetState(VL6180xDev_t dev, int state){ int status; LOG_FUNCTION_START("%d", state); @@ -972,7 +972,7 @@ LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_FilterGetState(VL6180xDev_t dev){ int status; LOG_FUNCTION_START(""); @@ -984,14 +984,14 @@ LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_RangeGetResult(VL6180xDev_t dev, int32_t *pRange_mm) { int status; uint8_t RawRange; int32_t Upscale; - + LOG_FUNCTION_START("%p",pRange_mm); - + status = VL6180x_RdByte(dev, RESULT_RANGE_VAL, &RawRange); if( !status ){ Upscale = _GetUpscale(dev); @@ -1000,7 +1000,7 @@ LOG_FUNCTION_END_FMT(status, "%d", (int)*pRange_mm); return status; } - + int VL6180X::VL6180x_RangeSetRawThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high) { int status; @@ -1010,11 +1010,11 @@ if( !status){ status=VL6180x_WrByte(dev, SYSRANGE_THRESH_LOW, low); } - + LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_RangeSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high, int UseSafeParamHold) { int status; @@ -1045,20 +1045,20 @@ } while(0); } - + LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_RangeGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high) { int status; uint8_t RawLow, RawHigh; int scale; - + LOG_FUNCTION_START("%p %p", low , high); - + scale=_GetUpscale(dev,UpscaleFactor); do{ if( high != NULL ){ @@ -1082,8 +1082,8 @@ LOG_FUNCTION_END_FMT(status, "%d %d",(int)*low ,(int)*high); return status; } - - + + int VL6180X::VL6180x_RangeGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus) { int status; uint8_t IntStatus; @@ -1092,12 +1092,12 @@ * not just new sample or over status , that will nevr show up in case of error*/ status = VL6180x_RdByte(dev, RESULT_INTERRUPT_STATUS_GPIO, &IntStatus); *pIntStatus= IntStatus&0xC7; - + LOG_FUNCTION_END_FMT(status, "%d", (int)*pIntStatus); return status; } - - + + int VL6180X::VL6180x_GetInterruptStatus(VL6180xDev_t dev, uint8_t *IntStatus) { int status; @@ -1106,7 +1106,7 @@ LOG_FUNCTION_END_FMT(status, "%d", (int)*IntStatus); return status; } - + int VL6180X::VL6180x_ClearInterrupt(VL6180xDev_t dev, uint8_t IntClear ) { int status; @@ -1120,13 +1120,13 @@ LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_RangeStaticInit(VL6180xDev_t dev) { int status; LOG_FUNCTION_START(""); - + /* REGISTER_TUNING_SR03_270514_CustomerView.txt */ VL6180x_WrByte( dev, 0x0207, 0x01); VL6180x_WrByte( dev, 0x0208, 0x01); @@ -1158,7 +1158,7 @@ VL6180x_WrByte( dev, 0x01ac, 0x3e); VL6180x_WrByte( dev, 0x01a7, 0x1f); VL6180x_WrByte( dev, 0x0030, 0x00); - + /* Recommended : Public registers - See data sheet for more detail */ VL6180x_WrByte( dev, 0x0011, 0x10); /* Enables polling for New Sample ready when measurement completes */ VL6180x_WrByte( dev, 0x010a, 0x30); /* Set the averaging sample period (compromise between lower noise and increased execution time) */ @@ -1166,21 +1166,21 @@ VL6180x_WrByte( dev, 0x0031, 0xFF); /* sets the # of range measurements after which auto calibration of system is performed */ VL6180x_WrByte( dev, 0x0040, 0x63); /* Set ALS integration time to 100ms */ VL6180x_WrByte( dev, 0x002e, 0x01); /* perform a single temperature calibration of the ranging sensor */ - + /* Optional: Public registers - See data sheet for more detail */ VL6180x_WrByte( dev, 0x001b, 0x09); /* Set default ranging inter-measurement period to 100ms */ VL6180x_WrByte( dev, 0x003e, 0x31); /* Set default ALS inter-measurement period to 500ms */ VL6180x_WrByte( dev, 0x0014, 0x24); /* Configures interrupt on New sample ready */ - - + + status=VL6180x_RangeSetMaxConvergenceTime(dev, 50); /* Calculate ece value on initialization (use max conv) */ LOG_FUNCTION_END(status); - + return status; } - + #if VL6180x_UPSCALE_SUPPORT != 1 - + int VL6180X::_UpscaleInitPatch0(VL6180xDev_t dev){ int status; uint32_t CalValue=0; @@ -1188,7 +1188,7 @@ status=VL6180x_WrDWord( dev, 0xDA, CalValue); return status; } - + /* only include up-scaling register setting when up-scale support is configured in */ int VL6180X::VL6180x_UpscaleRegInit(VL6180xDev_t dev) { @@ -1204,9 +1204,9 @@ VL6180x_WrByte( dev, 0x00e7, 0x03); VL6180x_WrByte( dev, 0x00f5, 0x02); VL6180x_WrByte( dev, 0x00d9, 0x05); - + _UpscaleInitPatch0(dev); - + VL6180x_WrByte( dev, 0x009f, 0x00); VL6180x_WrByte( dev, 0x00a3, 0x28); VL6180x_WrByte( dev, 0x00b7, 0x00); @@ -1243,15 +1243,15 @@ #else #define VL6180x_UpscaleRegInit(...) -1 #endif - + int VL6180X::VL6180x_UpscaleSetScaling(VL6180xDev_t dev, uint8_t scaling) { int status; uint16_t Scaler; int8_t Offset; - + LOG_FUNCTION_START("%d",(int) scaling); - + #ifdef VL6180x_HAVE_UPSCALE_DATA #define min_scaling 1 #define max_scaling sizeof(ScalerLookUP)/sizeof(ScalerLookUP[0]) @@ -1260,13 +1260,13 @@ #define min_scaling VL6180x_UPSCALE_SUPPORT #define max_scaling VL6180x_UPSCALE_SUPPORT #endif - + if( scaling>=min_scaling && scaling<= max_scaling ){ - + Scaler = ScalerLookUP[scaling-1]; status = VL6180x_WrWord(dev, RANGE_SCALER, Scaler); _SetUpscale(dev, scaling ); - + /* Apply scaling on part-2-part offset */ Offset = VL6180xDevDataGet(dev, Part2PartOffsetNVM)/scaling; status = VL6180x_WrByte(dev, SYSRANGE_PART_TO_PART_RANGE_OFFSET, Offset); @@ -1275,7 +1275,7 @@ status = VL6180x_RangeSetEceState(dev, scaling == 1); /* enable ece only at 1x scaling */ } if( status == 0 && !VL6180x_EXTENDED_RANGE && scaling!=1 ){ - status = NOT_GUARANTEED ; + status = NOT_GUARANTEED ; } #endif } @@ -1287,24 +1287,24 @@ LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_UpscaleGetScaling(VL6180xDev_t dev) { int status; LOG_FUNCTION_START(""); status=_GetUpscale(dev ); LOG_FUNCTION_END(status); - + return status; } - - + + int VL6180X::VL6180x_UpscaleStaticInit(VL6180xDev_t dev) { /* todo make these a fail macro in case only 1x is suppoted */ int status; - + LOG_FUNCTION_START(""); do{ status=VL6180x_UpscaleRegInit(dev); @@ -1328,13 +1328,13 @@ LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_SetGPIOxPolarity(VL6180xDev_t dev, int pin, int active_high) { int status; LOG_FUNCTION_START("%d %d",(int) pin, (int)active_high); - + if( pin ==0 || pin ==1 ){ uint16_t RegIndex; uint8_t DataSet; @@ -1342,38 +1342,38 @@ RegIndex= SYSTEM_MODE_GPIO0; else RegIndex= SYSTEM_MODE_GPIO1; - + if (active_high ) DataSet = GPIOx_POLARITY_SELECT_MASK; else DataSet = 0; - + status = VL6180x_UpdateByte(dev, RegIndex, (uint8_t)~GPIOx_POLARITY_SELECT_MASK, DataSet); } else{ VL6180x_ErrLog("Invalid pin param %d", (int)pin); status = INVALID_PARAMS; } - + LOG_FUNCTION_END(status); - + return status; } - + int VL6180X::VL6180x_SetGPIOxFunctionality(VL6180xDev_t dev, int pin, uint8_t functionality) { int status; - + LOG_FUNCTION_START("%d %d",(int) pin, (int)functionality); - + if( ((pin ==0) || (pin ==1)) && IsValidGPIOFunction(functionality) ){ uint16_t RegIndex; - + if( pin==0 ) RegIndex= SYSTEM_MODE_GPIO0; else RegIndex= SYSTEM_MODE_GPIO1; - + status = VL6180x_UpdateByte(dev, RegIndex, (uint8_t)~GPIOx_FUNCTIONALITY_SELECT_MASK, functionality<<GPIOx_FUNCTIONALITY_SELECT_SHIFT); if( status){ VL6180x_ErrLog("Update SYSTEM_MODE_GPIO%d fail", (int)pin); @@ -1383,30 +1383,30 @@ VL6180x_ErrLog("Invalid pin %d or function %d", (int)pin, (int) functionality); status = INVALID_PARAMS; } - + LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_SetupGPIOx(VL6180xDev_t dev, int pin, uint8_t IntFunction, int ActiveHigh) { int status; - + LOG_FUNCTION_START("%d %d",(int) pin, (int)IntFunction); - + if( ((pin ==0) || (pin ==1)) && IsValidGPIOFunction(IntFunction) ){ uint16_t RegIndex; uint8_t value=0; - + if( pin==0 ) RegIndex= SYSTEM_MODE_GPIO0; else RegIndex= SYSTEM_MODE_GPIO1; - + if( ActiveHigh ) value|=GPIOx_POLARITY_SELECT_MASK; - + value |= IntFunction<<GPIOx_FUNCTIONALITY_SELECT_SHIFT; status = VL6180x_WrByte(dev, RegIndex, value); if( status ){ @@ -1417,24 +1417,24 @@ VL6180x_ErrLog("Invalid pin %d or function %d", (int)pin, (int) IntFunction); status = INVALID_PARAMS; } - + LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_DisableGPIOxOut(VL6180xDev_t dev, int pin) { int status; - + LOG_FUNCTION_START("%d",(int)pin); - + status=VL6180x_SetGPIOxFunctionality(dev, pin, GPIOx_SELECT_OFF); - + LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_SetupGPIO1(VL6180xDev_t dev, uint8_t IntFunction, int ActiveHigh) { int status; @@ -1443,11 +1443,11 @@ LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_RangeConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt) { int status; - + if( ConfigGpioInt<= CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY){ status = VL6180x_UpdateByte(dev, SYSTEM_INTERRUPT_CONFIG_GPIO, (uint8_t)(~CONFIG_GPIO_RANGE_MASK), ConfigGpioInt); } @@ -1458,12 +1458,12 @@ LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_RangeSetEceFactor(VL6180xDev_t dev, uint16_t FactorM, uint16_t FactorD){ int status; uint8_t u8; - + LOG_FUNCTION_START("%d %d", (int)FactorM, (int)FactorD ); do{ /* D cannot be 0 M must be <=D and >= 0 */ @@ -1491,23 +1491,23 @@ LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_RangeSetEceState(VL6180xDev_t dev, int enable ){ int status; uint8_t or_mask; - + LOG_FUNCTION_START("%d", (int)enable); if( enable ) or_mask = RANGE_CHECK_ECE_ENABLE_MASK; else or_mask = 0; - + status =VL6180x_UpdateByte(dev, SYSRANGE_RANGE_CHECK_ENABLES, ~RANGE_CHECK_ECE_ENABLE_MASK, or_mask); LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_RangeSetMaxConvergenceTime(VL6180xDev_t dev, uint8_t MaxConTime_msec) { int status = 0; @@ -1527,11 +1527,11 @@ LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_RangeSetInterMeasPeriod(VL6180xDev_t dev, uint32_t InterMeasTime_msec){ uint8_t SetTime; int status; - + LOG_FUNCTION_START("%d",(int)InterMeasTime_msec); do { if( InterMeasTime_msec > 2550 ){ @@ -1556,8 +1556,8 @@ LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_RangeGetDeviceReady(VL6180xDev_t dev, int * Ready){ int status; uint8_t u8; @@ -1568,8 +1568,8 @@ LOG_FUNCTION_END_FMT(status,"%d", *Ready); return status; } - - + + int VL6180X::VL6180x_RangeWaitDeviceReady(VL6180xDev_t dev, int MaxLoop ){ int status; /* if user specify an invalid <=0 loop count we'll return error */ int n; @@ -1586,7 +1586,7 @@ u8 = u8 & RANGE_DEVICE_READY_MASK; if( u8 ) break; - + } if( !status && !u8 ){ status = TIME_OUT; @@ -1595,7 +1595,7 @@ LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_RangeSetSystemMode(VL6180xDev_t dev, uint8_t mode) { int status; @@ -1616,8 +1616,8 @@ LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_RangeStartContinuousMode(VL6180xDev_t dev) { int status; @@ -1626,7 +1626,7 @@ LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_RangeStartSingleShot(VL6180xDev_t dev) { int status; LOG_FUNCTION_START(""); @@ -1634,12 +1634,12 @@ LOG_FUNCTION_END(status); return status; } - - + + int VL6180X::VL6180x_RangeSetEarlyConvergenceEestimateThreshold(VL6180xDev_t dev) { int status; - + const uint32_t cMicroSecPerMilliSec = 1000; const uint32_t cEceSampleTime_us = 500; uint32_t ece_factor_m = VL6180xDevDataGet(dev, EceFactorM); @@ -1650,9 +1650,9 @@ uint8_t u8; uint32_t maxConv_ms; int32_t AveTime; - + LOG_FUNCTION_START(""); - + do{ status = VL6180x_RdByte(dev, SYSRANGE_MAX_CONVERGENCE_TIME, &u8); if( status ){ @@ -1665,7 +1665,7 @@ status=-1; break; } - + convergTime_us = maxConv_ms * cMicroSecPerMilliSec - AveTime; status = VL6180x_RdDWord(dev, 0xB8, &fineThresh); if( status ) { @@ -1674,15 +1674,15 @@ } fineThresh*=256; eceThresh = ece_factor_m * cEceSampleTime_us * fineThresh/(convergTime_us * ece_factor_d); - + status=VL6180x_WrWord(dev, SYSRANGE_EARLY_CONVERGENCE_ESTIMATE, (uint16_t)eceThresh); } while(0); - + LOG_FUNCTION_END(status); return status; } - + /* * Return >0 = time * <0 1 if fail to get read data from device to compute time @@ -1698,9 +1698,9 @@ int32_t TotalAveTime_us; uint8_t u8; int status; - + LOG_FUNCTION_START(""); - + status = VL6180x_RdByte(dev, 0x109, &u8); if (status) { VL6180x_ErrLog("rd 0x109 fail"); @@ -1715,25 +1715,25 @@ SamplePeriod = u8; SingleTime_us = cFwOverhead_us + cVcpSetupTime_us + (SamplePeriod * 10); TotalAveTime_us = (Samples + 1) * SingleTime_us + cPLL2_StartupDelay_us; - + LOG_FUNCTION_END(TotalAveTime_us); return TotalAveTime_us; } - + #if VL6180x_HAVE_DMAX_RANGING #define _GetDMaxDataRetSignalAt400mm(dev) VL6180xDevDataGet(dev, DMaxData.retSignalAt400mm) #else #define _GetDMaxDataRetSignalAt400mm(dev) 375 // Use a default high value #endif - - + + #if VL6180x_WRAP_AROUND_FILTER_SUPPORT - + #define FILTER_STDDEV_SAMPLES 6 #define MIN_FILTER_STDDEV_SAMPLES 3 #define MIN_FILTER_VALID_STDDEV_SAMPLES 3 #define FILTER_INVALID_DISTANCE 65535 - + #define _FilterData(field) VL6180xDevDataGet(dev, FilterData.field) /* * One time init @@ -1741,32 +1741,32 @@ int _filter_Init( VL6180xDev_t dev) { int i; _FilterData(MeasurementIndex) = 0; - + _FilterData(Default_ZeroVal) = 0; _FilterData(Default_VAVGVal) = 0; _FilterData(NoDelay_ZeroVal) = 0; _FilterData(NoDelay_VAVGVal) = 0; _FilterData(Previous_VAVGDiff) = 0; - + _FilterData(StdFilteredReads) = 0; - + for (i = 0; i < FILTER_NBOF_SAMPLES; i++) { _FilterData(LastTrueRange)[i] = FILTER_INVALID_DISTANCE; _FilterData(LastReturnRates)[i] = 0; } return 0; } - - + + static uint32_t _filter_StdDevDamper(uint32_t AmbientRate, uint32_t SignalRate, const uint32_t StdDevLimitLowLight, const uint32_t StdDevLimitLowLightSNR, const uint32_t StdDevLimitHighLight, const uint32_t StdDevLimitHighLightSNR) { uint32_t newStdDev; uint16_t SNR; - + if (AmbientRate > 0) SNR = (uint16_t) ((100 * SignalRate) / AmbientRate); else SNR = 9999; - + if (SNR >= StdDevLimitLowLightSNR) { newStdDev = StdDevLimitLowLight; } else { @@ -1776,35 +1776,35 @@ newStdDev = (uint32_t) (StdDevLimitHighLight + (SNR - StdDevLimitHighLightSNR) * (int) (StdDevLimitLowLight - StdDevLimitHighLight) / (StdDevLimitLowLightSNR - StdDevLimitHighLightSNR)); } } - + return newStdDev; } - - + + /* * Return <0 on error */ int32_t VL6180X::_filter_Start(VL6180xDev_t dev, uint16_t m_trueRange_mm, uint16_t m_rawRange_mm, uint32_t m_rtnSignalRate, uint32_t m_rtnAmbientRate, uint16_t errorCode) { int status; uint16_t m_newTrueRange_mm = 0; - + uint16_t i; uint16_t bypassFilter = 0; - + uint16_t registerValue; - + uint32_t register32BitsValue1; uint32_t register32BitsValue2; - + uint16_t ValidDistance = 0; - + uint16_t WrapAroundFlag = 0; uint16_t NoWrapAroundFlag = 0; uint16_t NoWrapAroundHighConfidenceFlag = 0; - + uint16_t FlushFilter = 0; uint32_t RateChange = 0; - + uint16_t StdDevSamples = 0; uint32_t StdDevDistanceSum = 0; uint32_t StdDevDistanceMean = 0; @@ -1813,44 +1813,44 @@ uint32_t StdDevRateMean = 0; uint32_t StdDevRate = 0; uint32_t StdDevLimitWithTargetMove = 0; - + uint32_t VAVGDiff; uint32_t IdealVAVGDiff; uint32_t MinVAVGDiff; uint32_t MaxVAVGDiff; - + /* Filter Parameters */ static const uint16_t ROMABLE_DATA WrapAroundLowRawRangeLimit = 60; static const uint32_t ROMABLE_DATA WrapAroundLowReturnRateLimit_ROM = 800; // Shall be adapted depending on crossTalk static const uint16_t ROMABLE_DATA WrapAroundLowRawRangeLimit2 = 165; static const uint32_t ROMABLE_DATA WrapAroundLowReturnRateLimit2_ROM = 180; // Shall be adapted depending on crossTalk and device sensitivity - + static const uint32_t ROMABLE_DATA WrapAroundLowReturnRateFilterLimit_ROM = 850; // Shall be adapted depending on crossTalk and device sensitivity static const uint16_t ROMABLE_DATA WrapAroundHighRawRangeFilterLimit = 350; static const uint32_t ROMABLE_DATA WrapAroundHighReturnRateFilterLimit_ROM = 1400; // Shall be adapted depending on crossTalk and device sensitivity - + static const uint32_t ROMABLE_DATA WrapAroundMaximumAmbientRateFilterLimit = 7500; - + /* Temporal filter data and flush values */ static const uint32_t ROMABLE_DATA MinReturnRateFilterFlush = 75; static const uint32_t ROMABLE_DATA MaxReturnRateChangeFilterFlush = 50; - + /* STDDEV values and damper values */ - + static const uint32_t ROMABLE_DATA StdDevLimitLowLight = 300; static const uint32_t ROMABLE_DATA StdDevLimitLowLightSNR = 30; /* 0.3 */ static const uint32_t ROMABLE_DATA StdDevLimitHighLight = 2500; static const uint32_t ROMABLE_DATA StdDevLimitHighLightSNR = 5; /* 0.05 */ - + static const uint32_t ROMABLE_DATA StdDevHighConfidenceSNRLimit = 8; - + static const uint32_t ROMABLE_DATA StdDevMovingTargetStdDevLimit = 90000; - + static const uint32_t ROMABLE_DATA StdDevMovingTargetReturnRateLimit = 3500; static const uint32_t ROMABLE_DATA StdDevMovingTargetStdDevForReturnRateLimit = 5000; - + static const uint32_t ROMABLE_DATA MAX_VAVGDiff = 1800; - + /* WrapAroundDetection variables */ static const uint16_t ROMABLE_DATA WrapAroundNoDelayCheckPeriod = 2; static const uint16_t ROMABLE_DATA StdFilteredReadsIncrement = 2; @@ -1861,13 +1861,13 @@ uint32_t WrapAroundLowReturnRateLimit2; uint32_t WrapAroundLowReturnRateFilterLimit; uint32_t WrapAroundHighReturnRateFilterLimit; - + uint8_t u8, u8_2; uint32_t XTalkCompRate_KCps; uint32_t StdDevLimit = 300; uint32_t MaxOrInvalidDistance = 255*_GetUpscale(dev); /* #define MaxOrInvalidDistance (uint16_t) (255 * 3) */ - + /* Check if distance is Valid or not */ switch (errorCode) { case 0x0C: @@ -1893,7 +1893,7 @@ m_newTrueRange_mm = m_trueRange_mm; XTalkCompRate_KCps = VL6180xDevDataGet(dev, XTalkCompRate_KCps ); - + //Update signal rate limits depending on crosstalk SignalRateDMax = (uint32_t)_GetDMaxDataRetSignalAt400mm(dev) + XTalkCompRate_KCps; @@ -1901,8 +1901,8 @@ WrapAroundLowReturnRateLimit2 = ((WrapAroundLowReturnRateLimit2_ROM * SignalRateDMax) / 312) + XTalkCompRate_KCps; WrapAroundLowReturnRateFilterLimit = ((WrapAroundLowReturnRateFilterLimit_ROM * SignalRateDMax) / 312) + XTalkCompRate_KCps; WrapAroundHighReturnRateFilterLimit = ((WrapAroundHighReturnRateFilterLimit_ROM * SignalRateDMax) / 312) + XTalkCompRate_KCps; - - + + /* Checks on low range data */ if ((m_rawRange_mm < WrapAroundLowRawRangeLimit) && (m_rtnSignalRate < WrapAroundLowReturnRateLimit)) { m_newTrueRange_mm = MaxOrInvalidDistance; @@ -1912,7 +1912,7 @@ m_newTrueRange_mm = MaxOrInvalidDistance; bypassFilter = 1; } - + /* Checks on Ambient rate level */ if (m_rtnAmbientRate > WrapAroundMaximumAmbientRateFilterLimit) { /* Too high ambient rate */ @@ -1953,11 +1953,11 @@ else _FilterData(LastTrueRange)[0] = FILTER_INVALID_DISTANCE; _FilterData(LastReturnRates)[0] = m_rtnSignalRate; - + /* Check if we need to go through the filter or not */ if (!(((m_rawRange_mm < WrapAroundHighRawRangeFilterLimit) && (m_rtnSignalRate < WrapAroundLowReturnRateFilterLimit)) || ((m_rawRange_mm >= WrapAroundHighRawRangeFilterLimit) && (m_rtnSignalRate < WrapAroundHighReturnRateFilterLimit)))) bypassFilter = 1; - + /* Check which kind of measurement has been made */ status = VL6180x_RdByte(dev, 0x01AC, &u8 ); if( status ){ @@ -1965,7 +1965,7 @@ goto done_err; } registerValue =u8; - + /* Read data for filtering */ status = VL6180x_RdByte(dev, 0x10C, &u8 ); /* read only 8 lsb bits */ if( status ){ @@ -1979,7 +1979,7 @@ goto done_err; } register32BitsValue2 = u8; - + if (registerValue == 0x3E) { _FilterData(Default_ZeroVal) = register32BitsValue1; _FilterData(Default_VAVGVal) = register32BitsValue2; @@ -1987,7 +1987,7 @@ _FilterData(NoDelay_ZeroVal) = register32BitsValue1; _FilterData(NoDelay_VAVGVal) = register32BitsValue2; } - + if (bypassFilter == 1) { /* Do not go through the filter */ if (registerValue != 0x3E) { @@ -2008,13 +2008,13 @@ _FilterData(NoDelay_ZeroVal) = register32BitsValue1; _FilterData(NoDelay_VAVGVal) = register32BitsValue2; _FilterData(MeasurementIndex) = 0; - + return m_newTrueRange_mm; } - + if (_FilterData(MeasurementIndex) % WrapAroundNoDelayCheckPeriod == 0) { u8=0x3C; - u8_2 = 0x05; + u8_2 = 0x05; } else { u8=0x3E; u8_2 = 0x01; @@ -2029,17 +2029,17 @@ VL6180x_ErrLog("0x0F2 wr fail"); goto done_err; } - - + + _FilterData(MeasurementIndex)++; - + /* Computes current VAVGDiff */ if (_FilterData(Default_VAVGVal) > _FilterData(NoDelay_VAVGVal)) VAVGDiff = _FilterData(Default_VAVGVal) - _FilterData(NoDelay_VAVGVal); else VAVGDiff = 0; _FilterData(Previous_VAVGDiff) = VAVGDiff; - + /* Check the VAVGDiff */ if (_FilterData(Default_ZeroVal) > _FilterData(NoDelay_ZeroVal)) IdealVAVGDiff = _FilterData(Default_ZeroVal) - _FilterData(NoDelay_ZeroVal); @@ -2054,10 +2054,10 @@ WrapAroundFlag = 1; } else { /* Go through filtering check */ - + /* StdDevLimit Damper on SNR */ StdDevLimit = _filter_StdDevDamper(m_rtnAmbientRate, m_rtnSignalRate, StdDevLimitLowLight, StdDevLimitLowLightSNR, StdDevLimitHighLight, StdDevLimitHighLightSNR); - + /* Standard deviations computations */ StdDevSamples = 0; StdDevDistanceSum = 0; @@ -2095,7 +2095,7 @@ StdDevDistance = 0; StdDevRate = 0; } - + /* Check Return rate standard deviation */ if (StdDevRate < StdDevMovingTargetStdDevLimit) { if (StdDevSamples < MIN_FILTER_VALID_STDDEV_SAMPLES) { @@ -2106,7 +2106,7 @@ StdDevLimitWithTargetMove = StdDevLimit + (((StdDevMovingTargetStdDevForReturnRateLimit - StdDevLimit) * StdDevRate) / StdDevMovingTargetReturnRateLimit); else StdDevLimitWithTargetMove = StdDevMovingTargetStdDevForReturnRateLimit; - + if ((StdDevDistance * StdDevHighConfidenceSNRLimit) < StdDevLimitWithTargetMove) { NoWrapAroundHighConfidenceFlag = 1; } else { @@ -2125,7 +2125,7 @@ WrapAroundFlag = 1; } } - + if (m_newTrueRange_mm == MaxOrInvalidDistance) { if (_FilterData(StdFilteredReads) > 0) _FilterData(StdFilteredReads) = (uint16_t) (_FilterData(StdFilteredReads) - 1); @@ -2151,22 +2151,22 @@ } } } - + return m_newTrueRange_mm; done_err: return -1; - + #undef MaxOrInvalidDistance } - - + + int VL6180X::_filter_GetResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData) { uint32_t m_rawRange_mm = 0; int32_t FilteredRange; const uint8_t scaler = _GetUpscale(dev); uint8_t u8; int status; - + do { status = VL6180x_RdByte(dev, RESULT_RANGE_RAW, &u8); if (status) { @@ -2174,7 +2174,7 @@ break; } m_rawRange_mm = u8; - + FilteredRange = _filter_Start(dev, pRangeData->range_mm, (m_rawRange_mm * scaler), pRangeData->rtnRate, pRangeData->rtnAmbRate, pRangeData->errorStatus); if( FilteredRange<0 ){ status = -1; @@ -2185,17 +2185,17 @@ } while (0); return status; } - + #undef _FilterData #undef FILTER_STDDEV_SAMPLES #undef MIN_FILTER_STDDEV_SAMPLES #undef MIN_FILTER_VALID_STDDEV_SAMPLES #undef FILTER_INVALID_DISTANCE - + #endif /* VL6180x_WRAP_AROUND_FILTER_SUPPORT */ - + #ifdef VL6180x_HAVE_RATE_DATA - + int VL6180X::_GetRateResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData) { uint32_t m_rtnConvTime = 0; uint32_t m_rtnSignalRate = 0; @@ -2206,11 +2206,11 @@ uint32_t cRtnSignalCountMax = 0x7FFFFFFF; uint32_t cDllPeriods = 6; uint32_t calcConvTime = 0; - + int status; - + do { - + status = VL6180x_RdDWord(dev, RESULT_RANGE_RETURN_SIGNAL_COUNT, &m_rtnSignalCount); if (status) { VL6180x_ErrLog("RESULT_RANGE_RETURN_SIGNAL_COUNT rd fail"); @@ -2219,49 +2219,49 @@ if (m_rtnSignalCount > cRtnSignalCountMax) { m_rtnSignalCount = 0; } - + status = VL6180x_RdDWord(dev, RESULT_RANGE_RETURN_AMB_COUNT, &m_rtnAmbientCount); if (status) { VL6180x_ErrLog("RESULT_RANGE_RETURN_AMB_COUNTrd fail"); break; } - - + + status = VL6180x_RdDWord(dev, RESULT_RANGE_RETURN_CONV_TIME, &m_rtnConvTime); if (status) { VL6180x_ErrLog("RESULT_RANGE_RETURN_CONV_TIME rd fail"); break; } - + status = VL6180x_RdDWord(dev, RESULT_RANGE_REFERENCE_CONV_TIME, &m_refConvTime); if (status) { VL6180x_ErrLog("RESULT_RANGE_REFERENCE_CONV_TIME rd fail"); break; } - + pRangeData->rtnConvTime = m_rtnConvTime; pRangeData->refConvTime = m_refConvTime; - + calcConvTime = m_refConvTime; if (m_rtnConvTime > m_refConvTime) { calcConvTime = m_rtnConvTime; } if (calcConvTime == 0) calcConvTime = 63000; - + m_rtnSignalRate = (m_rtnSignalCount * 1000) / calcConvTime; m_rtnAmbientRate = (m_rtnAmbientCount * cDllPeriods * 1000) / calcConvTime; - + pRangeData->rtnRate = m_rtnSignalRate; pRangeData->rtnAmbRate = m_rtnAmbientRate; - - + + } while (0); return status; } #endif /* VL6180x_HAVE_RATE_DATA */ - - + + int VL6180X::VL6180x_DMaxSetState(VL6180xDev_t dev, int state){ int status; LOG_FUNCTION_START("%d", state); @@ -2279,7 +2279,7 @@ LOG_FUNCTION_END(status); return status; } - + int VL6180X::VL6180x_DMaxGetState(VL6180xDev_t dev){ int status; LOG_FUNCTION_START(""); @@ -2291,17 +2291,17 @@ LOG_FUNCTION_END(status); return status; } - - + + #if VL6180x_HAVE_DMAX_RANGING - + #define _DMaxData(field) VL6180xDevDataGet(dev, DMaxData.field) /* * Convert fix point x.7 to KCpount per sec */ - + #ifndef VL6180x_PLATFORM_PROVIDE_SQRT - + /* * 32 bit integer square root with not so bad precision (integer result) and is quite fast * see http://en.wikipedia.org/wiki/Methods_of_computing_square_roots @@ -2309,11 +2309,11 @@ uint32_t VL6180x_SqrtUint32(uint32_t num) { uint32_t res = 0; uint32_t bit = 1 << 30; /* The second-to-top bit is set: 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; @@ -2326,22 +2326,22 @@ return res; } #endif - - + + /* DMax one time init */ void _DMax_OneTimeInit(VL6180xDev_t dev){ _DMaxData(ambTuningWindowFactor_K)=DEF_AMBIENT_TUNING; } - - + + static uint32_t _DMax_RawValueAtRateKCps(VL6180xDev_t dev, int32_t rate){ uint32_t snrLimit_K; int32_t DMaxSq; uint32_t RawDMax; DMaxFix_t retSignalAt400mm; uint32_t ambTuningWindowFactor_K; - - + + ambTuningWindowFactor_K = _DMaxData(ambTuningWindowFactor_K); snrLimit_K = _DMaxData(snrLimit_K); retSignalAt400mm = _DMaxData(retSignalAt400mm); /* 12 to 18 bits Kcps */ @@ -2365,7 +2365,7 @@ } return RawDMax; } - + /* * fetch static data from register to avoid re-read * precompute all intermediate constant and cliipings @@ -2392,9 +2392,9 @@ uint8_t SysRangeCheckEn; uint8_t snrLimit; warning=0; - + static const int ROMABLE_DATA MaxConvTimeAdjust=-4; - + LOG_FUNCTION_START(""); do{ status = VL6180x_RdByte(dev, 0x02A ,&u8); @@ -2402,31 +2402,31 @@ VL6180x_ErrLog("Reg 0x02A rd fail"); break; } - + if( u8 == 0 ) { warning = CALIBRATION_WARNING; u8 = 40; /* use a default average value */ } Reg2A_KCps = Fix7_2_KCPs(u8); /* convert to KCPs */ - + status = VL6180x_RdByte(dev, SYSRANGE_RANGE_CHECK_ENABLES, &SysRangeCheckEn); if (status) { VL6180x_ErrLog("SYSRANGE_RANGE_CHECK_ENABLES rd fail "); break; } - + status = VL6180x_RdByte(dev, SYSRANGE_MAX_CONVERGENCE_TIME, &MaxConvTime); if( status){ VL6180x_ErrLog("SYSRANGE_MAX_CONVERGENCE_TIME rd fail "); break; } - + status = VL6180x_RdDWord(dev, 0x0B8, &RegB8); if( status ){ VL6180x_ErrLog("reg 0x0B8 rd fail "); break; } - + status = VL6180x_RdByte(dev, SYSRANGE_MAX_AMBIENT_LEVEL_MULT, &snrLimit); if( status){ VL6180x_ErrLog("SYSRANGE_MAX_AMBIENT_LEVEL_MULT rd fail "); @@ -2434,14 +2434,14 @@ } _DMaxData(snrLimit_K) = (int32_t)16*1000/snrLimit; XTalkCompRate_KCps = VL6180xDevDataGet(dev, XTalkCompRate_KCps ); - + if( Reg2A_KCps >= XTalkCompRate_KCps){ _DMaxData(retSignalAt400mm)=( Reg2A_KCps - XTalkCompRate_KCps); } else{ _DMaxData(retSignalAt400mm)=0; /* Reg2A_K - XTalkCompRate_KCp <0 is invalid */ } - + /* if xtalk range check is off omit it in snr clipping */ if( SysRangeCheckEn&RANGE_CHECK_RANGE_ENABLE_MASK ){ status = VL6180x_RdWord(dev, SYSRANGE_RANGE_IGNORE_THRESHOLD, &u16); @@ -2454,12 +2454,12 @@ else{ RangeIgnoreThreshold = 0; } - + minSignalNeeded = (RegB8*256)/((int32_t)MaxConvTime+(int32_t)MaxConvTimeAdjust); /* KCps 8+8 bit -(1 to 6 bit) => 15-10 bit */ /* minSignalNeeded = max ( minSignalNeeded, RangeIgnoreThreshold - XTalkCompRate_KCps) */ if( minSignalNeeded <= RangeIgnoreThreshold - XTalkCompRate_KCps ) minSignalNeeded = RangeIgnoreThreshold - XTalkCompRate_KCps; - + u32 = (minSignalNeeded*(uint32_t)snrLimit)/16; _DMaxData(ClipSnrLimit ) = _DMax_RawValueAtRateKCps(dev, u32 ); /* clip to dmax to min signal snr limit rate*/ } @@ -2469,20 +2469,20 @@ LOG_FUNCTION_END(status); return status; } - + static int _DMax_Compute(VL6180xDev_t dev, VL6180x_RangeData_t *pRange){ uint32_t rtnAmbRate; int32_t DMax; int scaling; uint16_t HwLimitAtScale; static const int ROMABLE_DATA rtnAmbLowLimit_KCps=330*1000; - + rtnAmbRate = pRange->rtnAmbRate; if( rtnAmbRate < rtnAmbLowLimit_KCps ){ DMax = _DMax_RawValueAtRateKCps( dev, rtnAmbRate); scaling = _GetUpscale(dev); HwLimitAtScale=UpperLimitLookUP[scaling - 1]; - + if( DMax > _DMaxData(ClipSnrLimit) ){ DMax=_DMaxData(ClipSnrLimit); } @@ -2496,1081 +2496,1097 @@ } return 0; } - + #undef _DMaxData #undef Fix7_2_KCPs - + #endif /* VL6180x_HAVE_DMAX_RANGING */ - - + + /******************************************************************************/ /******************************************************************************/ - - - + + + /****************** Write and read functions from I2C *************************/ - + int VL6180X::VL6180x_WrByte(VL6180xDev_t dev, uint16_t index, uint8_t data) { - int status; - - status=VL6180x_I2CWrite(Device->I2cAddr, index, &data,(uint8_t)1); - return status; + int status; + + status=VL6180x_I2CWrite(Device->I2cAddr, index, &data,(uint8_t)1); + return status; } - + int VL6180X::VL6180x_WrWord(VL6180xDev_t dev, uint16_t index, uint16_t data) { - int status; - status=VL6180x_I2CWrite(Device->I2cAddr, index, (uint8_t *)&data,(uint8_t)2); - return status; + int status; + + status=VL6180x_I2CWrite(Device->I2cAddr, index, (uint8_t *)&data,(uint8_t)2); + return status; } - + int VL6180X::VL6180x_WrDWord(VL6180xDev_t dev, uint16_t index, uint32_t data) { - int status; - status=VL6180x_I2CWrite(Device->I2cAddr, index, (uint8_t *)&data,(uint8_t)4); - return status; + int status; + + status=VL6180x_I2CWrite(Device->I2cAddr, index, (uint8_t *)&data,(uint8_t)4); + return status; } - + int VL6180X::VL6180x_RdByte(VL6180xDev_t dev, uint16_t index, uint8_t *data) { - int status; - uint8_t buffer; - status=VL6180x_I2CRead(Device->I2cAddr, index, &buffer,1); - if( !status ) - { - *data=buffer; - } - return status; + int status; + + uint8_t buffer; + status=VL6180x_I2CRead(Device->I2cAddr, index, &buffer,1); + if(!status) + { + *data=buffer; + } + return status; } - + int VL6180X::VL6180x_RdWord(VL6180xDev_t dev, uint16_t index, uint16_t *data) { - int status; - uint8_t buffer[2]; - status=VL6180x_I2CRead(Device->I2cAddr, index, buffer, 2); - if( !status ) - { - memcpy(data, buffer, 2); - } - return status; + int status; + + uint8_t buffer[2]; + status=VL6180x_I2CRead(Device->I2cAddr, index, buffer, 2); + if(!status) + { + memcpy(data, buffer, 2); + } + return status; } - + int VL6180X::VL6180x_RdDWord(VL6180xDev_t dev, uint16_t index, uint32_t *data) { - int status; - uint8_t buffer[4]; - status=VL6180x_I2CRead(Device->I2cAddr, index, buffer,4); - if( !status ) - { - memcpy(data, buffer, 4); - } - return status; + int status; + uint8_t buffer[4]; + status=VL6180x_I2CRead(Device->I2cAddr, index, buffer,4); + if(!status) + { + memcpy(data, buffer, 4); + } + return status; } - + int VL6180X::VL6180x_UpdateByte(VL6180xDev_t dev, uint16_t index, uint8_t AndData, uint8_t OrData) { - int status; - uint8_t buffer; - - status=VL6180x_I2CWrite(Device->I2cAddr, index, (uint8_t *)buffer,(uint8_t)0); - if( !status ){ - /* read data direct onto buffer */ - status=VL6180x_I2CRead(Device->I2cAddr, index, &buffer,1); - if( !status ){ - buffer=(buffer & AndData)|OrData; - status=VL6180x_I2CWrite(Device->I2cAddr, index, &buffer, (uint8_t)1); - } - } - - return status; + int status; + uint8_t buffer; + + status=VL6180x_I2CWrite(Device->I2cAddr, index, (uint8_t *)buffer,(uint8_t)0); + if(!status) + { + /* read data direct onto buffer */ + status=VL6180x_I2CRead(Device->I2cAddr, index, &buffer,1); + if(!status) + { + buffer=(buffer & AndData)|OrData; + status=VL6180x_I2CWrite(Device->I2cAddr, index, &buffer, (uint8_t)1); + } + } + return status; } - + int VL6180X::VL6180x_I2CWrite(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t* pBuffer, uint16_t NumByteToWrite) { - int ret; - int i; - uint8_t tmp[TEMP_BUF_SIZE]; - uint16_t myRegisterAddr = RegisterAddr; - uint16_t WriteDeviceAddr=0; - /* First, prepare 8 bits device address in 7bits i2ci format */ - WriteDeviceAddr=DeviceAddr*2; - if(NumByteToWrite >= TEMP_BUF_SIZE) return -2; + int ret; + int i; + uint8_t tmp[TEMP_BUF_SIZE]; + uint16_t myRegisterAddr = RegisterAddr; + uint16_t WriteDeviceAddr=0; + + /* First, prepare 8 bits device address in 7bits i2ci format */ + WriteDeviceAddr=DeviceAddr*2; + if(NumByteToWrite >= TEMP_BUF_SIZE) return -2; - /* then prepare 16 bits register address in BE format. Then, send data and STOP condition */ - tmp[0] = *(((uint8_t*)&myRegisterAddr)+1); - tmp[1] = (uint8_t)RegisterAddr; + /* then prepare 16 bits register address in BE format. Then, send data and STOP condition */ + tmp[0] = *(((uint8_t*)&myRegisterAddr)+1); + tmp[1] = (uint8_t)RegisterAddr; - if(NumByteToWrite>1) /* swap data endianess */ - { - for(i=0;i<NumByteToWrite;i++) - { - tmp[NumByteToWrite+sizeof(RegisterAddr)-1-i]=pBuffer[i]; - } - } - else - { - memcpy(tmp+sizeof(RegisterAddr), pBuffer, NumByteToWrite); - } - ret = dev_i2c.write(WriteDeviceAddr, (const char*)tmp, NumByteToWrite+sizeof(RegisterAddr), false); - - if(ret) return -1; - return 0; + if(NumByteToWrite>1) /* swap data endianess */ + { + for(i=0;i<NumByteToWrite;i++) + { + tmp[NumByteToWrite+sizeof(RegisterAddr)-1-i]=pBuffer[i]; + } + } + else + { + memcpy(tmp+sizeof(RegisterAddr), pBuffer, NumByteToWrite); + } + ret = dev_i2c.write(WriteDeviceAddr, (const char*)tmp, NumByteToWrite+sizeof(RegisterAddr), false); + + if(ret) + return -1; + return 0; } - + int VL6180X::VL6180x_I2CRead(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t* pBuffer, uint16_t NumByteToRead) { - int ret,i; - uint8_t tmp[TEMP_BUF_SIZE]; - uint16_t myRegisterAddr = RegisterAddr; - uint16_t myRegisterAddrBE; - uint16_t ReadDeviceAddr=DeviceAddr; + int ret,i; + uint8_t tmp[TEMP_BUF_SIZE]; + uint16_t myRegisterAddr = RegisterAddr; + uint16_t myRegisterAddrBE; + uint16_t ReadDeviceAddr=DeviceAddr; - ReadDeviceAddr=DeviceAddr*2; - myRegisterAddrBE = *(((uint8_t*)&myRegisterAddr)+1); - *(((uint8_t*)&myRegisterAddrBE)+1) = (uint8_t)myRegisterAddr; + ReadDeviceAddr=DeviceAddr*2; + myRegisterAddrBE = *(((uint8_t*)&myRegisterAddr)+1); + *(((uint8_t*)&myRegisterAddrBE)+1) = (uint8_t)myRegisterAddr; - /* Send 8 bits device address and 16 bits register address in BE format, with no STOP condition */ - ret = dev_i2c.write(ReadDeviceAddr, (const char*)&myRegisterAddrBE, sizeof(RegisterAddr), true); - if(!ret) { - ReadDeviceAddr|=0x001; - /* Read data, with STOP condition */ - ret = dev_i2c.read(ReadDeviceAddr, (char*)tmp, NumByteToRead, false); - } - if(ret) return -1; - - if(NumByteToRead>1) /* swap data endianess */ - { - for(i=0;i<NumByteToRead;i++) - { - pBuffer[i] = tmp[NumByteToRead-1-i]; - } - } - else - { - memcpy(pBuffer, tmp, NumByteToRead); - } - return 0; + /* Send 8 bits device address and 16 bits register address in BE format, with no STOP condition */ + ret = dev_i2c.write(ReadDeviceAddr, (const char*)&myRegisterAddrBE, sizeof(RegisterAddr), true); + if(!ret) + { + ReadDeviceAddr|=0x001; + /* Read data, with STOP condition */ + ret = dev_i2c.read(ReadDeviceAddr, (char*)tmp, NumByteToRead, false); + } + if(ret) + return -1; + + if(NumByteToRead>1) /* swap data endianess */ + { + for(i=0;i<NumByteToRead;i++) + { + pBuffer[i] = tmp[NumByteToRead-1-i]; + } + } + else + { + memcpy(pBuffer, tmp, NumByteToRead); + } + return 0; } - - + + int VL6180X::ReadID() { - int status; - uint8_t rl_id=0; - - status=VL6180x_RdByte(Device, IDENTIFICATION_MODEL_ID, &rl_id); - if((status==0)&&(rl_id==0xB4)) - return status; - else - return INVALID_PARAMS; + int status; + uint8_t rl_id=0; + + status=VL6180x_RdByte(Device, IDENTIFICATION_MODEL_ID, &rl_id); + if((status==0)&&(rl_id==0xB4)) + return status; + else + return INVALID_PARAMS; } - - + + int VL6180X::InitSensor(uint8_t NewAddr) //FIXME printf da sostituire con VL6180x_ErrLog e poi specificare il contenuto di questa funzione { int status; - + VL6180x_Off(); VL6180x_On(); - /*status=VL6180x_WaitDeviceBooted(Device); - if(status) - printf("WaitDeviceBooted fail\n\r");*/ + /*status=VL6180x_WaitDeviceBooted(Device); + if(status) + printf("WaitDeviceBooted fail\n\r");*/ status=IsPresent(); if(!status) { - Device->Present=1; - status=Init(); - if(status) - { - printf("Failed to init VL6180X sensor!\n\r"); - return status; - } - status=Prepare(); - if(status) - { - printf("Failed to prepare VL6180X!\n\r"); - return status; - } - if(NewAddr!=DEFAULT_DEVICE_ADDRESS) - { - status=SetI2CAddress(NewAddr); - if(status) - { - printf("Failed to change I2C address!\n\r"); - return status; - } - } - else - { - printf("Invalid new address!\n\r"); - return INVALID_PARAMS; - } - Device->Ready=1; - } - return status; + Device->Present=1; + status=Init(); + if(status) + { + printf("Failed to init VL6180X sensor!\n\r"); + return status; + } + status=Prepare(); + if(status) + { + printf("Failed to prepare VL6180X!\n\r"); + return status; + } + if(NewAddr!=DEFAULT_DEVICE_ADDRESS) + { + status=SetI2CAddress(NewAddr); + if(status) + { + printf("Failed to change I2C address!\n\r"); + return status; + } + } + else + { + printf("Invalid new address!\n\r"); + return INVALID_PARAMS; + } + Device->Ready=1; + } + VL6180x_RangeSetMaxConvergenceTime(Device,10); //FIXME temporaneo, capire se devo fissare questi valori di default oppure impostarli solo quando faccio la hand gesture + VL6180x_RangeSetInterMeasPeriod(Device,10); //FIXME + return status; } - - + + int VL6180X::StartMeasurement(OperatingMode operating_mode, void (*fptr)(void), MeasureData_t *Data, uint16_t low, uint16_t high) { int status, r_status, l_status; - + switch(operating_mode) { - case(range_single_shot_polling): - r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); - l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - return RangeMeasPollSingleShot(Data); - else - return (r_status|l_status); - + case(range_single_shot_polling): + r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); + l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + return RangeMeasPollSingleShot(Data); + else + return (r_status|l_status); + case(als_single_shot_polling): - r_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); - l_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - return AlsMeasPollSingleShot(Data); - else - return (r_status|l_status); - - case(range_continuous_polling): - r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); - l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - return RangeMeasPollContinuousMode(); - else - return (r_status|l_status); - - case(als_continuous_polling): - r_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); - l_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - return AlsMeasPollContinuousMode(); - else - return (r_status|l_status); - + r_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); + l_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + return AlsMeasPollSingleShot(Data); + else + return (r_status|l_status); + + case(range_continuous_polling): + r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); + l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + return RangeMeasPollContinuousMode(); + else + return (r_status|l_status); + + case(als_continuous_polling): + r_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); + l_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + return AlsMeasPollContinuousMode(); + else + return (r_status|l_status); + case(range_continuous_interrupt): - r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); - l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - return RangeMeasIntContinuousMode(fptr); - else - return (r_status|l_status); - - case(als_continuous_interrupt): - l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); - r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - return AlsMeasIntContinuousMode(fptr); - else - return (r_status|l_status); - - case(interleaved_mode_interrupt): - l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); - r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - return InterleavedMode(fptr); - else - return (r_status|l_status); - + r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); + l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + return RangeMeasIntContinuousMode(fptr); + else + return (r_status|l_status); + + case(als_continuous_interrupt): + l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); + r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + return AlsMeasIntContinuousMode(fptr); + else + return (r_status|l_status); + + case(interleaved_mode_interrupt): + l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); + r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + return InterleavedMode(fptr); + else + return (r_status|l_status); + case(range_continuous_polling_low_threshold): - r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_LOW); - l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_LOW); + l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=RangeSetLowThreshold(low); - if(!status) - return RangeMeasPollContinuousMode(); - else - return status; - } + if(!status) + return RangeMeasPollContinuousMode(); + else + return status; + } else return (r_status|l_status); - case(range_continuous_polling_high_threshold): + case(range_continuous_polling_high_threshold): status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_HIGH); - status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=RangeSetHighThreshold(high); - if(!status) - return RangeMeasPollContinuousMode(); - else - return status; - } + if(!status) + return RangeMeasPollContinuousMode(); + else + return status; + } else return (r_status|l_status); - - case(range_continuous_polling_out_of_window): - status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW); - status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + + case(range_continuous_polling_out_of_window): + status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW); + status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=VL6180x_RangeSetThresholds(Device,low,high,1); - if(!status) - return RangeMeasPollContinuousMode(); - else - return status; - } + if(!status) + return RangeMeasPollContinuousMode(); + else + return status; + } else return (r_status|l_status); - + case(als_continuous_polling_low_threshold): status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_LOW); - status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=AlsSetLowThreshold(low); - if(!status) - return AlsMeasPollContinuousMode(); - else - return status; - } + if(!status) + return AlsMeasPollContinuousMode(); + else + return status; + } else return (r_status|l_status); - - case(als_continuous_polling_high_threshold): - status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_HIGH); - status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + + case(als_continuous_polling_high_threshold): + status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_HIGH); + status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=AlsSetHighThreshold(high); - if(!status) - return AlsMeasPollContinuousMode(); - else - return status; - } + if(!status) + return AlsMeasPollContinuousMode(); + else + return status; + } else return (r_status|l_status); - - case(als_continuous_polling_out_of_window): - status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW); - status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + + case(als_continuous_polling_out_of_window): + status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW); + status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=VL6180x_AlsSetThresholds(Device,low,high); - if(!status) - return AlsMeasPollContinuousMode(); - else - return status; - } + if(!status) + return AlsMeasPollContinuousMode(); + else + return status; + } else return (r_status|l_status); - - case(range_continuous_interrupt_low_threshold): - status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_LOW); - status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + + case(range_continuous_interrupt_low_threshold): + status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_LOW); + status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=RangeSetLowThreshold(low); - if(!status) - return RangeMeasIntContinuousMode(fptr); - else - return status; - } + if(!status) + return RangeMeasIntContinuousMode(fptr); + else + return status; + } else - return (r_status|l_status); - - case(range_continuous_interrrupt_high_threshold): - status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_HIGH); - status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + return (r_status|l_status); + + case(range_continuous_interrrupt_high_threshold): + status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_HIGH); + status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=RangeSetHighThreshold(high); - if(!status) - return RangeMeasIntContinuousMode(fptr); - else - return status; - } + if(!status) + return RangeMeasIntContinuousMode(fptr); + else + return status; + } else return (r_status|l_status); - - case(range_continuous_interrupt_out_of_window): - status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW); - status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + + case(range_continuous_interrupt_out_of_window): + status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW); + status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=VL6180x_RangeSetThresholds(Device,low,high,1); - if(!status) - return RangeMeasIntContinuousMode(fptr); - else - return status; - } + if(!status) + return RangeMeasIntContinuousMode(fptr); + else + return status; + } else return (r_status|l_status); - - case(als_continuous_interrupt_low_threshold): - status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_LOW); - status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + + case(als_continuous_interrupt_low_threshold): + status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_LOW); + status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=AlsSetLowThreshold(low); - if(!status) - return AlsMeasIntContinuousMode(fptr); - else - return status; - } + if(!status) + return AlsMeasIntContinuousMode(fptr); + else + return status; + } else - return (r_status|l_status); - - case(als_continuous_interrupt_high_threshold): - status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_HIGH); - status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + return (r_status|l_status); + + case(als_continuous_interrupt_high_threshold): + status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_LEVEL_HIGH); + status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=AlsSetHighThreshold(high); - if(!status) - return AlsMeasIntContinuousMode(fptr); - else - return status; - } + if(!status) + return AlsMeasIntContinuousMode(fptr); + else + return status; + } else return (r_status|l_status); - - case(als_continuous_interrupt_out_of_window): - status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW); - status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if((!r_status)&&(!l_status)) - { + + case(als_continuous_interrupt_out_of_window): + status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW); + status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if((!r_status)&&(!l_status)) + { status=VL6180x_AlsSetThresholds(Device,low,high); - if(!status) - return AlsMeasIntContinuousMode(fptr); - else - return status; - } + if(!status) + return AlsMeasIntContinuousMode(fptr); + else + return status; + } else return (r_status|l_status); - - default: - return INVALID_PARAMS; - } + + default: + return INVALID_PARAMS; + } } - - + + int VL6180X::GetRangeError(MeasureData_t *Data, VL6180x_RangeData_t RangeData) { - Data->range_error=RangeData.errorStatus; - if(Data->range_error!=0) - { + Data->range_error=RangeData.errorStatus; + if(Data->range_error!=0) + { VL6180x_ErrLog("Range error %d",Data->range_error); return RANGE_ERROR; - } - return NoError_; + } + return NoError_; } - - + + int VL6180X::GetAlsError(MeasureData_t *Data, VL6180x_AlsData_t AlsData) { - Data->als_error=AlsData.errorStatus; - if(Data->als_error!=0) - { + Data->als_error=AlsData.errorStatus; + if(Data->als_error!=0) + { VL6180x_ErrLog("Light error %d",Data->light_error); - return API_ERROR; - } - return NoError_; + return API_ERROR; + } + return NoError_; } - - + + int VL6180X::RangeMeasPollSingleShot(MeasureData_t *Data) { - VL6180x_RangeData_t RangeData; - int status; - - status=RangePollMeasurement(&RangeData); - if(!status) - { - status=GetRangeError(Data, RangeData); - if(!status) - Data->range_mm=RangeData.range_mm; - else - Data->range_mm=0xFFFFFFFF; - } - return status; -} - - + VL6180x_RangeData_t RangeData; + int status; + + status=RangePollMeasurement(&RangeData); + if(!status) + { + status=GetRangeError(Data, RangeData); + if(!status) + Data->range_mm=RangeData.range_mm; + else + Data->range_mm=0xFFFFFFFF; + } + return status; +} + + int VL6180X::AlsMeasPollSingleShot(MeasureData_t *Data) { - VL6180x_AlsData_t AlsData; - int status; - - status=AlsPollMeasurement(&AlsData); - if(!status) - { - status=GetAlsError(Data, AlsData); - if(!status) - Data->lux=AlsData.lux; - else - Data->lux=0xFFFFFFFF; - } - return status; + VL6180x_AlsData_t AlsData; + int status; + + status=AlsPollMeasurement(&AlsData); + if(!status) + { + status=GetAlsError(Data, AlsData); + if(!status) + Data->lux=AlsData.lux; + else + Data->lux=0xFFFFFFFF; + } + return status; } - - + + int VL6180X::RangeMeasPollContinuousMode() { int status; - - status=VL6180x_RangeClearInterrupt(Device); - if(status) - { - VL6180x_ErrLog("VL6180x_RangeClearInterrupt fail"); - return status; - } - status=VL6180x_ClearErrorInterrupt(Device); - if(status) - { - VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); - return status; - } - return RangeStartContinuousMode(); + + status=VL6180x_RangeClearInterrupt(Device); + if(status) + { + VL6180x_ErrLog("VL6180x_RangeClearInterrupt fail"); + return status; + } + status=VL6180x_ClearErrorInterrupt(Device); + if(status) + { + VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); + return status; + } + return RangeStartContinuousMode(); } - - + + int VL6180X::AlsMeasPollContinuousMode() { - int status; - - status=VL6180x_AlsClearInterrupt(Device); - if(status) - { - VL6180x_ErrLog("VL6180x_AlsClearInterrupt fail"); - return status; - } - status=VL6180x_ClearErrorInterrupt(Device); - if(status) - { - VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); - return status; - } - return AlsStartContinuousMode(); + int status; + + status=VL6180x_AlsClearInterrupt(Device); + if(status) + { + VL6180x_ErrLog("VL6180x_AlsClearInterrupt fail"); + return status; + } + status=VL6180x_ClearErrorInterrupt(Device); + if(status) + { + VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); + return status; + } + return AlsStartContinuousMode(); } - - + + int VL6180X::AlsGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData) { int status; - uint8_t IntStatus; - - status=VL6180x_AlsGetInterruptStatus(dev, &IntStatus); - if(!status) - { - if(IntStatus==RES_INT_STAT_GPIO_NEW_SAMPLE_READY) - { - status = VL6180x_AlsGetMeasurement(dev, pAlsData); - if(!status) - { - status=VL6180x_AlsClearInterrupt(Device); + uint8_t IntStatus; + + status=VL6180x_AlsGetInterruptStatus(dev, &IntStatus); + if(!status) + { + if(IntStatus==RES_INT_STAT_GPIO_NEW_SAMPLE_READY) + { + status = VL6180x_AlsGetMeasurement(dev, pAlsData); + if(!status) + { + status=VL6180x_AlsClearInterrupt(Device); if(status) VL6180x_ErrLog("VL6180x_AlsClearInterrupt fail"); - } - } - else - status=NOT_READY; - } - else - VL6180x_ErrLog("Failed to get interrupt status"); - return status; + } + } + else + status=NOT_READY; + } + else + VL6180x_ErrLog("Failed to get interrupt status"); + return status; } - - + + int VL6180X::RangeMeasIntContinuousMode(void (*fptr)(void)) { - int status, ClrStatus; - - EnableInterruptMeasureDetectionIRQ(); - AttachInterruptMeasureDetectionIRQ(fptr); - status=SetupGPIO1(GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT, 1); - ClrStatus=VL6180x_ClearAllInterrupt(Device); - if(ClrStatus) - VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); + int status, ClrStatus; + + EnableInterruptMeasureDetectionIRQ(); + AttachInterruptMeasureDetectionIRQ(fptr); + status=SetupGPIO1(GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT, 1); + ClrStatus=VL6180x_ClearAllInterrupt(Device); + if(ClrStatus) + VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); if(!status) - status=RangeStartContinuousMode(); - return status; + status=RangeStartContinuousMode(); + return status; } - - + + int VL6180X::AlsMeasIntContinuousMode(void (*fptr)(void)) { int status, ClrStatus; - - EnableInterruptMeasureDetectionIRQ(); + + EnableInterruptMeasureDetectionIRQ(); AttachInterruptMeasureDetectionIRQ(fptr); status=SetupGPIO1(GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT, 1); - ClrStatus=VL6180x_ClearAllInterrupt(Device); - if(ClrStatus) - VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); + ClrStatus=VL6180x_ClearAllInterrupt(Device); + if(ClrStatus) + VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); if(!status) - status=AlsStartContinuousMode(); - return status; -} - - + status=AlsStartContinuousMode(); + return status; +} + + int VL6180X::StartInterleavedMode() { - int status; - uint16_t integration_period, intermeasurement_period_ms; - uint8_t max_convergence_time; - uint8_t buf; - + int status; + uint16_t integration_period, intermeasurement_period_ms; + uint8_t max_convergence_time; + uint8_t buf; + status=VL6180x_WrByte(Device, 0x2A3, 1); if(status) { - VL6180x_ErrLog("Failed to write INTERLEAVED_MODE_ENABLE!\n\r"); - return status; - } - status=VL6180x_RdByte(Device, SYSRANGE_MAX_CONVERGENCE_TIME, &max_convergence_time); - if(status) - { - VL6180x_ErrLog("Failed to read SYSRANGE_MAX_CONVERGENCE_TIME!\n\r"); - return status; - } - status=VL6180x_RdWord(Device, SYSALS_INTEGRATION_PERIOD, &integration_period); - if(status) - { - VL6180x_ErrLog("Failed to read SYSALS_INTEGRATION_PERIOD!\n\r"); - return status; - } - max_convergence_time&=0x3F; - integration_period&=0x01FF; - intermeasurement_period_ms=((max_convergence_time+5)+(integration_period*1.1)); - intermeasurement_period_ms=(intermeasurement_period_ms/0.9)+10; - intermeasurement_period_ms=200; - status=VL6180x_AlsSetInterMeasurementPeriod(Device, intermeasurement_period_ms); - VL6180x_RdByte(Device, 0x03E, &buf); - if(status) + VL6180x_ErrLog("Failed to write INTERLEAVED_MODE_ENABLE!\n\r"); + return status; + } + status=VL6180x_RdByte(Device, SYSRANGE_MAX_CONVERGENCE_TIME, &max_convergence_time); + if(status) + { + VL6180x_ErrLog("Failed to read SYSRANGE_MAX_CONVERGENCE_TIME!\n\r"); + return status; + } + status=VL6180x_RdWord(Device, SYSALS_INTEGRATION_PERIOD, &integration_period); + if(status) { - VL6180x_ErrLog("Failed to write SYSALS_INTERMEASUREMENT_PERIOD!\n\r"); - return status; - } - return AlsStartContinuousMode(); + VL6180x_ErrLog("Failed to read SYSALS_INTEGRATION_PERIOD!\n\r"); + return status; + } + max_convergence_time&=0x3F; + integration_period&=0x01FF; + intermeasurement_period_ms=((max_convergence_time+5)+(integration_period*1.1)); + intermeasurement_period_ms=(intermeasurement_period_ms/0.9)+10; + intermeasurement_period_ms=200; + status=VL6180x_AlsSetInterMeasurementPeriod(Device, intermeasurement_period_ms); + VL6180x_RdByte(Device, 0x03E, &buf); + if(status) + { + VL6180x_ErrLog("Failed to write SYSALS_INTERMEASUREMENT_PERIOD!\n\r"); + return status; + } + return AlsStartContinuousMode(); } - - + + int VL6180X::InterleavedMode(void (*fptr)(void)) { - int status, ClrStatus; - - EnableInterruptMeasureDetectionIRQ(); - AttachInterruptMeasureDetectionIRQ(fptr); - status=SetupGPIO1(GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT, 1); - ClrStatus=VL6180x_ClearAllInterrupt(Device); - if(ClrStatus) - VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); - if(!status) + int status, ClrStatus; + + EnableInterruptMeasureDetectionIRQ(); + AttachInterruptMeasureDetectionIRQ(fptr); + status=SetupGPIO1(GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT, 1); + ClrStatus=VL6180x_ClearAllInterrupt(Device); + if(ClrStatus) + VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); + if(!status) status=StartInterleavedMode(); - return status; + return status; } - - + + int VL6180X::HandleIRQ(OperatingMode operating_mode, MeasureData_t *Data) { - int status; - - status=GetMeasurement(operating_mode, Data); - EnableInterruptMeasureDetectionIRQ(); - return status; + int status; + + EnableInterruptMeasureDetectionIRQ(); + status=GetMeasurement(operating_mode, Data); + return status; } - - + + int VL6180X::RangeSetLowThreshold(uint16_t threshold) { - int status; - uint16_t low, high; - - status=VL6180x_RangeGetThresholds(Device, &low, &high); - if(!status) - status=VL6180x_RangeSetThresholds(Device, threshold, high, 1); - return status; + int status; + uint16_t low, high; + + status=VL6180x_RangeGetThresholds(Device, &low, &high); + if(!status) + status=VL6180x_RangeSetThresholds(Device, threshold, high, 1); + return status; } - - + + int VL6180X::RangeSetHighThreshold(uint16_t threshold) { - int status; - uint16_t low, high; - - status=VL6180x_RangeGetThresholds(Device, &low, &high); - if(!status) - status=VL6180x_RangeSetThresholds(Device, low, threshold, 1); - return status; + int status; + uint16_t low, high; + + status=VL6180x_RangeGetThresholds(Device, &low, &high); + if(!status) + status=VL6180x_RangeSetThresholds(Device, low, threshold, 1); + return status; } - - + + int VL6180X::AlsSetLowThreshold(uint16_t threshold) { - int status; - uint16_t low, high; - - status=VL6180x_AlsGetThresholds(Device, &low, &high); - if(!status) - status=VL6180x_AlsSetThresholds(Device, threshold, high); - return status; + int status; + uint16_t low, high; + + status=VL6180x_AlsGetThresholds(Device, &low, &high); + if(!status) + status=VL6180x_AlsSetThresholds(Device, threshold, high); + return status; } - - + + int VL6180X::AlsSetHighThreshold(uint16_t threshold) { - int status; - uint16_t low, high; - - status=VL6180x_AlsGetThresholds(Device, &low, &high); - if(!status) - status=VL6180x_AlsSetThresholds(Device, low, threshold); - return status; + int status; + uint16_t low, high; + + status=VL6180x_AlsGetThresholds(Device, &low, &high); + if(!status) + status=VL6180x_AlsSetThresholds(Device, low, threshold); + return status; } - - -int VL6180X::VL6180x_AlsGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high) + + +int VL6180X::VL6180x_AlsGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high) { int status; - - status=VL6180x_RdWord(dev, SYSALS_THRESH_LOW, low); - if(status) - { - VL6180x_ErrLog("rd SYSALS_THRESH_LOW fail"); - return status; - } - status=VL6180x_RdWord(dev, SYSALS_THRESH_HIGH, high); - if(status) - { - VL6180x_ErrLog("rd SYSALS_THRESH_HIGH fail"); - return status; - } - return status; + + status=VL6180x_RdWord(dev, SYSALS_THRESH_LOW, low); + if(status) + { + VL6180x_ErrLog("rd SYSALS_THRESH_LOW fail"); + return status; + } + status=VL6180x_RdWord(dev, SYSALS_THRESH_HIGH, high); + if(status) + { + VL6180x_ErrLog("rd SYSALS_THRESH_HIGH fail"); + return status; + } + return status; } - - + + int VL6180X::GetMeasurement(OperatingMode operating_mode, MeasureData_t *Data) { - switch(operating_mode) - { - case(range_continuous_polling): - case(range_continuous_interrupt): - case(range_continuous_polling_low_threshold): - case(range_continuous_polling_high_threshold): - case(range_continuous_polling_out_of_window): - case(range_continuous_interrupt_low_threshold): - case(range_continuous_interrrupt_high_threshold): - case(range_continuous_interrupt_out_of_window): - return GetRangeMeas(operating_mode, Data); - - case(als_continuous_polling): - case(als_continuous_interrupt): - case(als_continuous_polling_low_threshold): - case(als_continuous_polling_high_threshold): - case(als_continuous_polling_out_of_window): - case(als_continuous_interrupt_low_threshold): - case(als_continuous_interrupt_high_threshold): - case(als_continuous_interrupt_out_of_window): - return GetAlsMeas(operating_mode, Data); - - case(interleaved_mode_interrupt): - return GetRangeAlsMeas(Data); - - default: - return INVALID_PARAMS; - } + switch(operating_mode) + { + case(range_continuous_polling): + case(range_continuous_interrupt): + case(range_continuous_polling_low_threshold): + case(range_continuous_polling_high_threshold): + case(range_continuous_polling_out_of_window): + case(range_continuous_interrupt_low_threshold): + case(range_continuous_interrrupt_high_threshold): + case(range_continuous_interrupt_out_of_window): + return GetRangeMeas(operating_mode, Data); + + case(als_continuous_polling): + case(als_continuous_interrupt): + case(als_continuous_polling_low_threshold): + case(als_continuous_polling_high_threshold): + case(als_continuous_polling_out_of_window): + case(als_continuous_interrupt_low_threshold): + case(als_continuous_interrupt_high_threshold): + case(als_continuous_interrupt_out_of_window): + return GetAlsMeas(operating_mode, Data); + + case(interleaved_mode_interrupt): + return GetRangeAlsMeas(Data); + + default: + return INVALID_PARAMS; + } } - - + + int VL6180X::GetRangeMeas(OperatingMode operating_mode, MeasureData_t *Data) { VL6180x_RangeData_t RangeData; - int status, ClrStatus; - IntrStatus_t IntStatus; - - status=VL6180x_RangeGetInterruptStatus(Device, &IntStatus.val); - if(!status) - { - Data->int_error=IntStatus.status.Error; - if(IntStatus.status.Error!=0) - { + int status, ClrStatus; + IntrStatus_t IntStatus; + + status=VL6180x_RangeGetInterruptStatus(Device, &IntStatus.val); + if(!status) + { + Data->int_error=IntStatus.status.Error; + if(IntStatus.status.Error!=0) + { VL6180x_ErrLog("GPIO int Error report %d",(int)IntStatus.val); - return RANGE_ERROR; + status=RANGE_ERROR; } - } - else - { - VL6180x_ErrLog("Failed to read RESULT_INTERRUPT_STATUS_GPIO"); - return status; - } - if((operating_mode==range_continuous_polling)||(operating_mode==range_continuous_interrupt)) - { - if(IntStatus.status.Range==RES_INT_STAT_GPIO_NEW_SAMPLE_READY) - status=VL6180x_RangeGetMeasurement(Device, &RangeData); - else - return NOT_READY; - } - else if((operating_mode==range_continuous_polling_low_threshold)||(operating_mode==range_continuous_interrupt_low_threshold)) - { - if(IntStatus.status.Range==RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD) - status=VL6180x_RangeGetMeasurement(Device, &RangeData); - else - return NOT_READY; - } - else if((operating_mode==range_continuous_polling_high_threshold)||(operating_mode==range_continuous_interrrupt_high_threshold)) - { - if(IntStatus.status.Range==RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD) - status=VL6180x_RangeGetMeasurement(Device, &RangeData); - else - return NOT_READY; - } - else if((operating_mode==range_continuous_polling_out_of_window)||(operating_mode==range_continuous_interrupt_out_of_window)) - { - if(IntStatus.status.Range==RES_INT_STAT_GPIO_OUT_OF_WINDOW) - status=VL6180x_RangeGetMeasurement(Device, &RangeData); - else - return NOT_READY; - } - if(!status) - { - status=GetRangeError(Data, RangeData); - if(!status) - Data->range_mm=RangeData.range_mm; - else - Data->range_mm=0xFFFFFFFF; - } - ClrStatus=VL6180x_RangeClearInterrupt(Device); - if(ClrStatus) - { - VL6180x_ErrLog("VL6180x_RangeClearInterrupt fail"); - return ClrStatus; - } - ClrStatus=VL6180x_ClearErrorInterrupt(Device); - if(ClrStatus) - { - VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); - return ClrStatus; - } - return status; + } + else + { + VL6180x_ErrLog("Failed to read RESULT_INTERRUPT_STATUS_GPIO"); + } + ClrStatus=VL6180x_RangeClearInterrupt(Device); + if(ClrStatus) + { + VL6180x_ErrLog("VL6180x_RangeClearInterrupt fail"); + } + ClrStatus=VL6180x_ClearErrorInterrupt(Device); + if(ClrStatus) + { + VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); + } + if(status) + return status; + if((operating_mode==range_continuous_polling)||(operating_mode==range_continuous_interrupt)) + { + if(IntStatus.status.Range==RES_INT_STAT_GPIO_NEW_SAMPLE_READY) + status=VL6180x_RangeGetMeasurement(Device, &RangeData); + else + return NOT_READY; + } + else if((operating_mode==range_continuous_polling_low_threshold)||(operating_mode==range_continuous_interrupt_low_threshold)) + { + if(IntStatus.status.Range==RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD) + status=VL6180x_RangeGetMeasurement(Device, &RangeData); + else + return NOT_READY; + } + else if((operating_mode==range_continuous_polling_high_threshold)||(operating_mode==range_continuous_interrrupt_high_threshold)) + { + if(IntStatus.status.Range==RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD) + status=VL6180x_RangeGetMeasurement(Device, &RangeData); + else + return NOT_READY; + } + else if((operating_mode==range_continuous_polling_out_of_window)||(operating_mode==range_continuous_interrupt_out_of_window)) + { + if(IntStatus.status.Range==RES_INT_STAT_GPIO_OUT_OF_WINDOW) + status=VL6180x_RangeGetMeasurement(Device, &RangeData); + else + return NOT_READY; + } + if(!status) + { + status=GetRangeError(Data, RangeData); + if(!status) + Data->range_mm=RangeData.range_mm; + else + Data->range_mm=0xFFFFFFFF; + } + return status; } - - + + int VL6180X::GetAlsMeas(OperatingMode operating_mode, MeasureData_t *Data) { VL6180x_AlsData_t AlsData; - int status, ClrStatus; - uint8_t IntStatus; - - status=VL6180x_AlsGetInterruptStatus(Device, &IntStatus); - if(status) - { - VL6180x_ErrLog("Failed to read RESULT_INTERRUPT_STATUS_GPIO"); - return status; - } - if((operating_mode==als_continuous_polling)||(operating_mode==als_continuous_interrupt)) - { - if(IntStatus==RES_INT_STAT_GPIO_NEW_SAMPLE_READY) - status=VL6180x_AlsGetMeasurement(Device, &AlsData); - else - return NOT_READY; - } - else if((operating_mode==als_continuous_polling_low_threshold)||(operating_mode==als_continuous_interrupt_low_threshold)) - { - if(IntStatus==RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD) - status=VL6180x_AlsGetMeasurement(Device, &AlsData); - else - return NOT_READY; - } - else if((operating_mode==als_continuous_polling_high_threshold)||(operating_mode==als_continuous_interrupt_high_threshold)) - { - if(IntStatus==RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD) - status=VL6180x_AlsGetMeasurement(Device, &AlsData); - else - return NOT_READY; - } - else if((operating_mode==als_continuous_polling_out_of_window)||(operating_mode==als_continuous_interrupt_out_of_window)) - { - if(IntStatus==RES_INT_STAT_GPIO_OUT_OF_WINDOW) - status=VL6180x_AlsGetMeasurement(Device, &AlsData); - else - return NOT_READY; - } - if(!status) - { - status=GetAlsError(Data, AlsData); - if(!status) - Data->lux=AlsData.lux; - else - Data->lux=0xFFFFFFFF; - } - ClrStatus=VL6180x_AlsClearInterrupt(Device); - if(ClrStatus) - VL6180x_ErrLog("VL6180x_AlsClearInterrupt fail"); - ClrStatus=VL6180x_ClearErrorInterrupt(Device); - if(ClrStatus) - VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); - return status; + int status, ClrStatus; + uint8_t IntStatus; + + status=VL6180x_AlsGetInterruptStatus(Device, &IntStatus); + if(status) + { + VL6180x_ErrLog("Failed to read RESULT_INTERRUPT_STATUS_GPIO"); + } + ClrStatus=VL6180x_AlsClearInterrupt(Device); + if(ClrStatus) + { + VL6180x_ErrLog("VL6180x_AlsClearInterrupt fail"); + } + ClrStatus=VL6180x_ClearErrorInterrupt(Device); + if(ClrStatus) + { + VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); + } + if(status) + return status; + if((operating_mode==als_continuous_polling)||(operating_mode==als_continuous_interrupt)) + { + if(IntStatus==RES_INT_STAT_GPIO_NEW_SAMPLE_READY) + status=VL6180x_AlsGetMeasurement(Device, &AlsData); + else + return NOT_READY; + } + else if((operating_mode==als_continuous_polling_low_threshold)||(operating_mode==als_continuous_interrupt_low_threshold)) + { + if(IntStatus==RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD) + status=VL6180x_AlsGetMeasurement(Device, &AlsData); + else + return NOT_READY; + } + else if((operating_mode==als_continuous_polling_high_threshold)||(operating_mode==als_continuous_interrupt_high_threshold)) + { + if(IntStatus==RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD) + status=VL6180x_AlsGetMeasurement(Device, &AlsData); + else + return NOT_READY; + } + else if((operating_mode==als_continuous_polling_out_of_window)||(operating_mode==als_continuous_interrupt_out_of_window)) + { + if(IntStatus==RES_INT_STAT_GPIO_OUT_OF_WINDOW) + status=VL6180x_AlsGetMeasurement(Device, &AlsData); + else + return NOT_READY; + } + if(!status) + { + status=GetAlsError(Data, AlsData); + if(!status) + Data->lux=AlsData.lux; + else + Data->lux=0xFFFFFFFF; + } + return status; } - - + + int VL6180X::GetRangeAlsMeas(MeasureData_t *Data) { int status, ClrStatus, r_status, l_status; - IntrStatus_t IntStatus; - VL6180x_RangeData_t RangeData; - VL6180x_AlsData_t AlsData; - - status=VL6180x_RdByte(Device, RESULT_INTERRUPT_STATUS_GPIO, &IntStatus.val); - if(!status) - { - Data->int_error=IntStatus.status.Error; - if(IntStatus.status.Error!=0) - { + IntrStatus_t IntStatus; + VL6180x_RangeData_t RangeData; + VL6180x_AlsData_t AlsData; + + status=VL6180x_RdByte(Device, RESULT_INTERRUPT_STATUS_GPIO, &IntStatus.val); + if(!status) + { + Data->int_error=IntStatus.status.Error; + if(IntStatus.status.Error!=0) + { VL6180x_ErrLog("GPIO int Error report %d",(int)IntStatus.val); - return RANGE_ERROR; + status=RANGE_ERROR; } - } - else - { - VL6180x_ErrLog("Failed to read RESULT_INTERRUPT_STATUS_GPIO"); - return status; - } - - if(IntStatus.status.Als==RES_INT_STAT_GPIO_NEW_SAMPLE_READY) - { - r_status=VL6180x_RangeGetMeasurement(Device, &RangeData); - l_status=VL6180x_AlsGetMeasurement(Device, &AlsData); - if((!r_status)&&(!l_status)) - { - r_status=GetRangeError(Data, RangeData); - l_status=GetAlsError(Data, AlsData); - if(!r_status) - Data->range_mm=RangeData.range_mm; - else - Data->range_mm=0xFFFFFFFF; - if(!l_status) - Data->lux=AlsData.lux; - else - Data->lux=0xFFFFFFFF; - status=r_status|l_status; - } - else - { - status=r_status|l_status; - } - ClrStatus=VL6180x_ClearAllInterrupt(Device); - if(ClrStatus) - VL6180x_ErrLog("VL6180x_ClearAllInterrupt fail"); - } - else - return NOT_READY; - return status; + } + else + { + VL6180x_ErrLog("Failed to read RESULT_INTERRUPT_STATUS_GPIO"); + } + ClrStatus=VL6180x_ClearAllInterrupt(Device); + if(ClrStatus) + VL6180x_ErrLog("VL6180x_ClearAllInterrupt fail"); + if(status) + return status; + + if(IntStatus.status.Als==RES_INT_STAT_GPIO_NEW_SAMPLE_READY) + { + r_status=VL6180x_RangeGetMeasurement(Device, &RangeData); + l_status=VL6180x_AlsGetMeasurement(Device, &AlsData); + if((!r_status)&&(!l_status)) + { + r_status=GetRangeError(Data, RangeData); + l_status=GetAlsError(Data, AlsData); + if(!r_status) + Data->range_mm=RangeData.range_mm; + else + Data->range_mm=0xFFFFFFFF; + if(!l_status) + Data->lux=AlsData.lux; + else + Data->lux=0xFFFFFFFF; + status=r_status|l_status; + } + else + { + status=r_status|l_status; + } + } + else + return NOT_READY; + return status; } - - + + int VL6180X::StopMeasurement(OperatingMode operating_mode) { - int status; - - switch(operating_mode) - { - case(range_single_shot_polling): - case(range_continuous_polling): - case(range_continuous_interrupt): - case(range_continuous_polling_low_threshold): - case(range_continuous_polling_high_threshold): - case(range_continuous_polling_out_of_window): - case(range_continuous_interrupt_low_threshold): - case(range_continuous_interrrupt_high_threshold): - case(range_continuous_interrupt_out_of_window): - return StopRangeMeasurement(operating_mode); - - case(als_single_shot_polling): - case(als_continuous_polling): - case(als_continuous_interrupt): - case(als_continuous_polling_low_threshold): - case(als_continuous_polling_high_threshold): - case(als_continuous_polling_out_of_window): - case(als_continuous_interrupt_low_threshold): - case(als_continuous_interrupt_high_threshold): - case(als_continuous_interrupt_out_of_window): - return StopAlsMeasurement(operating_mode); - - case(interleaved_mode_interrupt): - status=StopRangeMeasurement(range_continuous_interrupt); - if(!status) - return StopAlsMeasurement(als_continuous_interrupt); - else return status; - - default: - return INVALID_PARAMS; - } + int status; + + switch(operating_mode) + { + case(range_single_shot_polling): + case(range_continuous_polling): + case(range_continuous_interrupt): + case(range_continuous_polling_low_threshold): + case(range_continuous_polling_high_threshold): + case(range_continuous_polling_out_of_window): + case(range_continuous_interrupt_low_threshold): + case(range_continuous_interrrupt_high_threshold): + case(range_continuous_interrupt_out_of_window): + return StopRangeMeasurement(operating_mode); + + case(als_single_shot_polling): + case(als_continuous_polling): + case(als_continuous_interrupt): + case(als_continuous_polling_low_threshold): + case(als_continuous_polling_high_threshold): + case(als_continuous_polling_out_of_window): + case(als_continuous_interrupt_low_threshold): + case(als_continuous_interrupt_high_threshold): + case(als_continuous_interrupt_out_of_window): + return StopAlsMeasurement(operating_mode); + + case(interleaved_mode_interrupt): + status=StopRangeMeasurement(range_continuous_interrupt); + if(!status) + return StopAlsMeasurement(als_continuous_interrupt); + else return status; + + default: + return INVALID_PARAMS; + } } - - + + int VL6180X::StopRangeMeasurement(OperatingMode operating_mode) { - int status; - - if(operating_mode==range_single_shot_polling) - status=VL6180x_RangeSetSystemMode(Device, MODE_SINGLESHOT); - else - status=VL6180x_RangeSetSystemMode(Device, MODE_START_STOP|MODE_SINGLESHOT); - if(status) - return status; - status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if(status) - { - VL6180x_ErrLog("VL6180x_RangeConfigInterrupt fail"\n\r); - return status; - } - status=VL6180x_RangeClearInterrupt(Device); - if(status) - { - VL6180x_ErrLog("VL6180x_RangeClearInterrupt fail"); - return status; - } - status=VL6180x_ClearErrorInterrupt(Device); - if(status) - { - VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); - return status; - } - status=VL6180x_RangeSetRawThresholds(Device, 10, 200); - if(status) - VL6180x_ErrLog("VL6180x_RangeSetThresholds fail"); - return status; + int status; + + if(operating_mode==range_single_shot_polling) + status=VL6180x_RangeSetSystemMode(Device, MODE_SINGLESHOT); + else + status=VL6180x_RangeSetSystemMode(Device, MODE_START_STOP|MODE_SINGLESHOT); + if(status) + return status; + status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if(status) + { + VL6180x_ErrLog("VL6180x_RangeConfigInterrupt fail"\n\r); + return status; + } + status=VL6180x_RangeClearInterrupt(Device); + if(status) + { + VL6180x_ErrLog("VL6180x_RangeClearInterrupt fail"); + return status; + } + status=VL6180x_ClearErrorInterrupt(Device); + if(status) + { + VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); + return status; + } + status=VL6180x_RangeSetRawThresholds(Device, 10, 200); + if(status) + VL6180x_ErrLog("VL6180x_RangeSetThresholds fail"); + return status; } - - + + int VL6180X::StopAlsMeasurement(OperatingMode operating_mode) { - int status; - - if(operating_mode==als_single_shot_polling) - status=VL6180x_AlsSetSystemMode(Device, MODE_SINGLESHOT); - else - status=VL6180x_AlsSetSystemMode(Device, MODE_START_STOP|MODE_SINGLESHOT); - if(status) - return status; - status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); - if(status) - { - VL6180x_ErrLog("VL6180x_AlsConfigInterrupt fail"\n\r); - return status; - } - status=VL6180x_AlsClearInterrupt(Device); - if(status) - { - VL6180x_ErrLog("VL6180x_AlsClearInterrupt fail"); - return status; - } - status=VL6180x_ClearErrorInterrupt(Device); - if(status) - { - VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); - return status; - } - status=VL6180x_AlsSetThresholds(Device, 0x0, 0xFF); - if(status) - VL6180x_ErrLog("VL6180x_AlsSetThresholds fail"); - return status; + int status; + + if(operating_mode==als_single_shot_polling) + status=VL6180x_AlsSetSystemMode(Device, MODE_SINGLESHOT); + else + status=VL6180x_AlsSetSystemMode(Device, MODE_START_STOP|MODE_SINGLESHOT); + if(status) + return status; + status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED); + if(status) + { + VL6180x_ErrLog("VL6180x_AlsConfigInterrupt fail"\n\r); + return status; + } + status=VL6180x_AlsClearInterrupt(Device); + if(status) + { + VL6180x_ErrLog("VL6180x_AlsClearInterrupt fail"); + return status; + } + status=VL6180x_ClearErrorInterrupt(Device); + if(status) + { + VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail"); + return status; + } + status=VL6180x_AlsSetThresholds(Device, 0x0, 0xFF); + if(status) + VL6180x_ErrLog("VL6180x_AlsSetThresholds fail"); + return status; } - - - - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + + + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ \ No newline at end of file
--- a/Components/VL6180X/vl6180x_class.h Tue Oct 20 16:44:28 2015 +0200 +++ b/Components/VL6180X/vl6180x_class.h Tue Oct 27 15:25:11 2015 +0100 @@ -54,38 +54,38 @@ in case of invalid data range_mm=0xFFFFFFFF and lux=0xFFFFFFFF */ typedef struct MeasureData { - int32_t range_mm; - uint32_t lux; - uint32_t range_error; - uint32_t als_error; - uint32_t int_error; + uint32_t range_mm; + uint32_t lux; + uint32_t range_error; + uint32_t als_error; + uint32_t int_error; }MeasureData_t; /* sensor operating modes */ typedef enum { - range_single_shot_polling=1, - als_single_shot_polling, - range_continuous_polling, - als_continuous_polling, - range_continuous_interrupt, - als_continuous_interrupt, - interleaved_mode_interrupt, - range_continuous_polling_low_threshold, - range_continuous_polling_high_threshold, - range_continuous_polling_out_of_window, - als_continuous_polling_low_threshold, - als_continuous_polling_high_threshold, - als_continuous_polling_out_of_window, - range_continuous_interrupt_low_threshold, - range_continuous_interrrupt_high_threshold, - range_continuous_interrupt_out_of_window, - als_continuous_interrupt_low_threshold, - als_continuous_interrupt_high_threshold, - als_continuous_interrupt_out_of_window, - //interleaved con soglie - range_continuous_als_single_shot, - range_single_shot_als_continuous, + range_single_shot_polling=1, + als_single_shot_polling, + range_continuous_polling, + als_continuous_polling, + range_continuous_interrupt, + als_continuous_interrupt, + interleaved_mode_interrupt, + range_continuous_polling_low_threshold, + range_continuous_polling_high_threshold, + range_continuous_polling_out_of_window, + als_continuous_polling_low_threshold, + als_continuous_polling_high_threshold, + als_continuous_polling_out_of_window, + range_continuous_interrupt_low_threshold, + range_continuous_interrrupt_high_threshold, + range_continuous_interrupt_out_of_window, + als_continuous_interrupt_low_threshold, + als_continuous_interrupt_high_threshold, + als_continuous_interrupt_out_of_window, + //interleaved con soglie + range_continuous_als_single_shot, + range_single_shot_als_continuous, }OperatingMode; /** default device address */ @@ -103,183 +103,183 @@ * @param[in] gpio1 pin * @param[in] device address, 0x29 by default */ - VL6180X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), LightSensor(), dev_i2c(i2c), gpio0(&pin), interrupt_measure(pin_gpio1) - { - MyDevice.I2cAddr=DevAddr; - MyDevice.Present=0; - MyDevice.Ready=0; - Device=&MyDevice;; - expgpio0=NULL; - } + VL6180X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), LightSensor(), dev_i2c(i2c), gpio0(&pin), interrupt_measure(pin_gpio1) + { + MyDevice.I2cAddr=DevAddr; + MyDevice.Present=0; + MyDevice.Ready=0; + Device=&MyDevice;; + expgpio0=NULL; + } - VL6180X(DevI2C &i2c, STMPE1600DigiOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), LightSensor(), dev_i2c(i2c), expgpio0(&pin), interrupt_measure(pin_gpio1) - { - MyDevice.I2cAddr=DevAddr; - MyDevice.Present=0; - MyDevice.Ready=0; - Device=&MyDevice; - gpio0=NULL; - } + VL6180X(DevI2C &i2c, STMPE1600DigiOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), LightSensor(), dev_i2c(i2c), expgpio0(&pin), interrupt_measure(pin_gpio1) + { + MyDevice.I2cAddr=DevAddr; + MyDevice.Present=0; + MyDevice.Ready=0; + Device=&MyDevice; + gpio0=NULL; + } /** Destructor */ //~VL6180X(){} /* turns on the sensor */ - void VL6180x_On(void) - { - if(gpio0) - *gpio0=1; - else if(expgpio0) - *expgpio0=1; - } + void VL6180x_On(void) + { + if(gpio0) + *gpio0=1; + else if(expgpio0) + *expgpio0=1; + } - /* turns off the sensor */ + /* turns off the sensor */ void VL6180x_Off(void) - { - if(gpio0) - *gpio0=0; - else if(expgpio0) - *expgpio0=0; - } + { + if(gpio0) + *gpio0=0; + else if(expgpio0) + *expgpio0=0; + } - int InitSensor(uint8_t NewAddr); - int StartMeasurement(OperatingMode operating_mode, void (*fptr)(void), MeasureData_t *Data, uint16_t low, uint16_t high); - int GetMeasurement(OperatingMode operating_mode, MeasureData_t *Data); - int StopMeasurement(OperatingMode operating_mode); + int InitSensor(uint8_t NewAddr); + int StartMeasurement(OperatingMode operating_mode, void (*fptr)(void), MeasureData_t *Data, uint16_t low, uint16_t high); + int GetMeasurement(OperatingMode operating_mode, MeasureData_t *Data); + int StopMeasurement(OperatingMode operating_mode); - /* handling functions of the interrupt_measure */ + /* handling functions of the interrupt_measure */ - /** Attach a function to call when an interrupt is detected, i.e. measurement is ready - * - * @param[in] fptr A pointer to a void function, or 0 to set as none - */ - void AttachInterruptMeasureDetectionIRQ(void (*fptr)(void)) - { - interrupt_measure.rise(fptr); - } + /** Attach a function to call when an interrupt is detected, i.e. measurement is ready + * + * @param[in] fptr A pointer to a void function, or 0 to set as none + */ + void AttachInterruptMeasureDetectionIRQ(void (*fptr)(void)) + { + interrupt_measure.rise(fptr); + } - /** Enable interrupt measure IRQ - */ - void EnableInterruptMeasureDetectionIRQ(void) - { - interrupt_measure.enable_irq(); - } + /** Enable interrupt measure IRQ + */ + void EnableInterruptMeasureDetectionIRQ(void) + { + interrupt_measure.enable_irq(); + } - /** Disable interrupt measure IRQ - */ - void DisableInterruptMeasureDetectionIRQ(void) - { - interrupt_measure.disable_irq(); - } + /** Disable interrupt measure IRQ + */ + void DisableInterruptMeasureDetectionIRQ(void) + { + interrupt_measure.disable_irq(); + } - int HandleIRQ(OperatingMode operating_mode, MeasureData_t *Data); + int HandleIRQ(OperatingMode operating_mode, MeasureData_t *Data); - unsigned Present() - { - return Device->Present; - } + unsigned Present() + { + return Device->Present; + } - /* Wrapper functions */ - int WaitDeviceBooted() - { - return VL6180x_WaitDeviceBooted(Device); - } + /* Wrapper functions */ + int WaitDeviceBooted() + { + return VL6180x_WaitDeviceBooted(Device); + } - int Init() + int Init() { return VL6180x_InitData(Device); } - int SetupGPIO1(uint8_t InitFunction, int ActiveHigh) - { - return VL6180x_SetupGPIO1(Device, InitFunction, ActiveHigh); - } + int SetupGPIO1(uint8_t InitFunction, int ActiveHigh) + { + return VL6180x_SetupGPIO1(Device, InitFunction, ActiveHigh); + } - int Prepare() - { - return VL6180x_Prepare(Device); - } + int Prepare() + { + return VL6180x_Prepare(Device); + } - int RangeStartContinuousMode() - { - return VL6180x_RangeStartContinuousMode(Device); - } + int RangeStartContinuousMode() + { + return VL6180x_RangeStartContinuousMode(Device); + } - int RangeStartSingleShot() - { - return VL6180x_RangeStartSingleShot(Device); - } + int RangeStartSingleShot() + { + return VL6180x_RangeStartSingleShot(Device); + } - int RangeSetMaxConvergenceTime(uint8_t MaxConTime_msec) - { - return VL6180x_RangeSetMaxConvergenceTime(Device, MaxConTime_msec); - } + int RangeSetMaxConvergenceTime(uint8_t MaxConTime_msec) + { + return VL6180x_RangeSetMaxConvergenceTime(Device, MaxConTime_msec); + } - int RangePollMeasurement(VL6180x_RangeData_t *pRangeData) - { - return VL6180x_RangePollMeasurement(Device, pRangeData); - } + int RangePollMeasurement(VL6180x_RangeData_t *pRangeData) + { + return VL6180x_RangePollMeasurement(Device, pRangeData); + } - int RangeGetMeasurementIfReady(VL6180x_RangeData_t *pRangeData) - { - return VL6180x_RangeGetMeasurementIfReady(Device, pRangeData); - } + int RangeGetMeasurementIfReady(VL6180x_RangeData_t *pRangeData) + { + return VL6180x_RangeGetMeasurementIfReady(Device, pRangeData); + } - int RangeGetMeasurement(VL6180x_RangeData_t *pRangeData) - { - return VL6180x_RangeGetMeasurement(Device, pRangeData); - } + int RangeGetMeasurement(VL6180x_RangeData_t *pRangeData) + { + return VL6180x_RangeGetMeasurement(Device, pRangeData); + } - int GetRange(int32_t *piData) - { - return VL6180x_RangeGetResult(Device, piData); - } + int GetRange(int32_t *piData) + { + return VL6180x_RangeGetResult(Device, piData); + } - int RangeConfigInterrupt(uint8_t ConfigGpioInt) - { - return VL6180x_RangeConfigInterrupt(Device, ConfigGpioInt); - } + int RangeConfigInterrupt(uint8_t ConfigGpioInt) + { + return VL6180x_RangeConfigInterrupt(Device, ConfigGpioInt); + } - int RangeGetInterruptStatus(uint8_t *pIntStatus) - { - return VL6180x_RangeGetInterruptStatus(Device, pIntStatus); - } + int RangeGetInterruptStatus(uint8_t *pIntStatus) + { + return VL6180x_RangeGetInterruptStatus(Device, pIntStatus); + } - int AlsPollMeasurement(VL6180x_AlsData_t *pAlsData) - { - return VL6180x_AlsPollMeasurement(Device, pAlsData); - } + int AlsPollMeasurement(VL6180x_AlsData_t *pAlsData) + { + return VL6180x_AlsPollMeasurement(Device, pAlsData); + } - int AlsGetMeasurement(VL6180x_AlsData_t *pAlsData) - { - return VL6180x_AlsGetMeasurement(Device, pAlsData); - } + int AlsGetMeasurement(VL6180x_AlsData_t *pAlsData) + { + return VL6180x_AlsGetMeasurement(Device, pAlsData); + } - int AlsConfigInterrupt(uint8_t ConfigGpioInt) - { - return VL6180x_AlsConfigInterrupt(Device, ConfigGpioInt); - } + int AlsConfigInterrupt(uint8_t ConfigGpioInt) + { + return VL6180x_AlsConfigInterrupt(Device, ConfigGpioInt); + } - int AlsSetIntegrationPeriod(uint16_t period_ms) - { + int AlsSetIntegrationPeriod(uint16_t period_ms) + { return VL6180x_AlsSetIntegrationPeriod(Device, period_ms); - } + } - int AlsSetInterMeasurementPeriod(uint16_t intermeasurement_period_ms) - { + int AlsSetInterMeasurementPeriod(uint16_t intermeasurement_period_ms) + { return VL6180x_AlsSetInterMeasurementPeriod(Device, intermeasurement_period_ms); } int AlsSetAnalogueGain(uint8_t gain) - { - return VL6180x_AlsSetAnalogueGain(Device, gain); - } + { + return VL6180x_AlsSetAnalogueGain(Device, gain); + } - int AlsSetThresholds(uint8_t low, uint8_t high) - { - return VL6180x_AlsSetThresholds(Device, low, high); - } + int AlsSetThresholds(uint8_t low, uint8_t high) + { + return VL6180x_AlsSetThresholds(Device, low, high); + } int AlsGetInterruptStatus(uint8_t *pIntStatus) { @@ -287,231 +287,231 @@ } int StaticInit() - { - return VL6180x_StaticInit(Device); - } + { + return VL6180x_StaticInit(Device); + } - int RangeWaitDeviceReady(int MaxLoop ) - { - return VL6180x_RangeWaitDeviceReady(Device, MaxLoop); - } + int RangeWaitDeviceReady(int MaxLoop ) + { + return VL6180x_RangeWaitDeviceReady(Device, MaxLoop); + } - int RangeSetInterMeasPeriod(uint32_t InterMeasTime_msec) - { - return VL6180x_RangeSetInterMeasPeriod(Device, InterMeasTime_msec); - } + int RangeSetInterMeasPeriod(uint32_t InterMeasTime_msec) + { + return VL6180x_RangeSetInterMeasPeriod(Device, InterMeasTime_msec); + } - int UpscaleSetScaling(uint8_t scaling) - { - return VL6180x_UpscaleSetScaling(Device, scaling); - } + int UpscaleSetScaling(uint8_t scaling) + { + return VL6180x_UpscaleSetScaling(Device, scaling); + } - int UpscaleGetScaling() - { - return VL6180x_UpscaleGetScaling(Device); - } + int UpscaleGetScaling() + { + return VL6180x_UpscaleGetScaling(Device); + } - uint16_t GetUpperLimit() - { - return VL6180x_GetUpperLimit(Device); - } + uint16_t GetUpperLimit() + { + return VL6180x_GetUpperLimit(Device); + } - int RangeSetThresholds(uint16_t low, uint16_t high, int SafeHold) - { - return VL6180x_RangeSetThresholds(Device, low, high, SafeHold); - } + int RangeSetThresholds(uint16_t low, uint16_t high, int SafeHold) + { + return VL6180x_RangeSetThresholds(Device, low, high, SafeHold); + } - int RangeGetThresholds(uint16_t *low, uint16_t *high) - { - return VL6180x_RangeGetThresholds(Device, low, high); - } + int RangeGetThresholds(uint16_t *low, uint16_t *high) + { + return VL6180x_RangeGetThresholds(Device, low, high); + } - int RangeSetRawThresholds(uint8_t low, uint8_t high) - { - return VL6180x_RangeSetRawThresholds(Device, low, high); - } + int RangeSetRawThresholds(uint8_t low, uint8_t high) + { + return VL6180x_RangeSetRawThresholds(Device, low, high); + } - int RangeSetEceFactor(uint16_t FactorM, uint16_t FactorD) - { - return VL6180x_RangeSetEceFactor(Device, FactorM, FactorD); - } + int RangeSetEceFactor(uint16_t FactorM, uint16_t FactorD) + { + return VL6180x_RangeSetEceFactor(Device, FactorM, FactorD); + } - int RangeSetEceState(int enable) - { - return VL6180x_RangeSetEceState(Device, enable); - } + int RangeSetEceState(int enable) + { + return VL6180x_RangeSetEceState(Device, enable); + } - int FilterSetState(int state) - { - return VL6180x_FilterSetState(Device, state); - } + int FilterSetState(int state) + { + return VL6180x_FilterSetState(Device, state); + } - int FilterGetState() - { - return VL6180x_FilterGetState(Device); - } + int FilterGetState() + { + return VL6180x_FilterGetState(Device); + } - int DMaxSetState(int state) - { - return VL6180x_DMaxSetState(Device, state); - } + int DMaxSetState(int state) + { + return VL6180x_DMaxSetState(Device, state); + } - int DMaxGetState() - { - return VL6180x_DMaxGetState(Device); - } + int DMaxGetState() + { + return VL6180x_DMaxGetState(Device); + } - int RangeSetSystemMode(uint8_t mode) - { - return VL6180x_RangeSetSystemMode(Device, mode); - } + int RangeSetSystemMode(uint8_t mode) + { + return VL6180x_RangeSetSystemMode(Device, mode); + } - int8_t GetOffsetCalibrationData() - { - return VL6180x_GetOffsetCalibrationData(Device); - } + int8_t GetOffsetCalibrationData() + { + return VL6180x_GetOffsetCalibrationData(Device); + } - void SetOffsetCalibrationData(int8_t offset) - { - return VL6180x_SetOffsetCalibrationData(Device, offset); - } + void SetOffsetCalibrationData(int8_t offset) + { + return VL6180x_SetOffsetCalibrationData(Device, offset); + } - int SetXTalkCompensationRate(FixPoint97_t Rate) - { - return VL6180x_SetXTalkCompensationRate(Device, Rate); - } + int SetXTalkCompensationRate(FixPoint97_t Rate) + { + return VL6180x_SetXTalkCompensationRate(Device, Rate); + } - int AlsWaitDeviceReady(int MaxLoop) - { - return VL6180x_AlsWaitDeviceReady(Device, MaxLoop); - } + int AlsWaitDeviceReady(int MaxLoop) + { + return VL6180x_AlsWaitDeviceReady(Device, MaxLoop); + } - int AlsSetSystemMode(uint8_t mode) - { - return VL6180x_AlsSetSystemMode(Device, mode); - } + int AlsSetSystemMode(uint8_t mode) + { + return VL6180x_AlsSetSystemMode(Device, mode); + } - int SetGroupParamHold(int Hold) - { - return VL6180x_SetGroupParamHold(Device, Hold); - } + int SetGroupParamHold(int Hold) + { + return VL6180x_SetGroupParamHold(Device, Hold); + } - int SetI2CAddress(int NewAddr) - { - int status; + int SetI2CAddress(int NewAddr) + { + int status; - status=VL6180x_SetI2CAddress(Device, NewAddr); - if(!status) - Device->I2cAddr=NewAddr; - return status; - } + status=VL6180x_SetI2CAddress(Device, NewAddr); + if(!status) + Device->I2cAddr=NewAddr; + return status; + } - int SetupGPIOx(int pin, uint8_t IntFunction, int ActiveHigh) - { - return VL6180x_SetupGPIOx(Device, pin, IntFunction, ActiveHigh); - } + int SetupGPIOx(int pin, uint8_t IntFunction, int ActiveHigh) + { + return VL6180x_SetupGPIOx(Device, pin, IntFunction, ActiveHigh); + } - int SetGPIOxPolarity(int pin, int active_high) - { - return VL6180x_SetGPIOxPolarity(Device, pin, active_high); - } + int SetGPIOxPolarity(int pin, int active_high) + { + return VL6180x_SetGPIOxPolarity(Device, pin, active_high); + } - int SetGPIOxFunctionality(int pin, uint8_t functionality) - { - return VL6180x_SetGPIOxFunctionality(Device, pin, functionality); - } + int SetGPIOxFunctionality(int pin, uint8_t functionality) + { + return VL6180x_SetGPIOxFunctionality(Device, pin, functionality); + } - int DisableGPIOxOut(int pin) - { - return VL6180x_DisableGPIOxOut(Device, pin); - } + int DisableGPIOxOut(int pin) + { + return VL6180x_DisableGPIOxOut(Device, pin); + } - int GetInterruptStatus(uint8_t *status) - { - return VL6180x_GetInterruptStatus(Device, status); - } + int GetInterruptStatus(uint8_t *status) + { + return VL6180x_GetInterruptStatus(Device, status); + } - int ClearInterrupt(uint8_t IntClear) - { - return VL6180x_ClearInterrupt(Device, IntClear ); - } + int ClearInterrupt(uint8_t IntClear) + { + return VL6180x_ClearInterrupt(Device, IntClear ); + } - int GetLight(uint32_t *piData) - { - return VL6180x_AlsGetLux(Device, piData); - } + int GetLight(uint32_t *piData) + { + return VL6180x_AlsGetLux(Device, piData); + } - int AlsStartContinuousMode() - { - return VL6180x_AlsSetSystemMode(Device, MODE_START_STOP|MODE_CONTINUOUS); - } + int AlsStartContinuousMode() + { + return VL6180x_AlsSetSystemMode(Device, MODE_START_STOP|MODE_CONTINUOUS); + } -private: - /* api.h functions */ - int VL6180x_WaitDeviceBooted(VL6180xDev_t dev); - int VL6180x_InitData(VL6180xDev_t dev ); - int VL6180x_SetupGPIO1(VL6180xDev_t dev, uint8_t IntFunction, int ActiveHigh); - int VL6180x_Prepare(VL6180xDev_t dev); - int VL6180x_RangeStartContinuousMode(VL6180xDev_t dev); - int VL6180x_RangeStartSingleShot(VL6180xDev_t dev); - int VL6180x_RangeSetMaxConvergenceTime(VL6180xDev_t dev, uint8_t MaxConTime_msec); - int VL6180x_RangePollMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); - int VL6180x_RangeGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); - int VL6180x_RangeGetMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); - int VL6180x_RangeGetResult(VL6180xDev_t dev, int32_t *pRange_mm); - int VL6180x_RangeConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt); - int VL6180x_RangeGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus); - int VL6180x_AlsPollMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData); - int VL6180x_AlsGetMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData); - int VL6180x_AlsConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt); - int VL6180x_AlsSetIntegrationPeriod(VL6180xDev_t dev, uint16_t period_ms); - int VL6180x_AlsSetInterMeasurementPeriod(VL6180xDev_t dev, uint16_t intermeasurement_period_ms); - int VL6180x_AlsSetAnalogueGain(VL6180xDev_t dev, uint8_t gain); - int VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high); - int VL6180x_AlsGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus); - int VL6180x_StaticInit(VL6180xDev_t dev); - int VL6180x_RangeWaitDeviceReady(VL6180xDev_t dev, int MaxLoop ); - int VL6180x_RangeSetInterMeasPeriod(VL6180xDev_t dev, uint32_t InterMeasTime_msec); - int VL6180x_UpscaleSetScaling(VL6180xDev_t dev, uint8_t scaling); - int VL6180x_UpscaleGetScaling(VL6180xDev_t dev); - uint16_t VL6180x_GetUpperLimit(VL6180xDev_t dev); - int VL6180x_RangeSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high, int SafeHold); - int VL6180x_RangeGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high); - int VL6180x_RangeSetRawThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high); - int VL6180x_RangeSetEceFactor(VL6180xDev_t dev, uint16_t FactorM, uint16_t FactorD); - int VL6180x_RangeSetEceState(VL6180xDev_t dev, int enable ); - int VL6180x_FilterSetState(VL6180xDev_t dev, int state); - int VL6180x_FilterGetState(VL6180xDev_t dev); - int VL6180x_DMaxSetState(VL6180xDev_t dev, int state); - int VL6180x_DMaxGetState(VL6180xDev_t dev); - int VL6180x_RangeSetSystemMode(VL6180xDev_t dev, uint8_t mode); - int8_t VL6180x_GetOffsetCalibrationData(VL6180xDev_t dev); - void VL6180x_SetOffsetCalibrationData(VL6180xDev_t dev, int8_t offset); - int VL6180x_SetXTalkCompensationRate(VL6180xDev_t dev, FixPoint97_t Rate); - int VL6180x_AlsWaitDeviceReady(VL6180xDev_t dev, int MaxLoop ); - int VL6180x_AlsSetSystemMode(VL6180xDev_t dev, uint8_t mode); - int VL6180x_SetGroupParamHold(VL6180xDev_t dev, int Hold); - int VL6180x_SetI2CAddress(VL6180xDev_t dev, uint8_t NewAddr); - int VL6180x_SetupGPIOx(VL6180xDev_t dev, int pin, uint8_t IntFunction, int ActiveHigh); - int VL6180x_SetGPIOxPolarity(VL6180xDev_t dev, int pin, int active_high); - int VL6180x_SetGPIOxFunctionality(VL6180xDev_t dev, int pin, uint8_t functionality); - int VL6180x_DisableGPIOxOut(VL6180xDev_t dev, int pin); - int VL6180x_GetInterruptStatus(VL6180xDev_t dev, uint8_t *status); - int VL6180x_ClearInterrupt(VL6180xDev_t dev, uint8_t IntClear ); + private: + /* api.h functions */ + int VL6180x_WaitDeviceBooted(VL6180xDev_t dev); + int VL6180x_InitData(VL6180xDev_t dev ); + int VL6180x_SetupGPIO1(VL6180xDev_t dev, uint8_t IntFunction, int ActiveHigh); + int VL6180x_Prepare(VL6180xDev_t dev); + int VL6180x_RangeStartContinuousMode(VL6180xDev_t dev); + int VL6180x_RangeStartSingleShot(VL6180xDev_t dev); + int VL6180x_RangeSetMaxConvergenceTime(VL6180xDev_t dev, uint8_t MaxConTime_msec); + int VL6180x_RangePollMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); + int VL6180x_RangeGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); + int VL6180x_RangeGetMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); + int VL6180x_RangeGetResult(VL6180xDev_t dev, int32_t *pRange_mm); + int VL6180x_RangeConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt); + int VL6180x_RangeGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus); + int VL6180x_AlsPollMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData); + int VL6180x_AlsGetMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData); + int VL6180x_AlsConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt); + int VL6180x_AlsSetIntegrationPeriod(VL6180xDev_t dev, uint16_t period_ms); + int VL6180x_AlsSetInterMeasurementPeriod(VL6180xDev_t dev, uint16_t intermeasurement_period_ms); + int VL6180x_AlsSetAnalogueGain(VL6180xDev_t dev, uint8_t gain); + int VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high); + int VL6180x_AlsGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus); + int VL6180x_StaticInit(VL6180xDev_t dev); + int VL6180x_RangeWaitDeviceReady(VL6180xDev_t dev, int MaxLoop ); + int VL6180x_RangeSetInterMeasPeriod(VL6180xDev_t dev, uint32_t InterMeasTime_msec); + int VL6180x_UpscaleSetScaling(VL6180xDev_t dev, uint8_t scaling); + int VL6180x_UpscaleGetScaling(VL6180xDev_t dev); + uint16_t VL6180x_GetUpperLimit(VL6180xDev_t dev); + int VL6180x_RangeSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high, int SafeHold); + int VL6180x_RangeGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high); + int VL6180x_RangeSetRawThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high); + int VL6180x_RangeSetEceFactor(VL6180xDev_t dev, uint16_t FactorM, uint16_t FactorD); + int VL6180x_RangeSetEceState(VL6180xDev_t dev, int enable ); + int VL6180x_FilterSetState(VL6180xDev_t dev, int state); + int VL6180x_FilterGetState(VL6180xDev_t dev); + int VL6180x_DMaxSetState(VL6180xDev_t dev, int state); + int VL6180x_DMaxGetState(VL6180xDev_t dev); + int VL6180x_RangeSetSystemMode(VL6180xDev_t dev, uint8_t mode); + int8_t VL6180x_GetOffsetCalibrationData(VL6180xDev_t dev); + void VL6180x_SetOffsetCalibrationData(VL6180xDev_t dev, int8_t offset); + int VL6180x_SetXTalkCompensationRate(VL6180xDev_t dev, FixPoint97_t Rate); + int VL6180x_AlsWaitDeviceReady(VL6180xDev_t dev, int MaxLoop ); + int VL6180x_AlsSetSystemMode(VL6180xDev_t dev, uint8_t mode); + int VL6180x_SetGroupParamHold(VL6180xDev_t dev, int Hold); + int VL6180x_SetI2CAddress(VL6180xDev_t dev, uint8_t NewAddr); + int VL6180x_SetupGPIOx(VL6180xDev_t dev, int pin, uint8_t IntFunction, int ActiveHigh); + int VL6180x_SetGPIOxPolarity(VL6180xDev_t dev, int pin, int active_high); + int VL6180x_SetGPIOxFunctionality(VL6180xDev_t dev, int pin, uint8_t functionality); + int VL6180x_DisableGPIOxOut(VL6180xDev_t dev, int pin); + int VL6180x_GetInterruptStatus(VL6180xDev_t dev, uint8_t *status); + int VL6180x_ClearInterrupt(VL6180xDev_t dev, uint8_t IntClear ); - /* Other functions defined in api.c */ - int VL6180x_RangeStaticInit(VL6180xDev_t dev); - int VL6180x_UpscaleRegInit(VL6180xDev_t dev); - int VL6180x_UpscaleStaticInit(VL6180xDev_t dev); - int VL6180x_AlsGetLux(VL6180xDev_t dev, lux_t *pLux); - int _UpscaleInitPatch0(VL6180xDev_t dev); - int VL6180x_RangeGetDeviceReady(VL6180xDev_t dev, int * Ready); - int VL6180x_RangeSetEarlyConvergenceEestimateThreshold(VL6180xDev_t dev); - int32_t _GetAveTotalTime(VL6180xDev_t dev); - int32_t _filter_Start(VL6180xDev_t dev, uint16_t m_trueRange_mm, uint16_t m_rawRange_mm, uint32_t m_rtnSignalRate, uint32_t m_rtnAmbientRate, uint16_t errorCode); - int _filter_GetResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); - int _GetRateResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); - int _DMax_InitData(VL6180xDev_t dev); + /* Other functions defined in api.c */ + int VL6180x_RangeStaticInit(VL6180xDev_t dev); + int VL6180x_UpscaleRegInit(VL6180xDev_t dev); + int VL6180x_UpscaleStaticInit(VL6180xDev_t dev); + int VL6180x_AlsGetLux(VL6180xDev_t dev, lux_t *pLux); + int _UpscaleInitPatch0(VL6180xDev_t dev); + int VL6180x_RangeGetDeviceReady(VL6180xDev_t dev, int * Ready); + int VL6180x_RangeSetEarlyConvergenceEestimateThreshold(VL6180xDev_t dev); + int32_t _GetAveTotalTime(VL6180xDev_t dev); + int32_t _filter_Start(VL6180xDev_t dev, uint16_t m_trueRange_mm, uint16_t m_rawRange_mm, uint32_t m_rtnSignalRate, uint32_t m_rtnAmbientRate, uint16_t errorCode); + int _filter_GetResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); + int _GetRateResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); + int _DMax_InitData(VL6180xDev_t dev); /* Read function of the ID device */ int ReadID(); @@ -523,41 +523,41 @@ int VL6180x_RdByte(VL6180xDev_t dev, uint16_t index, uint8_t *data); int VL6180x_RdWord(VL6180xDev_t dev, uint16_t index, uint16_t *data); int VL6180x_RdDWord(VL6180xDev_t dev, uint16_t index, uint32_t *data); - int VL6180x_UpdateByte(VL6180xDev_t dev, uint16_t index, uint8_t AndData, uint8_t OrData); + int VL6180x_UpdateByte(VL6180xDev_t dev, uint16_t index, uint8_t AndData, uint8_t OrData); int VL6180x_I2CWrite(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToWrite); int VL6180x_I2CRead(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToRead); - int IsPresent() - { - int status; + int IsPresent() + { + int status; - status=ReadID(); + status=ReadID(); if(status) - printf("Failed to read ID device! Device not present!\n\r"); //FIXME da sistemare la funzione di stampa errore ErrLog da platform.h - return status; - } - int StopRangeMeasurement(OperatingMode operating_mode); - int StopAlsMeasurement(OperatingMode operating_mode); - int GetRangeMeas(OperatingMode operating_mode, MeasureData_t *Data); - int GetAlsMeas(OperatingMode operating_mode, MeasureData_t *Data); - int GetRangeAlsMeas(MeasureData_t *Data); - int RangeSetLowThreshold(uint16_t threshold); - int RangeSetHighThreshold(uint16_t threshold); - int AlsSetLowThreshold(uint16_t threshold); - int AlsSetHighThreshold(uint16_t threshold); - int GetRangeError(MeasureData_t *Data, VL6180x_RangeData_t RangeData); - int GetAlsError(MeasureData_t *Data, VL6180x_AlsData_t AlsData); - int RangeMeasPollSingleShot(MeasureData_t *Data); - int AlsMeasPollSingleShot(MeasureData_t *Data); - int RangeMeasPollContinuousMode(); - int AlsMeasPollContinuousMode(); - int AlsGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData); - int RangeMeasIntContinuousMode(void (*fptr)(void)); - int AlsMeasIntContinuousMode(void (*fptr)(void)); - int InterleavedMode(void (*fptr)(void)); - int StartInterleavedMode(); - int VL6180x_AlsGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high); + printf("Failed to read ID device! Device not present!\n\r"); //FIXME da sistemare la funzione di stampa errore ErrLog da platform.h + return status; + } + int StopRangeMeasurement(OperatingMode operating_mode); + int StopAlsMeasurement(OperatingMode operating_mode); + int GetRangeMeas(OperatingMode operating_mode, MeasureData_t *Data); + int GetAlsMeas(OperatingMode operating_mode, MeasureData_t *Data); + int GetRangeAlsMeas(MeasureData_t *Data); + int RangeSetLowThreshold(uint16_t threshold); + int RangeSetHighThreshold(uint16_t threshold); + int AlsSetLowThreshold(uint16_t threshold); + int AlsSetHighThreshold(uint16_t threshold); + int GetRangeError(MeasureData_t *Data, VL6180x_RangeData_t RangeData); + int GetAlsError(MeasureData_t *Data, VL6180x_AlsData_t AlsData); + int RangeMeasPollSingleShot(MeasureData_t *Data); + int AlsMeasPollSingleShot(MeasureData_t *Data); + int RangeMeasPollContinuousMode(); + int AlsMeasPollContinuousMode(); + int AlsGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData); + int RangeMeasIntContinuousMode(void (*fptr)(void)); + int AlsMeasIntContinuousMode(void (*fptr)(void)); + int InterleavedMode(void (*fptr)(void)); + int StartInterleavedMode(); + int VL6180x_AlsGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high); /* IO Device */
--- a/Components/VL6180X/vl6180x_platform.h Tue Oct 20 16:44:28 2015 +0200 +++ b/Components/VL6180X/vl6180x_platform.h Tue Oct 27 15:25:11 2015 +0100 @@ -31,9 +31,9 @@ #define VL6180x_SINGLE_DEVICE_DRIVER 0 #define VL6180x_RANGE_STATUS_ERRSTRING 1 -#define VL6180X_SAFE_POLLING_ENTER 0 -#define VL6180X_LOG_ENABLE 0 - +#define VL6180X_SAFE_POLLING_ENTER 0 +#define VL6180X_LOG_ENABLE 0 +#define MY_LOG 1 #define VL6180x_DEV_DATA_ATTR #define ROMABLE_DATA @@ -69,11 +69,17 @@ }while(0) #else /* VL6180X_LOG_ENABLE no logging */ -void OnErrLog(void); - #define LOG_FUNCTION_START(...) (void)0 - #define LOG_FUNCTION_END(...) (void)0 - #define LOG_FUNCTION_END_FMT(...) (void)0 - #define VL6180x_ErrLog(... ) OnErrLog() //(void)0 + void OnErrLog(void); + #define LOG_FUNCTION_START(...) (void)0 + #define LOG_FUNCTION_END(...) (void)0 + #define LOG_FUNCTION_END_FMT(...) (void)0 + #define VL6180x_ErrLog(... ) OnErrLog() //(void)0 +#endif + + +#ifdef MY_LOG + extern Serial pc; + #define printf(...) pc.printf(__VA_ARGS__) #endif
--- a/x_nucleo_6180xa1.cpp Tue Oct 20 16:44:28 2015 +0200 +++ b/x_nucleo_6180xa1.cpp Tue Oct 27 15:25:11 2015 +0100 @@ -45,82 +45,82 @@ X_NUCLEO_6180XA1* X_NUCLEO_6180XA1::Instance(DevI2C *ext_i2c) { - if(_instance==NULL) - _instance=new X_NUCLEO_6180XA1(ext_i2c); - else - VL6180x_ErrLog("Failed to init X_NUCLEO_6180XA1 board!\n"); - return _instance; + if(_instance==NULL) + _instance=new X_NUCLEO_6180XA1(ext_i2c); + else + VL6180x_ErrLog("Failed to init X_NUCLEO_6180XA1 board!\n"); + return _instance; } int X_NUCLEO_6180XA1::InitBoard() //FIXME sistemare le stampe degli errori { - int status, n_dev=0; + int status, n_dev=0; - sensor_top->VL6180x_Off(); - sensor_bottom->VL6180x_Off(); - sensor_left->VL6180x_Off(); - sensor_right->VL6180x_Off(); - status=sensor_top->InitSensor(NEW_SENSOR_TOP_ADDRESS); - if(status) - { - delete sensor_top; - delete gpio0_top; - sensor_top=NULL; - gpio0_top=NULL; - //VL6180x_ErrLog("Fail to init sensor_top\n\r"); - printf("Failure to init sensor_top\n\r"); - } - else - { - n_dev++; - } - status=sensor_bottom->InitSensor(NEW_SENSOR_BOTTOM_ADDRESS); - if(status) - { - delete sensor_bottom; - delete gpio0_bottom; - sensor_bottom=NULL; - gpio0_bottom=NULL; - //VL6180x_ErrLog("Fail to init sensor_bottom\n\r"); - printf("Failed to init sensor_bottom\n\r"); - } - else - { - n_dev++; - } - status=sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS); - if(status) - { - delete sensor_left; - delete gpio0_left; - sensor_left=NULL; - gpio0_left=NULL; - //VL6180x_ErrLog("Fail to init sensor_left\n\r"); - printf("Failed to init sensor_left\n\r"); - } - else - { - n_dev++; - } - status=sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS); - if(status) - { - delete sensor_right; - delete gpio0_right; - sensor_right=NULL; - gpio0_right=NULL; - //VL6180x_ErrLog("Fail to init sensor_right\n\r"); - printf("Failed to init sensor_right\n\r"); - } - else - { - n_dev++; - } - if(n_dev==0) - return 1; - else - return 0; + sensor_top->VL6180x_Off(); + sensor_bottom->VL6180x_Off(); + sensor_left->VL6180x_Off(); + sensor_right->VL6180x_Off(); + status=sensor_top->InitSensor(NEW_SENSOR_TOP_ADDRESS); + if(status) + { + delete sensor_top; + delete gpio0_top; + sensor_top=NULL; + gpio0_top=NULL; + //VL6180x_ErrLog("Failed to init sensor_top\n\r"); + printf("Failed to init sensor_top\n\r"); + } + else + { + n_dev++; + } + status=sensor_bottom->InitSensor(NEW_SENSOR_BOTTOM_ADDRESS); + if(status) + { + delete sensor_bottom; + delete gpio0_bottom; + sensor_bottom=NULL; + gpio0_bottom=NULL; + //VL6180x_ErrLog("Failed to init sensor_bottom\n\r"); + printf("Failed to init sensor_bottom\n\r"); + } + else + { + n_dev++; + } + status=sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS); + if(status) + { + delete sensor_left; + delete gpio0_left; + sensor_left=NULL; + gpio0_left=NULL; + //VL6180x_ErrLog("Failed to init sensor_left\n\r"); + printf("Failed to init sensor_left\n\r"); + } + else + { + n_dev++; + } + status=sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS); + if(status) + { + delete sensor_right; + delete gpio0_right; + sensor_right=NULL; + gpio0_right=NULL; + //VL6180x_ErrLog("Failed to init sensor_right\n\r"); + printf("Failed to init sensor_right\n\r"); + } + else + { + n_dev++; + } + if(n_dev==0) + return 1; + else + return 0; }
--- a/x_nucleo_6180xa1.h Tue Oct 20 16:44:28 2015 +0200 +++ b/x_nucleo_6180xa1.h Tue Oct 27 15:25:11 2015 +0100 @@ -43,7 +43,7 @@ /* Includes ------------------------------------------------------------------*/ #include "mbed.h" #include "vl6180x_class.h" -#include "display_class.h" +#include "Display_class.h" #include "STMPE1600_class.h" #include "DevI2C.h" @@ -57,81 +57,125 @@ class X_NUCLEO_6180XA1 { - public: - X_NUCLEO_6180XA1(DevI2C *ext_i2c) : dev_i2c(ext_i2c) + public: + X_NUCLEO_6180XA1(DevI2C *ext_i2c) : dev_i2c(ext_i2c) { - gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12); - sensor_top=new VL6180X(*dev_i2c, *gpio0_top, PB_0); - gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13); - sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, PA_4); - gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14); - sensor_left=new VL6180X(*dev_i2c, *gpio0_left, D13); - gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15); - sensor_right=new VL6180X(*dev_i2c, *gpio0_right, PA_10); - } + digit1=new STMPE1600DigiOut(*dev_i2c, GPIO_7); + digit2=new STMPE1600DigiOut(*dev_i2c, GPIO_8); + digit3=new STMPE1600DigiOut(*dev_i2c, GPIO_9); + digit4=new STMPE1600DigiOut(*dev_i2c, GPIO_10); + + dispA=new STMPE1600DigiOut(*dev_i2c, GPIO_0); + dispB=new STMPE1600DigiOut(*dev_i2c, GPIO_1); + dispC=new STMPE1600DigiOut(*dev_i2c, GPIO_2); + dispD=new STMPE1600DigiOut(*dev_i2c, GPIO_3); + dispE=new STMPE1600DigiOut(*dev_i2c, GPIO_4); + dispF=new STMPE1600DigiOut(*dev_i2c, GPIO_5); + dispG=new STMPE1600DigiOut(*dev_i2c, GPIO_6); + //display=new Display(*digit1,*digit2,*digit3,*digit4,*dispA,*dispB,*dispC,*dispD,*dispE,*dispF,*dispG); + display=new Display(*ext_i2c); + + gpio0_top=new STMPE1600DigiOut(*dev_i2c, GPIO_12); + sensor_top=new VL6180X(*dev_i2c, *gpio0_top, PB_0); + + gpio0_bottom=new STMPE1600DigiOut(*dev_i2c, GPIO_13); + sensor_bottom=new VL6180X(*dev_i2c, *gpio0_bottom, PA_4); + + gpio0_left=new STMPE1600DigiOut(*dev_i2c, GPIO_14); + sensor_left=new VL6180X(*dev_i2c, *gpio0_left, PA_5); + + gpio0_right=new STMPE1600DigiOut(*dev_i2c, GPIO_15); + sensor_right=new VL6180X(*dev_i2c, *gpio0_right, PA_10); + } - ~X_NUCLEO_6180XA1() + ~X_NUCLEO_6180XA1() { - if(gpio0_top!=NULL) - { - delete gpio0_top; - gpio0_top=NULL; - } - if(sensor_top!=NULL) - { - delete sensor_top; - sensor_top=NULL; - } - if(gpio0_bottom!=NULL) - { - delete gpio0_bottom; - gpio0_bottom=NULL; - } - if(sensor_bottom!=NULL) - { - delete sensor_bottom; - sensor_bottom=NULL; - } - if(gpio0_left!=NULL) - { - delete gpio0_left; - gpio0_left=NULL; - } - if(sensor_left!=NULL) - { - delete sensor_left; - sensor_left=NULL; - } - if(gpio0_right!=NULL) - { - delete gpio0_right; - gpio0_right=NULL; - } - if(sensor_right!=NULL) - { - delete sensor_right; - sensor_right=NULL; - } - } + if(gpio0_top!=NULL) + { + delete gpio0_top; + gpio0_top=NULL; + } + if(sensor_top!=NULL) + { + delete sensor_top; + sensor_top=NULL; + } + if(gpio0_bottom!=NULL) + { + delete gpio0_bottom; + gpio0_bottom=NULL; + } + if(sensor_bottom!=NULL) + { + delete sensor_bottom; + sensor_bottom=NULL; + } + if(gpio0_left!=NULL) + { + delete gpio0_left; + gpio0_left=NULL; + } + if(sensor_left!=NULL) + { + delete sensor_left; + sensor_left=NULL; + } + if(gpio0_left!=NULL) + { + delete gpio0_left; + gpio0_left=NULL; + } + if(sensor_left!=NULL) + { + delete sensor_left; + sensor_left=NULL; + } + if(gpio0_right!=NULL) + { + delete gpio0_right; + gpio0_right=NULL; + } + if(sensor_right!=NULL) + { + delete sensor_right; + sensor_right=NULL; + } + } - DevI2C *dev_i2c; - STMPE1600DigiOut *gpio0_top; - STMPE1600DigiOut *gpio0_bottom; - STMPE1600DigiOut *gpio0_left; - STMPE1600DigiOut *gpio0_right; - VL6180X *sensor_top; - VL6180X *sensor_bottom; - VL6180X *sensor_left; - VL6180X *sensor_right; + DevI2C *dev_i2c; + + VL6180X *sensor_top; + VL6180X *sensor_bottom; + VL6180X *sensor_left; + VL6180X *sensor_right; + + STMPE1600DigiOut *gpio0_top; + STMPE1600DigiOut *gpio0_bottom; + STMPE1600DigiOut *gpio0_left; + STMPE1600DigiOut *gpio0_right; - //Display *display; - - static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c); + + STMPE1600DigiOut *digit1; + STMPE1600DigiOut *digit2; + STMPE1600DigiOut *digit3; + STMPE1600DigiOut *digit4; - int InitBoard(); + STMPE1600DigiOut *dispA; + STMPE1600DigiOut *dispB; + STMPE1600DigiOut *dispC; + STMPE1600DigiOut *dispD; + STMPE1600DigiOut *dispE; + STMPE1600DigiOut *dispF; + STMPE1600DigiOut *dispG; + + Display *display; - private: - static X_NUCLEO_6180XA1 *_instance; + static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c); + + int InitBoard(); + + private: + static X_NUCLEO_6180XA1 *_instance; }; #endif /* __X_NUCLEO_6180XA1_H */