Implemented first Hangar-Service
Dependencies: CalibrateMagneto QuaternionMath
Fork of SML2 by
PowerAwareI2C.h@33:bd56fc8aeb0a, 2015-05-05 (annotated)
- Committer:
- pvaibhav
- Date:
- Tue May 05 09:59:11 2015 +0000
- Revision:
- 33:bd56fc8aeb0a
- Parent:
- 32:d37447aec6b4
- Child:
- 46:fd5a62296b12
White LED mirrors blue LED
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 | 32:d37447aec6b4 | 12 | |
pvaibhav | 32:d37447aec6b4 | 13 | /// Power on the I2C peripheral |
pvaibhav | 32:d37447aec6b4 | 14 | void powerOn() |
pvaibhav | 32:d37447aec6b4 | 15 | { |
pvaibhav | 33:bd56fc8aeb0a | 16 | _i2c.i2c->ENABLE = (TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos); |
pvaibhav | 32:d37447aec6b4 | 17 | } |
pvaibhav | 32:d37447aec6b4 | 18 | |
pvaibhav | 32:d37447aec6b4 | 19 | /// Power off the I2C peripheral |
pvaibhav | 32:d37447aec6b4 | 20 | void powerOff() |
pvaibhav | 32:d37447aec6b4 | 21 | { |
pvaibhav | 33:bd56fc8aeb0a | 22 | _i2c.i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; |
pvaibhav | 33:bd56fc8aeb0a | 23 | _i2c.i2c->POWER = 0; |
pvaibhav | 32:d37447aec6b4 | 24 | } |
pvaibhav | 32:d37447aec6b4 | 25 | }; |
pvaibhav | 32:d37447aec6b4 | 26 | |
pvaibhav | 32:d37447aec6b4 | 27 | #endif//_H_POWERAWAREI2C_H |