use VL6180XA1 chip wothout X-NUCLEO-6180XA1 Board. Simple way to use the chip.

Dependents:   Check_VL6180XA1_ToF

Fork of X_NUCLEO_6180XA1 by ST

Files at this revision

API Documentation at this revision

Comitter:
gallonm
Date:
Tue Oct 13 14:22:45 2015 +0200
Parent:
11:88541229403e
Child:
13:6736a00a0aa9
Commit message:
Introduced virtual functions GetRange and GetLight of the sensor classes.
Fixed as wrapper functions of VL6180x_RangeGetResult and VL6180x_AlsGetLux.

Fixed a comment of the stmpe1600_class.h

Fixed the function InitSensor.
Introduced the function StartMeasurement to choose the operating mode.
Introduced the funcions RangeMeasPollSingleShot, AlsMeasPollSingleShot,
RangeMeasPollContinuousMode, AlsMeasPollContinuousMode, RangeMeasIntContinuousMode,
AlsMeasIntContinuousMode and InterleavedMode to manage different type of operating
mode.
Introduced the functions GetRangeError and GetAlsError to verify error measurement.
Introduced the functions GetRangeMeasContinuousMode and GetAlsMeasContinuousMode
to get the result of the measure in continuous mode.
Introduced the function StartInterleavedMode to start the interleaved mode.
Introduced the function HandleIRQ to manage the interrupt request.

Introduced MeasureData_t struct that contains the results of range and als measure
and related error (range, als and gpio).
Introduced enum OperatingMode and MeasureType.
Fixed the Vl6180x constructor, introducing the parameter PinName gpio1 needed to
interrupt_measure.
Introduced the wrapper functions.
Introducede InterruptIn interrupt_measure to handle the interrupt request.

Fixed the x_nucleo_6180xa1 constructor.

Fixed the object sensor_top.

Changed in this revision

Components/Interfaces/LightSensor.h Show annotated file Show diff for this revision Revisions of this file
Components/Interfaces/RangeSensor.h Show annotated file Show diff for this revision Revisions of this file
Components/STMPE1600/stmpe1600_class.h Show annotated file Show diff for this revision Revisions of this file
Components/VL6180X/vl6180x_class.cpp Show annotated file Show diff for this revision Revisions of this file
Components/VL6180X/vl6180x_class.h Show annotated file Show diff for this revision Revisions of this file
x_nucleo_6180xa1.cpp Show annotated file Show diff for this revision Revisions of this file
x_nucleo_6180xa1.h Show annotated file Show diff for this revision Revisions of this file
--- a/Components/Interfaces/LightSensor.h	Tue Oct 06 09:43:25 2015 +0200
+++ b/Components/Interfaces/LightSensor.h	Tue Oct 13 14:22:45 2015 +0200
@@ -54,7 +54,7 @@
      * @param[out]  piData Pointer to where to store light to
      * @return      0 in case of success, an error code otherwise
      */
-    //virtual int GetLight(int *piData) = 0;
+    virtual int GetLight(uint32_t *piData) = 0;
 };
 
 #endif /* __LIGHT_SENSOR_CLASS_H */
--- a/Components/Interfaces/RangeSensor.h	Tue Oct 06 09:43:25 2015 +0200
+++ b/Components/Interfaces/RangeSensor.h	Tue Oct 13 14:22:45 2015 +0200
@@ -54,7 +54,7 @@
      * @param[out]  piData Pointer to where to store range to
      * @return      0 in case of success, an error code otherwise
      */
-    //virtual int GetRange(int *piData) = 0;
+    virtual int GetRange(int32_t *piData) = 0;
 };
 
 #endif /* __RANGE_SENSOR_CLASS_H */
--- a/Components/STMPE1600/stmpe1600_class.h	Tue Oct 06 09:43:25 2015 +0200
+++ b/Components/STMPE1600/stmpe1600_class.h	Tue Oct 13 14:22:45 2015 +0200
@@ -94,7 +94,7 @@
 			/* 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 gopio as out 			
+			*(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);
@@ -132,7 +132,7 @@
 			/* 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);			
-			*(uint16_t*)data = *(uint16_t*)data & (uint16_t)(~(1<<(uint16_t)exppinname));  // set gopio as in			
+			*(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);						
 		}         
--- a/Components/VL6180X/vl6180x_class.cpp	Tue Oct 06 09:43:25 2015 +0200
+++ b/Components/VL6180X/vl6180x_class.cpp	Tue Oct 13 14:22:45 2015 +0200
@@ -90,6 +90,7 @@
 
 
 /****************** define for i2c configuration *******************************/
