Jamie Satchell
/
JSatchell_SOFT253ReferredCoursework
Finished project.
Fork of ReferredCoursework2016 by
Components/lsm6ds0/lsm6ds0_class.h@7:a2bb3d5e12e9, 2015-04-15 (annotated)
- Committer:
- Wolfgang Betz
- Date:
- Wed Apr 15 14:08:20 2015 +0200
- Revision:
- 7:a2bb3d5e12e9
- Child:
- 18:1cb4ae9d83e7
Added component LSM6DS0
Who changed what in which revision?
User | Revision | Line number | New 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>© 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 |
7:a2bb3d5e12e9 | 44 | #include "../Common/Imu6Axes.h" |
Wolfgang Betz |
7:a2bb3d5e12e9 | 45 | #include "lsm6ds0.h" |
Wolfgang Betz |
7:a2bb3d5e12e9 | 46 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 47 | /* Classes -------------------------------------------------------------------*/ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 48 | /** Class representing a LSM6DS0 sensor component |
Wolfgang Betz |
7:a2bb3d5e12e9 | 49 | */ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 50 | class LSM6DS0 : public Imu6Axes { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 51 | public: |
Wolfgang Betz |
7:a2bb3d5e12e9 | 52 | /** Constructor |
Wolfgang Betz |
7:a2bb3d5e12e9 | 53 | * @param i2c device I2C to be used for communication |
Wolfgang Betz |
7:a2bb3d5e12e9 | 54 | */ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 55 | LSM6DS0(DevI2C &i2c) : Imu6Axes(), dev_i2c(i2c) { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 56 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 57 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 58 | /*** Interface Methods ***/ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 59 | virtual IMU_6AXES_StatusTypeDef Init(IMU_6AXES_InitTypeDef *init_struct) { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 60 | return LSM6DS0_Init(init_struct); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 61 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 62 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 63 | virtual IMU_6AXES_StatusTypeDef Read_XG_ID(uint8_t *xg_id) { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 64 | return LSM6DS0_Read_XG_ID(xg_id); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 65 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 66 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 67 | virtual IMU_6AXES_StatusTypeDef Get_X_Axes(int32_t *pData) { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 68 | return LSM6DS0_X_GetAxes(pData); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 69 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 70 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 71 | virtual IMU_6AXES_StatusTypeDef Get_G_Axes(int32_t *pData) { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 72 | return LSM6DS0_G_GetAxes(pData); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 73 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 74 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 75 | virtual IMU_6AXES_StatusTypeDef Get_X_Sensitivity(float *pfData) { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 76 | return LSM6DS0_X_GetSensitivity(pfData); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 77 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 78 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 79 | virtual IMU_6AXES_StatusTypeDef Get_G_Sensitivity(float *pfData) { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 80 | return LSM6DS0_G_GetSensitivity(pfData); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 81 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 82 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 83 | protected: |
Wolfgang Betz |
7:a2bb3d5e12e9 | 84 | /*** Methods ***/ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 85 | IMU_6AXES_StatusTypeDef LSM6DS0_Init(IMU_6AXES_InitTypeDef *LSM6DS0_Init); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 86 | IMU_6AXES_StatusTypeDef LSM6DS0_Read_XG_ID(uint8_t *xg_id); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 87 | IMU_6AXES_StatusTypeDef LSM6DS0_X_GetAxes(int32_t *pData); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 88 | IMU_6AXES_StatusTypeDef LSM6DS0_G_GetAxes(int32_t *pData); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 89 | IMU_6AXES_StatusTypeDef LSM6DS0_X_GetSensitivity( float *pfData ); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 90 | IMU_6AXES_StatusTypeDef LSM6DS0_G_GetSensitivity( float *pfData ); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 91 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 92 | IMU_6AXES_StatusTypeDef LSM6DS0_X_GetAxesRaw(int16_t *pData); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 93 | IMU_6AXES_StatusTypeDef LSM6DS0_G_GetAxesRaw(int16_t *pData); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 94 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 95 | /** |
Wolfgang Betz |
7:a2bb3d5e12e9 | 96 | * @brief Configures LSM6DS0 interrupt lines for NUCLEO boards |
Wolfgang Betz |
7:a2bb3d5e12e9 | 97 | * @param None |
Wolfgang Betz |
7:a2bb3d5e12e9 | 98 | * @retval None |
Wolfgang Betz |
7:a2bb3d5e12e9 | 99 | */ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 100 | void LSM6DS0_IO_ITConfig(void) |
Wolfgang Betz |
7:a2bb3d5e12e9 | 101 | { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 102 | /* To be implemented */ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 103 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 104 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 105 | /** |
Wolfgang Betz |
7:a2bb3d5e12e9 | 106 | * @brief Configures LSM6DS0 I2C interface |
Wolfgang Betz |
7:a2bb3d5e12e9 | 107 | * @param None |
Wolfgang Betz |
7:a2bb3d5e12e9 | 108 | * @retval IMU_6AXES_OK in case of success, an error code otherwise |
Wolfgang Betz |
7:a2bb3d5e12e9 | 109 | */ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 110 | IMU_6AXES_StatusTypeDef LSM6DS0_IO_Init(void) |
Wolfgang Betz |
7:a2bb3d5e12e9 | 111 | { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 112 | return IMU_6AXES_OK; /* done in constructor */ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 113 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 114 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 115 | /** |
Wolfgang Betz |
7:a2bb3d5e12e9 | 116 | * @brief utility function to read data from STC3115 |
Wolfgang Betz |
7:a2bb3d5e12e9 | 117 | * @param pBuffer: pointer to data to be read. |
Wolfgang Betz |
7:a2bb3d5e12e9 | 118 | * @param RegisterAddr: specifies internal address register to read from. |
Wolfgang Betz |
7:a2bb3d5e12e9 | 119 | * @param NumByteToRead: number of bytes to be read. |
Wolfgang Betz |
7:a2bb3d5e12e9 | 120 | * @retval IMU_6AXES_OK if ok, IMU_6AXES_ERROR if an I2C error has occured |
Wolfgang Betz |
7:a2bb3d5e12e9 | 121 | */ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 122 | IMU_6AXES_StatusTypeDef LSM6DS0_IO_Read(uint8_t* pBuffer, |
Wolfgang Betz |
7:a2bb3d5e12e9 | 123 | uint8_t RegisterAddr, uint16_t NumByteToRead) |
Wolfgang Betz |
7:a2bb3d5e12e9 | 124 | { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 125 | int ret = dev_i2c.i2c_read(pBuffer, |
Wolfgang Betz |
7:a2bb3d5e12e9 | 126 | LSM6DS0_XG_MEMS_ADDRESS, |
Wolfgang Betz |
7:a2bb3d5e12e9 | 127 | RegisterAddr, |
Wolfgang Betz |
7:a2bb3d5e12e9 | 128 | NumByteToRead); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 129 | if(ret != 0) { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 130 | return IMU_6AXES_ERROR; |
Wolfgang Betz |
7:a2bb3d5e12e9 | 131 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 132 | return IMU_6AXES_OK; |
Wolfgang Betz |
7:a2bb3d5e12e9 | 133 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 134 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 135 | /** |
Wolfgang Betz |
7:a2bb3d5e12e9 | 136 | * @brief utility function to write data to STC3115 |
Wolfgang Betz |
7:a2bb3d5e12e9 | 137 | * @param pBuffer: pointer to buffer to be filled. |
Wolfgang Betz |
7:a2bb3d5e12e9 | 138 | * @param RegisterAddr: specifies internal address register to read from. |
Wolfgang Betz |
7:a2bb3d5e12e9 | 139 | * @param NumByteToWrite: number of bytes to write. |
Wolfgang Betz |
7:a2bb3d5e12e9 | 140 | * @retval 0 if ok, -1 if an I2C error has occured |
Wolfgang Betz |
7:a2bb3d5e12e9 | 141 | */ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 142 | IMU_6AXES_StatusTypeDef LSM6DS0_IO_Write(uint8_t* pBuffer, |
Wolfgang Betz |
7:a2bb3d5e12e9 | 143 | uint8_t RegisterAddr, uint16_t NumByteToWrite) |
Wolfgang Betz |
7:a2bb3d5e12e9 | 144 | { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 145 | int ret = dev_i2c.i2c_write(pBuffer, |
Wolfgang Betz |
7:a2bb3d5e12e9 | 146 | LSM6DS0_XG_MEMS_ADDRESS, |
Wolfgang Betz |
7:a2bb3d5e12e9 | 147 | RegisterAddr, |
Wolfgang Betz |
7:a2bb3d5e12e9 | 148 | NumByteToWrite); |
Wolfgang Betz |
7:a2bb3d5e12e9 | 149 | if(ret != 0) { |
Wolfgang Betz |
7:a2bb3d5e12e9 | 150 | return IMU_6AXES_ERROR; |
Wolfgang Betz |
7:a2bb3d5e12e9 | 151 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 152 | return IMU_6AXES_OK; |
Wolfgang Betz |
7:a2bb3d5e12e9 | 153 | } |
Wolfgang Betz |
7:a2bb3d5e12e9 | 154 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 155 | /*** Instance Variables ***/ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 156 | /* IO Device */ |
Wolfgang Betz |
7:a2bb3d5e12e9 | 157 | DevI2C &dev_i2c; |
Wolfgang Betz |
7:a2bb3d5e12e9 | 158 | }; |
Wolfgang Betz |
7:a2bb3d5e12e9 | 159 | |
Wolfgang Betz |
7:a2bb3d5e12e9 | 160 | #endif // __LSM6DS0_CLASS_H |