mbed library sources
Dependents: Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more
Superseded
This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.
Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.
If you are looking for a stable and tested release, please import one of the official mbed library releases:
Import librarymbed
The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Diff: targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/i2c_api.c
- Revision:
- 404:cbc7dfcb0ce9
- Parent:
- 402:09075a3b15e3
- Child:
- 414:4ec4c5b614b0
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/i2c_api.c Fri Nov 14 09:15:08 2014 +0000 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/i2c_api.c Fri Nov 14 10:15:07 2014 +0000 @@ -82,6 +82,7 @@ pin_mode(sda, OpenDrain); pin_mode(scl, OpenDrain); } + // Enable I2C2 clock and pinout if not done if ((obj->i2c == I2C_2) && !i2c2_inited) { i2c2_inited = 1; @@ -178,7 +179,7 @@ int count; int value; - /* update CR2 register */ + // Update CR2 register i2c->CR2 = (i2c->CR2 & (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | I2C_CR2_RD_WRN | I2C_CR2_START | I2C_CR2_STOP))) | (uint32_t)(((uint32_t)address & I2C_CR2_SADD) | (((uint32_t)length << 16) & I2C_CR2_NBYTES) | (uint32_t)I2C_SOFTEND_MODE | (uint32_t)I2C_GENERATE_START_READ); @@ -201,7 +202,7 @@ // If not repeated start, send stop. if (stop) { i2c_stop(obj); - /* Wait until STOPF flag is set */ + // Wait until STOPF flag is set timeout = FLAG_TIMEOUT; while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_STOPF) == RESET) { timeout--; @@ -209,7 +210,7 @@ return -1; } } - /* Clear STOP Flag */ + // Clear STOP Flag __HAL_I2C_CLEAR_FLAG(&I2cHandle, I2C_FLAG_STOPF); } @@ -223,12 +224,10 @@ int timeout; int count; - /* update CR2 register */ + // Update CR2 register i2c->CR2 = (i2c->CR2 & (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | I2C_CR2_RD_WRN | I2C_CR2_START | I2C_CR2_STOP))) | (uint32_t)(((uint32_t)address & I2C_CR2_SADD) | (((uint32_t)length << 16) & I2C_CR2_NBYTES) | (uint32_t)I2C_SOFTEND_MODE | (uint32_t)I2C_GENERATE_START_WRITE); - - for (count = 0; count < length; count++) { i2c_byte_write(obj, data[count]); } @@ -243,10 +242,10 @@ } __HAL_I2C_CLEAR_FLAG(&I2cHandle, I2C_FLAG_TC); - // If not repeated start, send stop. + // If not repeated start, send stop if (stop) { i2c_stop(obj); - /* Wait until STOPF flag is set */ + // Wait until STOPF flag is set timeout = FLAG_TIMEOUT; while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_STOPF) == RESET) { timeout--; @@ -254,7 +253,7 @@ return -1; } } - /* Clear STOP Flag */ + // Clear STOP Flag __HAL_I2C_CLEAR_FLAG(&I2cHandle, I2C_FLAG_STOPF); } @@ -299,7 +298,7 @@ { int timeout; - // wait before reset + // Wait before reset timeout = LONG_TIMEOUT; while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0)); @@ -336,7 +335,6 @@ void i2c_slave_mode(i2c_t *obj, int enable_slave) { - I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); uint16_t tmpreg; @@ -352,7 +350,6 @@ // Set new mode i2c->OAR1 = tmpreg; - } // See I2CSlave.h