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 06 09:03:10 2015 +0200
Parent:
9:9cbc1736f148
Child:
11:88541229403e
Commit message:
Fitted all api files (reinserted original api files)
Modified file platform.h and removed vl6180x_appcfg.h from the include
Modified value of the define SINGLE_DEVICE_DRIVER
Updated file stmpe1600_class.h
Fitted the ReadID function and I2C functions (read and write)
Updated file vl6180x_class.cpp
Introduced functions InitSensor and StartMeasurement
Fitted the constructor and the destructor of x_nucleo_6180xa1
Added the instance to create a singleton object
Introduced InitBoard function

Changed in this revision

Components/STMPE1600/stmpe1600_class.h Show annotated file Show diff for this revision Revisions of this file
Components/VL6180X/vl6180x_api.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
Components/VL6180X/vl6180x_def.h Show annotated file Show diff for this revision Revisions of this file
Components/VL6180X/vl6180x_platform.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/STMPE1600/stmpe1600_class.h	Tue Sep 29 15:40:08 2015 +0200
+++ b/Components/STMPE1600/stmpe1600_class.h	Tue Oct 06 09:03:10 2015 +0200
@@ -37,8 +37,7 @@
 #ifndef     __STMPE1600_CLASS
 #define     __STMPE1600_CLASS
 /* Includes ------------------------------------------------------------------*/
-#include    "mbed.h"
-#include		<assert.h>
+#include    "DevI2C.h"
 
 #define STMPE1600_DEF_DEVICE_ADDRESS  (uint8_t)0x42*2   
 #define STMPE1600_DEF_DIGIOUT_LVL      1
--- a/Components/VL6180X/vl6180x_api.h	Tue Sep 29 15:40:08 2015 +0200
+++ b/Components/VL6180X/vl6180x_api.h	Tue Oct 06 09:03:10 2015 +0200
@@ -50,6 +50,15 @@
 /** @defgroup api_hl API High Level Functions
  *  @brief    API High level functions
  */
+ 
+
+/*
+ * Check and set default platform dependent configuration
+ */
+#ifndef  VL6180x_SINGLE_DEVICE_DRIVER
+#error "VL6180x_SINGLE_DEVICE_DRIVER not defined"
+/* TODO you may remove or comment these #error but it is best you update your vl6180x_platform.h file to define it*/
+#endif
 
 
 #ifndef  VL6180x_RANGE_STATUS_ERRSTRING
