INSAT Mini Project

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Revision:
10:4954b09b72d8
Parent:
9:9cbc1736f148
Child:
12:71d589e6fd2c
--- 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;
 }