K Andres / Mbed 2 deprecated SCIboard

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SCIboard_LSM303DLHC.h Source File

SCIboard_LSM303DLHC.h

00001 /* SCIboard(TM) LSM303DLHC.h
00002 Copyright (c) 2013 K. Andres
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021 */
00022 
00023 #ifndef SCIboard_LSM303DLHC_H
00024 #define SCIboard_LSM303DLHC_H
00025 
00026 #include "mbed.h"
00027 #include "SCIboard_I2C.h"
00028 
00029 // STMicroelectronics www.st.com - Ultra compact high performance
00030 // e-compass, 3D accelerometer, and 3D magnetometer module
00031 // Data sheet - Preliminary data - Rev 1
00032 #define ACC_I2C_ADDR (0x19<<1)
00033 #define MAG_I2C_ADDR (0x1E<<1)
00034 
00035 // Acc Registers
00036 #define ACCREG_CTRL_REG1        0x20
00037 #define ACCREG_CTRL_REG2        0x21
00038 #define ACCREG_CTRL_REG3        0x22
00039 #define ACCREG_CTRL_REG4        0x23
00040 #define ACCREG_CTRL_REG5        0x24
00041 #define ACCREG_CTRL_REG6        0x25
00042 #define ACCREG_REFERENCE        0x26
00043 #define ACCREG_STATUS           0x27
00044 #define ACCREG_OUT_X_L          0x28
00045 #define ACCREG_OUT_Y_L          0x2A
00046 #define ACCREG_OUT_Z_L          0x2C
00047 
00048 #define ACCREG_INT1_CFG         0x30
00049 #define ACCREG_INT1_SOURCE      0x31
00050 #define ACCREG_INT1_THS         0x32
00051 #define ACCREG_INT1_DURATION    0x33
00052 
00053 #define ACCREG_INT2_CFG         0x34
00054 #define ACCREG_INT2_SOURCE      0x35
00055 #define ACCREG_INT2_THS         0x36
00056 #define ACCREG_INT2_DURATION    0x37
00057 
00058 // Mag Resisters
00059 #define MAGREG_CRA_REG          0x00
00060 #define MAGREG_CRB_REG          0x01
00061 #define MAGREG_MR_REG           0X02
00062 #define MAGREG_OUT_X_H          0x03
00063 #define MAGREG_OUT_Z_H          0x05    // Note Z out of order
00064 #define MAGREG_OUT_Y_H          0x07
00065 #define MAGREG_SR_REG           0x09
00066 
00067 #define MAGREG_IRA_REG          0x0A
00068 
00069 #define MAGREG_TEMP_OUT_H       0x31
00070 
00071 
00072 // Status Register
00073 #define STATUS_REG_ZYXDA        0x08
00074 
00075 // ACCREG_CTRL_REG1 Output Data Rate (ODR)
00076 #define ACC_1HZ                 1
00077 #define ACC_10HZ                2
00078 #define ACC_25HZ                3
00079 #define ACC_50HZ                4
00080 #define ACC_100HZ               5
00081 #define ACC_200HZ               6
00082 #define ACC_400HZ               7
00083 #define ACC_1620HZ              8       // Low power mode
00084 #define ACC_5376HZ              9       // Low power mode / Normal 1344Hz
00085 
00086 // ACCREG_CTRL_REG4 Full-scale selection +/-g
00087 #define ACC_2G                  0
00088 #define ACC_4G                  1
00089 #define ACC_8G                  2
00090 #define ACC_16G                 3
00091 
00092 // MAGREG_CRA_REG
00093 #define MAG_TEMP_EN             0x80
00094 #define MAG_0p75HZ              0
00095 #define MAG_1p5HZ               1
00096 #define MAG_3p0HZ               2
00097 #define MAG_7p5HZ               3
00098 #define MAG_15HZ                4       // Default
00099 #define MAG_30HZ                5
00100 #define MAG_75HZ                6
00101 #define MAG_220HZ               7
00102 
00103 // MAGREG_CRB_REG Gain setting [Gauss]
00104 #define MAG_1p3G                1
00105 #define MAG_1p9G                2
00106 #define MAG_2p5G                3
00107 #define MAG_4p0G                4
00108 #define MAG_4p7G                5
00109 #define MAG_5p6G                6
00110 #define MAG_8p1G                7
00111 
00112 // MAGREG_MR_REG Mode select bits
00113 #define MAG_Continuous_Conv     0
00114 #define MAG_Single_Conv         1
00115 #define MAG_Sleep_Mode          2
00116 
00117 // MAGREG_SR_REG 
00118 #define MAG_DRDY                1
00119 #define MAG_LOCK                2
00120 
00121 
00122 class SCIboard_LSM303DLHC
00123 {
00124 public:
00125     SCIboard_LSM303DLHC(SCIboard_I2C *ptr_I2C);
00126     void getDeviceID(unsigned char *id);
00127 
00128     void setAccMode(unsigned char AccFs, unsigned char AccRate);
00129     unsigned char getAccStatus(void);
00130     bool bAccDataAvailable(void);
00131     void getAccData(float *fData);
00132     unsigned char getInt1Src(void);
00133     void writeCtrlReg(unsigned char reg, unsigned char value);
00134 
00135     void setMagMode(unsigned char MagFs, unsigned char MagRate);
00136     unsigned char getMagStatus(void);
00137     bool bMagDataAvailable(void);
00138     void getMagData(float *fData);
00139     void getMagData(char *cData);
00140     float getTemp(void);
00141     void getTemp(char *cData);
00142   
00143 private:
00144     SCIboard_I2C *pI2C;
00145     float accSF;
00146     float accRate;
00147     float magSF[3];
00148     float magRate;
00149 };
00150 
00151 #endif