@@ -100,7 +109,871 @@
  *  @ingroup api_hl
  *  @{  
  */
+/**
+ * @brief Wait for device booted after chip enable (hardware standby)
+ * @par Function Description
+ * After Chip enable Application you can also simply wait at least 1ms to ensure device is ready
+ * @warning After device chip enable (gpio0) de-asserted  user must wait gpio1 to get asserted (hardware standby).
+ * or wait at least 400usec prior to do any low level access or api call .
+ *
+ * This function implements polling for standby but you must ensure 400usec from chip enable passed\n
+ * @warning if device get prepared @a VL6180x_Prepare() re-using these function can hold indefinitely\n
+ *
+ * @param dev  The device
+ * @return     0 on success
+ */
+int VL6180x_WaitDeviceBooted(VL6180xDev_t dev);
+
+/**
+ *
+ * @brief One time device initialization
+ *
+ * To be called once and only once after device is brought out of reset (Chip enable) and booted see @a VL6180x_WaitDeviceBooted()
+ *
+ * @par Function Description
+ * When not used after a fresh device "power up" or reset, it may return @a #CALIBRATION_WARNING
+ * meaning wrong calibration data may have been fetched from device that can result in ranging offset error\n
+ * If application cannot execute device reset or need to run VL6180x_InitData  multiple time
+ * then it  must ensure proper offset calibration saving and restore on its own
+ * by using @a VL6180x_GetOffsetCalibrationData() on first power up and then @a VL6180x_SetOffsetCalibrationData() all all subsequent init
+ *
+ * @param dev  The device
+ * @return     0 on success,  @a #CALIBRATION_WARNING if failed
+ */
+int VL6180x_InitData(VL6180xDev_t dev );
+
+/**
+ * @brief Configure GPIO1 function and set polarity.
+ * @par Function Description
+ * To be used prior to arm single shot measure or start  continuous mode.
+ *
+ * The function uses @a VL6180x_SetupGPIOx() for setting gpio 1.
+ * @warning  changing polarity can generate a spurious interrupt on pins.
+ * It sets an interrupt flags condition that must be cleared to avoid polling hangs. \n
+ * It is safe to run VL6180x_ClearAllInterrupt() just after.
+ *
+ * @param dev           The device
+ * @param IntFunction   The interrupt functionality to use one of :\n
+ *  @a #GPIOx_SELECT_OFF \n
+ *  @a #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT
+ * @param ActiveHigh  The interrupt line polarity see ::IntrPol_e
+ *      use @a #INTR_POL_LOW (falling edge) or @a #INTR_POL_HIGH (rising edge)
+ * @return 0 on success
+ */
+int VL6180x_SetupGPIO1(VL6180xDev_t dev, uint8_t IntFunction, int ActiveHigh);
+
+ /**
+  * @brief  Prepare device for operation
+  * @par Function Description
+  * Does static initialization and reprogram common default settings \n
+  * Device is prepared for new measure, ready single shot ranging or ALS typical polling operation\n
+  * After prepare user can : \n
+  * @li Call other API function to set other settings\n
+  * @li Configure the interrupt pins, etc... \n
+  * @li Then start ranging or ALS operations in single shot or continuous mode
+  *
+  * @param dev   The device
+  * @return      0 on success
+  */
+ int VL6180x_Prepare(VL6180xDev_t dev);
  
+ /** @}  */
+ 
+
+/** @defgroup api_hl_range Ranging functions
+ *  @brief    Ranging functions
+ *  @ingroup api_hl
+ *  @{  
+ */
+ 
+ /**
+ * @brief Start continuous ranging mode
+ *
+ * @details End user should ensure device is in idle state and not already running
+ */
+int VL6180x_RangeStartContinuousMode(VL6180xDev_t dev);
+
+/**
+ * @brief Start single shot ranging measure
+ *
+ * @details End user should ensure device is in idle state and not already running
+ */
+int VL6180x_RangeStartSingleShot(VL6180xDev_t dev);
+
+/**
+ * @brief Set maximum convergence time
+ *
+ * @par Function Description
+ * Setting a low convergence time can impact maximal detectable distance.
+ * Refer to VL6180x Datasheet Table 7 : Typical range convergence time.
+ * A typical value for up to x3 scaling is 50 ms
+ *
+ * @param dev
+ * @param MaxConTime_msec
+ * @return 0 on success. <0 on error. >0 for calibration warning status
+ */
+int VL6180x_RangeSetMaxConvergenceTime(VL6180xDev_t dev, uint8_t  MaxConTime_msec);
+ 
+/**
+  * @brief Single shot Range measurement in polling mode.
+  *
+  * @par Function Description
+  * Kick off a new single shot range  then wait for ready to retrieve it by polling interrupt status \n
+  * Ranging must be prepared by a first call to  @a VL6180x_Prepare() and it is safer to clear  very first poll call \n
+  * This function reference VL6180x_PollDelay(dev) porting macro/call on each polling loop,
+  * but PollDelay(dev) may never be called if measure in ready on first poll loop \n
+  * Should not be use in continuous mode operation as it will stop it and cause stop/start misbehaviour \n
+  * \n This function clears Range Interrupt status , but not error one. For that uses  @a VL6180x_ClearErrorInterrupt() \n
+  * This range error is not related VL6180x_RangeData_t::errorStatus that refer measure status \n
+  * 
+  * @param dev          The device
+  * @param pRangeData   Will be populated with the result ranging data @a  VL6180x_RangeData_t
+  * @return 0 on success , @a #RANGE_ERROR if device reports an error case in it status (not cleared) use
+  *
+  * \sa ::VL6180x_RangeData_t
+  */
+int VL6180x_RangePollMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
+
+/**
+ * @brief Check for measure readiness and get it if ready
+ *
+ * @par Function Description
+ * Using this function is an alternative to @a VL6180x_RangePollMeasurement() to avoid polling operation. This is suitable for applications
+ * where host CPU is triggered on a interrupt (not from VL6180X) to perform ranging operation. In this scenario, we assume that the very first ranging
+ * operation is triggered by a call to @a VL6180x_RangeStartSingleShot(). Then, host CPU regularly calls @a VL6180x_RangeGetMeasurementIfReady() to
+ * get a distance measure if ready. In case the distance is not ready, host may get it at the next call.\n
+ *
+ * @warning 
+ * This function does not re-start a new measurement : this is up to the host CPU to do it.\n 
+ * This function clears Range Interrupt for measure ready , but not error interrupts. For that, uses  @a VL6180x_ClearErrorInterrupt() \n
+ *
+ * @param dev  The device
+ * @param pRangeData  Will be populated with the result ranging data if available
+ * @return  0 when measure is ready pRange data is updated (untouched when not ready),  >0 for warning and @a #NOT_READY if measurement not yet ready, <0 for error @a #RANGE_ERROR if device report an error,
+ */
+int VL6180x_RangeGetMeasurementIfReady(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
+
+/**
+ * @brief Retrieve range measurements set  from device
+ *
+ * @par Function Description
+ * The measurement is made of range_mm status and error code @a VL6180x_RangeData_t \n
+ * Based on configuration selected extra measures are included.
+ *
+ * @warning should not be used in continuous if wrap around filter is active \n
+ * Does not perform any wait nor check for result availability or validity.
+ *\sa VL6180x_RangeGetResult for "range only" measurement
+ *
+ * @param dev         The device
+ * @param pRangeData  Pointer to the data structure to fill up
+ * @return            0 on success
+ */
+int VL6180x_RangeGetMeasurement(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData);
+
+/**
+ * @brief Get ranging result and only that
+ *
+ * @par Function Description
+ * Unlike @a VL6180x_RangeGetMeasurement() this function only retrieves the range in millimeter \n
+ * It does any required up-scale translation\n
+ * It can be called after success status polling or in interrupt mode \n
+ * @warning these function is not doing wrap around filtering \n
+ * This function doesn't perform any data ready check!
+ *
+ * @param dev        The device
+ * @param pRange_mm  Pointer to range distance
+ * @return           0 on success
+ */
+int VL6180x_RangeGetResult(VL6180xDev_t dev, int32_t *pRange_mm);
+
+/**
+ * @brief Configure ranging interrupt reported to application
+ *
+ * @param dev            The device
+ * @param ConfigGpioInt  Select ranging report\n select one (and only one) of:\n
+ *   @a #CONFIG_GPIO_INTERRUPT_DISABLED \n
+ *   @a #CONFIG_GPIO_INTERRUPT_LEVEL_LOW \n
+ *   @a #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH \n
+ *   @a #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW \n
+ *   @a #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY
+ * @return   0 on success
+ */
+int VL6180x_RangeConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt);
+
+
+/**
+ * @brief Clear range interrupt
+ *
+ * @param dev    The device
+ * @return  0    On success
+ */
+#define VL6180x_RangeClearInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_RANGING)
+
+/**
+ * @brief Return ranging error interrupt status
+ *
+ * @par Function Description
+ * Appropriate Interrupt report must have been selected first by @a VL6180x_RangeConfigInterrupt() or @a  VL6180x_Prepare() \n
+ *
+ * Can be used in polling loop to wait for a given ranging event or in interrupt to read the trigger \n
+ * Events triggers are : \n
+ * @a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n
+ * @a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n
+ * @a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n (RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD|RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD)
+ * @a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY \n
+ *
+ * @sa IntrStatus_t
+ * @param dev        The device
+ * @param pIntStatus Pointer to status variable to update
+ * @return           0 on success
+ */
+int VL6180x_RangeGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus);
+
+#if VL6180x_RANGE_STATUS_ERRSTRING
+
+extern const char * ROMABLE_DATA VL6180x_RangeStatusErrString[];
+/**
+ * @brief Human readable error string for range error status
+ *
+ * @param RangeErrCode  The error code as stored on @a VL6180x_RangeData_t::errorStatus
+ * @return  error string , NULL for invalid RangeErrCode
+ * @sa ::RangeError_u
+ */
+const char * VL6180x_RangeGetStatusErrString(uint8_t RangeErrCode);
+#else
+#define VL6180x_RangeGetStatusErrString(...) NULL
+#endif
+
+/** @}  */
+
+#if VL6180x_ALS_SUPPORT
+
+/** @defgroup api_hl_als ALS functions
+ *  @brief    ALS functions
+ *  @ingroup api_hl
+ *  @{  
+ */
+
+/**
+ * @brief   Run a single ALS measurement in single shot polling mode
+ *
+ * @par Function Description
+ * Kick off a new single shot ALS then wait new measurement ready to retrieve it ( polling system interrupt status register for als) \n
+ * ALS must be prepared by a first call to @a VL6180x_Prepare() \n
+ * \n Should not be used in continuous or interrupt mode it will break it and create hazard in start/stop \n
+ *
+ * @param dev          The device
+ * @param pAlsData     Als data structure to fill up @a VL6180x_AlsData_t
+ * @return             0 on success
+ */
+int VL6180x_AlsPollMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData);
+
+
+/**
+ * @brief  Get actual ALS measurement
+ *
+ * @par Function Description
+ * Can be called after success status polling or in interrupt mode to retrieve ALS measurement from device \n
+ * This function doesn't perform any data ready check !
+ *
+ * @param dev        The device
+ * @param pAlsData   Pointer to measurement struct @a VL6180x_AlsData_t
+ * @return  0 on success
+ */
+int VL6180x_AlsGetMeasurement(VL6180xDev_t dev, VL6180x_AlsData_t *pAlsData);
+
+/**
+ * @brief  Configure ALS interrupts provide to application
+ *
+ * @param dev            The Device
+ * @param ConfigGpioInt  Select one (and only one) of : \n
+ *   @a #CONFIG_GPIO_INTERRUPT_DISABLED \n
+ *   @a #CONFIG_GPIO_INTERRUPT_LEVEL_LOW \n
+ *   @a #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH \n
+ *   @a #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW \n
+ *   @a #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY
+ * @return               0 on success may return #INVALID_PARAMS for invalid mode
+ */
+int VL6180x_AlsConfigInterrupt(VL6180xDev_t dev, uint8_t ConfigGpioInt);
+
+
+/**
+ * @brief Set ALS integration period
+ *
+ * @param dev        The device
+ * @param period_ms  Integration period in msec. Value in between 50 to 100 msec is recommended\n
+ * @return           0 on success
+ */
+int VL6180x_AlsSetIntegrationPeriod(VL6180xDev_t dev, uint16_t period_ms);
+
+/**
+ * @brief Set ALS "inter-measurement period"
+ *
+ * @par Function Description
+ * The so call data-sheet "inter measurement period" is actually an extra inter-measurement delay
+ *
+ * @param dev        The device
+ * @param intermeasurement_period_ms Inter measurement time in milli second\n
+ *        @warning applied value is clipped to 2550 ms\n
+ * @return           0 on success if value is
+ */
+int VL6180x_AlsSetInterMeasurementPeriod(VL6180xDev_t dev,  uint16_t intermeasurement_period_ms);
+
+/**
+ * @brief Set ALS analog gain code
+ *
+ * @par Function Description
+ * ALS gain code value programmed in @a SYSALS_ANALOGUE_GAIN .
+ * @param dev   The device
+ * @param gain  Gain code see datasheet or AlsGainLookUp for real value. Value is clipped to 7.
+ * @return  0 on success
+ */
+ 
+int VL6180x_AlsSetAnalogueGain(VL6180xDev_t dev, uint8_t gain);
+/**
+ * @brief Set thresholds for ALS continuous mode 
+ * @warning Threshold are raw device value not lux!
+ *
+ * @par Function Description
+ * Basically value programmed in @a SYSALS_THRESH_LOW and @a SYSALS_THRESH_HIGH registers
+ * @param dev   The device
+ * @param low   ALS low raw threshold for @a SYSALS_THRESH_LOW
+ * @param high  ALS high raw threshold for  @a SYSALS_THRESH_HIGH
+ * @return  0 on success
+ */
+int VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high);
+
+/**
+ * @brief  Clear ALS interrupt
+ *
+ * @param dev    The device
+ * @return  0    On success
+ */
+ #define VL6180x_AlsClearInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_ALS)
+ 
+/**
+ * Read ALS interrupt status
+ * @param dev         Device
+ * @param pIntStatus  Pointer to status
+ * @return            0 on success
+ */
+int VL6180x_AlsGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus);
+ 
+/** @}  */
+#endif
+
+/** @defgroup api_ll_init Init functions
+ *  @brief    Init functions
+ *  @ingroup api_ll
+ *  @{  
+ */
+ 
+/**
+ * @brief Low level ranging and ALS register static settings (you should call @a VL6180x_Prepare() function instead)
+ *
+ * @param dev
+ * @return 0 on success
+ */
+int VL6180x_StaticInit(VL6180xDev_t dev);
+ 
+ /** @}  */
+ 
+/** @defgroup api_ll_range Ranging functions
+ *  @brief    Ranging Low Level functions
+ *  @ingroup api_ll
+ *  @{  
+ */
+
+/**
+ * @brief Wait for device to be ready (before a new ranging command can be issued by application)
+ * @param dev        The device
+ * @param MaxLoop    Max Number of i2c polling loop see @a #msec_2_i2cloop
+ * @return           0 on success. <0 when fail \n
+ *                   @ref VL6180x_ErrCode_t::TIME_OUT for time out \n
+ *                   @ref VL6180x_ErrCode_t::INVALID_PARAMS if MaxLop<1
+ */
+int VL6180x_RangeWaitDeviceReady(VL6180xDev_t dev, int MaxLoop );
+
+/**
+ * @brief Program Inter measurement period (used only in continuous mode)
+ *
+ * @par Function Description
+ * When trying to set too long time, it returns #INVALID_PARAMS
+ *
+ * @param dev     The device
+ * @param InterMeasTime_msec Requires inter-measurement time in msec
+ * @return 0 on success
+ */
+int VL6180x_RangeSetInterMeasPeriod(VL6180xDev_t dev, uint32_t  InterMeasTime_msec);
+
+
+/**
+ * @brief Set device ranging scaling factor
+ *
+ * @par Function Description
+ * The ranging scaling factor is applied on the raw distance measured by the device to increase operating ranging at the price of the precision.
+ * Changing the scaling factor when device is not in f/w standby state (free running) is not safe.
+ * It can be source of spurious interrupt, wrongly scaled range etc ...
+ * @warning __This  function doesns't update high/low threshold and other programmed settings linked to scaling factor__.
+ *  To ensure proper operation, threshold and scaling changes should be done following this procedure: \n
+ *  @li Set Group hold  : @a VL6180x_SetGroupParamHold() \n
+ *  @li Get Threshold @a VL6180x_RangeGetThresholds() \n
+ *  @li Change scaling : @a VL6180x_UpscaleSetScaling() \n
+ *  @li Set Threshold : @a VL6180x_RangeSetThresholds() \n
+ *  @li Unset Group Hold : @a VL6180x_SetGroupParamHold()
+ *
+ * @param dev      The device
+ * @param scaling  Scaling factor to apply (1,2 or 3)
+ * @return          0 on success when up-scale support is not configured it fail for any
+ *                  scaling than the one statically configured.
+ */
+int VL6180x_UpscaleSetScaling(VL6180xDev_t dev, uint8_t scaling);
+
+/**
+ * @brief Get current ranging scaling factor
+ *
+ * @param dev The device
+ * @return    The current scaling factor
+ */
+int VL6180x_UpscaleGetScaling(VL6180xDev_t dev);
+
+
+/**
+ * @brief Give filtered state (wrap-around filter) of a range measurement
+ * @param pRangeData  Range measurement data
+ * @return  0 means measure was not filtered,  when not 0 range from device got filtered by filter post processing
+ */
+#define VL6180x_RangeIsFilteredMeasurement(pRangeData) ((pRangeData)->errorStatus == RangingFiltered)
+
+/**
+ * @brief Get the maximal distance for actual scaling
+ * @par Function Description
+ * Do not use prior to @a VL6180x_Prepare() or at least @a VL6180x_InitData()
+ *
+ * Any range value more than the value returned by this function is to be considered as "no target detected"
+ * or "no target in detectable range" \n
+ * @warning The maximal distance depends on the scaling
+ *
+ * @param dev The device
+ * @return    The maximal range limit for actual mode and scaling
+ */
+uint16_t VL6180x_GetUpperLimit(VL6180xDev_t dev);
+
+/**
+ * @brief Apply low and high ranging thresholds that are considered only in continuous mode
+ *
+ * @par Function Description
+ * This function programs low and high ranging thresholds that are considered in continuous mode : 
+ * interrupt will be raised only when an object is detected at a distance inside this [low:high] range.  
+ * The function takes care of applying current scaling factor if any.\n
+ * To be safe, in continuous operation, thresholds must be changed under "group parameter hold" cover.
+ * Group hold can be activated/deactivated directly in the function or externally (then set 0)
+ * using /a VL6180x_SetGroupParamHold() function.
+ *
+ * @param dev      The device
+ * @param low      Low threshold in mm
+ * @param high     High threshold in mm
+ * @param SafeHold  Use of group parameters hold to surround threshold programming.
+ * @return  0 On success
+ */
+int VL6180x_RangeSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high, int SafeHold);
+
+/**
+ * @brief  Get scaled high and low threshold from device
+ *
+ * @par Function Description
+ * Due to scaling factor, the returned value may be different from what has been programmed first (precision lost).
+ * For instance VL6180x_RangeSetThresholds(dev,11,22) with scale 3
+ * will read back 9 ((11/3)x3) and 21 ((22/3)x3).
+
+ * @param dev  The device
+ * @param low  scaled low Threshold ptr  can be NULL if not needed
+ * @param high scaled High Threshold ptr can be NULL if not needed
+ * @return 0 on success, return value is undefined if both low and high are NULL
+ * @warning return value is undefined if both low and high are NULL
+ */
+int VL6180x_RangeGetThresholds(VL6180xDev_t dev, uint16_t *low, uint16_t *high);
+
+/**
+ * @brief Set ranging raw thresholds (scaling not considered so not recommended to use it)
+ *
+ * @param dev  The device
+ * @param low  raw low threshold set to raw register
+ * @param high raw high threshold set to raw  register
+ * @return 0 on success
+ */
+int VL6180x_RangeSetRawThresholds(VL6180xDev_t dev, uint8_t low, uint8_t high);
+
+/**
+ * @brief Set Early Convergence Estimate ratio
+ * @par Function Description
+ * For more information on ECE check datasheet
+ * @warning May return a calibration warning in some use cases
+ *
+ * @param dev        The device
+ * @param FactorM    ECE factor M in M/D
+ * @param FactorD    ECE factor D in M/D
+ * @return           0 on success. <0 on error. >0 on warning
+ */
+int VL6180x_RangeSetEceFactor(VL6180xDev_t dev, uint16_t  FactorM, uint16_t FactorD);
+
+/**
+ * @brief Set Early Convergence Estimate state (See #SYSRANGE_RANGE_CHECK_ENABLES register)
+ * @param dev       The device
+ * @param enable    State to be set 0=disabled, otherwise enabled
+ * @return          0 on success
+ */
+int VL6180x_RangeSetEceState(VL6180xDev_t dev, int enable );
+
+/**
+ * @brief Set activation state of the wrap around filter
+ * @param dev   The device
+ * @param state New activation state (0=off,  otherwise on)
+ * @return      0 on success
+ */
+int VL6180x_FilterSetState(VL6180xDev_t dev, int state);
+
+/**
+ * Get activation state of the wrap around filter
+ * @param dev  The device
+ * @return     Filter enabled or not, when filter is not supported it always returns 0S
+ */
+int VL6180x_FilterGetState(VL6180xDev_t dev);
+
+
+/**
+ * @brief Set activation state of  DMax computation
+ * @param dev   The device
+ * @param state New activation state (0=off,  otherwise on)
+ * @return      0 on success
+ */
+int VL6180x_DMaxSetState(VL6180xDev_t dev, int state);
+
+/**
+ * Get activation state of DMax computation
+ * @param dev  The device
+ * @return     Filter enabled or not, when filter is not supported it always returns 0S
+ */
+int VL6180x_DMaxGetState(VL6180xDev_t dev);
+
+
+/**
+ * @brief Set ranging mode and start/stop measure (use high level functions instead : @a VL6180x_RangeStartSingleShot() or @a VL6180x_RangeStartContinuousMode())
+ *
+ * @par Function Description
+ * When used outside scope of known polling single shot stopped state, \n
+ * user must ensure the device state is "idle" before to issue a new command.
+ *
+ * @param dev   The device
+ * @param mode  A combination of working mode (#MODE_SINGLESHOT or #MODE_CONTINUOUS) and start/stop condition (#MODE_START_STOP) \n
+ * @return      0 on success
+ */
+int VL6180x_RangeSetSystemMode(VL6180xDev_t dev, uint8_t mode);
+ 
+/** @}  */ 
+
+/** @defgroup api_ll_range_calibration Ranging calibration functions
+ *  @brief    Ranging calibration functions
+ *  @ingroup api_ll
+ *  @{  
+ */
+/**
+ * @brief Get part to part calibration offset
+ *
+ * @par Function Description
+ * Should only be used after a successful call to @a VL6180x_InitData to backup device nvm value
+ *
+ * @param dev  The device
+ * @return part to part calibration offset from device
+ */
+int8_t VL6180x_GetOffsetCalibrationData(VL6180xDev_t dev);
+
+/**
+ * Set or over-write part to part calibration offset
+ * \sa VL6180x_InitData(), VL6180x_GetOffsetCalibrationData()
+ * @param dev     The device
+ * @param offset   Offset
+ */
+void VL6180x_SetOffsetCalibrationData(VL6180xDev_t dev, int8_t offset);
+
+/**
+ * @brief Set Cross talk compensation rate
+ *
+ * @par Function Description
+ * It programs register @a #SYSRANGE_CROSSTALK_COMPENSATION_RATE
+ *
+ * @param dev  The device
+ * @param Rate Compensation rate (9.7 fix point) see datasheet for details
+ * @return     0 on success
+ */
+int  VL6180x_SetXTalkCompensationRate(VL6180xDev_t dev, FixPoint97_t Rate);
+
+/** @}  */
+
+
+
+#if VL6180x_ALS_SUPPORT
+/** @defgroup api_ll_als ALS functions
+ *  @brief    ALS functions
+ *  @ingroup api_ll
+ *  @{  
+ */
+
+/**
+ * @brief Wait for device to be ready for new als operation or max pollign loop (time out)
+ * @param dev        The device
+ * @param MaxLoop    Max Number of i2c polling loop see @a #msec_2_i2cloop
+ * @return           0 on success. <0 when @a VL6180x_ErrCode_t::TIME_OUT if timed out
+ */
+int VL6180x_AlsWaitDeviceReady(VL6180xDev_t dev, int MaxLoop );
+
+/**
+ * @brief Set ALS system mode and start/stop measure
+ *
+ * @warning When used outside after single shot polling, \n
+ * User must ensure  the device state is ready before issuing a new command (using @a VL6180x_AlsWaitDeviceReady()). \n
+ * Non respect of this, can cause loss of interrupt or device hanging.
+ *
+ * @param dev   The device
+ * @param mode  A combination of working mode (#MODE_SINGLESHOT or #MODE_CONTINUOUS) and start condition (#MODE_START_STOP) \n
+ * @return      0 on success
+ */
+int VL6180x_AlsSetSystemMode(VL6180xDev_t dev, uint8_t mode); 
+
+/** @}  */ 
+#endif 
+
+/** @defgroup api_ll_misc Misc functions
+ *  @brief    Misc functions
+ *  @ingroup api_ll
+ *  @{  
+ */
+
+/**
+ * Set Group parameter Hold state
+ *
+ * @par Function Description
+ * Group parameter holds @a #SYSTEM_GROUPED_PARAMETER_HOLD enable safe update (non atomic across multiple measure) by host
+ * \n The critical register group is composed of: \n
+ * #SYSTEM_INTERRUPT_CONFIG_GPIO \n
+ * #SYSRANGE_THRESH_HIGH \n
+ * #SYSRANGE_THRESH_LOW \n
+ * #SYSALS_INTEGRATION_PERIOD \n
+ * #SYSALS_ANALOGUE_GAIN \n
+ * #SYSALS_THRESH_HIGH \n
+ * #SYSALS_THRESH_LOW
+ *
+ *
+ * @param dev   The device
+ * @param Hold  Group parameter Hold state to be set (on/off)
+ * @return      0 on success
+ */
+int VL6180x_SetGroupParamHold(VL6180xDev_t dev, int Hold);
+
+/**
+ * @brief Set new device i2c address
+ *
+ * After completion the device will answer to the new address programmed.
+ *
+ * @sa AN4478: Using multiple VL6180X's in a single design
+ * @param dev       The device
+ * @param NewAddr   The new i2c address (7bit)
+ * @return          0 on success
+ */
+int VL6180x_SetI2CAddress(VL6180xDev_t dev, uint8_t NewAddr);
+
+/**
+ * @brief Fully configure gpio 0/1 pin : polarity and functionality
+ *
+ * @param dev          The device
+ * @param pin          gpio pin 0 or 1
+ * @param IntFunction  Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
+ * @param ActiveHigh   Set active high polarity, or active low see @a ::IntrPol_e
+ * @return             0 on success
+ */
+int VL6180x_SetupGPIOx(VL6180xDev_t dev, int pin, uint8_t IntFunction, int ActiveHigh);
+
+
+/**
+ * @brief Set interrupt pin polarity for the given GPIO
+ *
+ * @param dev          The device
+ * @param pin          Pin 0 or 1
+ * @param active_high  select active high or low polarity using @ref IntrPol_e
+ * @return             0 on success
+ */
+int VL6180x_SetGPIOxPolarity(VL6180xDev_t dev, int pin, int active_high);
+
+/**
+ * Select interrupt functionality for the given GPIO
+ *
+ * @par Function Description
+ * Functionality refer to @a SYSTEM_MODE_GPIO0
+ *
+ * @param dev            The device
+ * @param pin            Pin to configure 0 or 1 (gpio0 or gpio1)\nNote that gpio0 is chip enable at power up !
+ * @param functionality  Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
+ * @return              0 on success
+ */
+int VL6180x_SetGPIOxFunctionality(VL6180xDev_t dev, int pin, uint8_t functionality);
+
+/**
+ * #brief Disable and turn to Hi-Z gpio output pin
+ *
+ * @param dev  The device
+ * @param pin  The pin number to disable 0 or 1
+ * @return     0 on success
+ */
+int VL6180x_DisableGPIOxOut(VL6180xDev_t dev, int pin);
+
+/**
+ * @def msec_2_i2cloop
+ * @brief  Number of I2C polling loop (an 8 bit register) to run for maximal wait time.
+ *
+ * @par Function Description
+ * When polling via I2C the overall time is mainly the I2C transaction time because it is a slow bus
+ *   one 8 bit register poll on I2C bus timing is shown below: \n
+ *   start + addr_w(a)  + 2x8bit index(a)  + stop  + start  + addr_rd(a)  + 1x8bit data_rd(a) + stop \n
+ *   1        8   1        2*(8+1)           1       1          8     1        8           1    1 \n
+ *  so 49 serial bits
+ *
+ * @param  time_ms  Time to wait in milli second 10
+ * @param  i2c_khz  I2C bus frequencies in KHz  for instance 400
+ * @return The number of loops (at least 1)
+ */
+#define msec_2_i2cloop( time_ms, i2c_khz )  (((time_ms)*(i2c_khz)/49)+1)
+
+/** @}  */
+
+
+
+/**
+ * polarity use in @a VL6180x_SetupGPIOx() , @a VL6180x_SetupGPIO1()
+ */
+typedef enum  {
+    INTR_POL_LOW        =0, /*!< set active low polarity best setup for falling edge */
+    INTR_POL_HIGH       =1, /*!< set active high polarity best setup for rising edge */
+}IntrPol_e;
+
+/** @defgroup api_ll_intr Interrupts management functions
+ *  @brief    Interrupts management functions
+ *  @ingroup api_ll
+ *  @{  
+ */
+
+/**
+ * @brief     Get all interrupts cause
+ *
+ * @param dev    The device
+ * @param status Ptr to interrupt status. You can use @a IntrStatus_t::val
+ * @return 0 on success
+ */
+int VL6180x_GetInterruptStatus(VL6180xDev_t dev, uint8_t *status);
+
+/**
+ * @brief Clear given system interrupt condition
+ *
+ * @par Function Description
+ * Clear given interrupt cause by writing into register #SYSTEM_INTERRUPT_CLEAR register.
+ * @param dev       The device 
+ * @param IntClear  Which interrupt source to clear. Use any combinations of #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ALS , #INTERRUPT_CLEAR_ERROR.
+ * @return  0       On success
+ */
+int VL6180x_ClearInterrupt(VL6180xDev_t dev, uint8_t IntClear );
+
+/**
+ * @brief Clear error interrupt
+ *
+ * @param dev    The device
+ * @return  0    On success
+ */
+ #define VL6180x_ClearErrorInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR)
+
+/**
+ * @brief Clear All interrupt causes (als+range+error)
+ *
+ * @param dev    The device
+ * @return  0    On success
+ */
+#define VL6180x_ClearAllInterrupt(dev) VL6180x_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR|INTERRUPT_CLEAR_RANGING|INTERRUPT_CLEAR_ALS)
+
+/** @}  */
+
+
+/** @defgroup api_reg API Register access functions
+ *  @brief    Registers access functions called by API core functions
+ *  @ingroup api_ll
+ *  @{  
+ */
+
+/**
+ * Write VL6180x single byte register
+ * @param dev   The device
+ * @param index The register index
+ * @param data  8 bit register data
+ * @return success
+ */
+int VL6180x_WrByte(VL6180xDev_t dev, uint16_t index, uint8_t data);
+/**
+ * Thread safe VL6180x Update (rd/modify/write) single byte register
+ *
+ * Final_reg = (Initial_reg & and_data) |or_data
+ *
+ * @param dev   The device
+ * @param index The register index
+ * @param AndData  8 bit and data
+ * @param OrData   8 bit or data
+ * @return 0 on success
+ */
+int VL6180x_UpdateByte(VL6180xDev_t dev, uint16_t index, uint8_t AndData, uint8_t OrData);
+/**
+ * Write VL6180x word register
+ * @param dev   The device
+ * @param index The register index
+ * @param data  16 bit register data
+ * @return  0 on success
+ */
+int VL6180x_WrWord(VL6180xDev_t dev, uint16_t index, uint16_t data);
+/**
+ * Write VL6180x double word (4 byte) register
+ * @param dev   The device
+ * @param index The register index
+ * @param data  32 bit register data
+ * @return  0 on success
+ */
+int VL6180x_WrDWord(VL6180xDev_t dev, uint16_t index, uint32_t data);
+
+/**
+ * Read VL6180x single byte register
+ * @param dev   The device
+ * @param index The register index
+ * @param data  pointer to 8 bit data
+ * @return 0 on success
+ */
+int VL6180x_RdByte(VL6180xDev_t dev, uint16_t index, uint8_t *data);
+
+/**
+ * Read VL6180x word (2byte) register
+ * @param dev   The device
+ * @param index The register index
+ * @param data  pointer to 16 bit data
+ * @return 0 on success
+ */
+int VL6180x_RdWord(VL6180xDev_t dev, uint16_t index, uint16_t *data);
+
+/**
+ * Read VL6180x dword (4byte) register
+ * @param dev   The device
+ * @param index The register index
+ * @param data  pointer to 32 bit data
+ * @return 0 on success
+ */
+int VL6180x_RdDWord(VL6180xDev_t dev, uint16_t index, uint32_t *data);
+
+/** @}  */
+
+
+
 
 #ifdef __cplusplus
 }
