Jamie Satchell
/
JSatchell_SOFT253ReferredCoursework
Finished project.
Fork of ReferredCoursework2016 by
Components/lis3mdl/lis3mdl_class.h@5:8bab0f419849, 2015-04-15 (annotated)
- Committer:
- Wolfgang Betz
- Date:
- Wed Apr 15 12:10:42 2015 +0200
- Revision:
- 5:8bab0f419849
- Child:
- 6:8d2abd695c52
Added component LIS3MDL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wolfgang Betz |
5:8bab0f419849 | 1 | /** |
Wolfgang Betz |
5:8bab0f419849 | 2 | ****************************************************************************** |
Wolfgang Betz |
5:8bab0f419849 | 3 | * @file lis3mdl_class.h |
Wolfgang Betz |
5:8bab0f419849 | 4 | * @author AST / EST |
Wolfgang Betz |
5:8bab0f419849 | 5 | * @version V0.0.1 |
Wolfgang Betz |
5:8bab0f419849 | 6 | * @date 14-April-2015 |
Wolfgang Betz |
5:8bab0f419849 | 7 | * @brief Header file for component LIS3MDL |
Wolfgang Betz |
5:8bab0f419849 | 8 | ****************************************************************************** |
Wolfgang Betz |
5:8bab0f419849 | 9 | * @attention |
Wolfgang Betz |
5:8bab0f419849 | 10 | * |
Wolfgang Betz |
5:8bab0f419849 | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
Wolfgang Betz |
5:8bab0f419849 | 12 | * |
Wolfgang Betz |
5:8bab0f419849 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
Wolfgang Betz |
5:8bab0f419849 | 14 | * are permitted provided that the following conditions are met: |
Wolfgang Betz |
5:8bab0f419849 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
Wolfgang Betz |
5:8bab0f419849 | 16 | * this list of conditions and the following disclaimer. |
Wolfgang Betz |
5:8bab0f419849 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Wolfgang Betz |
5:8bab0f419849 | 18 | * this list of conditions and the following disclaimer in the documentation |
Wolfgang Betz |
5:8bab0f419849 | 19 | * and/or other materials provided with the distribution. |
Wolfgang Betz |
5:8bab0f419849 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Wolfgang Betz |
5:8bab0f419849 | 21 | * may be used to endorse or promote products derived from this software |
Wolfgang Betz |
5:8bab0f419849 | 22 | * without specific prior written permission. |
Wolfgang Betz |
5:8bab0f419849 | 23 | * |
Wolfgang Betz |
5:8bab0f419849 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Wolfgang Betz |
5:8bab0f419849 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Wolfgang Betz |
5:8bab0f419849 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Wolfgang Betz |
5:8bab0f419849 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Wolfgang Betz |
5:8bab0f419849 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Wolfgang Betz |
5:8bab0f419849 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Wolfgang Betz |
5:8bab0f419849 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Wolfgang Betz |
5:8bab0f419849 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Wolfgang Betz |
5:8bab0f419849 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Wolfgang Betz |
5:8bab0f419849 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Wolfgang Betz |
5:8bab0f419849 | 34 | * |
Wolfgang Betz |
5:8bab0f419849 | 35 | ****************************************************************************** |
Wolfgang Betz |
5:8bab0f419849 | 36 | */ |
Wolfgang Betz |
5:8bab0f419849 | 37 | |
Wolfgang Betz |
5:8bab0f419849 | 38 | #ifndef __LIS3MDL_CLASS_H |
Wolfgang Betz |
5:8bab0f419849 | 39 | #define __LIS3MDL_CLASS_H |
Wolfgang Betz |
5:8bab0f419849 | 40 | |
Wolfgang Betz |
5:8bab0f419849 | 41 | /* Includes ------------------------------------------------------------------*/ |
Wolfgang Betz |
5:8bab0f419849 | 42 | #include "mbed.h" |
Wolfgang Betz |
5:8bab0f419849 | 43 | #include "DevI2C.h" |
Wolfgang Betz |
5:8bab0f419849 | 44 | #include "../Common/Magneto.h" |
Wolfgang Betz |
5:8bab0f419849 | 45 | #include "lis3mdl.h" |
Wolfgang Betz |
5:8bab0f419849 | 46 | |
Wolfgang Betz |
5:8bab0f419849 | 47 | /* Classes -------------------------------------------------------------------*/ |
Wolfgang Betz |
5:8bab0f419849 | 48 | /** Class representing a LIS3MDL sensor component |
Wolfgang Betz |
5:8bab0f419849 | 49 | */ |
Wolfgang Betz |
5:8bab0f419849 | 50 | class LIS3MDL : public Magneto { |
Wolfgang Betz |
5:8bab0f419849 | 51 | public: |
Wolfgang Betz |
5:8bab0f419849 | 52 | /** Constructor |
Wolfgang Betz |
5:8bab0f419849 | 53 | * @param i2c device I2C to be used for communication |
Wolfgang Betz |
5:8bab0f419849 | 54 | */ |
Wolfgang Betz |
5:8bab0f419849 | 55 | LIS3MDL(DevI2C &i2c) : Magneto(), dev_i2c(i2c) { |
Wolfgang Betz |
5:8bab0f419849 | 56 | } |
Wolfgang Betz |
5:8bab0f419849 | 57 | |
Wolfgang Betz |
5:8bab0f419849 | 58 | /*** Interface Methods ***/ |
Wolfgang Betz |
5:8bab0f419849 | 59 | virtual MAGNETO_StatusTypeDef Init(MAGNETO_InitTypeDef *init_struct) { |
Wolfgang Betz |
5:8bab0f419849 | 60 | return LIS3MDL_Init(init_struct); |
Wolfgang Betz |
5:8bab0f419849 | 61 | } |
Wolfgang Betz |
5:8bab0f419849 | 62 | |
Wolfgang Betz |
5:8bab0f419849 | 63 | virtual MAGNETO_StatusTypeDef Read_M_ID(uint8_t *m_id) { |
Wolfgang Betz |
5:8bab0f419849 | 64 | return LIS3MDL_Read_M_ID(m_id); |
Wolfgang Betz |
5:8bab0f419849 | 65 | } |
Wolfgang Betz |
5:8bab0f419849 | 66 | |
Wolfgang Betz |
5:8bab0f419849 | 67 | virtual MAGNETO_StatusTypeDef Get_M_Axes(int32_t *pData) { |
Wolfgang Betz |
5:8bab0f419849 | 68 | return LIS3MDL_M_GetAxes(pData); |
Wolfgang Betz |
5:8bab0f419849 | 69 | } |
Wolfgang Betz |
5:8bab0f419849 | 70 | |
Wolfgang Betz |
5:8bab0f419849 | 71 | protected: |
Wolfgang Betz |
5:8bab0f419849 | 72 | /*** Methods ***/ |
Wolfgang Betz |
5:8bab0f419849 | 73 | MAGNETO_StatusTypeDef LIS3MDL_Init(MAGNETO_InitTypeDef *LIS3MDL_Init); |
Wolfgang Betz |
5:8bab0f419849 | 74 | MAGNETO_StatusTypeDef LIS3MDL_Read_M_ID(uint8_t *m_id); |
Wolfgang Betz |
5:8bab0f419849 | 75 | MAGNETO_StatusTypeDef LIS3MDL_M_GetAxes(int32_t *pData); |
Wolfgang Betz |
5:8bab0f419849 | 76 | MAGNETO_StatusTypeDef LIS3MDL_M_GetAxesRaw(int16_t *pData); |
Wolfgang Betz |
5:8bab0f419849 | 77 | |
Wolfgang Betz |
5:8bab0f419849 | 78 | /** |
Wolfgang Betz |
5:8bab0f419849 | 79 | * @brief Configures LIS3MDL interrupt lines for NUCLEO boards |
Wolfgang Betz |
5:8bab0f419849 | 80 | * @param None |
Wolfgang Betz |
5:8bab0f419849 | 81 | * @retval None |
Wolfgang Betz |
5:8bab0f419849 | 82 | */ |
Wolfgang Betz |
5:8bab0f419849 | 83 | void LIS3MDL_IO_ITConfig(void) |
Wolfgang Betz |
5:8bab0f419849 | 84 | { |
Wolfgang Betz |
5:8bab0f419849 | 85 | /* To be implemented */ |
Wolfgang Betz |
5:8bab0f419849 | 86 | } |
Wolfgang Betz |
5:8bab0f419849 | 87 | |
Wolfgang Betz |
5:8bab0f419849 | 88 | /** |
Wolfgang Betz |
5:8bab0f419849 | 89 | * @brief Configures LIS3MDL I2C interface |
Wolfgang Betz |
5:8bab0f419849 | 90 | * @param None |
Wolfgang Betz |
5:8bab0f419849 | 91 | * @retval MAGNETO_OK in case of success, an error code otherwise |
Wolfgang Betz |
5:8bab0f419849 | 92 | */ |
Wolfgang Betz |
5:8bab0f419849 | 93 | MAGNETO_StatusTypeDef LIS3MDL_IO_Init(void) |
Wolfgang Betz |
5:8bab0f419849 | 94 | { |
Wolfgang Betz |
5:8bab0f419849 | 95 | return MAGNETO_OK; /* done in constructor */ |
Wolfgang Betz |
5:8bab0f419849 | 96 | } |
Wolfgang Betz |
5:8bab0f419849 | 97 | |
Wolfgang Betz |
5:8bab0f419849 | 98 | /** |
Wolfgang Betz |
5:8bab0f419849 | 99 | * @brief utility function to read data from STC3115 |
Wolfgang Betz |
5:8bab0f419849 | 100 | * @param pBuffer: pointer to data to be read. |
Wolfgang Betz |
5:8bab0f419849 | 101 | * @param RegisterAddr: specifies internal address register to read from. |
Wolfgang Betz |
5:8bab0f419849 | 102 | * @param NumByteToRead: number of bytes to be read. |
Wolfgang Betz |
5:8bab0f419849 | 103 | * @retval MAGNETO_OK if ok, MAGNETO_ERROR if an I2C error has occured |
Wolfgang Betz |
5:8bab0f419849 | 104 | */ |
Wolfgang Betz |
5:8bab0f419849 | 105 | MAGNETO_StatusTypeDef LIS3MDL_IO_Read(uint8_t* pBuffer, |
Wolfgang Betz |
5:8bab0f419849 | 106 | uint8_t RegisterAddr, uint16_t NumByteToRead) |
Wolfgang Betz |
5:8bab0f419849 | 107 | { |
Wolfgang Betz |
5:8bab0f419849 | 108 | int ret = dev_i2c.i2c_read(pBuffer, |
Wolfgang Betz |
5:8bab0f419849 | 109 | LIS3MDL_M_MEMS_ADDRESS, |
Wolfgang Betz |
5:8bab0f419849 | 110 | RegisterAddr, |
Wolfgang Betz |
5:8bab0f419849 | 111 | NumByteToRead); |
Wolfgang Betz |
5:8bab0f419849 | 112 | if(ret != 0) { |
Wolfgang Betz |
5:8bab0f419849 | 113 | return MAGNETO_ERROR; |
Wolfgang Betz |
5:8bab0f419849 | 114 | } |
Wolfgang Betz |
5:8bab0f419849 | 115 | return MAGNETO_OK; |
Wolfgang Betz |
5:8bab0f419849 | 116 | } |
Wolfgang Betz |
5:8bab0f419849 | 117 | |
Wolfgang Betz |
5:8bab0f419849 | 118 | /** |
Wolfgang Betz |
5:8bab0f419849 | 119 | * @brief utility function to write data to STC3115 |
Wolfgang Betz |
5:8bab0f419849 | 120 | * @param pBuffer: pointer to buffer to be filled. |
Wolfgang Betz |
5:8bab0f419849 | 121 | * @param RegisterAddr: specifies internal address register to read from. |
Wolfgang Betz |
5:8bab0f419849 | 122 | * @param NumByteToWrite: number of bytes to write. |
Wolfgang Betz |
5:8bab0f419849 | 123 | * @retval 0 if ok, -1 if an I2C error has occured |
Wolfgang Betz |
5:8bab0f419849 | 124 | */ |
Wolfgang Betz |
5:8bab0f419849 | 125 | MAGNETO_StatusTypeDef LIS3MDL_IO_Write(uint8_t* pBuffer, |
Wolfgang Betz |
5:8bab0f419849 | 126 | uint8_t RegisterAddr, uint16_t NumByteToWrite) |
Wolfgang Betz |
5:8bab0f419849 | 127 | { |
Wolfgang Betz |
5:8bab0f419849 | 128 | int ret = dev_i2c.i2c_write(pBuffer, |
Wolfgang Betz |
5:8bab0f419849 | 129 | LIS3MDL_M_MEMS_ADDRESS, |
Wolfgang Betz |
5:8bab0f419849 | 130 | RegisterAddr, |
Wolfgang Betz |
5:8bab0f419849 | 131 | NumByteToWrite); |
Wolfgang Betz |
5:8bab0f419849 | 132 | if(ret != 0) { |
Wolfgang Betz |
5:8bab0f419849 | 133 | return MAGNETO_ERROR; |
Wolfgang Betz |
5:8bab0f419849 | 134 | } |
Wolfgang Betz |
5:8bab0f419849 | 135 | return MAGNETO_OK; |
Wolfgang Betz |
5:8bab0f419849 | 136 | } |
Wolfgang Betz |
5:8bab0f419849 | 137 | |
Wolfgang Betz |
5:8bab0f419849 | 138 | /*** Instance Variables ***/ |
Wolfgang Betz |
5:8bab0f419849 | 139 | /* IO Device */ |
Wolfgang Betz |
5:8bab0f419849 | 140 | DevI2C &dev_i2c; |
Wolfgang Betz |
5:8bab0f419849 | 141 | |
Wolfgang Betz |
5:8bab0f419849 | 142 | /* TODO */ |
Wolfgang Betz |
5:8bab0f419849 | 143 | }; |
Wolfgang Betz |
5:8bab0f419849 | 144 | |
Wolfgang Betz |
5:8bab0f419849 | 145 | #endif // __LIS3MDL_CLASS_H |