Finished project.

Dependencies:   X_NUCLEO_COMMON

Fork of ReferredCoursework2016 by Stage-1 Students SoCEM

Committer:
Wolfgang Betz
Date:
Mon Jun 08 18:04:19 2015 +0200
Revision:
50:f507d4465c31
Parent:
46:badcff0675e8
Child:
54:2a676c734b30
Cleanup interfaces from not yet comfirmed methods

Potential generic methods to be put into interface classes from which to
derive other interfaces from are (among others):
- virtual int PowerOff(void) { /* not yet implemented */ return 0; }
- virtual int Reset(void) { /* not yet implemented */ return 0; }

- virtual void ConfigIT(uint16_t) { /* not yet implemented */ }
- virtual void EnableIT(uint8_t) { /* not yet implemented */ }
- virtual void DisableIT(uint8_t) { /* not yet implemented */ }
- virtual uint8_t ITStatus(uint16_t, uint16_t) { /* not yet implemented */ return 0; }
- virtual void ClearIT(uint16_t, uint16_t) { /* not yet implemented */ }
- virtual void AttachIT(void (*fptr)(void)) { /* not yet implemented */ }

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 43:2544d064d528 44 #include "../Interfaces/GyroSensor.h"
Wolfgang Betz 43:2544d064d528 45 #include "../Interfaces/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 44:d757094f6229 59 /** Destructor
Wolfgang Betz 44:d757094f6229 60 */
Wolfgang Betz 44:d757094f6229 61 virtual ~LSM6DS0() {}
Wolfgang Betz 44:d757094f6229 62
Wolfgang Betz 7:a2bb3d5e12e9 63 /*** Interface Methods ***/
Wolfgang Betz 18:1cb4ae9d83e7 64 virtual int Init(void *init_struct) {
Wolfgang Betz 18:1cb4ae9d83e7 65 return LSM6DS0_Init((IMU_6AXES_InitTypeDef*)init_struct);
Wolfgang Betz 7:a2bb3d5e12e9 66 }
Wolfgang Betz 7:a2bb3d5e12e9 67
Wolfgang Betz 20:c20c8bd5be6b 68 virtual int ReadID(uint8_t *xg_id) {
Wolfgang Betz 7:a2bb3d5e12e9 69 return LSM6DS0_Read_XG_ID(xg_id);
Wolfgang Betz 7:a2bb3d5e12e9 70 }
Wolfgang Betz 7:a2bb3d5e12e9 71
Wolfgang Betz 18:1cb4ae9d83e7 72 virtual int Get_X_Axes(int32_t *pData) {
Wolfgang Betz 7:a2bb3d5e12e9 73 return LSM6DS0_X_GetAxes(pData);
Wolfgang Betz 7:a2bb3d5e12e9 74 }
Wolfgang Betz 7:a2bb3d5e12e9 75
Wolfgang Betz 24:92cc9c6e4b2b 76 virtual int Get_X_AxesRaw(int16_t *pData) {
Wolfgang Betz 24:92cc9c6e4b2b 77 return LSM6DS0_X_GetAxesRaw(pData);
Wolfgang Betz 24:92cc9c6e4b2b 78 }
Wolfgang Betz 24:92cc9c6e4b2b 79
Wolfgang Betz 18:1cb4ae9d83e7 80 virtual int Get_G_Axes(int32_t *pData) {
Wolfgang Betz 7:a2bb3d5e12e9 81 return LSM6DS0_G_GetAxes(pData);
Wolfgang Betz 7:a2bb3d5e12e9 82 }
Wolfgang Betz 7:a2bb3d5e12e9 83
Wolfgang Betz 24:92cc9c6e4b2b 84 virtual int Get_G_AxesRaw(int16_t *pData) {
Wolfgang Betz 24:92cc9c6e4b2b 85 return LSM6DS0_G_GetAxesRaw(pData);
Wolfgang Betz 24:92cc9c6e4b2b 86 }
Wolfgang Betz 24:92cc9c6e4b2b 87
Wolfgang Betz 24:92cc9c6e4b2b 88 virtual int Get_X_ODR(float *odr) {
Wolfgang Betz 24:92cc9c6e4b2b 89 return LSM6DS0_X_Get_ODR(odr);
Wolfgang Betz 24:92cc9c6e4b2b 90 }
Wolfgang Betz 24:92cc9c6e4b2b 91
Wolfgang Betz 24:92cc9c6e4b2b 92 virtual int Set_X_ODR(float odr) {
Wolfgang Betz 24:92cc9c6e4b2b 93 return LSM6DS0_X_Set_ODR(odr);
Wolfgang Betz 24:92cc9c6e4b2b 94 }
Wolfgang Betz 24:92cc9c6e4b2b 95
Wolfgang Betz 18:1cb4ae9d83e7 96 virtual int Get_X_Sensitivity(float *pfData) {
Wolfgang Betz 7:a2bb3d5e12e9 97 return LSM6DS0_X_GetSensitivity(pfData);
Wolfgang Betz 7:a2bb3d5e12e9 98 }
Wolfgang Betz 7:a2bb3d5e12e9 99
Wolfgang Betz 24:92cc9c6e4b2b 100 virtual int Get_X_FS(float *fullScale) {
Wolfgang Betz 24:92cc9c6e4b2b 101 return LSM6DS0_X_Get_FS(fullScale);
Wolfgang Betz 24:92cc9c6e4b2b 102 }
Wolfgang Betz 24:92cc9c6e4b2b 103
Wolfgang Betz 24:92cc9c6e4b2b 104 virtual int Set_X_FS(float fullScale) {
Wolfgang Betz 24:92cc9c6e4b2b 105 return LSM6DS0_X_Set_FS(fullScale);
Wolfgang Betz 24:92cc9c6e4b2b 106 }
Wolfgang Betz 24:92cc9c6e4b2b 107
Wolfgang Betz 24:92cc9c6e4b2b 108 virtual int Get_G_ODR(float *odr) {
Wolfgang Betz 24:92cc9c6e4b2b 109 return LSM6DS0_G_Get_ODR(odr);
Wolfgang Betz 24:92cc9c6e4b2b 110 }
Wolfgang Betz 24:92cc9c6e4b2b 111
Wolfgang Betz 24:92cc9c6e4b2b 112 virtual int Set_G_ODR(float odr) {
Wolfgang Betz 24:92cc9c6e4b2b 113 return LSM6DS0_G_Set_ODR(odr);
Wolfgang Betz 24:92cc9c6e4b2b 114 }
Wolfgang Betz 24:92cc9c6e4b2b 115
Wolfgang Betz 18:1cb4ae9d83e7 116 virtual int Get_G_Sensitivity(float *pfData) {
Wolfgang Betz 7:a2bb3d5e12e9 117 return LSM6DS0_G_GetSensitivity(pfData);
Wolfgang Betz 7:a2bb3d5e12e9 118 }
Wolfgang Betz 7:a2bb3d5e12e9 119
Wolfgang Betz 24:92cc9c6e4b2b 120 virtual int Get_G_FS(float *fullScale) {
Wolfgang Betz 24:92cc9c6e4b2b 121 return LSM6DS0_G_Get_FS(fullScale);
Wolfgang Betz 24:92cc9c6e4b2b 122 }
Wolfgang Betz 24:92cc9c6e4b2b 123
Wolfgang Betz 24:92cc9c6e4b2b 124 virtual int Set_G_FS(float fullScale) {
Wolfgang Betz 24:92cc9c6e4b2b 125 return LSM6DS0_G_Set_FS(fullScale);
Wolfgang Betz 24:92cc9c6e4b2b 126 }
Wolfgang Betz 24:92cc9c6e4b2b 127
Wolfgang Betz 7:a2bb3d5e12e9 128 protected:
Wolfgang Betz 7:a2bb3d5e12e9 129 /*** Methods ***/
Wolfgang Betz 7:a2bb3d5e12e9 130 IMU_6AXES_StatusTypeDef LSM6DS0_Init(IMU_6AXES_InitTypeDef *LSM6DS0_Init);
Wolfgang Betz 7:a2bb3d5e12e9 131 IMU_6AXES_StatusTypeDef LSM6DS0_Read_XG_ID(uint8_t *xg_id);
Wolfgang Betz 7:a2bb3d5e12e9 132 IMU_6AXES_StatusTypeDef LSM6DS0_X_GetAxes(int32_t *pData);
Wolfgang Betz 24:92cc9c6e4b2b 133 IMU_6AXES_StatusTypeDef LSM6DS0_X_GetAxesRaw(int16_t *pData);
Wolfgang Betz 7:a2bb3d5e12e9 134 IMU_6AXES_StatusTypeDef LSM6DS0_G_GetAxes(int32_t *pData);
Wolfgang Betz 24:92cc9c6e4b2b 135 IMU_6AXES_StatusTypeDef LSM6DS0_G_GetAxesRaw(int16_t *pData);
Wolfgang Betz 24:92cc9c6e4b2b 136 IMU_6AXES_StatusTypeDef LSM6DS0_X_Get_ODR( float *odr );
Wolfgang Betz 24:92cc9c6e4b2b 137 IMU_6AXES_StatusTypeDef LSM6DS0_X_Set_ODR( float odr );
Wolfgang Betz 7:a2bb3d5e12e9 138 IMU_6AXES_StatusTypeDef LSM6DS0_X_GetSensitivity( float *pfData );
Wolfgang Betz 24:92cc9c6e4b2b 139 IMU_6AXES_StatusTypeDef LSM6DS0_X_Get_FS( float *fullScale );
Wolfgang Betz 24:92cc9c6e4b2b 140 IMU_6AXES_StatusTypeDef LSM6DS0_X_Set_FS( float fullScale );
Wolfgang Betz 24:92cc9c6e4b2b 141 IMU_6AXES_StatusTypeDef LSM6DS0_G_Get_ODR( float *odr );
Wolfgang Betz 24:92cc9c6e4b2b 142 IMU_6AXES_StatusTypeDef LSM6DS0_G_Set_ODR( float odr );
Wolfgang Betz 7:a2bb3d5e12e9 143 IMU_6AXES_StatusTypeDef LSM6DS0_G_GetSensitivity( float *pfData );
Wolfgang Betz 24:92cc9c6e4b2b 144 IMU_6AXES_StatusTypeDef LSM6DS0_G_Get_FS( float *fullScale );
Wolfgang Betz 24:92cc9c6e4b2b 145 IMU_6AXES_StatusTypeDef LSM6DS0_G_Set_FS( float fullScale );
Wolfgang Betz 24:92cc9c6e4b2b 146
Wolfgang Betz 24:92cc9c6e4b2b 147 IMU_6AXES_StatusTypeDef LSM6DS0_X_Set_Axes_Status(uint8_t enableX, uint8_t enableY, uint8_t enableZ);
Wolfgang Betz 24:92cc9c6e4b2b 148 IMU_6AXES_StatusTypeDef LSM6DS0_G_Set_Axes_Status(uint8_t enableX, uint8_t enableY, uint8_t enableZ);
Wolfgang Betz 7:a2bb3d5e12e9 149
Wolfgang Betz 7:a2bb3d5e12e9 150 /**
Wolfgang Betz 7:a2bb3d5e12e9 151 * @brief Configures LSM6DS0 interrupt lines for NUCLEO boards
Wolfgang Betz 7:a2bb3d5e12e9 152 * @param None
Wolfgang Betz 7:a2bb3d5e12e9 153 * @retval None
Wolfgang Betz 7:a2bb3d5e12e9 154 */
Wolfgang Betz 7:a2bb3d5e12e9 155 void LSM6DS0_IO_ITConfig(void)
Wolfgang Betz 7:a2bb3d5e12e9 156 {
Wolfgang Betz 7:a2bb3d5e12e9 157 /* To be implemented */
Wolfgang Betz 7:a2bb3d5e12e9 158 }
Wolfgang Betz 7:a2bb3d5e12e9 159
Wolfgang Betz 7:a2bb3d5e12e9 160 /**
Wolfgang Betz 7:a2bb3d5e12e9 161 * @brief Configures LSM6DS0 I2C interface
Wolfgang Betz 7:a2bb3d5e12e9 162 * @param None
Wolfgang Betz 7:a2bb3d5e12e9 163 * @retval IMU_6AXES_OK in case of success, an error code otherwise
Wolfgang Betz 7:a2bb3d5e12e9 164 */
Wolfgang Betz 7:a2bb3d5e12e9 165 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Init(void)
Wolfgang Betz 7:a2bb3d5e12e9 166 {
Wolfgang Betz 7:a2bb3d5e12e9 167 return IMU_6AXES_OK; /* done in constructor */
Wolfgang Betz 7:a2bb3d5e12e9 168 }
Wolfgang Betz 7:a2bb3d5e12e9 169
Wolfgang Betz 7:a2bb3d5e12e9 170 /**
Wolfgang Betz 7:a2bb3d5e12e9 171 * @brief utility function to read data from STC3115
Wolfgang Betz 7:a2bb3d5e12e9 172 * @param pBuffer: pointer to data to be read.
Wolfgang Betz 7:a2bb3d5e12e9 173 * @param RegisterAddr: specifies internal address register to read from.
Wolfgang Betz 7:a2bb3d5e12e9 174 * @param NumByteToRead: number of bytes to be read.
Wolfgang Betz 7:a2bb3d5e12e9 175 * @retval IMU_6AXES_OK if ok, IMU_6AXES_ERROR if an I2C error has occured
Wolfgang Betz 7:a2bb3d5e12e9 176 */
Wolfgang Betz 7:a2bb3d5e12e9 177 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Read(uint8_t* pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 178 uint8_t RegisterAddr, uint16_t NumByteToRead)
Wolfgang Betz 7:a2bb3d5e12e9 179 {
Wolfgang Betz 7:a2bb3d5e12e9 180 int ret = dev_i2c.i2c_read(pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 181 LSM6DS0_XG_MEMS_ADDRESS,
Wolfgang Betz 7:a2bb3d5e12e9 182 RegisterAddr,
Wolfgang Betz 7:a2bb3d5e12e9 183 NumByteToRead);
Wolfgang Betz 7:a2bb3d5e12e9 184 if(ret != 0) {
Wolfgang Betz 7:a2bb3d5e12e9 185 return IMU_6AXES_ERROR;
Wolfgang Betz 7:a2bb3d5e12e9 186 }
Wolfgang Betz 7:a2bb3d5e12e9 187 return IMU_6AXES_OK;
Wolfgang Betz 7:a2bb3d5e12e9 188 }
Wolfgang Betz 7:a2bb3d5e12e9 189
Wolfgang Betz 7:a2bb3d5e12e9 190 /**
Wolfgang Betz 7:a2bb3d5e12e9 191 * @brief utility function to write data to STC3115
Wolfgang Betz 7:a2bb3d5e12e9 192 * @param pBuffer: pointer to buffer to be filled.
Wolfgang Betz 7:a2bb3d5e12e9 193 * @param RegisterAddr: specifies internal address register to read from.
Wolfgang Betz 7:a2bb3d5e12e9 194 * @param NumByteToWrite: number of bytes to write.
Wolfgang Betz 7:a2bb3d5e12e9 195 * @retval 0 if ok, -1 if an I2C error has occured
Wolfgang Betz 7:a2bb3d5e12e9 196 */
Wolfgang Betz 7:a2bb3d5e12e9 197 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Write(uint8_t* pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 198 uint8_t RegisterAddr, uint16_t NumByteToWrite)
Wolfgang Betz 7:a2bb3d5e12e9 199 {
Wolfgang Betz 7:a2bb3d5e12e9 200 int ret = dev_i2c.i2c_write(pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 201 LSM6DS0_XG_MEMS_ADDRESS,
Wolfgang Betz 7:a2bb3d5e12e9 202 RegisterAddr,
Wolfgang Betz 7:a2bb3d5e12e9 203 NumByteToWrite);
Wolfgang Betz 7:a2bb3d5e12e9 204 if(ret != 0) {
Wolfgang Betz 7:a2bb3d5e12e9 205 return IMU_6AXES_ERROR;
Wolfgang Betz 7:a2bb3d5e12e9 206 }
Wolfgang Betz 7:a2bb3d5e12e9 207 return IMU_6AXES_OK;
Wolfgang Betz 7:a2bb3d5e12e9 208 }
Wolfgang Betz 7:a2bb3d5e12e9 209
Wolfgang Betz 7:a2bb3d5e12e9 210 /*** Instance Variables ***/
Wolfgang Betz 7:a2bb3d5e12e9 211 /* IO Device */
Wolfgang Betz 7:a2bb3d5e12e9 212 DevI2C &dev_i2c;
Wolfgang Betz 7:a2bb3d5e12e9 213 };
Wolfgang Betz 7:a2bb3d5e12e9 214
Wolfgang Betz 7:a2bb3d5e12e9 215 #endif // __LSM6DS0_CLASS_H