AGV_RKP

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Revision:
7:c9c9ed520566
Parent:
4:00493226e59f
--- a/lis3mdl_class.h	Wed Oct 18 11:14:26 2017 +0200
+++ b/lis3mdl_class.h	Mon Sep 27 05:10:52 2021 +0000
@@ -51,8 +51,10 @@
  */
 class LIS3MDL : public MagneticSensor {
  public:
-    enum SPI_type_t {SPI3W, SPI4W};    
+    //my
+     enum SPI_type_t {SPI3W, SPI4W};    
     
+    //my 
     LIS3MDL(SPI *spi, PinName cs_pin, PinName int_pin=NC, SPI_type_t spi_type=SPI4W);
         
 	/** Constructor
@@ -81,15 +83,26 @@
 	virtual int get_m_axes_raw(int16_t *pData) {
 		return LIS3MDL_M_GetAxesRaw(pData);
 	}
-
+	
+    virtual int set_m_axes_offset(uint8_t axe,int16_t offset) { //my
+      	return LIS3MDL_M_SetAxeOffset(axe,offset);
+    }
+    virtual int set_BDU() { //my
+      	uint8_t tmp;
+      	if(LIS3MDL_IO_Read(&tmp, LIS3MDL_M_CTRL_REG5_M, 1) != MAGNETO_OK)
+    		return MAGNETO_ERROR;
+    	tmp=0x40;
+  		return LIS3MDL_IO_Write(&tmp, LIS3MDL_M_CTRL_REG5_M, 1);
+    }    
  protected:
 	/*** Methods ***/
 	MAGNETO_StatusTypeDef LIS3MDL_Init(MAGNETO_InitTypeDef *LIS3MDL_Init);
 	MAGNETO_StatusTypeDef LIS3MDL_Read_M_ID(uint8_t *m_id);
 	MAGNETO_StatusTypeDef LIS3MDL_M_GetAxes(int32_t *pData);
 	MAGNETO_StatusTypeDef LIS3MDL_M_GetAxesRaw(int16_t *pData);
+	//my 
 	MAGNETO_StatusTypeDef LIS3MDL_Set_SpiInterface (void *handle, LIS3MDL_SPIMode_t spimode);
-
+	MAGNETO_StatusTypeDef LIS3MDL_M_SetAxeOffset(uint8_t axe,int16_t offset);//my
 	/**
 	 * @brief  Configures LIS3MDL interrupt lines for NUCLEO boards
 	 */
@@ -118,8 +131,9 @@
 	MAGNETO_StatusTypeDef LIS3MDL_IO_Read(uint8_t* pBuffer, 
 					      uint8_t RegisterAddr, uint16_t NumByteToRead)
 	{
+/*my		
         if (_dev_spi) {
-        /* Write Reg Address */
+        // Write Reg Address 
             _dev_spi->lock();
             _cs_pin = 0;           
             if (_spi_type == SPI4W) {            
@@ -128,14 +142,15 @@
                     *(pBuffer+i) = _dev_spi->write(0x00);
                 }
             } else if (_spi_type == SPI3W){
-                /* Write RD Reg Address with RD bit*/
+                // Write RD Reg Address with RD bit
                 uint8_t TxByte = RegisterAddr | 0x80;    
                 _dev_spi->write((char *)&TxByte, 1, (char *)pBuffer, (int) NumByteToRead);
             }            
             _cs_pin = 1;
             _dev_spi->unlock(); 
             return MAGNETO_OK;
-        }            		
+        }  
+*/                  		
         if (!_dev_i2c) return MAGNETO_ERROR;			
 		int ret = _dev_i2c->i2c_read(pBuffer,
 					   _address,
@@ -158,7 +173,7 @@
 	MAGNETO_StatusTypeDef LIS3MDL_IO_Write(uint8_t* pBuffer, 
 					       uint8_t RegisterAddr, uint16_t NumByteToWrite)
 	{
-		
+/*		
         if (_dev_spi) { 
             _dev_spi->lock();
             _cs_pin = 0;
@@ -168,7 +183,7 @@
             _dev_spi->unlock();
             return MAGNETO_OK;                    
         }        
-		
+*/		
         if (!_dev_i2c) return MAGNETO_ERROR;	
 		int ret = _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
 		if(ret != 0) {
@@ -180,10 +195,12 @@
 	/*** Instance Variables ***/
 	/* IO Device */
 	DevI2C *_dev_i2c;
+	//my 
 	SPI    *_dev_spi;
     uint8_t _address;	
     DigitalOut  _cs_pin; 
     InterruptIn _int_pin;    
+    //my 
     SPI_type_t _spi_type;        
 };