Implemented first Hangar-Service
Dependencies: CalibrateMagneto QuaternionMath
Fork of SML2 by
PowerAwareI2C.h@46:fd5a62296b12, 2015-05-27 (annotated)
- Committer:
- pvaibhav
- Date:
- Wed May 27 13:01:43 2015 +0000
- Revision:
- 46:fd5a62296b12
- Parent:
- 33:bd56fc8aeb0a
Code reformatted
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pvaibhav | 32:d37447aec6b4 | 1 | #ifndef _H_POWERAWAREI2C_H |
pvaibhav | 32:d37447aec6b4 | 2 | #define _H_POWERAWAREI2C_H |
pvaibhav | 32:d37447aec6b4 | 3 | |
pvaibhav | 32:d37447aec6b4 | 4 | #include "mbed.h" |
pvaibhav | 32:d37447aec6b4 | 5 | #include "i2c_api.h" |
pvaibhav | 32:d37447aec6b4 | 6 | |
pvaibhav | 32:d37447aec6b4 | 7 | /// 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. |
pvaibhav | 32:d37447aec6b4 | 8 | class PowerAwareI2C : public I2C |
pvaibhav | 32:d37447aec6b4 | 9 | { |
pvaibhav | 32:d37447aec6b4 | 10 | public: |
pvaibhav | 32:d37447aec6b4 | 11 | PowerAwareI2C(PinName sda, PinName scl) : I2C(sda, scl) {} |
pvaibhav | 46:fd5a62296b12 | 12 | |
pvaibhav | 32:d37447aec6b4 | 13 | /// Power on the I2C peripheral |
pvaibhav | 46:fd5a62296b12 | 14 | void powerOn() { |
pvaibhav | 33:bd56fc8aeb0a | 15 | _i2c.i2c->ENABLE = (TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos); |
pvaibhav | 32:d37447aec6b4 | 16 | } |
pvaibhav | 46:fd5a62296b12 | 17 | |
pvaibhav | 46:fd5a62296b12 | 18 | /// Power off the I2C peripheral |
pvaibhav | 46:fd5a62296b12 | 19 | void powerOff() { |
pvaibhav | 33:bd56fc8aeb0a | 20 | _i2c.i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; |
pvaibhav | 33:bd56fc8aeb0a | 21 | _i2c.i2c->POWER = 0; |
pvaibhav | 32:d37447aec6b4 | 22 | } |
pvaibhav | 32:d37447aec6b4 | 23 | }; |
pvaibhav | 32:d37447aec6b4 | 24 | |
pvaibhav | 32:d37447aec6b4 | 25 | #endif//_H_POWERAWAREI2C_H |