removed X-NUCLEO-COMMON and ST-INTERFACES
Dependents: unh-hackathon-example unh-hackathon-example-raw
Fork of X_NUCLEO_IKS01A1 by
Revision 5:8bab0f419849, committed 2015-04-15
- Comitter:
- Wolfgang Betz
- Date:
- Wed Apr 15 12:10:42 2015 +0200
- Parent:
- 4:566f2c41dc1d
- Child:
- 6:8d2abd695c52
- Commit message:
- Added component LIS3MDL
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/Common/Imu6Axes.h Wed Apr 15 12:10:42 2015 +0200 @@ -0,0 +1,64 @@ +/** + ****************************************************************************** + * @file Imu6Axes.h + * @author AST / EST + * @version V0.0.1 + * @date 13-April-2015 + * @brief This file contains the abstract class describing in general + * the interfaces of a 6-axes accelerometer and gyroscope + ****************************************************************************** + * @attention + * + * <h2><center>© 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 from recursive inclusion --------------------------------*/ +#ifndef __IMU_6AXES_CLASS_H +#define __IMU_6AXES_CLASS_H + +/* Includes ------------------------------------------------------------------*/ +#include "mbed.h" +#include "imu_6axes.h" + +/* Classes ------------------------------------------------------------------*/ +/** An abstract class for Imu6Axes components + */ +class Imu6Axes +{ + public: + virtual IMU_6AXES_StatusTypeDef Init(IMU_6AXES_InitTypeDef*) = 0; + virtual IMU_6AXES_StatusTypeDef Read_XG_ID(uint8_t*) = 0; + virtual IMU_6AXES_StatusTypeDef Get_X_Axes(int32_t*) = 0; + virtual IMU_6AXES_StatusTypeDef Get_G_Axes(int32_t*) = 0; + virtual IMU_6AXES_StatusTypeDef Get_X_Sensitivity(float*) = 0; + virtual IMU_6AXES_StatusTypeDef Get_G_Sensitivity(float*) = 0; + + protected: + Imu6Axes(void) {}; +}; + +#endif /* __IMU_6AXES_CLASS_H */
--- a/Components/Common/Imu6Axis.h Tue Apr 14 15:32:06 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/** - ****************************************************************************** - * @file Imu6Axis.h - * @author AST / EST - * @version V0.0.1 - * @date 13-April-2015 - * @brief This file contains the abstract class describing in general - * the interfaces of a 6-axis accelerometer and gyroscope - ****************************************************************************** - * @attention - * - * <h2><center>© 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 from recursive inclusion --------------------------------*/ -#ifndef __IMU_6AXIS_CLASS_H -#define __IMU_6AXIS_CLASS_H - -/* Includes ------------------------------------------------------------------*/ -#include "mbed.h" -#include "imu_6axis.h" - -/* Classes ------------------------------------------------------------------*/ -/** An abstract class for Imu6Axis components - */ -class Imu6Axis -{ - public: - virtual IMU_6AXIS_StatusTypeDef Init(IMU_6AXIS_InitTypeDef*) = 0; - virtual IMU_6AXIS_StatusTypeDef Read_XG_ID(uint8_t*) = 0; - virtual IMU_6AXIS_StatusTypeDef Get_X_Axes(int32_t*) = 0; - virtual IMU_6AXIS_StatusTypeDef Get_G_Axes(int32_t*) = 0; - virtual IMU_6AXIS_StatusTypeDef Get_X_Sensitivity(float*) = 0; - virtual IMU_6AXIS_StatusTypeDef Get_G_Sensitivity(float*) = 0; - - protected: - Imu6Axis(void) {}; -}; - -#endif /* __IMU_6AXIS_CLASS_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/Common/imu_6axes.h Wed Apr 15 12:10:42 2015 +0200 @@ -0,0 +1,146 @@ +/** + ****************************************************************************** + * @file imu_6axes.h + * @author MEMS Application Team + * @version V1.2.0 + * @date 28-January-2015 + * @brief This header file contains the functions prototypes for the + * accelerometer and gyroscope driver. + ****************************************************************************** + * @attention + * + * <h2><center>© 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 __IMU_6AXES_H +#define __IMU_6AXES_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* Includes ------------------------------------------------------------------*/ +#include <stdint.h> + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup Components + * @{ + */ + +/** @addtogroup IMU_6AXES + * @{ + */ + +/** @defgroup IMU_6AXES_Exported_Types + * @{ + */ + +/** + * @brief IMU_6AXES init structure definition + */ +typedef struct +{ + uint8_t G_OutputDataRate; + uint8_t G_FullScale; + uint8_t G_X_Axis; + uint8_t G_Y_Axis; + uint8_t G_Z_Axis; + uint8_t X_OutputDataRate; + uint8_t X_FullScale; + uint8_t X_X_Axis; + uint8_t X_Y_Axis; + uint8_t X_Z_Axis; +}IMU_6AXES_InitTypeDef; + +/** + * @brief IMU_6AXES status enumerator definition + */ +typedef enum { + IMU_6AXES_OK = 0, + IMU_6AXES_ERROR = 1, + IMU_6AXES_TIMEOUT = 2, + IMU_6AXES_NOT_IMPLEMENTED = 3 +} IMU_6AXES_StatusTypeDef; + +/** + * @brief IMU_6AXES component id enumerator definition + */ +typedef enum { + IMU_6AXES_NONE_COMPONENT = 0, + IMU_6AXES_LSM6DS0_COMPONENT = 1, + IMU_6AXES_LSM6DS3_DIL24_COMPONENT = 2 +} IMU_6AXES_ComponentTypeDef; + +/** + * @brief IMU_6AXES driver extended structure definition + */ +typedef struct { + IMU_6AXES_ComponentTypeDef id; /* This id must be unique for each component belonging to this class that wants to extend common class */ + void *pData; /* This pointer is specific for each component */ +}IMU_6AXES_DrvExtTypeDef; + +/** + * @brief IMU_6AXES driver structure definition + */ +typedef struct { + IMU_6AXES_StatusTypeDef (*Init)(IMU_6AXES_InitTypeDef *); + IMU_6AXES_StatusTypeDef (*Read_XG_ID)(uint8_t *); + IMU_6AXES_StatusTypeDef (*Get_X_Axes)(int32_t *); + IMU_6AXES_StatusTypeDef (*Get_G_Axes)(int32_t *); + IMU_6AXES_StatusTypeDef (*Get_X_Sensitivity) (float *); + IMU_6AXES_StatusTypeDef (*Get_G_Sensitivity) (float *); + IMU_6AXES_DrvExtTypeDef *extData; +}IMU_6AXES_DrvTypeDef; + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __IMU_6AXES_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/Components/Common/imu_6axis.h Tue Apr 14 15:32:06 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/** - ****************************************************************************** - * @file imu_6axis.h - * @author MEMS Application Team - * @version V1.2.0 - * @date 28-January-2015 - * @brief This header file contains the functions prototypes for the - * accelerometer and gyroscope driver. - ****************************************************************************** - * @attention - * - * <h2><center>© 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 __IMU_6AXIS_H -#define __IMU_6AXIS_H - -#ifdef __cplusplus -extern "C" { -#endif - - /* Includes ------------------------------------------------------------------*/ -#include <stdint.h> - -/** @addtogroup BSP - * @{ - */ - -/** @addtogroup Components - * @{ - */ - -/** @addtogroup IMU_6AXIS - * @{ - */ - -/** @defgroup IMU_6AXIS_Exported_Types - * @{ - */ - -/** - * @brief IMU_6AXIS init structure definition - */ -typedef struct -{ - uint8_t G_OutputDataRate; - uint8_t G_FullScale; - uint8_t G_X_Axis; - uint8_t G_Y_Axis; - uint8_t G_Z_Axis; - uint8_t X_OutputDataRate; - uint8_t X_FullScale; - uint8_t X_X_Axis; - uint8_t X_Y_Axis; - uint8_t X_Z_Axis; -}IMU_6AXIS_InitTypeDef; - -/** - * @brief IMU_6AXIS status enumerator definition - */ -typedef enum { - IMU_6AXIS_OK = 0, - IMU_6AXIS_ERROR = 1, - IMU_6AXIS_TIMEOUT = 2, - IMU_6AXIS_NOT_IMPLEMENTED = 3 -} IMU_6AXIS_StatusTypeDef; - -/** - * @brief IMU_6AXIS component id enumerator definition - */ -typedef enum { - IMU_6AXIS_NONE_COMPONENT = 0, - IMU_6AXIS_LSM6DS0_COMPONENT = 1, - IMU_6AXIS_LSM6DS3_DIL24_COMPONENT = 2 -} IMU_6AXIS_ComponentTypeDef; - -/** - * @brief IMU_6AXIS driver extended structure definition - */ -typedef struct { - IMU_6AXIS_ComponentTypeDef id; /* This id must be unique for each component belonging to this class that wants to extend common class */ - void *pData; /* This pointer is specific for each component */ -}IMU_6AXIS_DrvExtTypeDef; - -/** - * @brief IMU_6AXIS driver structure definition - */ -typedef struct { - IMU_6AXIS_StatusTypeDef (*Init)(IMU_6AXIS_InitTypeDef *); - IMU_6AXIS_StatusTypeDef (*Read_XG_ID)(uint8_t *); - IMU_6AXIS_StatusTypeDef (*Get_X_Axes)(int32_t *); - IMU_6AXIS_StatusTypeDef (*Get_G_Axes)(int32_t *); - IMU_6AXIS_StatusTypeDef (*Get_X_Sensitivity) (float *); - IMU_6AXIS_StatusTypeDef (*Get_G_Sensitivity) (float *); - IMU_6AXIS_DrvExtTypeDef *extData; -}IMU_6AXIS_DrvTypeDef; - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __IMU_6AXIS_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/Common/readme.txt Wed Apr 15 12:10:42 2015 +0200 @@ -0,0 +1,15 @@ +hum_temp.h corresponds to: +- X-CUBE-MEMS1/trunk/Drivers/BSP/Components/Common/hum_temp.h: revision #184, +- X-CUBE-MEMS1/trunk: revision #293 + +imu_6axes.h corresponds to: +- X-CUBE-MEMS1/trunk/Drivers/BSP/Components/Common/imu_6axes.h: revision #184, +- X-CUBE-MEMS1/trunk: revision #293 + +magneto.h corresponds to: +- X-CUBE-MEMS1/trunk/Drivers/BSP/Components/Common/magneto.h: revision #184, +- X-CUBE-MEMS1/trunk: revision #293 + +pressure.h corresponds to: +- X-CUBE-MEMS1/trunk/Drivers/BSP/Components/Common/pressure.h: revision #184, +- X-CUBE-MEMS1/trunk: revision #293
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/lis3mdl/lis3mdl.h Wed Apr 15 12:10:42 2015 +0200 @@ -0,0 +1,453 @@ +/** + ****************************************************************************** + * @file lis3mdl.h + * @author MEMS Application Team + * @version V1.2.0 + * @date 28-January-2015 + * @brief This file contains definitions for the lis3mdl.c + * firmware driver. + ****************************************************************************** + * @attention + * + * <h2><center>© 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 "../Common/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/Components/lis3mdl/lis3mdl_class.cpp Wed Apr 15 12:10:42 2015 +0200 @@ -0,0 +1,215 @@ +/** + ****************************************************************************** + * @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>© 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 "mbed.h" +#include "lis3mdl_class.h" +#include "lis3mdl.h" +#include "../../x_nucleo_iks01a1_targets.h" + +/* Methods -------------------------------------------------------------------*/ +/* betzw - based on: + X-CUBE-MEMS1/trunk/Drivers/BSP/Components/lis3mdl/lis3mdl.c: revision #184, + X-CUBE-MEMS1/trunk: revision #293 +*/ +/** + * @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; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/lis3mdl/lis3mdl_class.h Wed Apr 15 12:10:42 2015 +0200 @@ -0,0 +1,145 @@ +/** + ****************************************************************************** + * @file lis3mdl_class.h + * @author AST / EST + * @version V0.0.1 + * @date 14-April-2015 + * @brief Header file for component LIS3MDL + ****************************************************************************** + * @attention + * + * <h2><center>© 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 "../Common/Magneto.h" +#include "lis3mdl.h" + +/* Classes -------------------------------------------------------------------*/ +/** Class representing a LIS3MDL sensor component + */ +class LIS3MDL : public Magneto { + public: + /** Constructor + * @param i2c device I2C to be used for communication + */ + LIS3MDL(DevI2C &i2c) : Magneto(), dev_i2c(i2c) { + } + + /*** Interface Methods ***/ + virtual MAGNETO_StatusTypeDef Init(MAGNETO_InitTypeDef *init_struct) { + return LIS3MDL_Init(init_struct); + } + + virtual MAGNETO_StatusTypeDef Read_M_ID(uint8_t *m_id) { + return LIS3MDL_Read_M_ID(m_id); + } + + virtual MAGNETO_StatusTypeDef Get_M_Axes(int32_t *pData) { + return LIS3MDL_M_GetAxes(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 + * @param None + * @retval None + */ + void LIS3MDL_IO_ITConfig(void) + { + /* To be implemented */ + } + + /** + * @brief Configures LIS3MDL I2C interface + * @param None + * @retval 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 STC3115 + * @param pBuffer: pointer to data to be read. + * @param RegisterAddr: specifies internal address register to read from. + * @param NumByteToRead: number of bytes to be read. + * @retval MAGNETO_OK if ok, 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 STC3115 + * @param pBuffer: pointer to buffer to be filled. + * @param RegisterAddr: specifies internal address register to read from. + * @param NumByteToWrite: number of bytes to write. + * @retval 0 if ok, -1 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; + + /* TODO */ +}; + +#endif // __LIS3MDL_CLASS_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Components/lis3mdl/readme.txt Wed Apr 15 12:10:42 2015 +0200 @@ -0,0 +1,3 @@ +lis3mdl.h corresponds to: +- X-CUBE-MEMS1/trunk/Drivers/BSP/Components/lis3mdl/lis3mdl.h: revision #165, +- X-CUBE-MEMS1/trunk: revision #293
--- a/x_nucleo_iks01a1.cpp Tue Apr 14 15:32:06 2015 +0200 +++ b/x_nucleo_iks01a1.cpp Wed Apr 15 12:10:42 2015 +0200 @@ -39,6 +39,7 @@ #include "mbed.h" #include "x_nucleo_iks01a1.h" #include "hts221/hts221_class.h" +#include "lis3mdl/lis3mdl_class.h" /* Static variables ----------------------------------------------------------*/ X_NUCLEO_IKS01A1* X_NUCLEO_IKS01A1::_instance = NULL; @@ -49,10 +50,10 @@ * @brief Constructor */ X_NUCLEO_IKS01A1::X_NUCLEO_IKS01A1(DevI2C *ext_i2c) : dev_i2c(ext_i2c), - ht_sensor(*(new HTS221(*dev_i2c))) + ht_sensor(*(new HTS221(*dev_i2c))), + magnetometer(*(new LIS3MDL(*dev_i2c))) #if 0 // betzw: TODO lps25h(*dev_i2c), - lis3mdl(*dev_i2c), lsm6ds0(*dev_i2c) #endif // 0 {
--- a/x_nucleo_iks01a1.h Tue Apr 14 15:32:06 2015 +0200 +++ b/x_nucleo_iks01a1.h Wed Apr 15 12:10:42 2015 +0200 @@ -45,9 +45,9 @@ #include "x_nucleo_iks01a1_targets.h" #include "DevI2C.h" #include "Common/HumTemp.h" +#include "Common/Magneto.h" #if 0 // betzw: TODO #include "Common/Pressure.h" -#include "Common/Magneto.h" #include "Common/Imu6Axis.h" #endif @@ -81,9 +81,9 @@ DevI2C *dev_i2c; HumTemp &ht_sensor; + Magneto &magnetometer; #if 0 // betzw: TODO Pressure &pressure_sensor; - Magneto &magnetometer; Imu6Axis &gyroscope; #endif // 0
--- a/x_nucleo_iks01a1_i2c.h Tue Apr 14 15:32:06 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -/** -****************************************************************************** -* @file x_cube_mems_i2c.h -* @author AST / EST -* @version V0.0.1 -* @date 28-November-2014 -* @brief Header file for a special I2C class DevI2C which provides some -* helper function for on-board communication -****************************************************************************** -* @attention -* -* <h2><center>© COPYRIGHT(c) 2014 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 from recursive inclusion --------------------------------*/ -#ifndef __X_CUBE_MEMS_I2C_H -#define __X_CUBE_MEMS_I2C_H - -/* Includes ------------------------------------------------------------------*/ -#include "mbed.h" - -/* betzw - TODO: find a better place! */ -typedef struct { - int32_t AXIS_X; - int32_t AXIS_Y; - int32_t AXIS_Z; -} AxesRaw_TypeDef; - -/* Classes -------------------------------------------------------------------*/ -/** Helper class DevI2C providing some common functionality useful for on-board - * communication. - */ -class DevI2C : public I2C -{ - public: - /** Create a DevI2C Master interface, connected to the specified pins - * - * @param sda I2C data line pin - * @param scl I2C clock line pin - */ - DevI2C(PinName sda, PinName scl) : I2C(sda, scl) {}; - - /** - * @brief Writes a buffer from the I2C peripheral device. - * @param pBuffer pointer to data to be read. - * @param DeviceAddr specifies the peripheral device slave address - * (correctly masked). - * @param RegisterAddr specifies internal address register to read from. - * @param NumByteToWrite number of bytes to be written. - * @retval 0 if ok, -1 if an I2C error has occured - * @note on some devices if NumByteToWrite is greater - * than one, the DeviceAddr must be masked correctly - */ - int i2c_write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, - uint16_t NumByteToWrite) - { - int ret; - uint8_t tmp[32]; - - //Acquire mbed mutex/semaphore/lock? - - /* First, send device address. Then, send data and STOP condition */ - tmp[0] = RegisterAddr; - memcpy(tmp+1, pBuffer, NumByteToWrite); - - ret = write(DeviceAddr, (const char*)tmp, NumByteToWrite+1, 0); - - //Release mbed mutex/semaphore/lock? - - if(ret) { - error("%s: dev = %d, reg = %d, num = %d\n", - __func__, DeviceAddr, RegisterAddr, NumByteToWrite); - return -1; - } - return 0; - } - - /** - * @brief Reads a buffer from the I2C peripheral device. - * @param pBuffer pointer to data to be read. - * @param DaviceAddr specifies the peripheral device slave address - * (correctly masked).. - * @param RegisterAddr specifies internal address register to read from. - * @param NumByteToRead number of bytes to be read. - * @retval 0 if ok, -1 if an I2C error has occured - * @note on some devices if NumByteToRead is greater - * than one, the DeviceAddr must be masked correctly - */ - int i2c_read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, - uint16_t NumByteToRead) - { - int ret; - - //Acquire mbed mutex/semaphore/lock? - - /* Send device address, with no STOP condition */ - ret = write(DeviceAddr, (const char*)&RegisterAddr, 1, 1); - if(!ret) { - /* Read data, with STOP condition */ - ret = read(DeviceAddr, (char*)pBuffer, NumByteToRead, 0); - } - - //Release mbed mutex/semaphore/lock? - - if(ret) { - error("%s: dev = %d, reg = %d, num = %d\n", - __func__, DeviceAddr, RegisterAddr, NumByteToRead); - return -1; - } - return 0; - } -}; - -#endif /* __X_CUBE_MEMS_I2C_H */