Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ST_INTERFACES X_NUCLEO_COMMON_SPI3W
Fork of X_NUCLEO_IKS01A2 by
LSM303AGRMagSensor.h
00001 /** 00002 ****************************************************************************** 00003 * @file LSM303AGRMagSensor.h 00004 * @author CLab 00005 * @version V1.0.0 00006 * @date 5 August 2016 00007 * @brief Abstract Class of an LSM303AGR magnetometer sensor. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 00039 /* Prevent recursive inclusion -----------------------------------------------*/ 00040 00041 #ifndef __LSM303AGRMagSensor_H__ 00042 #define __LSM303AGRMagSensor_H__ 00043 00044 00045 /* Includes ------------------------------------------------------------------*/ 00046 00047 #include "SPI3W.h" 00048 #include "DevI2C.h" 00049 #include "LSM303AGR_mag_driver.h" 00050 #include "MagneticSensor.h" 00051 00052 00053 /* Class Declaration ---------------------------------------------------------*/ 00054 00055 /** 00056 * Abstract class of an LSM303AGR Inertial Measurement Unit (IMU) 6 axes 00057 * sensor. 00058 */ 00059 class LSM303AGRMagSensor : public MagneticSensor 00060 { 00061 public: 00062 LSM303AGRMagSensor(SPI3W *spi3w, PinName cs_pin, PinName intmag_pin=NC); 00063 LSM303AGRMagSensor(DevI2C *i2c, uint8_t address=LSM303AGR_MAG_I2C_ADDRESS, PinName intmag_pin=NC); 00064 00065 virtual int init(void *init); 00066 virtual int read_id(uint8_t *id); 00067 virtual int get_m_axes(int32_t *pData); 00068 virtual int get_m_axes_raw(int16_t *pData); 00069 int enable(void); 00070 int disable(void); 00071 int get_m_sensitivity(float *pfData); 00072 int get_m_odr(float *odr); 00073 int set_m_odr(float odr); 00074 int get_m_fs(float *fullScale); 00075 int set_m_fs(float fullScale); 00076 int read_reg(uint8_t reg, uint8_t *data); 00077 int write_reg(uint8_t reg, uint8_t data); 00078 00079 /** 00080 * @brief Utility function to read data. 00081 * @param pBuffer: pointer to data to be read. 00082 * @param RegisterAddr: specifies internal address register to be read. 00083 * @param NumByteToRead: number of bytes to be read. 00084 * @retval 0 if ok, an error code otherwise. 00085 */ 00086 uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) 00087 { 00088 if (_dev_spi3w) return _dev_spi3w->spi3w_read(pBuffer, &_cs_pin, RegisterAddr, NumByteToRead); 00089 00090 if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); 00091 return 1; 00092 } 00093 00094 /** 00095 * @brief Utility function to write data. 00096 * @param pBuffer: pointer to data to be written. 00097 * @param RegisterAddr: specifies internal address register to be written. 00098 * @param NumByteToWrite: number of bytes to write. 00099 * @retval 0 if ok, an error code otherwise. 00100 */ 00101 uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) 00102 { 00103 if (_dev_spi3w) return _dev_spi3w->spi3w_write(pBuffer, &_cs_pin, RegisterAddr, NumByteToWrite); 00104 00105 if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); 00106 return 1; 00107 } 00108 00109 private: 00110 00111 /* Helper classes. */ 00112 DevI2C *_dev_i2c; 00113 SPI3W *_dev_spi3w; 00114 00115 /* Configuration */ 00116 uint8_t _address; 00117 DigitalOut _cs_pin; 00118 InterruptIn _intmag_pin; 00119 }; 00120 00121 #ifdef __cplusplus 00122 extern "C" { 00123 #endif 00124 uint8_t LSM303AGR_MAG_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); 00125 uint8_t LSM303AGR_MAG_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); 00126 #ifdef __cplusplus 00127 } 00128 #endif 00129 00130 #endif
Generated on Wed Jul 13 2022 22:58:06 by
