Bremen Team - Hangar / SML2

Dependencies:   CalibrateMagneto QuaternionMath

Fork of SML2 by TobyRich GmbH

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PowerAwareI2C.h Source File

PowerAwareI2C.h

00001 #ifndef _H_POWERAWAREI2C_H
00002 #define _H_POWERAWAREI2C_H
00003 
00004 #include "mbed.h"
00005 #include "i2c_api.h"
00006 
00007 /// This is a variation of I2C class from mbed, which adds power on and off functions to the I2C peripheral. This should save about 1 mA.
00008 class PowerAwareI2C : public I2C
00009 {
00010 public:
00011     PowerAwareI2C(PinName sda, PinName scl) : I2C(sda, scl) {}
00012 
00013     /// Power on the I2C peripheral
00014     void powerOn() {
00015         _i2c.i2c->ENABLE = (TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos);
00016     }
00017 
00018     /// Power off the I2C peripheral
00019     void powerOff() {
00020         _i2c.i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
00021         _i2c.i2c->POWER  = 0;
00022     }
00023 };
00024 
00025 #endif//_H_POWERAWAREI2C_H