mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
Diff: targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/i2c_api.c
- Revision:
- 247:135e3186a638
- Parent:
- 227:7bd0639b8911
- Child:
- 250:a49055e7a707
diff -r c22b0f22a58f -r 135e3186a638 targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/i2c_api.c --- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/i2c_api.c Tue Jul 01 06:15:07 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/i2c_api.c Tue Jul 01 15:00:09 2014 +0100 @@ -159,8 +159,6 @@ int count; int value; - if (length == 0) return 0; - /* 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); @@ -176,7 +174,7 @@ while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_TC) == RESET) { timeout--; if (timeout == 0) { - return 0; + return -1; } } @@ -190,7 +188,7 @@ while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_STOPF) == RESET) { timeout--; if (timeout == 0) { - return 0; + return -1; } } /* Clear STOP Flag */ @@ -206,8 +204,6 @@ int timeout; int count; - if (length == 0) return 0; - /* 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); @@ -221,7 +217,7 @@ while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_TC) == RESET) { timeout--; if (timeout == 0) { - return 0; + return -1; } } @@ -235,7 +231,7 @@ while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_STOPF) == RESET) { timeout--; if (timeout == 0) { - return 0; + return -1; } } /* Clear STOP Flag */ @@ -253,7 +249,7 @@ timeout = FLAG_TIMEOUT; while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_RXNE) == RESET) { if ((timeout--) == 0) { - return 0; + return -1; } } @@ -354,8 +350,6 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) { char size = 0; - if (length == 0) return 0; - while (size < length) data[size++] = (char)i2c_byte_read(obj, 0); return size; @@ -365,8 +359,6 @@ char size = 0; I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c); - if (length == 0) return 0; - do { i2c_byte_write(obj, data[size]); size++;