Beta
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_IKS01A2 by
Components/LSM303AGRSensor/LSM303AGRMagSensor.h@9:038121268b07, 2017-03-14 (annotated)
- Committer:
- Davidroid
- Date:
- Tue Mar 14 13:30:55 2017 +0000
- Revision:
- 9:038121268b07
- Parent:
- 7:753cd372c183
Updated with the new version of the ST_INTERFACES library, and other typos corrected.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
davide.aliprandi@st.com | 7:753cd372c183 | 1 | /** |
davide.aliprandi@st.com | 7:753cd372c183 | 2 | ****************************************************************************** |
davide.aliprandi@st.com | 7:753cd372c183 | 3 | * @file LSM303AGRMagSensor.h |
davide.aliprandi@st.com | 7:753cd372c183 | 4 | * @author CLab |
davide.aliprandi@st.com | 7:753cd372c183 | 5 | * @version V1.0.0 |
davide.aliprandi@st.com | 7:753cd372c183 | 6 | * @date 5 August 2016 |
davide.aliprandi@st.com | 7:753cd372c183 | 7 | * @brief Abstract Class of an LSM303AGR magnetometer sensor. |
davide.aliprandi@st.com | 7:753cd372c183 | 8 | ****************************************************************************** |
davide.aliprandi@st.com | 7:753cd372c183 | 9 | * @attention |
davide.aliprandi@st.com | 7:753cd372c183 | 10 | * |
davide.aliprandi@st.com | 7:753cd372c183 | 11 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
davide.aliprandi@st.com | 7:753cd372c183 | 12 | * |
davide.aliprandi@st.com | 7:753cd372c183 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
davide.aliprandi@st.com | 7:753cd372c183 | 14 | * are permitted provided that the following conditions are met: |
davide.aliprandi@st.com | 7:753cd372c183 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
davide.aliprandi@st.com | 7:753cd372c183 | 16 | * this list of conditions and the following disclaimer. |
davide.aliprandi@st.com | 7:753cd372c183 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
davide.aliprandi@st.com | 7:753cd372c183 | 18 | * this list of conditions and the following disclaimer in the documentation |
davide.aliprandi@st.com | 7:753cd372c183 | 19 | * and/or other materials provided with the distribution. |
davide.aliprandi@st.com | 7:753cd372c183 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
davide.aliprandi@st.com | 7:753cd372c183 | 21 | * may be used to endorse or promote products derived from this software |
davide.aliprandi@st.com | 7:753cd372c183 | 22 | * without specific prior written permission. |
davide.aliprandi@st.com | 7:753cd372c183 | 23 | * |
davide.aliprandi@st.com | 7:753cd372c183 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
davide.aliprandi@st.com | 7:753cd372c183 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
davide.aliprandi@st.com | 7:753cd372c183 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
davide.aliprandi@st.com | 7:753cd372c183 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
davide.aliprandi@st.com | 7:753cd372c183 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
davide.aliprandi@st.com | 7:753cd372c183 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
davide.aliprandi@st.com | 7:753cd372c183 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
davide.aliprandi@st.com | 7:753cd372c183 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
davide.aliprandi@st.com | 7:753cd372c183 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
davide.aliprandi@st.com | 7:753cd372c183 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
davide.aliprandi@st.com | 7:753cd372c183 | 34 | * |
davide.aliprandi@st.com | 7:753cd372c183 | 35 | ****************************************************************************** |
davide.aliprandi@st.com | 7:753cd372c183 | 36 | */ |
davide.aliprandi@st.com | 7:753cd372c183 | 37 | |
davide.aliprandi@st.com | 7:753cd372c183 | 38 | |
davide.aliprandi@st.com | 7:753cd372c183 | 39 | /* Prevent recursive inclusion -----------------------------------------------*/ |
davide.aliprandi@st.com | 7:753cd372c183 | 40 | |
davide.aliprandi@st.com | 7:753cd372c183 | 41 | #ifndef __LSM303AGRMagSensor_H__ |
davide.aliprandi@st.com | 7:753cd372c183 | 42 | #define __LSM303AGRMagSensor_H__ |
davide.aliprandi@st.com | 7:753cd372c183 | 43 | |
davide.aliprandi@st.com | 7:753cd372c183 | 44 | |
davide.aliprandi@st.com | 7:753cd372c183 | 45 | /* Includes ------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 7:753cd372c183 | 46 | |
davide.aliprandi@st.com | 7:753cd372c183 | 47 | #include "DevI2C.h" |
davide.aliprandi@st.com | 7:753cd372c183 | 48 | #include "LSM303AGR_mag_driver.h" |
davide.aliprandi@st.com | 7:753cd372c183 | 49 | #include "MagneticSensor.h" |
davide.aliprandi@st.com | 7:753cd372c183 | 50 | |
davide.aliprandi@st.com | 7:753cd372c183 | 51 | |
davide.aliprandi@st.com | 7:753cd372c183 | 52 | /* Class Declaration ---------------------------------------------------------*/ |
davide.aliprandi@st.com | 7:753cd372c183 | 53 | |
davide.aliprandi@st.com | 7:753cd372c183 | 54 | /** |
davide.aliprandi@st.com | 7:753cd372c183 | 55 | * Abstract class of an LSM303AGR Inertial Measurement Unit (IMU) 6 axes |
davide.aliprandi@st.com | 7:753cd372c183 | 56 | * sensor. |
davide.aliprandi@st.com | 7:753cd372c183 | 57 | */ |
davide.aliprandi@st.com | 7:753cd372c183 | 58 | class LSM303AGRMagSensor : public MagneticSensor |
davide.aliprandi@st.com | 7:753cd372c183 | 59 | { |
davide.aliprandi@st.com | 7:753cd372c183 | 60 | public: |
davide.aliprandi@st.com | 7:753cd372c183 | 61 | LSM303AGRMagSensor(DevI2C &i2c); |
davide.aliprandi@st.com | 7:753cd372c183 | 62 | LSM303AGRMagSensor(DevI2C &i2c, uint8_t address); |
davide.aliprandi@st.com | 7:753cd372c183 | 63 | virtual int init(void *init); |
davide.aliprandi@st.com | 7:753cd372c183 | 64 | virtual int read_id(uint8_t *id); |
davide.aliprandi@st.com | 7:753cd372c183 | 65 | virtual int get_m_axes(int32_t *pData); |
Davidroid | 9:038121268b07 | 66 | virtual int get_m_axes_raw(int16_t *pData); |
davide.aliprandi@st.com | 7:753cd372c183 | 67 | int enable(void); |
davide.aliprandi@st.com | 7:753cd372c183 | 68 | int disable(void); |
davide.aliprandi@st.com | 7:753cd372c183 | 69 | int get_m_sensitivity(float *pfData); |
davide.aliprandi@st.com | 7:753cd372c183 | 70 | int get_m_odr(float *odr); |
davide.aliprandi@st.com | 7:753cd372c183 | 71 | int set_m_odr(float odr); |
davide.aliprandi@st.com | 7:753cd372c183 | 72 | int get_m_fs(float *fullScale); |
davide.aliprandi@st.com | 7:753cd372c183 | 73 | int set_m_fs(float fullScale); |
davide.aliprandi@st.com | 7:753cd372c183 | 74 | int read_reg(uint8_t reg, uint8_t *data); |
davide.aliprandi@st.com | 7:753cd372c183 | 75 | int write_reg(uint8_t reg, uint8_t data); |
davide.aliprandi@st.com | 7:753cd372c183 | 76 | |
davide.aliprandi@st.com | 7:753cd372c183 | 77 | /** |
davide.aliprandi@st.com | 7:753cd372c183 | 78 | * @brief Utility function to read data. |
davide.aliprandi@st.com | 7:753cd372c183 | 79 | * @param pBuffer: pointer to data to be read. |
davide.aliprandi@st.com | 7:753cd372c183 | 80 | * @param RegisterAddr: specifies internal address register to be read. |
davide.aliprandi@st.com | 7:753cd372c183 | 81 | * @param NumByteToRead: number of bytes to be read. |
davide.aliprandi@st.com | 7:753cd372c183 | 82 | * @retval 0 if ok, an error code otherwise. |
davide.aliprandi@st.com | 7:753cd372c183 | 83 | */ |
davide.aliprandi@st.com | 7:753cd372c183 | 84 | uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) |
davide.aliprandi@st.com | 7:753cd372c183 | 85 | { |
Davidroid | 9:038121268b07 | 86 | return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); |
davide.aliprandi@st.com | 7:753cd372c183 | 87 | } |
davide.aliprandi@st.com | 7:753cd372c183 | 88 | |
davide.aliprandi@st.com | 7:753cd372c183 | 89 | /** |
davide.aliprandi@st.com | 7:753cd372c183 | 90 | * @brief Utility function to write data. |
davide.aliprandi@st.com | 7:753cd372c183 | 91 | * @param pBuffer: pointer to data to be written. |
davide.aliprandi@st.com | 7:753cd372c183 | 92 | * @param RegisterAddr: specifies internal address register to be written. |
davide.aliprandi@st.com | 7:753cd372c183 | 93 | * @param NumByteToWrite: number of bytes to write. |
davide.aliprandi@st.com | 7:753cd372c183 | 94 | * @retval 0 if ok, an error code otherwise. |
davide.aliprandi@st.com | 7:753cd372c183 | 95 | */ |
davide.aliprandi@st.com | 7:753cd372c183 | 96 | uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) |
davide.aliprandi@st.com | 7:753cd372c183 | 97 | { |
Davidroid | 9:038121268b07 | 98 | return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); |
davide.aliprandi@st.com | 7:753cd372c183 | 99 | } |
davide.aliprandi@st.com | 7:753cd372c183 | 100 | |
davide.aliprandi@st.com | 7:753cd372c183 | 101 | private: |
davide.aliprandi@st.com | 7:753cd372c183 | 102 | |
davide.aliprandi@st.com | 7:753cd372c183 | 103 | /* Helper classes. */ |
Davidroid | 9:038121268b07 | 104 | DevI2C &_dev_i2c; |
davide.aliprandi@st.com | 7:753cd372c183 | 105 | |
davide.aliprandi@st.com | 7:753cd372c183 | 106 | /* Configuration */ |
Davidroid | 9:038121268b07 | 107 | uint8_t _address; |
davide.aliprandi@st.com | 7:753cd372c183 | 108 | }; |
davide.aliprandi@st.com | 7:753cd372c183 | 109 | |
davide.aliprandi@st.com | 7:753cd372c183 | 110 | #ifdef __cplusplus |
davide.aliprandi@st.com | 7:753cd372c183 | 111 | extern "C" { |
davide.aliprandi@st.com | 7:753cd372c183 | 112 | #endif |
davide.aliprandi@st.com | 7:753cd372c183 | 113 | uint8_t LSM303AGR_MAG_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); |
davide.aliprandi@st.com | 7:753cd372c183 | 114 | uint8_t LSM303AGR_MAG_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); |
davide.aliprandi@st.com | 7:753cd372c183 | 115 | #ifdef __cplusplus |
davide.aliprandi@st.com | 7:753cd372c183 | 116 | } |
davide.aliprandi@st.com | 7:753cd372c183 | 117 | #endif |
davide.aliprandi@st.com | 7:753cd372c183 | 118 | |
davide.aliprandi@st.com | 7:753cd372c183 | 119 | #endif |