mbed
Fork of mbed-dev by
Diff: drivers/I2C.cpp
- Revision:
- 181:96ed750bd169
- Parent:
- 175:b96e65c34a4d
--- a/drivers/I2C.cpp Thu Dec 07 14:01:42 2017 +0000 +++ b/drivers/I2C.cpp Wed Jan 17 15:23:54 2018 +0000 @@ -28,9 +28,10 @@ I2C::I2C(PinName sda, PinName scl) : #if DEVICE_I2C_ASYNCH - _irq(this), _usage(DMA_USAGE_NEVER), + _irq(this), _usage(DMA_USAGE_NEVER), _deep_sleep_locked(false), #endif - _i2c(), _hz(100000) { + _i2c(), _hz(100000) +{ // No lock needed in the constructor // The init function also set the frequency to 100000 @@ -133,7 +134,7 @@ unlock(); return -1; // transaction ongoing } - sleep_manager_lock_deep_sleep(); + lock_deep_sleep(); aquire(); _callback = callback; @@ -148,7 +149,7 @@ { lock(); i2c_abort_asynch(&_i2c); - sleep_manager_unlock_deep_sleep(); + unlock_deep_sleep(); unlock(); } @@ -159,11 +160,26 @@ _callback.call(event); } if (event) { - sleep_manager_unlock_deep_sleep(); + unlock_deep_sleep(); } } +void I2C::lock_deep_sleep() +{ + if (_deep_sleep_locked == false) { + sleep_manager_lock_deep_sleep(); + _deep_sleep_locked = true; + } +} + +void I2C::unlock_deep_sleep() +{ + if (_deep_sleep_locked == true) { + sleep_manager_unlock_deep_sleep(); + _deep_sleep_locked = false; + } +} #endif