--- a/Components/VL6180X/vl6180x_class.cpp	Tue Sep 29 15:40:08 2015 +0200
+++ b/Components/VL6180X/vl6180x_class.cpp	Tue Oct 06 09:03:10 2015 +0200
@@ -142,6 +142,11 @@
 /** 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 */
@@ -221,6 +226,30 @@
     #define _SetUpscale(dev, Scaling ) VL6180xDevDataSet(dev, UpscaleFactor, Scaling)
 #endif
 
+
+#if VL6180x_SINGLE_DEVICE_DRIVER
+/**
+ * the unique driver data  When single device driver is active
+ */
+struct VL6180xDevData_t VL6180x_DEV_DATA_ATTR  SingleVL6180xDevData={
+        .EceFactorM        = DEF_ECE_FACTOR_M,
+        .EceFactorD        = DEF_ECE_FACTOR_D,
+#ifdef VL6180x_HAVE_UPSCALE_DATA
+        .UpscaleFactor     = DEF_UPSCALE,
+#endif
+#ifdef VL6180x_HAVE_ALS_DATA
+        .IntegrationPeriod = DEF_INT_PEFRIOD,
+        .AlsGainCode       = DEF_ALS_GAIN,
+        .AlsScaler         = DEF_ALS_SCALER,
+#endif
+#ifdef VL6180x_HAVE_DMAX_RANGING
+        .DMaxEnable =   DEF_DMAX_ENABLE,
+#endif
+};
+#endif /* VL6180x_SINGLE_DEVICE_DRIVER */
+
+
+
 #define Fix7_2_KCPs(x) ((((uint32_t)(x))*1000)>>7)
 
 
