minor fix

This commit is contained in:
King Kévin 2017-05-02 17:18:20 +02:00
parent fa9678812c
commit f1c078c721
1 changed files with 5 additions and 10 deletions

View File

@ -99,10 +99,10 @@ bool i2c_master_read(uint8_t slave, const uint8_t* address, size_t address_size,
// sanity check // sanity check
if (address==NULL || address_size==0 || data==NULL || data_size==0) { // input data is erroneous if (address==NULL || address_size==0 || data==NULL || data_size==0) { // input data is erroneous
return false; return false;
} }
if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_BUSY) { // I2C device is busy if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_BUSY) { // I2C device is busy
return false; return false;
} }
if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_MSL) { // I2C device is already in master mode if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_MSL) { // I2C device is already in master mode
return false; return false;
} }
@ -201,9 +201,6 @@ bool i2c_master_read(uint8_t slave, const uint8_t* address, size_t address_size,
to_return = true; to_return = true;
error: error:
if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_BUSY) { // release bus if busy
// i2c_send_stop(I2C(I2C_MASTER_I2C)); // send stop to release bus
}
i2c_send_stop(I2C(I2C_MASTER_I2C)); // send stop to release bus i2c_send_stop(I2C(I2C_MASTER_I2C)); // send stop to release bus
timer_set_counter(TIM(I2C_MASTER_TIMER),0); // restart timer timer_set_counter(TIM(I2C_MASTER_TIMER),0); // restart timer
timer_clear_flag(TIM(I2C_MASTER_TIMER), TIM_SR_UIF); // clear flag timer_clear_flag(TIM(I2C_MASTER_TIMER), TIM_SR_UIF); // clear flag
@ -221,10 +218,10 @@ bool i2c_master_write(uint8_t slave, const uint8_t* address, size_t address_size
// sanity check // sanity check
if (address==NULL || address_size==0 || data==NULL || data_size==0) { // input data is erroneous if (address==NULL || address_size==0 || data==NULL || data_size==0) { // input data is erroneous
return false; return false;
} }
if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_BUSY) { // I2C device is busy if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_BUSY) { // I2C device is busy
return false; return false;
} }
if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_MSL) { // I2C device is already in master mode if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_MSL) { // I2C device is already in master mode
return false; return false;
} }
@ -293,9 +290,7 @@ bool i2c_master_write(uint8_t slave, const uint8_t* address, size_t address_size
to_return = true; to_return = true;
error: error:
if (I2C_SR2(I2C(I2C_MASTER_I2C)) & I2C_SR2_BUSY) { // release bus if busy i2c_send_stop(I2C(I2C_MASTER_I2C)); // send stop to release bus
i2c_send_stop(I2C(I2C_MASTER_I2C)); // send stop to release bus
}
timer_set_counter(TIM(I2C_MASTER_TIMER),0); // restart timer timer_set_counter(TIM(I2C_MASTER_TIMER),0); // restart timer
timer_clear_flag(TIM(I2C_MASTER_TIMER), TIM_SR_UIF); // clear flag timer_clear_flag(TIM(I2C_MASTER_TIMER), TIM_SR_UIF); // clear flag
timer_enable_counter(TIM(I2C_MASTER_TIMER)); // enable timer for timeouts timer_enable_counter(TIM(I2C_MASTER_TIMER)); // enable timer for timeouts