removed X-NUCLEO-COMMON and ST-INTERFACES

Dependents:   unh-hackathon-example unh-hackathon-example-raw

Fork of X_NUCLEO_IKS01A1 by ST

Committer:
mfiore
Date:
Sat Apr 08 03:55:37 2017 +0000
Revision:
93:c7bd4f2e378c
Parent:
92:d1c67d482bad
remove sub libraries

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 57:04563dd74269 44 #include "lsm6ds0.h"
Davidroid 88:7b8d3316d753 45 #include "GyroSensor.h"
Davidroid 88:7b8d3316d753 46 #include "MotionSensor.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 54:2a676c734b30 54 * @param[in] 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 92:d1c67d482bad 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 92:d1c67d482bad 68 virtual int read_id(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 92:d1c67d482bad 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 92:d1c67d482bad 76 virtual int get_x_axes_raw(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 92:d1c67d482bad 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 92:d1c67d482bad 84 virtual int get_g_axes_raw(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 92:d1c67d482bad 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 92:d1c67d482bad 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 92:d1c67d482bad 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 92:d1c67d482bad 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 92:d1c67d482bad 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 92:d1c67d482bad 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 92:d1c67d482bad 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 92:d1c67d482bad 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 92:d1c67d482bad 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 92:d1c67d482bad 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 */
Wolfgang Betz 7:a2bb3d5e12e9 153 void LSM6DS0_IO_ITConfig(void)
Wolfgang Betz 7:a2bb3d5e12e9 154 {
Wolfgang Betz 7:a2bb3d5e12e9 155 /* To be implemented */
Wolfgang Betz 7:a2bb3d5e12e9 156 }
Wolfgang Betz 7:a2bb3d5e12e9 157
Wolfgang Betz 7:a2bb3d5e12e9 158 /**
Wolfgang Betz 7:a2bb3d5e12e9 159 * @brief Configures LSM6DS0 I2C interface
Wolfgang Betz 57:04563dd74269 160 * @return IMU_6AXES_OK in case of success, an error code otherwise
Wolfgang Betz 7:a2bb3d5e12e9 161 */
Wolfgang Betz 7:a2bb3d5e12e9 162 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Init(void)
Wolfgang Betz 7:a2bb3d5e12e9 163 {
Wolfgang Betz 7:a2bb3d5e12e9 164 return IMU_6AXES_OK; /* done in constructor */
Wolfgang Betz 7:a2bb3d5e12e9 165 }
Wolfgang Betz 7:a2bb3d5e12e9 166
Wolfgang Betz 7:a2bb3d5e12e9 167 /**
Wolfgang Betz 57:04563dd74269 168 * @brief Utility function to read data from LSM6DS0
Wolfgang Betz 57:04563dd74269 169 * @param[out] pBuffer pointer to the byte-array to read data in to
Wolfgang Betz 57:04563dd74269 170 * @param[in] RegisterAddr specifies internal address register to read from.
Wolfgang Betz 57:04563dd74269 171 * @param[in] NumByteToRead number of bytes to be read.
Wolfgang Betz 57:04563dd74269 172 * @retval IMU_6AXES_OK if ok,
Wolfgang Betz 57:04563dd74269 173 * @retval IMU_6AXES_ERROR if an I2C error has occured
Wolfgang Betz 7:a2bb3d5e12e9 174 */
Wolfgang Betz 7:a2bb3d5e12e9 175 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Read(uint8_t* pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 176 uint8_t RegisterAddr, uint16_t NumByteToRead)
Wolfgang Betz 7:a2bb3d5e12e9 177 {
Wolfgang Betz 7:a2bb3d5e12e9 178 int ret = dev_i2c.i2c_read(pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 179 LSM6DS0_XG_MEMS_ADDRESS,
Wolfgang Betz 7:a2bb3d5e12e9 180 RegisterAddr,
Wolfgang Betz 7:a2bb3d5e12e9 181 NumByteToRead);
Wolfgang Betz 7:a2bb3d5e12e9 182 if(ret != 0) {
Wolfgang Betz 7:a2bb3d5e12e9 183 return IMU_6AXES_ERROR;
Wolfgang Betz 7:a2bb3d5e12e9 184 }
Wolfgang Betz 7:a2bb3d5e12e9 185 return IMU_6AXES_OK;
Wolfgang Betz 7:a2bb3d5e12e9 186 }
Wolfgang Betz 7:a2bb3d5e12e9 187
Wolfgang Betz 7:a2bb3d5e12e9 188 /**
Wolfgang Betz 57:04563dd74269 189 * @brief Utility function to write data to LSM6DS0
Wolfgang Betz 57:04563dd74269 190 * @param[in] pBuffer pointer to the byte-array data to send
Wolfgang Betz 57:04563dd74269 191 * @param[in] RegisterAddr specifies internal address register to read from.
Wolfgang Betz 57:04563dd74269 192 * @param[in] NumByteToWrite number of bytes to write.
Wolfgang Betz 57:04563dd74269 193 * @retval IMU_6AXES_OK if ok,
Wolfgang Betz 57:04563dd74269 194 * @retval IMU_6AXES_ERROR if an I2C error has occured
Wolfgang Betz 7:a2bb3d5e12e9 195 */
Wolfgang Betz 7:a2bb3d5e12e9 196 IMU_6AXES_StatusTypeDef LSM6DS0_IO_Write(uint8_t* pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 197 uint8_t RegisterAddr, uint16_t NumByteToWrite)
Wolfgang Betz 7:a2bb3d5e12e9 198 {
Wolfgang Betz 7:a2bb3d5e12e9 199 int ret = dev_i2c.i2c_write(pBuffer,
Wolfgang Betz 7:a2bb3d5e12e9 200 LSM6DS0_XG_MEMS_ADDRESS,
Wolfgang Betz 7:a2bb3d5e12e9 201 RegisterAddr,
Wolfgang Betz 7:a2bb3d5e12e9 202 NumByteToWrite);
Wolfgang Betz 7:a2bb3d5e12e9 203 if(ret != 0) {
Wolfgang Betz 7:a2bb3d5e12e9 204 return IMU_6AXES_ERROR;
Wolfgang Betz 7:a2bb3d5e12e9 205 }
Wolfgang Betz 7:a2bb3d5e12e9 206 return IMU_6AXES_OK;
Wolfgang Betz 7:a2bb3d5e12e9 207 }
Wolfgang Betz 7:a2bb3d5e12e9 208
Wolfgang Betz 7:a2bb3d5e12e9 209 /*** Instance Variables ***/
Wolfgang Betz 7:a2bb3d5e12e9 210 /* IO Device */
Wolfgang Betz 7:a2bb3d5e12e9 211 DevI2C &dev_i2c;
Wolfgang Betz 7:a2bb3d5e12e9 212 };
Wolfgang Betz 7:a2bb3d5e12e9 213
Wolfgang Betz 7:a2bb3d5e12e9 214 #endif // __LSM6DS0_CLASS_H