@@ -382,7 +411,6 @@
     if( status ){
         VL6180x_ErrLog("new i2c addr Wr fail");
     }
-		DevData.I2cAddr = NewAddress;
     LOG_FUNCTION_END(status);
     return status;
 }
@@ -966,7 +994,7 @@
 
     status = VL6180x_RdByte(dev, RESULT_RANGE_VAL, &RawRange);
     if( !status ){
-        Upscale = _GetUpscale(dev);
+         Upscale = _GetUpscale(dev);
         *pRange_mm= Upscale*(int32_t)RawRange;
     }
     LOG_FUNCTION_END_FMT(status, "%d", (int)*pRange_mm);
@@ -2486,21 +2514,21 @@
 {
     int  status;
 
-    status=VL6180x_I2CWrite(dev.I2cAddr, index, &data,(uint8_t)1);
+    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(dev.I2cAddr, index, (uint8_t *)&data,(uint8_t)2);
+    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(dev.I2cAddr, index, (uint8_t *)&data,(uint8_t)4);
+	  status=VL6180x_I2CWrite(Device->I2cAddr, index, (uint8_t *)&data,(uint8_t)4);
     return status;
 }
 
@@ -2508,9 +2536,10 @@
 {
     int  status;
     uint8_t buffer;
-    status=VL6180x_I2CRead(dev.I2cAddr, index, &buffer,1);
-    if( !status ){
-        *data=buffer;
+    status=VL6180x_I2CRead(Device->I2cAddr, index, &buffer,1);
+    if( !status )
+		{
+       *data=buffer;
     }
     return status;
 }
@@ -2519,7 +2548,11 @@
 {
     int  status;
     uint8_t buffer[2];
-    status=VL6180x_I2CRead(dev.I2cAddr, index, buffer, 2);
+    status=VL6180x_I2CRead(Device->I2cAddr, index, buffer, 2);
+	  if( !status )
+		{
+       memcpy(data, buffer, 2);
+    }
     return status;
 }
 
@@ -2527,8 +2560,11 @@
 {
     int status;
     uint8_t buffer[4];
-    
-    status=VL6180x_I2CRead(dev.I2cAddr, index, buffer,4);
+    status=VL6180x_I2CRead(Device->I2cAddr, index, buffer,4);
+	  if( !status )
+		{
+       memcpy(data, buffer, 4);
+    }
     return status;
 }
 
@@ -2537,13 +2573,13 @@
     int  status;
     uint8_t buffer;
 
-    status=VL6180x_I2CWrite(dev.I2cAddr, index, (uint8_t *)buffer,(uint8_t)0);
+    status=VL6180x_I2CWrite(Device->I2cAddr, index, (uint8_t *)buffer,(uint8_t)0);
     if( !status ){
         /* read data direct onto buffer */
-        status=VL6180x_I2CRead(dev.I2cAddr, index, &buffer,1);
+        status=VL6180x_I2CRead(Device->I2cAddr, index, &buffer,1);
         if( !status ){
             buffer=(buffer & AndData)|OrData;
-            status=VL6180x_I2CWrite(dev.I2cAddr, index, &buffer, (uint8_t)1);
+            status=VL6180x_I2CWrite(Device->I2cAddr, index, &buffer, (uint8_t)1);
         }
     }
 
@@ -2569,7 +2605,7 @@
     {
     	  for(i=0;i<NumByteToWrite;i++)
     	  {
-    	  	 tmp[NumByteToWrite+sizeof(RegisterAddr)-i]=pBuffer[i];
+    	  	 tmp[NumByteToWrite+sizeof(RegisterAddr)-1-i]=pBuffer[i];
     	  }
     }
 		else
@@ -2605,23 +2641,29 @@
 		
     if(NumByteToRead>1)  /* swap data endianess */
     {
-    	  for(i=0;i<NumByteToRead;i++)
-    	  {		
-			pBuffer[i] = tmp[NumByteToRead-1-i];
-    	  }
+    	 for(i=0;i<NumByteToRead;i++)
+    	 {		
+			    pBuffer[i] = tmp[NumByteToRead-1-i];
+    	 }
     }
-	else
-	{  	 
-        memcpy(pBuffer, tmp, NumByteToRead);
+	  else
+	  {  	 
+       memcpy(pBuffer, tmp, NumByteToRead);
     }		
     return 0;
 } 
 
-int VL6180X::VL6180X_ReadID()
+
+int VL6180X::ReadID()
 {
-	uint8_t rd_id;
-	VL6180x_RdByte( DevData, IDENTIFICATION_MODEL_ID, &rd_id);
-	return rd_id;
+	 int status;
+	 uint8_t rl_id;
+	
+	 status=VL6180x_RdByte( Device, IDENTIFICATION_MODEL_ID, &rl_id);
+	 if((status==0)&&(rl_id==0xB4))
+		  return status;
+	 else
+		  return INVALID_PARAMS;
 }
 
 
--- a/Components/VL6180X/vl6180x_class.h	Tue Sep 29 15:40:08 2015 +0200
+++ b/Components/VL6180X/vl6180x_class.h	Tue Oct 06 09:03:10 2015 +0200
@@ -41,11 +41,11 @@
 /* Includes ------------------------------------------------------------------*/
 #include "RangeSensor.h"
 #include "LightSensor.h"
-#include "DevI2C.h" //temporaneo fino alla creazione della classe x_nucleo_6180xa1
-//#include "vl6180x_api.h"
-//#include "vl6180x_cfg.h"
-//#include "vl6180x_def.h"
-//#include "vl6180x_types.h"
+#include "DevI2C.h" 
+#include "vl6180x_api.h"
+#include "vl6180x_cfg.h"
+#include "vl6180x_def.h"
+#include "vl6180x_types.h"
 #include "vl6180x_platform.h"
 //#include "vl6180x_appcfg.h"
 #include "STMPE1600_class.h"
@@ -56,6 +56,7 @@
 /* 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:
@@ -65,24 +66,24 @@
      * @param[in] device address, 0x29 by default 
      * @param[in] device id, 0 by default
      */
-
-		 
-		 VL6180X(DevI2C &i2c, DigitalOut &pin, 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)
 		 {
-//		    MyDeviceAddress=DevAddr;
-				DevData.I2cAddr = DevAddr;
-        DevData.Present=0;
-        DevData.Ready=0;
-				expgpio0 = NULL;
+			  MyDevice.I2cAddr=DevAddr;		 
+        MyDevice.Present=0;
+        MyDevice.Ready=0;
+        Device=&MyDevice;;
+				expgpio0=NULL;
+			  //free_fall=new InterruptIn(pin_gpio1);
 		 }  
-		 
-     VL6180X(DevI2C &i2c, STMPE1600DigiOut &pin, 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)
 		 {
-//		    MyDeviceAddress=DevAddr;
-				DevData.I2cAddr = DevAddr;		 
-        DevData.Present=0;
-        DevData.Ready=0;
-				gpio0 = NULL;			 
+			  MyDevice.I2cAddr=DevAddr;		 
+        MyDevice.Present=0;
+        MyDevice.Ready=0;
+        Device=&MyDevice;
+			  gpio0=NULL;			 
+        //free_fall=new InterruptIn(pin_gpio1);			 
 		 }  
 		 
     
@@ -100,46 +101,110 @@
 			if (gpio0) *gpio0=0;
 			else if (expgpio0) *expgpio0=0;			
 		}
