AGV_RKP

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Revision:
7:c9c9ed520566
Parent:
6:308889c4d074
--- a/lis3mdl_class.cpp	Wed Oct 18 11:14:26 2017 +0200
+++ b/lis3mdl_class.cpp	Mon Sep 27 05:10:52 2021 +0000
@@ -44,7 +44,7 @@
            X-CUBE-MEMS1/trunk/Drivers/BSP/Components/lis3mdl/lis3mdl.c: revision #400,
            X-CUBE-MEMS1/trunk: revision #416
 */
-
+//my
 LIS3MDL::LIS3MDL(SPI *spi, PinName cs_pin, PinName int_pin, SPI_type_t spi_type) : 
                 _dev_spi(spi), _cs_pin(cs_pin), _int_pin(int_pin), _spi_type(spi_type)
 {
@@ -63,15 +63,15 @@
     if (_spi_type == SPI3W) LIS3MDL_Set_SpiInterface ((void *)this, LIS3MDL_SPI_3_WIRE);
     else if (_spi_type == SPI4W) LIS3MDL_Set_SpiInterface ((void *)this, LIS3MDL_SPI_4_WIRE);
 }  
-
+//
 LIS3MDL::LIS3MDL(DevI2C *i2c, uint8_t address, PinName int_pin) :
        _dev_i2c(i2c), _address(address), _cs_pin(NC), _int_pin(int_pin)  
 {
     assert (i2c);
-    _dev_spi = NULL;
+    //_dev_spi = NULL;
 }  
 
-
+// my
 MAGNETO_StatusTypeDef LIS3MDL::LIS3MDL_Set_SpiInterface (void *handle, LIS3MDL_SPIMode_t spimode)
 {
     uint8_t tmp=0x03;  //deft LIS3MDL_CTRL_REG3 value  
@@ -80,7 +80,7 @@
     if (LIS3MDL_IO_Write(&tmp, LIS3MDL_M_CTRL_REG3_M, 1) != MAGNETO_OK) return MAGNETO_ERROR;      
     return MAGNETO_OK;
 }
-
+//
 /**
  * @brief  Set LIS3MDL Initialization
  * @param  LIS3MDL_Init the configuration setting for the LIS3MDL
@@ -90,8 +90,8 @@
 {
   uint8_t tmp1 = 0x00;
   MAGNETO_InitTypeDef *initStructure = LIS3MDL_Init;
-  MAGNETO_InitTypeDef tempInit;  
-  
+  MAGNETO_InitTypeDef tempInit; 
+    
   if (initStructure == NULL) {// default params   
     tempInit.M_FullScale = LIS3MDL_M_FS_4;
     tempInit.M_OperatingMode = LIS3MDL_M_MD_CONTINUOUS;
@@ -155,6 +155,8 @@
     return MAGNETO_ERROR;
   }
   
+  //set_BDU();//my 
+  
   /* Configure interrupt lines */
   LIS3MDL_IO_ITConfig();
   
@@ -203,7 +205,7 @@
     return MAGNETO_ERROR;
   }
   
-  pData[1] = ((((int16_t)tempReg[1]) << 8) + (int16_t)tempReg[0]);
+  pData[1] = *((int16_t*)&tempReg[0]);//((((int16_t)tempReg[1]) << 8) + (int16_t)tempReg[0]);
   
   if(LIS3MDL_IO_Read(&tempReg[0], (LIS3MDL_M_OUT_Z_L_M | LIS3MDL_I2C_MULTIPLEBYTE_CMD),
                      2) != MAGNETO_OK)
@@ -216,6 +218,24 @@
   return MAGNETO_OK;
 }
 
+//my----------------------------------------------------------------------------
+MAGNETO_StatusTypeDef LIS3MDL::LIS3MDL_M_SetAxeOffset(uint8_t axe,int16_t offset)
+{
+  uint8_t tmp[2];
+  tmp[0]=offset;
+  tmp[1]=offset>>8;
+  if(LIS3MDL_IO_Write(tmp, 5+2*axe, 2)!= MAGNETO_OK)
+    return MAGNETO_ERROR;
+  else  
+    return MAGNETO_OK;   
+/*    
+  tmp=offset>>8;   
+  if(LIS3MDL_IO_Write(&tmp, 6+2*axe, 1)!= MAGNETO_OK)
+    return MAGNETO_ERROR;      
+  return MAGNETO_OK;
+*/  
+}
+
 
 /**
  * @brief Read data from LIS3MDL Magnetic sensor and calculate Magnetic in mgauss
@@ -232,7 +252,7 @@
   {
     return MAGNETO_ERROR;
   }
-  
+
   if(LIS3MDL_IO_Read(&tempReg, LIS3MDL_M_CTRL_REG2_M, 1) != MAGNETO_OK)
   {
     return MAGNETO_ERROR;
@@ -259,7 +279,7 @@
   pData[0] = (int32_t)(pDataRaw[0] * sensitivity);
   pData[1] = (int32_t)(pDataRaw[1] * sensitivity);
   pData[2] = (int32_t)(pDataRaw[2] * sensitivity);
-  
+
   return MAGNETO_OK;
 }