Rohm / BM1422AGMV

Dependents:   rohm-SensorShield-example mbed_blinky

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BM1422AGMV.h Source File

BM1422AGMV.h

00001 /* Copyright (c) 2017 Renesas Electronics., MIT License
00002 *
00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004 * and associated documentation files (the "Software"), to deal in the Software without
00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
00007 * Software is furnished to do so, subject to the following conditions:
00008 *
00009 * The above copyright notice and this permission notice shall be included in all copies or
00010 * substantial portions of the Software.
00011 *
00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017 */
00018 
00019 #ifndef _BM1422AGMV_H_
00020 #define _BM1422AGMV_H_
00021 
00022 #include "mbed.h"
00023 
00024 #define BM1422AGMV_DEVICE_ADDRESS_0E    (0x0E << 1)
00025 #define BM1422AGMV_DEVICE_ADDRESS_0F    (0x0F << 1)
00026 #define BM1422AGMV_WIA_VAL             (0x41)
00027 
00028 #define BM1422AGMV_WIA                 (0x0F)
00029 #define BM1422AGMV_DATAX               (0x10)
00030 #define BM1422AGMV_STA1                (0x18)
00031 #define BM1422AGMV_CNTL1               (0x1B)
00032 #define BM1422AGMV_CNTL2               (0x1C)
00033 #define BM1422AGMV_CNTL3               (0x1D)
00034 #define BM1422AGMV_AVE_A               (0x40)
00035 #define BM1422AGMV_CNTL4               (0x5C)
00036 
00037 #define BM1422AGMV_STA1_RD_DRDY        (1 << 6)
00038 
00039 #define BM1422AGMV_CNTL1_FS1           (1 << 1)
00040 #define BM1422AGMV_CNTL1_ODR_10Hz      (0 << 3)
00041 #define BM1422AGMV_CNTL1_RST_LV        (1 << 5)
00042 #define BM1422AGMV_CNTL1_OUT_BIT       (1 << 6)
00043 #define BM1422AGMV_CNTL1_PC1           (1 << 7)
00044 
00045 #define BM1422AGMV_CNTL2_DRP           (1 << 2)
00046 #define BM1422AGMV_CNTL2_DREN          (1 << 3)
00047 
00048 #define BM1422AGMV_CNTL3_FORCE         (1 << 6)
00049 
00050 #define BM1422AGMV_AVE_A_AVE4          (0 << 2)
00051 
00052 #define BM1422AGMV_CNTL1_VAL           (BM1422AGMV_CNTL1_FS1 | BM1422AGMV_CNTL1_OUT_BIT | BM1422AGMV_CNTL1_PC1)
00053 #define BM1422AGMV_CNTL2_VAL           (BM1422AGMV_CNTL2_DREN)
00054 #define BM1422AGMV_CNTL3_VAL           (BM1422AGMV_CNTL3_FORCE)
00055 #define BM1422AGMV_CNTL4_VAL           (0x0000)
00056 #define BM1422AGMV_AVE_A_VAL           (BM1422AGMV_AVE_A_AVE4)
00057 
00058 #define BM1422AGMV_14BIT_SENS          (24)
00059 #define BM1422AGMV_12BIT_SENS          (6)
00060 
00061 //#define _DEBUG
00062 #ifdef _DEBUG
00063 #undef DEBUG_PRINT
00064 extern Serial pc;
00065 #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__)
00066 #else
00067 #define DEBUG_PRINT(...)
00068 #endif
00069 
00070 class BM1422AGMV
00071 {
00072 public:
00073     /**
00074     * BM1422 constructor
00075     *
00076     * @param sda SDA pin
00077     * @param sdl SCL pin
00078     * @param addr slave address of the I2C peripheral (default: 0x1C)
00079     */
00080     BM1422AGMV(PinName sda, PinName scl, int addr = BM1422AGMV_DEVICE_ADDRESS_0E);
00081     /**
00082      * Create a BM1422 instance which is connected to specified I2C pins
00083      * with specified address
00084      *
00085      * @param i2c_obj I2C object (instance)
00086      * @param addr slave address of the I2C-bus peripheral (default: 0x1C)
00087      */
00088     BM1422AGMV(I2C &i2c_obj, int addr = BM1422AGMV_DEVICE_ADDRESS_0E);
00089     /**
00090     * BM1422 destructor
00091     */
00092     ~BM1422AGMV();
00093     /** Initializa BM1422 sensor
00094      *
00095      *  Configure sensor setting
00096      *
00097      */
00098     void initialize(void);
00099     /**
00100      * Get XYZ axis acceleration
00101      *
00102      * @returns XYZ (filled in float[3]) axis acceleration
00103      */
00104     void get_val(float *data);
00105 
00106 private:
00107     I2C m_i2c;
00108     int m_addr;
00109     void readRegs(int addr, uint8_t * data, int len);
00110     void writeRegs(uint8_t * data, int len);
00111     uint8_t _sens;
00112     /**
00113      * Get XYZ axis acceleration
00114      *
00115      * @returns XYZ (rawdata) axis acceleration
00116      */
00117     void get_rawval(unsigned char *data);
00118     /**
00119      * Convert XYZ axis acceleration
00120      *
00121      * @returns XYZ (float array [3]) axis acceleration
00122      */
00123     void convert_uT(int16_t *rawdata, float *data);
00124 };
00125 
00126 #endif