-		//Init sensor accende, legge id, inizializza il dispositivo e prepara per le misure (range, als)
-    //altrimenti errore e cancello dalla board		
-		
-    /*** Interface Methods ***/
-    /*virtual*/ int Init() 
+    
+		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(DevData); // ritorna 0 se corretto 
+       return VL6180x_InitData(Device); // ritorna 0 se corretto 
     }
-    
-    /*virtual*/ int ReadID() 
-    {
-        return VL6180X_ReadID(); // ritorna 0 se corretto e -2 se errore
-    }
-		/*
-
+		
+		int IsPresent()
+		{
+			 int status;
+			
+			 status=ReadID();
+       if(!status)
+				 error("Failed to read ID device! Device not present!\n");
+			 return status;
+		}
+		
 		void SetPresent()
 		{
-			  MyDevice.Present=1;
-		}
-		
-		void SetDeviceID(int n)
-		{
-			  MyDevice.DevID=n;
+			 Device->Present=1;
 		}
 		
 		void SetReady()
 		{
-			  MyDevice.Ready=1;
-		}		
-	   
-    */
-/*		
-    virtual int GetRange(int *piData) {
-        return VL6180X_GetRange(piData);
+			 Device->Ready=1;
+		}
+		
+		int Prepare()
+		{
+			 return VL6180x_Prepare(Device);
+		}
+		
+		int SetI2CAddress(int NewAddr)
+		{
+			 int status;
+			
+			 status=VL6180x_SetI2CAddress(Device, NewAddr);
+			 if(!status)
+				  Device->I2cAddr;
+			 return status;
+		}
+		
+		int StartMeasurement(int operating_mode)
+		{
+		  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);
     }
 
-    virtual int GetLight(int *piData) {
-        return VL6180X_GetLight(piData);
-    }
-*/    
+    int GetLight(int *piData) {
+        return VL6180X_AlsGetMeasurement(piData);
+    }*/
+		
+		int RangePollMeasurement()
+		{
+			 return VL6180x_RangePollMeasurement(Device, &RangeData);
+		}
+		
+		int AlsPollMeasurement()
+		{
+			 return VL6180x_AlsPollMeasurement(Device, &AlsData);
+		}
+		
+		    
 		/* api.c functions */
 		int VL6180x_WaitDeviceBooted(VL6180xDev_t dev);
 		int VL6180x_InitData(VL6180xDev_t dev );