+
 #define TEMP_BUF_SIZE	32
 
 #define IsValidGPIOFunction(x) ((x)==GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT || (x)==GPIOx_SELECT_OFF)
@@ -826,7 +827,6 @@
         goto done;
     }
 
-
     /* poll for new sample ready */
     while(1 ){
         status=VL6180x_RangeGetInterruptStatus(dev, &IntStatus.val);
@@ -842,7 +842,7 @@
         if( IntStatus.status.Range == RES_INT_STAT_GPIO_NEW_SAMPLE_READY){
             break;
         }
-
+        
         VL6180x_PollDelay(dev);
     }
  /* //![single_shot_snipet] */
@@ -2667,5 +2667,353 @@
 }
 
 
-
+int VL6180X::InitSensor(uint8_t NewAddr) //FIXME printf da sostituire con VL6180x_ErrLog e poi specificare il contenuto di questa funzione
+{
+   int status=0;
+	  
+   VL6180x_Off();
+   VL6180x_On();
+   status=IsPresent();
+   if(!status)
+   {
+     Device->Present=1;
+		 status=Init();
+     if(status)
+       printf("Failed to init VL6180X sensor!\n");
+		 status=Prepare();
+     if(status)
+       printf("Failed to prepare VL6180X!\n");
+     //status=SetI2CAddress(NewAddr);
+     if(status)
+			 printf("Failed to change I2C address!\n");
+		 /* disable early convergence estimate 
+		 status=VL6180x_RangeSetEceState(Device, 0);
+		 if(status)
+			 printf("Failed to disable ECE!");*/
+		 Device->Ready=1;
+ 	 }
+	 return status;
+}
+
+
+int VL6180X::StartMeasurement(OperatingMode operating_mode, void (*fptr)(void), MeasureData_t *Data) 
+{
+   int status;
+	
+   switch(operating_mode)
+   {
+		  case(1):
+				return RangeMeasPollSingleShot(Data);
+		
+      case(2):
+			  return AlsMeasPollSingleShot(Data);
+			
+			case(3):
+				return RangeMeasPollContinuousMode(Data);
+				 
+			case(4):
+				return AlsMeasPollContinuousMode(Data);  
+				 
+      case(5):
+				return RangeMeasIntContinuousMode(fptr);
+					 
+		  case(6):
+				return AlsMeasIntContinuousMode(fptr);
+				
+	    case(7): break;
+				
+	    case(8): break;
+				
+		  case(9):
+			  return InterleavedMode(fptr); 
+				
+		  default:
+			   return INVALID_PARAMS;
+	 }
+}
+
+
+int VL6180X::GetRangeError(MeasureData_t *Data, VL6180x_RangeData_t RangeData)
+{
+	 IntrStatus_t IntStatus;
+	 int status;
+	 
+	 status=VL6180x_RangeGetInterruptStatus(Device, &IntStatus.val);
+	 if(status)
+		 return status;
+	 Data->range_error=RangeData.errorStatus;
+	 Data->int_error=IntStatus.status.Error;
+	 if((Data->int_error!=0)||(Data->range_error!=0))
+	 {
+      VL6180x_ErrLog("GPIO int Error report %d",(int)IntStatus.val);
+      status=RANGE_ERROR;
+	 }
+	 return status;
+}
+
+
+int VL6180X::GetAlsError(MeasureData_t *Data, VL6180x_AlsData_t AlsData)
+{
+	 Data->als_error=AlsData.errorStatus;
+	 if(Data->als_error!=0)
+     return API_ERROR;
+	 return API_NO_ERROR;
+}
+
+
+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;
+	 }
+	 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;
+	 }
+	 return status;	
+}
+
+
+int VL6180X::RangeMeasPollContinuousMode(MeasureData_t *Data)
+{
+   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();
+}
+
+
+int VL6180X::AlsMeasPollContinuousMode(MeasureData_t *Data) 
+{
+	 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::GetRangeMeasContinuousMode(MeasureData_t *Data)
+{
+   VL6180x_RangeData_t RangeData;
+	 int status;
+	
+	 status=VL6180x_RangeGetMeasurement(Device, &RangeData);
+	 if(!status)
+	 {
+		  status=GetRangeError(Data, RangeData);
+		  if(!status)
+		    Data->range_mm=RangeData.range_mm;
+	 }
+	 return status;
+}
+
+
+int VL6180X::GetAlsMeasContinuousMode(MeasureData_t *Data)
+{
+	 VL6180x_AlsData_t AlsData;
+	 int status;
+	
+	 status=VL6180x_AlsGetMeasurement(Device, &AlsData);
+	 if(!status)
+	 {
+	    status=GetAlsError(Data, AlsData);
+		  if(!status)
+				Data->lux=AlsData.lux;
+	 }
+	 return status;
+}
+
+
+int VL6180X::RangeMeasIntContinuousMode(void (*fptr)(void))
+{
+	 int status;
+	 
+	 EnableInterruptMeasureDetectionIRQ();
+	 AttachInterruptMeasureDetectionIRQ(fptr);
+	 status=SetupGPIO1(GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT, 1);
+	 /*ClrStatus=VL6180x_ClearAllInterrupt(Device);
+		if(ClrStatus)
+			VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail");*/
+   if(!status)
+		 return RangeStartContinuousMode();
+}
+
+
+int VL6180X::AlsMeasIntContinuousMode(void (*fptr)(void))
+{
+   int status;
+	
+	 EnableInterruptMeasureDetectionIRQ();
+   AttachInterruptMeasureDetectionIRQ(fptr);
+   status=SetupGPIO1(GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT, 1);
+	 /*ClrStatus=VL6180x_ClearAllInterrupt(Device);
+		if(ClrStatus)
+			VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail");*/
+   if(!status)
+     return AlsStartContinuousMode(); 
+}	
+
+
+int VL6180X::StartInterleavedMode()
+{
+	 int status;
+	 uint16_t integration_period, intermeasurement_period_ms;
+	 uint8_t max_convergence_time;
+	
+   status=VL6180x_WrByte(Device, 0x2A3, 1);
+   if(status)
+   {
+		 VL6180x_ErrLog("Failed to read 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;
+	 status=VL6180x_AlsSetInterMeasurementPeriod(Device, intermeasurement_period_ms);
+	 if(status)
+   {
+		 VL6180x_ErrLog("Failed to write SYSALS_INTERMEASUREMENT_PERIOD!\n\r");
+		 return status;
+	 }
+	 return AlsStartContinuousMode();
+}
+
+
+int VL6180X::InterleavedMode(void (*fptr)(void))
+{
+	  int status;
+	
+	  EnableInterruptMeasureDetectionIRQ();
+    AttachInterruptMeasureDetectionIRQ(fptr);
+    status=SetupGPIO1(GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT, 1);
+	  /*ClrStatus=VL6180x_ClearAllInterrupt(Device);
+		if(ClrStatus)
+			VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail");*/
+    if(!status)
+      return StartInterleavedMode();
+}
+
+
+void VL6180X::HandleIRQ(MeasureType measure_type, MeasureData_t *Data)
+{
+	 int status, ClrStatus;
+	 /* range measure */
+	 if(measure_type==1)
+	 {
+		  VL6180x_RangeData_t RangeData;
+		  status=RangeGetMeasurement(&RangeData);
+			if(status)
+				VL6180x_ErrLog("Failed to get range measurement");
+			ClrStatus=VL6180x_RangeClearInterrupt(Device);
+			if(ClrStatus)
+				VL6180x_ErrLog("VL6180x_RangeClearInterrupt fail");
+			ClrStatus=VL6180x_ClearErrorInterrupt(Device);
+			if(ClrStatus)
+				VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail");
+		  EnableInterruptMeasureDetectionIRQ();
+			status=GetRangeError(Data, RangeData);
+		  if(!status)
+		     Data->range_mm=RangeData.range_mm;
+   }
+	 /* light measure */
+	 else if(measure_type==2)
+	 {
+	    VL6180x_AlsData_t AlsData;
+		  status=AlsGetMeasurement(&AlsData);
+		  if(status)
+				VL6180x_ErrLog("Failed to get light measurement");
+			ClrStatus=VL6180x_AlsClearInterrupt(Device);
+			if(ClrStatus)
+				VL6180x_ErrLog("VL6180x_AlsClearInterrupt fail");
+			ClrStatus=VL6180x_ClearErrorInterrupt(Device);
+			if(ClrStatus)
+				VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail");
+			EnableInterruptMeasureDetectionIRQ();
+			status=GetAlsError(Data, AlsData);
+		  if(!status)
+			   Data->lux=AlsData.lux;
+	 }
+	 /* light and range measure */
+	 else if(measure_type==3)
+	 {
+		  VL6180x_RangeData_t RangeData;
+		  VL6180x_AlsData_t AlsData;
+		  status=RangeGetMeasurement(&RangeData);
+			if(status)
+				VL6180x_ErrLog("Failed to get range measurement");
+			status=AlsGetMeasurement(&AlsData);
+		  if(status)
+				VL6180x_ErrLog("Failed to get light measurement");		 
+		  ClrStatus=VL6180x_ClearAllInterrupt(Device);
+			if(ClrStatus)
+				VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail");	
+			EnableInterruptMeasureDetectionIRQ();
+			status=GetAlsError(Data, AlsData);
+			if(!status)
+				Data->lux=AlsData.lux;
+			status=GetRangeError(Data, RangeData);
+			if(!status)
+				Data->range_mm=RangeData.range_mm;
+	 }
+   else
+		  printf("Error! Invalid parameter!");
+}
+
+
+
+	
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/Components/VL6180X/vl6180x_class.h	Tue Oct 06 09:43:25 2015 +0200
+++ b/Components/VL6180X/vl6180x_class.h	Tue Oct 13 14:22:45 2015 +0200
@@ -50,47 +50,75 @@
 //#include "vl6180x_appcfg.h"
 #include "STMPE1600_class.h"
 
+/* data struct containing range measure, light measure and type of error provided to the user */	
+typedef struct MeasureData 
+{
+	int32_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,
+	range_continuous_als_single_shot,
+	range_single_shot_als_continuous,
+	interleaved_mode,
+}OperatingMode;
+
+/* type of sensor measurement */
+typedef enum
+{
+  range_measure=1,
+	light_measure,
+	light_range_measure,
+}MeasureType;
+
+
 /** default device address */
 #define DEFAULT_DEVICE_ADDRESS		0x29
 
 /* Classes -------------------------------------------------------------------*/
 /** Class representing a VL6180X sensor component
  */
- //FIXME verficare se impostare le funzioni come virtual come nel caso IKS
 class VL6180X : public RangeSensor, public LightSensor 
 {
  public:
     /** Constructor
      * @param[in] i2c device I2C to be used for communication
      * @param[in] digital out pin/STMPE1600DigiOut pin to be used for GPIO expander communication
-     * @param[in] device address, 0x29 by default 
-     * @param[in] device id, 0 by default
+     * @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)
+		 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;
-			  //free_fall=new InterruptIn(pin_gpio1);
 		 }  
 		
-     VL6180X(DevI2C &i2c, STMPE1600DigiOut &pin, /*PinName pin_gpio1,*/ uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), LightSensor(), dev_i2c(i2c), expgpio0(&pin)
+     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;			 
-        //free_fall=new InterruptIn(pin_gpio1);			 
-		 }  
-		 
+			  gpio0=NULL;			 		 
+		 }  	 
     
    /** Destructor
     */
-    //~VL6180X(){} 
-		 
+    //~VL6180X(){} 		 
 		 
 		 void VL6180x_On(void) {
 			if (gpio0) *gpio0=1;
@@ -101,54 +129,91 @@
 			if (gpio0) *gpio0=0;
 			else if (expgpio0) *expgpio0=0;			
 		}
-    
-		int InitSensor(uint8_t NewAddr) 
-		{
-		   int status;
-	  
-       VL6180x_Off();
-       VL6180x_On();
-	     status=IsPresent();
-	     if(!status)
-	     {
-		     Device->Present=1;
-		     status=Init();
-         if(status)
-			      error("Failed to init VL6180X sensor!\n");
-         status=Prepare();
-         if(status)
-			      error("Failed to prepare VL6180X!\n");
-	       status=SetI2CAddress(NewAddr);
-		     if(status)
-			      error("Failed to change I2C address!\n");
-		     Device->Ready=1;
-	     }
-			 return status;
-		}
-    
-    int Init() 
-    {
-       return VL6180x_InitData(Device); // ritorna 0 se corretto 
-    }
-		
+ 
 		int IsPresent()
 		{
 			 int status;
 			
 			 status=ReadID();
-       if(!status)
-				 error("Failed to read ID device! Device not present!\n");
+       if(status)
+				 printf("Failed to read ID device! Device not present!\n"); //FIXME da sistemare la funzione di stampa errore ErrLog da platform.h
 			 return status;
 		}
 		
-		void SetPresent()
+		int InitSensor(uint8_t NewAddr);	
+		
+		int StartMeasurement(OperatingMode operating_mode, void (*fptr)(void), MeasureData_t *Data); 
+		
+		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 AlsStartContinuousMode()
 		{
-			 Device->Present=1;
+			 return VL6180x_AlsSetSystemMode(Device, MODE_START_STOP|MODE_CONTINUOUS);
 		}
 		
-		void SetReady()
+		int RangeMeasPollContinuousMode(MeasureData_t *Data);
+		
+		int AlsMeasPollContinuousMode(MeasureData_t *Data);
+		
+		int GetRangeMeasContinuousMode(MeasureData_t *Data);
+		
+		int GetAlsMeasContinuousMode(MeasureData_t *Data);
+		
+		int RangeMeasIntContinuousMode(void (*fptr)(void));
+		
+		int AlsMeasIntContinuousMode(void (*fptr)(void));
+		
+		int InterleavedMode(void (*fptr)(void));
+		
+		int StartInterleavedMode();
+
+		/* 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))
 		{
-			 Device->Ready=1;
+		  interrupt_measure.rise(fptr);
+	  }
+
+	  /** Enable interrupt measure IRQ
+	  */
+	  void EnableInterruptMeasureDetectionIRQ(void) 
+		{
+		  interrupt_measure.enable_irq();
+	  }
+
+	  /** Disable interrupt measure IRQ
+	  */
+	  void DisableInterruptMeasureDetectionIRQ(void) 
+		{
+		  interrupt_measure.disable_irq();
+	  }
+		
+		void HandleIRQ(MeasureType measure_type, MeasureData_t *Data); // FIXME sistemare la sequenza delle funzioni completandola con i print degli errori
+		
+		/* Wrapper functions */	
+		int WaitDeviceBooted()
+		{
+			 return VL6180x_WaitDeviceBooted(Device);
+		}
+		
+		int Init() 
+    {
+       return VL6180x_InitData(Device);
+    }
+		
+		int SetupGPIO1(uint8_t InitFunction, int ActiveHigh)
+		{
+			 return VL6180x_SetupGPIO1(Device, InitFunction, ActiveHigh);
 		}
 		
 		int Prepare()
@@ -156,6 +221,201 @@
 			 return VL6180x_Prepare(Device);
 		}
 		
