Combine AS7000 into BNO055
Fork of BNO055 by
Revision 10:1914e07be563, committed 2017-05-22
- Comitter:
- tsungta
- Date:
- Mon May 22 08:03:56 2017 +0000
- Parent:
- 9:f04b0a4c8057
- Commit message:
- Combine AS7000 into BNO055 to reduce the usage of I2C LLD
Changed in this revision
BNO055.cpp | Show annotated file Show diff for this revision Revisions of this file |
BNO055.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r f04b0a4c8057 -r 1914e07be563 BNO055.cpp --- a/BNO055.cpp Thu May 04 02:37:08 2017 +0000 +++ b/BNO055.cpp Mon May 22 08:03:56 2017 +0000 @@ -1,6 +1,9 @@ #include "BNO055.h" #include "mbed.h" +DigitalOut AS7000_GPIO8(p5); //NNN50-P5 map to GPIO-8 for AS7000 on/off +DigitalInOut AS7000_INT(p4); //NNN50-P4 GPIO-5 for AS7000 INT + BNO055::BNO055(PinName SDA, PinName SCL) : _i2c(SDA,SCL){ //Set I2C fast and bring reset line high _i2c.frequency(400000); @@ -9,6 +12,19 @@ rate_scale = 1.0f/16.0f; angle_scale = 1.0f/16.0f; temp_scale = 1; + + //Set I2C fast and bring reset line high + //_i2c.frequency(400000); + //address = AS7000Address; + + AS7000_INT.mode(PullNone); + + AS7000_INT.output(); + + AS7000_GPIO8.write(1); // Power OFF AS7000 + AS7000_INT.write(1); // AS7000 GPIO OUTPUT LOW + AS7000_INT.input(); + wait_ms(100); } void BNO055::reset(){ @@ -277,4 +293,42 @@ writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x24); writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x00); } +} + +//AS7000::AS7000(PinName SDA, PinName SCL) : _i2c(SDA,SCL){ +// +//} + +void BNO055::enable(void){ + char cmd[2]; + + AS7000_GPIO8.write(0); //Power ON AS7000 + wait_ms(280); //Wait for > 250ms for booting + + cmd[0] = AS7000_STARTUP; //0x04; + cmd[1] = 0x02; + _i2c.write(AS7000Address, cmd, 2); + wait_ms(35); + +} + +void BNO055::update(void){ + +} + +void BNO055::hr_only(void){ + char cmd[2]; + cmd[0] = HR_ONLY; + if(AS7000_INT == 0) { + _i2c.write(AS7000Address, cmd, 1); + _i2c.read(AS7000Address, rawdata, 7, false); + wait_ms(10); + //update(); + hrm.transaction_id = rawdata[0]; + hrm.status = rawdata[1]; + hrm.hreat_rate = rawdata[2]; + hrm.signal_QA = rawdata[3]; + hrm.LED_current = ((rawdata[4]<<8)+rawdata[5]); + hrm.SYNC = rawdata[6]; + } } \ No newline at end of file
diff -r f04b0a4c8057 -r 1914e07be563 BNO055.h --- a/BNO055.h Thu May 04 02:37:08 2017 +0000 +++ b/BNO055.h Mon May 22 08:03:56 2017 +0000 @@ -173,14 +173,40 @@ char serial[16]; }chip; +#define AS7000Address 0x60 +//Register definitions +#define AS7000_STARTUP 0x04 //4 +#define HR_ONLY 0x08 //8 +#define HR_ONLY_LEN 0x07 //7 +#define HR_REG 0x12 //18 +#define HR_LEN 21 + +typedef struct{ + uint8_t transaction_id; + uint8_t status; + uint8_t hreat_rate; + uint8_t signal_QA; + uint16_t LED_current; + uint8_t SYNC; + uint8_t startup_flag; + bool contact_detected; +}as7000_t; + /** Class for operating Bosch BNO055 sensor over I2C **/ class BNO055 { public: - + /** Create BNO055 instance **/ BNO055(PinName SDA, PinName SCL); - + + void gpio_init(void); + void enable (void);///< Heart Rate Sensor Enbable API,it include startup senario + void startup (void); + void hr_only (void);///< Hreat Rate Sensor sensing and data + void update (void); + as7000_t hrm; + /** Perform a power-on reset of the BNO055 **/ void reset(); /** Check that the BNO055 is connected and download the software details @@ -276,5 +302,13 @@ void setpage(char value){ writechar(BNO055_PAGE_ID_ADDR,value); } + +// private: +// I2C _i2c; +// char rx,tx[2],address; +// char rawdata[22]; + char hreat_rate; + char startup_flag; + }; #endif \ No newline at end of file