@@ -204,10 +269,8 @@
 		int _GetRateResult(VL6180xDev_t dev, VL6180x_RangeData_t *pRangeData); 
 		int _DMax_InitData(VL6180xDev_t dev);
 		
-    /* Read functions from registers and write functions into registers  */
-    int VL6180X_ReadID();
-    int VL6180X_IO_Read(uint8_t *pBuffer, uint16_t RegisterAddress, uint16_t NumByteToRead);
-		int VL6180X_IO_Write(uint8_t *pBuffer, uint16_t RegisterAddress, uint16_t NumByteToWrite);
+    /* Read function of the ID device */
+    int ReadID();
     
     /* Write and read functions from I2C */
     int VL6180x_WrByte(VL6180xDev_t dev, uint16_t index, uint8_t data);
@@ -220,20 +283,24 @@
     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);
 
-		VL6180xDev_t  DevData;
+		
 
 private:
-    /*** Instance Variables ***/
     /* IO Device */
     DevI2C &dev_i2c;
+    /* Digital out pin */
     DigitalOut *gpio0;
-    STMPE1600DigiOut *expgpio0;  
-
-//		VL6180xDev_t  DevData;
-//    VL6180xDev_t MyDeviceAddress;
-//    unsigned Present;
-//    unsigned Ready;
-    
+    /* GPIO expander */
+    STMPE1600DigiOut *expgpio0;
+    /* Input interrupt */
+    //InterruptIn *free_fall;
+    /* 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/Components/VL6180X/vl6180x_def.h	Tue Sep 29 15:40:08 2015 +0200
+++ b/Components/VL6180X/vl6180x_def.h	Tue Oct 06 09:03:10 2015 +0200
@@ -127,7 +127,7 @@
 
 
 #if VL6180x_WRAP_AROUND_FILTER_SUPPORT || VL6180x_HAVE_DMAX_RANGING
-    #define VL6180x_HAVE_RATE_DATA
+	#define	VL6180x_HAVE_RATE_DATA
 #endif
 
 /** Error and warning code returned by API
@@ -136,7 +136,7 @@
  * positive value  are warning most of time it's ok to continue\n
  */
 enum VL6180x_ErrCode_t{
-    API_NO_ERROR        = 0,
+	API_NO_ERROR        = 0,
     CALIBRATION_WARNING = 1,  /*!< warning invalid calibration data may be in used \a  VL6180x_InitData() \a VL6180x_GetOffsetCalibrationData \a VL6180x_SetOffsetCalibrationData*/
     MIN_CLIPED          = 2,  /*!< warning parameter passed was clipped to min before to be applied */
     NOT_GUARANTEED      = 3,  /*!< Correct operation is not guaranteed typically using extended ranging on vl6180x */
@@ -238,6 +238,13 @@
     int8_t  Part2PartOffsetNVM;     /*!< backed up NVM value */
 };
 
+#if VL6180x_SINGLE_DEVICE_DRIVER
+extern  struct VL6180xDevData_t SingleVL6180xDevData;
+#define VL6180xDevDataGet(dev, field) (SingleVL6180xDevData.field)
+/* is also used as direct accessor like VL6180xDevDataGet(dev, x)++*/
+#define VL6180xDevDataSet(dev, field, data) (SingleVL6180xDevData.field)=(data)
+#endif
+
 
 /**
  * @struct VL6180x_RangeData_t
@@ -327,15 +334,15 @@
 /**
  * The device model ID
  */
-#define IDENTIFICATION_MODEL_ID                 (uint16_t) 0x000
+#define IDENTIFICATION_MODEL_ID                 0x000
 /**
  * Revision identifier of the Device for major change.
  */
-#define IDENTIFICATION_MODULE_REV_MAJOR         (uint16_t) 0x003
+#define IDENTIFICATION_MODULE_REV_MAJOR         0x003
 /**
  * Revision identifier of the Device for minor change.
  */
-#define IDENTIFICATION_MODULE_REV_MINOR         (uint16_t) 0x004
+#define IDENTIFICATION_MODULE_REV_MINOR         0x004
 
 
 /**
@@ -345,7 +352,7 @@
  *  Same definition as #SYSTEM_MODE_GPIO1
  * @ingroup device_regdef
  */
-#define SYSTEM_MODE_GPIO0                       (uint16_t) 0x010
+#define SYSTEM_MODE_GPIO0                       0x010
 /**
  * @def SYSTEM_MODE_GPIO1
  * @brief Configures polarity and select what als or ranging functionality gpio pin serves.
@@ -354,7 +361,7 @@
  * Same definition apply to register GPIO0 that is used as chip enable at power up.
  * @ingroup device_regdef
  */
-#define SYSTEM_MODE_GPIO1                       (uint16_t) 0x011
+#define SYSTEM_MODE_GPIO1                       0x011
     /** gpio pad POLARITY mask in #SYSTEM_MODE_GPIO1 (and/or 0) write  1  to set active high polarity (positive edge) */
     #define GPIOx_POLARITY_SELECT_MASK              0x20
     /** gpio pad Function select shift in #SYSTEM_MODE_GPIO1 or 0 */
@@ -390,7 +397,7 @@
  * \sa GPIO use for interrupt #SYSTEM_MODE_GPIO0 or #SYSTEM_MODE_GPIO1\n
  * @ingroup device_regdef
  */
-#define SYSTEM_INTERRUPT_CONFIG_GPIO           (uint16_t) 0x014
+#define SYSTEM_INTERRUPT_CONFIG_GPIO           0x014
     /** RANGE bits shift in #SYSTEM_INTERRUPT_CONFIG_GPIO */
     #define CONFIG_GPIO_RANGE_SHIFT            0
     /** RANGE bits mask in #SYSTEM_INTERRUPT_CONFIG_GPIO  (unshifted)*/
@@ -417,7 +424,7 @@
  *  Use or combination of any #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ALS , #INTERRUPT_CLEAR_ERROR
  *  @ingroup device_regdef
  */
-#define SYSTEM_INTERRUPT_CLEAR                (uint16_t) 0x015
+#define SYSTEM_INTERRUPT_CLEAR                0x015
     /** clear ranging interrupt in write to #SYSTEM_INTERRUPT_CLEAR */
     #define INTERRUPT_CLEAR_RANGING                0x01
     /** clear als interrupt  in write to #SYSTEM_INTERRUPT_CLEAR */
@@ -426,7 +433,7 @@
     #define INTERRUPT_CLEAR_ERROR                  0x04
 
 /** After power up or reset this register will start reading 1 when device is ready */
-#define SYSTEM_FRESH_OUT_OF_RESET             (uint16_t) 0x016
+#define SYSTEM_FRESH_OUT_OF_RESET             0x016
 
 /**
  * @def SYSTEM_GROUPED_PARAMETER_HOLD
@@ -443,7 +450,7 @@
  * #SYSALS_THRESH_LOW
  * @ingroup device_regdef
  */
-#define SYSTEM_GROUPED_PARAMETER_HOLD         (uint16_t) 0x017
+#define SYSTEM_GROUPED_PARAMETER_HOLD         0x017
 
 
 /**
@@ -454,7 +461,7 @@
  *
  * @ingroup device_regdef
  */
-#define SYSRANGE_START                        (uint16_t) 0x018
+#define SYSRANGE_START                        0x018
     /** mask existing bit in #SYSRANGE_START*/
     #define MODE_MASK          0x03
     /** bit 0 in #SYSRANGE_START write 1 toggle state in continuous mode and arm next shot in single shot mode */
@@ -469,14 +476,14 @@
  * High level range  threshold (must be scaled)
  * @ingroup device_regdef
  */
-#define SYSRANGE_THRESH_HIGH                  (uint16_t) 0x019
+#define SYSRANGE_THRESH_HIGH                  0x019
 
 /**
  * @def SYSRANGE_THRESH_LOW
  * Low level range  threshold (must be scaled)
  * @ingroup device_regdef
  */
-#define SYSRANGE_THRESH_LOW                   (uint16_t) 0x01A
+#define SYSRANGE_THRESH_LOW                   0x01A
 
 /**
  * @def SYSRANGE_INTERMEASUREMENT_PERIOD
@@ -487,7 +494,7 @@
  *
  * @ingroup device_regdef
  */
