Update latest

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Files at this revision

API Documentation at this revision

Comitter:
nikapov
Date:
Tue Sep 05 10:15:14 2017 +0000
Child:
1:d85092ab306e
Commit message:
First version.

Changed in this revision

ST_INTERFACES.lib Show annotated file Show diff for this revision Revisions of this file
X_NUCLEO_COMMON.lib Show annotated file Show diff for this revision Revisions of this file
lis3mdl.h Show annotated file Show diff for this revision Revisions of this file
lis3mdl_class.cpp Show annotated file Show diff for this revision Revisions of this file
lis3mdl_class.h Show annotated file Show diff for this revision Revisions of this file
readme.txt Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ST_INTERFACES.lib	Tue Sep 05 10:15:14 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#8f70f7159316
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_COMMON.lib	Tue Sep 05 10:15:14 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#12be3dfc15fd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lis3mdl.h	Tue Sep 05 10:15:14 2017 +0000
@@ -0,0 +1,455 @@
+/**
+ ******************************************************************************
+ * @file    lis3mdl.h
+ * @author  MEMS Application Team
+ * @version V1.3.0
+ * @date    28-May-2015
+ * @brief   This file contains definitions for the lis3mdl.c
+ *          firmware driver.
+ ******************************************************************************
+ * @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.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __LIS3MDL_H
+#define __LIS3MDL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "magneto.h"
+
+/** @addtogroup BSP
+ * @{
+ */
+
+/** @addtogroup Components
+ * @{
+ */
+
+/** @addtogroup LIS3MDL
+ * @{
+ */
+
+/** @defgroup LIS3MDL_Exported_Defines LIS3MDL_Exported_Defines
+ * @{
+ */
+#ifndef NULL
+#define NULL      (void *) 0
+#endif
+
+
+/******************************************************************************/
+/***************** START MAGNETIC SENSOR REGISTER MAPPING  ********************/
+/******************************************************************************/
+
+/**
+  * @brief Device identifier register.
+  * \code
+  * Read
+  * Default value:
+  * 7:0 This read-only register contains the device identifier
+  * \endcode
+*/
+#define LIS3MDL_M_WHO_AM_I_ADDR                             0x0F
+
+
+/**
+ * @brief Magnetic sensor Control Register 1
+ * \code
+ * Read/write
+ * Default value: 0x10
+ * [7] TEMP_COMP: Temperature compensation enable
+ * [6:5] OM1-0: X and Y axes operative mode selection
+ * [4:2] DO2-0: Output data rate selection
+ * [1] This bit must be set to �0� for the correct operation of the device
+ * [0] ST: Self-test enable
+ * \endcode
+ */
+#define LIS3MDL_M_CTRL_REG1_M                               0x20
+
+
+/**
+ * @brief Magnetic sensor Control Register 2
+ * \code
+ * Read/write
+ * Default value: 0x00
+ * [7] These bits must be set to �0� for the correct operation of the device
+ * [6:5] FS1-0: Full-scale configuration
+ * [4] These bits must be set to �0� for the correct operation of the device
+ * [3] REBOOT: Reboot memory content
+ * [2] SOFT_RST: Configuration registers and user register reset function
+ * [1:0] These bits must be set to �0� for the correct operation of the device
+ * \endcode
+ */
+#define LIS3MDL_M_CTRL_REG2_M                               0x21
+
+
+/**
+ * @brief Magnetic sensor Control Register 3
+ * \code
+ * Read/write
+ * Default value: 0x03
+ * [7] I2C_DISABLE: Disable I2C interface
+ * [6] These bits must be set to �0� for the correct operation of the device
+ * [5] LP: Low-power mode configuration
+ * [4:3] These bits must be set to �0� for the correct operation of the device
+ * [2] SIM: SPI Serial Interface mode selection
+ * [1:0] MD1-0: Operating mode selection
+ * \endcode
+ */
+#define LIS3MDL_M_CTRL_REG3_M                               0x22
+
+
+/**
+ * @brief Magnetic sensor data (LSB)
+ * \code
+ * Read
+ * \endcode
+ */
+#define LIS3MDL_M_OUT_X_L_M                                 0x28
+
+
+/**
+ * @brief Magnetic sensor data (MSB)
+ * \code
+ * Read
+ * \endcode
+ */
+#define LIS3MDL_M_OUT_X_H_M                                  0x29
+
+
+/**
+ * @brief Magnetic sensor data (LSB)
+ * \code
+ * Read
+ * \endcode
+ */
+#define LIS3MDL_M_OUT_Y_L_M                                  0x2A
+
+
+/**
+ * @brief Magnetic sensor data (MSB)
+ * \code
+ * Read
+ * \endcode
+ */
+#define LIS3MDL_M_OUT_Y_H_M                                  0x2B
+
+
+/**
+ * @brief Magnetic sensor data (LSB)
+ * \code
+ * Read
+ * \endcode
+ */
+#define LIS3MDL_M_OUT_Z_L_M                                  0x2C
+
+
+/**
+ * @brief Magnetic sensor data (MSB)
+ * \code
+ * Read
+ * \endcode
+ */
+#define LIS3MDL_M_OUT_Z_H_M                                  0x2D
+
+
+/**
+ * @brief Magnetic sensor Interrupt config register
+ * \code
+ * Read/write
+ * Default value: 0x00
+ * [7] XIEN: Enable interrupt generation on X axis
+ * [6] YIEN: Enable interrupt generation on Y axis
+ * [5] ZIEN: Enable interrupt generation on Z axis
+ * [4:3] Must be 0
+ * [2] IEA: Interrupt active configuration on INT
+ * [1] LIR: Latch interrupt request
+ * [0] IEN: Interrupt enable on INT pin
+ * \endcode
+ */
+#define LIS3MDL_M_INT_CFG                                   0x30
+
+
+/**
+ * @brief Magnetic sensor Interrupt source register
+ * \code
+ * Read/write
+ * Default value: 0x00
+ * [7] PTH_X: Value on X-axis exceeds the threshold on the positive side
+ * [6] PTH_Y: Value on Y-axis exceeds the threshold on the positive side
+ * [5] PTH_Z: Value on Z-axis exceeds the threshold on the positive side
+ * [4] NTH_X: Value on X-axis exceeds the threshold on the negative side
+ * [3] NTH_Y: Value on Y-axis exceeds the threshold on the negative side
+ * [2] NTH_Z: Value on Z-axis exceeds the threshold on the negative side
+ * [1] MROI: Internal measurement range overflow on magnetic value
+ * [0] INT: This bit signals when interrupt event occours
+ * \endcode
+ */
+#define LIS3MDL_M_INT_SRC                                   0x31
+
+
+/**
+ * @brief Magnetic sensor Interrupt threshold register low
+ * \code
+ * Read/write
+ * Default value: 0x00
+ * [7:0] THS7-0: Least 8 significant bits of interrupt threshold
+ * \endcode
+ */
+#define LIS3MDL_M_INT_THS_L_M                               0x32
+
+
+/**
+ * @brief Magnetic sensor Interrupt threshold register high
+ * \code
+ * Read/write
+ * Default value: 0x00
+ * [7] Must be 0
+ * [6:0] THS14-8: Most 7 significant bits of interrupt threshold
+ * \endcode
+ */
+#define LIS3MDL_M_INT_THS_H_M                               0x33
+
+/******************************************************************************/
+/******************* END MAGNETIC SENSOR REGISTER MAPPING  ********************/
+/******************************************************************************/
+
+/**
+ * @brief Multiple Byte. Mask for enabling multiple byte read/write command.
+ */
+#define LIS3MDL_I2C_MULTIPLEBYTE_CMD                      ((uint8_t)0x80)
+
+/**
+ * @brief Device Address
+ */
+
+#define LIS3MDL_M_MEMS_ADDRESS                              0x3C    // SAD[1] = 1
+
+/**
+ * @brief Device Identifier. Default value of the WHO_AM_I register.
+ */
+#define I_AM_LIS3MDL_M                                  ((uint8_t)0x3D)
+
+
+/*********************************** MAGNETIC SENSOR REGISTERS VALUE ****************************************/
+
+/** @defgroup LIS3MDL_M_Temperature_Compensation_Enable_Selection_CTRL_REG1_M LIS3MDL_M_Temperature_Compensation_Enable_Selection_CTRL_REG1_M
+ * @{
+ */
+#define LIS3MDL_M_TEMP_COMP_DISABLE                     ((uint8_t)0x00) /*!< Temperature compensation: disable */
+#define LIS3MDL_M_TEMP_COMP_ENABLE                      ((uint8_t)0x80) /*!< Temperature compensation: enable */
+
+#define LIS3MDL_M_TEMP_COMP_MASK                        ((uint8_t)0x80)
+/**
+  * @}
+  */
+
+/** @defgroup LIS3MDL_M_X_And_Y_Axes_Operative_Mode_Selection_CTRL_REG1_M LIS3MDL_M_X_And_Y_Axes_Operative_Mode_Selection_CTRL_REG1_M
+ * @{
+ */
+#define LIS3MDL_M_OM_LP                                 ((uint8_t)0x00) /*!< X and Y axes operative mode: Low-power mode */
+#define LIS3MDL_M_OM_MP                                 ((uint8_t)0x20) /*!< X and Y axes operative mode: Medium-performance mode */
+#define LIS3MDL_M_OM_HP                                 ((uint8_t)0x40) /*!< X and Y axes operative mode: High-performance mode */
+#define LIS3MDL_M_OM_UHP                                ((uint8_t)0x60) /*!< X and Y axes operative mode: Ultra-high performance mode */
+
+#define LIS3MDL_M_OM_MASK                               ((uint8_t)0x60)
+/**
+  * @}
+  */
+
+/** @defgroup LIS3MDL_M_Output_Data_Rate_Selection_CTRL_REG1_M LIS3MDL_M_Output_Data_Rate_Selection_CTRL_REG1_M
+ * @{
+ */
+#define LIS3MDL_M_DO_0_625                              ((uint8_t)0x00) /*!< Output data rate selection: 0.625 */
+#define LIS3MDL_M_DO_1_25                               ((uint8_t)0x04) /*!< Output data rate selection: 1.25 */
+#define LIS3MDL_M_DO_2_5                                ((uint8_t)0x08) /*!< Output data rate selection: 2.5 */
+#define LIS3MDL_M_DO_5                                  ((uint8_t)0x0C) /*!< Output data rate selection: 5 */
+#define LIS3MDL_M_DO_10                                 ((uint8_t)0x10) /*!< Output data rate selection: 10 */
+#define LIS3MDL_M_DO_20                                 ((uint8_t)0x14) /*!< Output data rate selection: 20 */
+#define LIS3MDL_M_DO_40                                 ((uint8_t)0x18) /*!< Output data rate selection: 40 */
+#define LIS3MDL_M_DO_80                                 ((uint8_t)0x1C) /*!< Output data rate selection: 80 */
+
+#define LIS3MDL_M_DO_MASK                               ((uint8_t)0x1C)
+/**
+  * @}
+  */
+
+/** @defgroup LIS3MDL_M_Self_Test_Enable_Selection_CTRL_REG1_M LIS3MDL_M_Self_Test_Enable_Selection_CTRL_REG1_M
+ * @{
+ */
+#define LIS3MDL_M_ST_DISABLE                            ((uint8_t)0x00) /*!< Self-test: disable */
+#define LIS3MDL_M_ST_ENABLE                             ((uint8_t)0x01) /*!< Self-test: enable */
+
+#define LIS3MDL_M_ST_MASK                               ((uint8_t)0x01)
+/**
+  * @}
+  */
+
+/** @defgroup LIS3MDL_M_Full_Scale_Selection_CTRL_REG2_M LIS3MDL_M_Full_Scale_Selection_CTRL_REG2_M
+ * @{
+ */
+#define LIS3MDL_M_FS_4                                  ((uint8_t)0x00) /*!< Full scale: +-4 guass */
+#define LIS3MDL_M_FS_8                                  ((uint8_t)0x20) /*!< Full scale: +-8 gauss */
+#define LIS3MDL_M_FS_12                                 ((uint8_t)0x40) /*!< Full scale: +-12 gauss */
+#define LIS3MDL_M_FS_16                                 ((uint8_t)0x60) /*!< Full scale: +-16 gauss */
+
+#define LIS3MDL_M_FS_MASK                               ((uint8_t)0x60)
+/**
+  * @}
+  */
+
+/** @defgroup LIS3MDL_M_Reboot_Memory_Selection_CTRL_REG2_M LIS3MDL_M_Reboot_Memory_Selection_CTRL_REG2_M
+ * @{
+ */
+#define LIS3MDL_M_REBOOT_NORMAL                         ((uint8_t)0x00) /*!< Reboot mode: normal mode */
+#define LIS3MDL_M_REBOOT_MEM_CONTENT                    ((uint8_t)0x08) /*!< Reboot mode: reboot memory content */
+
+#define LIS3MDL_M_REBOOT_MASK                           ((uint8_t)0x08)
+/**
+  * @}
+  */
+
+/** @defgroup LIS3MDL_M_Configuration_Registers_And_User_Register_Reset_CTRL_REG2_M LIS3MDL_M_Configuration_Registers_And_User_Register_Reset_CTRL_REG2_M
+ * @{
+ */
+#define LIS3MDL_M_SOFT_RST_DEFAULT                      ((uint8_t)0x00) /*!< Reset function: default value */
+#define LIS3MDL_M_SOFT_RST_RESET                        ((uint8_t)0x04) /*!< Reset function: reset operation */
+
+#define LIS3MDL_M_SOFT_RST_MASK                         ((uint8_t)0x04)
+/**
+  * @}
+  */
+
+/** @defgroup LIS3MDL_M_Disable_I2C_Interface_Selection_CTRL_REG3_M LIS3MDL_M_Disable_I2C_Interface_Selection_CTRL_REG3_M
+ * @{
+ */
+#define LIS3MDL_M_I2C_ENABLE                            ((uint8_t)0x00) /*!< I2C interface: enable */
+#define LIS3MDL_M_I2C_DISABLE                           ((uint8_t)0x80) /*!< I2C interface: disable */
+
+#define LIS3MDL_M_I2C_MASK                              ((uint8_t)0x80)
+/**
+  * @}
+  */
+
+/** @defgroup LIS3MDL_M_Low_Power_Mode_Selection_CTRL_REG3_M LIS3MDL_M_Low_Power_Mode_Selection_CTRL_REG3_M
+ * @{
+ */
+#define LIS3MDL_M_LP_ENABLE                            ((uint8_t)0x00) /*!< Low-power mode: magnetic data rate is configured by
+                                                                                            the DO bits in the CTRL_REG1_M */
+#define LIS3MDL_M_LP_DISABLE                           ((uint8_t)0x20) /*!< Low-power mode: the DO bits is set to 0.625 Hz and the system performs,
+                                                                                            for each channel, the minimum number of averages */
+
+#define LIS3MDL_M_LP_MASK                              ((uint8_t)0x20)
+/**
+  * @}
+  */
+
+/** @defgroup LIS3MDL_M_SPI_Serial_Interface_Mode_Selection_CTRL_REG3_M LIS3MDL_M_SPI_Serial_Interface_Mode_Selection_CTRL_REG3_M
+ * @{
+ */
+#define LIS3MDL_M_SPI_R_ENABLE                          ((uint8_t)0x00) /*!< SPI Serial Interface mode: only write operations enabled */
+#define LIS3MDL_M_SPI_R_DISABLE                         ((uint8_t)0x40) /*!< SPI Serial Interface mode: read and write operations enable */
+
+#define LIS3MDL_M_SPI_R_MASK                            ((uint8_t)0x40)
+/**
+  * @}
+  */
+
+/** @defgroup LIS3MDL_M_Operating_Mode_Selection_CTRL_REG3_M LIS3MDL_M_Operating_Mode_Selection_CTRL_REG3_M
+ * @{
+ */
+#define LIS3MDL_M_MD_CONTINUOUS                         ((uint8_t)0x00) /*!< Operating mode: Continuous-conversion mode */
+#define LIS3MDL_M_MD_SINGLE                             ((uint8_t)0x01) /*!< Operating mode: Single-conversion mode has to be used with sampling frequency from 0.625 Hz to 80 Hz. */
+#define LIS3MDL_M_MD_PD                                 ((uint8_t)0x02) /*!< Operating mode: Power-down mode */
+
+#define LIS3MDL_M_MD_MASK                               ((uint8_t)0x03)
+/**
+ * @}
+ */
+
+/**
+  * @}
+  */
+
+/** @defgroup LIS3MDL_Imported_Functions LIS3MDL_Imported_Functions
+ * @{
+ */
+
+/* Magneto sensor IO functions */
+extern MAGNETO_StatusTypeDef LIS3MDL_IO_Init(void);
+extern MAGNETO_StatusTypeDef LIS3MDL_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr,
+    uint16_t NumByteToWrite);
+extern MAGNETO_StatusTypeDef LIS3MDL_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr,
+    uint16_t NumByteToRead);
+extern void LIS3MDL_IO_ITConfig( void );
+
+/**
+ * @}
+ */
+
+/* ------------------------------------------------------- */
+/* Here you should declare the internal struct of          */
+/* extended features of LSM6DS0. See the example of        */
+/* LSM6DS3 in lsm6ds3.h                                    */
+/* ------------------------------------------------------- */
+
+/** @addtogroup LIS3MDL_Exported_Variables LIS3MDL_Exported_Variables
+ * @{
+ */
+/* Magneto sensor driver structure */
+extern MAGNETO_DrvTypeDef LIS3MDLDrv;
+extern MAGNETO_DrvExtTypeDef LIS3MDLDrv_ext;
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIS3MDL_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lis3mdl_class.cpp	Tue Sep 05 10:15:14 2017 +0000
@@ -0,0 +1,219 @@
+/**
+ ******************************************************************************
+ * @file    lis3mdl_class.cpp
+ * @author  AST / EST
+ * @version V0.0.1
+ * @date    14-April-2015
+ * @brief   Implementation file for the LIS3MDL driver 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 "lis3mdl_class.h"
+#include "lis3mdl.h"
+
+/* Methods -------------------------------------------------------------------*/
+/* betzw - based on:
+           X-CUBE-MEMS1/trunk/Drivers/BSP/Components/lis3mdl/lis3mdl.c: revision #400,
+           X-CUBE-MEMS1/trunk: revision #416
+*/
+
+/**
+ * @brief  Set LIS3MDL Initialization
+ * @param  LIS3MDL_Init the configuration setting for the LIS3MDL
+ * @retval MAGNETO_OK in case of success, an error code otherwise
+ */
+MAGNETO_StatusTypeDef LIS3MDL::LIS3MDL_Init(MAGNETO_InitTypeDef *LIS3MDL_Init)
+{
+  uint8_t tmp1 = 0x00;
+  
+  /* Configure the low level interface ---------------------------------------*/
+  if(LIS3MDL_IO_Init() != MAGNETO_OK)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  /****** Magnetic sensor *******/
+  
+  if(LIS3MDL_IO_Read(&tmp1, LIS3MDL_M_CTRL_REG3_M, 1) != MAGNETO_OK)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  /* Conversion mode selection */
+  tmp1 &= ~(LIS3MDL_M_MD_MASK);
+  tmp1 |= LIS3MDL_Init->M_OperatingMode;
+  
+  if(LIS3MDL_IO_Write(&tmp1, LIS3MDL_M_CTRL_REG3_M, 1) != MAGNETO_OK)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  if(LIS3MDL_IO_Read(&tmp1, LIS3MDL_M_CTRL_REG1_M, 1) != MAGNETO_OK)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  /* Output data rate selection */
+  tmp1 &= ~(LIS3MDL_M_DO_MASK);
+  tmp1 |= LIS3MDL_Init->M_OutputDataRate;
+  
+  /* X and Y axes Operative mode selection */
+  tmp1 &= ~(LIS3MDL_M_OM_MASK);
+  tmp1 |= LIS3MDL_Init->M_XYOperativeMode;
+  
+  if(LIS3MDL_IO_Write(&tmp1, LIS3MDL_M_CTRL_REG1_M, 1) != MAGNETO_OK)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  if(LIS3MDL_IO_Read(&tmp1, LIS3MDL_M_CTRL_REG2_M, 1) != MAGNETO_OK)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  /* Full scale selection */
+  tmp1 &= ~(LIS3MDL_M_FS_MASK);
+  tmp1 |= LIS3MDL_Init->M_FullScale;
+  
+  if(LIS3MDL_IO_Write(&tmp1, LIS3MDL_M_CTRL_REG2_M, 1) != MAGNETO_OK)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  /* Configure interrupt lines */
+  LIS3MDL_IO_ITConfig();
+  
+  return MAGNETO_OK;
+  
+  /******************************/
+}
+
+
+/**
+ * @brief  Read ID of LIS3MDL Magnetic sensor
+ * @param  m_id the pointer where the ID of the device is stored
+ * @retval MAGNETO_OK in case of success, an error code otherwise
+ */
+MAGNETO_StatusTypeDef LIS3MDL::LIS3MDL_Read_M_ID(uint8_t *m_id)
+{
+  if(!m_id)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  return LIS3MDL_IO_Read(m_id, LIS3MDL_M_WHO_AM_I_ADDR, 1);
+}
+
+
+/**
+ * @brief  Read raw data from LIS3MDL Magnetic sensor output register
+ * @param  pData the pointer where the magnetometer raw data are stored
+ * @retval MAGNETO_OK in case of success, an error code otherwise
+ */
+MAGNETO_StatusTypeDef LIS3MDL::LIS3MDL_M_GetAxesRaw(int16_t *pData)
+{
+  uint8_t tempReg[2] = {0, 0};
+  
+  if(LIS3MDL_IO_Read(&tempReg[0], (LIS3MDL_M_OUT_X_L_M | LIS3MDL_I2C_MULTIPLEBYTE_CMD),
+                     2) != MAGNETO_OK)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  pData[0] = ((((int16_t)tempReg[1]) << 8) + (int16_t)tempReg[0]);
+  
+  if(LIS3MDL_IO_Read(&tempReg[0], (LIS3MDL_M_OUT_Y_L_M | LIS3MDL_I2C_MULTIPLEBYTE_CMD),
+                     2) != MAGNETO_OK)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  pData[1] = ((((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)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  pData[2] = ((((int16_t)tempReg[1]) << 8) + (int16_t)tempReg[0]);
+  
+  return MAGNETO_OK;
+}
+
+
+/**
+ * @brief Read data from LIS3MDL Magnetic sensor and calculate Magnetic in mgauss
+ * @param pData the pointer where the magnetometer data are stored
+ * @retval MAGNETO_OK in case of success, an error code otherwise
+ */
+MAGNETO_StatusTypeDef LIS3MDL::LIS3MDL_M_GetAxes(int32_t *pData)
+{
+  uint8_t tempReg = 0x00;
+  int16_t pDataRaw[3];
+  float sensitivity = 0;
+  
+  if(LIS3MDL_M_GetAxesRaw(pDataRaw) != MAGNETO_OK)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  if(LIS3MDL_IO_Read(&tempReg, LIS3MDL_M_CTRL_REG2_M, 1) != MAGNETO_OK)
+  {
+    return MAGNETO_ERROR;
+  }
+  
+  tempReg &= LIS3MDL_M_FS_MASK;
+  
+  switch(tempReg)
+  {
+    case LIS3MDL_M_FS_4:
+      sensitivity = 0.14;
+      break;
+    case LIS3MDL_M_FS_8:
+      sensitivity = 0.29;
+      break;
+    case LIS3MDL_M_FS_12:
+      sensitivity = 0.43;
+      break;
+    case LIS3MDL_M_FS_16:
+      sensitivity = 0.58;
+      break;
+  }
+  
+  pData[0] = (int32_t)(pDataRaw[0] * sensitivity);
+  pData[1] = (int32_t)(pDataRaw[1] * sensitivity);
+  pData[2] = (int32_t)(pDataRaw[2] * sensitivity);
+  
+  return MAGNETO_OK;
+}
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lis3mdl_class.h	Tue Sep 05 10:15:14 2017 +0000
@@ -0,0 +1,150 @@
+/**
+ ******************************************************************************
+ * @file    lis3mdl_class.h
+ * @author  AST / EST
+ * @version V0.0.1
+ * @date    14-April-2015
+ * @brief   Header file for component LIS3MDL
+ ******************************************************************************
+ * @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.
+ *
+ ******************************************************************************
+*/
+
+#ifndef __LIS3MDL_CLASS_H
+#define __LIS3MDL_CLASS_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "mbed.h"
+#include "DevI2C.h"
+#include "lis3mdl.h"
+#include "MagneticSensor.h"
+
+/* Classes -------------------------------------------------------------------*/
+/** Class representing a LIS3MDL sensor component
+ */
+class LIS3MDL : public MagneticSensor {
+ public:
+	/** Constructor
+	 * @param[in] i2c device I2C to be used for communication
+	 */
+        LIS3MDL(DevI2C &i2c) : MagneticSensor(), dev_i2c(i2c) {
+	}
+	
+	/** Destructor
+	 */
+        virtual ~LIS3MDL() {}
+	
+	/*** Interface Methods ***/
+	virtual int init(void *init_struct) {
+		return LIS3MDL_Init((MAGNETO_InitTypeDef*)init_struct);
+	}
+
+	virtual int read_id(uint8_t *m_id) {
+		return LIS3MDL_Read_M_ID(m_id);
+	}
+
+	virtual int get_m_axes(int32_t *pData) {
+		return LIS3MDL_M_GetAxes(pData);
+	}
+
+	virtual int get_m_axes_raw(int16_t *pData) {
+		return LIS3MDL_M_GetAxesRaw(pData);
+	}
+
+ 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);
+
+	/**
+	 * @brief  Configures LIS3MDL interrupt lines for NUCLEO boards
+	 */
+	void LIS3MDL_IO_ITConfig(void)
+	{
+		/* To be implemented */
+	}
+
+	/**
+	 * @brief  Configures LIS3MDL I2C interface
+	 * @return MAGNETO_OK in case of success, an error code otherwise
+	 */
+	MAGNETO_StatusTypeDef LIS3MDL_IO_Init(void)
+	{
+		return MAGNETO_OK; /* done in constructor */
+	}
+
+	/**
+	 * @brief      Utility function to read data from LIS3MDL
+	 * @param[out] pBuffer pointer to the byte-array to read data in to
+	 * @param[in]  RegisterAddr specifies internal address register to read from.
+	 * @param[in]  NumByteToRead number of bytes to be read.
+	 * @retval     MAGNETO_OK if ok, 
+	 * @retval     MAGNETO_ERROR if an I2C error has occured
+	 */
+	MAGNETO_StatusTypeDef LIS3MDL_IO_Read(uint8_t* pBuffer, 
+					      uint8_t RegisterAddr, uint16_t NumByteToRead)
+	{
+		int ret = dev_i2c.i2c_read(pBuffer,
+					   LIS3MDL_M_MEMS_ADDRESS,
+					   RegisterAddr,
+					   NumByteToRead);
+		if(ret != 0) {
+			return MAGNETO_ERROR;
+		}
+		return MAGNETO_OK;
+	}
+	
+	/**
+	 * @brief      Utility function to write data to LIS3MDL
+	 * @param[in]  pBuffer pointer to the byte-array data to send
+	 * @param[in]  RegisterAddr specifies internal address register to read from.
+	 * @param[in]  NumByteToWrite number of bytes to write.
+	 * @retval     MAGNETO_OK if ok, 
+	 * @retval     MAGNETO_ERROR if an I2C error has occured
+	 */
+	MAGNETO_StatusTypeDef LIS3MDL_IO_Write(uint8_t* pBuffer, 
+					       uint8_t RegisterAddr, uint16_t NumByteToWrite)
+	{
+		int ret = dev_i2c.i2c_write(pBuffer,
+					    LIS3MDL_M_MEMS_ADDRESS,
+					    RegisterAddr,
+					    NumByteToWrite);
+		if(ret != 0) {
+			return MAGNETO_ERROR;
+		}
+		return MAGNETO_OK;
+	}
+	
+	/*** Instance Variables ***/
+	/* IO Device */
+	DevI2C &dev_i2c;
+};
+
+#endif // __LIS3MDL_CLASS_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/readme.txt	Tue Sep 05 10:15:14 2017 +0000
@@ -0,0 +1,3 @@
+lis3mdl.h corresponds to:
+- X-CUBE-MEMS1/trunk/Drivers/BSP/Components/lis3mdl/lis3mdl.h: revision #402,
+- X-CUBE-MEMS1/trunk: revision #416