Version of the IKS01A1 library for this coursework

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_IKS01A1 by ST

Committer:
Wolfgang Betz
Date:
Fri May 29 16:29:31 2015 +0200
Revision:
20:c20c8bd5be6b
Parent:
18:1cb4ae9d83e7
Child:
24:92cc9c6e4b2b
Use multiple inheritance for combianed sensor components

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 18:1cb4ae9d83e7 72 virtual int Get_G_Axes(int32_t *pData) {
Wolfgang Betz 7:a2bb3d5e12e9 73 return LSM6DS0_G_GetAxes(pData);
Wolfgang Betz 7:a2bb3d5e12e9 74 }
Wolfgang Betz 7:a2bb3d5e12e9 75
Wolfgang Betz 18:1cb4ae9d83e7 76 virtual int Get_X_Sensitivity(float *pfData) {
Wolfgang Betz 7:a2bb3d5e12e9 77 return LSM6DS0_X_GetSensitivity(pfData);
Wolfgang Betz 7:a2bb3d5e12e9 78 }
Wolfgang Betz 7:a2bb3d5e12e9 79
Wolfgang Betz 18:1cb4ae9d83e7 80 virtual int Get_G_Sensitivity(float *pfData) {
Wolfgang Betz 7:a2bb3d5e12e9 81 return LSM6DS0_G_GetSensitivity(pfData);
Wolfgang Betz 7:a2bb3d5e12e9 82 }
Wolfgang Betz 7:a2bb3d5e12e9 83
Wolfgang Betz 7:a2bb3d5e12e9 84 protected:
Wolfgang Betz 7:a2bb3d5e12e9 85 /*** Methods ***/
Wolfgang Betz 7:a2bb3d5e12e9 86 IMU_6AXES_StatusTypeDef LSM6DS0_Init(IMU_6AXES_InitTypeDef *LSM6DS0_Init);
Wolfgang Betz 7:a2bb3d5e12e9 87 IMU_6AXES_StatusTypeDef LSM6DS0_Read_XG_ID(uint8_t *xg_id);
Wolfgang Betz 7:a2bb3d5e12e9 88 IMU_6AXES_StatusTypeDef LSM6DS0_X_GetAxes(int32_t *pData);
Wolfgang Betz 7:a2bb3d5e12e9 89 IMU_6AXES_StatusTypeDef LSM6DS0_G_GetAxes(int32_t *pData);
Wolfgang Betz 7:a2bb3d5e12e9 90 IMU_6AXES_StatusTypeDef LSM6DS0_X_GetSensitivity( float *pfData );
Wolfgang Betz 7:a2bb3d5e12e9 91 IMU_6AXES_StatusTypeDef LSM6DS0_G_GetSensitivity( float *pfData );
Wolfgang Betz 7:a2bb3d5e12e9 92
Wolfgang Betz 7:a2bb3d5e12e9 93 IMU_6AXES_StatusTypeDef LSM6DS0_X_GetAxesRaw(int16_t *pData);
Wolfgang Betz 7:a2bb3d5e12e9 94 IMU_6AXES_StatusTypeDef LSM6DS0_G_GetAxesRaw(int16_t *pData);
Wolfgang Betz 7:a2bb3d5e12e9 95
Wolfgang Betz 7:a2bb3d5e12e9 96 /**
Wolfgang Betz 7:a2bb3d5e12e9 97 * @brief Configures LSM6DS0 interrupt lines for NUCLEO boards
Wolfgang Betz 7:a2bb3d5e12e9 98 * @param None
Wolfgang Betz 7:a2bb3d5e12e9 99 * @retval None
Wolfgang Betz 7:a2bb3d5e12e9 100 */
Wolfgang Betz 7:a2bb3d5e12e9 101 void LSM6DS0_IO_ITConfig(void)
Wolfgang Betz 7:a2bb3d5e12e9 102 {
Wolfgang Betz 7:a2bb3d5e12e9 103 /* To be implemented */
Wolfgang Betz 7:a2bb3d5e12e9 104 }
Wolfgang Betz 7:a2bb3d5e12e9 105
Wolfgang Betz 7:a2bb3d5e12e9 106 /**
Wolfgang Betz 7:a2bb3d5e12e9 107 * @brief Configures LSM6DS0 I2C interface
Wolfgang Betz 7:a2bb3d5e12e9 108 * @param None
Wolfgang Betz 7:a2bb3d5e12e9 109 * @retval IMU_6AXES_OK in case of success, an error code otherwise
Wolfgang Betz 7:a2bb3d5e12e9 110 */
Wolfgang Betz 7:a2bb3d5e12e9 111 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Init(void)
Wolfgang Betz 7:a2bb3d5e12e9 112 {
Wolfgang Betz 7:a2bb3d5e12e9 113 return IMU_6AXES_OK; /* done in constructor */
Wolfgang Betz 7:a2bb3d5e12e9 114 }
Wolfgang Betz 7:a2bb3d5e12e9 115
Wolfgang Betz 7:a2bb3d5e12e9 116 /**
Wolfgang Betz 7:a2bb3d5e12e9 117 * @brief utility function to read data from STC3115
Wolfgang Betz 7:a2bb3d5e12e9 118 * @param pBuffer: pointer to data to be read.
Wolfgang Betz 7:a2bb3d5e12e9 119 * @param RegisterAddr: specifies internal address register to read from.
Wolfgang Betz 7:a2bb3d5e12e9 120 * @param NumByteToRead: number of bytes to be read.
Wolfgang Betz 7:a2bb3d5e12e9 121 * @retval IMU_6AXES_OK if ok, IMU_6AXES_ERROR if an I2C error has occured
Wolfgang Betz 7:a2bb3d5e12e9 122 */
Wolfgang Betz 7:a2bb3d5e12e9 123 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Read(uint8_t* pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 124 uint8_t RegisterAddr, uint16_t NumByteToRead)
Wolfgang Betz 7:a2bb3d5e12e9 125 {
Wolfgang Betz 7:a2bb3d5e12e9 126 int ret = dev_i2c.i2c_read(pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 127 LSM6DS0_XG_MEMS_ADDRESS,
Wolfgang Betz 7:a2bb3d5e12e9 128 RegisterAddr,
Wolfgang Betz 7:a2bb3d5e12e9 129 NumByteToRead);
Wolfgang Betz 7:a2bb3d5e12e9 130 if(ret != 0) {
Wolfgang Betz 7:a2bb3d5e12e9 131 return IMU_6AXES_ERROR;
Wolfgang Betz 7:a2bb3d5e12e9 132 }
Wolfgang Betz 7:a2bb3d5e12e9 133 return IMU_6AXES_OK;
Wolfgang Betz 7:a2bb3d5e12e9 134 }
Wolfgang Betz 7:a2bb3d5e12e9 135
Wolfgang Betz 7:a2bb3d5e12e9 136 /**
Wolfgang Betz 7:a2bb3d5e12e9 137 * @brief utility function to write data to STC3115
Wolfgang Betz 7:a2bb3d5e12e9 138 * @param pBuffer: pointer to buffer to be filled.
Wolfgang Betz 7:a2bb3d5e12e9 139 * @param RegisterAddr: specifies internal address register to read from.
Wolfgang Betz 7:a2bb3d5e12e9 140 * @param NumByteToWrite: number of bytes to write.
Wolfgang Betz 7:a2bb3d5e12e9 141 * @retval 0 if ok, -1 if an I2C error has occured
Wolfgang Betz 7:a2bb3d5e12e9 142 */
Wolfgang Betz 7:a2bb3d5e12e9 143 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Write(uint8_t* pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 144 uint8_t RegisterAddr, uint16_t NumByteToWrite)
Wolfgang Betz 7:a2bb3d5e12e9 145 {
Wolfgang Betz 7:a2bb3d5e12e9 146 int ret = dev_i2c.i2c_write(pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 147 LSM6DS0_XG_MEMS_ADDRESS,
Wolfgang Betz 7:a2bb3d5e12e9 148 RegisterAddr,
Wolfgang Betz 7:a2bb3d5e12e9 149 NumByteToWrite);
Wolfgang Betz 7:a2bb3d5e12e9 150 if(ret != 0) {
Wolfgang Betz 7:a2bb3d5e12e9 151 return IMU_6AXES_ERROR;
Wolfgang Betz 7:a2bb3d5e12e9 152 }
Wolfgang Betz 7:a2bb3d5e12e9 153 return IMU_6AXES_OK;
Wolfgang Betz 7:a2bb3d5e12e9 154 }
Wolfgang Betz 7:a2bb3d5e12e9 155
Wolfgang Betz 7:a2bb3d5e12e9 156 /*** Instance Variables ***/
Wolfgang Betz 7:a2bb3d5e12e9 157 /* IO Device */
Wolfgang Betz 7:a2bb3d5e12e9 158 DevI2C &dev_i2c;
Wolfgang Betz 7:a2bb3d5e12e9 159 };
Wolfgang Betz 7:a2bb3d5e12e9 160
Wolfgang Betz 7:a2bb3d5e12e9 161 #endif // __LSM6DS0_CLASS_H