-#define SYSRANGE_INTERMEASUREMENT_PERIOD      (uint16_t) 0x01B
+#define SYSRANGE_INTERMEASUREMENT_PERIOD      0x01B
 
 /**
  * @brief Maximum time to run measurement in Ranging modes.
@@ -499,33 +506,33 @@
  *
  * @ingroup device_regdef
  */
-#define SYSRANGE_MAX_CONVERGENCE_TIME         (uint16_t) 0x01C
+#define SYSRANGE_MAX_CONVERGENCE_TIME         0x01C
 /**@brief Cross talk compensation rate
  * @warning  never write register directly use @a VL6180x_SetXTalkCompensationRate()
  * refer to manual for calibration procedure and computation
  * @ingroup device_regdef
  */
-#define SYSRANGE_CROSSTALK_COMPENSATION_RATE  (uint16_t) 0x01E
+#define SYSRANGE_CROSSTALK_COMPENSATION_RATE  0x01E
 /**
  * @brief Minimum range value in mm to qualify for crosstalk compensation
  */
-#define SYSRANGE_CROSSTALK_VALID_HEIGHT       (uint16_t) 0x021
-#define SYSRANGE_EARLY_CONVERGENCE_ESTIMATE   (uint16_t) 0x022
-#define SYSRANGE_PART_TO_PART_RANGE_OFFSET    (uint16_t) 0x024
-#define SYSRANGE_RANGE_IGNORE_VALID_HEIGHT    (uint16_t) 0x025
-#define SYSRANGE_RANGE_IGNORE_THRESHOLD       (uint16_t) 0x026
-#define SYSRANGE_EMITTER_BLOCK_THRESHOLD      (uint16_t) 0x028
-#define SYSRANGE_MAX_AMBIENT_LEVEL_THRESH     (uint16_t) 0x02A
-#define SYSRANGE_MAX_AMBIENT_LEVEL_MULT       (uint16_t) 0x02C
+#define SYSRANGE_CROSSTALK_VALID_HEIGHT       0x021
+#define SYSRANGE_EARLY_CONVERGENCE_ESTIMATE   0x022
+#define SYSRANGE_PART_TO_PART_RANGE_OFFSET    0x024
+#define SYSRANGE_RANGE_IGNORE_VALID_HEIGHT    0x025
+#define SYSRANGE_RANGE_IGNORE_THRESHOLD       0x026
+#define SYSRANGE_EMITTER_BLOCK_THRESHOLD      0x028
+#define SYSRANGE_MAX_AMBIENT_LEVEL_THRESH     0x02A
+#define SYSRANGE_MAX_AMBIENT_LEVEL_MULT       0x02C
 /** @brief  various Enable check enabel register
  *  @a VL6180x_RangeSetEceState()
  */
-#define SYSRANGE_RANGE_CHECK_ENABLES          (uint16_t) 0x02D
+#define SYSRANGE_RANGE_CHECK_ENABLES          0x02D
     #define RANGE_CHECK_ECE_ENABLE_MASK      0x01
     #define RANGE_CHECK_RANGE_ENABLE_MASK    0x02
     #define RANGE_CHECK_SNR_ENABLKE          0x10
 
-#define SYSRANGE_VHV_RECALIBRATE              (uint16_t) 0x02E
+#define SYSRANGE_VHV_RECALIBRATE              0x02E
 #define SYSRANGE_VHV_REPEAT_RATE              0x031
 
 /**
@@ -534,26 +541,26 @@
  *
  * same bit definition as range \a #SYSRANGE_START \n
  */
-#define SYSALS_START                          (uint16_t) 0x038
+#define SYSALS_START                          0x038
 
 /** ALS low Threshold high */
-#define SYSALS_THRESH_HIGH                    (uint16_t) 0x03A
+#define SYSALS_THRESH_HIGH                    0x03A
 /** ALS low Threshold low */
-#define SYSALS_THRESH_LOW                     (uint16_t) 0x03C
+#define SYSALS_THRESH_LOW                     0x03C
 /** ALS intermeasurement period */
-#define SYSALS_INTERMEASUREMENT_PERIOD        (uint16_t) 0x03E
+#define SYSALS_INTERMEASUREMENT_PERIOD        0x03E
 /** 
  * @warning or value with 0x40 when writing to these register*/
-#define SYSALS_ANALOGUE_GAIN                  (uint16_t) 0x03F
+#define SYSALS_ANALOGUE_GAIN                  0x03F
 /** ALS integration period */
-#define SYSALS_INTEGRATION_PERIOD             (uint16_t) 0x040
+#define SYSALS_INTEGRATION_PERIOD             0x040
 
 /**
  * @brief Result range status
  *
  *  Hold the various range interrupt flags and error Specific error codes
  */
-#define RESULT_RANGE_STATUS                   (uint16_t) 0x04D
+#define RESULT_RANGE_STATUS                   0x04D
     /** Device ready for new command bit 0*/
     #define RANGE_DEVICE_READY_MASK       0x01
     /** mask for error status covers bits [7:4]  in #RESULT_RANGE_STATUS @a ::RangeError_u */
@@ -566,7 +573,7 @@
  * @brief Result  als status \n
  *  Hold the various als interrupt flags and Specific error codes
  */
-#define RESULT_ALS_STATUS                     (uint16_t) 0x4E
+#define RESULT_ALS_STATUS                     0x4E
     /** Device ready for new command bit 0*/
    #define ALS_DEVICE_READY_MASK       0x01
 
@@ -577,7 +584,7 @@
  * Lux value depends on Gain and integration settings and calibrated lux/count setting
  * \a VL6180x_AlsGetLux() \a VL6180x_AlsGetMeasurement()
  */
-#define RESULT_ALS_VAL                        (uint16_t) 0x50
+#define RESULT_ALS_VAL                        0x50
 
 /**
  * @def FW_ALS_RESULT_SCALER
@@ -585,7 +592,7 @@
  * these register content is cached by API in \a VL6180xDevData_t::AlsScaler
  * for lux computation acceleration
  */
-#define FW_ALS_RESULT_SCALER                  (uint16_t) 0x120
+#define FW_ALS_RESULT_SCALER                  0x120
 
 
 /**
@@ -617,7 +624,7 @@
  *
  * @ingroup device_regdef
  */
-#define RESULT_INTERRUPT_STATUS_GPIO          (uint16_t) 0x4F
+#define RESULT_INTERRUPT_STATUS_GPIO          0x4F
     /** ranging interrupt 1st bit position in #RESULT_INTERRUPT_STATUS_GPIO */
     #define RES_INT_RANGE_SHIFT  0
     /** ALS interrupt 1st bit position in #RESULT_INTERRUPT_STATUS_GPIO */
@@ -647,33 +654,33 @@
 /**
  * Final range result value presented to the user for use. Unit is in mm.
  */
-#define RESULT_RANGE_VAL                        (uint16_t) 0x062
+#define RESULT_RANGE_VAL                        0x062
 
 /**
  * Raw Range result value with offset applied (no cross talk compensation applied). Unit is in mm.
  */
-#define RESULT_RANGE_RAW                        (uint16_t) 0x064
+#define RESULT_RANGE_RAW                        0x064
 
 /**
  * @brief Sensor count rate of signal returns correlated to IR emitter.
  *
  * Computed from RETURN_SIGNAL_COUNT / RETURN_CONV_TIME. Mcps 9.7 format
  */
-#define RESULT_RANGE_SIGNAL_RATE                (uint16_t) 0x066
+#define RESULT_RANGE_SIGNAL_RATE                0x066
 
 /**
  * @brief Return signal count
  *
  *  Sensor count output value attributed to signal correlated to IR emitter on the Return array.
  */
-#define RESULT_RANGE_RETURN_SIGNAL_COUNT        (uint16_t) 0x06C
+#define RESULT_RANGE_RETURN_SIGNAL_COUNT        0x06C
 
 /**
  * @brief Reference signal count
  *
  * sensor count output value attributed to signal correlated to IR emitter on the Reference array.
  */
-#define RESULT_RANGE_REFERENCE_SIGNAL_COUNT     (uint16_t) 0x070
+#define RESULT_RANGE_REFERENCE_SIGNAL_COUNT     0x070
 
 /**
  * @brief Return ambient count
@@ -681,24 +688,24 @@
  * sensor count output value attributed to uncorrelated ambient signal on the Return array.
  * Must be multiplied by 6 if used to calculate the ambient to signal threshold
  */
-#define RESULT_RANGE_RETURN_AMB_COUNT           (uint16_t) 0x074
+#define RESULT_RANGE_RETURN_AMB_COUNT           0x074
 
 /**
  * @brief   Reference ambient count
  *
  * Sensor count output value attributed to uncorrelated ambient signal on the Reference array.
  */
-#define RESULT_RANGE_REFERENCE_AMB_COUNT        (uint16_t) 0x078
+#define RESULT_RANGE_REFERENCE_AMB_COUNT        0x078
 
 /**
  * sensor count output value attributed to signal on the Return array.
  */
-#define RESULT_RANGE_RETURN_CONV_TIME           (uint16_t) 0x07C
+#define RESULT_RANGE_RETURN_CONV_TIME           0x07C
 
 /**
  * sensor count output value attributed to signal on the Reference array.
  */