+		int RangeStartContinuousMode()
+		{
+			 return VL6180x_RangeStartContinuousMode(Device);
+		}
+		
+		int RangeStartSingleShot()
+		{
+			return VL6180x_RangeStartSingleShot(Device);
+		}
+		
+		int RangeSetMaxConvergenceTime(uint8_t MaxConTime_msec)
+		{
+			 return VL6180x_RangeSetMaxConvergenceTime(Device, MaxConTime_msec);
+		}
+		
+		int RangePollMeasurement(VL6180x_RangeData_t *pRangeData)
+		{
+			 return VL6180x_RangePollMeasurement(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 GetRange(int32_t *piData)
+		{
+			 return VL6180x_RangeGetResult(Device, piData);
+		}
+		
+		int RangeConfigInterrupt(uint8_t ConfigGpioInt)
+		{
+			 return VL6180x_RangeConfigInterrupt(Device, ConfigGpioInt);
+		}
+		
+		int RangeGetInterruptStatus(uint8_t *pIntStatus)
+		{
+			 return VL6180x_RangeGetInterruptStatus(Device, pIntStatus);
+		}
+		
+		int AlsPollMeasurement(VL6180x_AlsData_t *pAlsData)
+		{
+			 return VL6180x_AlsPollMeasurement(Device, pAlsData);
+		}
+		
+		int AlsGetMeasurement(VL6180x_AlsData_t *pAlsData)
+		{
+			 return VL6180x_AlsGetMeasurement(Device, pAlsData);
+		}
+	
+		int AlsConfigInterrupt(uint8_t ConfigGpioInt)
+		{
+			 return VL6180x_AlsConfigInterrupt(Device, ConfigGpioInt);
+		}
+		
+		int AlsSetIntegrationPeriod(uint16_t period_ms)
+		{
+       return VL6180x_AlsSetIntegrationPeriod(Device, 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);
+		}
+		
+		int AlsSetThresholds(uint8_t low, uint8_t high)
+		{
+			 return VL6180x_AlsSetThresholds(Device, low, high);
+		}
+
+    int AlsGetInterruptStatus(uint8_t *pIntStatus)
+		{
+       return VL6180x_AlsGetInterruptStatus(Device, pIntStatus);
+    }
+
+    int StaticInit()
+		{
+			 return VL6180x_StaticInit(Device);
+		}
+		
+		int RangeWaitDeviceReady(int MaxLoop )
+		{
+			 return VL6180x_RangeWaitDeviceReady(Device, MaxLoop);
+		}
+		
+		int RangeSetInterMeasPeriod(uint32_t  InterMeasTime_msec)
+		{
+			 return VL6180x_RangeSetInterMeasPeriod(Device, InterMeasTime_msec);
+	  }
+		
+		int UpscaleSetScaling(uint8_t scaling)
+		{
+			 return VL6180x_UpscaleSetScaling(Device, scaling);
+		}
+		
+		int UpscaleGetScaling()
+		{
+			 return VL6180x_UpscaleGetScaling(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 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 RangeSetEceFactor(uint16_t  FactorM, uint16_t FactorD)
+		{
+			 return VL6180x_RangeSetEceFactor(Device, FactorM, FactorD);
+		}
+		
+		int RangeSetEceState(int enable)
+		{
+			 return VL6180x_RangeSetEceState(Device, enable);
+		}
+			
+		int FilterSetState(int state)
+		{
+			 return VL6180x_FilterSetState(Device, state);
+		}
+			
+		int FilterGetState()
+		{
+			 return VL6180x_FilterGetState(Device);
+		}
+		
+		int DMaxSetState(int state)
+		{
+			 return VL6180x_DMaxSetState(Device, state);
+		}
+		
+		int DMaxGetState()
+		{
+			 return VL6180x_DMaxGetState(Device);
+		}
+		
+		int RangeSetSystemMode(uint8_t mode)
+		{
+			 return VL6180x_RangeSetSystemMode(Device, mode);
+		}
+		
+		int8_t GetOffsetCalibrationData()
+		{
+			 return VL6180x_GetOffsetCalibrationData(Device);
+		}
+		
+		void SetOffsetCalibrationData(int8_t offset)
+		{
+			 return VL6180x_SetOffsetCalibrationData(Device, offset);
+		}
+		
+		int SetXTalkCompensationRate(FixPoint97_t Rate)
+		{
+			 return VL6180x_SetXTalkCompensationRate(Device, Rate);
+		}
+		
+		int AlsWaitDeviceReady(int MaxLoop)
+		{
+			 return VL6180x_AlsWaitDeviceReady(Device, MaxLoop);
+		}
+		
+		int AlsSetSystemMode(uint8_t mode)
+		{
+			 return VL6180x_AlsSetSystemMode(Device, mode);
+		}
+
+		int SetGroupParamHold(int Hold)
+		{
+			 return VL6180x_SetGroupParamHold(Device, Hold);
+		}		
+		
 		int SetI2CAddress(int NewAddr)
 		{
 			 int status;
@@ -166,46 +426,43 @@
 			 return status;
 		}
 		
-		int StartMeasurement(int operating_mode)
+		int SetupGPIOx(int pin, uint8_t IntFunction, int ActiveHigh)
 		{
-		  int status;
-	
-	    switch(operating_mode)
-	    {
-		     case(1):
-			     return VL6180x_RangePollMeasurement(Device, &RangeData);
-         case(2):
-			     return VL6180x_AlsPollMeasurement(Device, &AlsData);
-         case(3): break;		
-		     case(4): break;
-	       case(5): break;
-	       case(6): break;
-		     case(7): break;
-		     default:
-			     return INVALID_PARAMS;
-	    }
-	  }
-    /*
-    int GetRange(int *piData) {
-        return VL6180X_RangeGetMeasurement(piData);
-    }
-
-    int GetLight(int *piData) {
-        return VL6180X_AlsGetMeasurement(piData);
-    }*/
-		
-		int RangePollMeasurement()
-		{
-			 return VL6180x_RangePollMeasurement(Device, &RangeData);
+			 return VL6180x_SetupGPIOx(Device, pin, IntFunction, ActiveHigh);
 		}
 		
-		int AlsPollMeasurement()
+		int SetGPIOxPolarity(int pin, int active_high)
+		{
+			 return VL6180x_SetGPIOxPolarity(Device, pin, active_high);
+		}
+		 
+		int SetGPIOxFunctionality(int pin, uint8_t functionality)
 		{
-			 return VL6180x_AlsPollMeasurement(Device, &AlsData);
+			 return VL6180x_SetGPIOxFunctionality(Device, pin, functionality);
+		}
+	
+		int DisableGPIOxOut(int pin)
+		{
+			 return VL6180x_DisableGPIOxOut(Device, pin);
 		}
 		
-		    
-		/* api.c functions */
+		int GetInterruptStatus(uint8_t *status)
+		{
+			 return VL6180x_GetInterruptStatus(Device, status);
+		}
+		
+		int ClearInterrupt(uint8_t IntClear)
+		{
+			 return VL6180x_ClearInterrupt(Device, IntClear );
+		}
+		
+		int GetLight(uint32_t *piData)
+		{
+		   return VL6180x_AlsGetLux(Device, piData);
+	  }
+		
+		
+		/* 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);
@@ -256,6 +513,8 @@
 		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); 
@@ -292,15 +551,11 @@
     DigitalOut *gpio0;
     /* GPIO expander */
     STMPE1600DigiOut *expgpio0;
-    /* Input interrupt */
-    //InterruptIn *free_fall;
+    /* Measure detection IRQ */
+    InterruptIn interrupt_measure;
     /* Device data */
     MyVL6180Dev_t MyDevice;
     VL6180xDev_t Device;  
-    /* Device range data */
-    VL6180x_RangeData_t RangeData;
-    /* Device als data */
-    VL6180x_AlsData_t AlsData;
 };
 
 #endif // __VL6180X_CLASS_H
--- a/x_nucleo_6180xa1.cpp	Tue Oct 06 09:43:25 2015 +0200
+++ b/x_nucleo_6180xa1.cpp	Tue Oct 13 14:22:45 2015 +0200
@@ -60,8 +60,8 @@
 	status=sensor_top->InitSensor(NEW_SENSOR_TOP_ADDRESS);
 	if(status)
 	{
-	   delete[] sensor_top;
-		 delete[] gpio0_top;
+	   delete sensor_top;
+		 delete gpio0_top;
 		 sensor_top=NULL;
  		 gpio0_top=NULL;
 	}
--- a/x_nucleo_6180xa1.h	Tue Oct 06 09:43:25 2015 +0200
+++ b/x_nucleo_6180xa1.h	Tue Oct 13 14:22:45 2015 +0200
@@ -47,7 +47,7 @@
 #include "STMPE1600_class.h"
 #include "DevI2C.h"
 
-/** New device addresses */
+/** New device addresses */ //FIXME sistemare i nuovi indirizzi da assegnare ai sensori
 #define NEW_SENSOR_TOP_ADDRESS			0x10
 //#define NEW_SENSOR_LEFT_ADDRESS			0x33
 //#define NEW_SENSOR_BOTTOM_ADDRESS		0x34
@@ -61,7 +61,7 @@
 		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);
+	     sensor_top=new VL6180X(*dev_i2c, *gpio0_top, PB_0);
 		}
 		
 		~X_NUCLEO_6180XA1()
@@ -76,6 +76,7 @@
 		STMPE1600DigiOut *gpio0_top;
 		VL6180X *sensor_top;
 		
+		//pin gpio1: bottom=PA4, left=D13, right=PA10
 		//VL6180X *vl6180x_left;
 		//VL6180X *vl6180x_bottom;
 		//VL6180X *vl6180x_right;
@@ -83,7 +84,7 @@
 		
 		static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c);
 		
-	  int InitBoard(); // posso ritornare il numero dei dispositivi attivi 
+	  int InitBoard(); // FIXME posso ritornare il numero dei dispositivi attivi 
 		
 	private:
 		static X_NUCLEO_6180XA1 *_instance;