Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: MultiTech_Dragonfly_2015_ATT_Gov_Solutions_Hackathon_Example HelloWorld_IKS01A1 LoRaWAN-test-10secs ServoMotorDemo ... more
Fork of X_NUCLEO_IKS01A1 by
X-NUCLEO-IKS01A1 MEMS Inertial & Environmental Sensor Nucleo Expansion Board Firmware Package
Introduction
This firmware package includes Components Device Drivers and Board Support Package for STMicroelectronics' X-NUCLEO-IKS01A1 MEMS Inertial & Environmental Sensors Nucleo Expansion Board.
Firmware Library
Class X_NUCLEO_IKS01A1 is intended to represent the MEMS inertial & environmental sensors expansion board with the same name.
The expansion board is basically featuring four IPs:
- a HTS221 Relative Humidity and Temperature Sensor,
- a LIS3MDL 3-Axis Magnetometer,
- a LPS25H MEMS Pressure Sensor, and
- a LSM6DS0 3D Accelerometer and 3D Gyroscope
The expansion board features also a DIL 24-pin socket which makes it possible to add further MEMS adapters and other sensors (e.g. UV index).
It is intentionally implemented as a singleton because only one X_NUCLEO_IKS01A1 at a time might be deployed in a HW component stack. In order to get the singleton instance you have to call class method `Instance()`, e.g.:
// Sensors expansion board singleton instance static X_NUCLEO_IKS01A1 *sensors_expansion_board = X_NUCLEO_IKS01A1::Instance();
Furthermore, library ST_INTERFACES contains all abstract classes which together constitute the common API to which all existing and future ST components will adhere to.
Example Applications
Components/lis3mdl/lis3mdl_class.h@57:04563dd74269, 2015-06-15 (annotated)
- Committer:
- Wolfgang Betz 
- Date:
- Mon Jun 15 10:28:49 2015 +0200
- Revision:
- 57:04563dd74269
- Parent:
- 54:2a676c734b30
- Child:
- 88:7b8d3316d753
Further fine-tuning of doxygen comments
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| Wolfgang Betz | 5:8bab0f419849 | 1 | /** | 
| Wolfgang Betz | 5:8bab0f419849 | 2 | ****************************************************************************** | 
| Wolfgang Betz | 5:8bab0f419849 | 3 | * @file lis3mdl_class.h | 
| Wolfgang Betz | 5:8bab0f419849 | 4 | * @author AST / EST | 
| Wolfgang Betz | 5:8bab0f419849 | 5 | * @version V0.0.1 | 
| Wolfgang Betz | 5:8bab0f419849 | 6 | * @date 14-April-2015 | 
| Wolfgang Betz | 5:8bab0f419849 | 7 | * @brief Header file for component LIS3MDL | 
| Wolfgang Betz | 5:8bab0f419849 | 8 | ****************************************************************************** | 
| Wolfgang Betz | 5:8bab0f419849 | 9 | * @attention | 
| Wolfgang Betz | 5:8bab0f419849 | 10 | * | 
| Wolfgang Betz | 5:8bab0f419849 | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | 
| Wolfgang Betz | 5:8bab0f419849 | 12 | * | 
| Wolfgang Betz | 5:8bab0f419849 | 13 | * Redistribution and use in source and binary forms, with or without modification, | 
| Wolfgang Betz | 5:8bab0f419849 | 14 | * are permitted provided that the following conditions are met: | 
| Wolfgang Betz | 5:8bab0f419849 | 15 | * 1. Redistributions of source code must retain the above copyright notice, | 
| Wolfgang Betz | 5:8bab0f419849 | 16 | * this list of conditions and the following disclaimer. | 
| Wolfgang Betz | 5:8bab0f419849 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, | 
| Wolfgang Betz | 5:8bab0f419849 | 18 | * this list of conditions and the following disclaimer in the documentation | 
| Wolfgang Betz | 5:8bab0f419849 | 19 | * and/or other materials provided with the distribution. | 
| Wolfgang Betz | 5:8bab0f419849 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors | 
| Wolfgang Betz | 5:8bab0f419849 | 21 | * may be used to endorse or promote products derived from this software | 
| Wolfgang Betz | 5:8bab0f419849 | 22 | * without specific prior written permission. | 
| Wolfgang Betz | 5:8bab0f419849 | 23 | * | 
| Wolfgang Betz | 5:8bab0f419849 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
| Wolfgang Betz | 5:8bab0f419849 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
| Wolfgang Betz | 5:8bab0f419849 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
| Wolfgang Betz | 5:8bab0f419849 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
| Wolfgang Betz | 5:8bab0f419849 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
| Wolfgang Betz | 5:8bab0f419849 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
| Wolfgang Betz | 5:8bab0f419849 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
| Wolfgang Betz | 5:8bab0f419849 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
| Wolfgang Betz | 5:8bab0f419849 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| Wolfgang Betz | 5:8bab0f419849 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| Wolfgang Betz | 5:8bab0f419849 | 34 | * | 
| Wolfgang Betz | 5:8bab0f419849 | 35 | ****************************************************************************** | 
| Wolfgang Betz | 5:8bab0f419849 | 36 | */ | 
| Wolfgang Betz | 5:8bab0f419849 | 37 | |
| Wolfgang Betz | 5:8bab0f419849 | 38 | #ifndef __LIS3MDL_CLASS_H | 
| Wolfgang Betz | 5:8bab0f419849 | 39 | #define __LIS3MDL_CLASS_H | 
| Wolfgang Betz | 5:8bab0f419849 | 40 | |
| Wolfgang Betz | 5:8bab0f419849 | 41 | /* Includes ------------------------------------------------------------------*/ | 
| Wolfgang Betz | 5:8bab0f419849 | 42 | #include "mbed.h" | 
| Wolfgang Betz | 5:8bab0f419849 | 43 | #include "DevI2C.h" | 
| Wolfgang Betz | 57:04563dd74269 | 44 | #include "lis3mdl.h" | 
| Wolfgang Betz | 43:2544d064d528 | 45 | #include "../Interfaces/MagneticSensor.h" | 
| Wolfgang Betz | 5:8bab0f419849 | 46 | |
| Wolfgang Betz | 5:8bab0f419849 | 47 | /* Classes -------------------------------------------------------------------*/ | 
| Wolfgang Betz | 5:8bab0f419849 | 48 | /** Class representing a LIS3MDL sensor component | 
| Wolfgang Betz | 5:8bab0f419849 | 49 | */ | 
| Wolfgang Betz | 20:c20c8bd5be6b | 50 | class LIS3MDL : public MagneticSensor { | 
| Wolfgang Betz | 5:8bab0f419849 | 51 | public: | 
| Wolfgang Betz | 5:8bab0f419849 | 52 | /** Constructor | 
| Wolfgang Betz | 54:2a676c734b30 | 53 | * @param[in] i2c device I2C to be used for communication | 
| Wolfgang Betz | 5:8bab0f419849 | 54 | */ | 
| Wolfgang Betz | 20:c20c8bd5be6b | 55 | LIS3MDL(DevI2C &i2c) : MagneticSensor(), dev_i2c(i2c) { | 
| Wolfgang Betz | 5:8bab0f419849 | 56 | } | 
| Wolfgang Betz | 5:8bab0f419849 | 57 | |
| Wolfgang Betz | 44:d757094f6229 | 58 | /** Destructor | 
| Wolfgang Betz | 44:d757094f6229 | 59 | */ | 
| Wolfgang Betz | 44:d757094f6229 | 60 | virtual ~LIS3MDL() {} | 
| Wolfgang Betz | 44:d757094f6229 | 61 | |
| Wolfgang Betz | 5:8bab0f419849 | 62 | /*** Interface Methods ***/ | 
| Wolfgang Betz | 18:1cb4ae9d83e7 | 63 | virtual int Init(void *init_struct) { | 
| Wolfgang Betz | 18:1cb4ae9d83e7 | 64 | return LIS3MDL_Init((MAGNETO_InitTypeDef*)init_struct); | 
| Wolfgang Betz | 5:8bab0f419849 | 65 | } | 
| Wolfgang Betz | 5:8bab0f419849 | 66 | |
| Wolfgang Betz | 20:c20c8bd5be6b | 67 | virtual int ReadID(uint8_t *m_id) { | 
| Wolfgang Betz | 5:8bab0f419849 | 68 | return LIS3MDL_Read_M_ID(m_id); | 
| Wolfgang Betz | 5:8bab0f419849 | 69 | } | 
| Wolfgang Betz | 5:8bab0f419849 | 70 | |
| Wolfgang Betz | 18:1cb4ae9d83e7 | 71 | virtual int Get_M_Axes(int32_t *pData) { | 
| Wolfgang Betz | 5:8bab0f419849 | 72 | return LIS3MDL_M_GetAxes(pData); | 
| Wolfgang Betz | 5:8bab0f419849 | 73 | } | 
| Wolfgang Betz | 5:8bab0f419849 | 74 | |
| Wolfgang Betz | 24:92cc9c6e4b2b | 75 | virtual int Get_M_AxesRaw(int16_t *pData) { | 
| Wolfgang Betz | 24:92cc9c6e4b2b | 76 | return LIS3MDL_M_GetAxesRaw(pData); | 
| Wolfgang Betz | 24:92cc9c6e4b2b | 77 | } | 
| Wolfgang Betz | 24:92cc9c6e4b2b | 78 | |
| Wolfgang Betz | 5:8bab0f419849 | 79 | protected: | 
| Wolfgang Betz | 5:8bab0f419849 | 80 | /*** Methods ***/ | 
| Wolfgang Betz | 5:8bab0f419849 | 81 | MAGNETO_StatusTypeDef LIS3MDL_Init(MAGNETO_InitTypeDef *LIS3MDL_Init); | 
| Wolfgang Betz | 5:8bab0f419849 | 82 | MAGNETO_StatusTypeDef LIS3MDL_Read_M_ID(uint8_t *m_id); | 
| Wolfgang Betz | 5:8bab0f419849 | 83 | MAGNETO_StatusTypeDef LIS3MDL_M_GetAxes(int32_t *pData); | 
| Wolfgang Betz | 5:8bab0f419849 | 84 | MAGNETO_StatusTypeDef LIS3MDL_M_GetAxesRaw(int16_t *pData); | 
| Wolfgang Betz | 5:8bab0f419849 | 85 | |
| Wolfgang Betz | 5:8bab0f419849 | 86 | /** | 
| Wolfgang Betz | 5:8bab0f419849 | 87 | * @brief Configures LIS3MDL interrupt lines for NUCLEO boards | 
| Wolfgang Betz | 5:8bab0f419849 | 88 | */ | 
| Wolfgang Betz | 5:8bab0f419849 | 89 | void LIS3MDL_IO_ITConfig(void) | 
| Wolfgang Betz | 5:8bab0f419849 | 90 | { | 
| Wolfgang Betz | 5:8bab0f419849 | 91 | /* To be implemented */ | 
| Wolfgang Betz | 5:8bab0f419849 | 92 | } | 
| Wolfgang Betz | 5:8bab0f419849 | 93 | |
| Wolfgang Betz | 5:8bab0f419849 | 94 | /** | 
| Wolfgang Betz | 5:8bab0f419849 | 95 | * @brief Configures LIS3MDL I2C interface | 
| Wolfgang Betz | 36:8c73dbe43cf2 | 96 | * @return MAGNETO_OK in case of success, an error code otherwise | 
| Wolfgang Betz | 5:8bab0f419849 | 97 | */ | 
| Wolfgang Betz | 5:8bab0f419849 | 98 | MAGNETO_StatusTypeDef LIS3MDL_IO_Init(void) | 
| Wolfgang Betz | 5:8bab0f419849 | 99 | { | 
| Wolfgang Betz | 5:8bab0f419849 | 100 | return MAGNETO_OK; /* done in constructor */ | 
| Wolfgang Betz | 5:8bab0f419849 | 101 | } | 
| Wolfgang Betz | 5:8bab0f419849 | 102 | |
| Wolfgang Betz | 5:8bab0f419849 | 103 | /** | 
| Wolfgang Betz | 57:04563dd74269 | 104 | * @brief Utility function to read data from LIS3MDL | 
| Wolfgang Betz | 57:04563dd74269 | 105 | * @param[out] pBuffer pointer to the byte-array to read data in to | 
| Wolfgang Betz | 57:04563dd74269 | 106 | * @param[in] RegisterAddr specifies internal address register to read from. | 
| Wolfgang Betz | 57:04563dd74269 | 107 | * @param[in] NumByteToRead number of bytes to be read. | 
| Wolfgang Betz | 57:04563dd74269 | 108 | * @retval MAGNETO_OK if ok, | 
| Wolfgang Betz | 57:04563dd74269 | 109 | * @retval MAGNETO_ERROR if an I2C error has occured | 
| Wolfgang Betz | 5:8bab0f419849 | 110 | */ | 
| Wolfgang Betz | 5:8bab0f419849 | 111 | MAGNETO_StatusTypeDef LIS3MDL_IO_Read(uint8_t* pBuffer, | 
| Wolfgang Betz | 5:8bab0f419849 | 112 | uint8_t RegisterAddr, uint16_t NumByteToRead) | 
| Wolfgang Betz | 5:8bab0f419849 | 113 | { | 
| Wolfgang Betz | 5:8bab0f419849 | 114 | int ret = dev_i2c.i2c_read(pBuffer, | 
| Wolfgang Betz | 5:8bab0f419849 | 115 | LIS3MDL_M_MEMS_ADDRESS, | 
| Wolfgang Betz | 5:8bab0f419849 | 116 | RegisterAddr, | 
| Wolfgang Betz | 5:8bab0f419849 | 117 | NumByteToRead); | 
| Wolfgang Betz | 5:8bab0f419849 | 118 | if(ret != 0) { | 
| Wolfgang Betz | 5:8bab0f419849 | 119 | return MAGNETO_ERROR; | 
| Wolfgang Betz | 5:8bab0f419849 | 120 | } | 
| Wolfgang Betz | 5:8bab0f419849 | 121 | return MAGNETO_OK; | 
| Wolfgang Betz | 5:8bab0f419849 | 122 | } | 
| Wolfgang Betz | 5:8bab0f419849 | 123 | |
| Wolfgang Betz | 5:8bab0f419849 | 124 | /** | 
| Wolfgang Betz | 57:04563dd74269 | 125 | * @brief Utility function to write data to LIS3MDL | 
| Wolfgang Betz | 57:04563dd74269 | 126 | * @param[in] pBuffer pointer to the byte-array data to send | 
| Wolfgang Betz | 57:04563dd74269 | 127 | * @param[in] RegisterAddr specifies internal address register to read from. | 
| Wolfgang Betz | 57:04563dd74269 | 128 | * @param[in] NumByteToWrite number of bytes to write. | 
| Wolfgang Betz | 57:04563dd74269 | 129 | * @retval MAGNETO_OK if ok, | 
| Wolfgang Betz | 57:04563dd74269 | 130 | * @retval MAGNETO_ERROR if an I2C error has occured | 
| Wolfgang Betz | 5:8bab0f419849 | 131 | */ | 
| Wolfgang Betz | 5:8bab0f419849 | 132 | MAGNETO_StatusTypeDef LIS3MDL_IO_Write(uint8_t* pBuffer, | 
| Wolfgang Betz | 5:8bab0f419849 | 133 | uint8_t RegisterAddr, uint16_t NumByteToWrite) | 
| Wolfgang Betz | 5:8bab0f419849 | 134 | { | 
| Wolfgang Betz | 5:8bab0f419849 | 135 | int ret = dev_i2c.i2c_write(pBuffer, | 
| Wolfgang Betz | 5:8bab0f419849 | 136 | LIS3MDL_M_MEMS_ADDRESS, | 
| Wolfgang Betz | 5:8bab0f419849 | 137 | RegisterAddr, | 
| Wolfgang Betz | 5:8bab0f419849 | 138 | NumByteToWrite); | 
| Wolfgang Betz | 5:8bab0f419849 | 139 | if(ret != 0) { | 
| Wolfgang Betz | 5:8bab0f419849 | 140 | return MAGNETO_ERROR; | 
| Wolfgang Betz | 5:8bab0f419849 | 141 | } | 
| Wolfgang Betz | 5:8bab0f419849 | 142 | return MAGNETO_OK; | 
| Wolfgang Betz | 5:8bab0f419849 | 143 | } | 
| Wolfgang Betz | 5:8bab0f419849 | 144 | |
| Wolfgang Betz | 5:8bab0f419849 | 145 | /*** Instance Variables ***/ | 
| Wolfgang Betz | 5:8bab0f419849 | 146 | /* IO Device */ | 
| Wolfgang Betz | 5:8bab0f419849 | 147 | DevI2C &dev_i2c; | 
| Wolfgang Betz | 5:8bab0f419849 | 148 | }; | 
| Wolfgang Betz | 5:8bab0f419849 | 149 | |
| Wolfgang Betz | 5:8bab0f419849 | 150 | #endif // __LIS3MDL_CLASS_H | 

 X-NUCLEO-IKS01A1  - Motion MEMS and Environmental Sensors
            X-NUCLEO-IKS01A1  - Motion MEMS and Environmental Sensors