an I2C bus optical sensor for heart rate monitor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BH1790GLC.h Source File

BH1790GLC.h

00001 /*****************************************************************************
00002   BH1790GLC.h
00003 
00004  Copyright (c) 2016 ROHM Co.,Ltd.
00005 
00006  Permission is hereby granted, free of charge, to any person obtaining a copy
00007  of this software and associated documentation files (the "Software"), to deal
00008  in the Software without restriction, including without limitation the rights
00009  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010  copies of the Software, and to permit persons to whom the Software is
00011  furnished to do so, subject to the following conditions:
00012 
00013  The above copyright notice and this permission notice shall be included in
00014  all copies or substantial portions of the Software.
00015 
00016  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022  THE SOFTWARE.
00023 ******************************************************************************/
00024 #ifndef _BH1790GLC_H_
00025 #define _BH1790GLC_H_
00026 
00027 #define BH1790GLC_DEVICE_ADDRESS      (0x5B<<1)    
00028 #define BH1790GLC_MID_VAL             (0xE0)
00029 #define BH1790GLC_PID_VAL             (0x0D)
00030 
00031 #define BH1790GLC_MANUFACTURER_ID     (0x0F)
00032 #define BH1790GLC_PART_ID             (0x10)
00033 #define BH1790GLC_MEAS_CONTROL1       (0x41)
00034 #define BH1790GLC_DATAOUT_LEDOFF      (0x54)
00035 
00036 #define BH1790GLC_MEAS_CONTROL1_RDY                     (1 << 7)
00037 #define BH1790GLC_MEAS_CONTROL1_LED_LIGHTING_FREQ_128HZ (0 << 2)
00038 #define BH1790GLC_MEAS_CONTROL1_RCYCLE_32HZ             (2 << 0)
00039 
00040 #define BH1790GLC_MEAS_CONTROL2_LED_EN_00               (0 << 6)
00041 #define BH1790GLC_MEAS_CONTROL2_LED_ON_TIME_0_3MS       (0 << 5)
00042 #define BH1790GLC_MEAS_CONTROL2_LED_CURRENT_10MA        (12 << 0)
00043 
00044 #define BH1790GLC_MEAS_START_MEAS_ST                    (1 << 0)
00045 
00046 #define BH1790GLC_MEAS_CONTROL1_VAL   (BH1790GLC_MEAS_CONTROL1_RDY | BH1790GLC_MEAS_CONTROL1_LED_LIGHTING_FREQ_128HZ | BH1790GLC_MEAS_CONTROL1_RCYCLE_32HZ)
00047 #define BH1790GLC_MEAS_CONTROL2_VAL   (BH1790GLC_MEAS_CONTROL2_LED_EN_00 | BH1790GLC_MEAS_CONTROL2_LED_ON_TIME_0_3MS | BH1790GLC_MEAS_CONTROL2_LED_CURRENT_10MA)
00048 #define BH1790GLC_MEAS_START_VAL      (BH1790GLC_MEAS_START_MEAS_ST)
00049 
00050 #include "mbed.h"
00051 
00052 /** BH1790GLC class
00053  *
00054  *  BH1790GLC: an I2C bus optical sensor for heart rate monitor library
00055  *
00056  *  BH1790GLC is optical sensor for heart rate monitor IC in
00057  *  which LED driver and green light detection photo-diode
00058  *  are incorporated. This device drives LED and provides
00059  *  the intensity of light reflected from body.
00060  *
00061  *  For more information about BH1790GLC:
00062  *    http://www.rohm.com/web/global/datasheet/BH1790GLC/bh1790glc-e
00063  *    
00064  *  This was ported from Arduino library by H.Tanaka
00065  *    http://rohmfs.rohm.com/en/products/databook/applinote/ic/sensor/optical_sensor_for_heart_rate_monitor/bh1790glc-evk-001-manual-e.pdf
00066  *    http://rohmfs.rohm.com/en/products/databook/applinote/ic/sensor/optical_sensor_for_heart_rate_monitor/bh1790glc-software-manual-e.pdf
00067  */
00068 
00069 class BH1790GLC
00070 {
00071 public:
00072     /** Create a BH1790GLC instance connected to specified I2C pins with specified address
00073      *
00074      * @param sda I2C-bus SDA pin
00075      * @param scl I2C-bus SCL pin
00076      * @param i2c_address I2C-bus address (default: 0x5B<<1)
00077      */
00078     BH1790GLC(PinName sda, PinName scl, char address = BH1790GLC_DEVICE_ADDRESS);
00079     /** Create a BH1790GLC instance connected to specified I2C object with specified address
00080     *
00081     * @param i2c_obj I2C object (instance)
00082     * @param i2c_address I2C-bus address (default: 0x5B<<1)
00083     */
00084     BH1790GLC(I2C &i2c_obj, char address = BH1790GLC_DEVICE_ADDRESS);
00085     /** Destructor of BH1790GLC
00086      */
00087     ~BH1790GLC();
00088 
00089     void init(void);
00090     int meas_start(void);
00091     int get_rawval(char *data);
00092     int get_val(unsigned short *data);
00093     int write(char memory_address,char *data,int size);
00094     int read(char memory_address,char *data, int size);
00095 private:
00096     I2C *i2c_p;
00097     I2C &i2c;
00098     char adr;
00099 };
00100 #endif