Finished project.

Dependencies:   X_NUCLEO_COMMON

Fork of ReferredCoursework2016 by Stage-1 Students SoCEM

Committer:
Wolfgang Betz
Date:
Wed Jun 03 14:57:57 2015 +0200
Revision:
24:92cc9c6e4b2b
Parent:
20:c20c8bd5be6b
Child:
43:2544d064d528
Upgrade to match X-CUBE-MEMS1/trunk, revision #402

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 7:a2bb3d5e12e9 1 /**
Wolfgang Betz 7:a2bb3d5e12e9 2 ******************************************************************************
Wolfgang Betz 7:a2bb3d5e12e9 3 * @file lsm6ds0_class.h
Wolfgang Betz 7:a2bb3d5e12e9 4 * @author AST / EST
Wolfgang Betz 7:a2bb3d5e12e9 5 * @version V0.0.1
Wolfgang Betz 7:a2bb3d5e12e9 6 * @date 14-April-2015
Wolfgang Betz 7:a2bb3d5e12e9 7 * @brief Header file for component LSM6DS0
Wolfgang Betz 7:a2bb3d5e12e9 8 ******************************************************************************
Wolfgang Betz 7:a2bb3d5e12e9 9 * @attention
Wolfgang Betz 7:a2bb3d5e12e9 10 *
Wolfgang Betz 7:a2bb3d5e12e9 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Wolfgang Betz 7:a2bb3d5e12e9 12 *
Wolfgang Betz 7:a2bb3d5e12e9 13 * Redistribution and use in source and binary forms, with or without modification,
Wolfgang Betz 7:a2bb3d5e12e9 14 * are permitted provided that the following conditions are met:
Wolfgang Betz 7:a2bb3d5e12e9 15 * 1. Redistributions of source code must retain the above copyright notice,
Wolfgang Betz 7:a2bb3d5e12e9 16 * this list of conditions and the following disclaimer.
Wolfgang Betz 7:a2bb3d5e12e9 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Wolfgang Betz 7:a2bb3d5e12e9 18 * this list of conditions and the following disclaimer in the documentation
Wolfgang Betz 7:a2bb3d5e12e9 19 * and/or other materials provided with the distribution.
Wolfgang Betz 7:a2bb3d5e12e9 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Wolfgang Betz 7:a2bb3d5e12e9 21 * may be used to endorse or promote products derived from this software
Wolfgang Betz 7:a2bb3d5e12e9 22 * without specific prior written permission.
Wolfgang Betz 7:a2bb3d5e12e9 23 *
Wolfgang Betz 7:a2bb3d5e12e9 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Wolfgang Betz 7:a2bb3d5e12e9 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Wolfgang Betz 7:a2bb3d5e12e9 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Wolfgang Betz 7:a2bb3d5e12e9 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Wolfgang Betz 7:a2bb3d5e12e9 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Wolfgang Betz 7:a2bb3d5e12e9 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Wolfgang Betz 7:a2bb3d5e12e9 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Wolfgang Betz 7:a2bb3d5e12e9 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Wolfgang Betz 7:a2bb3d5e12e9 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Wolfgang Betz 7:a2bb3d5e12e9 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wolfgang Betz 7:a2bb3d5e12e9 34 *
Wolfgang Betz 7:a2bb3d5e12e9 35 ******************************************************************************
Wolfgang Betz 7:a2bb3d5e12e9 36 */
Wolfgang Betz 7:a2bb3d5e12e9 37
Wolfgang Betz 7:a2bb3d5e12e9 38 #ifndef __LSM6DS0_CLASS_H
Wolfgang Betz 7:a2bb3d5e12e9 39 #define __LSM6DS0_CLASS_H
Wolfgang Betz 7:a2bb3d5e12e9 40
Wolfgang Betz 7:a2bb3d5e12e9 41 /* Includes ------------------------------------------------------------------*/
Wolfgang Betz 7:a2bb3d5e12e9 42 #include "mbed.h"
Wolfgang Betz 7:a2bb3d5e12e9 43 #include "DevI2C.h"
Wolfgang Betz 20:c20c8bd5be6b 44 #include "../Common/GyroSensor.h"
Wolfgang Betz 20:c20c8bd5be6b 45 #include "../Common/MotionSensor.h"
Wolfgang Betz 7:a2bb3d5e12e9 46 #include "lsm6ds0.h"
Wolfgang Betz 7:a2bb3d5e12e9 47
Wolfgang Betz 7:a2bb3d5e12e9 48 /* Classes -------------------------------------------------------------------*/
Wolfgang Betz 7:a2bb3d5e12e9 49 /** Class representing a LSM6DS0 sensor component
Wolfgang Betz 7:a2bb3d5e12e9 50 */
Wolfgang Betz 20:c20c8bd5be6b 51 class LSM6DS0 : public GyroSensor, public MotionSensor {
Wolfgang Betz 7:a2bb3d5e12e9 52 public:
Wolfgang Betz 7:a2bb3d5e12e9 53 /** Constructor
Wolfgang Betz 7:a2bb3d5e12e9 54 * @param i2c device I2C to be used for communication
Wolfgang Betz 7:a2bb3d5e12e9 55 */
Wolfgang Betz 20:c20c8bd5be6b 56 LSM6DS0(DevI2C &i2c) : GyroSensor(), MotionSensor(), dev_i2c(i2c) {
Wolfgang Betz 7:a2bb3d5e12e9 57 }
Wolfgang Betz 7:a2bb3d5e12e9 58
Wolfgang Betz 7:a2bb3d5e12e9 59 /*** Interface Methods ***/
Wolfgang Betz 18:1cb4ae9d83e7 60 virtual int Init(void *init_struct) {
Wolfgang Betz 18:1cb4ae9d83e7 61 return LSM6DS0_Init((IMU_6AXES_InitTypeDef*)init_struct);
Wolfgang Betz 7:a2bb3d5e12e9 62 }
Wolfgang Betz 7:a2bb3d5e12e9 63
Wolfgang Betz 20:c20c8bd5be6b 64 virtual int ReadID(uint8_t *xg_id) {
Wolfgang Betz 7:a2bb3d5e12e9 65 return LSM6DS0_Read_XG_ID(xg_id);
Wolfgang Betz 7:a2bb3d5e12e9 66 }
Wolfgang Betz 7:a2bb3d5e12e9 67
Wolfgang Betz 18:1cb4ae9d83e7 68 virtual int Get_X_Axes(int32_t *pData) {
Wolfgang Betz 7:a2bb3d5e12e9 69 return LSM6DS0_X_GetAxes(pData);
Wolfgang Betz 7:a2bb3d5e12e9 70 }
Wolfgang Betz 7:a2bb3d5e12e9 71
Wolfgang Betz 24:92cc9c6e4b2b 72 virtual int Get_X_AxesRaw(int16_t *pData) {
Wolfgang Betz 24:92cc9c6e4b2b 73 return LSM6DS0_X_GetAxesRaw(pData);
Wolfgang Betz 24:92cc9c6e4b2b 74 }
Wolfgang Betz 24:92cc9c6e4b2b 75
Wolfgang Betz 18:1cb4ae9d83e7 76 virtual int Get_G_Axes(int32_t *pData) {
Wolfgang Betz 7:a2bb3d5e12e9 77 return LSM6DS0_G_GetAxes(pData);
Wolfgang Betz 7:a2bb3d5e12e9 78 }
Wolfgang Betz 7:a2bb3d5e12e9 79
Wolfgang Betz 24:92cc9c6e4b2b 80 virtual int Get_G_AxesRaw(int16_t *pData) {
Wolfgang Betz 24:92cc9c6e4b2b 81 return LSM6DS0_G_GetAxesRaw(pData);
Wolfgang Betz 24:92cc9c6e4b2b 82 }
Wolfgang Betz 24:92cc9c6e4b2b 83
Wolfgang Betz 24:92cc9c6e4b2b 84 virtual int Get_X_ODR(float *odr) {
Wolfgang Betz 24:92cc9c6e4b2b 85 return LSM6DS0_X_Get_ODR(odr);
Wolfgang Betz 24:92cc9c6e4b2b 86 }
Wolfgang Betz 24:92cc9c6e4b2b 87
Wolfgang Betz 24:92cc9c6e4b2b 88 virtual int Set_X_ODR(float odr) {
Wolfgang Betz 24:92cc9c6e4b2b 89 return LSM6DS0_X_Set_ODR(odr);
Wolfgang Betz 24:92cc9c6e4b2b 90 }
Wolfgang Betz 24:92cc9c6e4b2b 91
Wolfgang Betz 18:1cb4ae9d83e7 92 virtual int Get_X_Sensitivity(float *pfData) {
Wolfgang Betz 7:a2bb3d5e12e9 93 return LSM6DS0_X_GetSensitivity(pfData);
Wolfgang Betz 7:a2bb3d5e12e9 94 }
Wolfgang Betz 7:a2bb3d5e12e9 95
Wolfgang Betz 24:92cc9c6e4b2b 96 virtual int Get_X_FS(float *fullScale) {
Wolfgang Betz 24:92cc9c6e4b2b 97 return LSM6DS0_X_Get_FS(fullScale);
Wolfgang Betz 24:92cc9c6e4b2b 98 }
Wolfgang Betz 24:92cc9c6e4b2b 99
Wolfgang Betz 24:92cc9c6e4b2b 100 virtual int Set_X_FS(float fullScale) {
Wolfgang Betz 24:92cc9c6e4b2b 101 return LSM6DS0_X_Set_FS(fullScale);
Wolfgang Betz 24:92cc9c6e4b2b 102 }
Wolfgang Betz 24:92cc9c6e4b2b 103
Wolfgang Betz 24:92cc9c6e4b2b 104 virtual int Get_G_ODR(float *odr) {
Wolfgang Betz 24:92cc9c6e4b2b 105 return LSM6DS0_G_Get_ODR(odr);
Wolfgang Betz 24:92cc9c6e4b2b 106 }
Wolfgang Betz 24:92cc9c6e4b2b 107
Wolfgang Betz 24:92cc9c6e4b2b 108 virtual int Set_G_ODR(float odr) {
Wolfgang Betz 24:92cc9c6e4b2b 109 return LSM6DS0_G_Set_ODR(odr);
Wolfgang Betz 24:92cc9c6e4b2b 110 }
Wolfgang Betz 24:92cc9c6e4b2b 111
Wolfgang Betz 18:1cb4ae9d83e7 112 virtual int Get_G_Sensitivity(float *pfData) {
Wolfgang Betz 7:a2bb3d5e12e9 113 return LSM6DS0_G_GetSensitivity(pfData);
Wolfgang Betz 7:a2bb3d5e12e9 114 }
Wolfgang Betz 7:a2bb3d5e12e9 115
Wolfgang Betz 24:92cc9c6e4b2b 116 virtual int Get_G_FS(float *fullScale) {
Wolfgang Betz 24:92cc9c6e4b2b 117 return LSM6DS0_G_Get_FS(fullScale);
Wolfgang Betz 24:92cc9c6e4b2b 118 }
Wolfgang Betz 24:92cc9c6e4b2b 119
Wolfgang Betz 24:92cc9c6e4b2b 120 virtual int Set_G_FS(float fullScale) {
Wolfgang Betz 24:92cc9c6e4b2b 121 return LSM6DS0_G_Set_FS(fullScale);
Wolfgang Betz 24:92cc9c6e4b2b 122 }
Wolfgang Betz 24:92cc9c6e4b2b 123
Wolfgang Betz 7:a2bb3d5e12e9 124 protected:
Wolfgang Betz 7:a2bb3d5e12e9 125 /*** Methods ***/
Wolfgang Betz 7:a2bb3d5e12e9 126 IMU_6AXES_StatusTypeDef LSM6DS0_Init(IMU_6AXES_InitTypeDef *LSM6DS0_Init);
Wolfgang Betz 7:a2bb3d5e12e9 127 IMU_6AXES_StatusTypeDef LSM6DS0_Read_XG_ID(uint8_t *xg_id);
Wolfgang Betz 7:a2bb3d5e12e9 128 IMU_6AXES_StatusTypeDef LSM6DS0_X_GetAxes(int32_t *pData);
Wolfgang Betz 24:92cc9c6e4b2b 129 IMU_6AXES_StatusTypeDef LSM6DS0_X_GetAxesRaw(int16_t *pData);
Wolfgang Betz 7:a2bb3d5e12e9 130 IMU_6AXES_StatusTypeDef LSM6DS0_G_GetAxes(int32_t *pData);
Wolfgang Betz 24:92cc9c6e4b2b 131 IMU_6AXES_StatusTypeDef LSM6DS0_G_GetAxesRaw(int16_t *pData);
Wolfgang Betz 24:92cc9c6e4b2b 132 IMU_6AXES_StatusTypeDef LSM6DS0_X_Get_ODR( float *odr );
Wolfgang Betz 24:92cc9c6e4b2b 133 IMU_6AXES_StatusTypeDef LSM6DS0_X_Set_ODR( float odr );
Wolfgang Betz 7:a2bb3d5e12e9 134 IMU_6AXES_StatusTypeDef LSM6DS0_X_GetSensitivity( float *pfData );
Wolfgang Betz 24:92cc9c6e4b2b 135 IMU_6AXES_StatusTypeDef LSM6DS0_X_Get_FS( float *fullScale );
Wolfgang Betz 24:92cc9c6e4b2b 136 IMU_6AXES_StatusTypeDef LSM6DS0_X_Set_FS( float fullScale );
Wolfgang Betz 24:92cc9c6e4b2b 137 IMU_6AXES_StatusTypeDef LSM6DS0_G_Get_ODR( float *odr );
Wolfgang Betz 24:92cc9c6e4b2b 138 IMU_6AXES_StatusTypeDef LSM6DS0_G_Set_ODR( float odr );
Wolfgang Betz 7:a2bb3d5e12e9 139 IMU_6AXES_StatusTypeDef LSM6DS0_G_GetSensitivity( float *pfData );
Wolfgang Betz 24:92cc9c6e4b2b 140 IMU_6AXES_StatusTypeDef LSM6DS0_G_Get_FS( float *fullScale );
Wolfgang Betz 24:92cc9c6e4b2b 141 IMU_6AXES_StatusTypeDef LSM6DS0_G_Set_FS( float fullScale );
Wolfgang Betz 24:92cc9c6e4b2b 142
Wolfgang Betz 24:92cc9c6e4b2b 143 IMU_6AXES_StatusTypeDef LSM6DS0_X_Set_Axes_Status(uint8_t enableX, uint8_t enableY, uint8_t enableZ);
Wolfgang Betz 24:92cc9c6e4b2b 144 IMU_6AXES_StatusTypeDef LSM6DS0_G_Set_Axes_Status(uint8_t enableX, uint8_t enableY, uint8_t enableZ);
Wolfgang Betz 7:a2bb3d5e12e9 145
Wolfgang Betz 7:a2bb3d5e12e9 146 /**
Wolfgang Betz 7:a2bb3d5e12e9 147 * @brief Configures LSM6DS0 interrupt lines for NUCLEO boards
Wolfgang Betz 7:a2bb3d5e12e9 148 * @param None
Wolfgang Betz 7:a2bb3d5e12e9 149 * @retval None
Wolfgang Betz 7:a2bb3d5e12e9 150 */
Wolfgang Betz 7:a2bb3d5e12e9 151 void LSM6DS0_IO_ITConfig(void)
Wolfgang Betz 7:a2bb3d5e12e9 152 {
Wolfgang Betz 7:a2bb3d5e12e9 153 /* To be implemented */
Wolfgang Betz 7:a2bb3d5e12e9 154 }
Wolfgang Betz 7:a2bb3d5e12e9 155
Wolfgang Betz 7:a2bb3d5e12e9 156 /**
Wolfgang Betz 7:a2bb3d5e12e9 157 * @brief Configures LSM6DS0 I2C interface
Wolfgang Betz 7:a2bb3d5e12e9 158 * @param None
Wolfgang Betz 7:a2bb3d5e12e9 159 * @retval IMU_6AXES_OK in case of success, an error code otherwise
Wolfgang Betz 7:a2bb3d5e12e9 160 */
Wolfgang Betz 7:a2bb3d5e12e9 161 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Init(void)
Wolfgang Betz 7:a2bb3d5e12e9 162 {
Wolfgang Betz 7:a2bb3d5e12e9 163 return IMU_6AXES_OK; /* done in constructor */
Wolfgang Betz 7:a2bb3d5e12e9 164 }
Wolfgang Betz 7:a2bb3d5e12e9 165
Wolfgang Betz 7:a2bb3d5e12e9 166 /**
Wolfgang Betz 7:a2bb3d5e12e9 167 * @brief utility function to read data from STC3115
Wolfgang Betz 7:a2bb3d5e12e9 168 * @param pBuffer: pointer to data to be read.
Wolfgang Betz 7:a2bb3d5e12e9 169 * @param RegisterAddr: specifies internal address register to read from.
Wolfgang Betz 7:a2bb3d5e12e9 170 * @param NumByteToRead: number of bytes to be read.
Wolfgang Betz 7:a2bb3d5e12e9 171 * @retval IMU_6AXES_OK if ok, IMU_6AXES_ERROR if an I2C error has occured
Wolfgang Betz 7:a2bb3d5e12e9 172 */
Wolfgang Betz 7:a2bb3d5e12e9 173 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Read(uint8_t* pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 174 uint8_t RegisterAddr, uint16_t NumByteToRead)
Wolfgang Betz 7:a2bb3d5e12e9 175 {
Wolfgang Betz 7:a2bb3d5e12e9 176 int ret = dev_i2c.i2c_read(pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 177 LSM6DS0_XG_MEMS_ADDRESS,
Wolfgang Betz 7:a2bb3d5e12e9 178 RegisterAddr,
Wolfgang Betz 7:a2bb3d5e12e9 179 NumByteToRead);
Wolfgang Betz 7:a2bb3d5e12e9 180 if(ret != 0) {
Wolfgang Betz 7:a2bb3d5e12e9 181 return IMU_6AXES_ERROR;
Wolfgang Betz 7:a2bb3d5e12e9 182 }
Wolfgang Betz 7:a2bb3d5e12e9 183 return IMU_6AXES_OK;
Wolfgang Betz 7:a2bb3d5e12e9 184 }
Wolfgang Betz 7:a2bb3d5e12e9 185
Wolfgang Betz 7:a2bb3d5e12e9 186 /**
Wolfgang Betz 7:a2bb3d5e12e9 187 * @brief utility function to write data to STC3115
Wolfgang Betz 7:a2bb3d5e12e9 188 * @param pBuffer: pointer to buffer to be filled.
Wolfgang Betz 7:a2bb3d5e12e9 189 * @param RegisterAddr: specifies internal address register to read from.
Wolfgang Betz 7:a2bb3d5e12e9 190 * @param NumByteToWrite: number of bytes to write.
Wolfgang Betz 7:a2bb3d5e12e9 191 * @retval 0 if ok, -1 if an I2C error has occured
Wolfgang Betz 7:a2bb3d5e12e9 192 */
Wolfgang Betz 7:a2bb3d5e12e9 193 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Write(uint8_t* pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 194 uint8_t RegisterAddr, uint16_t NumByteToWrite)
Wolfgang Betz 7:a2bb3d5e12e9 195 {
Wolfgang Betz 7:a2bb3d5e12e9 196 int ret = dev_i2c.i2c_write(pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 197 LSM6DS0_XG_MEMS_ADDRESS,
Wolfgang Betz 7:a2bb3d5e12e9 198 RegisterAddr,
Wolfgang Betz 7:a2bb3d5e12e9 199 NumByteToWrite);
Wolfgang Betz 7:a2bb3d5e12e9 200 if(ret != 0) {
Wolfgang Betz 7:a2bb3d5e12e9 201 return IMU_6AXES_ERROR;
Wolfgang Betz 7:a2bb3d5e12e9 202 }
Wolfgang Betz 7:a2bb3d5e12e9 203 return IMU_6AXES_OK;
Wolfgang Betz 7:a2bb3d5e12e9 204 }
Wolfgang Betz 7:a2bb3d5e12e9 205
Wolfgang Betz 7:a2bb3d5e12e9 206 /*** Instance Variables ***/
Wolfgang Betz 7:a2bb3d5e12e9 207 /* IO Device */
Wolfgang Betz 7:a2bb3d5e12e9 208 DevI2C &dev_i2c;
Wolfgang Betz 7:a2bb3d5e12e9 209 };
Wolfgang Betz 7:a2bb3d5e12e9 210
Wolfgang Betz 7:a2bb3d5e12e9 211 #endif // __LSM6DS0_CLASS_H