Firmware Library for X-NUCLEO-IKS01A1 (MEMS Inertial & Environmental Sensors) Expansion Board
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
lis3mdl_class.h
00001 /** 00002 ****************************************************************************** 00003 * @file lis3mdl_class.h 00004 * @author AST / EST 00005 * @version V0.0.1 00006 * @date 14-April-2015 00007 * @brief Header file for component LIS3MDL 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 #ifndef __LIS3MDL_CLASS_H 00039 #define __LIS3MDL_CLASS_H 00040 00041 /* Includes ------------------------------------------------------------------*/ 00042 #include "mbed.h" 00043 #include "DevI2C.h" 00044 #include "lis3mdl.h" 00045 #include "MagneticSensor.h" 00046 00047 /* Classes -------------------------------------------------------------------*/ 00048 /** Class representing a LIS3MDL sensor component 00049 */ 00050 class LIS3MDL : public MagneticSensor { 00051 public: 00052 /** Constructor 00053 * @param[in] i2c device I2C to be used for communication 00054 */ 00055 LIS3MDL(DevI2C &i2c) : MagneticSensor(), dev_i2c(i2c) { 00056 } 00057 00058 /** Destructor 00059 */ 00060 virtual ~LIS3MDL() {} 00061 00062 /*** Interface Methods ***/ 00063 virtual int init(void *init_struct) { 00064 return LIS3MDL_Init((MAGNETO_InitTypeDef*)init_struct); 00065 } 00066 00067 virtual int read_id(uint8_t *m_id) { 00068 return LIS3MDL_Read_M_ID(m_id); 00069 } 00070 00071 virtual int get_m_axes(int32_t *pData) { 00072 return LIS3MDL_M_GetAxes(pData); 00073 } 00074 00075 virtual int get_m_axes_raw(int16_t *pData) { 00076 return LIS3MDL_M_GetAxesRaw(pData); 00077 } 00078 00079 protected: 00080 /*** Methods ***/ 00081 MAGNETO_StatusTypeDef LIS3MDL_Init(MAGNETO_InitTypeDef *LIS3MDL_Init); 00082 MAGNETO_StatusTypeDef LIS3MDL_Read_M_ID(uint8_t *m_id); 00083 MAGNETO_StatusTypeDef LIS3MDL_M_GetAxes(int32_t *pData); 00084 MAGNETO_StatusTypeDef LIS3MDL_M_GetAxesRaw(int16_t *pData); 00085 00086 /** 00087 * @brief Configures LIS3MDL interrupt lines for NUCLEO boards 00088 */ 00089 void LIS3MDL_IO_ITConfig(void) 00090 { 00091 /* To be implemented */ 00092 } 00093 00094 /** 00095 * @brief Configures LIS3MDL I2C interface 00096 * @return MAGNETO_OK in case of success, an error code otherwise 00097 */ 00098 MAGNETO_StatusTypeDef LIS3MDL_IO_Init(void) 00099 { 00100 return MAGNETO_OK; /* done in constructor */ 00101 } 00102 00103 /** 00104 * @brief Utility function to read data from LIS3MDL 00105 * @param[out] pBuffer pointer to the byte-array to read data in to 00106 * @param[in] RegisterAddr specifies internal address register to read from. 00107 * @param[in] NumByteToRead number of bytes to be read. 00108 * @retval MAGNETO_OK if ok, 00109 * @retval MAGNETO_ERROR if an I2C error has occured 00110 */ 00111 MAGNETO_StatusTypeDef LIS3MDL_IO_Read(uint8_t* pBuffer, 00112 uint8_t RegisterAddr, uint16_t NumByteToRead) 00113 { 00114 int ret = dev_i2c.i2c_read(pBuffer, 00115 LIS3MDL_M_MEMS_ADDRESS, 00116 RegisterAddr, 00117 NumByteToRead); 00118 if(ret != 0) { 00119 return MAGNETO_ERROR; 00120 } 00121 return MAGNETO_OK; 00122 } 00123 00124 /** 00125 * @brief Utility function to write data to LIS3MDL 00126 * @param[in] pBuffer pointer to the byte-array data to send 00127 * @param[in] RegisterAddr specifies internal address register to read from. 00128 * @param[in] NumByteToWrite number of bytes to write. 00129 * @retval MAGNETO_OK if ok, 00130 * @retval MAGNETO_ERROR if an I2C error has occured 00131 */ 00132 MAGNETO_StatusTypeDef LIS3MDL_IO_Write(uint8_t* pBuffer, 00133 uint8_t RegisterAddr, uint16_t NumByteToWrite) 00134 { 00135 int ret = dev_i2c.i2c_write(pBuffer, 00136 LIS3MDL_M_MEMS_ADDRESS, 00137 RegisterAddr, 00138 NumByteToWrite); 00139 if(ret != 0) { 00140 return MAGNETO_ERROR; 00141 } 00142 return MAGNETO_OK; 00143 } 00144 00145 /*** Instance Variables ***/ 00146 /* IO Device */ 00147 DevI2C &dev_i2c; 00148 }; 00149 00150 #endif // __LIS3MDL_CLASS_H
Generated on Tue Jul 12 2022 17:19:45 by 1.7.2