mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Diff: drivers/I2C.cpp
- Revision:
- 187:0387e8f68319
- Parent:
- 184:08ed48f1de7f
- Child:
- 189:f392fc9709a3
--- a/drivers/I2C.cpp Fri Jun 22 16:45:37 2018 +0100 +++ b/drivers/I2C.cpp Thu Sep 06 13:40:20 2018 +0100 @@ -41,7 +41,8 @@ _owner = this; } -void I2C::frequency(int hz) { +void I2C::frequency(int hz) +{ lock(); _hz = hz; @@ -53,7 +54,8 @@ unlock(); } -void I2C::aquire() { +void I2C::aquire() +{ lock(); if (_owner != this) { i2c_frequency(&_i2c, _hz); @@ -63,7 +65,8 @@ } // write - Master Transmitter Mode -int I2C::write(int address, const char* data, int length, bool repeated) { +int I2C::write(int address, const char *data, int length, bool repeated) +{ lock(); aquire(); @@ -74,7 +77,8 @@ return length != written; } -int I2C::write(int data) { +int I2C::write(int data) +{ lock(); int ret = i2c_byte_write(&_i2c, data); unlock(); @@ -82,7 +86,8 @@ } // read - Master Receiver Mode -int I2C::read(int address, char* data, int length, bool repeated) { +int I2C::read(int address, char *data, int length, bool repeated) +{ lock(); aquire(); @@ -93,7 +98,8 @@ return length != read; } -int I2C::read(int ack) { +int I2C::read(int ack) +{ lock(); int ret; if (ack) { @@ -105,29 +111,33 @@ return ret; } -void I2C::start(void) { +void I2C::start(void) +{ lock(); i2c_start(&_i2c); unlock(); } -void I2C::stop(void) { +void I2C::stop(void) +{ lock(); i2c_stop(&_i2c); unlock(); } -void I2C::lock() { +void I2C::lock() +{ _mutex->lock(); } -void I2C::unlock() { +void I2C::unlock() +{ _mutex->unlock(); } #if DEVICE_I2C_ASYNCH -int I2C::transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event, bool repeated) +int I2C::transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t &callback, int event, bool repeated) { lock(); if (i2c_active(&_i2c)) {