Changes to the library related to interrupt mode.

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Dependents:   Display_53L0A1_IntSatelites Display_53L0A1_InterruptMode

Fork of X_NUCLEO_53L0A1 by ST

Revision:
11:c955adfbb19b
Parent:
10:faf8d62ce6d1
--- a/Components/VL53L0X/vl53l0x_class.h	Wed Jun 07 14:58:36 2017 +0000
+++ b/Components/VL53L0X/vl53l0x_class.h	Wed Jun 14 13:35:05 2017 +0000
@@ -303,7 +303,7 @@
      * @param[in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
      * @param[in] DevAddr device address, 0x29 by default  
      */
-    VL53L0X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), dev_i2c(i2c), gpio0(&pin)
+    VL53L0X(DevI2C &i2c, DigitalOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : dev_i2c(i2c), gpio0(&pin)
     {
        MyDevice.I2cDevAddr=DevAddr;		 
        MyDevice.comms_type=1; // VL53L0X_COMMS_I2C
@@ -320,7 +320,7 @@
      * @param[in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT
      * @param[in] device address, 0x29 by default  
      */		
-    VL53L0X(DevI2C &i2c, STMPE1600DigiOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), dev_i2c(i2c), expgpio0(&pin)
+    VL53L0X(DevI2C &i2c, STMPE1600DigiOut &pin, PinName pin_gpio1, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : dev_i2c(i2c), expgpio0(&pin)
     {
        MyDevice.I2cDevAddr=DevAddr;		 
        MyDevice.comms_type=1; // VL53L0X_COMMS_I2C
@@ -479,6 +479,7 @@
 //			return 1;
     }
 
+
 /**
  *
  * @brief One time device initialization
@@ -495,9 +496,16 @@
  * @param void
  * @return     0 on success,  @a #CALIBRATION_WARNING if failed
  */		
+ 	virtual int init(void *init)
+	{
+		return VL53L0X_DataInit(Device);
+	}
+	
+/** deprecated Init funtion from ComponentObject. for backward compatibility
+*/	
     virtual int Init(void * NewAddr)
     {
-       return VL53L0X_DataInit(Device);
+    	return init(NewAddr);
     }
 
 /**
@@ -576,8 +584,9 @@
  */		
     int RangeStartContinuousMode()
     {
-//       return VL6180x_RangeStartContinuousMode(Device);
-			return 1;
+		int status;
+		status = RangeSetSystemMode(VL53L0X_REG_SYSRANGE_MODE_START_STOP|VL53L0X_REG_SYSRANGE_MODE_BACKTOBACK);
+    	return status;
     }
 
 /**
@@ -687,7 +696,7 @@
  * @param pRange_mm  Pointer to range distance
  * @return           0 on success
  */		
-    virtual int GetDistance(uint32_t *piData)
+    virtual int get_distance(uint32_t *piData)
     {
         int status=0;
         VL53L0X_RangingMeasurementData_t pRangingMeasurementData;
@@ -707,7 +716,11 @@
         StopMeasurement(range_single_shot_polling);
         return status;
     }
-		
+/* Deprecated funtion from RangeSensor class. For backward compatibility*/	
+	virtual int GetDistance(uint32_t *piData)
+	{
+		return get_distance(piData);
+	}	
 /**
  * @brief Configure ranging interrupt reported to application
  *
@@ -721,8 +734,18 @@
  */
     int RangeConfigInterrupt(uint8_t ConfigGpioInt)
     {
-//       return VL6180x_RangeConfigInterrupt(Device, ConfigGpioInt);
-			return 1;
+    	int status;
+		 if( ConfigGpioInt<= VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY)
+		 {
+		 	status = VL53L0X_UpdateByte(Device, VL53L0X_REG_SYSTEM_INTERRUPT_CONFIG_GPIO, (uint8_t)(~(0x7<<0)), ConfigGpioInt);
+		 }
+		 else
+		 {
+		 	status = 1;
+		 }	
+		//       return VL6180x_RangeConfigInterrupt(Device, ConfigGpioInt);
+			
+		return status;
     }
 
 /**
@@ -974,9 +997,24 @@
  * @return      0 on success
  */		
     int RangeSetSystemMode(uint8_t mode)
-    {
+    {    	
+	    int status;
+	    /* FIXME we are not checking device is ready via @a VL6180X_RangeWaitDeviceReady
+	     * so if called back to back real fast we are not checking
+	     * if previous mode "set" got absorbed => bit 0 must be 0 so that it work
+	     */
+	    if( mode <= 3){
+	        status=VL53L0X_WrByte(Device, VL53L0X_REG_SYSRANGE_START, mode);
+	        if( status ){
+	            VL53L0X_ErrLog("SYSRANGE_START wr fail");
+	        }
+	    }
+	    else{
+	        status = 1;
+	    }
+	    return status;    	
 //       return VL6180x_RangeSetSystemMode(Device, mode);
-			return 1;
+//			return 1;
     }
 
 /** @}  */ 
@@ -1044,8 +1082,7 @@
        if(!status)
           Device->I2cDevAddr=NewAddr;
        return status;
-			
-//			return 1;
+
     }
 
 /**
@@ -1134,8 +1171,9 @@
  */		
     int ClearInterrupt(uint8_t IntClear)
     {
+         int status = VL53L0X_WrByte(Device, VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR, IntClear);
 //       return VL6180x_ClearInterrupt(Device, IntClear );
-			return 1;
+	     return status;
     }
 
 /**
@@ -1339,9 +1377,13 @@
     		uint8_t *Revision,
     		VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo);
 
-    /* Read function of the ID device */
-//    virtual int ReadID();
+	/* deprecated Read function from Component class for backward compatibility*/
+	//   virtual int ReadID();
     virtual int ReadID(uint8_t *id);
+
+	/* Read function of the ID device */
+	//   virtual int read_id();    
+    virtual int read_id(uint8_t *id);
     
     VL53L0X_Error WaitMeasurementDataReady(VL53L0X_DEV Dev);
     VL53L0X_Error WaitStopCompleted(VL53L0X_DEV Dev);