Sample program for communicating with Fujitsuu IoT Platform using HTTP

Dependencies:   AsciiFont GR-PEACH_video GraphicsFramework LCD_shield_config R_BSP USBHost_custom easy-connect-gr-peach mbed-http picojson BM1383GLV KX022 rohm-sensor-hal rohm-bh1745

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 extern Serial pc;
00064 #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__)
00065 #else
00066 #define DEBUG_PRINT(...)
00067 #endif
00068 
00069 class BM1422AGMV
00070 {
00071 public:
00072     /**
00073     * BM1422 constructor
00074     *
00075     * @param sda SDA pin
00076     * @param sdl SCL pin
00077     * @param addr slave address of the I2C peripheral (default: 0x1C)
00078     */
00079     BM1422AGMV(PinName sda, PinName scl, int addr = BM1422AGMV_DEVICE_ADDRESS_0E);
00080 
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     /**
00091     * BM1422 destructor
00092     */
00093     ~BM1422AGMV();
00094 
00095     /** Initializa BM1422 sensor
00096      *
00097      *  Configure sensor setting
00098      *
00099      */
00100     void initialize(void);
00101 
00102     /**
00103      * Get X axis acceleration
00104      *
00105      * @returns X axis acceleration
00106      */
00107     void get_rawval(unsigned char *data);
00108 
00109     /**
00110      * Get Y axis acceleration
00111      *
00112      * @returns Y axis acceleration
00113      */
00114     void get_val(float *data);
00115 
00116     /**
00117      * Get Z axis acceleration
00118      *
00119      * @returns Z axis acceleration
00120      */
00121     void convert_uT(int16_t *rawdata, float *data);
00122 
00123     /**
00124      * Get XYZ axis acceleration
00125      *
00126      * @param res array where acceleration data will be stored
00127      */
00128     void set_drdy_flg(void);
00129     
00130     void isr_func(InterruptIn interrupt, void func(void));
00131 
00132 private:
00133     I2C m_i2c;
00134     int m_addr;
00135     void readRegs(int addr, uint8_t * data, int len);
00136     void writeRegs(uint8_t * data, int len);
00137     int _device_address;
00138     volatile int _drdy_flg;
00139     uint8_t _sens;
00140 
00141 };
00142 
00143 #endif