-#define RESULT_RANGE_REFERENCE_CONV_TIME        (uint16_t) 0x080
+#define RESULT_RANGE_REFERENCE_CONV_TIME        0x080
 
 
 /**
@@ -707,7 +714,7 @@
  *
  * Never should  user write directly onto that register directly \a VL6180x_UpscaleSetScaling()
  */
-#define RANGE_SCALER                            (uint16_t) 0x096
+#define RANGE_SCALER                            0x096
 
 /**
  * @def READOUT_AVERAGING_SAMPLE_PERIOD
@@ -722,7 +729,7 @@
  *
  * see datasheet for more detail
  */
-#define READOUT_AVERAGING_SAMPLE_PERIOD     (uint16_t) 0x10A
+#define READOUT_AVERAGING_SAMPLE_PERIOD     0x10A
 
 /**
  * @def I2C_SLAVE_DEVICE_ADDRESS
@@ -731,6 +738,6 @@
  * so what prohamd is commonly whar ergfer as adrerss /2
  * @sa VL6180x_SetI2CAddress()
  */
-#define I2C_SLAVE_DEVICE_ADDRESS               (uint16_t) 0x212
+#define I2C_SLAVE_DEVICE_ADDRESS               0x212
 
 #endif /* _VL6180x_DEF */
--- a/Components/VL6180X/vl6180x_platform.h	Tue Sep 29 15:40:08 2015 +0200
+++ b/Components/VL6180X/vl6180x_platform.h	Tue Oct 06 09:03:10 2015 +0200
@@ -1,48 +1,42 @@
 /*******************************************************************************
-Copyright © 2014, STMicroelectronics International N.V.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-    * Redistributions of source code must retain the above copyright
-      notice, this list of conditions and the following disclaimer.
-    * Redistributions in binary form must reproduce the above copyright
-      notice, this list of conditions and the following disclaimer in the
-      documentation and/or other materials provided with the distribution.
-    * Neither the name of STMicroelectronics nor the
-      names of its contributors may be used to endorse or promote products
-      derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
-NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED. 
-IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+################################################################################
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License version 2 and only version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+#------------------------------------------------------------------------------
+#                             Imaging Division
+################################################################################
 ********************************************************************************/
 
 
-
-/* vl6180x_platform.h STM32 Nucelo F401 single device  using generic cci-i2c
- * trace via swo port some GnuArm eclipse toolset */
+/* vl6180x_platform.h STM32 Nucleo F401 single device  sample code project */
 
 #ifndef VL6180x_PLATFORM
 #define VL6180x_PLATFORM
 
+
 #include "vl6180x_def.h"
 
 
+#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_DEV_DATA_ATTR
-
 #define ROMABLE_DATA
-/*  #define ROMABLE_DATA  __attribute__ ((section ("user_rom"))) */
-
 
 
 #if VL6180X_LOG_ENABLE
@@ -51,6 +45,7 @@
 #include "diag/trace.h"
 extern volatile uint32_t g_TickCnt;
 #define LOG_GET_TIME()  g_TickCnt
+//#define LOG_GET_TIME()  HAL_GetTick()
 #else
 /* these is nto stm32 vl6180x GNuArm eclpse build*/
 #define trace_printf(...) (void)0
@@ -74,29 +69,32 @@
     }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 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
 
 
-	typedef struct MyVL6180Dev_t {
-			struct VL6180xDevData_t Data;
-			uint8_t I2cAddr;
-			uint8_t DevID;
+#if  VL6180x_SINGLE_DEVICE_DRIVER
+    #error "VL6180x_SINGLE_DEVICE_DRIVER must be set"
+#endif
+		
+struct MyVL6180Dev_t {
+		struct VL6180xDevData_t Data;
+		uint8_t I2cAddr;
+		//uint8_t DevID;
     
-		// misc flags for application 	
-			unsigned Present:1;
-			unsigned Ready:1;
-	}VL6180xDev_t;		
+	//misc flags for application 	
+    unsigned Present:1;
+    unsigned Ready:1;
+};
+typedef struct MyVL6180Dev_t *VL6180xDev_t;
 
+#define VL6180xDevDataGet(dev, field) (dev->Data.field)
+#define VL6180xDevDataSet(dev, field, data) (dev->Data.field)=(data)
 
-#define VL6180xDevDataGet(dev, field) (dev.Data.field)
-#define VL6180xDevDataSet(dev, field, data) (dev.Data.field)=(data)
-
-//#endif /* #else VL6180x_SINGLE_DEVICE_DRIVER */
 
 void VL6180x_PollDelay(VL6180xDev_t dev);
 
--- a/x_nucleo_6180xa1.cpp	Tue Sep 29 15:40:08 2015 +0200
+++ b/x_nucleo_6180xa1.cpp	Tue Oct 06 09:03:10 2015 +0200
@@ -0,0 +1,72 @@
+/**
+ ******************************************************************************
+ * @file    x_nucleo_6180xa1.cpp
+ * @author  AST / EST
+ * @version V0.0.1
+ * @date    13-April-2015
+ * @brief   Implementation file for the X_NUCLEO_VL6180XA1 singleton class
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *   1. Redistributions of source code must retain the above copyright notice,
+ *      this list of conditions and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above copyright notice,
+ *      this list of conditions and the following disclaimer in the documentation
+ *      and/or other materials provided with the distribution.
+ *   3. Neither the name of STMicroelectronics nor the names of its contributors
+ *      may be used to endorse or promote products derived from this software
+ *      without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+
+/* Includes ------------------------------------------------------------------*/
+#include "x_nucleo_6180xa1.h"
+
+/* Static variables ----------------------------------------------------------*/
+X_NUCLEO_6180XA1* X_NUCLEO_6180XA1::_instance = NULL;
+
+
+X_NUCLEO_6180XA1* X_NUCLEO_6180XA1::Instance(DevI2C *ext_i2c)
+{
+	if(_instance==NULL)
+	   _instance=new X_NUCLEO_6180XA1(ext_i2c);
+	else
+	   error("Failed to init X_NUCLEO_6180XA1 board!\n");
+	return _instance;
+}
+
+
+int X_NUCLEO_6180XA1::InitBoard()
+{	
+	int status;
+	
+	status=sensor_top->InitSensor(NEW_SENSOR_TOP_ADDRESS);
+	if(status)
+	{
+	   delete[] sensor_top;
+		 delete[] gpio0_top;
+		 sensor_top=NULL;
+ 		 gpio0_top=NULL;
+	}
+		   
+  //stessa cosa per left, bottom e right		
+}
+
+
--- a/x_nucleo_6180xa1.h	Tue Sep 29 15:40:08 2015 +0200
+++ b/x_nucleo_6180xa1.h	Tue Oct 06 09:03:10 2015 +0200
@@ -44,47 +44,49 @@
 #include "mbed.h"
 #include "vl6180x_class.h"
 #include "display_class.h"
-#include "GPIO_expander_class.h"
+#include "STMPE1600_class.h"
 #include "DevI2C.h"
 
+/** New device addresses */
+#define NEW_SENSOR_TOP_ADDRESS			0x10
+//#define NEW_SENSOR_LEFT_ADDRESS			0x33
+//#define NEW_SENSOR_BOTTOM_ADDRESS		0x34
+//#define NEW_SENSOR_RIGHT_ADDRESS		0x35
+
 /* Classes--------------------------------------------------------------------*/
 
-/*class X_NUCLEO_6180XA1
+class X_NUCLEO_6180XA1
 {
-	protected:
-	
 	public:
-		X_NUCLEO_VL6180XA1(DevI2C *i2c)): dev_i2c(i2c), 
-			  vl6180x_top(new VL6180X()),
-			  vl6180x_left(new VL6180X()),
-			  vl6180x_bottom(new VL6180X()),
-			  vl6180x_right(new VL6180X()),
-			  display(new Display(i2c)),
-			  gpio_expander(i2c));			  
+		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);
+		}
 		
-			
-		VL6180X *vl6180x_top;
-		VL6180X *vl6180x_left;
-		VL6180X *vl6180x_bottom;
-		VL6180X *vl6180x_right;
-		Display *display;
-		GPIO_expander *gpio_expander;
-		DevI2C *dev_i2c;
+		~X_NUCLEO_6180XA1()
+    {
+			 if(gpio0_top!=NULL)
+			   delete[] gpio0_top;
+			 if(sensor_top!=NULL)
+			   delete[] sensor_top;
+		}
+		  
+	  DevI2C *dev_i2c;	
+		STMPE1600DigiOut *gpio0_top;
+		VL6180X *sensor_top;
 		
-		X_NUCLEO_VL6180XA1 *Instance(DevI2C *i2c)
-		{
-			 if(_instance==NULL)
-			 	  _instance=new X_NUCLEO_6180XA1(i2c);
-			 else
-			    errore
-		}
+		//VL6180X *vl6180x_left;
+		//VL6180X *vl6180x_bottom;
+		//VL6180X *vl6180x_right;
+		//Display *display;
+		
+		static X_NUCLEO_6180XA1 *Instance(DevI2C *ext_i2c);
+		
+	  int InitBoard(); // posso ritornare il numero dei dispositivi attivi 
 		
 	private:
 		static X_NUCLEO_6180XA1 *_instance;
-		
-}
-*/
-
-
+};
 
 #endif /* __X_NUCLEO_6180XA1_H */